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-03-01' and o_orderdate < cast(date '1994-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=1187081.25..1187081.30 rows=20 width=176) (actual time=42950.034..42950.041 rows=20 loops=1) Buffers: shared hit=699956 read=724312 dirtied=1306 written=135 -> Sort (cost=1187081.25..1188488.32 rows=562827 width=176) (actual time=42950.030..42950.033 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=699956 read=724312 dirtied=1306 written=135 -> HashAggregate (cost=1166476.36..1172104.63 rows=562827 width=176) (actual time=42413.734..42779.049 rows=381357 loops=1) Buffers: shared hit=699953 read=724312 dirtied=1306 written=135 -> Hash Join (cost=399040.44..1152405.68 rows=562827 width=176) (actual time=6295.580..37726.273 rows=1148648 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=699953 read=724312 dirtied=1306 written=135 -> Hash Join (cost=399038.88..1144665.25 rows=562827 width=154) (actual time=6295.540..36957.983 rows=1148648 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=699952 read=724312 dirtied=1306 written=135 -> Merge Join (cost=330010.88..1064380.71 rows=562827 width=12) (actual time=3593.583..31221.678 rows=1148648 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=665306 read=723680 dirtied=1306 written=135 -> Sort (cost=330010.86..331436.25 rows=570154 width=8) (actual time=3593.429..3799.868 rows=573629 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 51465kB Buffers: shared hit=207733 read=23348 dirtied=231 -> Bitmap Heap Scan on orders (cost=12162.00..275501.31 rows=570154 width=8) (actual time=619.842..3276.367 rows=573629 loops=1) Recheck Cond: ((o_orderdate >= '1994-03-01'::date) AND (o_orderdate < '1994-06-01'::date)) Buffers: shared hit=207733 read=23348 dirtied=231 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12019.46 rows=570154 width=0) (actual time=483.300..483.300 rows=576514 loops=1) Index Cond: ((o_orderdate >= '1994-03-01'::date) AND (o_orderdate < '1994-06-01'::date)) Buffers: shared read=1588 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..688650.82 rows=14895996 width=12) (actual time=0.110..23928.209 rows=14823256 loops=1) Buffers: shared hit=457573 read=700332 dirtied=1075 written=135 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=2700.201..2700.201 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=34646 read=632 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=146) (actual time=0.021..1154.708 rows=1500000 loops=1) Buffers: shared hit=34646 read=632 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.023..0.023 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.006..0.011 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 43037.616 ms (40 rows) COMMIT; COMMIT