postgresql/src/backend/catalog/pg_namespace.c
Tom Lane 15fe086fba Restructure system-catalog index updating logic. Instead of having
hardwired lists of index names for each catalog, use the relcache's
mechanism for caching lists of OIDs of indexes of any table.  This
reduces the common case of updating system catalog indexes to a single
line, makes it much easier to add a new system index (in fact, you
can now do so on-the-fly if you want to), and as a nice side benefit
improves performance a little.  Per recent pghackers discussion.
2002-08-05 03:29:17 +00:00

76 lines
1.9 KiB
C

/*-------------------------------------------------------------------------
*
* pg_namespace.c
* routines to support manipulation of the pg_namespace relation
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.5 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/heapam.h"
#include "catalog/catname.h"
#include "catalog/indexing.h"
#include "catalog/pg_namespace.h"
#include "utils/builtins.h"
#include "utils/syscache.h"
/* ----------------
* NamespaceCreate
* ---------------
*/
Oid
NamespaceCreate(const char *nspName, int32 ownerSysId)
{
Relation nspdesc;
HeapTuple tup;
Oid nspoid;
char nulls[Natts_pg_namespace];
Datum values[Natts_pg_namespace];
NameData nname;
TupleDesc tupDesc;
int i;
/* sanity checks */
if (!nspName)
elog(ERROR, "no namespace name supplied");
/* make sure there is no existing namespace of same name */
if (SearchSysCacheExists(NAMESPACENAME,
PointerGetDatum(nspName),
0, 0, 0))
elog(ERROR, "namespace \"%s\" already exists", nspName);
/* initialize nulls and values */
for (i = 0; i < Natts_pg_namespace; i++)
{
nulls[i] = ' ';
values[i] = (Datum) NULL;
}
namestrcpy(&nname, nspName);
values[Anum_pg_namespace_nspname - 1] = NameGetDatum(&nname);
values[Anum_pg_namespace_nspowner - 1] = Int32GetDatum(ownerSysId);
nulls[Anum_pg_namespace_nspacl - 1] = 'n';
nspdesc = heap_openr(NamespaceRelationName, RowExclusiveLock);
tupDesc = nspdesc->rd_att;
tup = heap_formtuple(tupDesc, values, nulls);
nspoid = simple_heap_insert(nspdesc, tup);
Assert(OidIsValid(nspoid));
CatalogUpdateIndexes(nspdesc, tup);
heap_close(nspdesc, RowExclusiveLock);
return nspoid;
}