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) > 314 ) 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=10413117.28..10413120.03 rows=100 width=39) (actual time=126472.804..126473.098 rows=85 loops=1) Buffers: shared hit=1108168 read=1335017 written=123 -> GroupAggregate (cost=10413117.28..11246159.60 rows=30292448 width=39) (actual time=126472.801..126473.086 rows=85 loops=1) Buffers: shared hit=1108168 read=1335017 written=123 -> Sort (cost=10413117.28..10488848.40 rows=30292448 width=39) (actual time=126472.784..126472.836 rows=595 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 71kB Buffers: shared hit=1108168 read=1335017 written=123 -> Hash Join (cost=3078468.18..5820598.81 rows=30292448 width=39) (actual time=89217.072..126469.661 rows=595 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1108154 read=1335017 written=123 -> Seq Scan on lineitem (cost=0.00..1681894.95 rows=60584895 width=8) (actual time=0.058..22912.079 rows=60044176 loops=1) Buffers: shared hit=297312 read=778734 written=123 -> Hash (cost=2983780.93..2983780.93 rows=7574980 width=39) (actual time=89064.120..89064.120 rows=85 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=810842 read=556283 -> Hash Join (cost=2195215.40..2983780.93 rows=7574980 width=39) (actual time=79983.902..89063.541 rows=85 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=810842 read=556283 -> Hash Join (cost=2126187.40..2763253.33 rows=7574980 width=20) (actual time=78208.302..87281.646 rows=85 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=775564 read=556283 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=16) (actual time=0.015..4321.834 rows=15015000 loops=1) Buffers: shared hit=238011 read=17790 -> Hash (cost=2075698.84..2075698.84 rows=4039085 width=4) (actual time=78061.685..78061.685 rows=85 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=537553 read=538493 -> HashAggregate (cost=1984819.43..2035307.99 rows=4039085 width=8) (actual time=69978.982..78061.027 rows=85 loops=1) Filter: (sum(public.lineitem.l_quantity) > 314::double precision) Rows Removed by Filter: 15014915 Buffers: shared hit=537553 read=538493 -> Seq Scan on lineitem (cost=0.00..1681894.95 rows=60584895 width=8) (actual time=0.056..22279.398 rows=60044176 loops=1) Buffers: shared hit=537553 read=538493 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1773.401..1773.401 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.032..946.966 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 126638.379 ms (39 rows) COMMIT; COMMIT