Skip to content

Commit af07a82

Browse files
committed
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
1 parent e00c45f commit af07a82

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/backend/storage/aio/read_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ read_stream_begin_relation(int flags,
551551
{
552552
stream->ios[i].op.rel = rel;
553553
stream->ios[i].op.smgr = RelationGetSmgr(rel);
554-
stream->ios[i].op.smgr_persistence = 0;
554+
stream->ios[i].op.persistence = rel->rd_rel->relpersistence;
555555
stream->ios[i].op.forknum = forknum;
556556
stream->ios[i].op.strategy = strategy;
557557
}

src/backend/storage/buffer/bufmgr.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ ZeroAndLockBuffer(Buffer buffer, ReadBufferMode mode, bool already_valid)
11041104
static pg_attribute_always_inline Buffer
11051105
PinBufferForBlock(Relation rel,
11061106
SMgrRelation smgr,
1107-
char smgr_persistence,
1107+
char persistence,
11081108
ForkNumber forkNum,
11091109
BlockNumber blockNum,
11101110
BufferAccessStrategy strategy,
@@ -1113,14 +1113,13 @@ PinBufferForBlock(Relation rel,
11131113
BufferDesc *bufHdr;
11141114
IOContext io_context;
11151115
IOObject io_object;
1116-
char persistence;
11171116

11181117
Assert(blockNum != P_NEW);
11191118

1120-
if (rel)
1121-
persistence = rel->rd_rel->relpersistence;
1122-
else
1123-
persistence = smgr_persistence;
1119+
/* Persistence should be set before */
1120+
Assert((persistence == RELPERSISTENCE_TEMP ||
1121+
persistence == RELPERSISTENCE_PERMANENT ||
1122+
persistence == RELPERSISTENCE_UNLOGGED));
11241123

11251124
if (persistence == RELPERSISTENCE_TEMP)
11261125
{
@@ -1195,6 +1194,7 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
11951194
ReadBuffersOperation operation;
11961195
Buffer buffer;
11971196
int flags;
1197+
char persistence;
11981198

11991199
/*
12001200
* Backward compatibility path, most code should use ExtendBufferedRel()
@@ -1216,12 +1216,17 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
12161216
return ExtendBufferedRel(BMR_REL(rel), forkNum, strategy, flags);
12171217
}
12181218

1219+
if (rel)
1220+
persistence = rel->rd_rel->relpersistence;
1221+
else
1222+
persistence = smgr_persistence;
1223+
12191224
if (unlikely(mode == RBM_ZERO_AND_CLEANUP_LOCK ||
12201225
mode == RBM_ZERO_AND_LOCK))
12211226
{
12221227
bool found;
12231228

1224-
buffer = PinBufferForBlock(rel, smgr, smgr_persistence,
1229+
buffer = PinBufferForBlock(rel, smgr, persistence,
12251230
forkNum, blockNum, strategy, &found);
12261231
ZeroAndLockBuffer(buffer, mode, found);
12271232
return buffer;
@@ -1233,7 +1238,7 @@ ReadBuffer_common(Relation rel, SMgrRelation smgr, char smgr_persistence,
12331238
flags = 0;
12341239
operation.smgr = smgr;
12351240
operation.rel = rel;
1236-
operation.smgr_persistence = smgr_persistence;
1241+
operation.persistence = persistence;
12371242
operation.forknum = forkNum;
12381243
operation.strategy = strategy;
12391244
if (StartReadBuffer(&operation,
@@ -1264,7 +1269,7 @@ StartReadBuffersImpl(ReadBuffersOperation *operation,
12641269

12651270
buffers[i] = PinBufferForBlock(operation->rel,
12661271
operation->smgr,
1267-
operation->smgr_persistence,
1272+
operation->persistence,
12681273
operation->forknum,
12691274
blockNum + i,
12701275
operation->strategy,
@@ -1410,10 +1415,8 @@ WaitReadBuffers(ReadBuffersOperation *operation)
14101415
buffers = &operation->buffers[0];
14111416
blocknum = operation->blocknum;
14121417
forknum = operation->forknum;
1418+
persistence = operation->persistence;
14131419

1414-
persistence = operation->rel
1415-
? operation->rel->rd_rel->relpersistence
1416-
: RELPERSISTENCE_PERMANENT;
14171420
if (persistence == RELPERSISTENCE_TEMP)
14181421
{
14191422
io_context = IOCONTEXT_NORMAL;

src/include/storage/bufmgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct ReadBuffersOperation
117117
/* The following members should be set by the caller. */
118118
Relation rel; /* optional */
119119
struct SMgrRelationData *smgr;
120-
char smgr_persistence; /* optional if rel != NULL */
120+
char persistence;
121121
ForkNumber forknum;
122122
BufferAccessStrategy strategy;
123123

0 commit comments

Comments
 (0)