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=10243159.14..10243161.89 rows=100 width=39) (actual time=71762.059..71762.404 rows=100 loops=1) Buffers: shared hit=1170123 read=1273056 dirtied=853 written=1004 -> GroupAggregate (cost=10243159.14..11076196.40 rows=30292264 width=39) (actual time=71762.057..71762.394 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1170123 read=1273056 dirtied=853 written=1004 -> Sort (cost=10243159.14..10318889.80 rows=30292264 width=39) (actual time=71762.047..71762.091 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=1170123 read=1273056 dirtied=853 written=1004 -> Hash Join (cost=2908549.82..5650668.36 rows=30292264 width=39) (actual time=52841.880..71761.035 rows=784 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1170111 read=1273056 dirtied=853 written=1004 -> Seq Scan on lineitem (cost=0.00..1681889.28 rows=60584528 width=8) (actual time=0.036..9485.849 rows=60044176 loops=1) Buffers: shared hit=384081 read=691963 dirtied=853 written=755 -> Hash (cost=2813862.57..2813862.57 rows=7574980 width=39) (actual time=52376.649..52376.649 rows=112 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=786030 read=581093 written=249 -> Hash Join (cost=2195617.15..2813862.57 rows=7574980 width=39) (actual time=45456.313..52376.432 rows=112 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=786030 read=581093 written=249 -> Hash Join (cost=2126589.15..2631209.87 rows=7574980 width=20) (actual time=44243.408..51163.193 rows=112 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=786028 read=545817 written=232 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=16) (actual time=0.005..3410.042 rows=15015000 loops=1) Buffers: shared hit=84800 read=171001 written=231 -> Hash (cost=2075954.43..2075954.43 rows=4050778 width=4) (actual time=44118.603..44118.603 rows=112 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=701228 read=374816 written=1 -> HashAggregate (cost=1984811.92..2035446.65 rows=4050778 width=8) (actual time=38495.066..44118.373 rows=112 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 15014888 Buffers: shared hit=701228 read=374816 written=1 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1681889.28 rows=60584528 width=8) (actual time=0.005..8993.237 rows=60044176 loops=1) Buffers: shared hit=701228 read=374816 written=1 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1203.968..1203.968 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 written=17 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.008..693.845 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=17 Planning time: 4.453 ms Execution time: 71877.781 ms (42 rows) COMMIT; COMMIT