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=10363231.05..10363233.80 rows=100 width=39) (actual time=127014.540..127015.066 rows=99 loops=1) Buffers: shared hit=1624886 read=806420 dirtied=406 written=2 -> GroupAggregate (cost=10363231.05..11192157.66 rows=30142786 width=39) (actual time=127014.537..127015.046 rows=99 loops=1) Buffers: shared hit=1624886 read=806420 dirtied=406 written=2 -> Sort (cost=10363231.05..10438588.01 rows=30142786 width=39) (actual time=127014.513..127014.593 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=1624886 read=806420 dirtied=406 written=2 -> Hash Join (cost=3065885.11..5794478.32 rows=30142786 width=39) (actual time=97202.085..127009.648 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1624872 read=806420 dirtied=406 written=2 -> Seq Scan on lineitem (cost=0.00..1673595.71 rows=60285571 width=8) (actual time=0.024..16932.178 rows=59986308 loops=1) Buffers: shared hit=651444 read=419296 -> Hash (cost=2971666.86..2971666.86 rows=7537460 width=39) (actual time=97025.607..97025.607 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=973428 read=387124 dirtied=406 written=2 -> Hash Join (cost=2186498.76..2971666.86 rows=7537460 width=39) (actual time=86648.293..97025.015 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=973428 read=387124 dirtied=406 written=2 -> Hash Join (cost=2117470.76..2751889.66 rows=7537460 width=20) (actual time=85165.395..95528.240 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=938150 read=387124 dirtied=406 written=2 -> Seq Scan on orders (cost=0.00..405283.20 rows=15074920 width=16) (actual time=0.016..4901.675 rows=15000000 loops=1) Buffers: shared hit=253004 read=1530 written=2 -> Hash (cost=2066596.76..2066596.76 rows=4069920 width=4) (actual time=84964.814..84964.814 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=685146 read=385594 dirtied=406 -> HashAggregate (cost=1975023.56..2025897.56 rows=4069920 width=8) (actual time=76058.781..84963.982 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 14999901 Buffers: shared hit=685146 read=385594 dirtied=406 -> Seq Scan on lineitem (cost=0.00..1673595.71 rows=60285571 width=8) (actual time=0.031..23607.573 rows=59986308 loops=1) Buffers: shared hit=685146 read=385594 dirtied=406 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1481.274..1481.274 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.009..747.997 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 127271.539 ms (39 rows) COMMIT; COMMIT