2 /*-------------------------------------------------------------------------
5 * yacc grammar for the "bootstrap" mode (BKI file format)
7 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 * src/backend/bootstrap/bootparse.y
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 "catalog/toasting.h"
37 #include "commands/defrem.h"
38 #include "miscadmin.h"
39 #include "nodes/makefuncs.h"
40 #include "nodes/nodes.h"
41 #include "nodes/parsenodes.h"
42 #include "nodes/pg_list.h"
43 #include "nodes/primnodes.h"
44 #include "rewrite/prs2lock.h"
45 #include "storage/block.h"
46 #include "storage/fd.h"
47 #include "storage/ipc.h"
48 #include "storage/itemptr.h"
49 #include "storage/off.h"
50 #include "storage/smgr.h"
51 #include "tcop/dest.h"
52 #include "utils/rel.h"
54 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
58 * Bison doesn't allocate anything that needs to live across parser calls,
59 * so we can easily have it use palloc instead of malloc. This prevents
60 * memory leaks if we error out during parsing. Note this only works with
61 * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
62 * if possible, so there's not really much problem anyhow, at least if
63 * you're building with gcc.
65 #define YYMALLOC palloc
71 StartTransactionCommand();
72 elog(DEBUG4, "start transaction");
79 CommitTransactionCommand();
80 elog(DEBUG4, "commit transaction");
81 CHECK_FOR_INTERRUPTS(); /* allow SIGINT to kill bootstrap run */
84 printf("bootstrap> ");
90 static int num_columns_read = 0;
95 %name-prefix="boot_yy"
106 %type <list> boot_index_params
107 %type <ielem> boot_index_param
108 %type <str> boot_const boot_ident
109 %type <ival> optbootstrap optsharedrelation optwithoutoids
110 %type <oidval> oidspec optoideq optrowtypeoid
112 %token <str> CONST_P ID
113 %token OPEN XCLOSE XCREATE INSERT_TUPLE
114 %token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE XTOAST
115 %token COMMA EQUALS LPAREN RPAREN
116 %token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS XROWTYPE_OID NULLVAL
132 | Boot_Queries Boot_Query
140 | Boot_DeclareIndexStmt
141 | Boot_DeclareUniqueIndexStmt
142 | Boot_DeclareToastStmt
156 XCLOSE boot_ident %prec low
171 XCREATE boot_ident oidspec optbootstrap optsharedrelation optwithoutoids optrowtypeoid LPAREN
175 elog(DEBUG4, "creating%s%s relation %s %u",
176 $4 ? " bootstrap" : "",
188 bool shared_relation;
189 bool mapped_relation;
193 tupdesc = CreateTupleDesc(numattr, !($6), attrtypes);
195 shared_relation = $5;
198 * The catalogs that use the relation mapper are the
199 * bootstrap catalogs plus the shared catalogs. If this
200 * ever gets more complicated, we should invent a BKI
201 * keyword to mark the mapped catalogs, but for now a
202 * quick hack seems the most appropriate thing. Note in
203 * particular that all "nailed" heap rels (see formrdesc
204 * in relcache.c) must be mapped.
206 mapped_relation = ($4 || shared_relation);
212 elog(DEBUG4, "create bootstrap: warning, open relation exists, closing first");
216 boot_reldesc = heap_create($2,
217 PG_CATALOG_NAMESPACE,
218 shared_relation ? GLOBALTABLESPACE_OID : 0,
222 RELPERSISTENCE_PERMANENT,
226 elog(DEBUG4, "bootstrap relation created");
232 id = heap_create_with_catalog($2,
233 PG_CATALOG_NAMESPACE,
234 shared_relation ? GLOBALTABLESPACE_OID : 0,
238 BOOTSTRAP_SUPERUSERID,
242 RELPERSISTENCE_PERMANENT,
251 elog(DEBUG4, "relation created with OID %u", id);
258 INSERT_TUPLE optoideq
262 elog(DEBUG4, "inserting row with oid %u", $2);
264 elog(DEBUG4, "inserting row");
265 num_columns_read = 0;
267 LPAREN boot_column_val_list RPAREN
269 if (num_columns_read != numattr)
270 elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
271 numattr, num_columns_read);
272 if (boot_reldesc == NULL)
273 elog(FATAL, "relation not open");
279 Boot_DeclareIndexStmt:
280 XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
284 DefineIndex(makeRangeVar(NULL, $6, -1),
291 false, false, false, false, false,
292 false, false, true, false, false);
297 Boot_DeclareUniqueIndexStmt:
298 XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
302 DefineIndex(makeRangeVar(NULL, $7, -1),
309 true, false, false, false, false,
310 false, false, true, false, false);
315 Boot_DeclareToastStmt:
316 XDECLARE XTOAST oidspec oidspec ON boot_ident
320 BootstrapToastTable($6, $3, $4);
336 boot_index_params COMMA boot_index_param { $$ = lappend($1, $3); }
337 | boot_index_param { $$ = list_make1($1); }
341 boot_ident boot_ident
343 IndexElem *n = makeNode(IndexElem);
346 n->indexcolname = NULL;
348 n->opclass = list_make1(makeString($2));
349 n->ordering = SORTBY_DEFAULT;
350 n->nulls_ordering = SORTBY_NULLS_DEFAULT;
356 XBOOTSTRAP { $$ = 1; }
361 XSHARED_RELATION { $$ = 1; }
366 XWITHOUT_OIDS { $$ = 1; }
371 XROWTYPE_OID oidspec { $$ = $2; }
372 | { $$ = InvalidOid; }
377 | boot_column_list COMMA boot_column_def
381 boot_ident EQUALS boot_ident
383 if (++numattr > MAXATTR)
384 elog(FATAL, "too many columns");
385 DefineAttr($1, $3, numattr-1);
390 boot_ident { $$ = atooid($1); }
394 OBJ_ID EQUALS oidspec { $$ = $3; }
395 | { $$ = InvalidOid; }
398 boot_column_val_list:
400 | boot_column_val_list boot_column_val
401 | boot_column_val_list COMMA boot_column_val
406 { InsertOneValue($1, num_columns_read++); }
408 { InsertOneValue($1, num_columns_read++); }
410 { InsertOneNull(num_columns_read++); }
414 CONST_P { $$ = yylval.str; }
418 ID { $$ = yylval.str; }
422 #include "bootscanner.c"