Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita25b94c

Browse files
committed
Create the pg_namespace system catalog. Doesn't do much yet, but it's
there and CREATE SCHEMA will make entries in it...
1 parent48c9164 commita25b94c

File tree

13 files changed

+285
-35
lines changed

13 files changed

+285
-35
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Documentation of the system catalogs, directed toward PostgreSQL developers
3-
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.36 2002/03/2219:20:03 petere Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.37 2002/03/2221:34:43 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -111,6 +111,11 @@
111111
<entry>asynchronous notification</entry>
112112
</row>
113113

114+
<row>
115+
<entry>pg_namespace</entry>
116+
<entry>namespaces (schemas)</entry>
117+
</row>
118+
114119
<row>
115120
<entry>pg_opclass</entry>
116121
<entry>index access method operator classes</entry>
@@ -1408,6 +1413,56 @@
14081413
</sect1>
14091414

14101415

1416+
<sect1 id="catalog-pg-namespace">
1417+
<title>pg_namespace</title>
1418+
1419+
<para>
1420+
A namespace is the structure underlying SQL92 schemas: each namespace
1421+
can have a separate collection of relations, types, etc without name
1422+
conflicts.
1423+
</para>
1424+
1425+
<table>
1426+
<title>pg_namespace Columns</title>
1427+
1428+
<tgroup cols=4>
1429+
<thead>
1430+
<row>
1431+
<entry>Name</entry>
1432+
<entry>Type</entry>
1433+
<entry>References</entry>
1434+
<entry>Description</entry>
1435+
</row>
1436+
</thead>
1437+
1438+
<tbody>
1439+
<row>
1440+
<entry>nspname</entry>
1441+
<entry><type>name</type></entry>
1442+
<entry></entry>
1443+
<entry>Name of the namespace</entry>
1444+
</row>
1445+
1446+
<row>
1447+
<entry>nspowner</entry>
1448+
<entry><type>int4</type></entry>
1449+
<entry>pg_shadow.usesysid</entry>
1450+
<entry>Owner (creator) of the namespace</entry>
1451+
</row>
1452+
1453+
<row>
1454+
<entry>nspacl</entry>
1455+
<entry><type>aclitem[]</type></entry>
1456+
<entry></entry>
1457+
<entry>Access permissions</entry>
1458+
</row>
1459+
</tbody>
1460+
</tgroup>
1461+
</table>
1462+
1463+
</sect1>
1464+
1465+
14111466
<sect1 id="catalog-pg-operator">
14121467
<title>pg_operator</title>
14131468

‎src/backend/catalog/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#-------------------------------------------------------------------------
22
#
3-
# Makefile for catalog
3+
# Makefile forbackend/catalog
44
#
5-
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.37 2001/08/25 18:52:41 tgl Exp $
5+
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.38 2002/03/22 21:34:43 tgl Exp $
66
#
77
#-------------------------------------------------------------------------
88

@@ -11,8 +11,8 @@ top_builddir = ../../..
1111
include$(top_builddir)/src/Makefile.global
1212

1313
OBJS = catalog.o heap.o index.o indexing.o aclchk.o\
14-
pg_aggregate.o pg_largeobject.opg_operator.o pg_proc.o\
15-
pg_type.o
14+
pg_aggregate.o pg_largeobject.opg_namespace.o\
15+
pg_operator.o pg_proc.opg_type.o
1616

1717
BKIFILES = postgres.bki postgres.description
1818

@@ -31,7 +31,7 @@ POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
3131
pg_operator.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
3232
pg_language.h pg_largeobject.h pg_aggregate.h pg_statistic.h \
3333
pg_rewrite.h pg_trigger.h pg_listener.h pg_description.h \
34-
pg_database.h pg_shadow.h pg_group.h indexing.h \
34+
pg_namespace.hpg_database.h pg_shadow.h pg_group.h indexing.h \
3535
)
3636

3737
pg_includes :=$(sort -I$(top_srcdir)/src/include -I$(top_builddir)/src/include)

‎src/backend/catalog/indexing.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.83 2002/02/19 20:11:11 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.84 2002/03/22 21:34:44 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -57,6 +57,8 @@ char *Name_pg_language_indices[Num_pg_language_indices] =
5757
{LanguageOidIndex,LanguageNameIndex};
5858
char*Name_pg_largeobject_indices[Num_pg_largeobject_indices]=
5959
{LargeObjectLOidPNIndex};
60+
char*Name_pg_namespace_indices[Num_pg_namespace_indices]=
61+
{NamespaceNameIndex,NamespaceOidIndex};
6062
char*Name_pg_opclass_indices[Num_pg_opclass_indices]=
6163
{OpclassAmNameIndex,OpclassOidIndex};
6264
char*Name_pg_operator_indices[Num_pg_operator_indices]=

‎src/backend/catalog/pg_namespace.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_namespace.c
4+
* routines to support manipulation of the pg_namespace relation
5+
*
6+
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*
10+
* IDENTIFICATION
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.1 2002/03/22 21:34:44 tgl Exp $
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
#include"postgres.h"
16+
17+
#include"access/heapam.h"
18+
#include"catalog/catname.h"
19+
#include"catalog/indexing.h"
20+
#include"catalog/pg_namespace.h"
21+
#include"miscadmin.h"
22+
#include"utils/builtins.h"
23+
#include"utils/syscache.h"
24+
25+
26+
/* ----------------
27+
* NamespaceCreate
28+
* ---------------
29+
*/
30+
Oid
31+
NamespaceCreate(constchar*nspName)
32+
{
33+
Relationnspdesc;
34+
HeapTupletup;
35+
Oidnspoid;
36+
charnulls[Natts_pg_namespace];
37+
Datumvalues[Natts_pg_namespace];
38+
NameDatanname;
39+
TupleDesctupDesc;
40+
inti;
41+
42+
/* sanity checks */
43+
if (!nspName)
44+
elog(ERROR,"no namespace name supplied");
45+
46+
/* make sure there is no existing namespace of same name */
47+
if (SearchSysCacheExists(NAMESPACENAME,
48+
PointerGetDatum(nspName),
49+
0,0,0))
50+
elog(ERROR,"namespace \"%s\" already exists",nspName);
51+
52+
/* initialize nulls and values */
53+
for (i=0;i<Natts_pg_namespace;i++)
54+
{
55+
nulls[i]=' ';
56+
values[i]= (Datum)NULL;
57+
}
58+
namestrcpy(&nname,nspName);
59+
values[Anum_pg_namespace_nspname-1]=NameGetDatum(&nname);
60+
values[Anum_pg_namespace_nspowner-1]=Int32GetDatum(GetUserId());
61+
nulls[Anum_pg_namespace_nspacl-1]='n';
62+
63+
nspdesc=heap_openr(NamespaceRelationName,RowExclusiveLock);
64+
tupDesc=nspdesc->rd_att;
65+
if (!HeapTupleIsValid(tup=heap_formtuple(tupDesc,
66+
values,
67+
nulls)))
68+
elog(ERROR,"NamespaceCreate: heap_formtuple failed");
69+
nspoid=heap_insert(nspdesc,tup);
70+
if (!OidIsValid(nspoid))
71+
elog(ERROR,"NamespaceCreate: heap_insert failed");
72+
73+
if (RelationGetForm(nspdesc)->relhasindex)
74+
{
75+
Relationidescs[Num_pg_namespace_indices];
76+
77+
CatalogOpenIndices(Num_pg_namespace_indices,Name_pg_namespace_indices,idescs);
78+
CatalogIndexInsert(idescs,Num_pg_namespace_indices,nspdesc,tup);
79+
CatalogCloseIndices(Num_pg_namespace_indices,idescs);
80+
}
81+
82+
heap_close(nspdesc,RowExclusiveLock);
83+
84+
returnnspoid;
85+
}

‎src/backend/commands/command.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.164 2002/03/2202:56:31 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.165 2002/03/2221:34:44 tgl Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -28,6 +28,7 @@
2828
#include"catalog/indexing.h"
2929
#include"catalog/pg_attrdef.h"
3030
#include"catalog/pg_index.h"
31+
#include"catalog/pg_namespace.h"
3132
#include"catalog/pg_opclass.h"
3233
#include"catalog/pg_relcheck.h"
3334
#include"catalog/pg_type.h"
@@ -2008,12 +2009,10 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
20082009
owner_name,authId);
20092010
}
20102011

2011-
/*FIXME FENN:Create the schema here */
2012-
(void)schemaName;/* suppress compiler warning for now... */
2012+
/* Create the schema's namespace */
2013+
NamespaceCreate(schemaName);
20132014

2014-
/*
2015-
* Let commands in the schema-element-list know about the schema
2016-
*/
2015+
/* Let commands in the schema-element-list know about the schema */
20172016
CommandCounterIncrement();
20182017

20192018
/*

‎src/backend/utils/cache/syscache.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.68 2002/03/21 23:27:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.69 2002/03/22 21:34:44 tgl Exp $
1212
*
1313
* NOTES
1414
* These routines allow the parser/planner/executor to perform
@@ -32,6 +32,7 @@
3232
#include"catalog/pg_index.h"
3333
#include"catalog/pg_inherits.h"
3434
#include"catalog/pg_language.h"
35+
#include"catalog/pg_namespace.h"
3536
#include"catalog/pg_opclass.h"
3637
#include"catalog/pg_operator.h"
3738
#include"catalog/pg_proc.h"
@@ -263,6 +264,26 @@ static struct cachedesc cacheinfo[] = {
263264
0,
264265
0
265266
}},
267+
{NamespaceRelationName,/* NAMESPACENAME */
268+
NamespaceNameIndex,
269+
0,
270+
1,
271+
{
272+
Anum_pg_namespace_nspname,
273+
0,
274+
0,
275+
0
276+
}},
277+
{NamespaceRelationName,/* NAMESPACEOID */
278+
NamespaceOidIndex,
279+
0,
280+
1,
281+
{
282+
ObjectIdAttributeNumber,
283+
0,
284+
0,
285+
0
286+
}},
266287
{OperatorRelationName,/* OPERNAME */
267288
OperatorNameIndex,
268289
0,

‎src/include/catalog/catalog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*-------------------------------------------------------------------------
22
*
33
* catalog.h
4-
* prototypes for functions inlib/catalog/catalog.c
4+
* prototypes for functions inbackend/catalog/catalog.c
55
*
66
*
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: catalog.h,v 1.21 2001/11/16 23:30:35 tgl Exp $
10+
* $Id: catalog.h,v 1.22 2002/03/22 21:34:44 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/

‎src/include/catalog/catname.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: catname.h,v 1.23 2001/11/05 17:46:31 momjian Exp $
10+
* $Id: catname.h,v 1.24 2002/03/22 21:34:44 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#ifndefCATNAME_H
1515
#defineCATNAME_H
1616

1717

18-
1918
#defineAggregateRelationName "pg_aggregate"
2019
#defineAccessMethodRelationName "pg_am"
2120
#defineAccessMethodOperatorRelationName "pg_amop"
@@ -29,6 +28,7 @@
2928
#defineLanguageRelationName "pg_language"
3029
#defineLargeObjectRelationName "pg_largeobject"
3130
#defineListenerRelationName "pg_listener"
31+
#defineNamespaceRelationName "pg_namespace"
3232
#defineOperatorClassRelationName "pg_opclass"
3333
#defineOperatorRelationName "pg_operator"
3434
#defineProcedureRelationName "pg_proc"

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.109 2002/03/2202:56:35 tgl Exp $
40+
* $Id: catversion.h,v 1.110 2002/03/2221:34:44 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200203212
56+
#defineCATALOG_VERSION_NO200203221
5757

5858
#endif

‎src/include/catalog/indexing.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: indexing.h,v 1.57 2002/02/19 20:11:19 tgl Exp $
11+
* $Id: indexing.h,v 1.58 2002/03/22 21:34:44 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -34,6 +34,7 @@
3434
#defineNum_pg_inherits_indices1
3535
#defineNum_pg_language_indices2
3636
#defineNum_pg_largeobject_indices1
37+
#defineNum_pg_namespace_indices2
3738
#defineNum_pg_opclass_indices2
3839
#defineNum_pg_operator_indices2
3940
#defineNum_pg_proc_indices2
@@ -70,6 +71,8 @@
7071
#defineLanguageNameIndex"pg_language_name_index"
7172
#defineLanguageOidIndex"pg_language_oid_index"
7273
#defineLargeObjectLOidPNIndex"pg_largeobject_loid_pn_index"
74+
#defineNamespaceNameIndex"pg_namespace_nspname_index"
75+
#defineNamespaceOidIndex"pg_namespace_oid_index"
7376
#defineOpclassAmNameIndex"pg_opclass_am_name_index"
7477
#defineOpclassOidIndex"pg_opclass_oid_index"
7578
#defineOperatorNameIndex"pg_operator_oprname_l_r_k_index"
@@ -104,6 +107,7 @@ extern char *Name_pg_index_indices[];
104107
externchar*Name_pg_inherits_indices[];
105108
externchar*Name_pg_language_indices[];
106109
externchar*Name_pg_largeobject_indices[];
110+
externchar*Name_pg_namespace_indices[];
107111
externchar*Name_pg_opclass_indices[];
108112
externchar*Name_pg_operator_indices[];
109113
externchar*Name_pg_proc_indices[];
@@ -165,6 +169,8 @@ DECLARE_UNIQUE_INDEX(pg_inherits_relid_seqno_index on pg_inherits using btree(in
165169
DECLARE_UNIQUE_INDEX(pg_language_name_indexonpg_languageusingbtree(lannamename_ops));
166170
DECLARE_UNIQUE_INDEX(pg_language_oid_indexonpg_languageusingbtree(oidoid_ops));
167171
DECLARE_UNIQUE_INDEX(pg_largeobject_loid_pn_indexonpg_largeobjectusingbtree(loidoid_ops,pagenoint4_ops));
172+
DECLARE_UNIQUE_INDEX(pg_namespace_nspname_indexonpg_namespaceusingbtree(nspnamename_ops));
173+
DECLARE_UNIQUE_INDEX(pg_namespace_oid_indexonpg_namespaceusingbtree(oidoid_ops));
168174
DECLARE_UNIQUE_INDEX(pg_opclass_am_name_indexonpg_opclassusingbtree(opcamidoid_ops,opcnamename_ops));
169175
DECLARE_UNIQUE_INDEX(pg_opclass_oid_indexonpg_opclassusingbtree(oidoid_ops));
170176
DECLARE_UNIQUE_INDEX(pg_operator_oid_indexonpg_operatorusingbtree(oidoid_ops));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp