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

Commit 6e38e34

Browse files
committed
Change the bootstrap sequence so that toast tables for system catalogs are
created in the bootstrap phase proper, rather than added after-the-fact by initdb. This is cleaner than before because it allows us to retire the undocumented ALTER TABLE ... CREATE TOAST TABLE command, but the real reason I'm doing it is so that toast tables of shared catalogs will now have predetermined OIDs. This will allow a reasonably clean solution to the problem of locking tables before we load their relcache entries, to appear in a forthcoming patch.
1 parent 638860c commit 6e38e34

26 files changed

+529
-406
lines changed

doc/src/sgml/bki.sgml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.17 2006/03/10 19:10:46 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/bki.sgml,v 1.18 2006/07/31 01:16:36 tgl Exp $ -->
22

33
<chapter id="bki">
44
<title><acronym>BKI</acronym> Backend Interface</title>
@@ -209,6 +209,28 @@
209209
</listitem>
210210
</varlistentry>
211211

212+
<varlistentry>
213+
<term>
214+
<literal>declare toast</>
215+
<replaceable class="parameter">toasttableoid</replaceable>
216+
<replaceable class="parameter">toastindexoid</replaceable>
217+
<literal>on</> <replaceable class="parameter">tablename</replaceable>
218+
</term>
219+
220+
<listitem>
221+
<para>
222+
Create a TOAST table for the table named
223+
<replaceable class="parameter">tablename</replaceable>.
224+
The TOAST table is assigned OID
225+
<replaceable class="parameter">toasttableoid</replaceable>
226+
and its index is assigned OID
227+
<replaceable class="parameter">toastindexoid</replaceable>.
228+
As with <literal>declare index</>, filling of the index
229+
is postponed.
230+
</para>
231+
</listitem>
232+
</varlistentry>
233+
212234
<varlistentry>
213235
<term><literal>build indices</></term>
214236

@@ -235,6 +257,12 @@
235257
the created table for data insertion.
236258
</para>
237259

260+
<para>
261+
Also, the <literal>declare index</> and <literal>declare toast</>
262+
commands cannot be used until the system catalogs they need have been
263+
created and filled in.
264+
</para>
265+
238266
<para>
239267
Thus, the structure of the <filename>postgres.bki</filename> file has to
240268
be:
@@ -286,7 +314,7 @@
286314
</listitem>
287315
<listitem>
288316
<para>
289-
Define indexes.
317+
Define indexes and toast tables.
290318
</para>
291319
</listitem>
292320
<listitem>

doc/src/sgml/keywords.sgml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/keywords.sgml,v 2.16 2005/10/12 09:45:29 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/keywords.sgml,v 2.17 2006/07/31 01:16:36 tgl Exp $ -->
22

33
<appendix id="sql-keywords-appendix">
44
<title><acronym>SQL</acronym> Key Words</title>
@@ -4013,13 +4013,6 @@
40134013
<entry>reserved</entry>
40144014
<entry>reserved</entry>
40154015
</row>
4016-
<row>
4017-
<entry><token>TOAST</token></entry>
4018-
<entry>non-reserved</entry>
4019-
<entry></entry>
4020-
<entry></entry>
4021-
<entry></entry>
4022-
</row>
40234016
<row>
40244017
<entry><token>TOP_LEVEL_COUNT</token></entry>
40254018
<entry></entry>

src/backend/bootstrap/bootparse.y

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.82 2006/07/03 22:45:37 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.83 2006/07/31 01:16:36 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -33,6 +33,7 @@
3333
#include "catalog/pg_class.h"
3434
#include "catalog/pg_namespace.h"
3535
#include "catalog/pg_tablespace.h"
36+
#include "catalog/toasting.h"
3637
#include "commands/defrem.h"
3738
#include "miscadmin.h"
3839
#include "nodes/makefuncs.h"
@@ -99,7 +100,7 @@ int num_columns_read = 0;
99100

100101
%token <ival> CONST_P ID
101102
%token OPEN XCLOSE XCREATE INSERT_TUPLE
102-
%token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE
103+
%token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE XTOAST
103104
%token COMMA EQUALS LPAREN RPAREN
104105
%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS NULLVAL
105106
%start TopLevel
@@ -126,6 +127,7 @@ Boot_Query :
126127
| Boot_InsertStmt
127128
| Boot_DeclareIndexStmt
128129
| Boot_DeclareUniqueIndexStmt
130+
| Boot_DeclareToastStmt
129131
| Boot_BuildIndsStmt
130132
;
131133

@@ -278,6 +280,16 @@ Boot_DeclareUniqueIndexStmt:
278280
}
279281
;
280282

283+
Boot_DeclareToastStmt:
284+
XDECLARE XTOAST oidspec oidspec ON boot_ident
285+
{
286+
do_start();
287+
288+
BootstrapToastTable(LexIDStr($6), $3, $4);
289+
do_end();
290+
}
291+
;
292+
281293
Boot_BuildIndsStmt:
282294
XBUILD INDICES
283295
{

src/backend/bootstrap/bootscanner.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.42 2006/03/07 01:03:12 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.43 2006/07/31 01:16:36 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -99,6 +99,7 @@ insert { return(INSERT_TUPLE); }
9999
"index" { return(INDEX); }
100100
"on" { return(ON); }
101101
"using" { return(USING); }
102+
"toast" { return(XTOAST); }
102103

103104
{arrayid} {
104105
yylval.ival = EnterString(MapArrayTypeName((char*)yytext));

src/backend/bootstrap/bootstrap.c

Lines changed: 2 additions & 2 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-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.221 2006/07/29 03:02:55 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.222 2006/07/31 01:16:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1242,7 +1242,7 @@ build_indices(void)
12421242
heap = heap_open(ILHead->il_heap, NoLock);
12431243
ind = index_open(ILHead->il_ind);
12441244

1245-
index_build(heap, ind, ILHead->il_info, false, false);
1245+
index_build(heap, ind, ILHead->il_info, false);
12461246

12471247
index_close(ind);
12481248
heap_close(heap, NoLock);

src/backend/catalog/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Makefile for backend/catalog
44
#
5-
# $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.59 2006/02/12 03:22:17 momjian Exp $
5+
# $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.60 2006/07/31 01:16:36 tgl Exp $
66
#
77
#-------------------------------------------------------------------------
88

@@ -13,7 +13,7 @@ include $(top_builddir)/src/Makefile.global
1313
OBJS = catalog.o dependency.o heap.o index.o indexing.o namespace.o aclchk.o \
1414
pg_aggregate.o pg_constraint.o pg_conversion.o pg_depend.o \
1515
pg_largeobject.o pg_namespace.o pg_operator.o pg_proc.o pg_shdepend.o \
16-
pg_type.o
16+
pg_type.o toasting.o
1717

1818
BKIFILES = postgres.bki postgres.description postgres.shdescription
1919

@@ -24,7 +24,7 @@ SUBSYS.o: $(OBJS)
2424

2525
# Note: there are some undocumented dependencies on the ordering in which
2626
# the catalog header files are assembled into postgres.bki. In particular,
27-
# indexing.h had better be last.
27+
# indexing.h had better be last, and toasting.h just before it.
2828

2929
POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
3030
pg_proc.h pg_type.h pg_attribute.h pg_class.h pg_autovacuum.h \
@@ -35,7 +35,7 @@ POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
3535
pg_namespace.h pg_conversion.h pg_depend.h \
3636
pg_database.h pg_tablespace.h pg_pltemplate.h \
3737
pg_authid.h pg_auth_members.h pg_shdepend.h pg_shdescription.h \
38-
indexing.h \
38+
toasting.h indexing.h \
3939
)
4040

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

src/backend/catalog/README

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/src/backend/catalog/README,v 1.9 2005/04/14 01:38:15 tgl Exp $
1+
$PostgreSQL: pgsql/src/backend/catalog/README,v 1.10 2006/07/31 01:16:36 tgl Exp $
22

33
This directory contains .c files that manipulate the system catalogs;
44
src/include/catalog contains the .h files that define the structure
@@ -73,8 +73,9 @@ heap_create_with_catalog process, because it needs these tables to exist
7373
already. The list of files this currently includes is:
7474
pg_proc.h pg_type.h pg_attribute.h pg_class.h
7575
Also, indexing.h must be last, since the indexes can't be created until all
76-
the tables are in place. There are reputedly some other order dependencies
77-
in the .bki list, too.
76+
the tables are in place, and toasting.h should probably be next-to-last
77+
(or at least after all the tables that need toast tables). There are
78+
reputedly some other order dependencies in the .bki list, too.
7879

7980
-----------------------------------------------------------------
8081

src/backend/catalog/genbki.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
#
1313
# IDENTIFICATION
14-
# $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.39 2006/03/05 15:58:22 momjian Exp $
14+
# $PostgreSQL: pgsql/src/backend/catalog/genbki.sh,v 1.40 2006/07/31 01:16:36 tgl Exp $
1515
#
1616
# NOTES
1717
# non-essential whitespace is removed from the generated file.
@@ -276,6 +276,28 @@ comment_level > 0 { next; }
276276
print "declare unique index " iname " " oid " " data
277277
}
278278
279+
/^DECLARE_TOAST\(/ {
280+
# ----
281+
# end any prior catalog data insertions before starting a define toast
282+
# ----
283+
if (reln_open == 1) {
284+
print "close " catalog;
285+
reln_open = 0;
286+
}
287+
288+
data = substr($0, 15, length($0) - 15);
289+
pos = index(data, ",");
290+
tname = substr(data, 1, pos-1);
291+
data = substr(data, pos+1, length(data)-pos);
292+
pos = index(data, ",");
293+
toastoid = substr(data, 1, pos-1);
294+
data = substr(data, pos+1, length(data)-pos);
295+
# previous commands already removed the trailing );
296+
indexoid = data;
297+
298+
print "declare toast " toastoid " " indexoid " on " tname
299+
}
300+
279301
/^BUILD_INDICES/ { print "build indices"; }
280302
281303
# ----------------

src/backend/catalog/heap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.309 2006/07/14 14:52:17 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.310 2006/07/31 01:16:36 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2009,8 +2009,8 @@ RelationTruncateIndexes(Oid heapId)
20092009
RelationTruncate(currentIndex, 0);
20102010

20112011
/* Initialize the index and rebuild */
2012-
/* Note: we do not need to re-establish pkey or toast settings */
2013-
index_build(heapRelation, currentIndex, indexInfo, false, false);
2012+
/* Note: we do not need to re-establish pkey setting */
2013+
index_build(heapRelation, currentIndex, indexInfo, false);
20142014

20152015
/* We're done with this index */
20162016
index_close(currentIndex);

src/backend/catalog/index.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.270 2006/07/30 02:07:18 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.271 2006/07/31 01:16:36 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -424,7 +424,6 @@ UpdateIndexRelation(Oid indexoid,
424424
* classObjectId: array of index opclass OIDs, one per index column
425425
* reloptions: AM-specific options
426426
* isprimary: index is a PRIMARY KEY
427-
* istoast: index is a toast table's index
428427
* isconstraint: index is owned by a PRIMARY KEY or UNIQUE constraint
429428
* allow_system_table_mods: allow table to be a system catalog
430429
* skip_build: true to skip the index_build() step for the moment; caller
@@ -442,7 +441,6 @@ index_create(Oid heapRelationId,
442441
Oid *classObjectId,
443442
Datum reloptions,
444443
bool isprimary,
445-
bool istoast,
446444
bool isconstraint,
447445
bool allow_system_table_mods,
448446
bool skip_build)
@@ -747,8 +745,7 @@ index_create(Oid heapRelationId,
747745
}
748746
else
749747
{
750-
index_build(heapRelation, indexRelation, indexInfo,
751-
isprimary, istoast);
748+
index_build(heapRelation, indexRelation, indexInfo, isprimary);
752749
}
753750

754751
/*
@@ -1241,8 +1238,8 @@ setNewRelfilenode(Relation relation)
12411238
* entries of the index and heap relation as needed, using statistics
12421239
* returned by ambuild as well as data passed by the caller.
12431240
*
1244-
* Note: when reindexing an existing index, isprimary and istoast can be
1245-
* false; the index is already properly marked and need not be re-marked.
1241+
* Note: when reindexing an existing index, isprimary can be false;
1242+
* the index is already properly marked and need not be re-marked.
12461243
*
12471244
* Note: before Postgres 8.2, the passed-in heap and index Relations
12481245
* were automatically closed by this routine. This is no longer the case.
@@ -1252,8 +1249,7 @@ void
12521249
index_build(Relation heapRelation,
12531250
Relation indexRelation,
12541251
IndexInfo *indexInfo,
1255-
bool isprimary,
1256-
bool istoast)
1252+
bool isprimary)
12571253
{
12581254
RegProcedure procedure;
12591255
IndexBuildResult *stats;
@@ -1283,7 +1279,8 @@ index_build(Relation heapRelation,
12831279
index_update_stats(heapRelation,
12841280
true,
12851281
isprimary,
1286-
istoast ? RelationGetRelid(indexRelation) : InvalidOid,
1282+
(heapRelation->rd_rel->relkind == RELKIND_TOASTVALUE) ?
1283+
RelationGetRelid(indexRelation) : InvalidOid,
12871284
stats->heap_tuples);
12881285

12891286
index_update_stats(indexRelation,
@@ -1618,8 +1615,8 @@ reindex_index(Oid indexId)
16181615
}
16191616

16201617
/* Initialize the index and rebuild */
1621-
/* Note: we do not need to re-establish pkey or toast settings */
1622-
index_build(heapRelation, iRel, indexInfo, false, false);
1618+
/* Note: we do not need to re-establish pkey setting */
1619+
index_build(heapRelation, iRel, indexInfo, false);
16231620
}
16241621
PG_CATCH();
16251622
{

0 commit comments

Comments
 (0)