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=10413001.18..10413003.93 rows=100 width=39) (actual time=144074.098..144074.534 rows=75 loops=1) Buffers: shared hit=1707326 read=735859 written=2 -> GroupAggregate (cost=10413001.18..11246036.04 rows=30292177 width=39) (actual time=144074.093..144074.514 rows=75 loops=1) Buffers: shared hit=1707326 read=735859 written=2 -> Sort (cost=10413001.18..10488731.62 rows=30292177 width=39) (actual time=144074.072..144074.148 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=1707326 read=735859 written=2 -> Hash Join (cost=3078409.57..5820525.33 rows=30292177 width=39) (actual time=97411.727..144070.107 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1707312 read=735859 written=2 -> Seq Scan on lineitem (cost=0.00..1681889.54 rows=60584354 width=8) (actual time=0.064..31881.418 rows=59984384 loops=1) Buffers: shared hit=387525 read=688521 written=2 -> Hash (cost=2983722.32..2983722.32 rows=7574980 width=39) (actual time=96344.790..96344.790 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=1319787 read=47338 -> Hash Join (cost=2195168.01..2983722.32 rows=7574980 width=39) (actual time=83692.649..96341.737 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1319787 read=47338 -> Hash Join (cost=2126140.01..2763194.72 rows=7574980 width=20) (actual time=82083.248..94729.852 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1289251 read=42596 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=16) (actual time=0.016..6078.263 rows=15000000 loops=1) Buffers: shared hit=255801 -> Hash (cost=2075665.48..2075665.48 rows=4037963 width=4) (actual time=81943.546..81943.546 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=1033450 read=42596 -> HashAggregate (cost=1984811.31..2035285.85 rows=4037963 width=8) (actual time=72804.891..81942.946 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 14999925 Buffers: shared hit=1033450 read=42596 -> Seq Scan on lineitem (cost=0.00..1681889.54 rows=60584354 width=8) (actual time=0.035..26012.697 rows=59984384 loops=1) Buffers: shared hit=1033450 read=42596 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1607.405..1607.405 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=30536 read=4742 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.015..957.580 rows=1500000 loops=1) Buffers: shared hit=30536 read=4742 Total runtime: 144251.181 ms (39 rows) COMMIT; COMMIT