mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +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:
@ -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;
|
||||
|
Reference in New Issue
Block a user