1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

Refactor PinBufferForBlock() to remove checks about persistence.

There are checks in PinBufferForBlock() function to set persistence of
the relation.  This function is called for each block in the relation.
Instead, set persistence of the relation before PinBufferForBlock().

Nazir Bilal Yavuz

Discussion: https://postgr.es/m/CAN55FZ0JKL6vk1xQp6rfOXiNFV1u1H0tJDPPGHWoiO3ea2Wc=A@mail.gmail.com
This commit is contained in:
Noah Misch 2024-07-20 04:22:12 -07:00
parent e00c45f685
commit af07a827b9
3 changed files with 17 additions and 14 deletions

View File

@ -551,7 +551,7 @@ read_stream_begin_relation(int flags,
{
stream->ios[i].op.rel = rel;
stream->ios[i].op.smgr = RelationGetSmgr(rel);
stream->ios[i].op.smgr_persistence = 0;
stream->ios[i].op.persistence = rel->rd_rel->relpersistence;
stream->ios[i].op.forknum = forknum;
stream->ios[i].op.strategy = strategy;
}

View File

@ -1104,7 +1104,7 @@ ZeroAndLockBuffer(Buffer buffer, ReadBufferMode mode, bool already_valid)
static pg_attribute_always_inline Buffer
PinBufferForBlock(Relation rel,
SMgrRelation smgr,
char smgr_persistence,
char persistence,
ForkNumber forkNum,
BlockNumber blockNum,
BufferAccessStrategy strategy,
@ -1113,14 +1113,13 @@ PinBufferForBlock(Relation rel,
BufferDesc *bufHdr;
IOContext io_context;
IOObject io_object;
char persistence;
Assert(blockNum != P_NEW);
if (rel)
persistence = rel->rd_rel->relpersistence;
else
persistence = smgr_persistence;
/* Persistence should be set before */
Assert((persistence == RELPERSISTENCE_TEMP ||
persistence == RELPERSISTENCE_PERMANENT ||
persistence == RELPERSISTENCE_UNLOGGED));
if (persistence == RELPERSISTENCE_TEMP)
{
@ -1195,6 +1194,7 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
ReadBuffersOperation operation;
Buffer buffer;
int flags;
char persistence;
/*
* Backward compatibility path, most code should use ExtendBufferedRel()
@ -1216,12 +1216,17 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
return ExtendBufferedRel(BMR_REL(rel), forkNum, strategy, flags);
}
if (rel)
persistence = rel->rd_rel->relpersistence;
else
persistence = smgr_persistence;
if (unlikely(mode == RBM_ZERO_AND_CLEANUP_LOCK ||
mode == RBM_ZERO_AND_LOCK))
{
bool found;
buffer = PinBufferForBlock(rel, smgr, smgr_persistence,
buffer = PinBufferForBlock(rel, smgr, persistence,
forkNum, blockNum, strategy, &found);
ZeroAndLockBuffer(buffer, mode, found);
return buffer;
@ -1233,7 +1238,7 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
flags = 0;
operation.smgr = smgr;
operation.rel = rel;
operation.smgr_persistence = smgr_persistence;
operation.persistence = persistence;
operation.forknum = forkNum;
operation.strategy = strategy;
if (StartReadBuffer(&operation,
@ -1264,7 +1269,7 @@ StartReadBuffersImpl(ReadBuffersOperation *operation,
buffers[i] = PinBufferForBlock(operation->rel,
operation->smgr,
operation->smgr_persistence,
operation->persistence,
operation->forknum,
blockNum + i,
operation->strategy,
@ -1410,10 +1415,8 @@ WaitReadBuffers(ReadBuffersOperation *operation)
buffers = &operation->buffers[0];
blocknum = operation->blocknum;
forknum = operation->forknum;
persistence = operation->persistence;
persistence = operation->rel
? operation->rel->rd_rel->relpersistence
: RELPERSISTENCE_PERMANENT;
if (persistence == RELPERSISTENCE_TEMP)
{
io_context = IOCONTEXT_NORMAL;

View File

@ -117,7 +117,7 @@ struct ReadBuffersOperation
/* The following members should be set by the caller. */
Relation rel; /* optional */
struct SMgrRelationData *smgr;
char smgr_persistence; /* optional if rel != NULL */
char persistence;
ForkNumber forknum;
BufferAccessStrategy strategy;