1
/*****************************************************************************
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file pars/pars0pars.c
1
/******************************************************
23
6
Created 11/19/1996 Heikki Tuuri
24
7
*******************************************************/
52
35
#include "eval0eval.h"
54
37
#ifdef UNIV_SQL_DEBUG
55
/** If the following is set TRUE, the lexer will print the SQL string
38
/* If the following is set TRUE, the lexer will print the SQL string
56
39
as it tokenizes it */
57
UNIV_INTERN ibool pars_print_lexed = FALSE;
41
ibool pars_print_lexed = FALSE;
58
42
#endif /* UNIV_SQL_DEBUG */
60
44
/* Global variable used while parsing a single procedure or query : the code is
95
79
UNIV_INTERN pars_res_word_t pars_unique_token = {PARS_UNIQUE_TOKEN};
96
80
UNIV_INTERN pars_res_word_t pars_clustered_token = {PARS_CLUSTERED_TOKEN};
98
/** Global variable used to denote the '*' in SELECT * FROM.. */
99
UNIV_INTERN ulint pars_star_denoter = 12345678;
102
/*********************************************************************//**
103
Determines the class of a function code.
104
@return function class: PARS_FUNC_ARITH, ... */
82
/* Global variable used to denote the '*' in SELECT * FROM.. */
83
#define PARS_STAR_DENOTER 12345678
84
UNIV_INTERN ulint pars_star_denoter = PARS_STAR_DENOTER;
87
/*************************************************************************
88
Determines the class of a function code. */
107
91
pars_func_get_class(
108
92
/*================*/
109
int func) /*!< in: function code: '=', PARS_GE_TOKEN, ... */
93
/* out: function class: PARS_FUNC_ARITH, ... */
94
int func) /* in: function code: '=', PARS_GE_TOKEN, ... */
112
97
case '+': case '-': case '*': case '/':
147
/*********************************************************************//**
148
Parses an operator or predefined function expression.
149
@return own: function node in a query tree */
132
/*************************************************************************
133
Parses an operator or predefined function expression. */
154
int func, /*!< in: function token code */
155
que_node_t* arg) /*!< in: first argument in the argument list */
138
/* out, own: function node in a query tree */
139
int func, /* in: function token code */
140
que_node_t* arg) /* in: first argument in the argument list */
157
142
func_node_t* node;
176
/*********************************************************************//**
177
Parses a function expression.
178
@return own: function node in a query tree */
161
/*************************************************************************
162
Parses a function expression. */
183
que_node_t* res_word,/*!< in: function name reserved word */
184
que_node_t* arg) /*!< in: first argument in the argument list */
167
/* out, own: function node in a query tree */
168
que_node_t* res_word,/* in: function name reserved word */
169
que_node_t* arg) /* in: first argument in the argument list */
186
171
return(pars_func_low(((pars_res_word_t*)res_word)->code, arg));
189
/*********************************************************************//**
190
Parses an operator expression.
191
@return own: function node in a query tree */
174
/*************************************************************************
175
Parses an operator expression. */
196
int func, /*!< in: operator token code */
197
que_node_t* arg1, /*!< in: first argument */
198
que_node_t* arg2) /*!< in: second argument or NULL for an unary
180
/* out, own: function node in a query tree */
181
int func, /* in: operator token code */
182
que_node_t* arg1, /* in: first argument */
183
que_node_t* arg2) /* in: second argument or NULL for an unary
201
186
que_node_list_add_last(NULL, arg1);
207
192
return(pars_func_low(func, arg1));
210
/*********************************************************************//**
211
Parses an ORDER BY clause. Order by a single column only is supported.
212
@return own: order-by node in a query tree */
195
/*************************************************************************
196
Parses an ORDER BY clause. Order by a single column only is supported. */
217
sym_node_t* column, /*!< in: column name */
218
pars_res_word_t* asc) /*!< in: &pars_asc_token or pars_desc_token */
201
/* out, own: order-by node in a query tree */
202
sym_node_t* column, /* in: column name */
203
pars_res_word_t* asc) /* in: &pars_asc_token or pars_desc_token */
220
205
order_node_t* node;
238
/*********************************************************************//**
223
/*************************************************************************
239
224
Determine if a data type is a built-in string data type of the InnoDB
241
@return TRUE if string data type */
244
228
pars_is_string_type(
245
229
/*================*/
246
ulint mtype) /*!< in: main data type */
230
/* out: TRUE if string data type */
231
ulint mtype) /* in: main data type */
249
234
case DATA_VARCHAR: case DATA_CHAR:
257
/*********************************************************************//**
242
/*************************************************************************
258
243
Resolves the data type of a function in an expression. The argument data
259
244
types must already be resolved. */
262
247
pars_resolve_func_data_type(
263
248
/*========================*/
264
func_node_t* node) /*!< in: function node */
249
func_node_t* node) /* in: function node */
350
/*********************************************************************//**
335
/*************************************************************************
351
336
Resolves the meaning of variables in an expression and the data types of
352
337
functions. It is an error if some identifier cannot be resolved here. */
355
340
pars_resolve_exp_variables_and_types(
356
341
/*=================================*/
357
sel_node_t* select_node, /*!< in: select node or NULL; if
342
sel_node_t* select_node, /* in: select node or NULL; if
358
343
this is not NULL then the variable
359
344
sym nodes are added to the
360
345
copy_variables list of select_node */
361
que_node_t* exp_node) /*!< in: expression */
346
que_node_t* exp_node) /* in: expression */
363
348
func_node_t* func_node;
437
422
que_node_get_data_type(node));
440
/*********************************************************************//**
425
/*************************************************************************
441
426
Resolves the meaning of variables in an expression list. It is an error if
442
427
some identifier cannot be resolved here. Resolves also the data types of
446
431
pars_resolve_exp_list_variables_and_types(
447
432
/*======================================*/
448
sel_node_t* select_node, /*!< in: select node or NULL */
449
que_node_t* exp_node) /*!< in: expression list first node, or
433
sel_node_t* select_node, /* in: select node or NULL */
434
que_node_t* exp_node) /* in: expression list first node, or
452
437
while (exp_node) {
459
/*********************************************************************//**
444
/*************************************************************************
460
445
Resolves the columns in an expression. */
463
448
pars_resolve_exp_columns(
464
449
/*=====================*/
465
sym_node_t* table_node, /*!< in: first node in a table list */
466
que_node_t* exp_node) /*!< in: expression */
450
sym_node_t* table_node, /* in: first node in a table list */
451
que_node_t* exp_node) /* in: expression */
468
453
func_node_t* func_node;
540
/*********************************************************************//**
525
/*************************************************************************
541
526
Resolves the meaning of columns in an expression list. */
544
529
pars_resolve_exp_list_columns(
545
530
/*==========================*/
546
sym_node_t* table_node, /*!< in: first node in a table list */
547
que_node_t* exp_node) /*!< in: expression list first node, or
531
sym_node_t* table_node, /* in: first node in a table list */
532
que_node_t* exp_node) /* in: expression list first node, or
550
535
while (exp_node) {
557
/*********************************************************************//**
542
/*************************************************************************
558
543
Retrieves the table definition for a table name id. */
561
546
pars_retrieve_table_def(
562
547
/*====================*/
563
sym_node_t* sym_node) /*!< in: table node */
548
sym_node_t* sym_node) /* in: table node */
565
550
const char* table_name;
577
562
ut_a(sym_node->table);
580
/*********************************************************************//**
581
Retrieves the table definitions for a list of table name ids.
582
@return number of tables */
565
/*************************************************************************
566
Retrieves the table definitions for a list of table name ids. */
585
569
pars_retrieve_table_list_defs(
586
570
/*==========================*/
587
sym_node_t* sym_node) /*!< in: first table node in list */
571
/* out: number of tables */
572
sym_node_t* sym_node) /* in: first table node in list */
607
/*********************************************************************//**
592
/*************************************************************************
608
593
Adds all columns to the select list if the query is SELECT * FROM ... */
611
596
pars_select_all_columns(
612
597
/*====================*/
613
sel_node_t* select_node) /*!< in: select node already containing
598
sel_node_t* select_node) /* in: select node already containing
614
599
the table list */
616
601
sym_node_t* col_node;
644
/*********************************************************************//**
629
/*************************************************************************
645
630
Parses a select list; creates a query graph node for the whole SELECT
647
@return own: select node in a query tree */
650
634
pars_select_list(
651
635
/*=============*/
652
que_node_t* select_list, /*!< in: select list */
653
sym_node_t* into_list) /*!< in: variables list or NULL */
636
/* out, own: select node in a query
638
que_node_t* select_list, /* in: select list */
639
sym_node_t* into_list) /* in: variables list or NULL */
655
641
sel_node_t* node;
667
/*********************************************************************//**
653
/*************************************************************************
668
654
Checks if the query is an aggregate query, in which case the selct list must
669
655
contain only aggregate function items. */
672
658
pars_check_aggregate(
673
659
/*=================*/
674
sel_node_t* select_node) /*!< in: select node already containing
660
sel_node_t* select_node) /* in: select node already containing
675
661
the select list */
677
663
que_node_t* exp_node;
710
/*********************************************************************//**
711
Parses a select statement.
712
@return own: select node in a query tree */
696
/*************************************************************************
697
Parses a select statement. */
715
700
pars_select_statement(
716
701
/*==================*/
717
sel_node_t* select_node, /*!< in: select node already containing
702
/* out, own: select node in a query
704
sel_node_t* select_node, /* in: select node already containing
718
705
the select list */
719
sym_node_t* table_list, /*!< in: table list */
720
que_node_t* search_cond, /*!< in: search condition or NULL */
721
pars_res_word_t* for_update, /*!< in: NULL or &pars_update_token */
722
pars_res_word_t* lock_shared, /*!< in: NULL or &pars_share_token */
723
order_node_t* order_by) /*!< in: NULL or an order-by node */
706
sym_node_t* table_list, /* in: table list */
707
que_node_t* search_cond, /* in: search condition or NULL */
708
pars_res_word_t* for_update, /* in: NULL or &pars_update_token */
709
pars_res_word_t* lock_shared, /* in: NULL or &pars_share_token */
710
order_node_t* order_by) /* in: NULL or an order-by node */
725
712
select_node->state = SEL_NODE_OPEN;
790
777
return(select_node);
793
/*********************************************************************//**
794
Parses a cursor declaration.
780
/*************************************************************************
781
Parses a cursor declaration. */
798
784
pars_cursor_declaration(
799
785
/*====================*/
800
sym_node_t* sym_node, /*!< in: cursor id node in the symbol
787
sym_node_t* sym_node, /* in: cursor id node in the symbol
802
sel_node_t* select_node) /*!< in: select node */
789
sel_node_t* select_node) /* in: select node */
804
791
sym_node->resolved = TRUE;
805
792
sym_node->token_type = SYM_CURSOR;
811
798
return(sym_node);
814
/*********************************************************************//**
815
Parses a function declaration.
801
/*************************************************************************
802
Parses a function declaration. */
819
805
pars_function_declaration(
820
806
/*======================*/
821
sym_node_t* sym_node) /*!< in: function id node in the symbol
808
sym_node_t* sym_node) /* in: function id node in the symbol
824
811
sym_node->resolved = TRUE;
831
818
return(sym_node);
834
/*********************************************************************//**
835
Parses a delete or update statement start.
836
@return own: update node in a query tree */
821
/*************************************************************************
822
Parses a delete or update statement start. */
839
825
pars_update_statement_start(
840
826
/*========================*/
841
ibool is_delete, /*!< in: TRUE if delete */
842
sym_node_t* table_sym, /*!< in: table name node */
843
col_assign_node_t* col_assign_list)/*!< in: column assignment list, NULL
827
/* out, own: update node in a query
829
ibool is_delete, /* in: TRUE if delete */
830
sym_node_t* table_sym, /* in: table name node */
831
col_assign_node_t* col_assign_list)/* in: column assignment list, NULL
846
834
upd_node_t* node;
858
/*********************************************************************//**
859
Parses a column assignment in an update.
860
@return column assignment node */
846
/*************************************************************************
847
Parses a column assignment in an update. */
862
849
col_assign_node_t*
863
850
pars_column_assignment(
864
851
/*===================*/
865
sym_node_t* column, /*!< in: column to assign */
866
que_node_t* exp) /*!< in: value to assign */
852
/* out: column assignment node */
853
sym_node_t* column, /* in: column to assign */
854
que_node_t* exp) /* in: value to assign */
868
856
col_assign_node_t* node;
880
/*********************************************************************//**
868
/*************************************************************************
881
869
Processes an update node assignment list. */
884
872
pars_process_assign_list(
885
873
/*=====================*/
886
upd_node_t* node) /*!< in: update node */
874
upd_node_t* node) /* in: update node */
888
876
col_assign_node_t* col_assign_list;
889
877
sym_node_t* table_sym;
964
951
node->cmpl_info = changes_ord_field | changes_field_size;
967
/*********************************************************************//**
968
Parses an update or delete statement.
969
@return own: update node in a query tree */
954
/*************************************************************************
955
Parses an update or delete statement. */
972
958
pars_update_statement(
973
959
/*==================*/
974
upd_node_t* node, /*!< in: update node */
975
sym_node_t* cursor_sym, /*!< in: pointer to a cursor entry in
960
/* out, own: update node in a query
962
upd_node_t* node, /* in: update node */
963
sym_node_t* cursor_sym, /* in: pointer to a cursor entry in
976
964
the symbol table or NULL */
977
que_node_t* search_cond) /*!< in: search condition or NULL */
965
que_node_t* search_cond) /* in: search condition or NULL */
979
967
sym_node_t* table_sym;
980
968
sel_node_t* sel_node;
1047
1035
node->pcur = &(plan->pcur);
1038
if (!node->is_delete && node->searched_update
1039
&& (node->cmpl_info & UPD_NODE_NO_SIZE_CHANGE)
1040
&& (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
1042
/* The select node can perform the update in-place */
1046
node->select_will_do_update = TRUE;
1047
sel_node->select_will_do_update = TRUE;
1048
sel_node->latch_mode = BTR_MODIFY_LEAF;
1053
/*********************************************************************//**
1054
Parses an insert statement.
1055
@return own: update node in a query tree */
1054
/*************************************************************************
1055
Parses an insert statement. */
1058
1058
pars_insert_statement(
1059
1059
/*==================*/
1060
sym_node_t* table_sym, /*!< in: table name node */
1061
que_node_t* values_list, /*!< in: value expression list or NULL */
1062
sel_node_t* select) /*!< in: select condition or NULL */
1060
/* out, own: update node in a query
1062
sym_node_t* table_sym, /* in: table name node */
1063
que_node_t* values_list, /* in: value expression list or NULL */
1064
sel_node_t* select) /* in: select condition or NULL */
1064
1066
ins_node_t* node;
1110
/*********************************************************************//**
1112
/*************************************************************************
1111
1113
Set the type of a dfield. */
1114
1116
pars_set_dfield_type(
1115
1117
/*=================*/
1116
dfield_t* dfield, /*!< in: dfield */
1117
pars_res_word_t* type, /*!< in: pointer to a type
1118
dfield_t* dfield, /* in: dfield */
1119
pars_res_word_t* type, /* in: pointer to a type
1119
ulint len, /*!< in: length, or 0 */
1120
ibool is_unsigned, /*!< in: if TRUE, column is
1121
ulint len, /* in: length, or 0 */
1122
ibool is_unsigned, /* in: if TRUE, column is
1122
ibool is_not_null) /*!< in: if TRUE, column is
1124
ibool is_not_null) /* in: if TRUE, column is
1125
1127
ulint flags = 0;
1160
/*********************************************************************//**
1161
Parses a variable declaration.
1162
@return own: symbol table node of type SYM_VAR */
1162
/*************************************************************************
1163
Parses a variable declaration. */
1165
1166
pars_variable_declaration(
1166
1167
/*======================*/
1167
sym_node_t* node, /*!< in: symbol table node allocated for the
1168
/* out, own: symbol table node of type
1170
sym_node_t* node, /* in: symbol table node allocated for the
1168
1171
id of the variable */
1169
pars_res_word_t* type) /*!< in: pointer to a type token */
1172
pars_res_word_t* type) /* in: pointer to a type token */
1171
1174
node->resolved = TRUE;
1172
1175
node->token_type = SYM_VAR;
1181
/*********************************************************************//**
1182
Parses a procedure parameter declaration.
1183
@return own: symbol table node of type SYM_VAR */
1184
/*************************************************************************
1185
Parses a procedure parameter declaration. */
1186
1188
pars_parameter_declaration(
1187
1189
/*=======================*/
1188
sym_node_t* node, /*!< in: symbol table node allocated for the
1190
/* out, own: symbol table node of type
1192
sym_node_t* node, /* in: symbol table node allocated for the
1189
1193
id of the parameter */
1190
1194
ulint param_type,
1191
/*!< in: PARS_INPUT or PARS_OUTPUT */
1192
pars_res_word_t* type) /*!< in: pointer to a type token */
1195
/* in: PARS_INPUT or PARS_OUTPUT */
1196
pars_res_word_t* type) /* in: pointer to a type token */
1194
1198
ut_a((param_type == PARS_INPUT) || (param_type == PARS_OUTPUT));
1203
/*********************************************************************//**
1207
/*************************************************************************
1204
1208
Sets the parent field in a query node list. */
1207
1211
pars_set_parent_in_list(
1208
1212
/*====================*/
1209
que_node_t* node_list, /*!< in: first node in a list */
1210
que_node_t* parent) /*!< in: parent value to set in all
1213
que_node_t* node_list, /* in: first node in a list */
1214
que_node_t* parent) /* in: parent value to set in all
1211
1215
nodes of the list */
1213
1217
que_common_t* common;
1224
/*********************************************************************//**
1225
Parses an elsif element.
1226
@return elsif node */
1228
/*************************************************************************
1229
Parses an elsif element. */
1229
1232
pars_elsif_element(
1230
1233
/*===============*/
1231
que_node_t* cond, /*!< in: if-condition */
1232
que_node_t* stat_list) /*!< in: statement list */
1234
/* out: elsif node */
1235
que_node_t* cond, /* in: if-condition */
1236
que_node_t* stat_list) /* in: statement list */
1234
1238
elsif_node_t* node;
1249
/*********************************************************************//**
1250
Parses an if-statement.
1251
@return if-statement node */
1253
/*************************************************************************
1254
Parses an if-statement. */
1254
1257
pars_if_statement(
1255
1258
/*==============*/
1256
que_node_t* cond, /*!< in: if-condition */
1257
que_node_t* stat_list, /*!< in: statement list */
1258
que_node_t* else_part) /*!< in: else-part statement list
1259
/* out: if-statement node */
1260
que_node_t* cond, /* in: if-condition */
1261
que_node_t* stat_list, /* in: statement list */
1262
que_node_t* else_part) /* in: else-part statement list
1259
1263
or elsif element list */
1261
1265
if_node_t* node;
1300
/*********************************************************************//**
1301
Parses a while-statement.
1302
@return while-statement node */
1304
/*************************************************************************
1305
Parses a while-statement. */
1305
1308
pars_while_statement(
1306
1309
/*=================*/
1307
que_node_t* cond, /*!< in: while-condition */
1308
que_node_t* stat_list) /*!< in: statement list */
1310
/* out: while-statement node */
1311
que_node_t* cond, /* in: while-condition */
1312
que_node_t* stat_list) /* in: statement list */
1310
1314
while_node_t* node;
1327
/*********************************************************************//**
1328
Parses a for-loop-statement.
1329
@return for-statement node */
1331
/*************************************************************************
1332
Parses a for-loop-statement. */
1332
1335
pars_for_statement(
1333
1336
/*===============*/
1334
sym_node_t* loop_var, /*!< in: loop variable */
1335
que_node_t* loop_start_limit,/*!< in: loop start expression */
1336
que_node_t* loop_end_limit, /*!< in: loop end expression */
1337
que_node_t* stat_list) /*!< in: statement list */
1337
/* out: for-statement node */
1338
sym_node_t* loop_var, /* in: loop variable */
1339
que_node_t* loop_start_limit,/* in: loop start expression */
1340
que_node_t* loop_end_limit, /* in: loop end expression */
1341
que_node_t* stat_list) /* in: statement list */
1339
1343
for_node_t* node;
1363
/*********************************************************************//**
1364
Parses an exit statement.
1365
@return exit statement node */
1367
/*************************************************************************
1368
Parses an exit statement. */
1368
1371
pars_exit_statement(void)
1369
1372
/*=====================*/
1373
/* out: exit statement node */
1371
1375
exit_node_t* node;
1379
/*********************************************************************//**
1380
Parses a return-statement.
1381
@return return-statement node */
1383
/*************************************************************************
1384
Parses a return-statement. */
1384
1387
pars_return_statement(void)
1385
1388
/*=======================*/
1389
/* out: return-statement node */
1387
1391
return_node_t* node;
1396
/*********************************************************************//**
1397
Parses an assignment statement.
1398
@return assignment statement node */
1400
/*************************************************************************
1401
Parses an assignment statement. */
1401
1404
pars_assignment_statement(
1402
1405
/*======================*/
1403
sym_node_t* var, /*!< in: variable to assign */
1404
que_node_t* val) /*!< in: value to assign */
1406
/* out: assignment statement node */
1407
sym_node_t* var, /* in: variable to assign */
1408
que_node_t* val) /* in: value to assign */
1406
1410
assign_node_t* node;
1424
/*********************************************************************//**
1425
Parses a procedure call.
1426
@return function node */
1428
/*************************************************************************
1429
Parses a procedure call. */
1429
1432
pars_procedure_call(
1430
1433
/*================*/
1431
que_node_t* res_word,/*!< in: procedure name reserved word */
1432
que_node_t* args) /*!< in: argument list */
1434
/* out: function node */
1435
que_node_t* res_word,/* in: procedure name reserved word */
1436
que_node_t* args) /* in: argument list */
1434
1438
func_node_t* node;
1443
/*********************************************************************//**
1447
/*************************************************************************
1444
1448
Parses a fetch statement. into_list or user_func (but not both) must be
1446
@return fetch statement node */
1449
1452
pars_fetch_statement(
1450
1453
/*=================*/
1451
sym_node_t* cursor, /*!< in: cursor node */
1452
sym_node_t* into_list, /*!< in: variables to set, or NULL */
1453
sym_node_t* user_func) /*!< in: user function name, or NULL */
1454
/* out: fetch statement node */
1455
sym_node_t* cursor, /* in: cursor node */
1456
sym_node_t* into_list, /* in: variables to set, or NULL */
1457
sym_node_t* user_func) /* in: user function name, or NULL */
1455
1459
sym_node_t* cursor_decl;
1456
1460
fetch_node_t* node;
1495
/*********************************************************************//**
1496
Parses an open or close cursor statement.
1497
@return fetch statement node */
1499
/*************************************************************************
1500
Parses an open or close cursor statement. */
1500
1503
pars_open_statement(
1501
1504
/*================*/
1502
ulint type, /*!< in: ROW_SEL_OPEN_CURSOR
1505
/* out: fetch statement node */
1506
ulint type, /* in: ROW_SEL_OPEN_CURSOR
1503
1507
or ROW_SEL_CLOSE_CURSOR */
1504
sym_node_t* cursor) /*!< in: cursor node */
1508
sym_node_t* cursor) /* in: cursor node */
1506
1510
sym_node_t* cursor_decl;
1507
1511
open_node_t* node;
1525
/*********************************************************************//**
1526
Parses a row_printf-statement.
1527
@return row_printf-statement node */
1529
/*************************************************************************
1530
Parses a row_printf-statement. */
1529
1532
row_printf_node_t*
1530
1533
pars_row_printf_statement(
1531
1534
/*======================*/
1532
sel_node_t* sel_node) /*!< in: select node */
1535
/* out: row_printf-statement node */
1536
sel_node_t* sel_node) /* in: select node */
1534
1538
row_printf_node_t* node;
1547
/*********************************************************************//**
1548
Parses a commit statement.
1549
@return own: commit node struct */
1551
/*************************************************************************
1552
Parses a commit statement. */
1552
1555
pars_commit_statement(void)
1555
1558
return(commit_node_create(pars_sym_tab_global->heap));
1558
/*********************************************************************//**
1559
Parses a rollback statement.
1560
@return own: rollback node struct */
1561
/*************************************************************************
1562
Parses a rollback statement. */
1563
1565
pars_rollback_statement(void)
1566
1568
return(roll_node_create(pars_sym_tab_global->heap));
1569
/*********************************************************************//**
1570
Parses a column definition at a table creation.
1571
@return column sym table node */
1571
/*************************************************************************
1572
Parses a column definition at a table creation. */
1574
1575
pars_column_def(
1575
1576
/*============*/
1576
sym_node_t* sym_node, /*!< in: column node in the
1577
/* out: column sym table
1579
sym_node_t* sym_node, /* in: column node in the
1577
1580
symbol table */
1578
pars_res_word_t* type, /*!< in: data type */
1579
sym_node_t* len, /*!< in: length of column, or
1581
pars_res_word_t* type, /* in: data type */
1582
sym_node_t* len, /* in: length of column, or
1581
void* is_unsigned, /*!< in: if not NULL, column
1584
void* is_unsigned, /* in: if not NULL, column
1582
1585
is of type UNSIGNED. */
1583
void* is_not_null) /*!< in: if not NULL, column
1586
void* is_not_null) /* in: if not NULL, column
1584
1587
is of type NOT NULL. */
1597
1600
return(sym_node);
1600
/*********************************************************************//**
1601
Parses a table creation operation.
1602
@return table create subgraph */
1603
/*************************************************************************
1604
Parses a table creation operation. */
1605
1607
pars_create_table(
1606
1608
/*==============*/
1607
sym_node_t* table_sym, /*!< in: table name node in the symbol
1609
/* out: table create subgraph */
1610
sym_node_t* table_sym, /* in: table name node in the symbol
1609
sym_node_t* column_defs, /*!< in: list of column names */
1612
sym_node_t* column_defs, /* in: list of column names */
1610
1613
void* not_fit_in_memory __attribute__((unused)))
1611
/*!< in: a non-NULL pointer means that
1614
/* in: a non-NULL pointer means that
1612
1615
this is a table which in simulations
1613
1616
should be simulated as not fitting
1614
1617
in memory; thread is put to sleep
1662
/*********************************************************************//**
1663
Parses an index creation operation.
1664
@return index create subgraph */
1665
/*************************************************************************
1666
Parses an index creation operation. */
1667
1669
pars_create_index(
1668
1670
/*==============*/
1669
pars_res_word_t* unique_def, /*!< in: not NULL if a unique index */
1670
pars_res_word_t* clustered_def, /*!< in: not NULL if a clustered index */
1671
sym_node_t* index_sym, /*!< in: index name node in the symbol
1673
sym_node_t* table_sym, /*!< in: table name node in the symbol
1675
sym_node_t* column_list) /*!< in: list of column names */
1671
/* out: index create subgraph */
1672
pars_res_word_t* unique_def, /* in: not NULL if a unique index */
1673
pars_res_word_t* clustered_def, /* in: not NULL if a clustered index */
1674
sym_node_t* index_sym, /* in: index name node in the symbol
1676
sym_node_t* table_sym, /* in: table name node in the symbol
1678
sym_node_t* column_list) /* in: list of column names */
1677
1680
dict_index_t* index;
1678
1681
sym_node_t* column;
1719
/*********************************************************************//**
1720
Parses a procedure definition.
1721
@return query fork node */
1722
/*************************************************************************
1723
Parses a procedure definition. */
1724
1726
pars_procedure_definition(
1725
1727
/*======================*/
1726
sym_node_t* sym_node, /*!< in: procedure id node in the symbol
1728
/* out: query fork node */
1729
sym_node_t* sym_node, /* in: procedure id node in the symbol
1728
sym_node_t* param_list, /*!< in: parameter declaration list */
1729
que_node_t* stat_list) /*!< in: statement list */
1731
sym_node_t* param_list, /* in: parameter declaration list */
1732
que_node_t* stat_list) /* in: statement list */
1731
1734
proc_node_t* node;
1732
1735
que_fork_t* fork;
1766
/*************************************************************//**
1769
/*****************************************************************
1767
1770
Parses a stored procedure call, when this is not within another stored
1768
1771
procedure, that is, the client issues a procedure call directly.
1769
1772
In MySQL/InnoDB, stored InnoDB procedures are invoked via the
1770
parsed procedure tree, not via InnoDB SQL, so this function is not used.
1771
@return query graph */
1773
parsed procedure tree, not via InnoDB SQL, so this function is not used. */
1774
1776
pars_stored_procedure_call(
1775
1777
/*=======================*/
1778
/* out: query graph */
1776
1779
sym_node_t* sym_node __attribute__((unused)))
1777
/*!< in: stored procedure name */
1780
/* in: stored procedure name */
1783
/*************************************************************//**
1786
/*****************************************************************
1784
1787
Retrieves characters to the lexical analyzer. */
1787
1790
pars_get_lex_chars(
1788
1791
/*===============*/
1789
char* buf, /*!< in/out: buffer where to copy */
1790
int* result, /*!< out: number of characters copied or EOF */
1791
int max_size) /*!< in: maximum number of characters which fit
1792
char* buf, /* in/out: buffer where to copy */
1793
int* result, /* out: number of characters copied or EOF */
1794
int max_size) /* in: maximum number of characters which fit
1792
1795
in the buffer */
1828
1831
pars_sym_tab_global->next_char_pos += len;
1831
/*************************************************************//**
1834
/*****************************************************************
1832
1835
Called by yyparse on error. */
1837
1840
const char* s __attribute__((unused)))
1838
/*!< in: error message string */
1841
/* in: error message string */
1847
/*************************************************************//**
1848
Parses an SQL string returning the query graph.
1849
@return own: the query graph */
1850
/*****************************************************************
1851
Parses an SQL string returning the query graph. */
1854
pars_info_t* info, /*!< in: extra information, or NULL */
1855
const char* str) /*!< in: SQL string */
1856
/* out, own: the query graph */
1857
pars_info_t* info, /* in: extra information, or NULL */
1858
const char* str) /* in: SQL string */
1857
1860
sym_node_t* sym_node;
1858
1861
mem_heap_t* heap;
1896
/******************************************************************//**
1899
/**********************************************************************
1897
1900
Completes a query graph by adding query thread and fork nodes
1898
1901
above it and prepares the graph for running. The fork created is of
1899
type QUE_FORK_MYSQL_INTERFACE.
1900
@return query thread node to run */
1902
type QUE_FORK_MYSQL_INTERFACE. */
1903
1905
pars_complete_graph_for_exec(
1904
1906
/*=========================*/
1905
que_node_t* node, /*!< in: root node for an incomplete
1907
/* out: query thread node to run */
1908
que_node_t* node, /* in: root node for an incomplete
1907
trx_t* trx, /*!< in: transaction handle */
1908
mem_heap_t* heap) /*!< in: memory heap from which allocated */
1910
trx_t* trx, /* in: transaction handle */
1911
mem_heap_t* heap) /* in: memory heap from which allocated */
1910
1913
que_fork_t* fork;
1911
1914
que_thr_t* thr;
1927
/****************************************************************//**
1928
Create parser info struct.
1929
@return own: info struct */
1930
/********************************************************************
1931
Create parser info struct.*/
1932
1934
pars_info_create(void)
1933
1935
/*==================*/
1936
/* out, own: info struct */
1935
1938
pars_info_t* info;
1936
1939
mem_heap_t* heap;
1951
/****************************************************************//**
1952
Free info struct and everything it contains. */
1954
/********************************************************************
1955
Free info struct and everything it contains.*/
1955
1958
pars_info_free(
1956
1959
/*===========*/
1957
pars_info_t* info) /*!< in, own: info struct */
1960
pars_info_t* info) /* in: info struct */
1959
1962
mem_heap_free(info->heap);
1962
/****************************************************************//**
1965
/********************************************************************
1963
1966
Add bound literal. */
1966
1969
pars_info_add_literal(
1967
1970
/*==================*/
1968
pars_info_t* info, /*!< in: info struct */
1969
const char* name, /*!< in: name */
1970
const void* address, /*!< in: address */
1971
ulint length, /*!< in: length of data */
1972
ulint type, /*!< in: type, e.g. DATA_FIXBINARY */
1973
ulint prtype) /*!< in: precise type, e.g.
1971
pars_info_t* info, /* in: info struct */
1972
const char* name, /* in: name */
1973
const void* address, /* in: address */
1974
ulint length, /* in: length of data */
1975
ulint type, /* in: type, e.g. DATA_FIXBINARY */
1976
ulint prtype) /* in: precise type, e.g.
1974
1977
DATA_UNSIGNED */
1976
1979
pars_bound_lit_t* pbl;
1992
1995
ib_vector_push(info->bound_lits, pbl);
1995
/****************************************************************//**
1998
/********************************************************************
1996
1999
Equivalent to pars_info_add_literal(info, name, str, strlen(str),
1997
2000
DATA_VARCHAR, DATA_ENGLISH). */
2000
2003
pars_info_add_str_literal(
2001
2004
/*======================*/
2002
pars_info_t* info, /*!< in: info struct */
2003
const char* name, /*!< in: name */
2004
const char* str) /*!< in: string */
2005
pars_info_t* info, /* in: info struct */
2006
const char* name, /* in: name */
2007
const char* str) /* in: string */
2006
2009
pars_info_add_literal(info, name, str, strlen(str),
2007
2010
DATA_VARCHAR, DATA_ENGLISH);
2010
/****************************************************************//**
2013
/********************************************************************
2021
2024
pars_info_add_int4_literal(
2022
2025
/*=======================*/
2023
pars_info_t* info, /*!< in: info struct */
2024
const char* name, /*!< in: name */
2025
lint val) /*!< in: value */
2026
pars_info_t* info, /* in: info struct */
2027
const char* name, /* in: name */
2028
lint val) /* in: value */
2027
2030
byte* buf = mem_heap_alloc(info->heap, 4);
2030
2033
pars_info_add_literal(info, name, buf, 4, DATA_INT, 0);
2033
/****************************************************************//**
2036
/********************************************************************
2044
2047
pars_info_add_dulint_literal(
2045
2048
/*=========================*/
2046
pars_info_t* info, /*!< in: info struct */
2047
const char* name, /*!< in: name */
2048
dulint val) /*!< in: value */
2049
pars_info_t* info, /* in: info struct */
2050
const char* name, /* in: name */
2051
dulint val) /* in: value */
2050
2053
byte* buf = mem_heap_alloc(info->heap, 8);
2054
2057
pars_info_add_literal(info, name, buf, 8, DATA_FIXBINARY, 0);
2057
/****************************************************************//**
2060
/********************************************************************
2058
2061
Add user function. */
2061
2064
pars_info_add_function(
2062
2065
/*===================*/
2063
pars_info_t* info, /*!< in: info struct */
2064
const char* name, /*!< in: function name */
2065
pars_user_func_cb_t func, /*!< in: function address */
2066
void* arg) /*!< in: user-supplied argument */
2066
pars_info_t* info, /* in: info struct */
2067
const char* name, /* in: function name */
2068
pars_user_func_cb_t func, /* in: function address */
2069
void* arg) /* in: user-supplied argument */
2068
2071
pars_user_func_t* puf;
2082
2085
ib_vector_push(info->funcs, puf);
2085
/****************************************************************//**
2088
/********************************************************************
2086
2089
Add bound id. */
2089
2092
pars_info_add_id(
2090
2093
/*=============*/
2091
pars_info_t* info, /*!< in: info struct */
2092
const char* name, /*!< in: name */
2093
const char* id) /*!< in: id */
2094
pars_info_t* info, /* in: info struct */
2095
const char* name, /* in: name */
2096
const char* id) /* in: id */
2095
2098
pars_bound_id_t* bid;
2108
2111
ib_vector_push(info->bound_ids, bid);
2111
/****************************************************************//**
2112
Get user function with the given name.
2113
@return user func, or NULL if not found */
2114
/********************************************************************
2115
Get user function with the given name.*/
2115
2117
pars_user_func_t*
2116
2118
pars_info_get_user_func(
2117
2119
/*====================*/
2118
pars_info_t* info, /*!< in: info struct */
2119
const char* name) /*!< in: function name to find*/
2120
/* out: user func, or NULL if not
2122
pars_info_t* info, /* in: info struct */
2123
const char* name) /* in: function name to find*/
2122
2126
ib_vector_t* vec;
2141
/****************************************************************//**
2142
Get bound literal with the given name.
2143
@return bound literal, or NULL if not found */
2145
/********************************************************************
2146
Get bound literal with the given name.*/
2145
2148
pars_bound_lit_t*
2146
2149
pars_info_get_bound_lit(
2147
2150
/*====================*/
2148
pars_info_t* info, /*!< in: info struct */
2149
const char* name) /*!< in: bound literal name to find */
2151
/* out: bound literal, or NULL if
2153
pars_info_t* info, /* in: info struct */
2154
const char* name) /* in: bound literal name to find */
2152
2157
ib_vector_t* vec;
2171
/****************************************************************//**
2172
Get bound id with the given name.
2173
@return bound id, or NULL if not found */
2176
/********************************************************************
2177
Get bound id with the given name.*/
2175
2179
pars_bound_id_t*
2176
2180
pars_info_get_bound_id(
2177
2181
/*===================*/
2178
pars_info_t* info, /*!< in: info struct */
2179
const char* name) /*!< in: bound id name to find */
2182
/* out: bound id, or NULL if not
2184
pars_info_t* info, /* in: info struct */
2185
const char* name) /* in: bound id name to find */
2182
2188
ib_vector_t* vec;