Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8021985

Browse files
committed
logtape.c: allocate read buffer even for an empty tape.
Prior to this commit, the read buffer was allocated at the time the tapewas rewound; but as an optimization, would not be allocated at all ifthe tape was empty.That optimization meant that it was valid to have a rewound tape withthe buffer set to NULL, but only if a number of conditions were metand only if the API was used properly. After7fdd919 refactored thecode to support lazily-allocating the buffer, Coverity startedcomplaining.The optimization for empty tapes doesn't seem important, so justallocate the buffer whether the tape has any data or not.Discussion:https://postgr.es/m/20351.1581868306%40sss.pgh.pa.us
1 parent0074919 commit8021985

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

‎src/backend/utils/sort/logtape.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,8 @@ ltsConcatWorkerTapes(LogicalTapeSet *lts, TapeShare *shared,
544544
staticvoid
545545
ltsInitReadBuffer(LogicalTapeSet*lts,LogicalTape*lt)
546546
{
547-
if (lt->firstBlockNumber!=-1L)
548-
{
549-
Assert(lt->buffer_size>0);
550-
lt->buffer=palloc(lt->buffer_size);
551-
}
547+
Assert(lt->buffer_size>0);
548+
lt->buffer=palloc(lt->buffer_size);
552549

553550
/* Read the first block, or reset if tape is empty */
554551
lt->nextBlockNumber=lt->firstBlockNumber;
@@ -839,13 +836,10 @@ LogicalTapeRewindForRead(LogicalTapeSet *lts, int tapenum, size_t buffer_size)
839836
/* Allocate a read buffer (unless the tape is empty) */
840837
if (lt->buffer)
841838
pfree(lt->buffer);
839+
840+
/* the buffer is lazily allocated, but set the size here */
842841
lt->buffer=NULL;
843-
lt->buffer_size=0;
844-
if (lt->firstBlockNumber!=-1L)
845-
{
846-
/* the buffer is lazily allocated, but set the size here */
847-
lt->buffer_size=buffer_size;
848-
}
842+
lt->buffer_size=buffer_size;
849843
}
850844

851845
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp