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=10330991.04..10330993.79 rows=100 width=39) (actual time=151931.125..151931.824 rows=99 loops=1) Buffers: shared hit=1307770 read=1116389 written=9 -> GroupAggregate (cost=10330991.04..11157445.52 rows=30052890 width=39) (actual time=151931.121..151931.809 rows=99 loops=1) Buffers: shared hit=1307770 read=1116389 written=9 -> Sort (cost=10330991.04..10406123.27 rows=30052890 width=39) (actual time=151931.083..151931.224 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=1307770 read=1116389 written=9 -> Hash Join (cost=3056055.31..5776510.28 rows=30052890 width=39) (actual time=111990.042..151926.002 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1307756 read=1116389 written=9 -> Seq Scan on lineitem (cost=0.00..1668603.81 rows=60105781 width=8) (actual time=0.038..24660.003 rows=60045603 loops=1) Buffers: shared hit=594116 read=473430 -> Hash (cost=2962118.01..2962118.01 rows=7514984 width=39) (actual time=111978.886..111978.886 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=713640 read=642959 written=9 -> Hash Join (cost=2179489.42..2962118.01 rows=7514984 width=39) (actual time=100908.644..111977.762 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=713640 read=642959 written=9 -> Hash Join (cost=2110461.42..2742790.33 rows=7514984 width=20) (actual time=99143.701..110205.409 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=678452 read=642869 written=9 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=16) (actual time=0.008..5652.145 rows=15015000 loops=1) Buffers: shared hit=243186 read=10589 -> Hash (cost=2059986.88..2059986.88 rows=4037963 width=4) (actual time=98974.599..98974.599 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=435266 read=632280 written=9 -> HashAggregate (cost=1969132.72..2019607.25 rows=4037963 width=8) (actual time=88721.297..98973.410 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=435266 read=632280 written=9 -> Seq Scan on lineitem (cost=0.00..1668603.81 rows=60105781 width=8) (actual time=0.020..23504.619 rows=60045603 loops=1) Buffers: shared hit=435266 read=632280 written=9 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1762.907..1762.907 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35188 read=90 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.010..786.588 rows=1500000 loops=1) Buffers: shared hit=35188 read=90 Total runtime: 152312.051 ms (39 rows) COMMIT; COMMIT