提交 cdeca5f5 编写于 作者: T Tom Lane

Make toast-table creation and deletion work somewhat reliably.

Don't go through pg_exec_query_dest(), but directly to the execution
routines.  Also, extend parameter lists so that there's no need to
change the global setting of allowSystemTableMods, a hack that was
certain to cause trouble in the event of any error.
上级 9cf32779
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.30 2000/06/18 22:43:51 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.31 2000/07/04 06:11:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -166,7 +166,7 @@ Boot_CreateStmt: ...@@ -166,7 +166,7 @@ Boot_CreateStmt:
puts("creating bootstrap relation"); puts("creating bootstrap relation");
tupdesc = CreateTupleDesc(numattr,attrtypes); tupdesc = CreateTupleDesc(numattr,attrtypes);
reldesc = heap_create(LexIDStr($3), tupdesc, reldesc = heap_create(LexIDStr($3), tupdesc,
false, true); false, true, true);
if (DebugMode) if (DebugMode)
puts("bootstrap relation created ok"); puts("bootstrap relation created ok");
} }
...@@ -177,7 +177,10 @@ Boot_CreateStmt: ...@@ -177,7 +177,10 @@ Boot_CreateStmt:
tupdesc = CreateTupleDesc(numattr,attrtypes); tupdesc = CreateTupleDesc(numattr,attrtypes);
id = heap_create_with_catalog(LexIDStr($3), id = heap_create_with_catalog(LexIDStr($3),
tupdesc, RELKIND_RELATION, false); tupdesc,
RELKIND_RELATION,
false,
true);
if (!Quiet) if (!Quiet)
printf("CREATED relation %s with OID %u\n", printf("CREATED relation %s with OID %u\n",
LexIDStr($3), id); LexIDStr($3), id);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.137 2000/07/03 23:09:27 wieck Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.138 2000/07/04 06:11:23 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -172,7 +172,8 @@ Relation ...@@ -172,7 +172,8 @@ Relation
heap_create(char *relname, heap_create(char *relname,
TupleDesc tupDesc, TupleDesc tupDesc,
bool istemp, bool istemp,
bool storage_create) bool storage_create,
bool allow_system_table_mods)
{ {
static unsigned int uniqueId = 0; static unsigned int uniqueId = 0;
...@@ -189,7 +190,7 @@ heap_create(char *relname, ...@@ -189,7 +190,7 @@ heap_create(char *relname,
*/ */
AssertArg(natts > 0); AssertArg(natts > 0);
if (relname && !allowSystemTableMods && if (relname && !allow_system_table_mods &&
IsSystemRelationName(relname) && IsNormalProcessingMode()) IsSystemRelationName(relname) && IsNormalProcessingMode())
{ {
elog(ERROR, "Illegal class name '%s'" elog(ERROR, "Illegal class name '%s'"
...@@ -744,7 +745,8 @@ Oid ...@@ -744,7 +745,8 @@ Oid
heap_create_with_catalog(char *relname, heap_create_with_catalog(char *relname,
TupleDesc tupdesc, TupleDesc tupdesc,
char relkind, char relkind,
bool istemp) bool istemp,
bool allow_system_table_mods)
{ {
Relation pg_class_desc; Relation pg_class_desc;
Relation new_rel_desc; Relation new_rel_desc;
...@@ -769,9 +771,9 @@ heap_create_with_catalog(char *relname, ...@@ -769,9 +771,9 @@ heap_create_with_catalog(char *relname,
(istemp && get_temp_rel_by_username(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 */
if (istemp) if (istemp)
{ {
/* save user relation name because heap_create changes it */
temp_relname = pstrdup(relname); /* save original value */ temp_relname = pstrdup(relname); /* save original value */
relname = palloc(NAMEDATALEN); relname = palloc(NAMEDATALEN);
strcpy(relname, temp_relname); /* heap_create will change this */ strcpy(relname, temp_relname); /* heap_create will change this */
...@@ -797,7 +799,8 @@ heap_create_with_catalog(char *relname, ...@@ -797,7 +799,8 @@ heap_create_with_catalog(char *relname,
* work of creating the disk file for the relation. * work of creating the disk file for the relation.
* ---------------- * ----------------
*/ */
new_rel_desc = heap_create(relname, tupdesc, istemp, false); new_rel_desc = heap_create(relname, tupdesc, istemp, false,
allow_system_table_mods);
new_rel_oid = new_rel_desc->rd_att->attrs[0]->attrelid; new_rel_oid = new_rel_desc->rd_att->attrs[0]->attrelid;
...@@ -1419,7 +1422,8 @@ DeleteTypeTuple(Relation rel) ...@@ -1419,7 +1422,8 @@ DeleteTypeTuple(Relation rel)
* -------------------------------- * --------------------------------
*/ */
void void
heap_drop_with_catalog(const char *relname) heap_drop_with_catalog(const char *relname,
bool allow_system_table_mods)
{ {
Relation rel; Relation rel;
Oid rid; Oid rid;
...@@ -1438,7 +1442,7 @@ heap_drop_with_catalog(const char *relname) ...@@ -1438,7 +1442,7 @@ heap_drop_with_catalog(const char *relname)
* ---------------- * ----------------
*/ */
/* allow temp of pg_class? Guess so. */ /* allow temp of pg_class? Guess so. */
if (!istemp && !allowSystemTableMods && if (!istemp && !allow_system_table_mods &&
IsSystemRelationName(RelationGetRelationName(rel))) IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation '%s' cannot be destroyed", elog(ERROR, "System relation '%s' cannot be destroyed",
RelationGetRelationName(rel)); RelationGetRelationName(rel));
...@@ -1546,15 +1550,9 @@ heap_drop_with_catalog(const char *relname) ...@@ -1546,15 +1550,9 @@ heap_drop_with_catalog(const char *relname)
if (has_toasttable) if (has_toasttable)
{ {
char toast_relname[NAMEDATALEN]; char toast_relname[NAMEDATALEN];
bool old_allow;
old_allow = allowSystemTableMods;
allowSystemTableMods = true;
sprintf(toast_relname, "pg_toast_%d", rid);
heap_drop_with_catalog(toast_relname);
allowSystemTableMods = old_allow; sprintf(toast_relname, "pg_toast_%u", rid);
heap_drop_with_catalog(toast_relname, true);
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.121 2000/06/30 07:04:17 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.122 2000/07/04 06:11:23 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -946,7 +946,8 @@ index_create(char *heapRelationName, ...@@ -946,7 +946,8 @@ index_create(char *heapRelationName,
Node *predicate, Node *predicate,
bool islossy, bool islossy,
bool unique, bool unique,
bool primary) bool primary,
bool allow_system_table_mods)
{ {
Relation heapRelation; Relation heapRelation;
Relation indexRelation; Relation indexRelation;
...@@ -989,9 +990,9 @@ index_create(char *heapRelationName, ...@@ -989,9 +990,9 @@ index_create(char *heapRelationName,
numatts, numatts,
attNums); attNums);
/* save user relation name because heap_create changes it */
if (istemp) if (istemp)
{ {
/* save user relation name because heap_create changes it */
temp_relname = pstrdup(indexRelationName); /* save original value */ temp_relname = pstrdup(indexRelationName); /* save original value */
indexRelationName = palloc(NAMEDATALEN); indexRelationName = palloc(NAMEDATALEN);
strcpy(indexRelationName, temp_relname); /* heap_create will strcpy(indexRelationName, temp_relname); /* heap_create will
...@@ -1003,7 +1004,7 @@ index_create(char *heapRelationName, ...@@ -1003,7 +1004,7 @@ index_create(char *heapRelationName,
* ---------------- * ----------------
*/ */
indexRelation = heap_create(indexRelationName, indexTupDesc, indexRelation = heap_create(indexRelationName, indexTupDesc,
istemp, false); istemp, false, allow_system_table_mods);
/* ---------------- /* ----------------
* construct the index relation descriptor * construct the index relation descriptor
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.56 2000/06/17 23:41:36 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.57 2000/07/04 06:11:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "commands/cluster.h" #include "commands/cluster.h"
#include "commands/rename.h" #include "commands/rename.h"
#include "miscadmin.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -140,7 +141,7 @@ cluster(char *oldrelname, char *oldindexname) ...@@ -140,7 +141,7 @@ cluster(char *oldrelname, char *oldindexname)
StartTransactionCommand(); StartTransactionCommand();
/* Destroy old heap (along with its index) and rename new. */ /* Destroy old heap (along with its index) and rename new. */
heap_drop_with_catalog(saveoldrelname); heap_drop_with_catalog(saveoldrelname, allowSystemTableMods);
CommitTransactionCommand(); CommitTransactionCommand();
StartTransactionCommand(); StartTransactionCommand();
...@@ -176,7 +177,8 @@ copy_heap(Oid OIDOldHeap) ...@@ -176,7 +177,8 @@ copy_heap(Oid OIDOldHeap)
tupdesc = CreateTupleDescCopy(OldHeapDesc); tupdesc = CreateTupleDescCopy(OldHeapDesc);
OIDNewHeap = heap_create_with_catalog(NewName, tupdesc, OIDNewHeap = heap_create_with_catalog(NewName, tupdesc,
RELKIND_RELATION, false); RELKIND_RELATION, false,
allowSystemTableMods);
if (!OidIsValid(OIDNewHeap)) if (!OidIsValid(OIDNewHeap))
elog(ERROR, "clusterheap: cannot create temporary heap relation\n"); elog(ERROR, "clusterheap: cannot create temporary heap relation\n");
...@@ -276,7 +278,8 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap) ...@@ -276,7 +278,8 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
(Node *) NULL, /* XXX where's the predicate? */ (Node *) NULL, /* XXX where's the predicate? */
Old_pg_index_Form->indislossy, Old_pg_index_Form->indislossy,
Old_pg_index_Form->indisunique, Old_pg_index_Form->indisunique,
Old_pg_index_Form->indisprimary); Old_pg_index_Form->indisprimary,
allowSystemTableMods);
setRelhasindexInplace(OIDNewHeap, true, false); setRelhasindexInplace(OIDNewHeap, true, false);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.82 2000/07/03 23:09:33 wieck Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.83 2000/07/04 06:11:27 tgl Exp $
* *
* NOTES * NOTES
* The PerformAddAttribute() code, like most of the relation * The PerformAddAttribute() code, like most of the relation
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
#include "catalog/catalog.h" #include "catalog/catalog.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/index.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_attrdef.h" #include "catalog/pg_attrdef.h"
#include "catalog/pg_opclass.h"
#include "commands/command.h" #include "commands/command.h"
#include "executor/spi.h" #include "executor/spi.h"
#include "catalog/heap.h" #include "catalog/heap.h"
...@@ -1184,22 +1186,18 @@ AlterTableCreateToastTable(const char *relationName) ...@@ -1184,22 +1186,18 @@ AlterTableCreateToastTable(const char *relationName)
Form_pg_attribute *att; Form_pg_attribute *att;
Relation class_rel; Relation class_rel;
Relation ridescs[Num_pg_class_indices]; Relation ridescs[Num_pg_class_indices];
Oid toast_relid = 2; Oid toast_relid;
Oid toast_idxid = 2; Oid toast_idxid;
bool has_toastable_attrs = false; bool has_toastable_attrs = false;
bool old_allow;
int i; int i;
char toast_relname[NAMEDATALEN]; char toast_relname[NAMEDATALEN];
char toast_idxname[NAMEDATALEN]; char toast_idxname[NAMEDATALEN];
char tmp_query[1024];
Relation toast_rel; Relation toast_rel;
AttrNumber attNums[1];
Oid classObjectId[1];
/* /*
* permissions checking. this would normally be done in utility.c, * permissions checking. XXX exactly what is appropriate here?
* but this particular routine is recursive.
*
* normally, only the owner of a class can change its schema.
*/ */
/* /*
if (!allowSystemTableMods && IsSystemRelationName(relationName)) if (!allowSystemTableMods && IsSystemRelationName(relationName))
...@@ -1215,7 +1213,7 @@ AlterTableCreateToastTable(const char *relationName) ...@@ -1215,7 +1213,7 @@ AlterTableCreateToastTable(const char *relationName)
* Grab an exclusive lock on the target table, which we will NOT * Grab an exclusive lock on the target table, which we will NOT
* release until end of transaction. * release until end of transaction.
*/ */
rel = heap_openr(relationName, RowExclusiveLock); rel = heap_openr(relationName, AccessExclusiveLock);
myrelid = RelationGetRelid(rel); myrelid = RelationGetRelid(rel);
/* /*
...@@ -1261,26 +1259,43 @@ AlterTableCreateToastTable(const char *relationName) ...@@ -1261,26 +1259,43 @@ AlterTableCreateToastTable(const char *relationName)
relationName); relationName);
/* /*
* Create the toast table and it's index * Create the toast table and its index
* This is bad and ugly, because we need to override */
* allowSystemTableMods in order to keep the toast sprintf(toast_relname, "pg_toast_%u", myrelid);
* table- and index-name out of the users namespace. sprintf(toast_idxname, "pg_toast_%u_idx", myrelid);
*/
sprintf(toast_relname, "pg_toast_%d", myrelid); /* this is pretty painful... need a tuple descriptor */
sprintf(toast_idxname, "pg_toast_%d_idx", myrelid); tupdesc = CreateTemplateTupleDesc(3);
TupleDescInitEntry(tupdesc, (AttrNumber) 1,
old_allow = allowSystemTableMods; "chunk_id",
allowSystemTableMods = true; OIDOID,
-1, 0, false);
sprintf(tmp_query, "create table \"%s\" (chunk_id oid, chunk_seq int4, chunk_data text)", TupleDescInitEntry(tupdesc, (AttrNumber) 2,
toast_relname); "chunk_seq",
pg_exec_query_dest(tmp_query, None, CurrentMemoryContext); INT4OID,
-1, 0, false);
sprintf(tmp_query, "create index \"%s\" on \"%s\" (chunk_id)", TupleDescInitEntry(tupdesc, (AttrNumber) 3,
toast_idxname, toast_relname); "chunk_data",
pg_exec_query_dest(tmp_query, None, CurrentMemoryContext); TEXTOID, /* XXX wouldn't BYTEAOID be better? */
-1, 0, false);
allowSystemTableMods = old_allow;
/* XXX use RELKIND_TOASTVALUE here? */
/* XXX what if owning relation is temp? need we mark toasttable too? */
heap_create_with_catalog(toast_relname, tupdesc, RELKIND_RELATION,
false, true);
/* make the toast relation visible, else index creation will fail */
CommandCounterIncrement();
/* create index on chunk_id */
attNums[0] = 1;
classObjectId[0] = OID_OPS_OID;
index_create(toast_relname, toast_idxname, NULL, NULL, BTREE_AM_OID,
1, attNums, classObjectId,
(Node *) NULL, false, false, false, true);
/* make the index visible in this transaction */
CommandCounterIncrement();
/* /*
* Get the OIDs of the newly created objects * Get the OIDs of the newly created objects
...@@ -1318,8 +1333,8 @@ AlterTableCreateToastTable(const char *relationName) ...@@ -1318,8 +1333,8 @@ AlterTableCreateToastTable(const char *relationName)
heap_freetuple(reltup); heap_freetuple(reltup);
heap_close(class_rel, RowExclusiveLock);
heap_close(rel, NoLock); heap_close(rel, NoLock);
heap_close(class_rel, NoLock);
} }
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
* *
* IDENTIFICATION * IDENTIFICATION
<<<<<<< creatinh.c <<<<<<< creatinh.c
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.61 2000/06/12 03:40:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.62 2000/07/04 06:11:27 tgl Exp $
======= =======
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.61 2000/06/12 03:40:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.62 2000/07/04 06:11:27 tgl Exp $
>>>>>>> 1.58 >>>>>>> 1.58
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "catalog/pg_ipl.h" #include "catalog/pg_ipl.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/creatinh.h" #include "commands/creatinh.h"
#include "miscadmin.h"
#include "utils/syscache.h" #include "utils/syscache.h"
/* ---------------- /* ----------------
...@@ -146,7 +147,8 @@ DefineRelation(CreateStmt *stmt, char relkind) ...@@ -146,7 +147,8 @@ DefineRelation(CreateStmt *stmt, char relkind)
} }
relationId = heap_create_with_catalog(relname, descriptor, relationId = heap_create_with_catalog(relname, descriptor,
relkind, stmt->istemp); relkind, stmt->istemp,
allowSystemTableMods);
StoreCatalogInheritance(relationId, inheritList); StoreCatalogInheritance(relationId, inheritList);
...@@ -224,7 +226,7 @@ void ...@@ -224,7 +226,7 @@ void
RemoveRelation(char *name) RemoveRelation(char *name)
{ {
AssertArg(name); AssertArg(name);
heap_drop_with_catalog(name); heap_drop_with_catalog(name, allowSystemTableMods);
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.32 2000/06/28 03:31:28 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.33 2000/07/04 06:11:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "access/genam.h" #include "access/genam.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/catalog.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/heap.h" #include "catalog/heap.h"
#include "catalog/index.h" #include "catalog/index.h"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_shadow.h" #include "catalog/pg_shadow.h"
#include "commands/defrem.h" #include "commands/defrem.h"
#include "miscadmin.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
...@@ -38,8 +40,6 @@ ...@@ -38,8 +40,6 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "miscadmin.h" /* ReindexDatabase() */
#include "catalog/catalog.h" /* ReindexDatabase() */
#define IsFuncIndex(ATTR_LIST) (((IndexElem*)lfirst(ATTR_LIST))->args != NIL) #define IsFuncIndex(ATTR_LIST) (((IndexElem*)lfirst(ATTR_LIST))->args != NIL)
...@@ -197,7 +197,7 @@ DefineIndex(char *heapRelationName, ...@@ -197,7 +197,7 @@ DefineIndex(char *heapRelationName,
accessMethodId, numberOfAttributes, attributeNumberA, accessMethodId, numberOfAttributes, attributeNumberA,
classObjectId, classObjectId,
(Node *) cnfPred, (Node *) cnfPred,
lossy, unique, primary); lossy, unique, primary, allowSystemTableMods);
} }
else else
{ {
...@@ -215,7 +215,7 @@ DefineIndex(char *heapRelationName, ...@@ -215,7 +215,7 @@ DefineIndex(char *heapRelationName,
accessMethodId, numberOfAttributes, attributeNumberA, accessMethodId, numberOfAttributes, attributeNumberA,
classObjectId, classObjectId,
(Node *) cnfPred, (Node *) cnfPred,
lossy, unique, primary); lossy, unique, primary, allowSystemTableMods);
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.49 2000/05/28 20:34:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.50 2000/07/04 06:11:29 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -236,7 +236,7 @@ AttributeAndRelationRemove(Oid typeOid) ...@@ -236,7 +236,7 @@ AttributeAndRelationRemove(Oid typeOid)
char *name; char *name;
name = NameStr(((Form_pg_class) GETSTRUCT(tup))->relname); name = NameStr(((Form_pg_class) GETSTRUCT(tup))->relname);
heap_drop_with_catalog(name); heap_drop_with_catalog(name, allowSystemTableMods);
} }
heap_endscan(scan); heap_endscan(scan);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: view.c,v 1.44 2000/06/30 07:06:05 tgl Exp $ * $Id: view.c,v 1.45 2000/07/04 06:11:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "catalog/heap.h" #include "catalog/heap.h"
#include "commands/creatinh.h" #include "commands/creatinh.h"
#include "commands/view.h" #include "commands/view.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "parser/parse_type.h" #include "parser/parse_type.h"
...@@ -296,5 +297,5 @@ RemoveView(char *viewName) ...@@ -296,5 +297,5 @@ RemoveView(char *viewName)
* We just have to drop the relation; the associated rules will * We just have to drop the relation; the associated rules will
* be cleaned up automatically. * be cleaned up automatically.
*/ */
heap_drop_with_catalog(viewName); heap_drop_with_catalog(viewName, allowSystemTableMods);
} }
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.118 2000/06/17 21:48:47 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.119 2000/07/04 06:11:33 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -877,8 +877,12 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) ...@@ -877,8 +877,12 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
*/ */
tupdesc = CreateTupleDescCopy(tupType); tupdesc = CreateTupleDescCopy(tupType);
intoRelationId = heap_create_with_catalog(intoName, intoRelationId =
tupdesc, RELKIND_RELATION, parseTree->isTemp); heap_create_with_catalog(intoName,
tupdesc,
RELKIND_RELATION,
parseTree->isTemp,
allowSystemTableMods);
FreeTupleDesc(tupdesc); FreeTupleDesc(tupdesc);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.33 2000/06/28 03:31:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.34 2000/07/04 06:11:37 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -136,7 +136,11 @@ PQexec(char *query) ...@@ -136,7 +136,11 @@ PQexec(char *query)
* pg_exec_query_dest will put the query results in a portal which will * pg_exec_query_dest will put the query results in a portal which will
* end up on the top of the portal stack. * end up on the top of the portal stack.
* *
* XXX memory context manipulation needs thought here. * XXX memory context manipulation is WRONG here --- the query needs
* to be executed in a context different from CurrentMemoryContext,
* perhaps a freshly created sub-context. If I were expecting that
* this code needs to work again, then I'd fix it. But actually I'm
* planning to rip out this entire module sometime soon... tgl 7/2000.
* ---------------- * ----------------
*/ */
pg_exec_query_dest(query, Local, CurrentMemoryContext); pg_exec_query_dest(query, Local, CurrentMemoryContext);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.72 2000/06/28 03:32:04 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.73 2000/07/04 06:11:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -137,7 +137,8 @@ inv_create(int flags) ...@@ -137,7 +137,8 @@ inv_create(int flags)
* be located on whatever storage manager the user requested. * be located on whatever storage manager the user requested.
*/ */
heap_create_with_catalog(objname, tupdesc, RELKIND_LOBJECT, false); heap_create_with_catalog(objname, tupdesc, RELKIND_LOBJECT,
false, false);
/* make the relation visible in this transaction */ /* make the relation visible in this transaction */
CommandCounterIncrement(); CommandCounterIncrement();
...@@ -165,7 +166,7 @@ inv_create(int flags) ...@@ -165,7 +166,7 @@ inv_create(int flags)
classObjectId[0] = INT4_OPS_OID; classObjectId[0] = INT4_OPS_OID;
index_create(objname, indname, NULL, NULL, BTREE_AM_OID, index_create(objname, indname, NULL, NULL, BTREE_AM_OID,
1, &attNums[0], &classObjectId[0], 1, &attNums[0], &classObjectId[0],
(Node *) NULL, false, false, false); (Node *) NULL, false, false, false, false);
/* make the index visible in this transaction */ /* make the index visible in this transaction */
CommandCounterIncrement(); CommandCounterIncrement();
...@@ -297,7 +298,7 @@ inv_drop(Oid lobjId) ...@@ -297,7 +298,7 @@ inv_drop(Oid lobjId)
* Since heap_drop_with_catalog will destroy the relcache entry, * Since heap_drop_with_catalog will destroy the relcache entry,
* there's no need to drop the refcount in this path. * there's no need to drop the refcount in this path.
*/ */
heap_drop_with_catalog(RelationGetRelationName(r)); heap_drop_with_catalog(RelationGetRelationName(r), false);
return 1; return 1;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.165 2000/07/03 20:48:37 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.166 2000/07/04 06:11:43 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -538,7 +538,7 @@ pg_plan_query(Query *querytree) ...@@ -538,7 +538,7 @@ pg_plan_query(Query *querytree)
* *
* parse_context references a context suitable for holding the * parse_context references a context suitable for holding the
* parse/rewrite trees (typically this will be QueryContext). * parse/rewrite trees (typically this will be QueryContext).
* This context must be longer-lived than the CurrentMemoryContext! * This context *must* be longer-lived than the CurrentMemoryContext!
* In fact, if the query string might contain BEGIN/COMMIT commands, * In fact, if the query string might contain BEGIN/COMMIT commands,
* parse_context had better outlive TopTransactionContext! * parse_context had better outlive TopTransactionContext!
* *
...@@ -559,6 +559,16 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -559,6 +559,16 @@ pg_exec_query_dest(char *query_string, /* string to execute */
List *querytree_list, List *querytree_list,
*querytree_item; *querytree_item;
/*
* If you called this routine with parse_context = CurrentMemoryContext,
* you blew it. They *must* be different, else the context reset
* at the bottom of the loop will destroy the querytree list.
* (We really ought to check that parse_context isn't a child of
* CurrentMemoryContext either, but that would take more cycles than
* it's likely to be worth.)
*/
Assert(parse_context != CurrentMemoryContext);
/* /*
* Switch to appropriate context for constructing parsetrees. * Switch to appropriate context for constructing parsetrees.
*/ */
...@@ -1404,7 +1414,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1404,7 +1414,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.165 $ $Date: 2000/07/03 20:48:37 $\n"); puts("$Revision: 1.166 $ $Date: 2000/07/04 06:11:43 $\n");
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.25 2000/06/28 03:32:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.26 2000/07/04 06:11:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "catalog/heap.h" #include "catalog/heap.h"
#include "catalog/index.h" #include "catalog/index.h"
#include "miscadmin.h"
#include "utils/catcache.h" #include "utils/catcache.h"
#include "utils/temprel.h" #include "utils/temprel.h"
...@@ -112,7 +113,7 @@ remove_all_temp_relations(void) ...@@ -112,7 +113,7 @@ remove_all_temp_relations(void)
/* safe from deallocation */ /* safe from deallocation */
strcpy(relname, temp_rel->user_relname); strcpy(relname, temp_rel->user_relname);
heap_drop_with_catalog(relname); heap_drop_with_catalog(relname, allowSystemTableMods);
} }
else else
index_drop(temp_rel->relid); index_drop(temp_rel->relid);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 2000, PostgreSQL Development Team * Copyright (c) 2000, PostgreSQL Development Team
* *
* $Id: tuptoaster.h,v 1.4 2000/07/04 00:04:03 tgl Exp $ * $Id: tuptoaster.h,v 1.5 2000/07/04 06:11:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,10 +34,6 @@ extern void heap_tuple_toast_attrs(Relation rel, ...@@ -34,10 +34,6 @@ extern void heap_tuple_toast_attrs(Relation rel,
extern varattrib *heap_tuple_untoast_attr(varattrib * attr); extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
extern void heap_create_toast_table(Oid new_reloid,
TupleDesc new_tupdesc, bool istemp);
#endif /* TUPLE_TOASTER_ACTIVE */ #endif /* TUPLE_TOASTER_ACTIVE */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: heap.h,v 1.30 2000/06/18 22:44:25 tgl Exp $ * $Id: heap.h,v 1.31 2000/07/04 06:11:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -26,13 +26,18 @@ typedef struct RawColumnDefault ...@@ -26,13 +26,18 @@ typedef struct RawColumnDefault
extern Oid RelnameFindRelid(const char *relname); extern Oid RelnameFindRelid(const char *relname);
extern Relation heap_create(char *relname, TupleDesc tupDesc, extern Relation heap_create(char *relname, TupleDesc tupDesc,
bool istemp, bool storage_create); bool istemp, bool storage_create,
bool allow_system_table_mods);
extern bool heap_storage_create(Relation rel); extern bool heap_storage_create(Relation rel);
extern Oid heap_create_with_catalog(char *relname, TupleDesc tupdesc, extern Oid heap_create_with_catalog(char *relname, TupleDesc tupdesc,
char relkind, bool istemp); char relkind, bool istemp,
bool allow_system_table_mods);
extern void heap_drop_with_catalog(const char *relname,
bool allow_system_table_mods);
extern void heap_drop_with_catalog(const char *relname);
extern void heap_truncate(char *relname); extern void heap_truncate(char *relname);
extern void AddRelationRawConstraints(Relation rel, extern void AddRelationRawConstraints(Relation rel,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: index.h,v 1.26 2000/06/30 07:04:06 tgl Exp $ * $Id: index.h,v 1.27 2000/07/04 06:11:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -37,7 +37,8 @@ extern void index_create(char *heapRelationName, ...@@ -37,7 +37,8 @@ extern void index_create(char *heapRelationName,
Node *predicate, Node *predicate,
bool islossy, bool islossy,
bool unique, bool unique,
bool primary); bool primary,
bool allow_system_table_mods);
extern void index_drop(Oid indexId); extern void index_drop(Oid indexId);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_opclass.h,v 1.33 2000/06/19 03:54:45 tgl Exp $ * $Id: pg_opclass.h,v 1.34 2000/07/04 06:11:54 tgl Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -74,6 +74,7 @@ DESCR(""); ...@@ -74,6 +74,7 @@ DESCR("");
#define INT4_OPS_OID 426 #define INT4_OPS_OID 426
DATA(insert OID = 427 ( oid_ops 26 )); DATA(insert OID = 427 ( oid_ops 26 ));
DESCR(""); DESCR("");
#define OID_OPS_OID 427
DATA(insert OID = 428 ( float4_ops 700 )); DATA(insert OID = 428 ( float4_ops 700 ));
DESCR(""); DESCR("");
DATA(insert OID = 429 ( char_ops 18 )); DATA(insert OID = 429 ( char_ops 18 ));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册