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-05-01' and o_orderdate < cast(date '1993-05-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=1150894.72..1150894.77 rows=20 width=176) (actual time=30375.023..30375.032 rows=20 loops=1) Buffers: shared hit=669024 read=749671 dirtied=217 written=34 -> Sort (cost=1150894.72..1152326.52 rows=572719 width=176) (actual time=30375.019..30375.023 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=669024 read=749671 dirtied=217 written=34 -> HashAggregate (cost=1129927.68..1135654.87 rows=572719 width=176) (actual time=29962.564..30232.808 rows=381659 loops=1) Group Key: customer.c_custkey, customer.c_name, customer.c_acctbal, customer.c_phone, nation.n_name, customer.c_address, customer.c_comment Buffers: shared hit=669021 read=749671 dirtied=217 written=34 -> Hash Join (cost=351611.21..1115609.71 rows=572719 width=176) (actual time=4971.772..26297.999 rows=1148505 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=669021 read=749671 dirtied=217 written=34 -> Hash Join (cost=351609.64..1107733.26 rows=572719 width=154) (actual time=4971.733..25878.294 rows=1148505 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=669020 read=749671 dirtied=217 written=34 -> Hash Join (cost=282581.64..1030114.47 rows=572719 width=12) (actual time=3257.682..22904.788 rows=1148505 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=633747 read=749666 dirtied=217 written=34 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..686174.32 rows=14835136 width=12) (actual time=0.095..13972.811 rows=14823114 loops=1) Buffers: shared hit=513387 read=639631 written=34 -> Hash (cost=275313.73..275313.73 rows=581398 width=8) (actual time=3244.333..3244.333 rows=574090 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30618kB Buffers: shared hit=120360 read=110035 dirtied=217 -> Bitmap Heap Scan on orders (cost=12311.76..275313.73 rows=581398 width=8) (actual time=562.584..2976.857 rows=574090 loops=1) Recheck Cond: ((o_orderdate >= '1993-05-01'::date) AND (o_orderdate < '1993-08-01'::date)) Heap Blocks: exact=228825 Buffers: shared hit=120360 read=110035 dirtied=217 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12166.41 rows=581398 width=0) (actual time=427.902..427.902 rows=575830 loops=1) Index Cond: ((o_orderdate >= '1993-05-01'::date) AND (o_orderdate < '1993-08-01'::date)) Buffers: shared hit=1 read=1569 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=1702.612..1702.612 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=35273 read=5 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=146) (actual time=0.017..669.245 rows=1500000 loops=1) Buffers: shared hit=35273 read=5 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.022..0.022 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 10kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.007..0.009 rows=25 loops=1) Buffers: shared hit=1 Planning time: 4.440 ms Execution time: 30406.213 ms (42 rows) COMMIT; COMMIT