diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/cluster.c | 11 | ||||
-rw-r--r-- | src/backend/commands/command.c | 81 | ||||
-rw-r--r-- | src/backend/commands/creatinh.c | 10 | ||||
-rw-r--r-- | src/backend/commands/indexcmds.c | 10 | ||||
-rw-r--r-- | src/backend/commands/remove.c | 4 | ||||
-rw-r--r-- | src/backend/commands/view.c | 5 |
6 files changed, 71 insertions, 50 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 0fff922545c..38539707cd8 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -15,7 +15,7 @@ * * * 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 @@ #include "catalog/pg_proc.h" #include "commands/cluster.h" #include "commands/rename.h" +#include "miscadmin.h" #include "utils/builtins.h" #include "utils/syscache.h" @@ -140,7 +141,7 @@ cluster(char *oldrelname, char *oldindexname) StartTransactionCommand(); /* Destroy old heap (along with its index) and rename new. */ - heap_drop_with_catalog(saveoldrelname); + heap_drop_with_catalog(saveoldrelname, allowSystemTableMods); CommitTransactionCommand(); StartTransactionCommand(); @@ -176,7 +177,8 @@ copy_heap(Oid OIDOldHeap) tupdesc = CreateTupleDescCopy(OldHeapDesc); OIDNewHeap = heap_create_with_catalog(NewName, tupdesc, - RELKIND_RELATION, false); + RELKIND_RELATION, false, + allowSystemTableMods); if (!OidIsValid(OIDNewHeap)) elog(ERROR, "clusterheap: cannot create temporary heap relation\n"); @@ -276,7 +278,8 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap) (Node *) NULL, /* XXX where's the predicate? */ Old_pg_index_Form->indislossy, Old_pg_index_Form->indisunique, - Old_pg_index_Form->indisprimary); + Old_pg_index_Form->indisprimary, + allowSystemTableMods); setRelhasindexInplace(OIDNewHeap, true, false); diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index 595c09dc4ec..19c87104299 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * 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 * The PerformAddAttribute() code, like most of the relation @@ -21,8 +21,10 @@ #include "catalog/catalog.h" #include "catalog/catname.h" +#include "catalog/index.h" #include "catalog/indexing.h" #include "catalog/pg_attrdef.h" +#include "catalog/pg_opclass.h" #include "commands/command.h" #include "executor/spi.h" #include "catalog/heap.h" @@ -1184,22 +1186,18 @@ AlterTableCreateToastTable(const char *relationName) Form_pg_attribute *att; Relation class_rel; Relation ridescs[Num_pg_class_indices]; - Oid toast_relid = 2; - Oid toast_idxid = 2; + Oid toast_relid; + Oid toast_idxid; bool has_toastable_attrs = false; - bool old_allow; int i; - char toast_relname[NAMEDATALEN]; char toast_idxname[NAMEDATALEN]; - char tmp_query[1024]; Relation toast_rel; + AttrNumber attNums[1]; + Oid classObjectId[1]; /* - * permissions checking. this would normally be done in utility.c, - * but this particular routine is recursive. - * - * normally, only the owner of a class can change its schema. + * permissions checking. XXX exactly what is appropriate here? */ /* if (!allowSystemTableMods && IsSystemRelationName(relationName)) @@ -1215,7 +1213,7 @@ AlterTableCreateToastTable(const char *relationName) * Grab an exclusive lock on the target table, which we will NOT * release until end of transaction. */ - rel = heap_openr(relationName, RowExclusiveLock); + rel = heap_openr(relationName, AccessExclusiveLock); myrelid = RelationGetRelid(rel); /* @@ -1240,8 +1238,8 @@ AlterTableCreateToastTable(const char *relationName) * Get the pg_class tuple for the relation */ reltup = SearchSysCacheTuple(RELNAME, - PointerGetDatum(relationName), - 0, 0, 0); + PointerGetDatum(relationName), + 0, 0, 0); if (!HeapTupleIsValid(reltup)) elog(ERROR, "ALTER TABLE: relation \"%s\" not found", @@ -1261,26 +1259,43 @@ AlterTableCreateToastTable(const char *relationName) relationName); /* - * Create the toast table and it's index - * This is bad and ugly, because we need to override - * allowSystemTableMods in order to keep the toast - * table- and index-name out of the users namespace. + * Create the toast table and its index */ - sprintf(toast_relname, "pg_toast_%d", myrelid); - sprintf(toast_idxname, "pg_toast_%d_idx", myrelid); - - old_allow = allowSystemTableMods; - allowSystemTableMods = true; - - sprintf(tmp_query, "create table \"%s\" (chunk_id oid, chunk_seq int4, chunk_data text)", - toast_relname); - pg_exec_query_dest(tmp_query, None, CurrentMemoryContext); - - sprintf(tmp_query, "create index \"%s\" on \"%s\" (chunk_id)", - toast_idxname, toast_relname); - pg_exec_query_dest(tmp_query, None, CurrentMemoryContext); - - allowSystemTableMods = old_allow; + sprintf(toast_relname, "pg_toast_%u", myrelid); + sprintf(toast_idxname, "pg_toast_%u_idx", myrelid); + + /* this is pretty painful... need a tuple descriptor */ + tupdesc = CreateTemplateTupleDesc(3); + TupleDescInitEntry(tupdesc, (AttrNumber) 1, + "chunk_id", + OIDOID, + -1, 0, false); + TupleDescInitEntry(tupdesc, (AttrNumber) 2, + "chunk_seq", + INT4OID, + -1, 0, false); + TupleDescInitEntry(tupdesc, (AttrNumber) 3, + "chunk_data", + TEXTOID, /* XXX wouldn't BYTEAOID be better? */ + -1, 0, false); + + /* 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 @@ -1318,8 +1333,8 @@ AlterTableCreateToastTable(const char *relationName) heap_freetuple(reltup); + heap_close(class_rel, RowExclusiveLock); heap_close(rel, NoLock); - heap_close(class_rel, NoLock); } diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c index 401379f505c..1c49045330d 100644 --- a/src/backend/commands/creatinh.c +++ b/src/backend/commands/creatinh.c @@ -9,9 +9,9 @@ * * IDENTIFICATION <<<<<<< 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 * *------------------------------------------------------------------------- @@ -27,6 +27,7 @@ #include "catalog/pg_ipl.h" #include "catalog/pg_type.h" #include "commands/creatinh.h" +#include "miscadmin.h" #include "utils/syscache.h" /* ---------------- @@ -146,7 +147,8 @@ DefineRelation(CreateStmt *stmt, char relkind) } relationId = heap_create_with_catalog(relname, descriptor, - relkind, stmt->istemp); + relkind, stmt->istemp, + allowSystemTableMods); StoreCatalogInheritance(relationId, inheritList); @@ -224,7 +226,7 @@ void RemoveRelation(char *name) { AssertArg(name); - heap_drop_with_catalog(name); + heap_drop_with_catalog(name, allowSystemTableMods); } /* diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index bb45f01f673..1446aa8844b 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * 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 @@ #include "access/genam.h" #include "access/heapam.h" +#include "catalog/catalog.h" #include "catalog/catname.h" #include "catalog/heap.h" #include "catalog/index.h" @@ -28,6 +29,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_shadow.h" #include "commands/defrem.h" +#include "miscadmin.h" #include "optimizer/clauses.h" #include "optimizer/planmain.h" #include "optimizer/prep.h" @@ -38,8 +40,6 @@ #include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/syscache.h" -#include "miscadmin.h" /* ReindexDatabase() */ -#include "catalog/catalog.h" /* ReindexDatabase() */ #define IsFuncIndex(ATTR_LIST) (((IndexElem*)lfirst(ATTR_LIST))->args != NIL) @@ -197,7 +197,7 @@ DefineIndex(char *heapRelationName, accessMethodId, numberOfAttributes, attributeNumberA, classObjectId, (Node *) cnfPred, - lossy, unique, primary); + lossy, unique, primary, allowSystemTableMods); } else { @@ -215,7 +215,7 @@ DefineIndex(char *heapRelationName, accessMethodId, numberOfAttributes, attributeNumberA, classObjectId, (Node *) cnfPred, - lossy, unique, primary); + lossy, unique, primary, allowSystemTableMods); } /* diff --git a/src/backend/commands/remove.c b/src/backend/commands/remove.c index a90af396a05..75f3356289d 100644 --- a/src/backend/commands/remove.c +++ b/src/backend/commands/remove.c @@ -8,7 +8,7 @@ * * * 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) char *name; name = NameStr(((Form_pg_class) GETSTRUCT(tup))->relname); - heap_drop_with_catalog(name); + heap_drop_with_catalog(name, allowSystemTableMods); } heap_endscan(scan); } diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index 3b1bfedea23..8503eb3a7eb 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * 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 @@ #include "catalog/heap.h" #include "commands/creatinh.h" #include "commands/view.h" +#include "miscadmin.h" #include "nodes/makefuncs.h" #include "parser/parse_relation.h" #include "parser/parse_type.h" @@ -296,5 +297,5 @@ RemoveView(char *viewName) * We just have to drop the relation; the associated rules will * be cleaned up automatically. */ - heap_drop_with_catalog(viewName); + heap_drop_with_catalog(viewName, allowSystemTableMods); } |