~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/bootstrap/bootparse.y

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
/*-------------------------------------------------------------------------
 
3
 *
 
4
 * bootparse.y
 
5
 *        yacc parser grammar for the "backend" initialization program.
 
6
 *
 
7
 * Portions Copyright (c) 1996-2005, 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.75 2004-12-31 21:59:34 pgsql 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_class.h"
 
33
#include "catalog/pg_namespace.h"
 
34
#include "catalog/pg_tablespace.h"
 
35
#include "commands/defrem.h"
 
36
#include "miscadmin.h"
 
37
#include "nodes/makefuncs.h"
 
38
#include "nodes/nodes.h"
 
39
#include "nodes/parsenodes.h"
 
40
#include "nodes/pg_list.h"
 
41
#include "nodes/primnodes.h"
 
42
#include "rewrite/prs2lock.h"
 
43
#include "storage/block.h"
 
44
#include "storage/fd.h"
 
45
#include "storage/ipc.h"
 
46
#include "storage/itemptr.h"
 
47
#include "storage/off.h"
 
48
#include "storage/smgr.h"
 
49
#include "tcop/dest.h"
 
50
#include "utils/nabstime.h"
 
51
#include "utils/rel.h"
 
52
 
 
53
 
 
54
static void
 
55
do_start(void)
 
56
{
 
57
        StartTransactionCommand();
 
58
        elog(DEBUG4, "start transaction");
 
59
}
 
60
 
 
61
 
 
62
static void
 
63
do_end(void)
 
64
{
 
65
        CommitTransactionCommand();
 
66
        elog(DEBUG4, "commit transaction");
 
67
        CHECK_FOR_INTERRUPTS();         /* allow SIGINT to kill bootstrap run */
 
68
        if (isatty(0))
 
69
        {
 
70
                printf("bootstrap> ");
 
71
                fflush(stdout);
 
72
        }
 
73
}
 
74
 
 
75
 
 
76
int num_columns_read = 0;
 
77
 
 
78
%}
 
79
 
 
80
%union
 
81
{
 
82
        List            *list;
 
83
        IndexElem       *ielem;
 
84
        char            *str;
 
85
        int                     ival;
 
86
        Oid                     oidval;
 
87
}
 
88
 
 
89
%type <list>  boot_index_params
 
90
%type <ielem> boot_index_param
 
91
%type <ival>  boot_const boot_ident
 
92
%type <ival>  optbootstrap optsharedrelation optwithoutoids
 
93
%type <ival>  boot_tuple boot_tuplelist
 
94
%type <oidval> optoideq
 
95
 
 
96
%token <ival> CONST_P ID
 
97
%token OPEN XCLOSE XCREATE INSERT_TUPLE
 
98
%token STRING XDEFINE
 
99
%token XDECLARE INDEX ON USING XBUILD INDICES UNIQUE
 
100
%token COMMA EQUALS LPAREN RPAREN
 
101
%token OBJ_ID XBOOTSTRAP XSHARED_RELATION XWITHOUT_OIDS NULLVAL
 
102
%start TopLevel
 
103
 
 
104
%nonassoc low
 
105
%nonassoc high
 
106
 
 
107
%%
 
108
 
 
109
TopLevel:
 
110
                  Boot_Queries
 
111
                |
 
112
                ;
 
113
 
 
114
Boot_Queries:
 
115
                  Boot_Query
 
116
                | Boot_Queries Boot_Query
 
117
                ;
 
118
 
 
119
Boot_Query :
 
120
                  Boot_OpenStmt
 
121
                | Boot_CloseStmt
 
122
                | Boot_CreateStmt
 
123
                | Boot_InsertStmt
 
124
                | Boot_DeclareIndexStmt
 
125
                | Boot_DeclareUniqueIndexStmt
 
126
                | Boot_BuildIndsStmt
 
127
                ;
 
128
 
 
129
Boot_OpenStmt:
 
130
                  OPEN boot_ident
 
131
                                {
 
132
                                        do_start();
 
133
                                        boot_openrel(LexIDStr($2));
 
134
                                        do_end();
 
135
                                }
 
136
                ;
 
137
 
 
138
Boot_CloseStmt:
 
139
                  XCLOSE boot_ident %prec low
 
140
                                {
 
141
                                        do_start();
 
142
                                        closerel(LexIDStr($2));
 
143
                                        do_end();
 
144
                                }
 
145
                | XCLOSE %prec high
 
146
                                {
 
147
                                        do_start();
 
148
                                        closerel(NULL);
 
149
                                        do_end();
 
150
                                }
 
151
                ;
 
152
 
 
153
Boot_CreateStmt:
 
154
                  XCREATE optbootstrap optsharedrelation optwithoutoids boot_ident LPAREN
 
155
                                {
 
156
                                        do_start();
 
157
                                        numattr = 0;
 
158
                                        elog(DEBUG4, "creating%s%s relation %s",
 
159
                                                 $2 ? " bootstrap" : "",
 
160
                                                 $3 ? " shared" : "",
 
161
                                                 LexIDStr($5));
 
162
                                }
 
163
                  boot_typelist
 
164
                                {
 
165
                                        do_end();
 
166
                                }
 
167
                  RPAREN
 
168
                                {
 
169
                                        TupleDesc tupdesc;
 
170
 
 
171
                                        do_start();
 
172
 
 
173
                                        tupdesc = CreateTupleDesc(numattr, !($4), attrtypes);
 
174
 
 
175
                                        if ($2)
 
176
                                        {
 
177
                                                if (boot_reldesc)
 
178
                                                {
 
179
                                                        elog(DEBUG4, "create bootstrap: warning, open relation exists, closing first");
 
180
                                                        closerel(NULL);
 
181
                                                }
 
182
 
 
183
                                                boot_reldesc = heap_create(LexIDStr($5),
 
184
                                                                                                   PG_CATALOG_NAMESPACE,
 
185
                                                                                                   $3 ? GLOBALTABLESPACE_OID : 0,
 
186
                                                                                                   tupdesc,
 
187
                                                                                                   RELKIND_RELATION,
 
188
                                                                                                   $3,
 
189
                                                                                                   true);
 
190
                                                elog(DEBUG4, "bootstrap relation created");
 
191
                                        }
 
192
                                        else
 
193
                                        {
 
194
                                                Oid id;
 
195
 
 
196
                                                id = heap_create_with_catalog(LexIDStr($5),
 
197
                                                                                                          PG_CATALOG_NAMESPACE,
 
198
                                                                                                          $3 ? GLOBALTABLESPACE_OID : 0,
 
199
                                                                                                          tupdesc,
 
200
                                                                                                          RELKIND_RELATION,
 
201
                                                                                                          $3,
 
202
                                                                                                          true,
 
203
                                                                                                          0,
 
204
                                                                                                          ONCOMMIT_NOOP,
 
205
                                                                                                          true);
 
206
                                                elog(DEBUG4, "relation created with oid %u", id);
 
207
                                        }
 
208
                                        do_end();
 
209
                                }
 
210
                ;
 
211
 
 
212
Boot_InsertStmt:
 
213
                  INSERT_TUPLE optoideq
 
214
                                {
 
215
                                        do_start();
 
216
                                        if ($2)
 
217
                                                elog(DEBUG4, "inserting row with oid %u", $2);
 
218
                                        else
 
219
                                                elog(DEBUG4, "inserting row");
 
220
                                        num_columns_read = 0;
 
221
                                }
 
222
                  LPAREN  boot_tuplelist RPAREN
 
223
                                {
 
224
                                        if (num_columns_read != numattr)
 
225
                                                elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
 
226
                                                         numattr, num_columns_read);
 
227
                                        if (boot_reldesc == NULL)
 
228
                                        {
 
229
                                                elog(ERROR, "relation not open");
 
230
                                                err_out();
 
231
                                        }
 
232
                                        InsertOneTuple($2);
 
233
                                        do_end();
 
234
                                }
 
235
                ;
 
236
 
 
237
Boot_DeclareIndexStmt:
 
238
                  XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
 
239
                                {
 
240
                                        do_start();
 
241
 
 
242
                                        DefineIndex(makeRangeVar(NULL, LexIDStr($5)),
 
243
                                                                LexIDStr($3),
 
244
                                                                LexIDStr($7),
 
245
                                                                NULL,
 
246
                                                                $9,
 
247
                                                                NULL, NIL,
 
248
                                                                false, false, false,
 
249
                                                                false, false, true, false);
 
250
                                        do_end();
 
251
                                }
 
252
                ;
 
253
 
 
254
Boot_DeclareUniqueIndexStmt:
 
255
                  XDECLARE UNIQUE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
 
256
                                {
 
257
                                        do_start();
 
258
 
 
259
                                        DefineIndex(makeRangeVar(NULL, LexIDStr($6)),
 
260
                                                                LexIDStr($4),
 
261
                                                                LexIDStr($8),
 
262
                                                                NULL,
 
263
                                                                $10,
 
264
                                                                NULL, NIL,
 
265
                                                                true, false, false,
 
266
                                                                false, false, true, false);
 
267
                                        do_end();
 
268
                                }
 
269
                ;
 
270
 
 
271
Boot_BuildIndsStmt:
 
272
                  XBUILD INDICES
 
273
                                {
 
274
                                        do_start();
 
275
                                        build_indices();
 
276
                                        do_end();
 
277
                                }
 
278
                ;
 
279
 
 
280
 
 
281
boot_index_params:
 
282
                boot_index_params COMMA boot_index_param        { $$ = lappend($1, $3); }
 
283
                | boot_index_param                                                      { $$ = list_make1($1); }
 
284
                ;
 
285
 
 
286
boot_index_param:
 
287
                boot_ident boot_ident
 
288
                                {
 
289
                                        IndexElem *n = makeNode(IndexElem);
 
290
                                        n->name = LexIDStr($1);
 
291
                                        n->expr = NULL;
 
292
                                        n->opclass = list_make1(makeString(LexIDStr($2)));
 
293
                                        $$ = n;
 
294
                                }
 
295
                ;
 
296
 
 
297
optbootstrap:
 
298
                        XBOOTSTRAP      { $$ = 1; }
 
299
                |                               { $$ = 0; }
 
300
                ;
 
301
 
 
302
optsharedrelation:
 
303
                        XSHARED_RELATION        { $$ = 1; }
 
304
                |                                               { $$ = 0; }
 
305
                ;
 
306
 
 
307
optwithoutoids:
 
308
                        XWITHOUT_OIDS   { $$ = 1; }
 
309
                |                                       { $$ = 0; }
 
310
                ;
 
311
 
 
312
boot_typelist:
 
313
                  boot_type_thing
 
314
                | boot_typelist COMMA boot_type_thing
 
315
                ;
 
316
 
 
317
boot_type_thing:
 
318
                  boot_ident EQUALS boot_ident
 
319
                                {
 
320
                                   if (++numattr > MAXATTR)
 
321
                                                elog(FATAL, "too many columns");
 
322
                                   DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
 
323
                                }
 
324
                ;
 
325
 
 
326
optoideq:
 
327
                        OBJ_ID EQUALS boot_ident { $$ = atol(LexIDStr($3));     }
 
328
                |                                               { $$ = (Oid) 0; }
 
329
                ;
 
330
 
 
331
boot_tuplelist:
 
332
                   boot_tuple
 
333
                |  boot_tuplelist boot_tuple
 
334
                |  boot_tuplelist COMMA boot_tuple
 
335
                ;
 
336
 
 
337
boot_tuple:
 
338
                  boot_ident
 
339
                        { InsertOneValue(LexIDStr($1), num_columns_read++); }
 
340
                | boot_const
 
341
                        { InsertOneValue(LexIDStr($1), num_columns_read++); }
 
342
                | NULLVAL
 
343
                        { InsertOneNull(num_columns_read++); }
 
344
                ;
 
345
 
 
346
boot_const :
 
347
                  CONST_P { $$=yylval.ival; }
 
348
                ;
 
349
 
 
350
boot_ident :
 
351
                  ID    { $$=yylval.ival; }
 
352
                ;
 
353
%%
 
354
 
 
355
#include "bootscanner.c"