@@ -657,7 +657,7 @@ PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
657657
658658 if (RelationUsesLocalBuffers (reln ))
659659 {
660- /* see comments in ReadBufferExtended */
660+ /* see comments in PinBufferForBlock */
661661 if (RELATION_IS_OTHER_TEMP (reln ))
662662 ereport (ERROR ,
663663 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -794,16 +794,6 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum,
794794{
795795 Buffer buf ;
796796
797- /*
798- * Reject attempts to read non-local temporary relations; we would be
799- * likely to get wrong data since we have no visibility into the owning
800- * session's local buffers.
801- */
802- if (RELATION_IS_OTHER_TEMP (reln ))
803- ereport (ERROR ,
804- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
805- errmsg ("cannot access temporary tables of other sessions" )));
806-
807797 /*
808798 * Read the buffer, and update pgstat counters to reflect a cache hit or
809799 * miss.
@@ -1109,6 +1099,18 @@ PinBufferForBlock(Relation rel,
11091099
11101100 if (persistence == RELPERSISTENCE_TEMP )
11111101 {
1102+ /*
1103+ * Reject attempts to read non-local temporary relations; we would be
1104+ * likely to get wrong data since we have no visibility into the
1105+ * owning session's local buffers. We don't expect to get here
1106+ * without a relcache entry (see ReadBufferWithoutRelcache).
1107+ */
1108+ Assert (rel );
1109+ if (RELATION_IS_OTHER_TEMP (rel ))
1110+ ereport (ERROR ,
1111+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
1112+ errmsg ("cannot access temporary tables of other sessions" )));
1113+
11121114 io_context = IOCONTEXT_NORMAL ;
11131115 io_object = IOOBJECT_TEMP_RELATION ;
11141116 }
0 commit comments