]> granicus.if.org Git - postgresql/commitdiff
Commit to make clearer distinction for temp names and real names.
authorBruce Momjian <bruce@momjian.us>
Tue, 16 Nov 1999 04:14:03 +0000 (04:14 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 16 Nov 1999 04:14:03 +0000 (04:14 +0000)
Thanks to Tom Lane for ideas.

src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/smgr/md.c
src/backend/utils/cache/relcache.c
src/backend/utils/cache/syscache.c
src/backend/utils/cache/temprel.c
src/include/utils/rel.h
src/include/utils/temprel.h

index fe05d24194736fa2ce42824212cb13c3c2b14fe1..cc0ce0293b66c7abbd74a9d7e7bb2e3398034051 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.107 1999/11/07 23:08:00 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.108 1999/11/16 04:13:55 momjian Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -290,7 +290,7 @@ heap_create(char *relname,
         * ----------------
         */
        MemSet((char *) rel->rd_rel, 0, sizeof *rel->rd_rel);
-       strcpy(RelationGetRelationName(rel), relname);
+       strcpy(RelationGetPhysicalRelationName(rel), relname);
        rel->rd_rel->relkind = RELKIND_UNCATALOGED;
        rel->rd_rel->relnatts = natts;
        if (tupDesc->constr)
@@ -798,7 +798,7 @@ heap_create_with_catalog(char *relname,
 
        /* temp tables can mask non-temp tables */
        if ((!istemp && RelnameFindRelid(relname)) ||
-               (istemp && get_temp_rel_by_name(relname) != NULL))
+               (istemp && get_temp_rel_by_username(relname) != NULL))
                elog(ERROR, "Relation '%s' already exists", relname);
 
        /* save user relation name because heap_create changes it */
@@ -810,7 +810,7 @@ heap_create_with_catalog(char *relname,
        }
 
        /* ----------------
-        *      get_temp_rel_by_name() couldn't check the simultaneous
+        *      get_temp_rel_by_username() couldn't check the simultaneous
         *      creation. Uniqueness will be really checked by unique
         *      indexes of system tables but we couldn't check it here.
         *      We have to pospone to create the disk file for this
@@ -1448,7 +1448,7 @@ heap_destroy_with_catalog(char *relname)
 {
        Relation        rel;
        Oid                     rid;
-       bool            istemp = (get_temp_rel_by_name(relname) != NULL);
+       bool            istemp = (get_temp_rel_by_username(relname) != NULL);
 
        /* ----------------
         *      Open and lock the relation.
@@ -1518,9 +1518,6 @@ heap_destroy_with_catalog(char *relname)
 
        DeleteComments(RelationGetRelid(rel));
 
-       if (istemp)
-               remove_temp_relation(rid);
-
        /* ----------------
         *      delete type tuple.      here we want to see the effects
         *      of the deletions we just did, so we use setheapoverride().
@@ -1565,6 +1562,9 @@ heap_destroy_with_catalog(char *relname)
         * ----------------
         */
        RelationForgetRelation(rid);
+
+       if (istemp)
+               remove_temp_relation(rid);
 }
 
 /*
index 65d297a2508a7c5bcea0309f18b714dd052ba0d9..203d3f1ef80a57c1904fa44cf601703997ba55ce 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.94 1999/11/04 08:00:56 inoue Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.95 1999/11/16 04:13:55 momjian Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -120,7 +120,7 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName, bool istemp)
        indoid = RelnameFindRelid(indexRelationName);
 
        if ((!istemp && OidIsValid(indoid)) ||
-               (istemp && get_temp_rel_by_name(indexRelationName) != NULL))
+               (istemp && get_temp_rel_by_username(indexRelationName) != NULL))
                elog(ERROR, "Cannot create index: '%s' already exists",
                         indexRelationName);
 
@@ -948,7 +948,7 @@ index_create(char *heapRelationName,
        Oid                     heapoid;
        Oid                     indexoid;
        PredInfo   *predInfo;
-       bool            istemp = (get_temp_rel_by_name(heapRelationName) != NULL);
+       bool            istemp = (get_temp_rel_by_username(heapRelationName) != NULL);
        char       *temp_relname = NULL;
 
        /* ----------------
@@ -1182,9 +1182,6 @@ index_destroy(Oid indexId)
        }
        heap_close(attributeRelation, RowExclusiveLock);
 
-       /* does something only if it is a temp index */
-       remove_temp_relation(indexId);
-
        /* ----------------
         * fix INDEX relation
         * ----------------
@@ -1211,6 +1208,9 @@ index_destroy(Oid indexId)
        index_close(userindexRelation);
 
        RelationForgetRelation(indexId);
+
+       /* does something only if it is a temp index */
+       remove_temp_relation(indexId);
 }
 
 /* ----------------------------------------------------------------
index 19bbceb6b1efc3a13961d94f833a0d953dd0c8b0..bd5773e98e5345715f77d79b6b8bf77aa53eb9d6 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.65 1999/11/07 23:08:14 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.66 1999/11/16 04:13:56 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -622,7 +622,7 @@ BufferAlloc(Relation reln,
        }
 
        /* record the database name and relation name for this buffer */
-       strcpy(buf->sb_relname, RelationGetRelationName(reln));
+       strcpy(buf->sb_relname, RelationGetPhysicalRelationName(reln));
        strcpy(buf->sb_dbname, DatabaseName);
 
        INIT_BUFFERTAG(&(buf->tag), reln, blockNum);
index bf885e676d5170762757a528d758d468a5828b97..0cf2893d79c4aad5d73616c242bf2f22ca4ace9b 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.59 1999/11/07 23:08:19 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.60 1999/11/16 04:13:56 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -121,7 +121,7 @@ mdcreate(Relation reln)
        char       *path;
 
        Assert(reln->rd_unlinked && reln->rd_fd < 0);
-       path = relpath(RelationGetRelationName(reln));
+       path = relpath(RelationGetPhysicalRelationName(reln));
 #ifndef __CYGWIN32__
        fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL, 0600);
 #else
@@ -319,7 +319,7 @@ mdopen(Relation reln)
        int                     vfd;
 
        Assert(reln->rd_fd < 0);
-       path = relpath(RelationGetRelationName(reln));
+       path = relpath(RelationGetPhysicalRelationName(reln));
 
 #ifndef __CYGWIN32__
        fd = FileNameOpenFile(path, O_RDWR, 0600);
@@ -1011,7 +1011,7 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
                           *fullpath;
 
        /* be sure we have enough space for the '.segno', if any */
-       path = relpath(RelationGetRelationName(reln));
+       path = relpath(RelationGetPhysicalRelationName(reln));
 
        dofree = false;
        if (segno > 0)
index f780cf96b3970b146da726f0130fa76ee1b4a116..a0b971586027ab7ee0b17455858c9ba816ebaceb 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.76 1999/11/07 23:08:26 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.77 1999/11/16 04:13:58 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -962,7 +962,7 @@ formrdesc(char *relationName,
        relation->rd_rel = (Form_pg_class)
                palloc((Size) (sizeof(*relation->rd_rel)));
        MemSet(relation->rd_rel, 0, sizeof(FormData_pg_class));
-       strcpy(RelationGetRelationName(relation), relationName);
+       strcpy(RelationGetPhysicalRelationName(relation), relationName);
 
        /* ----------------
           initialize attribute tuple form
@@ -1177,7 +1177,7 @@ RelationNameGetRelation(char *relationName)
         *      we only index temp rels by their real names.
         * ----------------
         */
-       temprelname = get_temp_rel_by_name(relationName);
+       temprelname = get_temp_rel_by_username(relationName);
        if (temprelname)
                relationName = temprelname;
 
index 3cb393b802f8ae673eb7317c88525f16ebecece3..476fce4db8c424d5840d05b22c41753fdb5ca1f5 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.38 1999/11/01 02:29:25 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.39 1999/11/16 04:13:59 momjian Exp $
  *
  * NOTES
  *       These routines allow the parser/planner/executor to perform
@@ -472,7 +472,7 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
                char *nontemp_relname;
 
                if ((nontemp_relname =
-                        get_temp_rel_by_name(DatumGetPointer(key1))) != NULL)
+                        get_temp_rel_by_username(DatumGetPointer(key1))) != NULL)
                        key1 = PointerGetDatum(nontemp_relname);
        }
        
index 0119f9e59ecb532c2498e8777e72c88f6941817f..d57152d550d1a5f82314617414d3bc9a53fb0d21 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.15 1999/11/07 23:08:26 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.16 1999/11/16 04:13:59 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -150,7 +150,6 @@ remove_temp_relation(Oid relid)
                        prev = l;
                        l = lnext(l);
                }
-
        }
 
        MemoryContextSwitchTo(oldcxt);
@@ -203,7 +202,7 @@ invalidate_temp_relations(void)
 }
 
 char *
-get_temp_rel_by_name(char *user_relname)
+get_temp_rel_by_username(char *user_relname)
 {
        List       *l;
 
@@ -216,3 +215,22 @@ get_temp_rel_by_name(char *user_relname)
        }
        return NULL;
 }
+
+char *
+get_temp_rel_by_physicalname(char *relname)
+{
+       List       *l;
+
+       /* already physical, needed for bootstrapping temp tables */
+       if (strncmp(relname,"pg_temp.", strlen("pg_temp.")) == 0)
+               return relname;
+               
+       foreach(l, temp_rels)
+       {
+               TempTable  *temp_rel = lfirst(l);
+
+               if (strcmp(temp_rel->relname, relname) == 0)
+                       return temp_rel->user_relname;
+       }
+       return NULL;
+}
index b22ad294ceafc3a06c5c75269b2ac165e0a3c0a0..689d5d029504883d3c38864b4352414bf0027ab5 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: rel.h,v 1.29 1999/11/07 23:08:33 momjian Exp $
+ * $Id: rel.h,v 1.30 1999/11/16 04:14:03 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,7 +20,6 @@
 #include "rewrite/prs2lock.h"
 #include "storage/fd.h"
 
-
 /*
  * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
  * to declare them here so we can have a LockInfoData field in a Relation.
@@ -176,7 +175,26 @@ typedef Relation *RelationPtr;
  *
  *       Returns a Relation Name
  */
-#define RelationGetRelationName(relation) (NameStr((relation)->rd_rel->relname))
+/* added to prevent circular dependency.  bjm 1999/11/15 */
+char      *get_temp_rel_by_physicalname(char *relname);
+#define RelationGetRelationName(relation) \
+(\
+       (strncmp(RelationGetPhysicalRelationName(relation), \
+        "pg_temp.", strlen("pg_temp.")) != 0) \
+       ? \
+               RelationGetPhysicalRelationName(relation) \
+       : \
+               get_temp_rel_by_physicalname( \
+                       RelationGetPhysicalRelationName(relation)) \
+)
+
+
+/*
+ * RelationGetPhysicalRelationName
+ *
+ *       Returns a Relation Name
+ */
+#define RelationGetPhysicalRelationName(relation) (NameStr((relation)->rd_rel->relname))
 
 /*
  * RelationGetNumberOfAttributes
index 248a6e134e0dbb5cd2e46f22378164541fac2278..39e5157bd4bac13187892eb656362d833d97d33d 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: temprel.h,v 1.5 1999/09/04 19:55:50 momjian Exp $
+ * $Id: temprel.h,v 1.6 1999/11/16 04:14:03 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,6 +19,7 @@ void          create_temp_relation(char *relname, HeapTuple pg_class_tuple);
 void           remove_all_temp_relations(void);
 void           invalidate_temp_relations(void);
 void           remove_temp_relation(Oid relid);
-char      *get_temp_rel_by_name(char *user_relname);
+char      *get_temp_rel_by_username(char *user_relname);
+char      *get_temp_rel_by_physicalname(char *relname);
 
 #endif  /* TEMPREL_H */