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=10433734.66..10433737.41 rows=100 width=39) (actual time=137401.224..137401.830 rows=100 loops=1) Buffers: shared hit=1511844 read=936149 dirtied=979 written=798 -> GroupAggregate (cost=10433734.66..11268434.74 rows=30352730 width=39) (actual time=137401.220..137401.812 rows=100 loops=1) Buffers: shared hit=1511844 read=936149 dirtied=979 written=798 -> Sort (cost=10433734.66..10509616.49 rows=30352730 width=39) (actual time=137401.189..137401.306 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: 86kB Buffers: shared hit=1511844 read=936149 dirtied=979 written=798 -> Hash Join (cost=3084044.44..5831641.63 rows=30352730 width=39) (actual time=95942.420..137395.564 rows=791 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1511830 read=936149 dirtied=979 written=798 -> Seq Scan on lineitem (cost=0.00..1685251.61 rows=60705461 width=8) (actual time=0.030..26211.381 rows=59984852 loops=1) Buffers: shared hit=555255 read=522942 dirtied=979 written=787 -> Hash (cost=2989169.89..2989169.89 rows=7589964 width=39) (actual time=95813.496..95813.496 rows=113 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=956575 read=413207 written=11 -> Hash Join (cost=2199135.62..2989169.89 rows=7589964 width=39) (actual time=84726.143..95812.762 rows=113 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=956575 read=413207 written=11 -> Hash Join (cost=2130107.62..2768342.61 rows=7589964 width=20) (actual time=82544.983..93629.383 rows=113 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=953571 read=380933 written=11 -> Seq Scan on orders (cost=0.00..408106.27 rows=15179927 width=16) (actual time=0.025..5181.427 rows=15000000 loops=1) Buffers: shared hit=254847 read=1460 -> Hash (cost=2079633.08..2079633.08 rows=4037963 width=4) (actual time=82445.280..82445.280 rows=113 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=698724 read=379473 written=11 -> HashAggregate (cost=1988778.92..2039253.45 rows=4037963 width=8) (actual time=73011.341..82444.593 rows=113 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 14999887 Buffers: shared hit=698724 read=379473 written=11 -> Seq Scan on lineitem (cost=0.00..1685251.61 rows=60705461 width=8) (actual time=0.029..24477.186 rows=59984852 loops=1) Buffers: shared hit=698724 read=379473 written=11 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2179.456..2179.456 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=3004 read=32274 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.011..1365.797 rows=1500000 loops=1) Buffers: shared hit=3004 read=32274 Total runtime: 137611.446 ms (39 rows) COMMIT; COMMIT