]> granicus.if.org Git - postgresql/commitdiff
Create the pg_namespace system catalog. Doesn't do much yet, but it's
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Mar 2002 21:34:44 +0000 (21:34 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Mar 2002 21:34:44 +0000 (21:34 +0000)
there and CREATE SCHEMA will make entries in it...

13 files changed:
doc/src/sgml/catalogs.sgml
src/backend/catalog/Makefile
src/backend/catalog/indexing.c
src/backend/catalog/pg_namespace.c [new file with mode: 0644]
src/backend/commands/command.c
src/backend/utils/cache/syscache.c
src/include/catalog/catalog.h
src/include/catalog/catname.h
src/include/catalog/catversion.h
src/include/catalog/indexing.h
src/include/catalog/pg_namespace.h [new file with mode: 0644]
src/include/utils/syscache.h
src/test/regress/expected/sanity_check.out

index b72b083617981df3a558446d9fb648e347bedf00..5371da7ee7ebc5b4b9855797ccb13cfd0f47ae61 100644 (file)
@@ -1,6 +1,6 @@
 <!--
  Documentation of the system catalogs, directed toward PostgreSQL developers
- $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.36 2002/03/22 19:20:03 petere Exp $
+ $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.37 2002/03/22 21:34:43 tgl Exp $
  -->
 
 <chapter id="catalogs">
       <entry>asynchronous notification</entry>
      </row>
 
+     <row>
+      <entry>pg_namespace</entry>
+      <entry>namespaces (schemas)</entry>
+     </row>
+
      <row>
       <entry>pg_opclass</entry>
       <entry>index access method operator classes</entry>
  </sect1>
 
 
+ <sect1 id="catalog-pg-namespace">
+  <title>pg_namespace</title>
+
+  <para>
+   A namespace is the structure underlying SQL92 schemas: each namespace
+   can have a separate collection of relations, types, etc without name
+   conflicts.
+  </para>
+
+  <table>
+   <title>pg_namespace Columns</title>
+
+   <tgroup cols=4>
+    <thead>
+     <row>
+      <entry>Name</entry>
+      <entry>Type</entry>
+      <entry>References</entry>
+      <entry>Description</entry>
+     </row>
+    </thead>
+
+    <tbody>
+     <row>
+      <entry>nspname</entry>
+      <entry><type>name</type></entry>
+      <entry></entry>
+      <entry>Name of the namespace</entry>
+     </row>
+
+     <row>
+      <entry>nspowner</entry>
+      <entry><type>int4</type></entry>
+      <entry>pg_shadow.usesysid</entry>
+      <entry>Owner (creator) of the namespace</entry>
+     </row>
+
+     <row>
+      <entry>nspacl</entry>
+      <entry><type>aclitem[]</type></entry>
+      <entry></entry>
+      <entry>Access permissions</entry>
+     </row>
+    </tbody>
+   </tgroup>
+  </table>
+
+ </sect1>
+
+
  <sect1 id="catalog-pg-operator">
   <title>pg_operator</title>
 
index 6c5d2aaec2c191d4eb2102886f5d4b47cb79e76a..d0bc7b3726750757958c9b1d88973d7701303841 100644 (file)
@@ -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)
index e600eab6a30e3e0ac640b20410c6bda26f019f95..fcad116e99d8cc63b829af9b11f509790ec6c02f 100644 (file)
@@ -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] =
diff --git a/src/backend/catalog/pg_namespace.c b/src/backend/catalog/pg_namespace.c
new file mode 100644 (file)
index 0000000..c340cd0
--- /dev/null
@@ -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;
+}
index b9741e0f3a51fd9d78bfaf50aa97264d10d70888..af9e76e279151f07147af6c0316f1cc388d22223 100644 (file)
@@ -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();
 
        /*
index 8779125d1591d4554ee0c9c8809626df6dd1b6de..c30bbe3090cf3fb80622bcf989500cfbd8e656a2 100644 (file)
@@ -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,
index 25f6fcb0c5c1dc92877f1ec57ee16faa6752f279..62cc5736f7f72bd36fdf6a5e57fd65c2f57b3b28 100644 (file)
@@ -1,13 +1,13 @@
 /*-------------------------------------------------------------------------
  *
  * catalog.h
- *       prototypes for functions in lib/catalog/catalog.c
+ *       prototypes for functions in backend/catalog/catalog.c
  *
  *
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catalog.h,v 1.21 2001/11/16 23:30:35 tgl Exp $
+ * $Id: catalog.h,v 1.22 2002/03/22 21:34:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
index ecdc81aed1de9a1190bf625e3edf51f787e57ce5..bf3bf789756997d868aa0c9df1bd542e35a8ede7 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catname.h,v 1.23 2001/11/05 17:46:31 momjian Exp $
+ * $Id: catname.h,v 1.24 2002/03/22 21:34:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,7 +15,6 @@
 #define CATNAME_H
 
 
-
 #define  AggregateRelationName "pg_aggregate"
 #define  AccessMethodRelationName "pg_am"
 #define  AccessMethodOperatorRelationName "pg_amop"
@@ -29,6 +28,7 @@
 #define  LanguageRelationName "pg_language"
 #define  LargeObjectRelationName "pg_largeobject"
 #define  ListenerRelationName "pg_listener"
+#define  NamespaceRelationName "pg_namespace"
 #define  OperatorClassRelationName "pg_opclass"
 #define  OperatorRelationName "pg_operator"
 #define  ProcedureRelationName "pg_proc"
index e931772b07c151d9c0385733829d8b3816a9dffd..086df0b2f8465d19ddab83d5edada98eff0606c9 100644 (file)
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catversion.h,v 1.109 2002/03/22 02:56:35 tgl Exp $
+ * $Id: catversion.h,v 1.110 2002/03/22 21:34:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     200203212
+#define CATALOG_VERSION_NO     200203221
 
 #endif
index 8d0ba9c4b9c88e33e8dc4a0af028a68a72a1c6cf..c6291f2a3a4771dcd157a8f792dbec213cc315e0 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: indexing.h,v 1.57 2002/02/19 20:11:19 tgl Exp $
+ * $Id: indexing.h,v 1.58 2002/03/22 21:34:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -34,6 +34,7 @@
 #define Num_pg_inherits_indices                1
 #define Num_pg_language_indices                2
 #define Num_pg_largeobject_indices     1
+#define Num_pg_namespace_indices       2
 #define Num_pg_opclass_indices         2
 #define Num_pg_operator_indices                2
 #define Num_pg_proc_indices                    2
@@ -70,6 +71,8 @@
 #define LanguageNameIndex                      "pg_language_name_index"
 #define LanguageOidIndex                       "pg_language_oid_index"
 #define LargeObjectLOidPNIndex         "pg_largeobject_loid_pn_index"
+#define NamespaceNameIndex                     "pg_namespace_nspname_index"
+#define NamespaceOidIndex                      "pg_namespace_oid_index"
 #define OpclassAmNameIndex                     "pg_opclass_am_name_index"
 #define OpclassOidIndex                                "pg_opclass_oid_index"
 #define OperatorNameIndex                      "pg_operator_oprname_l_r_k_index"
@@ -104,6 +107,7 @@ extern char *Name_pg_index_indices[];
 extern char *Name_pg_inherits_indices[];
 extern char *Name_pg_language_indices[];
 extern char *Name_pg_largeobject_indices[];
+extern char *Name_pg_namespace_indices[];
 extern char *Name_pg_opclass_indices[];
 extern char *Name_pg_operator_indices[];
 extern char *Name_pg_proc_indices[];
@@ -165,6 +169,8 @@ DECLARE_UNIQUE_INDEX(pg_inherits_relid_seqno_index on pg_inherits using btree(in
 DECLARE_UNIQUE_INDEX(pg_language_name_index on pg_language using btree(lanname name_ops));
 DECLARE_UNIQUE_INDEX(pg_language_oid_index on pg_language using btree(oid oid_ops));
 DECLARE_UNIQUE_INDEX(pg_largeobject_loid_pn_index on pg_largeobject using btree(loid oid_ops, pageno int4_ops));
+DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index on pg_namespace using btree(nspname name_ops));
+DECLARE_UNIQUE_INDEX(pg_namespace_oid_index on pg_namespace using btree(oid oid_ops));
 DECLARE_UNIQUE_INDEX(pg_opclass_am_name_index on pg_opclass using btree(opcamid oid_ops, opcname name_ops));
 DECLARE_UNIQUE_INDEX(pg_opclass_oid_index on pg_opclass using btree(oid oid_ops));
 DECLARE_UNIQUE_INDEX(pg_operator_oid_index on pg_operator using btree(oid oid_ops));
diff --git a/src/include/catalog/pg_namespace.h b/src/include/catalog/pg_namespace.h
new file mode 100644 (file)
index 0000000..8a57cf7
--- /dev/null
@@ -0,0 +1,79 @@
+/*-------------------------------------------------------------------------
+ *
+ * pg_namespace.h
+ *       definition of the system "namespace" relation (pg_namespace)
+ *       along with the relation's initial contents.
+ *
+ *
+ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $Id: pg_namespace.h,v 1.1 2002/03/22 21:34:44 tgl Exp $
+ *
+ * NOTES
+ *       the genbki.sh script reads this file and generates .bki
+ *       information from the DATA() statements.
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_NAMESPACE_H
+#define PG_NAMESPACE_H
+
+/* ----------------
+ *             postgres.h contains the system type definitions and the
+ *             CATALOG(), BOOTSTRAP and DATA() sugar words so this file
+ *             can be read by both genbki.sh and the C compiler.
+ * ----------------
+ */
+
+/* ----------------------------------------------------------------
+ *             pg_namespace definition.
+ *
+ *             cpp turns this into typedef struct FormData_pg_namespace
+ *
+ *     nspname                         name of the namespace
+ *     nspowner                        owner (creator) of the namespace
+ *     nspacl                          access privilege list
+ * ----------------------------------------------------------------
+ */
+CATALOG(pg_namespace)
+{
+       NameData        nspname;
+       int4            nspowner;
+    aclitem            nspacl[1];              /* VARIABLE LENGTH FIELD */
+} FormData_pg_namespace;
+
+/* ----------------
+ *             Form_pg_namespace corresponds to a pointer to a tuple with
+ *             the format of pg_namespace relation.
+ * ----------------
+ */
+typedef FormData_pg_namespace *Form_pg_namespace;
+
+/* ----------------
+ *             compiler constants for pg_namespace
+ * ----------------
+ */
+
+#define Natts_pg_namespace                             3
+#define Anum_pg_namespace_nspname              1
+#define Anum_pg_namespace_nspowner             2
+#define Anum_pg_namespace_nspacl               3
+
+
+/* ----------------
+ * initial contents of pg_namespace
+ * ---------------
+ */
+
+DATA(insert OID = 11 ( "pg_catalog" PGUID "{=r}" ));
+DESCR("System catalog namespace");
+#define PG_CATALOG_NAMESPACE 11
+
+
+/*
+ * prototypes for functions in pg_namespace.c
+ */
+extern Oid     NamespaceCreate(const char *nspName);
+
+#endif   /* PG_NAMESPACE_H */
index d4bcd14256e1fd9650bace2110f6f2d1edc68fe4..45de795c9c8ff18d971fe87e987a19590dcdcdf5 100644 (file)
@@ -9,7 +9,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: syscache.h,v 1.38 2002/03/21 23:27:25 tgl Exp $
+ * $Id: syscache.h,v 1.39 2002/03/22 21:34:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #define INHRELID               14
 #define LANGNAME               15
 #define LANGOID                        16
-#define OPERNAME               17
-#define OPEROID                        18
-#define PROCNAME               19
-#define PROCOID                        20
-#define RELNAME                        21
-#define RELOID                 22
-#define RULENAME               23
-#define SHADOWNAME             24
-#define SHADOWSYSID            25
-#define STATRELATT             26
-#define TYPENAME               27
-#define TYPEOID                        28
+#define NAMESPACENAME  17
+#define NAMESPACEOID   18
+#define OPERNAME               19
+#define OPEROID                        20
+#define PROCNAME               21
+#define PROCOID                        22
+#define RELNAME                        23
+#define RELOID                 24
+#define RULENAME               25
+#define SHADOWNAME             26
+#define SHADOWSYSID            27
+#define STATRELATT             28
+#define TYPENAME               29
+#define TYPEOID                        30
 
 
 extern void InitCatalogCache(void);
index 47196e559931d635daade2063ed304b2369bfb26..7958da8433179a96290bf9625820722a6c9efdac 100644 (file)
@@ -45,6 +45,7 @@ SELECT relname, relhasindex
  pg_inherits         | t
  pg_language         | t
  pg_largeobject      | t
+ pg_namespace        | t
  pg_opclass          | t
  pg_operator         | t
  pg_proc             | t
@@ -59,5 +60,5 @@ SELECT relname, relhasindex
  shighway            | t
  tenk1               | t
  tenk2               | t
-(49 rows)
+(50 rows)