1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2021, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/pars0pars.h
29 SQL parser
30 
31 Created 11/19/1996 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef pars0pars_h
35 #define pars0pars_h
36 
37 #include "univ.i"
38 #include "que0types.h"
39 #include "usr0types.h"
40 #include "pars0types.h"
41 #include "row0types.h"
42 #include "trx0types.h"
43 #include "ut0vec.h"
44 #include "row0mysql.h"
45 
46 /** Type of the user functions. The first argument is always InnoDB-supplied
47 and varies in type, while 'user_arg' is a user-supplied argument. The
48 meaning of the return type also varies. See the individual use cases, e.g.
49 the FETCH statement, for details on them. */
50 typedef ibool	(*pars_user_func_cb_t)(void* arg, void* user_arg);
51 
52 /** If the following is set TRUE, the parser will emit debugging
53 information */
54 extern int	yydebug;
55 
56 /* Global variable used while parsing a single procedure or query : the code is
57 NOT re-entrant */
58 extern sym_tab_t*	pars_sym_tab_global;
59 
60 extern pars_res_word_t	pars_to_char_token;
61 extern pars_res_word_t	pars_to_number_token;
62 extern pars_res_word_t	pars_to_binary_token;
63 extern pars_res_word_t	pars_binary_to_number_token;
64 extern pars_res_word_t	pars_substr_token;
65 extern pars_res_word_t	pars_replstr_token;
66 extern pars_res_word_t	pars_concat_token;
67 extern pars_res_word_t	pars_length_token;
68 extern pars_res_word_t	pars_instr_token;
69 extern pars_res_word_t	pars_sysdate_token;
70 extern pars_res_word_t	pars_printf_token;
71 extern pars_res_word_t	pars_assert_token;
72 extern pars_res_word_t	pars_rnd_token;
73 extern pars_res_word_t	pars_rnd_str_token;
74 extern pars_res_word_t	pars_count_token;
75 extern pars_res_word_t	pars_sum_token;
76 extern pars_res_word_t	pars_distinct_token;
77 extern pars_res_word_t	pars_binary_token;
78 extern pars_res_word_t	pars_blob_token;
79 extern pars_res_word_t	pars_int_token;
80 extern pars_res_word_t	pars_bigint_token;
81 extern pars_res_word_t	pars_char_token;
82 extern pars_res_word_t	pars_float_token;
83 extern pars_res_word_t	pars_update_token;
84 extern pars_res_word_t	pars_asc_token;
85 extern pars_res_word_t	pars_desc_token;
86 extern pars_res_word_t	pars_open_token;
87 extern pars_res_word_t	pars_close_token;
88 extern pars_res_word_t	pars_share_token;
89 extern pars_res_word_t	pars_unique_token;
90 extern pars_res_word_t	pars_clustered_token;
91 
92 extern ulint		pars_star_denoter;
93 
94 /* Procedure parameter types */
95 #define PARS_INPUT	0
96 #define PARS_OUTPUT	1
97 #define PARS_NOT_PARAM	2
98 
99 int
100 yyparse(void);
101 
102 /*************************************************************//**
103 Parses an SQL string returning the query graph.
104 @return own: the query graph */
105 que_t*
106 pars_sql(
107 /*=====*/
108 	pars_info_t*	info,	/*!< in: extra information, or NULL */
109 	const char*	str);	/*!< in: SQL string */
110 /*************************************************************//**
111 Retrieves characters to the lexical analyzer.
112 @return number of characters copied or 0 on EOF */
113 int
114 pars_get_lex_chars(
115 /*===============*/
116 	char*	buf,		/*!< in/out: buffer where to copy */
117 	int	max_size);	/*!< in: maximum number of characters which fit
118 				in the buffer */
119 /*************************************************************//**
120 Called by yyparse on error. */
121 void
122 yyerror(
123 /*====*/
124 	const char*	s);	/*!< in: error message string */
125 /*********************************************************************//**
126 Parses a variable declaration.
127 @return own: symbol table node of type SYM_VAR */
128 sym_node_t*
129 pars_variable_declaration(
130 /*======================*/
131 	sym_node_t*	node,	/*!< in: symbol table node allocated for the
132 				id of the variable */
133 	pars_res_word_t* type);	/*!< in: pointer to a type token */
134 /*********************************************************************//**
135 Parses a function expression.
136 @return own: function node in a query tree */
137 func_node_t*
138 pars_func(
139 /*======*/
140 	que_node_t*	res_word,/*!< in: function name reserved word */
141 	que_node_t*	arg);	/*!< in: first argument in the argument list */
142 /*************************************************************************
143 Rebind a LIKE search string. NOTE: We ignore any '%' characters embedded
144 within the search string.
145 @return own: function node in a query tree */
146 int
147 pars_like_rebind(
148 /*=============*/
149         sym_node_t*     node,   /* in: The search string node.*/
150         const byte*     ptr,    /* in: literal to (re) bind */
151         ulint           len);   /* in: length of literal to (re) bind*/
152 /*********************************************************************//**
153 Parses an operator expression.
154 @return own: function node in a query tree */
155 func_node_t*
156 pars_op(
157 /*====*/
158 	int		func,	/*!< in: operator token code */
159 	que_node_t*	arg1,	/*!< in: first argument */
160 	que_node_t*	arg2);	/*!< in: second argument or NULL for an unary
161 				operator */
162 /*********************************************************************//**
163 Parses an ORDER BY clause. Order by a single column only is supported.
164 @return own: order-by node in a query tree */
165 order_node_t*
166 pars_order_by(
167 /*==========*/
168 	sym_node_t*	column,	/*!< in: column name */
169 	pars_res_word_t* asc);	/*!< in: &pars_asc_token or pars_desc_token */
170 /*********************************************************************//**
171 Parses a select list; creates a query graph node for the whole SELECT
172 statement.
173 @return own: select node in a query tree */
174 sel_node_t*
175 pars_select_list(
176 /*=============*/
177 	que_node_t*	select_list,	/*!< in: select list */
178 	sym_node_t*	into_list);	/*!< in: variables list or NULL */
179 /*********************************************************************//**
180 Parses a cursor declaration.
181 @return sym_node */
182 que_node_t*
183 pars_cursor_declaration(
184 /*====================*/
185 	sym_node_t*	sym_node,	/*!< in: cursor id node in the symbol
186 					table */
187 	sel_node_t*	select_node);	/*!< in: select node */
188 /*********************************************************************//**
189 Parses a function declaration.
190 @return sym_node */
191 que_node_t*
192 pars_function_declaration(
193 /*======================*/
194 	sym_node_t*	sym_node);	/*!< in: function id node in the symbol
195 					table */
196 /*********************************************************************//**
197 Parses a select statement.
198 @return own: select node in a query tree */
199 sel_node_t*
200 pars_select_statement(
201 /*==================*/
202 	sel_node_t*	select_node,	/*!< in: select node already containing
203 					the select list */
204 	sym_node_t*	table_list,	/*!< in: table list */
205 	que_node_t*	search_cond,	/*!< in: search condition or NULL */
206 	pars_res_word_t* for_update,	/*!< in: NULL or &pars_update_token */
207 	pars_res_word_t* consistent_read,/*!< in: NULL or
208 						&pars_consistent_token */
209 	order_node_t*	order_by);	/*!< in: NULL or an order-by node */
210 /*********************************************************************//**
211 Parses a column assignment in an update.
212 @return column assignment node */
213 col_assign_node_t*
214 pars_column_assignment(
215 /*===================*/
216 	sym_node_t*	column,	/*!< in: column to assign */
217 	que_node_t*	exp);	/*!< in: value to assign */
218 /*********************************************************************//**
219 Parses a delete or update statement start.
220 @return own: update node in a query tree */
221 upd_node_t*
222 pars_update_statement_start(
223 /*========================*/
224 	ibool		is_delete,	/*!< in: TRUE if delete */
225 	sym_node_t*	table_sym,	/*!< in: table name node */
226 	col_assign_node_t* col_assign_list);/*!< in: column assignment list, NULL
227 					if delete */
228 /*********************************************************************//**
229 Parses an update or delete statement.
230 @return own: update node in a query tree */
231 upd_node_t*
232 pars_update_statement(
233 /*==================*/
234 	upd_node_t*	node,		/*!< in: update node */
235 	sym_node_t*	cursor_sym,	/*!< in: pointer to a cursor entry in
236 					the symbol table or NULL */
237 	que_node_t*	search_cond);	/*!< in: search condition or NULL */
238 /*********************************************************************//**
239 Parses an insert statement.
240 @return own: update node in a query tree */
241 ins_node_t*
242 pars_insert_statement(
243 /*==================*/
244 	sym_node_t*	table_sym,	/*!< in: table name node */
245 	que_node_t*	values_list,	/*!< in: value expression list or NULL */
246 	sel_node_t*	select);	/*!< in: select condition or NULL */
247 /*********************************************************************//**
248 Parses a procedure parameter declaration.
249 @return own: symbol table node of type SYM_VAR */
250 sym_node_t*
251 pars_parameter_declaration(
252 /*=======================*/
253 	sym_node_t*	node,	/*!< in: symbol table node allocated for the
254 				id of the parameter */
255 	ulint		param_type,
256 				/*!< in: PARS_INPUT or PARS_OUTPUT */
257 	pars_res_word_t* type);	/*!< in: pointer to a type token */
258 /*********************************************************************//**
259 Parses an elsif element.
260 @return elsif node */
261 elsif_node_t*
262 pars_elsif_element(
263 /*===============*/
264 	que_node_t*	cond,		/*!< in: if-condition */
265 	que_node_t*	stat_list);	/*!< in: statement list */
266 /*********************************************************************//**
267 Parses an if-statement.
268 @return if-statement node */
269 if_node_t*
270 pars_if_statement(
271 /*==============*/
272 	que_node_t*	cond,		/*!< in: if-condition */
273 	que_node_t*	stat_list,	/*!< in: statement list */
274 	que_node_t*	else_part);	/*!< in: else-part statement list */
275 /*********************************************************************//**
276 Parses a for-loop-statement.
277 @return for-statement node */
278 for_node_t*
279 pars_for_statement(
280 /*===============*/
281 	sym_node_t*	loop_var,	/*!< in: loop variable */
282 	que_node_t*	loop_start_limit,/*!< in: loop start expression */
283 	que_node_t*	loop_end_limit,	/*!< in: loop end expression */
284 	que_node_t*	stat_list);	/*!< in: statement list */
285 /*********************************************************************//**
286 Parses a while-statement.
287 @return while-statement node */
288 while_node_t*
289 pars_while_statement(
290 /*=================*/
291 	que_node_t*	cond,		/*!< in: while-condition */
292 	que_node_t*	stat_list);	/*!< in: statement list */
293 /*********************************************************************//**
294 Parses an exit statement.
295 @return exit statement node */
296 exit_node_t*
297 pars_exit_statement(void);
298 /*=====================*/
299 /*********************************************************************//**
300 Parses a return-statement.
301 @return return-statement node */
302 return_node_t*
303 pars_return_statement(void);
304 /*=======================*/
305 /*********************************************************************//**
306 Parses a procedure call.
307 @return function node */
308 func_node_t*
309 pars_procedure_call(
310 /*================*/
311 	que_node_t*	res_word,/*!< in: procedure name reserved word */
312 	que_node_t*	args);	/*!< in: argument list */
313 /*********************************************************************//**
314 Parses an assignment statement.
315 @return assignment statement node */
316 assign_node_t*
317 pars_assignment_statement(
318 /*======================*/
319 	sym_node_t*	var,	/*!< in: variable to assign */
320 	que_node_t*	val);	/*!< in: value to assign */
321 /*********************************************************************//**
322 Parses a fetch statement. into_list or user_func (but not both) must be
323 non-NULL.
324 @return fetch statement node */
325 fetch_node_t*
326 pars_fetch_statement(
327 /*=================*/
328 	sym_node_t*	cursor,		/*!< in: cursor node */
329 	sym_node_t*	into_list,	/*!< in: variables to set, or NULL */
330 	sym_node_t*	user_func);	/*!< in: user function name, or NULL */
331 /*********************************************************************//**
332 Parses an open or close cursor statement.
333 @return fetch statement node */
334 open_node_t*
335 pars_open_statement(
336 /*================*/
337 	ulint		type,	/*!< in: ROW_SEL_OPEN_CURSOR
338 				or ROW_SEL_CLOSE_CURSOR */
339 	sym_node_t*	cursor);	/*!< in: cursor node */
340 /*********************************************************************//**
341 Parses a row_printf-statement.
342 @return row_printf-statement node */
343 row_printf_node_t*
344 pars_row_printf_statement(
345 /*======================*/
346 	sel_node_t*	sel_node);	/*!< in: select node */
347 /*********************************************************************//**
348 Parses a commit statement.
349 @return own: commit node struct */
350 commit_node_t*
351 pars_commit_statement(void);
352 /*=======================*/
353 /*********************************************************************//**
354 Parses a rollback statement.
355 @return own: rollback node struct */
356 roll_node_t*
357 pars_rollback_statement(void);
358 /*=========================*/
359 /*********************************************************************//**
360 Parses a column definition at a table creation.
361 @return column sym table node */
362 sym_node_t*
363 pars_column_def(
364 /*============*/
365 	sym_node_t*		sym_node,	/*!< in: column node in the
366 						symbol table */
367 	pars_res_word_t*	type,		/*!< in: data type */
368 	sym_node_t*		len,		/*!< in: length of column, or
369 						NULL */
370 	void*			is_unsigned,	/*!< in: if not NULL, column
371 						is of type UNSIGNED. */
372 	void*			is_not_null);	/*!< in: if not NULL, column
373 						is of type NOT NULL. */
374 /*********************************************************************//**
375 Parses a table creation operation.
376 @return table create subgraph */
377 tab_node_t*
378 pars_create_table(
379 /*==============*/
380 	sym_node_t*	table_sym,	/*!< in: table name node in the symbol
381 					table */
382 	sym_node_t*	column_defs,	/*!< in: list of column names */
383 	sym_node_t*	compact,	/* in: non-NULL if COMPACT table. */
384 	sym_node_t*	block_size,	/* in: block size (can be NULL) */
385 	void*		not_fit_in_memory);
386 					/*!< in: a non-NULL pointer means that
387 					this is a table which in simulations
388 					should be simulated as not fitting
389 					in memory; thread is put to sleep
390 					to simulate disk accesses; NOTE that
391 					this flag is not stored to the data
392 					dictionary on disk, and the database
393 					will forget about non-NULL value if
394 					it has to reload the table definition
395 					from disk */
396 /*********************************************************************//**
397 Parses an index creation operation.
398 @return index create subgraph */
399 ind_node_t*
400 pars_create_index(
401 /*==============*/
402 	pars_res_word_t* unique_def,	/*!< in: not NULL if a unique index */
403 	pars_res_word_t* clustered_def,	/*!< in: not NULL if a clustered index */
404 	sym_node_t*	index_sym,	/*!< in: index name node in the symbol
405 					table */
406 	sym_node_t*	table_sym,	/*!< in: table name node in the symbol
407 					table */
408 	sym_node_t*	column_list);	/*!< in: list of column names */
409 /*********************************************************************//**
410 Parses a procedure definition.
411 @return query fork node */
412 que_fork_t*
413 pars_procedure_definition(
414 /*======================*/
415 	sym_node_t*	sym_node,	/*!< in: procedure id node in the symbol
416 					table */
417 	sym_node_t*	param_list,	/*!< in: parameter declaration list */
418 	que_node_t*	stat_list);	/*!< in: statement list */
419 
420 /*************************************************************//**
421 Parses a stored procedure call, when this is not within another stored
422 procedure, that is, the client issues a procedure call directly.
423 In MySQL/InnoDB, stored InnoDB procedures are invoked via the
424 parsed procedure tree, not via InnoDB SQL, so this function is not used.
425 @return query graph */
426 que_fork_t*
427 pars_stored_procedure_call(
428 /*=======================*/
429 	sym_node_t*	sym_node);	/*!< in: stored procedure name */
430 /** Completes a query graph by adding query thread and fork nodes
431 above it and prepares the graph for running. The fork created is of
432 type QUE_FORK_MYSQL_INTERFACE.
433 @param[in]	node		root node for an incomplete query
434 				graph, or NULL for dummy graph
435 @param[in]	trx		transaction handle
436 @param[in]	heap		memory heap from which allocated
437 @param[in]	prebuilt	row prebuilt structure
438 @return query thread node to run */
439 que_thr_t*
440 pars_complete_graph_for_exec(
441 	que_node_t*	node,
442 	trx_t*		trx,
443 	mem_heap_t*	heap,
444 	row_prebuilt_t*	prebuilt)
445 	MY_ATTRIBUTE((nonnull(2,3), warn_unused_result));
446 
447 /****************************************************************//**
448 Create parser info struct.
449 @return own: info struct */
450 pars_info_t*
451 pars_info_create(void);
452 /*==================*/
453 
454 /****************************************************************//**
455 Free info struct and everything it contains. */
456 void
457 pars_info_free(
458 /*===========*/
459 	pars_info_t*	info);	/*!< in, own: info struct */
460 
461 /****************************************************************//**
462 Add bound literal. */
463 void
464 pars_info_add_literal(
465 /*==================*/
466 	pars_info_t*	info,		/*!< in: info struct */
467 	const char*	name,		/*!< in: name */
468 	const void*	address,	/*!< in: address */
469 	ulint		length,		/*!< in: length of data */
470 	ulint		type,		/*!< in: type, e.g. DATA_FIXBINARY */
471 	ulint		prtype);	/*!< in: precise type, e.g.
472 					DATA_UNSIGNED */
473 
474 /****************************************************************//**
475 Equivalent to pars_info_add_literal(info, name, str, strlen(str),
476 DATA_VARCHAR, DATA_ENGLISH). */
477 void
478 pars_info_add_str_literal(
479 /*======================*/
480 	pars_info_t*	info,		/*!< in: info struct */
481 	const char*	name,		/*!< in: name */
482 	const char*	str);		/*!< in: string */
483 /********************************************************************
484 If the literal value already exists then it rebinds otherwise it
485 creates a new entry.*/
486 void
487 pars_info_bind_literal(
488 /*===================*/
489 	pars_info_t*	info,		/* in: info struct */
490 	const char*	name,		/* in: name */
491 	const void*	address,	/* in: address */
492 	ulint		length,		/* in: length of data */
493 	ulint		type,		/* in: type, e.g. DATA_FIXBINARY */
494 	ulint		prtype);	/* in: precise type, e.g. */
495 /********************************************************************
496 If the literal value already exists then it rebinds otherwise it
497 creates a new entry.*/
498 void
499 pars_info_bind_varchar_literal(
500 /*===========================*/
501 	pars_info_t*	info,		/*!< in: info struct */
502 	const char*	name,		/*!< in: name */
503 	const byte*	str,		/*!< in: string */
504 	ulint		str_len);	/*!< in: string length */
505 /****************************************************************//**
506 Equivalent to:
507 
508 char buf[4];
509 mach_write_to_4(buf, val);
510 pars_info_add_literal(info, name, buf, 4, DATA_INT, 0);
511 
512 except that the buffer is dynamically allocated from the info struct's
513 heap. */
514 void
515 pars_info_bind_int4_literal(
516 /*=======================*/
517 	pars_info_t*		info,		/*!< in: info struct */
518 	const char*		name,		/*!< in: name */
519 	const ib_uint32_t*	val);		/*!< in: value */
520 /********************************************************************
521 If the literal value already exists then it rebinds otherwise it
522 creates a new entry. */
523 void
524 pars_info_bind_int8_literal(
525 /*=======================*/
526 	pars_info_t*		info,		/*!< in: info struct */
527 	const char*		name,		/*!< in: name */
528 	const ib_uint64_t*	val);		/*!< in: value */
529 /****************************************************************//**
530 Add user function. */
531 void
532 pars_info_bind_function(
533 /*===================*/
534 	pars_info_t*		info,	/*!< in: info struct */
535 	const char*		name,	/*!< in: function name */
536 	pars_user_func_cb_t	func,	/*!< in: function address */
537 	void*			arg);	/*!< in: user-supplied argument */
538 /****************************************************************//**
539 Add bound id. */
540 void
541 pars_info_bind_id(
542 /*=============*/
543 	pars_info_t*		info,	/*!< in: info struct */
544 	ibool			copy_name,/* in: make a copy of name if TRUE */
545 	const char*		name,	/*!< in: name */
546 	const char*		id);	/*!< in: id */
547 /****************************************************************//**
548 Equivalent to:
549 
550 char buf[4];
551 mach_write_to_4(buf, val);
552 pars_info_add_literal(info, name, buf, 4, DATA_INT, 0);
553 
554 except that the buffer is dynamically allocated from the info struct's
555 heap. */
556 void
557 pars_info_add_int4_literal(
558 /*=======================*/
559 	pars_info_t*	info,		/*!< in: info struct */
560 	const char*	name,		/*!< in: name */
561 	lint		val);		/*!< in: value */
562 
563 /****************************************************************//**
564 Equivalent to:
565 
566 char buf[8];
567 mach_write_to_8(buf, val);
568 pars_info_add_literal(info, name, buf, 8, DATA_FIXBINARY, 0);
569 
570 except that the buffer is dynamically allocated from the info struct's
571 heap. */
572 void
573 pars_info_add_ull_literal(
574 /*======================*/
575 	pars_info_t*	info,		/*!< in: info struct */
576 	const char*	name,		/*!< in: name */
577 	ib_uint64_t	val);		/*!< in: value */
578 
579 /****************************************************************//**
580 If the literal value already exists then it rebinds otherwise it
581 creates a new entry. */
582 void
583 pars_info_bind_ull_literal(
584 /*=======================*/
585 	pars_info_t*		info,	/*!< in: info struct */
586 	const char*		name,	/*!< in: name */
587 	const ib_uint64_t*	val)	/*!< in: value */
588 	MY_ATTRIBUTE((nonnull));
589 
590 /****************************************************************//**
591 Add bound id. */
592 void
593 pars_info_add_id(
594 /*=============*/
595 	pars_info_t*	info,		/*!< in: info struct */
596 	const char*	name,		/*!< in: name */
597 	const char*	id);		/*!< in: id */
598 
599 /****************************************************************//**
600 Get bound literal with the given name.
601 @return bound literal, or NULL if not found */
602 pars_bound_lit_t*
603 pars_info_get_bound_lit(
604 /*====================*/
605 	pars_info_t*		info,	/*!< in: info struct */
606 	const char*		name);	/*!< in: bound literal name to find */
607 
608 /****************************************************************//**
609 Get bound id with the given name.
610 @return bound id, or NULL if not found */
611 pars_bound_id_t*
612 pars_info_get_bound_id(
613 /*===================*/
614 	pars_info_t*		info,	/*!< in: info struct */
615 	const char*		name);	/*!< in: bound id name to find */
616 
617 /******************************************************************//**
618 Release any resources used by the lexer. */
619 void
620 pars_lexer_close(void);
621 /*==================*/
622 
623 /** Extra information supplied for pars_sql(). */
624 struct pars_info_t {
625 	mem_heap_t*	heap;		/*!< our own memory heap */
626 
627 	ib_vector_t*	funcs;		/*!< user functions, or NUll
628 					(pars_user_func_t*) */
629 	ib_vector_t*	bound_lits;	/*!< bound literals, or NULL
630 					(pars_bound_lit_t*) */
631 	ib_vector_t*	bound_ids;	/*!< bound ids, or NULL
632 					(pars_bound_id_t*) */
633 
634 	ibool		graph_owns_us;	/*!< if TRUE (which is the default),
635 					que_graph_free() will free us */
636 };
637 
638 /** User-supplied function and argument. */
639 struct pars_user_func_t {
640 	const char*		name;	/*!< function name */
641 	pars_user_func_cb_t	func;	/*!< function address */
642 	void*			arg;	/*!< user-supplied argument */
643 };
644 
645 /** Bound literal. */
646 struct pars_bound_lit_t {
647 	const char*	name;		/*!< name */
648 	const void*	address;	/*!< address */
649 	ulint		length;		/*!< length of data */
650 	ulint		type;		/*!< type, e.g. DATA_FIXBINARY */
651 	ulint		prtype;		/*!< precise type, e.g. DATA_UNSIGNED */
652 	sym_node_t*	node;		/*!< symbol node */
653 };
654 
655 /** Bound identifier. */
656 struct pars_bound_id_t {
657 	const char*	name;		/*!< name */
658 	const char*	id;		/*!< identifier */
659 };
660 
661 /** Struct used to denote a reserved word in a parsing tree */
662 struct pars_res_word_t{
663 	int	code;	/*!< the token code for the reserved word from
664 			pars0grm.h */
665 };
666 
667 /** A predefined function or operator node in a parsing tree; this construct
668 is also used for some non-functions like the assignment ':=' */
669 struct func_node_t{
670 	que_common_t	common;	/*!< type: QUE_NODE_FUNC */
671 	int		func;	/*!< token code of the function name */
672 	ulint		fclass;	/*!< class of the function */
673 	que_node_t*	args;	/*!< argument(s) of the function */
674 	UT_LIST_NODE_T(func_node_t) cond_list;
675 				/*!< list of comparison conditions; defined
676 				only for comparison operator nodes except,
677 				presently, for OPT_SCROLL_TYPE ones */
678 	UT_LIST_NODE_T(func_node_t) func_node_list;
679 				/*!< list of function nodes in a parsed
680 				query graph */
681 };
682 
683 /** An order-by node in a select */
684 struct order_node_t{
685 	que_common_t	common;	/*!< type: QUE_NODE_ORDER */
686 	sym_node_t*	column;	/*!< order-by column */
687 	ibool		asc;	/*!< TRUE if ascending, FALSE if descending */
688 };
689 
690 /** Procedure definition node */
691 struct proc_node_t{
692 	que_common_t	common;		/*!< type: QUE_NODE_PROC */
693 	sym_node_t*	proc_id;	/*!< procedure name symbol in the symbol
694 					table of this same procedure */
695 	sym_node_t*	param_list;	/*!< input and output parameters */
696 	que_node_t*	stat_list;	/*!< statement list */
697 	sym_tab_t*	sym_tab;	/*!< symbol table of this procedure */
698 };
699 
700 /** elsif-element node */
701 struct elsif_node_t{
702 	que_common_t	common;		/*!< type: QUE_NODE_ELSIF */
703 	que_node_t*	cond;		/*!< if condition */
704 	que_node_t*	stat_list;	/*!< statement list */
705 };
706 
707 /** if-statement node */
708 struct if_node_t{
709 	que_common_t	common;		/*!< type: QUE_NODE_IF */
710 	que_node_t*	cond;		/*!< if condition */
711 	que_node_t*	stat_list;	/*!< statement list */
712 	que_node_t*	else_part;	/*!< else-part statement list */
713 	elsif_node_t*	elsif_list;	/*!< elsif element list */
714 };
715 
716 /** while-statement node */
717 struct while_node_t{
718 	que_common_t	common;		/*!< type: QUE_NODE_WHILE */
719 	que_node_t*	cond;		/*!< while condition */
720 	que_node_t*	stat_list;	/*!< statement list */
721 };
722 
723 /** for-loop-statement node */
724 struct for_node_t{
725 	que_common_t	common;		/*!< type: QUE_NODE_FOR */
726 	sym_node_t*	loop_var;	/*!< loop variable: this is the
727 					dereferenced symbol from the
728 					variable declarations, not the
729 					symbol occurrence in the for loop
730 					definition */
731 	que_node_t*	loop_start_limit;/*!< initial value of loop variable */
732 	que_node_t*	loop_end_limit;	/*!< end value of loop variable */
733 	lint		loop_end_value;	/*!< evaluated value for the end value:
734 					it is calculated only when the loop
735 					is entered, and will not change within
736 					the loop */
737 	que_node_t*	stat_list;	/*!< statement list */
738 };
739 
740 /** exit statement node */
741 struct exit_node_t{
742 	que_common_t	common;		/*!< type: QUE_NODE_EXIT */
743 };
744 
745 /** return-statement node */
746 struct return_node_t{
747 	que_common_t	common;		/*!< type: QUE_NODE_RETURN */
748 };
749 
750 /** Assignment statement node */
751 struct assign_node_t{
752 	que_common_t	common;		/*!< type: QUE_NODE_ASSIGNMENT */
753 	sym_node_t*	var;		/*!< variable to set */
754 	que_node_t*	val;		/*!< value to assign */
755 };
756 
757 /** Column assignment node */
758 struct col_assign_node_t{
759 	que_common_t	common;		/*!< type: QUE_NODE_COL_ASSIGN */
760 	sym_node_t*	col;		/*!< column to set */
761 	que_node_t*	val;		/*!< value to assign */
762 };
763 
764 /** Classes of functions */
765 /* @{ */
766 #define PARS_FUNC_ARITH		1	/*!< +, -, *, / */
767 #define	PARS_FUNC_LOGICAL	2	/*!< AND, OR, NOT */
768 #define PARS_FUNC_CMP		3	/*!< comparison operators */
769 #define	PARS_FUNC_PREDEFINED	4	/*!< TO_NUMBER, SUBSTR, ... */
770 #define	PARS_FUNC_AGGREGATE	5	/*!< COUNT, DISTINCT, SUM */
771 #define	PARS_FUNC_OTHER		6	/*!< these are not real functions,
772 					e.g., := */
773 /* @} */
774 
775 #ifndef UNIV_NONINL
776 #include "pars0pars.ic"
777 #endif
778 
779 #endif
780