Modify the relcache to record the temp status of both local and nonlocal
authorTom Lane
Tue, 31 Mar 2009 22:12:48 +0000 (22:12 +0000)
committerTom Lane
Tue, 31 Mar 2009 22:12:48 +0000 (22:12 +0000)
temp relations; this is no more expensive than before, now that we have
pg_class.relistemp.  Insert tests into bufmgr.c to prevent attempting
to fetch pages from nonlocal temp relations.  This provides a low-level
defense against bugs-of-omission allowing temp pages to be loaded into shared
buffers, as in the contrib/pgstattuple problem reported by Stuart Bishop.
While at it, tweak a bunch of places to use new relcache tests (instead of
expensive probes into pg_namespace) to detect local or nonlocal temp tables.

14 files changed:
src/backend/catalog/index.c
src/backend/catalog/namespace.c
src/backend/catalog/toasting.c
src/backend/commands/analyze.c
src/backend/commands/cluster.c
src/backend/commands/copy.c
src/backend/commands/indexcmds.c
src/backend/commands/tablecmds.c
src/backend/commands/vacuum.c
src/backend/optimizer/prep/prepunion.c
src/backend/postmaster/autovacuum.c
src/backend/storage/buffer/bufmgr.c
src/backend/utils/cache/relcache.c
src/include/utils/rel.h

index 86ff1f7929e99f0c5081ad9849d30e4828045253..a14c588cc661422ea43a55d806fb1e47034c3346 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.314 2009/03/27 15:57:11 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.315 2009/03/31 22:12:46 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -2264,7 +2264,7 @@ reindex_index(Oid indexId)
     * Don't allow reindex on temp tables of other backends ... their local
     * buffer manager is not going to cope.
     */
-   if (isOtherTempNamespace(RelationGetNamespace(iRel)))
+   if (RELATION_IS_OTHER_TEMP(iRel))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("cannot reindex temporary tables of other sessions")));
index 0238e6078091697abf775a16f9b2aa238c44a866..f38568bed8ac7d773c4e8ea3f1d9651b1c3c432b 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.116 2009/01/01 17:23:37 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.117 2009/03/31 22:12:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2389,6 +2389,9 @@ isAnyTempNamespace(Oid namespaceId)
 /*
  * isOtherTempNamespace - is the given namespace some other backend's
  * temporary-table namespace (including temporary-toast-table namespaces)?
+ *
+ * Note: for most purposes in the C code, this function is obsolete.  Use
+ * RELATION_IS_OTHER_TEMP() instead to detect non-local temp relations.
  */
 bool
 isOtherTempNamespace(Oid namespaceId)
index 7510f96b47cdb444744089aecd024ad84d38fddf..5574b448ed64d28267806d01d6cc703d6202e0ef 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.13 2009/02/02 19:31:38 alvherre Exp $
+ *   $PostgreSQL: pgsql/src/backend/catalog/toasting.c,v 1.14 2009/03/31 22:12:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -179,7 +179,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
     * Toast tables for regular relations go in pg_toast; those for temp
     * relations go into the per-backend temp-toast-table namespace.
     */
-   if (rel->rd_istemp)
+   if (rel->rd_islocaltemp)
        namespaceid = GetTempToastNamespace();
    else
        namespaceid = PG_TOAST_NAMESPACE;
index 176ebde0efdb8a1e60e91d1db9b777ad657f34f4..47581ab705f2c92df871a08deb445181b843ea2d 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.134 2009/03/24 20:17:13 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.135 2009/03/31 22:12:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -213,7 +213,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
     * probably not up-to-date on disk.  (We don't throw a warning here; it
     * would just lead to chatter during a database-wide ANALYZE.)
     */
-   if (isOtherTempNamespace(RelationGetNamespace(onerel)))
+   if (RELATION_IS_OTHER_TEMP(onerel))
    {
        relation_close(onerel, ShareUpdateExclusiveLock);
        return;
index 6f578440da84dac68b2b0e66bc916b69317e7739..18f316dd517666a628a19b85d3c1a0af8d01b598 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.182 2009/02/02 19:31:38 alvherre Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.183 2009/03/31 22:12:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -117,7 +117,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
         * Reject clustering a remote temp table ... their local buffer
         * manager is not going to cope.
         */
-       if (isOtherTempNamespace(RelationGetNamespace(rel)))
+       if (RELATION_IS_OTHER_TEMP(rel))
            ereport(ERROR,
                    (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
               errmsg("cannot cluster temporary tables of other sessions")));
@@ -302,7 +302,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck, bool verbose)
         * check_index_is_clusterable which is redundant, but we leave it for
         * extra safety.
         */
-       if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
+       if (RELATION_IS_OTHER_TEMP(OldHeap))
        {
            relation_close(OldHeap, AccessExclusiveLock);
            return;
@@ -465,7 +465,7 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck)
     * Don't allow cluster on temp tables of other backends ... their local
     * buffer manager is not going to cope.
     */
-   if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
+   if (RELATION_IS_OTHER_TEMP(OldHeap))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
               errmsg("cannot cluster temporary tables of other sessions")));
index 611a343e3f93cd00ab3251a26af5ef8d169c4e6a..90ceb77bbbef31c88a0f69d1330b2cbf7e0eec4f 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.306 2009/03/26 19:24:54 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.307 2009/03/31 22:12:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1001,8 +1001,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
        }
 
        /* check read-only transaction */
-       if (XactReadOnly && is_from &&
-           !isTempNamespace(RelationGetNamespace(cstate->rel)))
+       if (XactReadOnly && is_from && !cstate->rel->rd_islocaltemp)
            ereport(ERROR,
                    (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
                     errmsg("transaction is read-only")));
index b0cd2ef0d151568334220c16ed35cd1870bb5faf..ab07509081981c071400f8ea0914ba4694a0d94a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.182 2009/02/02 19:31:38 alvherre Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.183 2009/03/31 22:12:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -175,7 +175,7 @@ DefineIndex(RangeVar *heapRelation,
    /*
     * Don't try to CREATE INDEX on temp tables of other backends.
     */
-   if (isOtherTempNamespace(namespaceId))
+   if (RELATION_IS_OTHER_TEMP(rel))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("cannot create indexes on temporary tables of other sessions")));
@@ -1404,7 +1404,8 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
            continue;
 
        /* Skip temp tables of other backends; we can't reindex them at all */
-       if (isOtherTempNamespace(classtuple->relnamespace))
+       if (classtuple->relistemp &&
+           !isTempNamespace(classtuple->relnamespace))
            continue;
 
        /* Check user/system classification, and optionally skip */
index 14c9f6b8bb0fc302c206d7616e75b50476b73fab..25c58fbbd45c002ba848a45434dbff32b2274099 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.280 2009/02/11 21:11:16 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.281 2009/03/31 22:12:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1056,7 +1056,7 @@ truncate_check_rel(Relation rel)
     * Don't allow truncate on temp tables of other backends ... their local
     * buffer manager is not going to cope.
     */
-   if (isOtherTempNamespace(RelationGetNamespace(rel)))
+   if (RELATION_IS_OTHER_TEMP(rel))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
              errmsg("cannot truncate temporary tables of other sessions")));
@@ -1203,7 +1203,7 @@ MergeAttributes(List *schema, List *supers, bool istemp,
                     errmsg("inherited relation \"%s\" is not a table",
                            parent->relname)));
        /* Permanent rels cannot inherit from temporary ones */
-       if (!istemp && isTempNamespace(RelationGetNamespace(relation)))
+       if (!istemp && relation->rd_istemp)
            ereport(ERROR,
                    (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                     errmsg("cannot inherit from temporary relation \"%s\"",
@@ -2793,7 +2793,7 @@ ATRewriteTables(List **wqueue)
             * Don't allow rewrite on temp tables of other backends ... their
             * local buffer manager is not going to cope.
             */
-           if (isOtherTempNamespace(RelationGetNamespace(OldHeap)))
+           if (RELATION_IS_OTHER_TEMP(OldHeap))
                ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                errmsg("cannot rewrite temporary tables of other sessions")));
@@ -4603,16 +4603,16 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
     * backend has created in the temp table, because non-shared buffers are
     * used for temp tables.)
     */
-   if (isTempNamespace(RelationGetNamespace(pkrel)))
+   if (pkrel->rd_istemp)
    {
-       if (!isTempNamespace(RelationGetNamespace(rel)))
+       if (!rel->rd_istemp)
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
                     errmsg("cannot reference temporary table from permanent table constraint")));
    }
    else
    {
-       if (isTempNamespace(RelationGetNamespace(rel)))
+       if (rel->rd_istemp)
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
                     errmsg("cannot reference permanent table from temporary table constraint")));
@@ -6690,7 +6690,7 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace)
     * Don't allow moving temp tables of other backends ... their local buffer
     * manager is not going to cope.
     */
-   if (isOtherTempNamespace(RelationGetNamespace(rel)))
+   if (RELATION_IS_OTHER_TEMP(rel))
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("cannot move temporary tables of other sessions")));
@@ -6901,8 +6901,7 @@ ATExecAddInherit(Relation child_rel, RangeVar *parent)
    ATSimplePermissions(parent_rel, false);
 
    /* Permanent rels cannot inherit from temporary ones */
-   if (!isTempNamespace(RelationGetNamespace(child_rel)) &&
-       isTempNamespace(RelationGetNamespace(parent_rel)))
+   if (parent_rel->rd_istemp && !child_rel->rd_istemp)
        ereport(ERROR,
                (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                 errmsg("cannot inherit from temporary relation \"%s\"",
index 78b179827ea7395a11e38b1ab38f74977a36021c..30c1972bcfc7685c550b8c9355dd16ed08ea29be 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.386 2009/03/24 20:17:13 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.387 2009/03/31 22:12:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1147,7 +1147,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, bool do_toast, bool for_wraparound,
     * warning here; it would just lead to chatter during a database-wide
     * VACUUM.)
     */
-   if (isOtherTempNamespace(RelationGetNamespace(onerel)))
+   if (RELATION_IS_OTHER_TEMP(onerel))
    {
        relation_close(onerel, lmode);
        PopActiveSnapshot();
index 43aa515ae5efa404d133c1c41fb6df69587ca7ba..06f920561a2e3daa1061aa1190f18f314333efe6 100644 (file)
@@ -22,7 +22,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.167 2009/03/05 17:30:29 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.168 2009/03/31 22:12:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1258,21 +1258,23 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
        Index       childRTindex;
        AppendRelInfo *appinfo;
 
+       /* Open rel, acquire the appropriate lock type */
+       if (childOID != parentOID)
+           newrelation = heap_open(childOID, lockmode);
+       else
+           newrelation = oldrelation;
+
        /*
         * It is possible that the parent table has children that are temp
         * tables of other backends.  We cannot safely access such tables
         * (because of buffering issues), and the best thing to do seems to be
         * to silently ignore them.
         */
-       if (childOID != parentOID &&
-           isOtherTempNamespace(get_rel_namespace(childOID)))
+       if (childOID != parentOID && RELATION_IS_OTHER_TEMP(newrelation))
+       {
+           heap_close(newrelation, lockmode);
            continue;
-
-       /* Open rel, acquire the appropriate lock type */
-       if (childOID != parentOID)
-           newrelation = heap_open(childOID, lockmode);
-       else
-           newrelation = oldrelation;
+       }
 
        /*
         * Build an RTE for the child, and attach to query's rangetable list.
index e7aea7fc23c9e9ebecc661fe93a86b76150a7a0c..6b250f2d27e0f2f8adccee48cf338f6e13d1067c 100644 (file)
@@ -55,7 +55,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.93 2009/02/09 20:57:59 alvherre Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.94 2009/03/31 22:12:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1942,7 +1942,6 @@ do_autovacuum(void)
        bool        dovacuum;
        bool        doanalyze;
        bool        wraparound;
-       int         backendID;
 
        relid = HeapTupleGetOid(tuple);
 
@@ -1959,10 +1958,12 @@ do_autovacuum(void)
         * Check if it is a temp table (presumably, of some other backend's).
         * We cannot safely process other backends' temp tables.
         */
-       backendID = GetTempNamespaceBackendId(classForm->relnamespace);
-
-       if (backendID > 0)
+       if (classForm->relistemp)
        {
+           int         backendID;
+
+           backendID = GetTempNamespaceBackendId(classForm->relnamespace);
+
            /* We just ignore it if the owning backend is still active */
            if (backendID == MyBackendId || !BackendIdIsActive(backendID))
            {
@@ -2052,10 +2053,9 @@ do_autovacuum(void)
        bool        wraparound;
 
        /*
-        * Skip temp tables (i.e. those in temp namespaces).  We cannot safely
-        * process other backends' temp tables.
+        * We cannot safely process other backends' temp tables, so skip 'em.
         */
-       if (isAnyTempNamespace(classForm->relnamespace))
+       if (classForm->relistemp)
            continue;
 
        relid = HeapTupleGetOid(tuple);
index 1f6e8d368038611b63596655c5ae4751305b792b..4a7dda3edbbabd882455eb4539ac8dfe75b25068 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.249 2009/03/23 01:52:38 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.250 2009/03/31 22:12:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -122,6 +122,12 @@ PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
 
    if (reln->rd_istemp)
    {
+       /* see comments in ReadBufferExtended */
+       if (RELATION_IS_OTHER_TEMP(reln))
+           ereport(ERROR,
+                   (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                    errmsg("cannot access temporary tables of other sessions")));
+
        /* pass it off to localbuf.c */
        LocalPrefetchBuffer(reln->rd_smgr, forkNum, blockNum);
    }
@@ -204,6 +210,16 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum,
    /* Open it at the smgr level if not already done */
    RelationOpenSmgr(reln);
 
+   /*
+    * 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.
@@ -220,6 +236,8 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum,
 /*
  * ReadBufferWithoutRelcache -- like ReadBufferExtended, but doesn't require
  *     a relcache entry for the relation.
+ *
+ * NB: caller is assumed to know what it's doing if isTemp is true.
  */
 Buffer
 ReadBufferWithoutRelcache(RelFileNode rnode, bool isTemp,
index c39759ee1c9ce0312795a9e1e5671aa21692eba6..ae6fcea7e67b924a458b4eecf5fccfe0d2b964ef 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.285 2009/03/31 17:59:56 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.286 2009/03/31 22:12:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -829,7 +829,11 @@ RelationBuildDesc(Oid targetRelId, Relation oldrelation)
    relation->rd_isnailed = false;
    relation->rd_createSubid = InvalidSubTransactionId;
    relation->rd_newRelfilenodeSubid = InvalidSubTransactionId;
-   relation->rd_istemp = isTempOrToastNamespace(relation->rd_rel->relnamespace);
+   relation->rd_istemp = relation->rd_rel->relistemp;
+   if (relation->rd_istemp)
+       relation->rd_islocaltemp = isTempOrToastNamespace(relation->rd_rel->relnamespace);
+   else
+       relation->rd_islocaltemp = false;
 
    /*
     * initialize the tuple descriptor (relation->rd_att).
@@ -1375,6 +1379,7 @@ formrdesc(const char *relationName, Oid relationReltype,
    relation->rd_createSubid = InvalidSubTransactionId;
    relation->rd_newRelfilenodeSubid = InvalidSubTransactionId;
    relation->rd_istemp = false;
+   relation->rd_islocaltemp = false;
 
    /*
     * initialize relation tuple form
@@ -2355,8 +2360,9 @@ RelationBuildLocalRelation(const char *relname,
    /* must flag that we have rels created in this transaction */
    need_eoxact_work = true;
 
-   /* is it a temporary relation? */
+   /* it is temporary if and only if it is in my temp-table namespace */
    rel->rd_istemp = isTempOrToastNamespace(relnamespace);
+   rel->rd_islocaltemp = rel->rd_istemp;
 
    /*
     * create a new tuple descriptor from the one passed in.  We do this
@@ -2403,9 +2409,7 @@ RelationBuildLocalRelation(const char *relname,
     * as the logical ID (OID).
     */
    rel->rd_rel->relisshared = shared_relation;
-
-   /* it is temporary if and only if it is in my temp-table namespace */
-   rel->rd_rel->relistemp = isTempOrToastNamespace(relnamespace);
+   rel->rd_rel->relistemp = rel->rd_istemp;
 
    RelationGetRelid(rel) = relid;
 
index a3aaf69e2f102c0c2dfd4bed7fbc825e0d82ba7b..8c849e3ad62de929536379b8d956685f4eec80de 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.112 2009/02/09 20:57:59 alvherre Exp $
+ * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.113 2009/03/31 22:12:48 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -126,7 +126,8 @@ typedef struct RelationData
    BlockNumber rd_targblock;   /* current insertion target block, or
                                 * InvalidBlockNumber */
    int         rd_refcnt;      /* reference count */
-   bool        rd_istemp;      /* rel uses the local buffer mgr */
+   bool        rd_istemp;      /* rel is a temporary relation */
+   bool        rd_islocaltemp; /* rel is a temp rel of this session */
    bool        rd_isnailed;    /* rel is nailed in cache */
    bool        rd_isvalid;     /* relcache entry is valid */
    char        rd_indexvalid;  /* state of rd_indexlist: 0 = not valid, 1 =
@@ -355,9 +356,18 @@ typedef struct StdRdOptions
  * Beware of multiple eval of argument
  */
 #define RELATION_IS_LOCAL(relation) \
-   ((relation)->rd_istemp || \
+   ((relation)->rd_islocaltemp || \
     (relation)->rd_createSubid != InvalidSubTransactionId)
 
+/*
+ * RELATION_IS_OTHER_TEMP
+ *     Test for a temporary relation that belongs to some other session.
+ *
+ * Beware of multiple eval of argument
+ */
+#define RELATION_IS_OTHER_TEMP(relation) \
+   ((relation)->rd_istemp && !(relation)->rd_islocaltemp)
+
 /* routines in utils/cache/relcache.c */
 extern void RelationIncrementReferenceCount(Relation rel);
 extern void RelationDecrementReferenceCount(Relation rel);