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) > 312 ) 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=10384127.58..10384130.33 rows=100 width=39) (actual time=213299.575..213300.184 rows=100 loops=1) Buffers: shared hit=1559353 read=876692 written=10 -> GroupAggregate (cost=10384127.58..11214685.28 rows=30202098 width=39) (actual time=213299.571..213300.152 rows=100 loops=1) Buffers: shared hit=1559353 read=876692 written=10 -> Sort (cost=10384127.58..10459632.83 rows=30202098 width=39) (actual time=213299.544..213299.640 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 85kB Buffers: shared hit=1559353 read=876692 written=10 -> Hash Join (cost=3071986.57..5805957.96 rows=30202098 width=39) (actual time=133712.341..213294.921 rows=777 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1559339 read=876692 written=10 -> Seq Scan on lineitem (cost=0.00..1676897.96 rows=60404196 width=8) (actual time=0.057..65211.895 rows=60045310 loops=1) Buffers: shared hit=383478 read=689378 -> Hash (cost=2977580.65..2977580.65 rows=7552474 width=39) (actual time=131683.293..131683.293 rows=111 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=1175861 read=187314 written=10 -> Hash Join (cost=2190810.64..2977580.65 rows=7552474 width=39) (actual time=114249.153..131682.514 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1175861 read=187314 written=10 -> Hash Join (cost=2121782.64..2757503.17 rows=7552474 width=20) (actual time=111442.551..128873.620 rows=111 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=1140704 read=187193 written=10 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=16) (actual time=0.015..11567.980 rows=15015000 loops=1) Buffers: shared hit=244221 read=10820 written=3 -> Hash (cost=2070759.89..2070759.89 rows=4081820 width=4) (actual time=111049.224..111049.224 rows=111 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=896483 read=176373 written=7 -> HashAggregate (cost=1978918.94..2029941.69 rows=4081820 width=8) (actual time=101619.584..111048.144 rows=111 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=896483 read=176373 written=7 -> Seq Scan on lineitem (cost=0.00..1676897.96 rows=60404196 width=8) (actual time=0.850..51215.164 rows=60045310 loops=1) Buffers: shared hit=896483 read=176373 written=7 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2804.310..2804.310 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35157 read=121 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.029..1942.372 rows=1500000 loops=1) Buffers: shared hit=35157 read=121 Total runtime: 213451.185 ms (39 rows) COMMIT; COMMIT