mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Create the pg_namespace system catalog. Doesn't do much yet, but it's
there and CREATE SCHEMA will make entries in it...
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for catalog
|
||||
# Makefile for backend/catalog
|
||||
#
|
||||
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.37 2001/08/25 18:52:41 tgl Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.38 2002/03/22 21:34:43 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -11,8 +11,8 @@ top_builddir = ../../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
|
||||
OBJS = catalog.o heap.o index.o indexing.o aclchk.o \
|
||||
pg_aggregate.o pg_largeobject.o pg_operator.o pg_proc.o \
|
||||
pg_type.o
|
||||
pg_aggregate.o pg_largeobject.o pg_namespace.o \
|
||||
pg_operator.o pg_proc.o pg_type.o
|
||||
|
||||
BKIFILES = postgres.bki postgres.description
|
||||
|
||||
@@ -31,7 +31,7 @@ POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
|
||||
pg_operator.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
|
||||
pg_language.h pg_largeobject.h pg_aggregate.h pg_statistic.h \
|
||||
pg_rewrite.h pg_trigger.h pg_listener.h pg_description.h \
|
||||
pg_database.h pg_shadow.h pg_group.h indexing.h \
|
||||
pg_namespace.h pg_database.h pg_shadow.h pg_group.h indexing.h \
|
||||
)
|
||||
|
||||
pg_includes := $(sort -I$(top_srcdir)/src/include -I$(top_builddir)/src/include)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.83 2002/02/19 20:11:11 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.84 2002/03/22 21:34:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -57,6 +57,8 @@ char *Name_pg_language_indices[Num_pg_language_indices] =
|
||||
{LanguageOidIndex, LanguageNameIndex};
|
||||
char *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
|
||||
{LargeObjectLOidPNIndex};
|
||||
char *Name_pg_namespace_indices[Num_pg_namespace_indices] =
|
||||
{NamespaceNameIndex, NamespaceOidIndex};
|
||||
char *Name_pg_opclass_indices[Num_pg_opclass_indices] =
|
||||
{OpclassAmNameIndex, OpclassOidIndex};
|
||||
char *Name_pg_operator_indices[Num_pg_operator_indices] =
|
||||
|
||||
85
src/backend/catalog/pg_namespace.c
Normal file
85
src/backend/catalog/pg_namespace.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pg_namespace.c
|
||||
* routines to support manipulation of the pg_namespace relation
|
||||
*
|
||||
* Portions Copyright (c) 1996-2001, 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.1 2002/03/22 21:34:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
/* ----------------
|
||||
* NamespaceCreate
|
||||
* ---------------
|
||||
*/
|
||||
Oid
|
||||
NamespaceCreate(const char *nspName)
|
||||
{
|
||||
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(GetUserId());
|
||||
nulls[Anum_pg_namespace_nspacl - 1] = 'n';
|
||||
|
||||
nspdesc = heap_openr(NamespaceRelationName, RowExclusiveLock);
|
||||
tupDesc = nspdesc->rd_att;
|
||||
if (!HeapTupleIsValid(tup = heap_formtuple(tupDesc,
|
||||
values,
|
||||
nulls)))
|
||||
elog(ERROR, "NamespaceCreate: heap_formtuple failed");
|
||||
nspoid = heap_insert(nspdesc, tup);
|
||||
if (!OidIsValid(nspoid))
|
||||
elog(ERROR, "NamespaceCreate: heap_insert failed");
|
||||
|
||||
if (RelationGetForm(nspdesc)->relhasindex)
|
||||
{
|
||||
Relation idescs[Num_pg_namespace_indices];
|
||||
|
||||
CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_namespace_indices, nspdesc, tup);
|
||||
CatalogCloseIndices(Num_pg_namespace_indices, idescs);
|
||||
}
|
||||
|
||||
heap_close(nspdesc, RowExclusiveLock);
|
||||
|
||||
return nspoid;
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.164 2002/03/22 02:56:31 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.165 2002/03/22 21:34:44 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The PerformAddAttribute() code, like most of the relation
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/pg_attrdef.h"
|
||||
#include "catalog/pg_index.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_relcheck.h"
|
||||
#include "catalog/pg_type.h"
|
||||
@@ -2008,12 +2009,10 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
owner_name, authId);
|
||||
}
|
||||
|
||||
/* FIXME FENN: Create the schema here */
|
||||
(void) schemaName; /* suppress compiler warning for now... */
|
||||
/* Create the schema's namespace */
|
||||
NamespaceCreate(schemaName);
|
||||
|
||||
/*
|
||||
* Let commands in the schema-element-list know about the schema
|
||||
*/
|
||||
/* Let commands in the schema-element-list know about the schema */
|
||||
CommandCounterIncrement();
|
||||
|
||||
/*
|
||||
|
||||
23
src/backend/utils/cache/syscache.c
vendored
23
src/backend/utils/cache/syscache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.68 2002/03/21 23:27:24 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.69 2002/03/22 21:34:44 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* These routines allow the parser/planner/executor to perform
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "catalog/pg_index.h"
|
||||
#include "catalog/pg_inherits.h"
|
||||
#include "catalog/pg_language.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
@@ -263,6 +264,26 @@ static struct cachedesc cacheinfo[] = {
|
||||
0,
|
||||
0
|
||||
}},
|
||||
{NamespaceRelationName, /* NAMESPACENAME */
|
||||
NamespaceNameIndex,
|
||||
0,
|
||||
1,
|
||||
{
|
||||
Anum_pg_namespace_nspname,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
}},
|
||||
{NamespaceRelationName, /* NAMESPACEOID */
|
||||
NamespaceOidIndex,
|
||||
0,
|
||||
1,
|
||||
{
|
||||
ObjectIdAttributeNumber,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
}},
|
||||
{OperatorRelationName, /* OPERNAME */
|
||||
OperatorNameIndex,
|
||||
0,
|
||||
|
||||
Reference in New Issue
Block a user