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=10374500.96..10374503.71 rows=100 width=39) (actual time=121461.466..121461.794 rows=99 loops=1) Buffers: shared hit=1545627 read=888048 written=1 -> GroupAggregate (cost=10374500.96..11204241.88 rows=30172397 width=39) (actual time=121461.463..121461.782 rows=99 loops=1) Buffers: shared hit=1545627 read=888048 written=1 -> Sort (cost=10374500.96..10449931.95 rows=30172397 width=39) (actual time=121461.442..121461.476 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=1545627 read=888048 written=1 -> Hash Join (cost=3069767.73..5801047.56 rows=30172397 width=39) (actual time=88796.083..121458.142 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1545613 read=888048 written=1 -> Seq Scan on lineitem (cost=0.00..1675245.94 rows=60344794 width=8) (actual time=0.079..18874.805 rows=60045826 loops=1) Buffers: shared hit=755681 read=316117 -> Hash (cost=2975455.83..2975455.83 rows=7544952 width=39) (actual time=88777.756..88777.756 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=789932 read=571931 written=1 -> Hash Join (cost=2189302.72..2975455.83 rows=7544952 width=39) (actual time=79699.193..88777.235 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=789932 read=571931 written=1 -> Hash Join (cost=2120274.72..2755528.79 rows=7544952 width=20) (actual time=78259.868..87335.791 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=754654 read=571931 written=1 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=16) (actual time=0.020..4228.812 rows=15015000 loops=1) Buffers: shared hit=254787 -> Hash (cost=2069094.43..2069094.43 rows=4094423 width=4) (actual time=78112.629..78112.629 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=499867 read=571931 written=1 -> HashAggregate (cost=1976969.91..2028150.20 rows=4094423 width=8) (actual time=68776.677..78111.942 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=499867 read=571931 written=1 -> Seq Scan on lineitem (cost=0.00..1675245.94 rows=60344794 width=8) (actual time=0.035..19088.354 rows=60045826 loops=1) Buffers: shared hit=499867 read=571931 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1437.697..1437.697 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.015..778.876 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 121685.773 ms (39 rows) COMMIT; COMMIT