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=10244181.43..10244184.18 rows=100 width=39) (actual time=102704.330..102704.578 rows=75 loops=1) Buffers: shared hit=1625374 read=817809 written=42 -> GroupAggregate (cost=10244181.43..11077220.61 rows=30292334 width=39) (actual time=102704.326..102704.562 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1625374 read=817809 written=42 -> Sort (cost=10244181.43..10319912.26 rows=30292334 width=39) (actual time=102704.308..102704.339 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=1625374 read=817809 written=42 -> Hash Join (cost=2909557.03..5651681.44 rows=30292334 width=39) (actual time=78946.037..102703.151 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1625362 read=817809 written=42 -> Seq Scan on lineitem (cost=0.00..1681892.69 rows=60584669 width=8) (actual time=0.026..12015.067 rows=60044176 loops=1) Buffers: shared hit=601701 read=474345 written=5 -> Hash (cost=2814869.78..2814869.78 rows=7574980 width=39) (actual time=78706.674..78706.674 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=1023661 read=343464 written=37 -> Hash Join (cost=2196401.45..2814869.78 rows=7574980 width=39) (actual time=69463.275..78702.107 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1023661 read=343464 written=37 -> Hash Join (cost=2127373.45..2632217.08 rows=7574980 width=20) (actual time=68330.023..77561.778 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=988384 read=343463 written=37 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=16) (actual time=0.011..3399.803 rows=15015000 loops=1) Buffers: shared hit=230825 read=24976 written=31 -> Hash (cost=2076460.09..2076460.09 rows=4073069 width=4) (actual time=68176.587..68176.587 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=757559 read=318487 written=6 -> HashAggregate (cost=1984816.04..2035729.40 rows=4073069 width=8) (actual time=57061.662..68173.042 rows=75 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 315::double precision) Rows Removed by Filter: 15014925 Buffers: shared hit=757559 read=318487 written=6 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1681892.69 rows=60584669 width=8) (actual time=0.017..14293.168 rows=60044176 loops=1) Buffers: shared hit=757559 read=318487 written=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1116.406..1116.406 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35277 read=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.023..617.337 rows=1500000 loops=1) Buffers: shared hit=35277 read=1 Planning time: 4.914 ms Execution time: 103033.852 ms (42 rows) COMMIT; COMMIT