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=10462345.72..10462348.47 rows=100 width=39) (actual time=127803.616..127803.905 rows=100 loops=1) Buffers: shared hit=1730195 read=724927 dirtied=49 written=3181 -> GroupAggregate (cost=10462345.72..11299510.40 rows=30442352 width=39) (actual time=127803.613..127803.895 rows=100 loops=1) Buffers: shared hit=1730195 read=724927 dirtied=49 written=3181 -> Sort (cost=10462345.72..10538451.60 rows=30442352 width=39) (actual time=127803.595..127803.630 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=1730195 read=724927 dirtied=49 written=3181 -> Hash Join (cost=3090305.95..5846017.33 rows=30442352 width=39) (actual time=107674.013..127799.769 rows=791 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1730181 read=724927 dirtied=49 written=3181 -> Seq Scan on lineitem (cost=0.00..1690229.04 rows=60884704 width=8) (actual time=0.091..11182.553 rows=60044793 loops=1) Buffers: shared hit=743854 read=337528 dirtied=1 -> Hash (cost=2995150.45..2995150.45 rows=7612440 width=39) (actual time=107440.453..107440.453 rows=113 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 8kB Buffers: shared hit=986327 read=387399 dirtied=48 written=3181 -> Hash Join (cost=2203365.81..2995150.45 rows=7612440 width=39) (actual time=98628.600..107439.823 rows=113 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=986327 read=387399 dirtied=48 written=3181 -> Hash Join (cost=2134337.81..2773873.65 rows=7612440 width=20) (actual time=96380.756..105189.974 rows=113 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=951049 read=387399 dirtied=48 written=3181 -> Seq Scan on orders (cost=0.00..409314.79 rows=15224879 width=16) (actual time=0.019..3841.361 rows=15015000 loops=1) Buffers: shared hit=168978 read=88088 dirtied=48 written=3181 -> Hash (cost=2084450.22..2084450.22 rows=3991007 width=4) (actual time=96258.228..96258.228 rows=113 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=782071 read=299311 -> HashAggregate (cost=1994652.56..2044540.15 rows=3991007 width=8) (actual time=88229.185..96257.037 rows=113 loops=1) Filter: (sum(public.lineitem.l_quantity) > 312::double precision) Rows Removed by Filter: 15014887 Buffers: shared hit=782071 read=299311 -> Seq Scan on lineitem (cost=0.00..1690229.04 rows=60884704 width=8) (actual time=0.019..36729.850 rows=60044793 loops=1) Buffers: shared hit=782071 read=299311 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=2245.439..2245.439 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.026..1443.567 rows=1500000 loops=1) Buffers: shared hit=35278 Total runtime: 127983.112 ms (39 rows) COMMIT; COMMIT