2 /*-------------------------------------------------------------------------
5 * yacc grammar for the "bootstrap" mode (BKI file format)
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
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 int num_columns_read
= 0;
94 %name
-prefix
="boot_yy"
105 %type
<list
> boot_index_params
106 %type
<ielem
> boot_index_param
107 %type
<ival
> boot_const boot_ident
108 %type
<ival
> optbootstrap optsharedrelation optwithoutoids
109 %type
<ival
> boot_tuple boot_tuplelist
110 %type
<oidval
> oidspec optoideq
112 %token
<ival
> 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 NULLVAL
131 | Boot_Queries Boot_Query
139 | Boot_DeclareIndexStmt
140 | Boot_DeclareUniqueIndexStmt
141 | Boot_DeclareToastStmt
149 boot_openrel
(LexIDStr
($2));
155 XCLOSE boot_ident %prec low
158 closerel
(LexIDStr
($2));
170 XCREATE optbootstrap optsharedrelation optwithoutoids boot_ident oidspec LPAREN
174 elog
(DEBUG4
, "creating%s%s relation %s %u",
175 $2 ?
" bootstrap" : "",
190 tupdesc
= CreateTupleDesc
(numattr
, !($4), attrtypes
);
196 elog
(DEBUG4
, "create bootstrap: warning, open relation exists, closing first");
200 boot_reldesc
= heap_create
(LexIDStr
($5),
201 PG_CATALOG_NAMESPACE
,
202 $3 ? GLOBALTABLESPACE_OID
: 0,
208 elog
(DEBUG4
, "bootstrap relation created");
214 id
= heap_create_with_catalog
(LexIDStr
($5),
215 PG_CATALOG_NAMESPACE
,
216 $3 ? GLOBALTABLESPACE_OID
: 0,
218 BOOTSTRAP_SUPERUSERID
,
228 elog
(DEBUG4
, "relation created with oid %u", id
);
235 INSERT_TUPLE optoideq
239 elog
(DEBUG4
, "inserting row with oid %u", $2);
241 elog
(DEBUG4
, "inserting row");
242 num_columns_read
= 0;
244 LPAREN boot_tuplelist RPAREN
246 if
(num_columns_read
!= numattr
)
247 elog
(ERROR
, "incorrect number of columns in row (expected %d, got %d)",
248 numattr
, num_columns_read
);
249 if
(boot_reldesc
== NULL
)
250 elog
(FATAL
, "relation not open");
256 Boot_DeclareIndexStmt:
257 XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
261 DefineIndex
(makeRangeVar
(NULL
, LexIDStr
($6), -1),
269 false
, false
, true
, false
, false
);
274 Boot_DeclareUniqueIndexStmt:
275 XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
279 DefineIndex
(makeRangeVar
(NULL
, LexIDStr
($7), -1),
287 false
, false
, true
, false
, false
);
292 Boot_DeclareToastStmt:
293 XDECLARE XTOAST oidspec oidspec ON boot_ident
297 BootstrapToastTable
(LexIDStr
($6), $3, $4);
313 boot_index_params COMMA boot_index_param
{ $$
= lappend
($1, $3); }
314 | boot_index_param
{ $$
= list_make1
($1); }
318 boot_ident boot_ident
320 IndexElem
*n
= makeNode
(IndexElem
);
321 n
->name
= LexIDStr
($1);
323 n
->opclass
= list_make1
(makeString
(LexIDStr
($2)));
324 n
->ordering
= SORTBY_DEFAULT
;
325 n
->nulls_ordering
= SORTBY_NULLS_DEFAULT
;
331 XBOOTSTRAP
{ $$
= 1; }
336 XSHARED_RELATION
{ $$
= 1; }
341 XWITHOUT_OIDS
{ $$
= 1; }
347 | boot_typelist COMMA boot_type_thing
351 boot_ident EQUALS boot_ident
353 if
(++numattr
> MAXATTR
)
354 elog
(FATAL
, "too many columns");
355 DefineAttr
(LexIDStr
($1),LexIDStr
($3),numattr
-1);
360 boot_ident
{ $$
= atooid
(LexIDStr
($1)); }
364 OBJ_ID EQUALS oidspec
{ $$
= $3; }
370 | boot_tuplelist boot_tuple
371 | boot_tuplelist COMMA boot_tuple
376 { InsertOneValue
(LexIDStr
($1), num_columns_read
++); }
378 { InsertOneValue
(LexIDStr
($1), num_columns_read
++); }
380 { InsertOneNull
(num_columns_read
++); }
384 CONST_P
{ $$
=yylval.ival
; }
388 ID
{ $$
=yylval.ival
; }
392 #include "bootscanner.c"