]> granicus.if.org Git - postgresql/blob - src/backend/bootstrap/bootparse.y
Code review for FILLFACTOR patch. Change WITH grammar as per earlier
[postgresql] / src / backend / bootstrap / bootparse.y
1 %{
2 /*-------------------------------------------------------------------------
3  *
4  * bootparse.y
5  *        yacc grammar for the "bootstrap" mode (BKI file format)
6  *
7  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  *
11  * IDENTIFICATION
12  *        $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.82 2006/07/03 22:45:37 tgl Exp $
13  *
14  *-------------------------------------------------------------------------
15  */
16
17 #include "postgres.h"
18
19 #include <unistd.h>
20
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"
52
53 #define atooid(x)       ((Oid) strtoul((x), NULL, 10))
54
55
56 static void
57 do_start(void)
58 {
59         StartTransactionCommand();
60         elog(DEBUG4, "start transaction");
61 }
62
63
64 static void
65 do_end(void)
66 {
67         CommitTransactionCommand();
68         elog(DEBUG4, "commit transaction");
69         CHECK_FOR_INTERRUPTS();         /* allow SIGINT to kill bootstrap run */
70         if (isatty(0))
71         {
72                 printf("bootstrap> ");
73                 fflush(stdout);
74         }
75 }
76
77
78 int num_columns_read = 0;
79
80 %}
81
82 %name-prefix="boot_yy"
83
84 %union
85 {
86         List            *list;
87         IndexElem       *ielem;
88         char            *str;
89         int                     ival;
90         Oid                     oidval;
91 }
92
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
99
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
105 %start TopLevel
106
107 %nonassoc low
108 %nonassoc high
109
110 %%
111
112 TopLevel:
113                   Boot_Queries
114                 |
115                 ;
116
117 Boot_Queries:
118                   Boot_Query
119                 | Boot_Queries Boot_Query
120                 ;
121
122 Boot_Query :
123                   Boot_OpenStmt
124                 | Boot_CloseStmt
125                 | Boot_CreateStmt
126                 | Boot_InsertStmt
127                 | Boot_DeclareIndexStmt
128                 | Boot_DeclareUniqueIndexStmt
129                 | Boot_BuildIndsStmt
130                 ;
131
132 Boot_OpenStmt:
133                   OPEN boot_ident
134                                 {
135                                         do_start();
136                                         boot_openrel(LexIDStr($2));
137                                         do_end();
138                                 }
139                 ;
140
141 Boot_CloseStmt:
142                   XCLOSE boot_ident %prec low
143                                 {
144                                         do_start();
145                                         closerel(LexIDStr($2));
146                                         do_end();
147                                 }
148                 | XCLOSE %prec high
149                                 {
150                                         do_start();
151                                         closerel(NULL);
152                                         do_end();
153                                 }
154                 ;
155
156 Boot_CreateStmt:
157                   XCREATE optbootstrap optsharedrelation optwithoutoids boot_ident oidspec LPAREN
158                                 {
159                                         do_start();
160                                         numattr = 0;
161                                         elog(DEBUG4, "creating%s%s relation %s %u",
162                                                  $2 ? " bootstrap" : "",
163                                                  $3 ? " shared" : "",
164                                                  LexIDStr($5),
165                                                  $6);
166                                 }
167                   boot_typelist
168                                 {
169                                         do_end();
170                                 }
171                   RPAREN
172                                 {
173                                         TupleDesc tupdesc;
174
175                                         do_start();
176
177                                         tupdesc = CreateTupleDesc(numattr, !($4), attrtypes);
178
179                                         if ($2)
180                                         {
181                                                 if (boot_reldesc)
182                                                 {
183                                                         elog(DEBUG4, "create bootstrap: warning, open relation exists, closing first");
184                                                         closerel(NULL);
185                                                 }
186
187                                                 boot_reldesc = heap_create(LexIDStr($5),
188                                                                                                    PG_CATALOG_NAMESPACE,
189                                                                                                    $3 ? GLOBALTABLESPACE_OID : 0,
190                                                                                                    $6,
191                                                                                                    tupdesc,
192                                                                                                    RELKIND_RELATION,
193                                                                                                    $3,
194                                                                                                    true);
195                                                 elog(DEBUG4, "bootstrap relation created");
196                                         }
197                                         else
198                                         {
199                                                 Oid id;
200
201                                                 id = heap_create_with_catalog(LexIDStr($5),
202                                                                                                           PG_CATALOG_NAMESPACE,
203                                                                                                           $3 ? GLOBALTABLESPACE_OID : 0,
204                                                                                                           $6,
205                                                                                                           BOOTSTRAP_SUPERUSERID,
206                                                                                                           tupdesc,
207                                                                                                           RELKIND_RELATION,
208                                                                                                           $3,
209                                                                                                           true,
210                                                                                                           0,
211                                                                                                           ONCOMMIT_NOOP,
212                                                                                                           (Datum) 0,
213                                                                                                           true);
214                                                 elog(DEBUG4, "relation created with oid %u", id);
215                                         }
216                                         do_end();
217                                 }
218                 ;
219
220 Boot_InsertStmt:
221                   INSERT_TUPLE optoideq
222                                 {
223                                         do_start();
224                                         if ($2)
225                                                 elog(DEBUG4, "inserting row with oid %u", $2);
226                                         else
227                                                 elog(DEBUG4, "inserting row");
228                                         num_columns_read = 0;
229                                 }
230                   LPAREN  boot_tuplelist RPAREN
231                                 {
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)
236                                         {
237                                                 elog(ERROR, "relation not open");
238                                                 err_out();
239                                         }
240                                         InsertOneTuple($2);
241                                         do_end();
242                                 }
243                 ;
244
245 Boot_DeclareIndexStmt:
246                   XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
247                                 {
248                                         do_start();
249
250                                         DefineIndex(makeRangeVar(NULL, LexIDStr($6)),
251                                                                 LexIDStr($3),
252                                                                 $4,
253                                                                 LexIDStr($8),
254                                                                 NULL,
255                                                                 $10,
256                                                                 NULL, NIL, NIL,
257                                                                 false, false, false,
258                                                                 false, false, true, false);
259                                         do_end();
260                                 }
261                 ;
262
263 Boot_DeclareUniqueIndexStmt:
264                   XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
265                                 {
266                                         do_start();
267
268                                         DefineIndex(makeRangeVar(NULL, LexIDStr($7)),
269                                                                 LexIDStr($4),
270                                                                 $5,
271                                                                 LexIDStr($9),
272                                                                 NULL,
273                                                                 $11,
274                                                                 NULL, NIL, NIL,
275                                                                 true, false, false,
276                                                                 false, false, true, false);
277                                         do_end();
278                                 }
279                 ;
280
281 Boot_BuildIndsStmt:
282                   XBUILD INDICES
283                                 {
284                                         do_start();
285                                         build_indices();
286                                         do_end();
287                                 }
288                 ;
289
290
291 boot_index_params:
292                 boot_index_params COMMA boot_index_param        { $$ = lappend($1, $3); }
293                 | boot_index_param                                                      { $$ = list_make1($1); }
294                 ;
295
296 boot_index_param:
297                 boot_ident boot_ident
298                                 {
299                                         IndexElem *n = makeNode(IndexElem);
300                                         n->name = LexIDStr($1);
301                                         n->expr = NULL;
302                                         n->opclass = list_make1(makeString(LexIDStr($2)));
303                                         $$ = n;
304                                 }
305                 ;
306
307 optbootstrap:
308                         XBOOTSTRAP      { $$ = 1; }
309                 |                               { $$ = 0; }
310                 ;
311
312 optsharedrelation:
313                         XSHARED_RELATION        { $$ = 1; }
314                 |                                               { $$ = 0; }
315                 ;
316
317 optwithoutoids:
318                         XWITHOUT_OIDS   { $$ = 1; }
319                 |                                       { $$ = 0; }
320                 ;
321
322 boot_typelist:
323                   boot_type_thing
324                 | boot_typelist COMMA boot_type_thing
325                 ;
326
327 boot_type_thing:
328                   boot_ident EQUALS boot_ident
329                                 {
330                                    if (++numattr > MAXATTR)
331                                                 elog(FATAL, "too many columns");
332                                    DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
333                                 }
334                 ;
335
336 oidspec:
337                         boot_ident                                                      { $$ = atooid(LexIDStr($1)); }
338                 ;
339
340 optoideq:
341                         OBJ_ID EQUALS oidspec                           { $$ = $3; }
342                 |                                                                               { $$ = (Oid) 0; }
343                 ;
344
345 boot_tuplelist:
346                    boot_tuple
347                 |  boot_tuplelist boot_tuple
348                 |  boot_tuplelist COMMA boot_tuple
349                 ;
350
351 boot_tuple:
352                   boot_ident
353                         { InsertOneValue(LexIDStr($1), num_columns_read++); }
354                 | boot_const
355                         { InsertOneValue(LexIDStr($1), num_columns_read++); }
356                 | NULLVAL
357                         { InsertOneNull(num_columns_read++); }
358                 ;
359
360 boot_const :
361                   CONST_P { $$=yylval.ival; }
362                 ;
363
364 boot_ident :
365                   ID    { $$=yylval.ival; }
366                 ;
367 %%
368
369 #include "bootscanner.c"