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) > 313 ) 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=10215100.49..10215103.24 rows=100 width=39) (actual time=86794.346..86794.643 rows=99 loops=1) Buffers: shared hit=1457943 read=978100 written=547 -> GroupAggregate (cost=10215100.49..11045670.62 rows=30202550 width=39) (actual time=86794.342..86794.630 rows=99 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1457943 read=978100 written=547 -> Sort (cost=10215100.49..10290606.87 rows=30202550 width=39) (actual time=86794.294..86794.327 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1457943 read=978100 written=547 -> Hash Join (cost=2902861.23..5636857.46 rows=30202550 width=39) (actual time=66227.120..86792.815 rows=693 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1457931 read=978100 written=547 -> Seq Scan on lineitem (cost=0.00..1676906.99 rows=60405099 width=8) (actual time=0.030..11350.665 rows=59984909 loops=1) Buffers: shared hit=568124 read=504732 written=7 -> Hash (cost=2808455.30..2808455.30 rows=7552474 width=39) (actual time=66026.906..66026.906 rows=99 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=889807 read=473368 written=540 -> Hash Join (cost=2191440.01..2808455.30 rows=7552474 width=39) (actual time=57077.082..66025.297 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=889807 read=473368 written=540 -> Hash Join (cost=2122412.01..2626140.19 rows=7552474 width=20) (actual time=55916.356..64860.546 rows=99 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=880190 read=447707 written=540 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=16) (actual time=0.008..3157.504 rows=15000000 loops=1) Buffers: shared hit=217663 read=37378 written=532 -> Hash (cost=2071169.32..2071169.32 rows=4099415 width=4) (actual time=55752.636..55752.636 rows=99 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=662527 read=410329 written=8 -> HashAggregate (cost=1978932.49..2030175.17 rows=4099415 width=8) (actual time=47744.613..55750.204 rows=99 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 14999901 Buffers: shared hit=662527 read=410329 written=8 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1676906.99 rows=60405099 width=8) (actual time=0.017..13355.758 rows=59984909 loops=1) Buffers: shared hit=662527 read=410329 written=8 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1144.761..1144.761 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=9617 read=25661 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.026..673.033 rows=1500000 loops=1) Buffers: shared hit=9617 read=25661 Planning time: 4.366 ms Execution time: 87068.563 ms (42 rows) COMMIT; COMMIT