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-06-01' and o_orderdate < cast(date '1993-06-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=1153492.79..1153492.84 rows=20 width=175) (actual time=28803.218..28803.225 rows=20 loops=1) Buffers: shared hit=885908 read=536338 dirtied=1700 written=9146 -> Sort (cost=1153492.79..1154903.56 rows=564308 width=175) (actual time=28803.214..28803.215 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=885908 read=536338 dirtied=1700 written=9146 -> HashAggregate (cost=1132833.68..1138476.76 rows=564308 width=175) (actual time=28245.505..28641.891 rows=381255 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=885905 read=536338 dirtied=1700 written=9146 -> Hash Join (cost=352126.51..1118725.98 rows=564308 width=175) (actual time=4816.323..25880.242 rows=1146483 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=885905 read=536338 dirtied=1700 written=9146 -> Hash Join (cost=352124.95..1110965.18 rows=564308 width=153) (actual time=4816.266..25448.193 rows=1146483 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=885904 read=536338 dirtied=1700 written=9146 -> Hash Join (cost=283096.95..1033472.56 rows=564308 width=12) (actual time=2555.223..22011.106 rows=1146483 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=885902 read=501062 dirtied=1700 written=9128 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..688866.87 rows=14897625 width=12) (actual time=0.083..14297.683 rows=14808293 loops=1) Buffers: shared hit=716135 read=439648 dirtied=1700 written=9073 -> Hash (cost=275944.50..275944.50 rows=572161 width=8) (actual time=2549.492..2549.492 rows=573702 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30603kB Buffers: shared hit=169767 read=61414 written=55 -> Bitmap Heap Scan on orders (cost=12321.09..275944.50 rows=572161 width=8) (actual time=302.672..2301.205 rows=573702 loops=1) Recheck Cond: ((o_orderdate >= '1993-06-01'::date) AND (o_orderdate < '1993-09-01'::date)) Heap Blocks: exact=229558 Buffers: shared hit=169767 read=61414 written=55 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12178.05 rows=572161 width=0) (actual time=216.695..216.695 rows=577673 loops=1) Index Cond: ((o_orderdate >= '1993-06-01'::date) AND (o_orderdate < '1993-09-01'::date)) Buffers: shared hit=551 read=1072 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=2247.084..2247.084 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=2 read=35276 written=18 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.020..1117.339 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=18 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.031..0.031 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.009..0.014 rows=25 loops=1) Buffers: shared hit=1 Planning time: 7.218 ms Execution time: 28831.370 ms (42 rows) COMMIT; COMMIT