Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1dbf8aa

Browse files
committed
pg_class has a relnamespace column. You can create and access tables
in schemas other than the system namespace; however, there's no search path yet, and not all operations work yet on tables outside the system namespace.
1 parent da631e9 commit 1dbf8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1062
-808
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 10 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.37 2002/03/22 21:34:43 tgl Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.38 2002/03/26 19:15:10 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -568,6 +568,15 @@
568568
<entry>Name of the table, index, view, etc.</entry>
569569
</row>
570570

571+
<row>
572+
<entry>relnamespace</entry>
573+
<entry><type>oid</type></entry>
574+
<entry>pg_namespace.oid</entry>
575+
<entry>
576+
The OID of the namespace that contains this relation
577+
</entry>
578+
</row>
579+
571580
<row>
572581
<entry>reltype</entry>
573582
<entry><type>oid</type></entry>

src/backend/access/heap/heapam.c

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.131 2002/03/03 17:47:53 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.132 2002/03/26 19:15:11 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
1515
* relation_open - open any relation by relation OID
16-
* relation_openr - open any relation by name
16+
* relation_openrv - open any relation specified by a RangeVar
17+
* relation_openr - open a system relation by name
1718
* relation_close - close any relation
1819
* heap_open - open a heap relation by relation OID
19-
* heap_openr - open a heap relation by name
20+
* heap_openrv - open a heap relation specified by a RangeVar
21+
* heap_openr - open a system heap relation by name
2022
* heap_close - (now just a macro for relation_close)
2123
* heap_beginscan - begin relation scan
2224
* heap_rescan - restart a relation scan
@@ -44,6 +46,7 @@
4446
#include "access/valid.h"
4547
#include "access/xlogutils.h"
4648
#include "catalog/catalog.h"
49+
#include "catalog/namespace.h"
4750
#include "miscadmin.h"
4851
#include "utils/inval.h"
4952
#include "utils/relcache.h"
@@ -481,29 +484,30 @@ relation_open(Oid relationId, LOCKMODE lockmode)
481484
}
482485

483486
/* ----------------
484-
* relation_openr - open any relation by name
487+
* relation_openrv - open any relation specified by a RangeVar
485488
*
486-
* As above, but lookup by name instead of OID.
489+
* As above, but the relation is specified by a RangeVar.
487490
* ----------------
488491
*/
489492
Relation
490-
relation_openr(const char *relationName, LOCKMODE lockmode)
493+
relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
491494
{
492-
Relation r;
493-
494-
Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
495+
Oid relOid;
495496

496497
/*
497-
* increment access statistics
498+
* In bootstrap mode, don't do any namespace processing.
498499
*/
499-
IncrHeapAccessStat(local_openr);
500-
IncrHeapAccessStat(global_openr);
500+
if (IsBootstrapProcessingMode())
501+
{
502+
Assert(relation->schemaname == NULL);
503+
return relation_openr(relation->relname, lockmode);
504+
}
501505

502506
/*
503507
* Check for shared-cache-inval messages before trying to open the
504508
* relation. This is needed to cover the case where the name
505509
* identifies a rel that has been dropped and recreated since the
506-
* start of our transaction: if we don't flush the old relcache entry
510+
* start of our transaction: if we don't flush the old syscache entry
507511
* then we'll latch onto that entry and suffer an error when we do
508512
* LockRelation. Note that relation_open does not need to do this,
509513
* since a relation's OID never changes.
@@ -514,11 +518,43 @@ relation_openr(const char *relationName, LOCKMODE lockmode)
514518
if (lockmode != NoLock)
515519
AcceptInvalidationMessages();
516520

521+
/* Look up the appropriate relation using namespace search */
522+
relOid = RangeVarGetRelid(relation, false);
523+
524+
/* Let relation_open do the rest */
525+
return relation_open(relOid, lockmode);
526+
}
527+
528+
/* ----------------
529+
* relation_openr - open a system relation specified by name.
530+
*
531+
* As above, but the relation is specified by an unqualified name;
532+
* it is assumed to live in the system catalog namespace.
533+
* ----------------
534+
*/
535+
Relation
536+
relation_openr(const char *sysRelationName, LOCKMODE lockmode)
537+
{
538+
Relation r;
539+
540+
Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
541+
542+
/*
543+
* increment access statistics
544+
*/
545+
IncrHeapAccessStat(local_openr);
546+
IncrHeapAccessStat(global_openr);
547+
548+
/*
549+
* We assume we should not need to worry about the rel's OID changing,
550+
* hence no need for AcceptInvalidationMessages here.
551+
*/
552+
517553
/* The relcache does all the real work... */
518-
r = RelationNameGetRelation(relationName);
554+
r = RelationSysNameGetRelation(sysRelationName);
519555

520556
if (!RelationIsValid(r))
521-
elog(ERROR, "Relation \"%s\" does not exist", relationName);
557+
elog(ERROR, "Relation \"%s\" does not exist", sysRelationName);
522558

523559
if (lockmode != NoLock)
524560
LockRelation(r, lockmode);
@@ -582,17 +618,44 @@ heap_open(Oid relationId, LOCKMODE lockmode)
582618
}
583619

584620
/* ----------------
585-
* heap_openr - open a heap relation by name
621+
* heap_openrv - open a heap relation specified
622+
* by a RangeVar node
623+
*
624+
* As above, but relation is specified by a RangeVar.
625+
* ----------------
626+
*/
627+
Relation
628+
heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
629+
{
630+
Relation r;
631+
632+
r = relation_openrv(relation, lockmode);
633+
634+
if (r->rd_rel->relkind == RELKIND_INDEX)
635+
elog(ERROR, "%s is an index relation",
636+
RelationGetRelationName(r));
637+
else if (r->rd_rel->relkind == RELKIND_SPECIAL)
638+
elog(ERROR, "%s is a special relation",
639+
RelationGetRelationName(r));
640+
641+
pgstat_initstats(&r->pgstat_info, r);
642+
643+
return r;
644+
}
645+
646+
/* ----------------
647+
* heap_openr - open a system heap relation specified by name.
586648
*
587-
* As above, but lookup by name instead of OID.
649+
* As above, but the relation is specified by an unqualified name;
650+
* it is assumed to live in the system catalog namespace.
588651
* ----------------
589652
*/
590653
Relation
591-
heap_openr(const char *relationName, LOCKMODE lockmode)
654+
heap_openr(const char *sysRelationName, LOCKMODE lockmode)
592655
{
593656
Relation r;
594657

595-
r = relation_openr(relationName, lockmode);
658+
r = relation_openr(sysRelationName, lockmode);
596659

597660
if (r->rd_rel->relkind == RELKIND_INDEX)
598661
elog(ERROR, "%s is an index relation",

src/backend/access/index/indexam.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.55 2001/11/02 16:30:29 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.56 2002/03/26 19:15:14 tgl Exp $
1212
*
1313
* INTERFACE ROUTINES
1414
* index_open - open an index relation by relation OID
15-
* index_openr - open an index relation by name
15+
* index_openrv - open an index relation specified by a RangeVar
16+
* index_openr - open a system index relation by name
1617
* index_close - close an index relation
1718
* index_beginscan - start a scan of an index
1819
* index_rescan - restart a scan of an index
@@ -136,17 +137,41 @@ index_open(Oid relationId)
136137
}
137138

138139
/* ----------------
139-
* index_openr - open an index relation by name
140+
* index_openrv - open an index relation specified
141+
* by a RangeVar node
140142
*
141-
* As above, but lookup by name instead of OID.
143+
* As above, but relation is specified by a RangeVar.
142144
* ----------------
143145
*/
144146
Relation
145-
index_openr(const char *relationName)
147+
index_openrv(const RangeVar *relation)
146148
{
147149
Relation r;
148150

149-
r = relation_openr(relationName, NoLock);
151+
r = relation_openrv(relation, NoLock);
152+
153+
if (r->rd_rel->relkind != RELKIND_INDEX)
154+
elog(ERROR, "%s is not an index relation",
155+
RelationGetRelationName(r));
156+
157+
pgstat_initstats(&r->pgstat_info, r);
158+
159+
return r;
160+
}
161+
162+
/* ----------------
163+
* index_openr - open a system index relation specified by name.
164+
*
165+
* As above, but the relation is specified by an unqualified name;
166+
* it is assumed to live in the system catalog namespace.
167+
* ----------------
168+
*/
169+
Relation
170+
index_openr(const char *sysRelationName)
171+
{
172+
Relation r;
173+
174+
r = relation_openr(sysRelationName, NoLock);
150175

151176
if (r->rd_rel->relkind != RELKIND_INDEX)
152177
elog(ERROR, "%s is not an index relation",

src/backend/bootstrap/bootparse.y

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.40 2002/03/02 21:39:20 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.41 2002/03/26 19:15:16 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -32,8 +32,10 @@
3232
#include "catalog/pg_am.h"
3333
#include "catalog/pg_attribute.h"
3434
#include "catalog/pg_class.h"
35+
#include "catalog/pg_namespace.h"
3536
#include "commands/defrem.h"
3637
#include "miscadmin.h"
38+
#include "nodes/makefuncs.h"
3739
#include "nodes/nodes.h"
3840
#include "nodes/parsenodes.h"
3941
#include "nodes/pg_list.h"
@@ -179,7 +181,9 @@ Boot_CreateStmt:
179181
}
180182

181183
tupdesc = CreateTupleDesc(numattr, attrtypes);
182-
reldesc = heap_create(LexIDStr($4), tupdesc,
184+
reldesc = heap_create(LexIDStr($4),
185+
PG_CATALOG_NAMESPACE,
186+
tupdesc,
183187
false, true, true);
184188
reldesc->rd_rel->relhasoids = ! ($3);
185189
elog(DEBUG3, "bootstrap relation created");
@@ -191,6 +195,7 @@ Boot_CreateStmt:
191195

192196
tupdesc = CreateTupleDesc(numattr,attrtypes);
193197
id = heap_create_with_catalog(LexIDStr($4),
198+
PG_CATALOG_NAMESPACE,
194199
tupdesc,
195200
RELKIND_RELATION,
196201
! ($3),
@@ -232,7 +237,7 @@ Boot_DeclareIndexStmt:
232237
{
233238
do_start();
234239

235-
DefineIndex(LexIDStr($5),
240+
DefineIndex(makeRangeVar(NULL, LexIDStr($5)),
236241
LexIDStr($3),
237242
LexIDStr($7),
238243
$9, false, false, NULL, NIL);
@@ -245,7 +250,7 @@ Boot_DeclareUniqueIndexStmt:
245250
{
246251
do_start();
247252

248-
DefineIndex(LexIDStr($6),
253+
DefineIndex(makeRangeVar(NULL, LexIDStr($6)),
249254
LexIDStr($4),
250255
LexIDStr($8),
251256
$10, true, false, NULL, NIL);

src/backend/bootstrap/bootstrap.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.124 2002/03/15 19:20:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.125 2002/03/26 19:15:16 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -153,8 +153,8 @@ extern char *optarg;
153153

154154
typedef struct _IndexList
155155
{
156-
char *il_heap;
157-
char *il_ind;
156+
Oid il_heap;
157+
Oid il_ind;
158158
IndexInfo *il_info;
159159
struct _IndexList *il_next;
160160
} IndexList;
@@ -1080,8 +1080,8 @@ AddStr(char *str, int strlength, int mderef)
10801080
* are present in the index.
10811081
*/
10821082
void
1083-
index_register(char *heap,
1084-
char *ind,
1083+
index_register(Oid heap,
1084+
Oid ind,
10851085
IndexInfo *indexInfo)
10861086
{
10871087
IndexList *newind;
@@ -1103,8 +1103,8 @@ index_register(char *heap,
11031103
oldcxt = MemoryContextSwitchTo(nogc);
11041104

11051105
newind = (IndexList *) palloc(sizeof(IndexList));
1106-
newind->il_heap = pstrdup(heap);
1107-
newind->il_ind = pstrdup(ind);
1106+
newind->il_heap = heap;
1107+
newind->il_ind = ind;
11081108
newind->il_info = (IndexInfo *) palloc(sizeof(IndexInfo));
11091109

11101110
memcpy(newind->il_info, indexInfo, sizeof(IndexInfo));
@@ -1126,8 +1126,8 @@ build_indices()
11261126
Relation heap;
11271127
Relation ind;
11281128

1129-
heap = heap_openr(ILHead->il_heap, NoLock);
1130-
ind = index_openr(ILHead->il_ind);
1129+
heap = heap_open(ILHead->il_heap, NoLock);
1130+
ind = index_open(ILHead->il_ind);
11311131
index_build(heap, ind, ILHead->il_info);
11321132

11331133
/*

src/backend/catalog/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#
33
# Makefile for backend/catalog
44
#
5-
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.38 2002/03/22 21:34:43 tgl Exp $
5+
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.39 2002/03/26 19:15:22 tgl Exp $
66
#
77
#-------------------------------------------------------------------------
88

99
subdir = src/backend/catalog
1010
top_builddir = ../../..
1111
include $(top_builddir)/src/Makefile.global
1212

13-
OBJS = catalog.o heap.o index.o indexing.o aclchk.o \
13+
OBJS = catalog.o heap.o index.o indexing.o namespace.o aclchk.o \
1414
pg_aggregate.o pg_largeobject.o pg_namespace.o \
1515
pg_operator.o pg_proc.o pg_type.o
1616

0 commit comments

Comments
 (0)