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=10217775.63..10217778.38 rows=100 width=39) (actual time=103619.859..103620.169 rows=100 loops=1) Buffers: shared hit=1608836 read=828079 dirtied=1355 written=416 -> GroupAggregate (cost=10217775.63..11048682.76 rows=30214805 width=39) (actual time=103619.856..103620.154 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1608836 read=828079 dirtied=1355 written=416 -> Sort (cost=10217775.63..10293312.64 rows=30214805 width=39) (actual time=103619.838..103619.882 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: 85kB Buffers: shared hit=1608836 read=828079 dirtied=1355 written=416 -> Hash Join (cost=2902479.32..5637585.60 rows=30214805 width=39) (actual time=79102.829..103618.170 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1608824 read=828079 dirtied=1355 written=416 -> Seq Scan on lineitem (cost=0.00..1677588.10 rows=60429610 width=8) (actual time=0.038..12746.311 rows=59984909 loops=1) Buffers: shared hit=762172 read=311120 dirtied=1037 written=1 -> Hash (cost=2808073.40..2808073.40 rows=7552474 width=39) (actual time=78770.977..78770.977 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=846652 read=516959 dirtied=318 written=415 -> Hash Join (cost=2191321.56..2808073.40 rows=7552474 width=39) (actual time=68892.541..78766.472 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=846652 read=516959 dirtied=318 written=415 -> Hash Join (cost=2122293.56..2625758.29 rows=7552474 width=20) (actual time=67865.574..77733.773 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=811415 read=516918 dirtied=318 written=410 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=16) (actual time=0.011..4072.665 rows=15000000 loops=1) Buffers: shared hit=130555 read=124486 written=162 -> Hash (cost=2071380.20..2071380.20 rows=4073069 width=4) (actual time=67682.333..67682.333 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=680860 read=392432 dirtied=318 written=248 -> HashAggregate (cost=1979736.15..2030649.51 rows=4073069 width=8) (actual time=54910.615..67679.962 rows=111 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 14999889 Buffers: shared hit=680860 read=392432 dirtied=318 written=248 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1677588.10 rows=60429610 width=8) (actual time=0.017..14127.091 rows=59984909 loops=1) Buffers: shared hit=680860 read=392432 dirtied=318 written=248 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1015.871..1015.871 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35237 read=41 written=5 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.017..549.528 rows=1500000 loops=1) Buffers: shared hit=35237 read=41 written=5 Planning time: 4.770 ms Execution time: 103994.059 ms (42 rows) COMMIT; COMMIT