diff options
author | Noah Misch <noah@leadboat.com> | 2024-07-20 04:22:12 -0700 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2024-07-20 04:22:12 -0700 |
commit | af07a827b9c579be64f144f88e03bff3bb85582c (patch) | |
tree | 879cdff42f7fcfb2a6b38ed1befe523b269ae230 /src/backend/storage/buffer | |
parent | e00c45f6850f86c53b48478f60c15be905dc914d (diff) | |
download | postgresql-af07a827b9c579be64f144f88e03bff3bb85582c.tar.gz postgresql-af07a827b9c579be64f144f88e03bff3bb85582c.zip |
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
Diffstat (limited to 'src/backend/storage/buffer')
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index db3eb2cce1e..bdb36e5a30e 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -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; |