Thanks to Tom Lane for ideas.
*
*
* 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
* ----------------
*/
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)
/* 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 */
}
/* ----------------
- * 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
{
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.
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().
* ----------------
*/
RelationForgetRelation(rid);
+
+ if (istemp)
+ remove_temp_relation(rid);
}
/*
*
*
* 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
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);
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;
/* ----------------
}
heap_close(attributeRelation, RowExclusiveLock);
- /* does something only if it is a temp index */
- remove_temp_relation(indexId);
-
/* ----------------
* fix INDEX relation
* ----------------
index_close(userindexRelation);
RelationForgetRelation(indexId);
+
+ /* does something only if it is a temp index */
+ remove_temp_relation(indexId);
}
/* ----------------------------------------------------------------
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
}
/* 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);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
int vfd;
Assert(reln->rd_fd < 0);
- path = relpath(RelationGetRelationName(reln));
+ path = relpath(RelationGetPhysicalRelationName(reln));
#ifndef __CYGWIN32__
fd = FileNameOpenFile(path, O_RDWR, 0600);
*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)
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
* 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;
*
*
* 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
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);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
prev = l;
l = lnext(l);
}
-
}
MemoryContextSwitchTo(oldcxt);
}
char *
-get_temp_rel_by_name(char *user_relname)
+get_temp_rel_by_username(char *user_relname)
{
List *l;
}
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;
+}
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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.
*
* 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
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 */