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-03-01' and o_orderdate < cast(date '1993-03-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=1195394.65..1195394.70 rows=20 width=175) (actual time=31636.424..31636.430 rows=20 loops=1) Buffers: shared hit=1232556 read=198272 dirtied=112 written=6663 -> Sort (cost=1195394.65..1196841.94 rows=578915 width=175) (actual time=31636.418..31636.421 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=1232556 read=198272 dirtied=112 written=6663 -> HashAggregate (cost=1174200.78..1179989.93 rows=578915 width=175) (actual time=31031.487..31436.433 rows=381988 loops=1) Buffers: shared hit=1232553 read=198272 dirtied=112 written=6663 -> Hash Join (cost=402126.18..1159727.91 rows=578915 width=175) (actual time=5465.309..27292.876 rows=1148397 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=1232553 read=198272 dirtied=112 written=6663 -> Hash Join (cost=402124.62..1151766.26 rows=578915 width=153) (actual time=5465.252..26555.195 rows=1148397 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1232552 read=198272 dirtied=112 written=6663 -> Merge Join (cost=333096.62..1071159.96 rows=578915 width=12) (actual time=2823.347..21708.766 rows=1148397 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=1232549 read=162997 dirtied=112 written=6663 -> Sort (cost=333096.62..334559.71 rows=585234 width=8) (actual time=2823.131..3011.992 rows=573516 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 51460kB Buffers: shared hit=228946 read=2777 -> Bitmap Heap Scan on orders (cost=12708.63..277035.14 rows=585234 width=8) (actual time=426.804..2534.345 rows=573516 loops=1) Recheck Cond: ((o_orderdate >= '1993-03-01'::date) AND (o_orderdate < '1993-06-01'::date)) Buffers: shared hit=228946 read=2777 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12562.32 rows=585234 width=0) (actual time=342.353..342.353 rows=579094 loops=1) Index Cond: ((o_orderdate >= '1993-03-01'::date) AND (o_orderdate < '1993-06-01'::date)) Buffers: shared hit=103 read=1555 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..691921.34 rows=14971568 width=12) (actual time=0.122..15415.865 rows=14807952 loops=1) Buffers: shared hit=1003603 read=160220 dirtied=112 written=6663 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=2639.546..2639.546 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=3 read=35275 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.043..1317.547 rows=1500000 loops=1) Buffers: shared hit=3 read=35275 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.030..0.030 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.009..0.015 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 31684.851 ms (40 rows) COMMIT; COMMIT