From aab5d17164b6441fc3ad9982abb1805441468699 Mon Sep 17 00:00:00 2001 From: Commitfest Bot Date: Fri, 12 Dec 2025 14:45:22 +0000 Subject: [PATCH] [PATCH]: ./v1-move-check-for-other-temp-table.patch --- src/backend/storage/buffer/bufmgr.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index c3e72fb1b967..e2bb3d89b7a4 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -657,7 +657,7 @@ PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum) if (RelationUsesLocalBuffers(reln)) { - /* see comments in ReadBufferExtended */ + /* see comments in PinBufferForBlock */ if (RELATION_IS_OTHER_TEMP(reln)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -794,16 +794,6 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, { Buffer buf; - /* - * Reject attempts to read non-local temporary relations; we would be - * likely to get wrong data since we have no visibility into the owning - * session's local buffers. - */ - if (RELATION_IS_OTHER_TEMP(reln)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot access temporary tables of other sessions"))); - /* * Read the buffer, and update pgstat counters to reflect a cache hit or * miss. @@ -1109,6 +1099,18 @@ PinBufferForBlock(Relation rel, if (persistence == RELPERSISTENCE_TEMP) { + /* + * Reject attempts to read non-local temporary relations; we would be + * likely to get wrong data since we have no visibility into the + * owning session's local buffers. We don't expect to get here + * without a relcache entry (see ReadBufferWithoutRelcache). + */ + Assert(rel); + if (RELATION_IS_OTHER_TEMP(rel)) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot access temporary tables of other sessions"))); + io_context = IOCONTEXT_NORMAL; io_object = IOOBJECT_TEMP_RELATION; }