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:
parent
e00c45f685
commit
af07a827b9
@ -551,7 +551,7 @@ read_stream_begin_relation(int flags,
|
|||||||
{
|
{
|
||||||
stream->ios[i].op.rel = rel;
|
stream->ios[i].op.rel = rel;
|
||||||
stream->ios[i].op.smgr = RelationGetSmgr(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.forknum = forknum;
|
||||||
stream->ios[i].op.strategy = strategy;
|
stream->ios[i].op.strategy = strategy;
|
||||||
}
|
}
|
||||||
|
@ -1104,7 +1104,7 @@ ZeroAndLockBuffer(Buffer buffer, ReadBufferMode mode, bool already_valid)
|
|||||||
static pg_attribute_always_inline Buffer
|
static pg_attribute_always_inline Buffer
|
||||||
PinBufferForBlock(Relation rel,
|
PinBufferForBlock(Relation rel,
|
||||||
SMgrRelation smgr,
|
SMgrRelation smgr,
|
||||||
char smgr_persistence,
|
char persistence,
|
||||||
ForkNumber forkNum,
|
ForkNumber forkNum,
|
||||||
BlockNumber blockNum,
|
BlockNumber blockNum,
|
||||||
BufferAccessStrategy strategy,
|
BufferAccessStrategy strategy,
|
||||||
@ -1113,14 +1113,13 @@ PinBufferForBlock(Relation rel,
|
|||||||
BufferDesc *bufHdr;
|
BufferDesc *bufHdr;
|
||||||
IOContext io_context;
|
IOContext io_context;
|
||||||
IOObject io_object;
|
IOObject io_object;
|
||||||
char persistence;
|
|
||||||
|
|
||||||
Assert(blockNum != P_NEW);
|
Assert(blockNum != P_NEW);
|
||||||
|
|
||||||
if (rel)
|
/* Persistence should be set before */
|
||||||
persistence = rel->rd_rel->relpersistence;
|
Assert((persistence == RELPERSISTENCE_TEMP ||
|
||||||
else
|
persistence == RELPERSISTENCE_PERMANENT ||
|
||||||
persistence = smgr_persistence;
|
persistence == RELPERSISTENCE_UNLOGGED));
|
||||||
|
|
||||||
if (persistence == RELPERSISTENCE_TEMP)
|
if (persistence == RELPERSISTENCE_TEMP)
|
||||||
{
|
{
|
||||||
@ -1195,6 +1194,7 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
|
|||||||
ReadBuffersOperation operation;
|
ReadBuffersOperation operation;
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
int flags;
|
int flags;
|
||||||
|
char persistence;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Backward compatibility path, most code should use ExtendBufferedRel()
|
* 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);
|
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 ||
|
if (unlikely(mode == RBM_ZERO_AND_CLEANUP_LOCK ||
|
||||||
mode == RBM_ZERO_AND_LOCK))
|
mode == RBM_ZERO_AND_LOCK))
|
||||||
{
|
{
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
buffer = PinBufferForBlock(rel, smgr, smgr_persistence,
|
buffer = PinBufferForBlock(rel, smgr, persistence,
|
||||||
forkNum, blockNum, strategy, &found);
|
forkNum, blockNum, strategy, &found);
|
||||||
ZeroAndLockBuffer(buffer, mode, found);
|
ZeroAndLockBuffer(buffer, mode, found);
|
||||||
return buffer;
|
return buffer;
|
||||||
@ -1233,7 +1238,7 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
|
|||||||
flags = 0;
|
flags = 0;
|
||||||
operation.smgr = smgr;
|
operation.smgr = smgr;
|
||||||
operation.rel = rel;
|
operation.rel = rel;
|
||||||
operation.smgr_persistence = smgr_persistence;
|
operation.persistence = persistence;
|
||||||
operation.forknum = forkNum;
|
operation.forknum = forkNum;
|
||||||
operation.strategy = strategy;
|
operation.strategy = strategy;
|
||||||
if (StartReadBuffer(&operation,
|
if (StartReadBuffer(&operation,
|
||||||
@ -1264,7 +1269,7 @@ StartReadBuffersImpl(ReadBuffersOperation *operation,
|
|||||||
|
|
||||||
buffers[i] = PinBufferForBlock(operation->rel,
|
buffers[i] = PinBufferForBlock(operation->rel,
|
||||||
operation->smgr,
|
operation->smgr,
|
||||||
operation->smgr_persistence,
|
operation->persistence,
|
||||||
operation->forknum,
|
operation->forknum,
|
||||||
blockNum + i,
|
blockNum + i,
|
||||||
operation->strategy,
|
operation->strategy,
|
||||||
@ -1410,10 +1415,8 @@ WaitReadBuffers(ReadBuffersOperation *operation)
|
|||||||
buffers = &operation->buffers[0];
|
buffers = &operation->buffers[0];
|
||||||
blocknum = operation->blocknum;
|
blocknum = operation->blocknum;
|
||||||
forknum = operation->forknum;
|
forknum = operation->forknum;
|
||||||
|
persistence = operation->persistence;
|
||||||
|
|
||||||
persistence = operation->rel
|
|
||||||
? operation->rel->rd_rel->relpersistence
|
|
||||||
: RELPERSISTENCE_PERMANENT;
|
|
||||||
if (persistence == RELPERSISTENCE_TEMP)
|
if (persistence == RELPERSISTENCE_TEMP)
|
||||||
{
|
{
|
||||||
io_context = IOCONTEXT_NORMAL;
|
io_context = IOCONTEXT_NORMAL;
|
||||||
|
@ -117,7 +117,7 @@ struct ReadBuffersOperation
|
|||||||
/* The following members should be set by the caller. */
|
/* The following members should be set by the caller. */
|
||||||
Relation rel; /* optional */
|
Relation rel; /* optional */
|
||||||
struct SMgrRelationData *smgr;
|
struct SMgrRelationData *smgr;
|
||||||
char smgr_persistence; /* optional if rel != NULL */
|
char persistence;
|
||||||
ForkNumber forknum;
|
ForkNumber forknum;
|
||||||
BufferAccessStrategy strategy;
|
BufferAccessStrategy strategy;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user