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

Commit 1d584f9

Browse files
committed
Clean up various to-do items associated with system indexes:
pg_database now has unique indexes on oid and on datname. pg_shadow now has unique indexes on usename and on usesysid. pg_am now has unique index on oid. pg_opclass now has unique index on oid. pg_amproc now has unique index on amid+amopclaid+amprocnum. Remove pg_rewrite's unnecessary index on oid, delete unused RULEOID syscache. Remove index on pg_listener and associated syscache for performance reasons (caching rows that are certain to change before you need 'em again is rather pointless). Change pg_attrdef's nonunique index on adrelid into a unique index on adrelid+adnum. Fix various incorrect settings of pg_class.relisshared, make that the primary reference point for whether a relation is shared or not. IsSharedSystemRelationName() is now only consulted to initialize relisshared during initial creation of tables and indexes. In theory we might now support shared user relations, though it's not clear how one would get entries for them into pg_class &etc of multiple databases. Fix recently reported bug that pg_attribute rows created for an index all have the same OID. (Proof that non-unique OID doesn't matter unless it's actually used to do lookups ;-)) There's no need to treat pg_trigger, pg_attrdef, pg_relcheck as bootstrap relations. Convert them into plain system catalogs without hardwired entries in pg_class and friends. Unify global.bki and template1.bki into a single init script postgres.bki, since the alleged distinction between them was misleading and pointless. Not to mention that it didn't work for setting up indexes on shared system relations. Rationalize locking of pg_shadow, pg_group, pg_attrdef (no need to use AccessExclusiveLock where ExclusiveLock or even RowExclusiveLock will do). Also, hold locks until transaction commit where necessary.
1 parent d2c8358 commit 1d584f9

30 files changed

+470
-646
lines changed

doc/src/sgml/bki.sgml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.6 2000/12/23 16:24:29 petere Exp $ -->
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/bki.sgml,v 1.7 2001/06/12 05:55:48 tgl Exp $
3+
-->
24

35
<chapter id="bki">
46
<title><acronym>BKI</acronym> Backend Interface</title>
@@ -15,16 +17,14 @@
1517
</para>
1618

1719
<para>
18-
<application>initdb</application> uses <acronym>BKI</acronym> files
20+
<application>initdb</application> uses a <acronym>BKI</acronym> file
1921
to do part of its job when creating a new database cluster. The
20-
input files used by <application>initbd</application> are created as
22+
input file used by <application>initdb</application> is created as
2123
part of building and installing <productname>Postgres</productname>
2224
by a program named <filename>genbki.sh</filename> from some
2325
specially formatted C header files in the source tree. The created
24-
BKI files are called <filename>global.bki</filename> (for global
25-
catalogs) and <filename>template1.bki</filename> (for the catalogs
26-
initially stored in the template1 database and then duplicated in
27-
every created database) and are normally installed in the
26+
BKI file is called <filename>postgres.bki</filename> and is
27+
normally installed in the
2828
<filename>share</filename> subdirectory of the installation tree.
2929
</para>
3030

@@ -39,7 +39,7 @@
3939
<para>
4040
This section describes how the <productname>Postgres</productname>
4141
backend interprets <acronym>BKI</acronym> files. This description
42-
will be easier to understand if the <filename>global.bki</filename>
42+
will be easier to understand if the <filename>postgres.bki</filename>
4343
file is at hand as an example. You should also study the source
4444
code of <application>initdb</application> to get an idea of how the
4545
backend is invoked.
@@ -49,7 +49,7 @@
4949
BKI input consists of a sequence of commands. Commands are made up
5050
of a number of tokens, depending on the syntax of the command.
5151
Tokens are usually separated by whitespace, but need not be if
52-
there is no ambiguity. There is not special command separator; the
52+
there is no ambiguity. There is no special command separator; the
5353
next token that syntactically cannot belong to the preceeding
5454
command starts a new one. (Usually you would put a new command on
5555
a new line, for clarity.) Tokens can be certain key words, special
@@ -155,13 +155,13 @@
155155
values and <replaceable
156156
class="parameter">oid_value</replaceable> for its OID. If
157157
<replaceable class="parameter">oid_value</replaceable> is zero
158-
(0) or the clause is ommitted, then the next available OID is
158+
(0) or the clause is omitted, then the next available OID is
159159
used.
160160
</para>
161161

162162
<para>
163163
NULL values can be specified using the special key word
164-
<literal>_null_</literal>. Values containing spaces should be
164+
<literal>_null_</literal>. Values containing spaces must be
165165
double quoted.
166166
</para>
167167
</listitem>

doc/src/sgml/catalogs.sgml

Lines changed: 3 additions & 2 deletions
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.17 2001/05/14 20:30:19 momjian Exp $
3+
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.18 2001/06/12 05:55:48 tgl Exp $
44
-->
55

66
<chapter id="catalogs">
@@ -645,7 +645,8 @@
645645
<entry>relisshared</entry>
646646
<entry><type>bool</type></entry>
647647
<entry></entry>
648-
<entry>XXX (This is not what it seems to be.)</entry>
648+
<entry>True if this table is shared across all databases in the
649+
cluster.</entry>
649650
</row>
650651

651652
<row>

src/backend/access/common/heaptuple.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.71 2001/03/22 06:16:06 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.72 2001/06/12 05:55:49 tgl Exp $
1313
*
1414
* NOTES
1515
* The old interface functions have been converted to macros
@@ -738,44 +738,46 @@ heap_freetuple(HeapTuple htup)
738738
}
739739

740740

741-
/* ----------------------------------------------------------------
742-
* other misc functions
743-
* ----------------------------------------------------------------
741+
/* ----------------
742+
* heap_addheader
743+
*
744+
* This routine forms a HeapTuple by copying the given structure (tuple
745+
* data) and adding a generic header. Note that the tuple data is
746+
* presumed to contain no null fields. It is typically only useful
747+
* for null-free system tables.
748+
* ----------------
744749
*/
745-
746750
HeapTuple
747-
heap_addheader(uint32 natts, /* max domain index */
748-
int structlen, /* its length */
749-
char *structure) /* pointer to the struct */
751+
heap_addheader(int natts, /* max domain index */
752+
Size structlen, /* its length */
753+
void *structure) /* pointer to the struct */
750754
{
751755
HeapTuple tuple;
752-
HeapTupleHeader td; /* tuple data */
753-
unsigned long len;
756+
HeapTupleHeader td;
757+
Size len;
754758
int hoff;
755759

756760
AssertArg(natts > 0);
757761

758-
len = offsetof(HeapTupleHeaderData, t_bits);
762+
/* header needs no null bitmap */
763+
hoff = MAXALIGN(offsetof(HeapTupleHeaderData, t_bits));
764+
len = hoff + structlen;
759765

760-
hoff = len = MAXALIGN(len); /* be conservative */
761-
len += structlen;
762766
tuple = (HeapTuple) palloc(HEAPTUPLESIZE + len);
763-
tuple->t_datamcxt = CurrentMemoryContext;
764-
td = tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
765767

766768
tuple->t_len = len;
767769
ItemPointerSetInvalid(&(tuple->t_self));
768770
tuple->t_tableOid = InvalidOid;
771+
tuple->t_datamcxt = CurrentMemoryContext;
772+
tuple->t_data = td = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
769773

770774
MemSet((char *) td, 0, len);
771775

772776
td->t_hoff = hoff;
773777
td->t_natts = natts;
774-
td->t_infomask = 0;
775-
td->t_infomask |= HEAP_XMAX_INVALID;
778+
td->t_infomask = HEAP_XMAX_INVALID; /* XXX sufficient? */
776779

777-
if (structlen > 0)
778-
memcpy((char *) td + hoff, structure, (size_t) structlen);
780+
memcpy((char *) td + hoff, structure, structlen);
779781

780782
return tuple;
781783
}

src/backend/catalog/Makefile

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Makefile for catalog
44
#
5-
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.34 2001/05/14 21:58:10 momjian Exp $
5+
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.35 2001/06/12 05:55:49 tgl Exp $
66
#
77
#-------------------------------------------------------------------------
88

@@ -14,42 +14,36 @@ OBJS = catalog.o heap.o index.o indexing.o aclchk.o \
1414
pg_aggregate.o pg_largeobject.o pg_operator.o pg_proc.o \
1515
pg_type.o
1616

17-
BKIFILES = global.bki template1.bki global.description template1.description
17+
BKIFILES = postgres.bki postgres.description
1818

1919
all: SUBSYS.o $(BKIFILES)
2020

2121
SUBSYS.o: $(OBJS)
2222
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
2323

24+
# Note: there are some undocumented dependencies on the ordering in which
25+
# the catalog header files are assembled into postgres.bki. In particular,
26+
# indexing.h had better be last.
2427

25-
GLOBAL_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
26-
pg_database.h pg_shadow.h pg_group.h pg_log.h \
27-
)
28-
29-
TEMPLATE1_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
28+
POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
3029
pg_proc.h pg_type.h pg_attribute.h pg_class.h \
31-
pg_inherits.h pg_index.h pg_statistic.h \
30+
pg_attrdef.h pg_relcheck.h pg_inherits.h pg_index.h \
3231
pg_operator.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
33-
pg_language.h pg_largeobject.h pg_aggregate.h \
34-
pg_rewrite.h pg_listener.h pg_description.h indexing.h \
32+
pg_language.h pg_largeobject.h pg_aggregate.h pg_statistic.h \
33+
pg_rewrite.h pg_trigger.h pg_listener.h pg_description.h \
34+
pg_database.h pg_shadow.h pg_group.h pg_log.h indexing.h \
3535
)
3636

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

39-
global.bki global.description: genbki.sh $(GLOBAL_BKI_SRCS) $(top_srcdir)/src/include/catalog/indexing.h \
40-
$(top_srcdir)/src/include/postgres_ext.h $(top_builddir)/src/include/config.h
41-
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o global $(pg_includes) $(GLOBAL_BKI_SRCS) --set-version=$(VERSION)
42-
43-
template1.bki template1.description: genbki.sh $(TEMPLATE1_BKI_SRCS) \
39+
postgres.bki postgres.description: genbki.sh $(POSTGRES_BKI_SRCS) \
4440
$(top_srcdir)/src/include/postgres_ext.h $(top_builddir)/src/include/config.h
45-
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o template1 $(pg_includes) $(TEMPLATE1_BKI_SRCS) --set-version=$(VERSION)
41+
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o postgres $(pg_includes) $(POSTGRES_BKI_SRCS) --set-version=$(VERSION)
4642

4743
.PHONY: install-bki
4844
install-bki: $(BKIFILES) installdirs
49-
$(INSTALL_DATA) global.bki $(DESTDIR)$(datadir)/global.bki
50-
$(INSTALL_DATA) global.description $(DESTDIR)$(datadir)/global.description
51-
$(INSTALL_DATA) template1.bki $(DESTDIR)$(datadir)/template1.bki
52-
$(INSTALL_DATA) template1.description $(DESTDIR)$(datadir)/template1.description
45+
$(INSTALL_DATA) postgres.bki $(DESTDIR)$(datadir)/postgres.bki
46+
$(INSTALL_DATA) postgres.description $(DESTDIR)$(datadir)/postgres.description
5347

5448
installdirs:
5549
$(mkinstalldirs) $(DESTDIR)$(datadir)

src/backend/catalog/heap.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.166 2001/05/30 12:57:36 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.167 2001/06/12 05:55:49 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -218,8 +218,9 @@ heap_create(char *relname,
218218
}
219219

220220
/*
221-
* real ugly stuff to assign the proper relid in the relation
222-
* descriptor follows.
221+
* Real ugly stuff to assign the proper relid in the relation
222+
* descriptor follows. Note that only "bootstrapped" relations
223+
* whose OIDs are hard-coded in pg_class.h need be listed here.
223224
*/
224225
if (relname && IsSystemRelationName(relname))
225226
{
@@ -263,12 +264,6 @@ heap_create(char *relname,
263264
tblNode = InvalidOid;
264265
relid = RelOid_pg_log;
265266
}
266-
else if (strcmp(AttrDefaultRelationName, relname) == 0)
267-
relid = RelOid_pg_attrdef;
268-
else if (strcmp(RelCheckRelationName, relname) == 0)
269-
relid = RelOid_pg_relcheck;
270-
else if (strcmp(TriggerRelationName, relname) == 0)
271-
relid = RelOid_pg_trigger;
272267
else
273268
{
274269
relid = newoid();
@@ -566,7 +561,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
566561

567562
tup = heap_addheader(Natts_pg_attribute,
568563
ATTRIBUTE_TUPLE_SIZE,
569-
(char *) *dpp);
564+
(void *) *dpp);
570565

571566
heap_insert(rel, tup);
572567

@@ -583,16 +578,18 @@ AddNewAttributeTuples(Oid new_rel_oid,
583578
dpp = SysAtt;
584579
for (i = 0; i < -1 - FirstLowInvalidHeapAttributeNumber; i++)
585580
{
586-
/* Fill in the correct relation OID */
587-
/* HACK: we are writing on static data here */
588-
(*dpp)->attrelid = new_rel_oid;
589-
/* Unneeded since they should be OK in the constant data anyway */
590-
/* (*dpp)->attstattarget = 0; */
591-
/* (*dpp)->attcacheoff = -1; */
581+
Form_pg_attribute attStruct;
592582

593583
tup = heap_addheader(Natts_pg_attribute,
594584
ATTRIBUTE_TUPLE_SIZE,
595-
(char *) *dpp);
585+
(void *) *dpp);
586+
587+
/* Fill in the correct relation OID in the copied tuple */
588+
attStruct = (Form_pg_attribute) GETSTRUCT(tup);
589+
attStruct->attrelid = new_rel_oid;
590+
/* Unneeded since they should be OK in the constant data anyway */
591+
/* attStruct->attstattarget = 0; */
592+
/* attStruct->attcacheoff = -1; */
596593

597594
heap_insert(rel, tup);
598595

@@ -603,13 +600,13 @@ AddNewAttributeTuples(Oid new_rel_oid,
603600
dpp++;
604601
}
605602

606-
heap_close(rel, RowExclusiveLock);
607-
608603
/*
609604
* close pg_attribute indices
610605
*/
611606
if (hasindex)
612607
CatalogCloseIndices(Num_pg_attr_indices, idescs);
608+
609+
heap_close(rel, RowExclusiveLock);
613610
}
614611

615612
/* --------------------------------
@@ -686,7 +683,7 @@ AddNewRelationTuple(Relation pg_class_desc,
686683
*/
687684
tup = heap_addheader(Natts_pg_class_fixed,
688685
CLASS_TUPLE_SIZE,
689-
(char *) new_rel_reltup);
686+
(void *) new_rel_reltup);
690687

691688
/* force tuple to have the desired OID */
692689
tup->t_data->t_oid = new_rel_oid;

0 commit comments

Comments
 (0)