*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
puts("creating bootstrap relation");
tupdesc = CreateTupleDesc(numattr,attrtypes);
reldesc = heap_create(LexIDStr($3), tupdesc,
- false, true);
+ false, true, true);
if (DebugMode)
puts("bootstrap relation created ok");
}
tupdesc = CreateTupleDesc(numattr,attrtypes);
id = heap_create_with_catalog(LexIDStr($3),
- tupdesc, RELKIND_RELATION, false);
+ tupdesc,
+ RELKIND_RELATION,
+ false,
+ true);
if (!Quiet)
printf("CREATED relation %s with OID %u\n",
LexIDStr($3), id);
*
*
* 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
heap_create(char *relname,
TupleDesc tupDesc,
bool istemp,
- bool storage_create)
+ bool storage_create,
+ bool allow_system_table_mods)
{
static unsigned int uniqueId = 0;
*/
AssertArg(natts > 0);
- if (relname && !allowSystemTableMods &&
+ if (relname && !allow_system_table_mods &&
IsSystemRelationName(relname) && IsNormalProcessingMode())
{
elog(ERROR, "Illegal class name '%s'"
heap_create_with_catalog(char *relname,
TupleDesc tupdesc,
char relkind,
- bool istemp)
+ bool istemp,
+ bool allow_system_table_mods)
{
Relation pg_class_desc;
Relation new_rel_desc;
(istemp && get_temp_rel_by_username(relname) != NULL))
elog(ERROR, "Relation '%s' already exists", relname);
- /* save user relation name because heap_create changes it */
if (istemp)
{
+ /* save user relation name because heap_create changes it */
temp_relname = pstrdup(relname); /* save original value */
relname = palloc(NAMEDATALEN);
strcpy(relname, temp_relname); /* heap_create will change this */
* 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;
* --------------------------------
*/
void
-heap_drop_with_catalog(const char *relname)
+heap_drop_with_catalog(const char *relname,
+ bool allow_system_table_mods)
{
Relation rel;
Oid rid;
* ----------------
*/
/* allow temp of pg_class? Guess so. */
- if (!istemp && !allowSystemTableMods &&
+ if (!istemp && !allow_system_table_mods &&
IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "System relation '%s' cannot be destroyed",
RelationGetRelationName(rel));
if (has_toasttable)
{
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);
}
}
*
*
* 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
Node *predicate,
bool islossy,
bool unique,
- bool primary)
+ bool primary,
+ bool allow_system_table_mods)
{
Relation heapRelation;
Relation indexRelation;
numatts,
attNums);
- /* save user relation name because heap_create changes it */
if (istemp)
{
- temp_relname = pstrdup(indexRelationName); /* save original value */
+ /* save user relation name because heap_create changes it */
+ temp_relname = pstrdup(indexRelationName); /* save original value */
indexRelationName = palloc(NAMEDATALEN);
- strcpy(indexRelationName, temp_relname); /* heap_create will
- * change this */
+ strcpy(indexRelationName, temp_relname); /* heap_create will
+ * change this */
}
/* ----------------
* ----------------
*/
indexRelation = heap_create(indexRelationName, indexTupDesc,
- istemp, false);
+ istemp, false, allow_system_table_mods);
/* ----------------
* construct the index relation descriptor
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "catalog/pg_proc.h"
#include "commands/cluster.h"
#include "commands/rename.h"
+#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/syscache.h"
StartTransactionCommand();
/* Destroy old heap (along with its index) and rename new. */
- heap_drop_with_catalog(saveoldrelname);
+ heap_drop_with_catalog(saveoldrelname, allowSystemTableMods);
CommitTransactionCommand();
StartTransactionCommand();
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");
(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);
*
*
* 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
#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"
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))
* 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);
/*
* 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",
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
heap_freetuple(reltup);
+ heap_close(class_rel, RowExclusiveLock);
heap_close(rel, NoLock);
- heap_close(class_rel, NoLock);
}
*
* 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
*
*-------------------------------------------------------------------------
#include "catalog/pg_ipl.h"
#include "catalog/pg_type.h"
#include "commands/creatinh.h"
+#include "miscadmin.h"
#include "utils/syscache.h"
/* ----------------
}
relationId = heap_create_with_catalog(relname, descriptor,
- relkind, stmt->istemp);
+ relkind, stmt->istemp,
+ allowSystemTableMods);
StoreCatalogInheritance(relationId, inheritList);
RemoveRelation(char *name)
{
AssertArg(name);
- heap_drop_with_catalog(name);
+ heap_drop_with_catalog(name, allowSystemTableMods);
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "access/genam.h"
#include "access/heapam.h"
+#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#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"
#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)
accessMethodId, numberOfAttributes, attributeNumberA,
classObjectId,
(Node *) cnfPred,
- lossy, unique, primary);
+ lossy, unique, primary, allowSystemTableMods);
}
else
{
accessMethodId, numberOfAttributes, attributeNumberA,
classObjectId,
(Node *) cnfPred,
- lossy, unique, primary);
+ lossy, unique, primary, allowSystemTableMods);
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
char *name;
name = NameStr(((Form_pg_class) GETSTRUCT(tup))->relname);
- heap_drop_with_catalog(name);
+ heap_drop_with_catalog(name, allowSystemTableMods);
}
heap_endscan(scan);
}
* 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 $
*
*-------------------------------------------------------------------------
*/
#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"
* 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);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
tupdesc = CreateTupleDescCopy(tupType);
- intoRelationId = heap_create_with_catalog(intoName,
- tupdesc, RELKIND_RELATION, parseTree->isTemp);
+ intoRelationId =
+ heap_create_with_catalog(intoName,
+ tupdesc,
+ RELKIND_RELATION,
+ parseTree->isTemp,
+ allowSystemTableMods);
FreeTupleDesc(tupdesc);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* pg_exec_query_dest will put the query results in a portal which will
* 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);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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 */
CommandCounterIncrement();
classObjectId[0] = INT4_OPS_OID;
index_create(objname, indname, NULL, NULL, BTREE_AM_OID,
1, &attNums[0], &classObjectId[0],
- (Node *) NULL, false, false, false);
+ (Node *) NULL, false, false, false, false);
/* make the index visible in this transaction */
CommandCounterIncrement();
* Since heap_drop_with_catalog will destroy the relcache entry,
* 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;
}
*
*
* 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
* this is the "main" module of the postgres backend and
*
* parse_context references a context suitable for holding the
* 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,
* parse_context had better outlive TopTransactionContext!
*
*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.
*/
oldcontext = MemoryContextSwitchTo(parse_context);
if (!IsUnderPostmaster)
{
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");
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "catalog/heap.h"
#include "catalog/index.h"
+#include "miscadmin.h"
#include "utils/catcache.h"
#include "utils/temprel.h"
/* safe from deallocation */
strcpy(relname, temp_rel->user_relname);
- heap_drop_with_catalog(relname);
+ heap_drop_with_catalog(relname, allowSystemTableMods);
}
else
index_drop(temp_rel->relid);
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 */
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* 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 $
*
*-------------------------------------------------------------------------
*/
extern Oid RelnameFindRelid(const char *relname);
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 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 AddRelationRawConstraints(Relation rel,
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* 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 $
*
*-------------------------------------------------------------------------
*/
Node *predicate,
bool islossy,
bool unique,
- bool primary);
+ bool primary,
+ bool allow_system_table_mods);
extern void index_drop(Oid indexId);
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* 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
* the genbki.sh script reads this file and generates .bki
#define INT4_OPS_OID 426
DATA(insert OID = 427 ( oid_ops 26 ));
DESCR("");
+#define OID_OPS_OID 427
DATA(insert OID = 428 ( float4_ops 700 ));
DESCR("");
DATA(insert OID = 429 ( char_ops 18 ));