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=10190373.87..10190376.62 rows=100 width=39) (actual time=85794.559..85794.791 rows=75 loops=1) Buffers: shared hit=1472243 read=958180 dirtied=391 written=4466 -> GroupAggregate (cost=10190373.87..11019062.25 rows=30134123 width=39) (actual time=85794.556..85794.779 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1472243 read=958180 dirtied=391 written=4466 -> Sort (cost=10190373.87..10265709.18 rows=30134123 width=39) (actual time=85794.529..85794.559 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=1472243 read=958180 dirtied=391 written=4466 -> Hash Join (cost=2895195.04..5622997.80 rows=30134123 width=39) (actual time=61133.854..85793.263 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1472231 read=958180 dirtied=391 written=4466 -> Seq Scan on lineitem (cost=0.00..1673108.46 rows=60268246 width=8) (actual time=0.036..12549.066 rows=59985781 loops=1) Buffers: shared hit=648740 read=421686 -> Hash (cost=2801070.44..2801070.44 rows=7529968 width=39) (actual time=61066.179..61066.179 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=823491 read=536494 dirtied=391 written=4466 -> Hash Join (cost=2186035.10..2801070.44 rows=7529968 width=39) (actual time=51594.775..61065.821 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=823491 read=536494 dirtied=391 written=4466 -> Hash Join (cost=2117007.10..2619092.92 rows=7529968 width=20) (actual time=50432.826..59897.927 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=799072 read=525635 dirtied=391 written=3978 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.010..3886.918 rows=15000000 loops=1) Buffers: shared hit=176460 read=77821 written=3628 -> Hash (cost=2066093.74..2066093.74 rows=4073069 width=4) (actual time=50235.015..50235.015 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=622612 read=447814 dirtied=391 written=350 -> HashAggregate (cost=1974449.69..2025363.05 rows=4073069 width=8) (actual time=43328.692..50234.561 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=622612 read=447814 dirtied=391 written=350 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1673108.46 rows=60268246 width=8) (actual time=0.010..13108.979 rows=59985781 loops=1) Buffers: shared hit=622612 read=447814 dirtied=391 written=350 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1147.018..1147.018 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=24419 read=10859 written=488 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.014..632.017 rows=1500000 loops=1) Buffers: shared hit=24419 read=10859 written=488 Planning time: 4.699 ms Execution time: 86170.793 ms (42 rows) COMMIT; COMMIT