Commit dc5c7713 authored by Bruce Momjian's avatar Bruce Momjian

Commit to make clearer distinction for temp names and real names.

Thanks to Tom Lane for ideas.
parent bf5d51e7
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 * INTERFACE ROUTINES
...@@ -290,7 +290,7 @@ heap_create(char *relname, ...@@ -290,7 +290,7 @@ heap_create(char *relname,
* ---------------- * ----------------
*/ */
MemSet((char *) rel->rd_rel, 0, sizeof *rel->rd_rel); 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->relkind = RELKIND_UNCATALOGED;
rel->rd_rel->relnatts = natts; rel->rd_rel->relnatts = natts;
if (tupDesc->constr) if (tupDesc->constr)
...@@ -798,7 +798,7 @@ heap_create_with_catalog(char *relname, ...@@ -798,7 +798,7 @@ heap_create_with_catalog(char *relname,
/* temp tables can mask non-temp tables */ /* temp tables can mask non-temp tables */
if ((!istemp && RelnameFindRelid(relname)) || 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); elog(ERROR, "Relation '%s' already exists", relname);
/* save user relation name because heap_create changes it */ /* save user relation name because heap_create changes it */
...@@ -810,7 +810,7 @@ heap_create_with_catalog(char *relname, ...@@ -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 * creation. Uniqueness will be really checked by unique
* indexes of system tables but we couldn't check it here. * indexes of system tables but we couldn't check it here.
* We have to pospone to create the disk file for this * We have to pospone to create the disk file for this
...@@ -1448,7 +1448,7 @@ heap_destroy_with_catalog(char *relname) ...@@ -1448,7 +1448,7 @@ heap_destroy_with_catalog(char *relname)
{ {
Relation rel; Relation rel;
Oid rid; 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. * Open and lock the relation.
...@@ -1518,9 +1518,6 @@ heap_destroy_with_catalog(char *relname) ...@@ -1518,9 +1518,6 @@ heap_destroy_with_catalog(char *relname)
DeleteComments(RelationGetRelid(rel)); DeleteComments(RelationGetRelid(rel));
if (istemp)
remove_temp_relation(rid);
/* ---------------- /* ----------------
* delete type tuple. here we want to see the effects * delete type tuple. here we want to see the effects
* of the deletions we just did, so we use setheapoverride(). * of the deletions we just did, so we use setheapoverride().
...@@ -1565,6 +1562,9 @@ heap_destroy_with_catalog(char *relname) ...@@ -1565,6 +1562,9 @@ heap_destroy_with_catalog(char *relname)
* ---------------- * ----------------
*/ */
RelationForgetRelation(rid); RelationForgetRelation(rid);
if (istemp)
remove_temp_relation(rid);
} }
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 * INTERFACE ROUTINES
...@@ -120,7 +120,7 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName, bool istemp) ...@@ -120,7 +120,7 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName, bool istemp)
indoid = RelnameFindRelid(indexRelationName); indoid = RelnameFindRelid(indexRelationName);
if ((!istemp && OidIsValid(indoid)) || 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", elog(ERROR, "Cannot create index: '%s' already exists",
indexRelationName); indexRelationName);
...@@ -948,7 +948,7 @@ index_create(char *heapRelationName, ...@@ -948,7 +948,7 @@ index_create(char *heapRelationName,
Oid heapoid; Oid heapoid;
Oid indexoid; Oid indexoid;
PredInfo *predInfo; PredInfo *predInfo;
bool istemp = (get_temp_rel_by_name(heapRelationName) != NULL); bool istemp = (get_temp_rel_by_username(heapRelationName) != NULL);
char *temp_relname = NULL; char *temp_relname = NULL;
/* ---------------- /* ----------------
...@@ -1182,9 +1182,6 @@ index_destroy(Oid indexId) ...@@ -1182,9 +1182,6 @@ index_destroy(Oid indexId)
} }
heap_close(attributeRelation, RowExclusiveLock); heap_close(attributeRelation, RowExclusiveLock);
/* does something only if it is a temp index */
remove_temp_relation(indexId);
/* ---------------- /* ----------------
* fix INDEX relation * fix INDEX relation
* ---------------- * ----------------
...@@ -1211,6 +1208,9 @@ index_destroy(Oid indexId) ...@@ -1211,6 +1208,9 @@ index_destroy(Oid indexId)
index_close(userindexRelation); index_close(userindexRelation);
RelationForgetRelation(indexId); RelationForgetRelation(indexId);
/* does something only if it is a temp index */
remove_temp_relation(indexId);
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -622,7 +622,7 @@ BufferAlloc(Relation reln,
} }
/* record the database name and relation name for this buffer */ /* 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); strcpy(buf->sb_dbname, DatabaseName);
INIT_BUFFERTAG(&(buf->tag), reln, blockNum); INIT_BUFFERTAG(&(buf->tag), reln, blockNum);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -121,7 +121,7 @@ mdcreate(Relation reln)
char *path; char *path;
Assert(reln->rd_unlinked && reln->rd_fd < 0); Assert(reln->rd_unlinked && reln->rd_fd < 0);
path = relpath(RelationGetRelationName(reln)); path = relpath(RelationGetPhysicalRelationName(reln));
#ifndef __CYGWIN32__ #ifndef __CYGWIN32__
fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL, 0600); fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL, 0600);
#else #else
...@@ -319,7 +319,7 @@ mdopen(Relation reln) ...@@ -319,7 +319,7 @@ mdopen(Relation reln)
int vfd; int vfd;
Assert(reln->rd_fd < 0); Assert(reln->rd_fd < 0);
path = relpath(RelationGetRelationName(reln)); path = relpath(RelationGetPhysicalRelationName(reln));
#ifndef __CYGWIN32__ #ifndef __CYGWIN32__
fd = FileNameOpenFile(path, O_RDWR, 0600); fd = FileNameOpenFile(path, O_RDWR, 0600);
...@@ -1011,7 +1011,7 @@ _mdfd_openseg(Relation reln, int segno, int oflags) ...@@ -1011,7 +1011,7 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
*fullpath; *fullpath;
/* be sure we have enough space for the '.segno', if any */ /* be sure we have enough space for the '.segno', if any */
path = relpath(RelationGetRelationName(reln)); path = relpath(RelationGetPhysicalRelationName(reln));
dofree = false; dofree = false;
if (segno > 0) if (segno > 0)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -962,7 +962,7 @@ formrdesc(char *relationName,
relation->rd_rel = (Form_pg_class) relation->rd_rel = (Form_pg_class)
palloc((Size) (sizeof(*relation->rd_rel))); palloc((Size) (sizeof(*relation->rd_rel)));
MemSet(relation->rd_rel, 0, sizeof(FormData_pg_class)); MemSet(relation->rd_rel, 0, sizeof(FormData_pg_class));
strcpy(RelationGetRelationName(relation), relationName); strcpy(RelationGetPhysicalRelationName(relation), relationName);
/* ---------------- /* ----------------
initialize attribute tuple form initialize attribute tuple form
...@@ -1177,7 +1177,7 @@ RelationNameGetRelation(char *relationName) ...@@ -1177,7 +1177,7 @@ RelationNameGetRelation(char *relationName)
* we only index temp rels by their real names. * 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) if (temprelname)
relationName = temprelname; relationName = temprelname;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* These routines allow the parser/planner/executor to perform * These routines allow the parser/planner/executor to perform
...@@ -472,7 +472,7 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */ ...@@ -472,7 +472,7 @@ SearchSysCacheTuple(int cacheId,/* cache selection code */
char *nontemp_relname; char *nontemp_relname;
if ((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); key1 = PointerGetDatum(nontemp_relname);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -150,7 +150,6 @@ remove_temp_relation(Oid relid)
prev = l; prev = l;
l = lnext(l); l = lnext(l);
} }
} }
MemoryContextSwitchTo(oldcxt); MemoryContextSwitchTo(oldcxt);
...@@ -203,7 +202,7 @@ invalidate_temp_relations(void) ...@@ -203,7 +202,7 @@ invalidate_temp_relations(void)
} }
char * char *
get_temp_rel_by_name(char *user_relname) get_temp_rel_by_username(char *user_relname)
{ {
List *l; List *l;
...@@ -216,3 +215,22 @@ get_temp_rel_by_name(char *user_relname) ...@@ -216,3 +215,22 @@ get_temp_rel_by_name(char *user_relname)
} }
return NULL; 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;
}
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 @@ ...@@ -20,7 +20,6 @@
#include "rewrite/prs2lock.h" #include "rewrite/prs2lock.h"
#include "storage/fd.h" #include "storage/fd.h"
/* /*
* LockRelId and LockInfo really belong to lmgr.h, but it's more convenient * 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. * to declare them here so we can have a LockInfoData field in a Relation.
...@@ -176,7 +175,26 @@ typedef Relation *RelationPtr; ...@@ -176,7 +175,26 @@ typedef Relation *RelationPtr;
* *
* Returns a Relation Name * 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 * RelationGetNumberOfAttributes
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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); ...@@ -19,6 +19,7 @@ void create_temp_relation(char *relname, HeapTuple pg_class_tuple);
void remove_all_temp_relations(void); void remove_all_temp_relations(void);
void invalidate_temp_relations(void); void invalidate_temp_relations(void);
void remove_temp_relation(Oid relid); 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 */ #endif /* TEMPREL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment