2 /*-------------------------------------------------------------------------
5 * yacc grammar for the "bootstrap" mode (BKI file format)
7 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.82 2006/07/03 22:45:37 tgl Exp $
14 *-------------------------------------------------------------------------
21 #include "access/attnum.h"
22 #include "access/htup.h"
23 #include "access/itup.h"
24 #include "access/skey.h"
25 #include "access/tupdesc.h"
26 #include "access/xact.h"
27 #include "bootstrap/bootstrap.h"
28 #include "catalog/catalog.h"
29 #include "catalog/heap.h"
30 #include "catalog/pg_am.h"
31 #include "catalog/pg_attribute.h"
32 #include "catalog/pg_authid.h"
33 #include "catalog/pg_class.h"
34 #include "catalog/pg_namespace.h"
35 #include "catalog/pg_tablespace.h"
36 #include "commands/defrem.h"
37 #include "miscadmin.h"
38 #include "nodes/makefuncs.h"
39 #include "nodes/nodes.h"
40 #include "nodes/parsenodes.h"
41 #include "nodes/pg_list.h"
42 #include "nodes/primnodes.h"
43 #include "rewrite/prs2lock.h"
44 #include "storage/block.h"
45 #include "storage/fd.h"
46 #include "storage/ipc.h"
47 #include "storage/itemptr.h"
48 #include "storage/off.h"
49 #include "storage/smgr.h"
50 #include "tcop/dest.h"
51 #include "utils/rel.h"
53 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
59 StartTransactionCommand();
60 elog(DEBUG4, "start transaction");
67 CommitTransactionCommand();
68 elog(DEBUG4, "commit transaction");
69 CHECK_FOR_INTERRUPTS(); /* allow SIGINT to kill bootstrap run */
72 printf("bootstrap> ");
78 int num_columns_read = 0;
82 %name-prefix="boot_yy"
93 %type <list> boot_index_params
94 %type <ielem> boot_index_param
95 %type <ival> boot_const boot_ident
96 %type <ival> optbootstrap optsharedrelation optwithoutoids
97 %type <ival> boot_tuple boot_tuplelist
98 %type <oidval> oidspec optoideq
100 %token <ival> CONST_P ID
101 %token OPEN XCLOSE XCREATE INSERT_TUPLE
102 %token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE
103 %token COMMA EQUALS LPAREN RPAREN
104 %token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS NULLVAL
119 | Boot_Queries Boot_Query
127 | Boot_DeclareIndexStmt
128 | Boot_DeclareUniqueIndexStmt
136 boot_openrel(LexIDStr($2));
142 XCLOSE boot_ident %prec low
145 closerel(LexIDStr($2));
157 XCREATE optbootstrap optsharedrelation optwithoutoids boot_ident oidspec LPAREN
161 elog(DEBUG4, "creating%s%s relation %s %u",
162 $2 ? " bootstrap" : "",
177 tupdesc = CreateTupleDesc(numattr, !($4), attrtypes);
183 elog(DEBUG4, "create bootstrap: warning, open relation exists, closing first");
187 boot_reldesc = heap_create(LexIDStr($5),
188 PG_CATALOG_NAMESPACE,
189 $3 ? GLOBALTABLESPACE_OID : 0,
195 elog(DEBUG4, "bootstrap relation created");
201 id = heap_create_with_catalog(LexIDStr($5),
202 PG_CATALOG_NAMESPACE,
203 $3 ? GLOBALTABLESPACE_OID : 0,
205 BOOTSTRAP_SUPERUSERID,
214 elog(DEBUG4, "relation created with oid %u", id);
221 INSERT_TUPLE optoideq
225 elog(DEBUG4, "inserting row with oid %u", $2);
227 elog(DEBUG4, "inserting row");
228 num_columns_read = 0;
230 LPAREN boot_tuplelist RPAREN
232 if (num_columns_read != numattr)
233 elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
234 numattr, num_columns_read);
235 if (boot_reldesc == NULL)
237 elog(ERROR, "relation not open");
245 Boot_DeclareIndexStmt:
246 XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
250 DefineIndex(makeRangeVar(NULL, LexIDStr($6)),
258 false, false, true, false);
263 Boot_DeclareUniqueIndexStmt:
264 XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
268 DefineIndex(makeRangeVar(NULL, LexIDStr($7)),
276 false, false, true, false);
292 boot_index_params COMMA boot_index_param { $$ = lappend($1, $3); }
293 | boot_index_param { $$ = list_make1($1); }
297 boot_ident boot_ident
299 IndexElem *n = makeNode(IndexElem);
300 n->name = LexIDStr($1);
302 n->opclass = list_make1(makeString(LexIDStr($2)));
308 XBOOTSTRAP { $$ = 1; }
313 XSHARED_RELATION { $$ = 1; }
318 XWITHOUT_OIDS { $$ = 1; }
324 | boot_typelist COMMA boot_type_thing
328 boot_ident EQUALS boot_ident
330 if (++numattr > MAXATTR)
331 elog(FATAL, "too many columns");
332 DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
337 boot_ident { $$ = atooid(LexIDStr($1)); }
341 OBJ_ID EQUALS oidspec { $$ = $3; }
347 | boot_tuplelist boot_tuple
348 | boot_tuplelist COMMA boot_tuple
353 { InsertOneValue(LexIDStr($1), num_columns_read++); }
355 { InsertOneValue(LexIDStr($1), num_columns_read++); }
357 { InsertOneNull(num_columns_read++); }
361 CONST_P { $$=yylval.ival; }
365 ID { $$=yylval.ival; }
369 #include "bootscanner.c"