OSDN Git Service

5a4b0b50b525bcdf43fdc990e1d9ef1d85555925
[pg-rex/syncrep.git] / src / backend / bootstrap / bootparse.y
1 %{
2 /*-------------------------------------------------------------------------
3  *
4  * backendparse.y
5  *        yacc parser grammer for the "backend" initialization program.
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.24 1999/02/13 23:14:51 momjian Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15
16 #include <stdio.h>
17 #include <time.h>
18
19 #include "postgres.h"
20
21 #include "miscadmin.h"
22
23 #include "access/attnum.h"
24 #include "access/funcindex.h"
25 #include "access/htup.h"
26 #include "access/itup.h"
27 #include "access/skey.h"
28 #include "access/strat.h"
29 #include "access/tupdesc.h"
30 #include "access/xact.h"
31 #include "bootstrap/bootstrap.h"
32 #include "catalog/heap.h"
33 #include "catalog/pg_am.h"
34 #include "catalog/pg_attribute.h"
35 #include "catalog/pg_class.h"
36 #include "commands/defrem.h"
37 #include "nodes/nodes.h"
38 #include "nodes/parsenodes.h"
39 #include "nodes/pg_list.h"
40 #include "nodes/primnodes.h"
41 #include "rewrite/prs2lock.h"
42 #include "storage/block.h"
43 #include "storage/fd.h"
44 #include "storage/ipc.h"
45 #include "storage/itemptr.h"
46 #include "storage/off.h"
47 #include "storage/smgr.h"
48 #include "storage/spin.h"
49 #include "tcop/dest.h"
50 #include "utils/nabstime.h"
51 #include "utils/rel.h"
52
53 #define DO_START { \
54                                         StartTransactionCommand();\
55                                  }
56
57 #define DO_END   { \
58                                         CommitTransactionCommand();\
59                                         if (!Quiet) { EMITPROMPT; }\
60                                                 fflush(stdout); \
61                                  }
62
63 int num_tuples_read = 0;
64 static Oid objectid;
65
66 %}
67
68 %union
69 {
70         List            *list;
71         IndexElem       *ielem;
72         char            *str;
73         int                     ival;
74 }
75
76 %type <list>  boot_index_params
77 %type <ielem> boot_index_param
78 %type <ival> boot_const boot_ident
79 %type <ival> optbootstrap optoideq boot_tuple boot_tuplelist
80
81 %token <ival> CONST ID
82 %token OPEN XCLOSE XCREATE INSERT_TUPLE
83 %token STRING XDEFINE
84 %token XDECLARE INDEX ON USING XBUILD INDICES
85 %token COMMA EQUALS LPAREN RPAREN
86 %token OBJ_ID XBOOTSTRAP NULLVAL
87 %start TopLevel
88
89 %nonassoc low
90 %nonassoc high
91
92 %%
93
94 TopLevel:
95                   Boot_Queries
96                 |
97                 ;
98
99 Boot_Queries:
100                   Boot_Query
101                 | Boot_Queries Boot_Query
102                 ;
103
104 Boot_Query :
105                   Boot_OpenStmt
106                 | Boot_CloseStmt
107                 | Boot_CreateStmt
108                 | Boot_InsertStmt
109                 | Boot_DeclareIndexStmt
110                 | Boot_BuildIndsStmt
111                 ;
112
113 Boot_OpenStmt:
114                   OPEN boot_ident
115                                 {
116                                         DO_START;
117                                         boot_openrel(LexIDStr($2));
118                                         DO_END;
119                                 }
120                 ;
121
122 Boot_CloseStmt:
123                   XCLOSE boot_ident %prec low
124                                 {
125                                         DO_START;
126                                         closerel(LexIDStr($2));
127                                         DO_END;
128                                 }
129                 | XCLOSE %prec high
130                                 {
131                                         DO_START;
132                                         closerel(NULL);
133                                         DO_END;
134                                 }
135                 ;
136
137 Boot_CreateStmt:
138                   XCREATE optbootstrap boot_ident LPAREN
139                                 {
140                                         DO_START;
141                                         numattr=(int)0;
142                                 }
143                   boot_typelist
144                                 {
145                                         if (!Quiet)
146                                                 putchar('\n');
147                                         DO_END;
148                                 }
149                   RPAREN
150                                 {
151                                         DO_START;
152
153                                         if ($2)
154                                         {
155                                                 extern Relation reldesc;
156                                                 TupleDesc tupdesc;
157
158                                                 if (reldesc)
159                                                 {
160                                                         puts("create bootstrap: Warning, open relation");
161                                                         puts("exists, closing first");
162                                                         closerel(NULL);
163                                                 }
164                                                 if (DebugMode)
165                                                         puts("creating bootstrap relation");
166                                                 tupdesc = CreateTupleDesc(numattr,attrtypes);
167                                                 reldesc = heap_create(LexIDStr($3), tupdesc,
168                                                                                           false, false);
169                                                 if (DebugMode)
170                                                         puts("bootstrap relation created ok");
171                                         }
172                                         else
173                                         {
174                                                 Oid id;
175                                                 TupleDesc tupdesc;
176
177                                                 tupdesc = CreateTupleDesc(numattr,attrtypes);
178                                                 id = heap_create_with_catalog(LexIDStr($3),
179                                                                                         tupdesc, RELKIND_RELATION, false);
180                                                 if (!Quiet)
181                                                         printf("CREATED relation %s with OID %d\n",
182                                                                    LexIDStr($3), id);
183                                         }
184                                         DO_END;
185                                         if (DebugMode)
186                                                 puts("Commit End");
187                                 }
188                 ;
189
190 Boot_InsertStmt:
191                   INSERT_TUPLE optoideq
192                                 {
193                                         DO_START;
194                                         if (DebugMode)
195                                                 printf("tuple %d<", $2);
196                                         num_tuples_read = 0;
197                                 }
198                   LPAREN  boot_tuplelist RPAREN
199                                 {
200                                         if (num_tuples_read != numattr)
201                                                 elog(ERROR,"incorrect number of values for tuple");
202                                         if (reldesc == (Relation)NULL)
203                                         {
204                                                 elog(ERROR,"must OPEN RELATION before INSERT\n");
205                                                 err_out();
206                                         }
207                                         if (DebugMode)
208                                                 puts("Insert Begin");
209                                         objectid = $2;
210                                         InsertOneTuple(objectid);
211                                         if (DebugMode)
212                                                 puts("Insert End");
213                                         if (!Quiet)
214                                                 putchar('\n');
215                                         DO_END;
216                                         if (DebugMode)
217                                                 puts("Transaction End");
218                                 }
219                 ;
220
221 Boot_DeclareIndexStmt:
222                   XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
223                                 {
224                                         DO_START;
225
226                                         DefineIndex(LexIDStr($5),
227                                                                 LexIDStr($3),
228                                                                 LexIDStr($7),
229                                                                 $9, NIL, 0, 0, 0, NIL);
230                                         DO_END;
231                                 }
232                 ;
233
234 Boot_BuildIndsStmt:
235                   XBUILD INDICES                { build_indices(); }
236
237
238 boot_index_params:
239                 boot_index_params COMMA boot_index_param        { $$ = lappend($1, $3); }
240                 | boot_index_param                                                      { $$ = lcons($1, NIL); }
241                 ;
242
243 boot_index_param:
244                 boot_ident boot_ident
245                                 {
246                                         IndexElem *n = makeNode(IndexElem);
247                                         n->name = LexIDStr($1);
248                                         n->class = LexIDStr($2);
249                                         $$ = n;
250                                 }
251
252 optbootstrap:
253                         XBOOTSTRAP      { $$ = 1; }
254                 |                               { $$ = 0; }
255                 ;
256
257 boot_typelist:
258                   boot_type_thing
259                 | boot_typelist COMMA boot_type_thing
260                 ;
261
262 boot_type_thing:
263                   boot_ident EQUALS boot_ident
264                                 {
265                                    if(++numattr > MAXATTR)
266                                                 elog(FATAL,"Too many attributes\n");
267                                    DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
268                                    if (DebugMode)
269                                            printf("\n");
270                                 }
271                 ;
272
273 optoideq:
274                         OBJ_ID EQUALS boot_ident { $$ = atol(LexIDStr($3));                             }
275                 |                                               { extern Oid newoid(); $$ = newoid();   }
276                 ;
277
278 boot_tuplelist:
279                    boot_tuple
280                 |  boot_tuplelist boot_tuple
281                 |  boot_tuplelist COMMA boot_tuple
282                 ;
283
284 boot_tuple:
285                   boot_ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
286                 | boot_const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
287                 | NULLVAL
288                         { InsertOneNull(num_tuples_read++); }
289                 ;
290
291 boot_const :
292                   CONST { $$=yylval.ival; }
293                 ;
294
295 boot_ident :
296                   ID    { $$=yylval.ival; }
297                 ;
298 %%