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=10353937.73..10353940.48 rows=100 width=39) (actual time=114251.399..114251.642 rows=75 loops=1) Buffers: shared hit=1556828 read=872077 dirtied=1058 written=60 -> GroupAggregate (cost=10353937.73..11182028.13 rows=30112378 width=39) (actual time=114251.395..114251.631 rows=75 loops=1) Buffers: shared hit=1556828 read=872077 dirtied=1058 written=60 -> Sort (cost=10353937.73..10429218.68 rows=30112378 width=39) (actual time=114251.375..114251.399 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=1556828 read=872077 dirtied=1058 written=60 -> Hash Join (cost=3064167.91..5790014.72 rows=30112378 width=39) (actual time=85101.078..114248.666 rows=525 loops=1) Hash Cond: (public.lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1556814 read=872077 dirtied=1058 written=60 -> Seq Scan on lineitem (cost=0.00..1671913.57 rows=60224757 width=8) (actual time=0.055..16336.353 rows=60045303 loops=1) Buffers: shared hit=614010 read=455656 -> Hash (cost=2970043.31..2970043.31 rows=7529968 width=39) (actual time=84334.256..84334.256 rows=75 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 6kB Buffers: shared hit=942804 read=416421 dirtied=1058 written=60 -> Hash Join (cost=2185370.16..2970043.31 rows=7529968 width=39) (actual time=74711.543..84333.609 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=942804 read=416421 dirtied=1058 written=60 -> Hash Join (cost=2116342.16..2750415.95 rows=7529968 width=20) (actual time=73245.729..82865.059 rows=75 loops=1) Hash Cond: (orders.o_orderkey = public.lineitem.l_orderkey) Buffers: shared hit=907535 read=416412 dirtied=1058 written=60 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.007..4732.608 rows=15015000 loops=1) Buffers: shared hit=230846 read=23435 written=46 -> Hash (cost=2065161.87..2065161.87 rows=4094423 width=4) (actual time=73042.208..73042.208 rows=75 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 3kB Buffers: shared hit=676689 read=392977 dirtied=1058 written=14 -> HashAggregate (cost=1973037.36..2024217.64 rows=4094423 width=8) (actual time=64315.906..73041.541 rows=75 loops=1) Filter: (sum(public.lineitem.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=676689 read=392977 dirtied=1058 written=14 -> Seq Scan on lineitem (cost=0.00..1671913.57 rows=60224757 width=8) (actual time=0.016..19269.966 rows=60045303 loops=1) Buffers: shared hit=676689 read=392977 dirtied=1058 written=14 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1464.114..1464.114 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 82032kB Buffers: shared hit=35269 read=9 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.013..748.220 rows=1500000 loops=1) Buffers: shared hit=35269 read=9 Total runtime: 114471.805 ms (39 rows) COMMIT; COMMIT