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) > 315 ) 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=10212543.95..10212546.70 rows=100 width=39) (actual time=88809.530..88809.761 rows=75 loops=1) Buffers: shared hit=1465209 read=970886 written=394 -> GroupAggregate (cost=10212543.95..11043126.51 rows=30203002 width=39) (actual time=88809.526..88809.749 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1465209 read=970886 written=394 -> Sort (cost=10212543.95..10288051.46 rows=30203002 width=39) (actual time=88809.509..88809.540 rows=525 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 66kB Buffers: shared hit=1465209 read=970886 written=394 -> Hash Join (cost=2900183.92..5634231.00 rows=30203002 width=39) (actual time=66889.525..88808.303 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1465197 read=970886 written=394 -> Seq Scan on lineitem (cost=0.00..1676942.03 rows=60406003 width=8) (actual time=0.055..11832.678 rows=59984909 loops=1) Buffers: shared hit=564804 read=508078 -> Hash (cost=2805777.99..2805777.99 rows=7552474 width=39) (actual time=66412.104..66412.104 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=900393 read=462808 written=394 -> Hash Join (cost=2189366.45..2805777.99 rows=7552474 width=39) (actual time=57478.804..66411.541 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=900393 read=462808 written=394 -> Hash Join (cost=2120338.45..2623462.88 rows=7552474 width=20) (actual time=56418.798..65309.443 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=865115 read=462808 written=394 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=16) (actual time=0.006..3310.602 rows=15000000 loops=1) Buffers: shared hit=176963 read=78078 written=391 -> Hash (cost=2069850.45..2069850.45 rows=4039040 width=4) (actual time=56245.774..56245.774 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=688152 read=384730 written=3 -> HashAggregate (cost=1978972.05..2029460.05 rows=4039040 width=8) (actual time=47558.377..56242.214 rows=75 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 315::double precision) Rows Removed by Filter: 14999925 Buffers: shared hit=688152 read=384730 written=3 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1676942.03 rows=60406003 width=8) (actual time=0.013..13094.170 rows=59984909 loops=1) Buffers: shared hit=688152 read=384730 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1047.820..1047.820 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.018..571.889 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 4.094 ms Execution time: 89074.504 ms (42 rows) COMMIT; COMMIT