BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue, c_acctbal, n_name, c_address, c_phone, c_comment from customer, orders, lineitem, nation where c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate >= date '1993-10-01' and o_orderdate < cast(date '1993-10-01' + interval '3 month' as date) and l_returnflag = 'R' and c_nationkey = n_nationkey group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment order by revenue desc LIMIT 20; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=1187526.65..1187526.70 rows=20 width=176) (actual time=32182.339..32182.347 rows=20 loops=1) Buffers: shared hit=699242 read=714624 written=32142 -> Sort (cost=1187526.65..1188959.43 rows=573112 width=176) (actual time=32182.335..32182.341 rows=20 loops=1) Sort Key: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount)))) Sort Method: top-N heapsort Memory: 30kB Buffers: shared hit=699242 read=714624 written=32142 -> HashAggregate (cost=1166545.23..1172276.35 rows=573112 width=176) (actual time=31676.100..32033.829 rows=381124 loops=1) Buffers: shared hit=699239 read=714624 written=32142 -> Hash Join (cost=399105.26..1152217.43 rows=573112 width=176) (actual time=4480.419..27682.445 rows=1147141 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=699239 read=714624 written=32142 -> Hash Join (cost=399103.69..1144335.57 rows=573112 width=154) (actual time=4480.367..27088.975 rows=1147141 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=699238 read=714624 written=32142 -> Merge Join (cost=330075.69..1063845.33 rows=573112 width=12) (actual time=1999.945..22088.237 rows=1147141 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=699236 read=679348 written=32142 -> Sort (cost=330075.67..331521.76 rows=578434 width=8) (actual time=1999.853..2169.943 rows=573178 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 51444kB Buffers: shared hit=228313 read=1730 -> Bitmap Heap Scan on orders (cost=12262.84..274714.35 rows=578434 width=8) (actual time=460.256..1797.812 rows=573178 loops=1) Recheck Cond: ((o_orderdate >= '1993-10-01'::date) AND (o_orderdate < '1994-01-01'::date)) Buffers: shared hit=228313 read=1730 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12118.24 rows=578434 width=0) (actual time=337.915..337.915 rows=574279 loops=1) Index Cond: ((o_orderdate >= '1993-10-01'::date) AND (o_orderdate < '1994-01-01'::date)) Buffers: shared read=1570 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..687917.19 rows=14891675 width=12) (actual time=0.070..17221.694 rows=14808183 loops=1) Buffers: shared hit=470923 read=677618 written=32142 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=2477.480..2477.480 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=2 read=35276 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=146) (actual time=0.018..1077.490 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.029..0.029 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 2kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.008..0.012 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 32252.608 ms (40 rows) COMMIT; COMMIT