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) > 315 ) 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=10351445.77..10351448.52 rows=100 width=39) (actual time=152709.839..152710.193 rows=75 loops=1) Buffers: shared hit=1039958 read=1388947 written=40 -> GroupAggregate (cost=10351445.77..11179541.47 rows=30112571 width=39) (actual time=152709.836..152710.186 rows=75 loops=1) Buffers: shared hit=1039958 read=1388947 written=40 -> Sort (cost=10351445.77..10426727.19 rows=30112571 width=39) (actual time=152709.812..152709.863 rows=525 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 66kB Buffers: shared hit=1039958 read=1388947 written=40 -> Hash Join (cost=3061632.98..5787490.39 rows=30112571 width=39) (actual time=110619.901..152706.116 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1039944 read=1388947 written=40 -> Seq Scan on lineitem (cost=0.00..1671917.42 rows=60225142 width=8) (actual time=0.039..25952.158 rows=60045303 loops=1) Buffers: shared hit=232078 read=837588 -> Hash (cost=2967508.38..2967508.38 rows=7529968 width=39) (actual time=110580.331..110580.331 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=807866 read=551359 written=40 -> Hash Join (cost=2183399.83..2967508.38 rows=7529968 width=39) (actual time=100995.801..110579.372 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=807866 read=551359 written=40 -> Hash Join (cost=2114371.83..2747881.02 rows=7529968 width=20) (actual time=98796.554..108376.262 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=773255 read=550692 written=40 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.022..4890.672 rows=15015000 loops=1) Buffers: shared hit=254281 -> Hash (cost=2063897.30..2063897.30 rows=4037963 width=4) (actual time=98677.303..98677.303 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=518974 read=550692 written=40 -> HashAggregate (cost=1973043.13..2023517.67 rows=4037963 width=8) (actual time=89471.430..98676.338 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=518974 read=550692 written=40 -> Seq Scan on lineitem (cost=0.00..1671917.42 rows=60225142 width=8) (actual time=0.048..32939.106 rows=60045303 loops=1) Buffers: shared hit=518974 read=550692 written=40 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2197.282..2197.282 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=34611 read=667 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.018..1308.414 rows=1500000 loops=1) Buffers: shared hit=34611 read=667 Total runtime: 153069.210 ms (39 rows) COMMIT; COMMIT