Simplify the code for logical tape read buffers.

Pass the buffer size as argument to LogicalTapeRewindForRead, rather than
setting it earlier with the separate LogicTapeAssignReadBufferSize call.
This way, the buffer size is set closer to where it's actually used, which
makes the code easier to understand.

This makes the calculation for how much memory to use for the buffers less
precise. We now use the same amount of memory for every tape, rounded down
to the nearest BLCKSZ boundary, instead of using one more block for some
tapes, to get the total up to exact amount of memory available. That should
be OK, merging isn't too sensitive to the exact amount of memory used.

Reviewed by Peter Geoghegan

Discussion: <>



Modified Files
src/backend/utils/sort/logtape.c   | 213 ++++++++++++++++++-------------------
src/backend/utils/sort/tuplesort.c | 120 ++++++---------------
src/include/utils/logtape.h        |   6 +-
3 files changed, 139 insertions(+), 200 deletions(-)

Sent via pgsql-committers mailing list (
To make changes to your subscription:

Reply via email to