mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Small cleanup of temp-table handling. Disallow creation of a non-temp
table that inherits from a temp table. Make sure the right things happen if one creates a temp table, creates another temp that inherits from it, then renames the first one. (Previously, system would end up trying to delete the temp tables in the wrong order.)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.113 2000/12/05 19:57:55 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.114 2000/12/22 23:12:05 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The PerformAddAttribute() code, like most of the relation
|
||||
@@ -1237,10 +1237,9 @@ AlterTableAddConstraint(char *relationName,
|
||||
int i;
|
||||
bool found = false;
|
||||
|
||||
if (get_temp_rel_by_username(fkconstraint->pktable_name)!=NULL &&
|
||||
get_temp_rel_by_username(relationName)==NULL) {
|
||||
if (is_temp_rel_name(fkconstraint->pktable_name) &&
|
||||
!is_temp_rel_name(relationName))
|
||||
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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.68 2000/12/14 00:41:09 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.69 2000/12/22 23:12:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,8 +24,9 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/creatinh.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/temprel.h"
|
||||
|
||||
/* ----------------
|
||||
* local stuff
|
||||
@@ -34,7 +35,7 @@
|
||||
|
||||
static int checkAttrExists(const char *attributeName,
|
||||
const char *attributeType, List *schema);
|
||||
static List *MergeAttributes(List *schema, List *supers,
|
||||
static List *MergeAttributes(List *schema, List *supers, bool istemp,
|
||||
List **supOids, List **supconstr);
|
||||
static void StoreCatalogInheritance(Oid relationId, List *supers);
|
||||
static void setRelhassubclassInRelation(Oid relationId, bool relhassubclass);
|
||||
@@ -71,7 +72,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
|
||||
* including inherited attributes.
|
||||
* ----------------
|
||||
*/
|
||||
schema = MergeAttributes(schema, stmt->inhRelnames,
|
||||
schema = MergeAttributes(schema, stmt->inhRelnames, stmt->istemp,
|
||||
&inheritOids, &old_constraints);
|
||||
|
||||
numberOfAttributes = length(schema);
|
||||
@@ -283,6 +284,7 @@ change_varattnos_of_a_node(Node *node, const AttrNumber *newattno)
|
||||
* 'schema' is the column/attribute definition for the table. (It's a list
|
||||
* of ColumnDef's.) It is destructively changed.
|
||||
* 'supers' is a list of names (as Value objects) of parent relations.
|
||||
* 'istemp' is TRUE if we are creating a temp relation.
|
||||
*
|
||||
* Output arguments:
|
||||
* 'supOids' receives an integer list of the OIDs of the parent relations.
|
||||
@@ -311,7 +313,7 @@ change_varattnos_of_a_node(Node *node, const AttrNumber *newattno)
|
||||
* stud_emp {7:percent}
|
||||
*/
|
||||
static List *
|
||||
MergeAttributes(List *schema, List *supers,
|
||||
MergeAttributes(List *schema, List *supers, bool istemp,
|
||||
List **supOids, List **supconstr)
|
||||
{
|
||||
List *entry;
|
||||
@@ -378,6 +380,9 @@ MergeAttributes(List *schema, List *supers,
|
||||
|
||||
if (relation->rd_rel->relkind != RELKIND_RELATION)
|
||||
elog(ERROR, "CREATE TABLE: inherited relation \"%s\" is not a table", name);
|
||||
/* Permanent rels cannot inherit from temporary ones */
|
||||
if (!istemp && is_temp_rel_name(name))
|
||||
elog(ERROR, "CREATE TABLE: cannot inherit from temp relation \"%s\"", name);
|
||||
|
||||
parentOids = lappendi(parentOids, relation->rd_id);
|
||||
setRelhassubclassInRelation(relation->rd_id, true);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.178 2000/12/22 00:51:53 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.179 2000/12/22 23:12:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -274,8 +274,8 @@ getrels(NameData *VacRelP)
|
||||
char *nontemp_relname;
|
||||
|
||||
/* We must re-map temp table names bjm 2000-04-06 */
|
||||
if ((nontemp_relname =
|
||||
get_temp_rel_by_username(NameStr(*VacRelP))) == NULL)
|
||||
nontemp_relname = get_temp_rel_by_username(NameStr(*VacRelP));
|
||||
if (nontemp_relname == NULL)
|
||||
nontemp_relname = NameStr(*VacRelP);
|
||||
|
||||
ScanKeyEntryInitialize(&key, 0x0, Anum_pg_class_relname,
|
||||
|
||||
Reference in New Issue
Block a user