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=10353502.24..10353504.99 rows=100 width=39) (actual time=112501.686..112502.123 rows=99 loops=1) Buffers: shared hit=1029529 read=1399376 dirtied=1065 written=905 -> GroupAggregate (cost=10353502.24..11181593.84 rows=30112422 width=39) (actual time=112501.682..112502.106 rows=99 loops=1) Buffers: shared hit=1029529 read=1399376 dirtied=1065 written=905 -> Sort (cost=10353502.24..10428783.29 rows=30112422 width=39) (actual time=112501.658..112501.730 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=1029529 read=1399376 dirtied=1065 written=905 -> Hash Join (cost=3063720.72..5789569.95 rows=30112422 width=39) (actual time=87657.478..112498.138 rows=693 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1029515 read=1399376 dirtied=1065 written=905 -> Seq Scan on lineitem (cost=0.00..1671914.45 rows=60224845 width=8) (actual time=0.049..13491.378 rows=60045303 loops=1) Buffers: shared hit=359437 read=710229 dirtied=1065 written=900 -> Hash (cost=2969596.12..2969596.12 rows=7529968 width=39) (actual time=87312.814..87312.814 rows=99 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 7kB Buffers: shared hit=670078 read=689147 written=5 -> Hash Join (cost=2185022.64..2969596.12 rows=7529968 width=39) (actual time=76421.743..87311.992 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=670078 read=689147 written=5 -> Hash Join (cost=2115994.64..2749968.76 rows=7529968 width=20) (actual time=74770.049..85656.196 rows=99 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=636578 read=687369 written=5 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.015..5230.692 rows=15015000 loops=1) Buffers: shared hit=206935 read=47346 written=5 -> Hash (cost=2064938.94..2064938.94 rows=4084456 width=4) (actual time=74587.301..74587.301 rows=99 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 4kB Buffers: shared hit=429643 read=640023 -> HashAggregate (cost=1973038.68..2024094.38 rows=4084456 width=8) (actual time=65637.882..74586.402 rows=99 loops=1) Filter: (sum(public.lineitem.l_quantity) > 313::double precision) Rows Removed by Filter: 15014901 Buffers: shared hit=429643 read=640023 -> Seq Scan on lineitem (cost=0.00..1671914.45 rows=60224845 width=8) (actual time=0.021..17922.174 rows=60045303 loops=1) Buffers: shared hit=429643 read=640023 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1650.220..1650.220 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=33500 read=1778 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.012..635.097 rows=1500000 loops=1) Buffers: shared hit=33500 read=1778 Total runtime: 112859.223 ms (39 rows) COMMIT; COMMIT