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=10184991.27..10184994.02 rows=100 width=39) (actual time=106804.201..106804.481 rows=75 loops=1) Buffers: shared hit=1651218 read=777685 dirtied=605 written=459 -> GroupAggregate (cost=10184991.27..11013087.08 rows=30112575 width=39) (actual time=106804.198..106804.467 rows=75 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1651218 read=777685 dirtied=605 written=459 -> Sort (cost=10184991.27..10260272.71 rows=30112575 width=39) (actual time=106804.180..106804.219 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=1651218 read=777685 dirtied=605 written=459 -> Hash Join (cost=2895177.75..5621035.37 rows=30112575 width=39) (actual time=83692.752..106803.013 rows=525 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1651206 read=777685 dirtied=605 written=459 -> Seq Scan on lineitem (cost=0.00..1671917.50 rows=60225150 width=8) (actual time=0.022..12276.444 rows=60045303 loops=1) Buffers: shared hit=840766 read=228900 dirtied=605 written=355 -> Hash (cost=2801053.15..2801053.15 rows=7529968 width=39) (actual time=83463.767..83463.767 rows=75 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=810440 read=548785 written=104 -> Hash Join (cost=2185709.11..2801053.15 rows=7529968 width=39) (actual time=73405.587..83463.257 rows=75 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=810440 read=548785 written=104 -> Hash Join (cost=2116681.11..2619075.62 rows=7529968 width=20) (actual time=71965.701..82017.789 rows=75 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=810437 read=513510 written=30 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.014..4264.101 rows=15015000 loops=1) Buffers: shared hit=175112 read=79169 written=23 -> Hash (cost=2065381.88..2065381.88 rows=4103939 width=4) (actual time=71707.828..71707.828 rows=75 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=635325 read=434341 written=7 -> HashAggregate (cost=1973043.25..2024342.49 rows=4103939 width=8) (actual time=58225.524..71707.100 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=635325 read=434341 written=7 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1671917.50 rows=60225150 width=8) (actual time=0.030..15930.128 rows=60045303 loops=1) Buffers: shared hit=635325 read=434341 written=7 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1426.817..1426.817 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=3 read=35275 written=74 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.015..836.845 rows=1500000 loops=1) Buffers: shared hit=3 read=35275 written=74 Planning time: 4.668 ms Execution time: 108664.402 ms (42 rows) COMMIT; COMMIT