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 '1994-02-01' and o_orderdate < cast(date '1994-02-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=1179349.88..1179349.93 rows=20 width=176) (actual time=40435.312..40435.316 rows=20 loops=1) Buffers: shared hit=1148243 read=259514 dirtied=114 written=2143 -> Sort (cost=1179349.88..1180726.04 rows=550464 width=176) (actual time=40435.307..40435.309 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=1148243 read=259514 dirtied=114 written=2143 -> HashAggregate (cost=1159197.60..1164702.24 rows=550464 width=176) (actual time=39874.356..40271.826 rows=371904 loops=1) Buffers: shared hit=1148240 read=259514 dirtied=114 written=2143 -> Hash Join (cost=395918.31..1145436.00 rows=550464 width=176) (actual time=11439.848..33381.757 rows=1109371 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=1148240 read=259514 dirtied=114 written=2143 -> Hash Join (cost=395916.75..1137865.55 rows=550464 width=154) (actual time=11439.804..32731.635 rows=1109371 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1148239 read=259514 dirtied=114 written=2143 -> Merge Join (cost=326888.75..1057828.27 rows=550464 width=12) (actual time=7447.324..25940.332 rows=1109371 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=1113008 read=259467 dirtied=114 written=2143 -> Sort (cost=326888.73..328281.90 rows=557269 width=8) (actual time=7447.183..7625.450 rows=554213 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 50555kB Buffers: shared hit=21879 read=205697 -> Bitmap Heap Scan on orders (cost=11821.90..273702.94 rows=557269 width=8) (actual time=422.358..7134.711 rows=554213 loops=1) Recheck Cond: ((o_orderdate >= '1994-02-01'::date) AND (o_orderdate < '1994-05-01'::date)) Buffers: shared hit=21879 read=205697 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..11682.59 rows=557269 width=0) (actual time=287.730..287.730 rows=554821 loops=1) Index Cond: ((o_orderdate >= '1994-02-01'::date) AND (o_orderdate < '1994-05-01'::date)) Buffers: shared hit=2 read=1516 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..685569.47 rows=14831634 width=12) (actual time=0.096..15135.224 rows=14808303 loops=1) Buffers: shared hit=1091129 read=53770 dirtied=114 written=2143 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=3990.210..3990.210 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=35231 read=47 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=146) (actual time=0.016..1011.247 rows=1500000 loops=1) Buffers: shared hit=35231 read=47 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.021..0.021 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.010..0.014 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 40561.403 ms (40 rows) COMMIT; COMMIT