mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Reimplement temp tables using schemas. The temp table map is history;
temp table entries in pg_class have the names the user would expect.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.75 2002/03/29 22:10:33 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.76 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -35,12 +35,10 @@
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
|
||||
static Oid copy_heap(Oid OIDOldHeap, char *NewName, bool istemp);
|
||||
static void copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName,
|
||||
bool istemp);
|
||||
static Oid copy_heap(Oid OIDOldHeap, char *NewName);
|
||||
static void copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName);
|
||||
static void rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
|
||||
|
||||
/*
|
||||
@@ -63,7 +61,6 @@ cluster(RangeVar *oldrelation, char *oldindexname)
|
||||
OIDNewHeap;
|
||||
Relation OldHeap,
|
||||
OldIndex;
|
||||
bool istemp;
|
||||
char NewHeapName[NAMEDATALEN];
|
||||
char NewIndexName[NAMEDATALEN];
|
||||
RangeVar *NewHeap;
|
||||
@@ -76,8 +73,6 @@ cluster(RangeVar *oldrelation, char *oldindexname)
|
||||
OldHeap = heap_openrv(oldrelation, AccessExclusiveLock);
|
||||
OIDOldHeap = RelationGetRelid(OldHeap);
|
||||
|
||||
istemp = is_temp_rel_name(oldrelation->relname);
|
||||
|
||||
/*
|
||||
* The index is expected to be in the same namespace as the relation.
|
||||
*/
|
||||
@@ -105,7 +100,7 @@ cluster(RangeVar *oldrelation, char *oldindexname)
|
||||
*/
|
||||
snprintf(NewHeapName, NAMEDATALEN, "temp_%u", OIDOldHeap);
|
||||
|
||||
OIDNewHeap = copy_heap(OIDOldHeap, NewHeapName, istemp);
|
||||
OIDNewHeap = copy_heap(OIDOldHeap, NewHeapName);
|
||||
|
||||
/* We do not need CommandCounterIncrement() because copy_heap did it. */
|
||||
|
||||
@@ -120,7 +115,7 @@ cluster(RangeVar *oldrelation, char *oldindexname)
|
||||
/* Create new index over the tuples of the new heap. */
|
||||
snprintf(NewIndexName, NAMEDATALEN, "temp_%u", OIDOldIndex);
|
||||
|
||||
copy_index(OIDOldIndex, OIDNewHeap, NewIndexName, istemp);
|
||||
copy_index(OIDOldIndex, OIDNewHeap, NewIndexName);
|
||||
|
||||
CommandCounterIncrement();
|
||||
|
||||
@@ -145,7 +140,7 @@ cluster(RangeVar *oldrelation, char *oldindexname)
|
||||
}
|
||||
|
||||
static Oid
|
||||
copy_heap(Oid OIDOldHeap, char *NewName, bool istemp)
|
||||
copy_heap(Oid OIDOldHeap, char *NewName)
|
||||
{
|
||||
TupleDesc OldHeapDesc,
|
||||
tupdesc;
|
||||
@@ -166,7 +161,6 @@ copy_heap(Oid OIDOldHeap, char *NewName, bool istemp)
|
||||
tupdesc,
|
||||
OldHeap->rd_rel->relkind,
|
||||
OldHeap->rd_rel->relhasoids,
|
||||
istemp,
|
||||
allowSystemTableMods);
|
||||
|
||||
/*
|
||||
@@ -188,7 +182,7 @@ copy_heap(Oid OIDOldHeap, char *NewName, bool istemp)
|
||||
}
|
||||
|
||||
static void
|
||||
copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName, bool istemp)
|
||||
copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName)
|
||||
{
|
||||
Relation OldIndex,
|
||||
NewHeap;
|
||||
@@ -209,7 +203,6 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName, bool istemp)
|
||||
indexInfo,
|
||||
OldIndex->rd_rel->relam,
|
||||
OldIndex->rd_index->indclass,
|
||||
istemp,
|
||||
OldIndex->rd_index->indisprimary,
|
||||
allowSystemTableMods);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.168 2002/03/30 01:02:41 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.169 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The PerformAddAttribute() code, like most of the relation
|
||||
@@ -55,7 +55,7 @@
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
|
||||
static void drop_default(Oid relid, int16 attnum);
|
||||
static bool needs_toast_table(Relation rel);
|
||||
@@ -1344,20 +1344,27 @@ AlterTableAddConstraint(Oid myrelid,
|
||||
List *list;
|
||||
int count;
|
||||
|
||||
if (is_temp_rel_name(fkconstraint->pktable->relname) &&
|
||||
!is_temp_rel_name(RelationGetRelationName(rel)))
|
||||
elog(ERROR, "ALTER TABLE / ADD CONSTRAINT: Unable to reference temporary table from permanent table constraint.");
|
||||
|
||||
/*
|
||||
* Grab an exclusive lock on the pk table, so that
|
||||
* someone doesn't delete rows out from under us.
|
||||
*
|
||||
* XXX wouldn't a lesser lock be sufficient?
|
||||
*/
|
||||
|
||||
pkrel = heap_openrv(fkconstraint->pktable,
|
||||
AccessExclusiveLock);
|
||||
|
||||
/*
|
||||
* Validity checks
|
||||
*/
|
||||
if (pkrel->rd_rel->relkind != RELKIND_RELATION)
|
||||
elog(ERROR, "referenced table \"%s\" not a relation",
|
||||
fkconstraint->pktable->relname);
|
||||
|
||||
if (isTempNamespace(RelationGetNamespace(pkrel)) &&
|
||||
!isTempNamespace(RelationGetNamespace(rel)))
|
||||
elog(ERROR, "ALTER TABLE / ADD CONSTRAINT: Unable to reference temporary table from permanent table constraint.");
|
||||
|
||||
/* Don't need pkrel open anymore, but hold lock */
|
||||
heap_close(pkrel, NoLock);
|
||||
|
||||
/*
|
||||
@@ -1763,8 +1770,9 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
|
||||
toast_relid = heap_create_with_catalog(toast_relname,
|
||||
PG_TOAST_NAMESPACE,
|
||||
tupdesc,
|
||||
RELKIND_TOASTVALUE, false,
|
||||
false, true);
|
||||
RELKIND_TOASTVALUE,
|
||||
false,
|
||||
true);
|
||||
|
||||
/* make the toast relation visible, else index creation will fail */
|
||||
CommandCounterIncrement();
|
||||
@@ -1794,7 +1802,7 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
|
||||
|
||||
toast_idxid = index_create(toast_relid, toast_idxname, indexInfo,
|
||||
BTREE_AM_OID, classObjectId,
|
||||
false, true, true);
|
||||
true, true);
|
||||
|
||||
/*
|
||||
* Update toast rel's pg_class entry to show that it has an index. The
|
||||
@@ -1971,7 +1979,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
}
|
||||
|
||||
/* Create the schema's namespace */
|
||||
NamespaceCreate(schemaName);
|
||||
NamespaceCreate(schemaName, owner_userid);
|
||||
|
||||
/* Let commands in the schema-element-list know about the schema */
|
||||
CommandCounterIncrement();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.94 2002/03/29 22:10:33 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.95 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "parser/parse_type.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
|
||||
/* ----------------
|
||||
* local stuff
|
||||
@@ -157,11 +157,11 @@ DefineRelation(CreateStmt *stmt, char relkind)
|
||||
}
|
||||
}
|
||||
|
||||
relationId = heap_create_with_catalog(relname, namespaceId,
|
||||
relationId = heap_create_with_catalog(relname,
|
||||
namespaceId,
|
||||
descriptor,
|
||||
relkind,
|
||||
stmt->hasoids || parentHasOids,
|
||||
stmt->relation->istemp,
|
||||
allowSystemTableMods);
|
||||
|
||||
StoreCatalogInheritance(relationId, inheritOids);
|
||||
@@ -447,7 +447,7 @@ MergeAttributes(List *schema, List *supers, bool istemp,
|
||||
elog(ERROR, "CREATE TABLE: inherited relation \"%s\" is not a table",
|
||||
parent->relname);
|
||||
/* Permanent rels cannot inherit from temporary ones */
|
||||
if (!istemp && is_temp_rel_name(parent->relname))
|
||||
if (!istemp && isTempNamespace(RelationGetNamespace(relation)))
|
||||
elog(ERROR, "CREATE TABLE: cannot inherit from temp relation \"%s\"",
|
||||
parent->relname);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.65 2002/03/26 19:15:41 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.66 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
|
||||
#define IsFuncIndex(ATTR_LIST) (((IndexElem*)lfirst(ATTR_LIST))->args != NIL)
|
||||
@@ -74,7 +73,6 @@ DefineIndex(RangeVar *heapRelation,
|
||||
Oid *classObjectId;
|
||||
Oid accessMethodId;
|
||||
Oid relationId;
|
||||
bool istemp = is_temp_rel_name(heapRelation->relname);
|
||||
Relation rel;
|
||||
HeapTuple tuple;
|
||||
Form_pg_am accessMethodForm;
|
||||
@@ -191,7 +189,7 @@ DefineIndex(RangeVar *heapRelation,
|
||||
|
||||
index_create(relationId, indexRelationName,
|
||||
indexInfo, accessMethodId, classObjectId,
|
||||
istemp, primary, allowSystemTableMods);
|
||||
primary, allowSystemTableMods);
|
||||
|
||||
/*
|
||||
* We update the relation's pg_class tuple even if it already has
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.66 2002/03/29 19:06:07 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.67 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
|
||||
#define RI_TRIGGER_PK 1 /* is a trigger on the PK relation */
|
||||
@@ -270,13 +269,6 @@ renamerel(const RangeVar *relation, const char *newrelname)
|
||||
elog(ERROR, "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs",
|
||||
newrelname);
|
||||
|
||||
/*
|
||||
* Check for renaming a temp table, which only requires altering the
|
||||
* temp-table mapping, not the underlying table.
|
||||
*/
|
||||
if (rename_temp_relation(relation->relname, newrelname))
|
||||
return; /* all done... */
|
||||
|
||||
/*
|
||||
* Grab an exclusive lock on the target table or index, which we will
|
||||
* NOT release until end of transaction.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.109 2002/03/29 22:10:33 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.110 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -471,7 +471,7 @@ RelationRemoveTriggers(Relation rel)
|
||||
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tup);
|
||||
|
||||
elog(NOTICE, "DROP TABLE implicitly drops referential integrity trigger from table \"%s\"",
|
||||
get_temp_rel_by_physicalname(get_rel_name(pg_trigger->tgrelid)));
|
||||
get_rel_name(pg_trigger->tgrelid));
|
||||
|
||||
DropTrigger(pg_trigger->tgrelid, NameStr(pg_trigger->tgname));
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.219 2002/03/21 23:27:22 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.220 2002/03/31 06:26:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,8 +42,6 @@
|
||||
#include "utils/inval.h"
|
||||
#include "utils/relcache.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
#include "pgstat.h"
|
||||
|
||||
|
||||
@@ -351,16 +349,9 @@ getrels(Name VacRelP, const char *stmttype)
|
||||
* we could use the cache here, but it is clearer to use scankeys
|
||||
* for both vacuum cases, bjm 2000/01/19
|
||||
*/
|
||||
char *nontemp_relname;
|
||||
|
||||
/* We must re-map temp table names bjm 2000-04-06 */
|
||||
nontemp_relname = get_temp_rel_by_username(NameStr(*VacRelP));
|
||||
if (nontemp_relname == NULL)
|
||||
nontemp_relname = NameStr(*VacRelP);
|
||||
|
||||
ScanKeyEntryInitialize(&key, 0x0, Anum_pg_class_relname,
|
||||
F_NAMEEQ,
|
||||
PointerGetDatum(nontemp_relname));
|
||||
PointerGetDatum(NameStr(*VacRelP)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user