BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) from customer, orders, lineitem where o_orderkey in ( select l_orderkey from lineitem group by l_orderkey having sum(l_quantity) > 312 ) and c_custkey = o_custkey and o_orderkey = l_orderkey group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice order by o_totalprice desc, o_orderdate LIMIT 100; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=10262902.91..10262905.66 rows=100 width=39) (actual time=88505.156..88505.442 rows=100 loops=1) Buffers: shared hit=1656024 read=791949 dirtied=800 written=783 -> GroupAggregate (cost=10262902.91..11097593.14 rows=30352372 width=39) (actual time=88505.152..88505.426 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1656024 read=791949 dirtied=800 written=783 -> Sort (cost=10262902.91..10338783.84 rows=30352372 width=39) (actual time=88505.134..88505.167 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 86kB Buffers: shared hit=1656024 read=791949 dirtied=800 written=783 -> Hash Join (cost=2913298.97..5660867.45 rows=30352372 width=39) (actual time=65084.106..88503.433 rows=791 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1656012 read=791949 dirtied=800 written=783 -> Seq Scan on lineitem (cost=0.00..1685235.44 rows=60704744 width=8) (actual time=0.026..12328.690 rows=60044994 loops=1) Buffers: shared hit=891878 read=186310 written=3 -> Hash (cost=2818424.42..2818424.42 rows=7589964 width=39) (actual time=64423.989..64423.989 rows=113 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=764134 read=605639 dirtied=800 written=780 -> Hash Join (cost=2199153.56..2818424.42 rows=7589964 width=39) (actual time=56668.641..64421.601 rows=113 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=764134 read=605639 dirtied=800 written=780 -> Hash Join (cost=2130125.56..2635546.96 rows=7589964 width=20) (actual time=55661.538..63407.387 rows=113 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=728856 read=605639 dirtied=800 written=780 -> Seq Scan on orders (cost=0.00..408106.27 rows=15179927 width=16) (actual time=0.008..3693.961 rows=15015000 loops=1) Buffers: shared hit=164507 read=91800 written=26 -> Hash (cost=2079637.56..2079637.56 rows=4039040 width=4) (actual time=55529.119..55529.119 rows=113 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=564349 read=513839 dirtied=800 written=754 -> HashAggregate (cost=1988759.16..2039247.16 rows=4039040 width=8) (actual time=41920.077..55528.311 rows=113 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 15014887 Buffers: shared hit=564349 read=513839 dirtied=800 written=754 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1685235.44 rows=60704744 width=8) (actual time=0.012..12285.431 rows=60044994 loops=1) Buffers: shared hit=564349 read=513839 dirtied=800 written=754 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=991.934..991.934 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.016..520.530 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 4.086 ms Execution time: 88752.561 ms (42 rows) COMMIT; COMMIT