1/*
2   Copyright (c) 2000, 2015, Oracle and/or its affiliates.
3   Copyright (c) 2010, 2021, MariaDB
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 as published by
7   the Free Software Foundation; version 2 of the License.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */
17
18/* sql_yacc.yy */
19
20/**
21  @defgroup Parser Parser
22  @{
23*/
24
25%{
26#define YYLIP  (& thd->m_parser_state->m_lip)
27#define YYPS   (& thd->m_parser_state->m_yacc)
28#define YYCSCL (thd->variables.character_set_client)
29
30#define MYSQL_YACC
31#define YYINITDEPTH 100
32#define YYMAXDEPTH 3200                        /* Because of 64K stack */
33#define Lex (thd->lex)
34
35#define Select Lex->current_select
36#include "mariadb.h"
37#include "sql_priv.h"
38#include "sql_parse.h"                        /* comp_*_creator */
39#include "sql_table.h"                        /* primary_key_name */
40#include "sql_partition.h"  /* partition_info, HASH_PARTITION */
41#include "sql_class.h"      /* Key_part_spec, enum_filetype, Diag_condition_item_name */
42#include "slave.h"
43#include "lex_symbol.h"
44#include "item_create.h"
45#include "sp_head.h"
46#include "sp_rcontext.h"
47#include "sp.h"
48#include "sql_show.h"
49#include "sql_alter.h"                         // Sql_cmd_alter_table*
50#include "sql_truncate.h"                      // Sql_cmd_truncate_table
51#include "sql_admin.h"                         // Sql_cmd_analyze/Check..._table
52#include "sql_partition_admin.h"               // Sql_cmd_alter_table_*_part.
53#include "sql_handler.h"                       // Sql_cmd_handler_*
54#include "sql_signal.h"
55#include "sql_get_diagnostics.h"               // Sql_cmd_get_diagnostics
56#include "sql_cte.h"
57#include "sql_window.h"
58#include "item_windowfunc.h"
59#include "event_parse_data.h"
60#include "create_options.h"
61#include <myisam.h>
62#include <myisammrg.h>
63#include "keycaches.h"
64#include "set_var.h"
65#include "rpl_mi.h"
66#include "lex_token.h"
67#include "sql_lex.h"
68#include "sql_sequence.h"
69#include "my_base.h"
70#include "sql_type_json.h"
71
72/* this is to get the bison compilation windows warnings out */
73#ifdef _MSC_VER
74/* warning C4065: switch statement contains 'default' but no 'case' labels */
75/* warning C4102: 'yyexhaustedlab': unreferenced label */
76#pragma warning (disable : 4065 4102)
77#endif
78#ifdef __GNUC__
79#pragma GCC diagnostic ignored "-Wunused-label" /* yyexhaustedlab: */
80#endif
81
82int yylex(void *yylval, void *yythd);
83
84#define yyoverflow(A,B,C,D,E,F)               \
85  {                                           \
86    size_t val= *(F);                         \
87    if (unlikely(my_yyoverflow((B), (D), &val))) \
88    {                                         \
89      yyerror(thd, (char*) (A));              \
90      return 2;                               \
91    }                                         \
92    else                                      \
93    {                                         \
94      *(F)= (YYSIZE_T)val;                    \
95    }                                         \
96  }
97
98#define MYSQL_YYABORT                         \
99  do                                          \
100  {                                           \
101    LEX::cleanup_lex_after_parse_error(thd);  \
102    YYABORT;                                  \
103  } while (0)
104
105#define MYSQL_YYABORT_UNLESS(A)                  \
106  if (unlikely(!(A)))                            \
107  {                                              \
108    thd->parse_error();                          \
109    MYSQL_YYABORT;                               \
110  }
111
112#define my_yyabort_error(A)                      \
113  do { my_error A; MYSQL_YYABORT; } while(0)
114
115#ifndef DBUG_OFF
116#define YYDEBUG 1
117#else
118#define YYDEBUG 0
119#endif
120
121
122static Item* escape(THD *thd)
123{
124  thd->lex->escape_used= false;
125  const char *esc= thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES ? "" : "\\";
126  return new (thd->mem_root) Item_string_ascii(thd, esc, MY_TEST(esc[0]));
127}
128
129
130/**
131  @brief Bison callback to report a syntax/OOM error
132
133  This function is invoked by the bison-generated parser
134  when a syntax error, a parse error or an out-of-memory
135  condition occurs. This function is not invoked when the
136  parser is requested to abort by semantic action code
137  by means of YYABORT or YYACCEPT macros. This is why these
138  macros should not be used (use MYSQL_YYABORT/MYSQL_YYACCEPT
139  instead).
140
141  The parser will abort immediately after invoking this callback.
142
143  This function is not for use in semantic actions and is internal to
144  the parser, as it performs some pre-return cleanup.
145  In semantic actions, please use thd->parse_error() or my_error to
146  push an error into the error stack and MYSQL_YYABORT
147  to abort from the parser.
148*/
149
150static void yyerror(THD *thd, const char *s)
151{
152  /*
153    Restore the original LEX if it was replaced when parsing
154    a stored procedure. We must ensure that a parsing error
155    does not leave any side effects in the THD.
156  */
157  LEX::cleanup_lex_after_parse_error(thd);
158
159  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
160  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
161    s= ER_THD(thd, ER_SYNTAX_ERROR);
162  thd->parse_error(s, 0);
163}
164
165
166#ifndef DBUG_OFF
167#define __CONCAT_UNDERSCORED(x,y)  x ## _ ## y
168#define _CONCAT_UNDERSCORED(x,y)   __CONCAT_UNDERSCORED(x,y)
169void _CONCAT_UNDERSCORED(turn_parser_debug_on,yyparse)()
170{
171  /*
172     MYSQLdebug is in sql/yy_*.cc, in bison generated code.
173     Turning this option on is **VERY** verbose, and should be
174     used when investigating a syntax error problem only.
175
176     The syntax to run with bison traces is as follows :
177     - Starting a server manually :
178       mysqld --debug-dbug="d,parser_debug" ...
179     - Running a test :
180       mysql-test-run.pl --mysqld="--debug-dbug=d,parser_debug" ...
181
182     The result will be in the process stderr (var/log/master.err)
183   */
184
185#ifndef _AIX
186  extern int yydebug;
187#else
188  static int yydebug;
189#endif
190  yydebug= 1;
191}
192#endif
193
194
195#define bincmp_collation(X,Y)           \
196  do                                    \
197  {                                     \
198     if (unlikely(Lex->set_bincmp(X,Y))) \
199       MYSQL_YYABORT;                   \
200  } while(0)
201
202%}
203%union {
204  int  num;
205  ulong ulong_num;
206  ulonglong ulonglong_number;
207  longlong longlong_number;
208  uint sp_instr_addr;
209
210  /* structs */
211  LEX_CSTRING lex_str;
212  Lex_ident_cli_st kwd;
213  Lex_ident_cli_st ident_cli;
214  Lex_ident_sys_st ident_sys;
215  Lex_column_list_privilege_st column_list_privilege;
216  Lex_string_with_metadata_st lex_string_with_metadata;
217  Lex_spblock_st spblock;
218  Lex_spblock_handlers_st spblock_handlers;
219  Lex_length_and_dec_st Lex_length_and_dec;
220  Lex_cast_type_st Lex_cast_type;
221  Lex_field_type_st Lex_field_type;
222  Lex_dyncol_type_st Lex_dyncol_type;
223  Lex_for_loop_st for_loop;
224  Lex_for_loop_bounds_st for_loop_bounds;
225  Lex_trim_st trim;
226  vers_history_point_t vers_history_point;
227  struct
228  {
229    enum sub_select_type unit_type;
230    bool distinct;
231  } unit_operation;
232  struct
233  {
234    SELECT_LEX *first;
235    SELECT_LEX *prev_last;
236  } select_list;
237  SQL_I_List<ORDER> *select_order;
238  Lex_select_lock select_lock;
239  Lex_select_limit select_limit;
240  Lex_order_limit_lock *order_limit_lock;
241
242  /* pointers */
243  Lex_ident_sys *ident_sys_ptr;
244  Create_field *create_field;
245  Spvar_definition *spvar_definition;
246  Row_definition_list *spvar_definition_list;
247  const Type_handler *type_handler;
248  const class Sp_handler *sp_handler;
249  CHARSET_INFO *charset;
250  Condition_information_item *cond_info_item;
251  DYNCALL_CREATE_DEF *dyncol_def;
252  Diagnostics_information *diag_info;
253  Item *item;
254  Item_num *item_num;
255  Item_param *item_param;
256  Item_basic_constant *item_basic_constant;
257  Key_part_spec *key_part;
258  LEX *lex;
259  sp_expr_lex *expr_lex;
260  sp_assignment_lex *assignment_lex;
261  class sp_lex_cursor *sp_cursor_stmt;
262  LEX_CSTRING *lex_str_ptr;
263  LEX_USER *lex_user;
264  USER_AUTH *user_auth;
265  List<Condition_information_item> *cond_info_list;
266  List<DYNCALL_CREATE_DEF> *dyncol_def_list;
267  List<Item> *item_list;
268  List<sp_assignment_lex> *sp_assignment_lex_list;
269  List<Statement_information_item> *stmt_info_list;
270  List<String> *string_list;
271  List<Lex_ident_sys> *ident_sys_list;
272  Statement_information_item *stmt_info_item;
273  String *string;
274  TABLE_LIST *table_list;
275  Table_ident *table;
276  Qualified_column_ident *qualified_column_ident;
277  char *simple_string;
278  const char *const_simple_string;
279  chooser_compare_func_creator boolfunc2creator;
280  class Lex_grant_privilege *lex_grant;
281  class Lex_grant_object_name *lex_grant_ident;
282  class my_var *myvar;
283  class sp_condition_value *spcondvalue;
284  class sp_head *sphead;
285  class sp_name *spname;
286  class sp_variable *spvar;
287  class With_element_head *with_element_head;
288  class With_clause *with_clause;
289  class Virtual_column_info *virtual_column;
290
291  handlerton *db_type;
292  st_select_lex *select_lex;
293  st_select_lex_unit *select_lex_unit;
294  struct p_elem_val *p_elem_value;
295  class Window_frame *window_frame;
296  class Window_frame_bound *window_frame_bound;
297  udf_func *udf;
298  st_trg_execution_order trg_execution_order;
299
300  /* enums */
301  enum enum_sp_suid_behaviour sp_suid;
302  enum enum_sp_aggregate_type sp_aggregate_type;
303  enum enum_view_suid view_suid;
304  enum Condition_information_item::Name cond_info_item_name;
305  enum enum_diag_condition_item_name diag_condition_item_name;
306  enum Diagnostics_information::Which_area diag_area;
307  enum enum_fk_option m_fk_option;
308  enum Item_udftype udf_type;
309  enum Key::Keytype key_type;
310  enum Statement_information_item::Name stmt_info_item_name;
311  enum enum_filetype filetype;
312  enum enum_tx_isolation tx_isolation;
313  enum enum_var_type var_type;
314  enum enum_yes_no_unknown m_yes_no_unk;
315  enum ha_choice choice;
316  enum ha_key_alg key_alg;
317  enum ha_rkey_function ha_rkey_mode;
318  enum index_hint_type index_hint;
319  enum interval_type interval, interval_time_st;
320  enum row_type row_type;
321  enum sp_variable::enum_mode spvar_mode;
322  enum thr_lock_type lock_type;
323  enum enum_mysql_timestamp_type date_time_type;
324  enum Window_frame_bound::Bound_precedence_type bound_precedence_type;
325  enum Window_frame::Frame_units frame_units;
326  enum Window_frame::Frame_exclusion frame_exclusion;
327  enum trigger_order_type trigger_action_order_type;
328  DDL_options_st object_ddl_options;
329  enum vers_kind_t vers_range_unit;
330  enum Column_definition::enum_column_versioning vers_column_versioning;
331  enum plsql_cursor_attr_t plsql_cursor_attr;
332  privilege_t privilege;
333}
334
335%{
336/* avoid unintentional %union size increases, it's what a parser stack made of */
337static_assert(sizeof(YYSTYPE) == sizeof(void*)*2+8, "%union size check");
338bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
339%}
340
341%pure-parser                                    /* We have threads */
342%parse-param { THD *thd }
343%lex-param { THD *thd }
344/*
345  We should not introduce any further shift/reduce conflicts.
346*/
347
348%ifdef MARIADB
349%expect 67
350%else
351%expect 69
352%endif
353
354
355/*
356   Comments for TOKENS.
357   For each token, please include in the same line a comment that contains
358   the following tags:
359   SQL-2011-R : Reserved keyword as per SQL-2011
360   SQL-2011-N : Non Reserved keyword as per SQL-2011
361   SQL-2003-R : Reserved keyword as per SQL-2003
362   SQL-2003-N : Non Reserved keyword as per SQL-2003
363   SQL-1999-R : Reserved keyword as per SQL-1999
364   SQL-1999-N : Non Reserved keyword as per SQL-1999
365   MYSQL      : MySQL extention (unspecified)
366   MYSQL-FUNC : MySQL extention, function
367   INTERNAL   : Not a real token, lex optimization
368   OPERATOR   : SQL operator
369   FUTURE-USE : Reserved for future use
370
371   This makes the code grep-able, and helps maintenance.
372*/
373
374
375%token <lex_str> '@'
376
377/*
378  Special purpose tokens
379*/
380%token  <NONE> ABORT_SYM              /* INTERNAL (used in lex) */
381%token  <NONE> IMPOSSIBLE_ACTION      /* To avoid warning for yyerrlab1 */
382%token  <NONE> END_OF_INPUT           /* INTERNAL */
383%token  <kwd>  COLON_ORACLE_SYM       /* INTERNAL */
384%token  <kwd>  PARAM_MARKER           /* INTERNAL */
385%token  <NONE> FOR_SYSTEM_TIME_SYM    /* INTERNAL */
386%token  <NONE> LEFT_PAREN_ALT         /* INTERNAL */
387%token  <NONE> LEFT_PAREN_WITH        /* INTERNAL */
388%token  <NONE> LEFT_PAREN_LIKE        /* INTERNAL */
389%token  <NONE> ORACLE_CONCAT_SYM      /* INTERNAL */
390%token  <NONE> PERCENT_ORACLE_SYM     /* INTERNAL */
391%token  <NONE> WITH_CUBE_SYM          /* INTERNAL */
392%token  <NONE> WITH_ROLLUP_SYM        /* INTERNAL */
393%token  <NONE> WITH_SYSTEM_SYM        /* INTERNAL */
394
395
396/*
397  Identifiers
398*/
399%token  IDENT
400%token  IDENT_QUOTED
401%token  LEX_HOSTNAME
402%token  UNDERSCORE_CHARSET            /* _latin1 */
403
404
405/*
406  Literals
407*/
408%token  BIN_NUM                       /* LITERAL */
409%token  DECIMAL_NUM                   /* LITERAL */
410%token  FLOAT_NUM                     /* LITERAL */
411%token  HEX_NUM                       /* LITERAL */
412%token  HEX_STRING                    /* LITERAL */
413%token  LONG_NUM                      /* LITERAL */
414%token  NCHAR_STRING                  /* LITERAL */
415%token  NUM                           /* LITERAL */
416%token  TEXT_STRING                   /* LITERAL */
417%token  ULONGLONG_NUM                 /* LITERAL */
418
419
420/*
421  Operators
422*/
423%token  <NONE> AND_AND_SYM            /* OPERATOR */
424%token  <NONE> DOT_DOT_SYM            /* OPERATOR */
425%token  <NONE> EQUAL_SYM              /* OPERATOR */
426%token  <NONE> GE                     /* OPERATOR */
427%token  <NONE> LE                     /* OPERATOR */
428%token  <NONE> MYSQL_CONCAT_SYM       /* OPERATOR */
429%token  <NONE> NE                     /* OPERATOR */
430%token  <NONE> NOT2_SYM               /* OPERATOR */
431%token  <NONE> OR2_SYM                /* OPERATOR */
432%token  <NONE> SET_VAR                /* OPERATOR */
433%token  <NONE> SHIFT_LEFT             /* OPERATOR */
434%token  <NONE> SHIFT_RIGHT            /* OPERATOR */
435
436
437/*
438  Reserved keywords
439*/
440%token  <kwd> ACCESSIBLE_SYM
441%token  <kwd> ADD                           /* SQL-2003-R */
442%token  <kwd> ALL                           /* SQL-2003-R */
443%token  <kwd> ALTER                         /* SQL-2003-R */
444%token  <kwd> ANALYZE_SYM
445%token  <kwd> AND_SYM                       /* SQL-2003-R */
446%token  <kwd> ASC                           /* SQL-2003-N */
447%token  <kwd> ASENSITIVE_SYM                /* FUTURE-USE */
448%token  <kwd> AS                            /* SQL-2003-R */
449%token  <kwd> BEFORE_SYM                    /* SQL-2003-N */
450%token  <kwd> BETWEEN_SYM                   /* SQL-2003-R */
451%token  <kwd> BIGINT                        /* SQL-2003-R */
452%token  <kwd> BINARY                        /* SQL-2003-R */
453%token  <kwd> BIT_AND                       /* MYSQL-FUNC */
454%token  <kwd> BIT_OR                        /* MYSQL-FUNC */
455%token  <kwd> BIT_XOR                       /* MYSQL-FUNC */
456%token  <kwd> BLOB_MARIADB_SYM              /* SQL-2003-R */
457%token  <kwd> BLOB_ORACLE_SYM               /* Oracle-R   */
458%token  <kwd> BODY_ORACLE_SYM               /* Oracle-R   */
459%token  <kwd> BOTH                          /* SQL-2003-R */
460%token  <kwd> BY                            /* SQL-2003-R */
461%token  <kwd> CALL_SYM                      /* SQL-2003-R */
462%token  <kwd> CASCADE                       /* SQL-2003-N */
463%token  <kwd> CASE_SYM                      /* SQL-2003-R */
464%token  <kwd> CAST_SYM                      /* SQL-2003-R */
465%token  <kwd> CHANGE
466%token  <kwd> CHAR_SYM                      /* SQL-2003-R */
467%token  <kwd> CHECK_SYM                     /* SQL-2003-R */
468%token  <kwd> COLLATE_SYM                   /* SQL-2003-R */
469%token  <kwd> CONDITION_SYM                 /* SQL-2003-R, SQL-2008-R */
470%token  <kwd> CONSTRAINT                    /* SQL-2003-R */
471%token  <kwd> CONTINUE_MARIADB_SYM          /* SQL-2003-R, Oracle-R */
472%token  <kwd> CONTINUE_ORACLE_SYM           /* SQL-2003-R, Oracle-R */
473%token  <kwd> CONVERT_SYM                   /* SQL-2003-N */
474%token  <kwd> COUNT_SYM                     /* SQL-2003-N */
475%token  <kwd> CREATE                        /* SQL-2003-R */
476%token  <kwd> CROSS                         /* SQL-2003-R */
477%token  <kwd> CUME_DIST_SYM
478%token  <kwd> CURDATE                       /* MYSQL-FUNC */
479%token  <kwd> CURRENT_ROLE                  /* SQL-2003-R */
480%token  <kwd> CURRENT_USER                  /* SQL-2003-R */
481%token  <kwd> CURSOR_SYM                    /* SQL-2003-R */
482%token  <kwd> CURTIME                       /* MYSQL-FUNC */
483%token  <kwd> DATABASE
484%token  <kwd> DATABASES
485%token  <kwd> DATE_ADD_INTERVAL             /* MYSQL-FUNC */
486%token  <kwd> DATE_SUB_INTERVAL             /* MYSQL-FUNC */
487%token  <kwd> DAY_HOUR_SYM
488%token  <kwd> DAY_MICROSECOND_SYM
489%token  <kwd> DAY_MINUTE_SYM
490%token  <kwd> DAY_SECOND_SYM
491%token  <kwd> DECIMAL_SYM                   /* SQL-2003-R */
492%token  <kwd> DECLARE_MARIADB_SYM           /* SQL-2003-R */
493%token  <kwd> DECLARE_ORACLE_SYM            /* Oracle-R   */
494%token  <kwd> DEFAULT                       /* SQL-2003-R */
495%token  <kwd> DELETE_DOMAIN_ID_SYM
496%token  <kwd> DELETE_SYM                    /* SQL-2003-R */
497%token  <kwd> DENSE_RANK_SYM
498%token  <kwd> DESCRIBE                      /* SQL-2003-R */
499%token  <kwd> DESC                          /* SQL-2003-N */
500%token  <kwd> DETERMINISTIC_SYM             /* SQL-2003-R */
501%token  <kwd> DISTINCT                      /* SQL-2003-R */
502%token  <kwd> DIV_SYM
503%token  <kwd> DO_DOMAIN_IDS_SYM
504%token  <kwd> DOUBLE_SYM                    /* SQL-2003-R */
505%token  <kwd> DROP                          /* SQL-2003-R */
506%token  <kwd> DUAL_SYM
507%token  <kwd> EACH_SYM                      /* SQL-2003-R */
508%token  <kwd> ELSEIF_MARIADB_SYM
509%token  <kwd> ELSE                          /* SQL-2003-R */
510%token  <kwd> ELSIF_ORACLE_SYM              /* PLSQL-R    */
511%token  <kwd> ENCLOSED
512%token  <kwd> ESCAPED
513%token  <kwd> EXCEPT_SYM                    /* SQL-2003-R */
514%token  <kwd> EXISTS                        /* SQL-2003-R */
515%token  <kwd> EXTRACT_SYM                   /* SQL-2003-N */
516%token  <kwd> FALSE_SYM                     /* SQL-2003-R */
517%token  <kwd> FETCH_SYM                     /* SQL-2003-R */
518%token  <kwd> FIRST_VALUE_SYM               /* SQL-2011 */
519%token  <kwd> FLOAT_SYM                     /* SQL-2003-R */
520%token  <kwd> FOREIGN                       /* SQL-2003-R */
521%token  <kwd> FOR_SYM                       /* SQL-2003-R */
522%token  <kwd> FROM
523%token  <kwd> FULLTEXT_SYM
524%token  <kwd> GOTO_ORACLE_SYM               /* Oracle-R   */
525%token  <kwd> GRANT                         /* SQL-2003-R */
526%token  <kwd> GROUP_CONCAT_SYM
527%token  <rwd> JSON_ARRAYAGG_SYM
528%token  <rwd> JSON_OBJECTAGG_SYM
529%token  <kwd> GROUP_SYM                     /* SQL-2003-R */
530%token  <kwd> HAVING                        /* SQL-2003-R */
531%token  <kwd> HOUR_MICROSECOND_SYM
532%token  <kwd> HOUR_MINUTE_SYM
533%token  <kwd> HOUR_SECOND_SYM
534%token  <kwd> IF_SYM
535%token  <kwd> IGNORE_DOMAIN_IDS_SYM
536%token  <kwd> IGNORE_SYM
537%token  <kwd> INDEX_SYM
538%token  <kwd> INFILE
539%token  <kwd> INNER_SYM                     /* SQL-2003-R */
540%token  <kwd> INOUT_SYM                     /* SQL-2003-R */
541%token  <kwd> INSENSITIVE_SYM               /* SQL-2003-R */
542%token  <kwd> INSERT                        /* SQL-2003-R */
543%token  <kwd> IN_SYM                        /* SQL-2003-R */
544%token  <kwd> INTERSECT_SYM                 /* SQL-2003-R */
545%token  <kwd> INTERVAL_SYM                  /* SQL-2003-R */
546%token  <kwd> INTO                          /* SQL-2003-R */
547%token  <kwd> INT_SYM                       /* SQL-2003-R */
548%token  <kwd> IS                            /* SQL-2003-R */
549%token  <kwd> ITERATE_SYM
550%token  <kwd> JOIN_SYM                      /* SQL-2003-R */
551%token  <kwd> KEYS
552%token  <kwd> KEY_SYM                       /* SQL-2003-N */
553%token  <kwd> KILL_SYM
554%token  <kwd> LAG_SYM                       /* SQL-2011 */
555%token  <kwd> LEADING                       /* SQL-2003-R */
556%token  <kwd> LEAD_SYM                      /* SQL-2011 */
557%token  <kwd> LEAVE_SYM
558%token  <kwd> LEFT                          /* SQL-2003-R */
559%token  <kwd> LIKE                          /* SQL-2003-R */
560%token  <kwd> LIMIT
561%token  <kwd> LINEAR_SYM
562%token  <kwd> LINES
563%token  <kwd> LOAD
564%token  <kwd> LOCATOR_SYM                   /* SQL-2003-N */
565%token  <kwd> LOCK_SYM
566%token  <kwd> LONGBLOB
567%token  <kwd> LONG_SYM
568%token  <kwd> LONGTEXT
569%token  <kwd> LOOP_SYM
570%token  <kwd> LOW_PRIORITY
571%token  <kwd> MASTER_SSL_VERIFY_SERVER_CERT_SYM
572%token  <kwd> MATCH                         /* SQL-2003-R */
573%token  <kwd> MAX_SYM                       /* SQL-2003-N */
574%token  <kwd> MAXVALUE_SYM                  /* SQL-2003-N */
575%token  <kwd> MEDIAN_SYM
576%token  <kwd> MEDIUMBLOB
577%token  <kwd> MEDIUMINT
578%token  <kwd> MEDIUMTEXT
579%token  <kwd> MIN_SYM                       /* SQL-2003-N */
580%token  <kwd> MINUTE_MICROSECOND_SYM
581%token  <kwd> MINUTE_SECOND_SYM
582%token  <kwd> MODIFIES_SYM                  /* SQL-2003-R */
583%token  <kwd> MOD_SYM                       /* SQL-2003-N */
584%token  <kwd> NATURAL                       /* SQL-2003-R */
585%token  <kwd> NEG
586%token  <kwd> NOT_SYM                       /* SQL-2003-R */
587%token  <kwd> NO_WRITE_TO_BINLOG
588%token  <kwd> NOW_SYM
589%token  <kwd> NTH_VALUE_SYM                 /* SQL-2011 */
590%token  <kwd> NTILE_SYM
591%token  <kwd> NULL_SYM                      /* SQL-2003-R */
592%token  <kwd> NUMERIC_SYM                   /* SQL-2003-R */
593%token  <kwd> ON                            /* SQL-2003-R */
594%token  <kwd> OPTIMIZE
595%token  <kwd> OPTIONALLY
596%token  <kwd> ORDER_SYM                     /* SQL-2003-R */
597%token  <kwd> OR_SYM                        /* SQL-2003-R */
598%token  <kwd> OTHERS_ORACLE_SYM             /* SQL-2011-N, PLSQL-R */
599%token  <kwd> OUTER
600%token  <kwd> OUTFILE
601%token  <kwd> OUT_SYM                       /* SQL-2003-R */
602%token  <kwd> OVER_SYM
603%token  <kwd> PACKAGE_ORACLE_SYM            /* Oracle-R   */
604%token  <kwd> PAGE_CHECKSUM_SYM
605%token  <kwd> PARSE_VCOL_EXPR_SYM
606%token  <kwd> PARTITION_SYM                 /* SQL-2003-R */
607%token  <kwd> PERCENTILE_CONT_SYM
608%token  <kwd> PERCENTILE_DISC_SYM
609%token  <kwd> PERCENT_RANK_SYM
610%token  <kwd> PORTION_SYM                   /* SQL-2016-R */
611%token  <kwd> POSITION_SYM                  /* SQL-2003-N */
612%token  <kwd> PRECISION                     /* SQL-2003-R */
613%token  <kwd> PRIMARY_SYM                   /* SQL-2003-R */
614%token  <kwd> PROCEDURE_SYM                 /* SQL-2003-R */
615%token  <kwd> PURGE
616%token  <kwd> RAISE_ORACLE_SYM              /* PLSQL-R    */
617%token  <kwd> RANGE_SYM                     /* SQL-2003-R */
618%token  <kwd> RANK_SYM
619%token  <kwd> READS_SYM                     /* SQL-2003-R */
620%token  <kwd> READ_SYM                      /* SQL-2003-N */
621%token  <kwd> READ_WRITE_SYM
622%token  <kwd> REAL                          /* SQL-2003-R */
623%token  <kwd> RECURSIVE_SYM
624%token  <kwd> REFERENCES                    /* SQL-2003-R */
625%token  <kwd> REF_SYSTEM_ID_SYM
626%token  <kwd> REGEXP
627%token  <kwd> RELEASE_SYM                   /* SQL-2003-R */
628%token  <kwd> RENAME
629%token  <kwd> REPEAT_SYM                    /* MYSQL-FUNC */
630%token  <kwd> REPLACE                       /* MYSQL-FUNC */
631%token  <kwd> REQUIRE_SYM
632%token  <kwd> RESIGNAL_SYM                  /* SQL-2003-R */
633%token  <kwd> RESTRICT
634%token  <kwd> RETURNING_SYM
635%token  <kwd> RETURN_MARIADB_SYM            /* SQL-2003-R, PLSQL-R */
636%token  <kwd> RETURN_ORACLE_SYM             /* SQL-2003-R, PLSQL-R */
637%token  <kwd> REVOKE                        /* SQL-2003-R */
638%token  <kwd> RIGHT                         /* SQL-2003-R */
639%token  <kwd> ROW_NUMBER_SYM
640%token  <kwd> ROWS_SYM                      /* SQL-2003-R */
641%token  <kwd> ROWTYPE_ORACLE_SYM            /* PLSQL-R    */
642%token  <kwd> SECOND_MICROSECOND_SYM
643%token  <kwd> SELECT_SYM                    /* SQL-2003-R */
644%token  <kwd> SENSITIVE_SYM                 /* FUTURE-USE */
645%token  <kwd> SEPARATOR_SYM
646%token  <kwd> SERVER_OPTIONS
647%token  <kwd> SET                           /* SQL-2003-R */
648%token  <kwd> SHOW
649%token  <kwd> SIGNAL_SYM                    /* SQL-2003-R */
650%token  <kwd> SMALLINT                      /* SQL-2003-R */
651%token  <kwd> SPATIAL_SYM
652%token  <kwd> SPECIFIC_SYM                  /* SQL-2003-R */
653%token  <kwd> SQL_BIG_RESULT
654%token  <kwd> SQLEXCEPTION_SYM              /* SQL-2003-R */
655%token  <kwd> SQL_SMALL_RESULT
656%token  <kwd> SQLSTATE_SYM                  /* SQL-2003-R */
657%token  <kwd> SQL_SYM                       /* SQL-2003-R */
658%token  <kwd> SQLWARNING_SYM                /* SQL-2003-R */
659%token  <kwd> SSL_SYM
660%token  <kwd> STARTING
661%token  <kwd> STATS_AUTO_RECALC_SYM
662%token  <kwd> STATS_PERSISTENT_SYM
663%token  <kwd> STATS_SAMPLE_PAGES_SYM
664%token  <kwd> STDDEV_SAMP_SYM               /* SQL-2003-N */
665%token  <kwd> STD_SYM
666%token  <kwd> STRAIGHT_JOIN
667%token  <kwd> SUBSTRING                     /* SQL-2003-N */
668%token  <kwd> SUM_SYM                       /* SQL-2003-N */
669%token  <kwd> SYSDATE
670%token  <kwd> TABLE_REF_PRIORITY
671%token  <kwd> TABLE_SYM                     /* SQL-2003-R */
672%token  <kwd> TERMINATED
673%token  <kwd> THEN_SYM                      /* SQL-2003-R */
674%token  <kwd> TINYBLOB
675%token  <kwd> TINYINT
676%token  <kwd> TINYTEXT
677%token  <kwd> TO_SYM                        /* SQL-2003-R */
678%token  <kwd> TRAILING                      /* SQL-2003-R */
679%token  <kwd> TRIGGER_SYM                   /* SQL-2003-R */
680%token  <kwd> TRIM                          /* SQL-2003-N */
681%token  <kwd> TRUE_SYM                      /* SQL-2003-R */
682%token  <kwd> UNDO_SYM                      /* FUTURE-USE */
683%token  <kwd> UNION_SYM                     /* SQL-2003-R */
684%token  <kwd> UNIQUE_SYM
685%token  <kwd> UNLOCK_SYM
686%token  <kwd> UNSIGNED
687%token  <kwd> UPDATE_SYM                    /* SQL-2003-R */
688%token  <kwd> USAGE                         /* SQL-2003-N */
689%token  <kwd> USE_SYM
690%token  <kwd> USING                         /* SQL-2003-R */
691%token  <kwd> UTC_DATE_SYM
692%token  <kwd> UTC_TIMESTAMP_SYM
693%token  <kwd> UTC_TIME_SYM
694%token  <kwd> VALUES_IN_SYM
695%token  <kwd> VALUES_LESS_SYM
696%token  <kwd> VALUES                        /* SQL-2003-R */
697%token  <kwd> VARBINARY
698%token  <kwd> VARCHAR                       /* SQL-2003-R */
699%token  <kwd> VARIANCE_SYM
700%token  <kwd> VAR_SAMP_SYM
701%token  <kwd> VARYING                       /* SQL-2003-R */
702%token  <kwd> WHEN_SYM                      /* SQL-2003-R */
703%token  <kwd> WHERE                         /* SQL-2003-R */
704%token  <kwd> WHILE_SYM
705%token  <kwd> WITH                          /* SQL-2003-R */
706%token  <kwd> XOR
707%token  <kwd> YEAR_MONTH_SYM
708%token  <kwd> ZEROFILL
709
710
711/*
712  Keywords that have different reserved status in std/oracle modes.
713*/
714%token  <kwd>  BODY_MARIADB_SYM              // Oracle-R
715%token  <kwd>  ELSEIF_ORACLE_SYM
716%token  <kwd>  ELSIF_MARIADB_SYM             // PLSQL-R
717%token  <kwd>  EXCEPTION_ORACLE_SYM          // SQL-2003-N, PLSQL-R
718%token  <kwd>  GOTO_MARIADB_SYM              // Oracle-R
719%token  <kwd>  OTHERS_MARIADB_SYM            // SQL-2011-N, PLSQL-R
720%token  <kwd>  PACKAGE_MARIADB_SYM           // Oracle-R
721%token  <kwd>  RAISE_MARIADB_SYM             // PLSQL-R
722%token  <kwd>  ROWTYPE_MARIADB_SYM           // PLSQL-R
723
724/*
725  Non-reserved keywords
726*/
727
728%token  <kwd>  ACCOUNT_SYM                   /* MYSQL */
729%token  <kwd>  ACTION                        /* SQL-2003-N */
730%token  <kwd>  ADMIN_SYM                     /* SQL-2003-N */
731%token  <kwd>  ADDDATE_SYM                   /* MYSQL-FUNC */
732%token  <kwd>  AFTER_SYM                     /* SQL-2003-N */
733%token  <kwd>  AGAINST
734%token  <kwd>  AGGREGATE_SYM
735%token  <kwd>  ALGORITHM_SYM
736%token  <kwd>  ALWAYS_SYM
737%token  <kwd>  ANY_SYM                       /* SQL-2003-R */
738%token  <kwd>  ASCII_SYM                     /* MYSQL-FUNC */
739%token  <kwd>  AT_SYM                        /* SQL-2003-R */
740%token  <kwd>  ATOMIC_SYM                    /* SQL-2003-R */
741%token  <kwd>  AUTHORS_SYM
742%token  <kwd>  AUTOEXTEND_SIZE_SYM
743%token  <kwd>  AUTO_INC
744%token  <kwd>  AUTO_SYM
745%token  <kwd>  AVG_ROW_LENGTH
746%token  <kwd>  AVG_SYM                       /* SQL-2003-N */
747%token  <kwd>  BACKUP_SYM
748%token  <kwd>  BEGIN_MARIADB_SYM             /* SQL-2003-R, PLSQL-R */
749%token  <kwd>  BEGIN_ORACLE_SYM              /* SQL-2003-R, PLSQL-R */
750%token  <kwd>  BINLOG_SYM
751%token  <kwd>  BIT_SYM                       /* MYSQL-FUNC */
752%token  <kwd>  BLOCK_SYM
753%token  <kwd>  BOOL_SYM
754%token  <kwd>  BOOLEAN_SYM                   /* SQL-2003-R, PLSQL-R */
755%token  <kwd>  BTREE_SYM
756%token  <kwd>  BYTE_SYM
757%token  <kwd>  CACHE_SYM
758%token  <kwd>  CASCADED                      /* SQL-2003-R */
759%token  <kwd>  CATALOG_NAME_SYM              /* SQL-2003-N */
760%token  <kwd>  CHAIN_SYM                     /* SQL-2003-N */
761%token  <kwd>  CHANGED
762%token  <kwd>  CHARSET
763%token  <kwd>  CHECKPOINT_SYM
764%token  <kwd>  CHECKSUM_SYM
765%token  <kwd>  CIPHER_SYM
766%token  <kwd>  CLASS_ORIGIN_SYM              /* SQL-2003-N */
767%token  <kwd>  CLIENT_SYM
768%token  <kwd>  CLOB_MARIADB_SYM              /* SQL-2003-R */
769%token  <kwd>  CLOB_ORACLE_SYM               /* Oracle-R   */
770%token  <kwd>  CLOSE_SYM                     /* SQL-2003-R */
771%token  <kwd>  COALESCE                      /* SQL-2003-N */
772%token  <kwd>  CODE_SYM
773%token  <kwd>  COLLATION_SYM                 /* SQL-2003-N */
774%token  <kwd>  COLUMNS
775%token  <kwd>  COLUMN_ADD_SYM
776%token  <kwd>  COLUMN_CHECK_SYM
777%token  <kwd>  COLUMN_CREATE_SYM
778%token  <kwd>  COLUMN_DELETE_SYM
779%token  <kwd>  COLUMN_GET_SYM
780%token  <kwd>  COLUMN_SYM                    /* SQL-2003-R */
781%token  <kwd>  COLUMN_NAME_SYM               /* SQL-2003-N */
782%token  <kwd>  COMMENT_SYM                   /* Oracle-R   */
783%token  <kwd>  COMMITTED_SYM                 /* SQL-2003-N */
784%token  <kwd>  COMMIT_SYM                    /* SQL-2003-R */
785%token  <kwd>  COMPACT_SYM
786%token  <kwd>  COMPLETION_SYM
787%token  <kwd>  COMPRESSED_SYM
788%token  <kwd>  CONCURRENT
789%token  <kwd>  CONNECTION_SYM
790%token  <kwd>  CONSISTENT_SYM
791%token  <kwd>  CONSTRAINT_CATALOG_SYM        /* SQL-2003-N */
792%token  <kwd>  CONSTRAINT_NAME_SYM           /* SQL-2003-N */
793%token  <kwd>  CONSTRAINT_SCHEMA_SYM         /* SQL-2003-N */
794%token  <kwd>  CONTAINS_SYM                  /* SQL-2003-N */
795%token  <kwd>  CONTEXT_SYM
796%token  <kwd>  CONTRIBUTORS_SYM
797%token  <kwd>  CPU_SYM
798%token  <kwd>  CUBE_SYM                      /* SQL-2003-R */
799%token  <kwd>  CURRENT_SYM                   /* SQL-2003-R */
800%token  <kwd>  CURRENT_POS_SYM
801%token  <kwd>  CURSOR_NAME_SYM               /* SQL-2003-N */
802%token  <kwd>  CYCLE_SYM
803%token  <kwd>  DATAFILE_SYM
804%token  <kwd>  DATA_SYM                      /* SQL-2003-N */
805%token  <kwd>  DATETIME
806%token  <kwd>  DATE_FORMAT_SYM               /* MYSQL-FUNC */
807%token  <kwd>  DATE_SYM                      /* SQL-2003-R, Oracle-R, PLSQL-R */
808%token  <kwd>  DAY_SYM                       /* SQL-2003-R */
809%token  <kwd>  DEALLOCATE_SYM                /* SQL-2003-R */
810%token  <kwd>  DECODE_MARIADB_SYM            /* Function, non-reserved */
811%token  <kwd>  DECODE_ORACLE_SYM             /* Function, non-reserved */
812%token  <kwd>  DEFINER_SYM
813%token  <kwd>  DELAYED_SYM
814%token  <kwd>  DELAY_KEY_WRITE_SYM
815%token  <kwd>  DES_KEY_FILE
816%token  <kwd>  DIAGNOSTICS_SYM               /* SQL-2003-N */
817%token  <kwd>  DIRECTORY_SYM
818%token  <kwd>  DISABLE_SYM
819%token  <kwd>  DISCARD
820%token  <kwd>  DISK_SYM
821%token  <kwd>  DO_SYM
822%token  <kwd>  DUMPFILE
823%token  <kwd>  DUPLICATE_SYM
824%token  <kwd>  DYNAMIC_SYM                   /* SQL-2003-R */
825%token  <kwd>  ENABLE_SYM
826%token  <kwd>  END                           /* SQL-2003-R, PLSQL-R */
827%token  <kwd>  ENDS_SYM
828%token  <kwd>  ENGINES_SYM
829%token  <kwd>  ENGINE_SYM
830%token  <kwd>  ENUM
831%token  <kwd>  ERROR_SYM
832%token  <kwd>  ERRORS
833%token  <kwd>  ESCAPE_SYM                    /* SQL-2003-R */
834%token  <kwd>  EVENTS_SYM
835%token  <kwd>  EVENT_SYM
836%token  <kwd>  EVERY_SYM                     /* SQL-2003-N */
837%token  <kwd>  EXCHANGE_SYM
838%token  <kwd>  EXAMINED_SYM
839%token  <kwd>  EXCLUDE_SYM                   /* SQL-2011-N */
840%token  <kwd>  EXECUTE_SYM                   /* SQL-2003-R */
841%token  <kwd>  EXCEPTION_MARIADB_SYM         /* SQL-2003-N, PLSQL-R */
842%token  <kwd>  EXIT_MARIADB_SYM              /* PLSQL-R */
843%token  <kwd>  EXIT_ORACLE_SYM               /* PLSQL-R */
844%token  <kwd>  EXPANSION_SYM
845%token  <kwd>  EXPIRE_SYM                    /* MySQL */
846%token  <kwd>  EXPORT_SYM
847%token  <kwd>  EXTENDED_SYM
848%token  <kwd>  EXTENT_SIZE_SYM
849%token  <kwd>  FAST_SYM
850%token  <kwd>  FAULTS_SYM
851%token  <kwd>  FEDERATED_SYM                 /* MariaDB privilege */
852%token  <kwd>  FILE_SYM
853%token  <kwd>  FIRST_SYM                     /* SQL-2003-N */
854%token  <kwd>  FIXED_SYM
855%token  <kwd>  FLUSH_SYM
856%token  <kwd>  FOLLOWS_SYM                   /* MYSQL trigger*/
857%token  <kwd>  FOLLOWING_SYM                 /* SQL-2011-N */
858%token  <kwd>  FORCE_SYM
859%token  <kwd>  FORMAT_SYM
860%token  <kwd>  FOUND_SYM                     /* SQL-2003-R */
861%token  <kwd>  FULL                          /* SQL-2003-R */
862%token  <kwd>  FUNCTION_SYM                  /* SQL-2003-R, Oracle-R */
863%token  <kwd>  GENERAL
864%token  <kwd>  GENERATED_SYM
865%token  <kwd>  GET_FORMAT                    /* MYSQL-FUNC */
866%token  <kwd>  GET_SYM                       /* SQL-2003-R */
867%token  <kwd>  GLOBAL_SYM                    /* SQL-2003-R */
868%token  <kwd>  GRANTS
869%token  <kwd>  HANDLER_SYM
870%token  <kwd>  HARD_SYM
871%token  <kwd>  HASH_SYM
872%token  <kwd>  HELP_SYM
873%token  <kwd>  HIGH_PRIORITY
874%token  <kwd>  HISTORY_SYM                   /* MYSQL */
875%token  <kwd>  HOST_SYM
876%token  <kwd>  HOSTS_SYM
877%token  <kwd>  HOUR_SYM                      /* SQL-2003-R */
878%token  <kwd>  ID_SYM                        /* MYSQL */
879%token  <kwd>  IDENTIFIED_SYM
880%token  <kwd>  IGNORE_SERVER_IDS_SYM
881%token  <kwd>  IMMEDIATE_SYM                 /* SQL-2003-R */
882%token  <kwd>  IMPORT
883%token  <kwd>  INCREMENT_SYM
884%token  <kwd>  INDEXES
885%token  <kwd>  INITIAL_SIZE_SYM
886%token  <kwd>  INSERT_METHOD
887%token  <kwd>  INSTALL_SYM
888%token  <kwd>  INVOKER_SYM
889%token  <kwd>  IO_SYM
890%token  <kwd>  IPC_SYM
891%token  <kwd>  ISOLATION                     /* SQL-2003-R */
892%token  <kwd>  ISOPEN_SYM                    /* Oracle-N   */
893%token  <kwd>  ISSUER_SYM
894%token  <kwd>  INVISIBLE_SYM
895%token  <kwd>  JSON_SYM
896%token  <kwd>  KEY_BLOCK_SIZE
897%token  <kwd>  LANGUAGE_SYM                  /* SQL-2003-R */
898%token  <kwd>  LAST_SYM                      /* SQL-2003-N */
899%token  <kwd>  LAST_VALUE
900%token  <kwd>  LASTVAL_SYM                   /* PostgreSQL sequence function */
901%token  <kwd>  LEAVES
902%token  <kwd>  LESS_SYM
903%token  <kwd>  LEVEL_SYM
904%token  <kwd>  LIST_SYM
905%token  <kwd>  LOCAL_SYM                     /* SQL-2003-R */
906%token  <kwd>  LOCKS_SYM
907%token  <kwd>  LOGFILE_SYM
908%token  <kwd>  LOGS_SYM
909%token  <kwd>  MASTER_CONNECT_RETRY_SYM
910%token  <kwd>  MASTER_DELAY_SYM
911%token  <kwd>  MASTER_GTID_POS_SYM
912%token  <kwd>  MASTER_HOST_SYM
913%token  <kwd>  MASTER_LOG_FILE_SYM
914%token  <kwd>  MASTER_LOG_POS_SYM
915%token  <kwd>  MASTER_PASSWORD_SYM
916%token  <kwd>  MASTER_PORT_SYM
917%token  <kwd>  MASTER_SERVER_ID_SYM
918%token  <kwd>  MASTER_SSL_CAPATH_SYM
919%token  <kwd>  MASTER_SSL_CA_SYM
920%token  <kwd>  MASTER_SSL_CERT_SYM
921%token  <kwd>  MASTER_SSL_CIPHER_SYM
922%token  <kwd>  MASTER_SSL_CRL_SYM
923%token  <kwd>  MASTER_SSL_CRLPATH_SYM
924%token  <kwd>  MASTER_SSL_KEY_SYM
925%token  <kwd>  MASTER_SSL_SYM
926%token  <kwd>  MASTER_SYM
927%token  <kwd>  MASTER_USER_SYM
928%token  <kwd>  MASTER_USE_GTID_SYM
929%token  <kwd>  MASTER_HEARTBEAT_PERIOD_SYM
930%token  <kwd>  MAX_CONNECTIONS_PER_HOUR
931%token  <kwd>  MAX_QUERIES_PER_HOUR
932%token  <kwd>  MAX_ROWS
933%token  <kwd>  MAX_SIZE_SYM
934%token  <kwd>  MAX_UPDATES_PER_HOUR
935%token  <kwd>  MAX_STATEMENT_TIME_SYM
936%token  <kwd>  MAX_USER_CONNECTIONS_SYM
937%token  <kwd>  MEDIUM_SYM
938%token  <kwd>  MEMORY_SYM
939%token  <kwd>  MERGE_SYM                     /* SQL-2003-R */
940%token  <kwd>  MESSAGE_TEXT_SYM              /* SQL-2003-N */
941%token  <kwd>  MICROSECOND_SYM               /* MYSQL-FUNC */
942%token  <kwd>  MIGRATE_SYM
943%token  <kwd>  MINUTE_SYM                    /* SQL-2003-R */
944%token  <kwd>  MINVALUE_SYM
945%token  <kwd>  MIN_ROWS
946%token  <kwd>  MODE_SYM
947%token  <kwd>  MODIFY_SYM
948%token  <kwd>  MONITOR_SYM                   /* MariaDB privilege */
949%token  <kwd>  MONTH_SYM                     /* SQL-2003-R */
950%token  <kwd>  MUTEX_SYM
951%token  <kwd>  MYSQL_SYM
952%token  <kwd>  MYSQL_ERRNO_SYM
953%token  <kwd>  NAMES_SYM                     /* SQL-2003-N */
954%token  <kwd>  NAME_SYM                      /* SQL-2003-N */
955%token  <kwd>  NATIONAL_SYM                  /* SQL-2003-R */
956%token  <kwd>  NCHAR_SYM                     /* SQL-2003-R */
957%token  <kwd>  NEVER_SYM                     /* MySQL */
958%token  <kwd>  NEW_SYM                       /* SQL-2003-R */
959%token  <kwd>  NEXT_SYM                      /* SQL-2003-N */
960%token  <kwd>  NEXTVAL_SYM                   /* PostgreSQL sequence function */
961%token  <kwd>  NOCACHE_SYM
962%token  <kwd>  NOCYCLE_SYM
963%token  <kwd>  NODEGROUP_SYM
964%token  <kwd>  NONE_SYM                      /* SQL-2003-R */
965%token  <kwd>  NOTFOUND_SYM                  /* Oracle-R   */
966%token  <kwd>  NO_SYM                        /* SQL-2003-R */
967%token  <kwd>  NOMAXVALUE_SYM
968%token  <kwd>  NOMINVALUE_SYM
969%token  <kwd>  NO_WAIT_SYM
970%token  <kwd>  NOWAIT_SYM
971%token  <kwd>  NUMBER_MARIADB_SYM            /* SQL-2003-N  */
972%token  <kwd>  NUMBER_ORACLE_SYM             /* Oracle-R, PLSQL-R */
973%token  <kwd>  NVARCHAR_SYM
974%token  <kwd>  OF_SYM                        /* SQL-1992-R, Oracle-R */
975%token  <kwd>  OFFSET_SYM
976%token  <kwd>  OLD_PASSWORD_SYM
977%token  <kwd>  ONE_SYM
978%token  <kwd>  ONLY_SYM                      /* SQL-2003-R */
979%token  <kwd>  ONLINE_SYM
980%token  <kwd>  OPEN_SYM                      /* SQL-2003-R */
981%token  <kwd>  OPTIONS_SYM
982%token  <kwd>  OPTION                        /* SQL-2003-N */
983%token  <kwd>  OVERLAPS_SYM
984%token  <kwd>  OWNER_SYM
985%token  <kwd>  PACK_KEYS_SYM
986%token  <kwd>  PAGE_SYM
987%token  <kwd>  PARSER_SYM
988%token  <kwd>  PARTIAL                       /* SQL-2003-N */
989%token  <kwd>  PARTITIONS_SYM
990%token  <kwd>  PARTITIONING_SYM
991%token  <kwd>  PASSWORD_SYM
992%token  <kwd>  PERIOD_SYM                    /* SQL-2011-R */
993%token  <kwd>  PERSISTENT_SYM
994%token  <kwd>  PHASE_SYM
995%token  <kwd>  PLUGINS_SYM
996%token  <kwd>  PLUGIN_SYM
997%token  <kwd>  PORT_SYM
998%token  <kwd>  PRECEDES_SYM                  /* MYSQL */
999%token  <kwd>  PRECEDING_SYM                 /* SQL-2011-N */
1000%token  <kwd>  PREPARE_SYM                   /* SQL-2003-R */
1001%token  <kwd>  PRESERVE_SYM
1002%token  <kwd>  PREV_SYM
1003%token  <kwd>  PREVIOUS_SYM
1004%token  <kwd>  PRIVILEGES                    /* SQL-2003-N */
1005%token  <kwd>  PROCESS
1006%token  <kwd>  PROCESSLIST_SYM
1007%token  <kwd>  PROFILE_SYM
1008%token  <kwd>  PROFILES_SYM
1009%token  <kwd>  PROXY_SYM
1010%token  <kwd>  QUARTER_SYM
1011%token  <kwd>  QUERY_SYM
1012%token  <kwd>  QUICK
1013%token  <kwd>  RAW_MARIADB_SYM
1014%token  <kwd>  RAW_ORACLE_SYM                /* Oracle-R */
1015%token  <kwd>  READ_ONLY_SYM
1016%token  <kwd>  REBUILD_SYM
1017%token  <kwd>  RECOVER_SYM
1018%token  <kwd>  REDOFILE_SYM
1019%token  <kwd>  REDO_BUFFER_SIZE_SYM
1020%token  <kwd>  REDUNDANT_SYM
1021%token  <kwd>  RELAY
1022%token  <kwd>  RELAYLOG_SYM
1023%token  <kwd>  RELAY_LOG_FILE_SYM
1024%token  <kwd>  RELAY_LOG_POS_SYM
1025%token  <kwd>  RELAY_THREAD
1026%token  <kwd>  RELOAD
1027%token  <kwd>  REMOVE_SYM
1028%token  <kwd>  REORGANIZE_SYM
1029%token  <kwd>  REPAIR
1030%token  <kwd>  REPEATABLE_SYM                /* SQL-2003-N */
1031%token  <kwd>  REPLAY_SYM                    /* MariaDB privilege */
1032%token  <kwd>  REPLICATION
1033%token  <kwd>  RESET_SYM
1034%token  <kwd>  RESTART_SYM
1035%token  <kwd>  RESOURCES
1036%token  <kwd>  RESTORE_SYM
1037%token  <kwd>  RESUME_SYM
1038%token  <kwd>  RETURNED_SQLSTATE_SYM         /* SQL-2003-N */
1039%token  <kwd>  RETURNS_SYM                   /* SQL-2003-R */
1040%token  <kwd>  REUSE_SYM                     /* Oracle-R   */
1041%token  <kwd>  REVERSE_SYM
1042%token  <kwd>  ROLE_SYM
1043%token  <kwd>  ROLLBACK_SYM                  /* SQL-2003-R */
1044%token  <kwd>  ROLLUP_SYM                    /* SQL-2003-R */
1045%token  <kwd>  ROUTINE_SYM                   /* SQL-2003-N */
1046%token  <kwd>  ROWCOUNT_SYM                  /* Oracle-N   */
1047%token  <kwd>  ROW_SYM                       /* SQL-2003-R */
1048%token  <kwd>  ROW_COUNT_SYM                 /* SQL-2003-N */
1049%token  <kwd>  ROW_FORMAT_SYM
1050%token  <kwd>  RTREE_SYM
1051%token  <kwd>  SAVEPOINT_SYM                 /* SQL-2003-R */
1052%token  <kwd>  SCHEDULE_SYM
1053%token  <kwd>  SCHEMA_NAME_SYM               /* SQL-2003-N */
1054%token  <kwd>  SECOND_SYM                    /* SQL-2003-R */
1055%token  <kwd>  SECURITY_SYM                  /* SQL-2003-N */
1056%token  <kwd>  SEQUENCE_SYM
1057%token  <kwd>  SERIALIZABLE_SYM              /* SQL-2003-N */
1058%token  <kwd>  SERIAL_SYM
1059%token  <kwd>  SESSION_SYM                   /* SQL-2003-N */
1060%token  <kwd>  SERVER_SYM
1061%token  <kwd>  SETVAL_SYM                    /* PostgreSQL sequence function */
1062%token  <kwd>  SHARE_SYM
1063%token  <kwd>  SHUTDOWN
1064%token  <kwd>  SIGNED_SYM
1065%token  <kwd>  SIMPLE_SYM                    /* SQL-2003-N */
1066%token  <kwd>  SLAVE
1067%token  <kwd>  SLAVES
1068%token  <kwd>  SLAVE_POS_SYM
1069%token  <kwd>  SLOW
1070%token  <kwd>  SNAPSHOT_SYM
1071%token  <kwd>  SOCKET_SYM
1072%token  <kwd>  SOFT_SYM
1073%token  <kwd>  SONAME_SYM
1074%token  <kwd>  SOUNDS_SYM
1075%token  <kwd>  SOURCE_SYM
1076%token  <kwd>  SQL_BUFFER_RESULT
1077%token  <kwd>  SQL_CACHE_SYM
1078%token  <kwd>  SQL_CALC_FOUND_ROWS
1079%token  <kwd>  SQL_NO_CACHE_SYM
1080%token  <kwd>  SQL_THREAD
1081%token  <kwd>  STAGE_SYM
1082%token  <kwd>  STARTS_SYM
1083%token  <kwd>  START_SYM                     /* SQL-2003-R */
1084%token  <kwd>  STATEMENT_SYM
1085%token  <kwd>  STATUS_SYM
1086%token  <kwd>  STOP_SYM
1087%token  <kwd>  STORAGE_SYM
1088%token  <kwd>  STORED_SYM
1089%token  <kwd>  STRING_SYM
1090%token  <kwd>  SUBCLASS_ORIGIN_SYM           /* SQL-2003-N */
1091%token  <kwd>  SUBDATE_SYM
1092%token  <kwd>  SUBJECT_SYM
1093%token  <kwd>  SUBPARTITIONS_SYM
1094%token  <kwd>  SUBPARTITION_SYM
1095%token  <kwd>  SUPER_SYM
1096%token  <kwd>  SUSPEND_SYM
1097%token  <kwd>  SWAPS_SYM
1098%token  <kwd>  SWITCHES_SYM
1099%token  <kwd>  SYSTEM                        /* SQL-2011-R */
1100%token  <kwd>  SYSTEM_TIME_SYM               /* SQL-2011-R */
1101%token  <kwd>  TABLES
1102%token  <kwd>  TABLESPACE
1103%token  <kwd>  TABLE_CHECKSUM_SYM
1104%token  <kwd>  TABLE_NAME_SYM                /* SQL-2003-N */
1105%token  <kwd>  TEMPORARY                     /* SQL-2003-N */
1106%token  <kwd>  TEMPTABLE_SYM
1107%token  <kwd>  TEXT_SYM
1108%token  <kwd>  THAN_SYM
1109%token  <kwd>  TIES_SYM                      /* SQL-2011-N */
1110%token  <kwd>  TIMESTAMP                     /* SQL-2003-R */
1111%token  <kwd>  TIMESTAMP_ADD
1112%token  <kwd>  TIMESTAMP_DIFF
1113%token  <kwd>  TIME_SYM                      /* SQL-2003-R, Oracle-R */
1114%token  <kwd>  TRANSACTION_SYM
1115%token  <kwd>  TRANSACTIONAL_SYM
1116%token  <kwd>  THREADS_SYM
1117%token  <kwd>  TRIGGERS_SYM
1118%token  <kwd>  TRIM_ORACLE
1119%token  <kwd>  TRUNCATE_SYM
1120%token  <kwd>  TYPES_SYM
1121%token  <kwd>  TYPE_SYM                      /* SQL-2003-N */
1122%token  <kwd>  UDF_RETURNS_SYM
1123%token  <kwd>  UNBOUNDED_SYM                 /* SQL-2011-N */
1124%token  <kwd>  UNCOMMITTED_SYM               /* SQL-2003-N */
1125%token  <kwd>  UNDEFINED_SYM
1126%token  <kwd>  UNDOFILE_SYM
1127%token  <kwd>  UNDO_BUFFER_SIZE_SYM
1128%token  <kwd>  UNICODE_SYM
1129%token  <kwd>  UNINSTALL_SYM
1130%token  <kwd>  UNKNOWN_SYM                   /* SQL-2003-R */
1131%token  <kwd>  UNTIL_SYM
1132%token  <kwd>  UPGRADE_SYM
1133%token  <kwd>  USER_SYM                      /* SQL-2003-R */
1134%token  <kwd>  USE_FRM
1135%token  <kwd>  VALUE_SYM                     /* SQL-2003-R */
1136%token  <kwd>  VARCHAR2_MARIADB_SYM
1137%token  <kwd>  VARCHAR2_ORACLE_SYM           /* Oracle-R, PLSQL-R */
1138%token  <kwd>  VARIABLES
1139%token  <kwd>  VERSIONING_SYM                /* SQL-2011-R */
1140%token  <kwd>  VIA_SYM
1141%token  <kwd>  VIEW_SYM                      /* SQL-2003-N */
1142%token  <kwd>  VISIBLE_SYM                   /* MySQL 8.0 */
1143%token  <kwd>  VIRTUAL_SYM
1144%token  <kwd>  WAIT_SYM
1145%token  <kwd>  WARNINGS
1146%token  <kwd>  WEEK_SYM
1147%token  <kwd>  WEIGHT_STRING_SYM
1148%token  <kwd>  WINDOW_SYM                    /* SQL-2003-R */
1149%token  <kwd>  WITHIN
1150%token  <kwd>  WITHOUT                       /* SQL-2003-R */
1151%token  <kwd>  WORK_SYM                      /* SQL-2003-N */
1152%token  <kwd>  WRAPPER_SYM
1153%token  <kwd>  WRITE_SYM                     /* SQL-2003-N */
1154%token  <kwd>  X509_SYM
1155%token  <kwd>  XA_SYM
1156%token  <kwd>  XML_SYM
1157%token  <kwd>  YEAR_SYM                      /* SQL-2003-R */
1158
1159/* A dummy token to force the priority of table_ref production in a join. */
1160%left   CONDITIONLESS_JOIN
1161%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT ON_SYM USING
1162
1163%left   SET_VAR
1164%left   OR_SYM OR2_SYM
1165%left   XOR
1166%left   AND_SYM AND_AND_SYM
1167
1168%left   PREC_BELOW_NOT
1169
1170%nonassoc NOT_SYM
1171%left   '=' EQUAL_SYM GE '>' LE '<' NE
1172%nonassoc IS
1173%right BETWEEN_SYM
1174%left   LIKE SOUNDS_SYM REGEXP IN_SYM
1175%left   '|'
1176%left   '&'
1177%left   SHIFT_LEFT SHIFT_RIGHT
1178%left   '-' '+' ORACLE_CONCAT_SYM
1179%left   '*' '/' '%' DIV_SYM MOD_SYM
1180%left   '^'
1181%left   MYSQL_CONCAT_SYM
1182%nonassoc NEG '~' NOT2_SYM BINARY
1183%nonassoc COLLATE_SYM
1184%nonassoc SUBQUERY_AS_EXPR
1185
1186/*
1187  Tokens that can change their meaning from identifier to something else
1188  in certain context.
1189
1190  - TRANSACTION: identifier, history unit:
1191      SELECT transaction FROM t1;
1192      SELECT * FROM t1 FOR SYSTEM_TIME AS OF TRANSACTION @var;
1193
1194  - TIMESTAMP: identifier, literal, history unit:
1195      SELECT timestamp FROM t1;
1196      SELECT TIMESTAMP '2001-01-01 10:20:30';
1197      SELECT * FROM t1 FOR SYSTEM_TIME AS OF TIMESTAMP CONCAT(@date,' ',@time);
1198
1199  - PERIOD: identifier, period for system time:
1200      SELECT period FROM t1;
1201      ALTER TABLE DROP PERIOD FOR SYSTEM TIME;
1202
1203  - SYSTEM: identifier, system versioning:
1204      SELECT system FROM t1;
1205      ALTER TABLE DROP SYSTEM VERSIONIONG;
1206
1207  - USER: identifier, user:
1208      SELECT user FROM t1;
1209      KILL USER foo;
1210
1211   Note, we need here only tokens that cause shift/reduce conflicts
1212   with keyword identifiers. For example:
1213      opt_clause1: %empty | KEYWORD ... ;
1214      clause2: opt_clause1 ident;
1215   KEYWORD can appear both in opt_clause1 and in "ident" through the "keyword"
1216   rule. So the parser reports a conflict on how to interpret KEYWORD:
1217     - as a start of non-empty branch in opt_clause1, or
1218     - as an identifier which follows the empty branch in opt_clause1.
1219
1220   Example#1:
1221     alter_list_item:
1222       DROP opt_column opt_if_exists_table_element field_ident
1223     | DROP SYSTEM VERSIONING_SYM
1224   SYSTEM can be a keyword in field_ident, or can be a start of
1225   SYSTEM VERSIONING.
1226
1227   Example#2:
1228     system_time_expr: AS OF_SYM history_point
1229     history_point: opt_history_unit bit_expr
1230     opt_history_unit: | TRANSACTION_SYM
1231   TRANSACTION can be a non-empty history unit, or can be an identifier
1232   in bit_expr.
1233
1234   In the grammar below we use %prec to explicitely tell Bison to go
1235   through the empty branch in the optional rule only when the lookahead
1236   token does not belong to a small set of selected tokens.
1237
1238   Tokens NEXT_SYM and PREVIOUS_SYM also change their meaning from
1239   identifiers to sequence operations when followed by VALUE_SYM:
1240      SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1241   but we don't need to list them here as they do not seem to cause
1242   conflicts (according to bison -v), as both meanings
1243   (as identifier, and as a sequence operation) are parts of the same target
1244   column_default_non_parenthesized_expr, and there are no any optional
1245   clauses between the start of column_default_non_parenthesized_expr
1246   and until NEXT_SYM / PREVIOUS_SYM.
1247*/
1248%left   PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
1249%left   TRANSACTION_SYM TIMESTAMP PERIOD_SYM SYSTEM USER COMMENT_SYM
1250
1251
1252/*
1253  Tokens that can appear in a token contraction on the second place
1254  and change the meaning of the previous token.
1255
1256  - TEXT_STRING: changes the meaning of TIMESTAMP/TIME/DATE
1257    from identifier to literal:
1258      SELECT timestamp FROM t1;
1259      SELECT TIMESTAMP'2001-01-01 00:00:00' FROM t1;
1260
1261  - Parenthesis: changes the meaning of TIMESTAMP/TIME/DATE
1262    from identifiers to CAST-alike functions:
1263      SELECT timestamp FROM t1;
1264      SELECT timestamp(1) FROM t1;
1265
1266  - VALUE: changes NEXT and PREVIOUS from identifier to sequence operation:
1267      SELECT next, previous FROM t1;
1268      SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1269
1270  - VERSIONING: changes SYSTEM from identifier to SYSTEM VERSIONING
1271      SELECT system FROM t1;
1272      ALTER TABLE t1 ADD SYSTEM VERSIONING;
1273*/
1274%left   PREC_BELOW_CONTRACTION_TOKEN2
1275%left   TEXT_STRING '(' ')' VALUE_SYM VERSIONING_SYM
1276%left EMPTY_FROM_CLAUSE
1277%right INTO
1278
1279%type <lex_str>
1280        DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
1281        HEX_NUM HEX_STRING
1282        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident_or_text
1283        TEXT_STRING_sys TEXT_STRING_literal
1284        key_cache_name
1285        sp_opt_label BIN_NUM TEXT_STRING_filesystem
1286        opt_constraint constraint opt_ident
1287        sp_block_label sp_control_label opt_place opt_db
1288
1289%type <ident_sys>
1290        IDENT_sys
1291        ident
1292        label_ident
1293        sp_decl_ident
1294        ident_or_empty
1295        ident_table_alias
1296        ident_sysvar_name
1297        ident_for_loop_index
1298
1299%type <lex_string_with_metadata>
1300        TEXT_STRING
1301        NCHAR_STRING
1302
1303%type <lex_str_ptr>
1304        opt_table_alias_clause
1305        table_alias_clause
1306
1307%type <ident_cli>
1308        IDENT
1309        IDENT_QUOTED
1310        IDENT_cli
1311        ident_cli
1312        ident_cli_set_usual_case
1313
1314%type <ident_sys_ptr>
1315        ident_sys_alloc
1316
1317%type <kwd>
1318        keyword_data_type
1319        keyword_cast_type
1320        keyword_ident
1321        keyword_label
1322        keyword_set_special_case
1323        keyword_set_usual_case
1324        keyword_sp_block_section
1325        keyword_sp_decl
1326        keyword_sp_head
1327        keyword_sp_var_and_label
1328        keyword_sp_var_not_label
1329        keyword_sysvar_name
1330        keyword_sysvar_type
1331        keyword_table_alias
1332        keyword_verb_clause
1333        charset
1334        reserved_keyword_udt
1335        reserved_keyword_udt_not_param_type
1336        non_reserved_keyword_udt
1337
1338%type <table>
1339        table_ident table_ident_nodb references xid
1340        table_ident_opt_wild create_like
1341
1342%type <qualified_column_ident>
1343        optionally_qualified_column_ident
1344
1345%type <simple_string>
1346        remember_name remember_end
1347        remember_tok_start
1348        wild_and_where
1349
1350%type <const_simple_string>
1351        field_length opt_field_length
1352        opt_compression_method
1353
1354%type <string>
1355        text_string hex_or_bin_String opt_gconcat_separator
1356
1357%type <type_handler> int_type real_type
1358
1359%type <sp_handler> sp_handler
1360
1361%type <Lex_field_type> field_type field_type_all
1362        qualified_field_type
1363        field_type_numeric
1364        field_type_string
1365        field_type_lob
1366        field_type_temporal
1367        field_type_misc
1368
1369%type <Lex_dyncol_type> opt_dyncol_type dyncol_type
1370        numeric_dyncol_type temporal_dyncol_type string_dyncol_type
1371
1372%type <column_list_privilege>
1373        column_list_privilege
1374
1375%type <create_field> field_spec column_def
1376
1377%type <num>
1378        order_dir lock_option
1379        udf_type opt_local opt_no_write_to_binlog
1380        opt_temporary all_or_any opt_distinct opt_glimit_clause
1381        opt_ignore_leaves fulltext_options union_option
1382        opt_not
1383        transaction_access_mode_types
1384        opt_natural_language_mode opt_query_expansion
1385        opt_ev_status opt_ev_on_completion ev_on_completion opt_ev_comment
1386        ev_alter_on_schedule_completion opt_ev_rename_to opt_ev_sql_stmt
1387        optional_flush_tables_arguments
1388        opt_time_precision kill_type kill_option int_num
1389        opt_default_time_precision
1390        case_stmt_body opt_bin_mod opt_for_system_time_clause
1391        opt_if_exists_table_element opt_if_not_exists_table_element
1392        opt_recursive opt_format_xid opt_for_portion_of_time_clause
1393
1394%type <object_ddl_options>
1395        create_or_replace
1396        opt_if_not_exists
1397        opt_if_exists
1398
1399/*
1400  Bit field of MYSQL_START_TRANS_OPT_* flags.
1401*/
1402%type <num> opt_start_transaction_option_list
1403%type <num> start_transaction_option_list
1404%type <num> start_transaction_option
1405
1406%type <m_yes_no_unk>
1407        opt_chain opt_release
1408
1409%type <m_fk_option>
1410        delete_option
1411
1412%type <privilege>
1413        column_privilege
1414        object_privilege
1415        opt_grant_options
1416        opt_grant_option
1417        grant_option_list
1418        grant_option
1419
1420%type <lex_grant>
1421        object_privilege_list
1422        grant_privileges
1423
1424%type <lex_grant_ident>
1425        grant_ident
1426
1427%type <ulong_num>
1428        ulong_num real_ulong_num merge_insert_types
1429        ws_nweights
1430        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
1431        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
1432        ws_level_range ws_level_list_or_range bool
1433        field_options last_field_options
1434
1435%type <ulonglong_number>
1436        ulonglong_num real_ulonglong_num size_number
1437
1438%type <longlong_number>
1439        longlong_num
1440
1441%type <choice> choice
1442
1443%type <lock_type>
1444        replace_lock_option opt_low_priority insert_lock_option load_data_lock
1445        insert_replace_option
1446
1447%type <item>
1448        literal insert_ident order_ident temporal_literal
1449        simple_ident expr sum_expr in_sum_expr
1450        variable variable_aux
1451        predicate bit_expr parenthesized_expr
1452        table_wild simple_expr column_default_non_parenthesized_expr udf_expr
1453        primary_expr string_factor_expr mysql_concatenation_expr
1454        select_sublist_qualified_asterisk
1455        expr_or_ignore expr_or_ignore_or_default set_expr_or_default
1456        signed_literal expr_or_literal
1457        sp_opt_default
1458        simple_ident_nospvar
1459        field_or_var limit_option
1460        part_func_expr
1461        window_func_expr
1462        window_func
1463        simple_window_func
1464        inverse_distribution_function
1465        percentile_function
1466        inverse_distribution_function_def
1467        explicit_cursor_attr
1468        function_call_keyword
1469        function_call_keyword_timestamp
1470        function_call_nonkeyword
1471        function_call_generic
1472        function_call_conflict kill_expr
1473        signal_allowed_expr
1474        simple_target_specification
1475        condition_number
1476        opt_versioning_interval_start
1477
1478%type <item_param> param_marker
1479
1480%type <item_num>
1481        NUM_literal
1482
1483%type <item_basic_constant> text_literal
1484
1485%type <item_list>
1486        expr_list opt_udf_expr_list udf_expr_list when_list when_list_opt_else
1487        ident_list ident_list_arg opt_expr_list
1488        decode_when_list_oracle
1489        execute_using
1490        execute_params
1491
1492%type <sp_cursor_stmt>
1493        sp_cursor_stmt_lex
1494        sp_cursor_stmt
1495
1496%type <expr_lex>
1497        expr_lex
1498
1499%type <assignment_lex>
1500        assignment_source_lex
1501        assignment_source_expr
1502        for_loop_bound_expr
1503
1504%type <sp_assignment_lex_list>
1505        cursor_actual_parameters
1506        opt_parenthesized_cursor_actual_parameters
1507
1508%type <var_type>
1509        option_type opt_var_type opt_var_ident_type
1510
1511%type <key_type>
1512        constraint_key_type fulltext spatial
1513
1514%type <key_alg>
1515        btree_or_rtree opt_key_algorithm_clause opt_USING_key_algorithm
1516
1517%type <string_list>
1518        using_list opt_use_partition use_partition
1519
1520%type <key_part>
1521        key_part
1522
1523%type <table_list>
1524        join_table_list  join_table
1525        table_factor table_ref esc_table_ref
1526        table_primary_ident table_primary_ident_opt_parens
1527        table_primary_derived table_primary_derived_opt_parens
1528        derived_table_list table_reference_list_parens
1529        nested_table_reference_list join_table_parens
1530        update_table_list
1531%type <date_time_type> date_time_type;
1532%type <interval> interval
1533
1534%type <interval_time_st> interval_time_stamp
1535
1536%type <db_type> storage_engines known_storage_engines
1537
1538%type <row_type> row_types
1539
1540%type <tx_isolation> isolation_types
1541
1542%type <ha_rkey_mode> handler_rkey_mode
1543
1544%type <Lex_cast_type> cast_type cast_type_numeric cast_type_temporal
1545
1546%type <Lex_length_and_dec> precision opt_precision float_options
1547
1548%type <lex_user> user grant_user grant_role user_or_role current_role
1549                 admin_option_for_role user_maybe_role
1550
1551%type <user_auth> opt_auth_str auth_expression auth_token
1552                  text_or_password
1553
1554%type <charset>
1555        opt_collate
1556        charset_name
1557        charset_or_alias
1558        charset_name_or_default
1559        old_or_new_charset_name
1560        old_or_new_charset_name_or_default
1561        collation_name
1562        collation_name_or_default
1563        opt_load_data_charset
1564        UNDERSCORE_CHARSET
1565
1566%type <select_lex> subselect
1567        query_specification
1568        table_value_constructor
1569        simple_table
1570        query_simple
1571        query_primary
1572        subquery
1573        select_into_query_specification
1574
1575%type <select_lex_unit>
1576        query_expression
1577        query_expression_no_with_clause
1578        query_expression_body_ext
1579        query_expression_body_ext_parens
1580        query_expression_body
1581        query_specification_start
1582
1583%type <boolfunc2creator> comp_op
1584
1585%type <dyncol_def> dyncall_create_element
1586
1587%type <dyncol_def_list> dyncall_create_list
1588
1589%type <myvar> select_outvar
1590
1591%type <virtual_column> opt_check_constraint check_constraint virtual_column_func
1592        column_default_expr
1593
1594%type <unit_operation> unit_type_decl
1595
1596%type <select_lock>
1597        opt_procedure_or_into
1598        opt_select_lock_type
1599        select_lock_type
1600        opt_lock_wait_timeout_new
1601
1602%type <select_limit> opt_limit_clause limit_clause limit_options
1603
1604%type <order_limit_lock>
1605        query_expression_tail
1606        opt_query_expression_tail
1607        order_or_limit
1608        order_limit_lock
1609        opt_order_limit_lock
1610
1611%type <select_order> opt_order_clause order_clause order_list
1612
1613%type <NONE>
1614        directly_executable_statement
1615        analyze_stmt_command backup backup_statements
1616        query verb_clause create create_routine change select select_into
1617        do drop drop_routine insert replace insert_start stmt_end
1618        insert_values update delete truncate rename compound_statement
1619        show describe load alter optimize keycache preload flush
1620        reset purge begin_stmt_mariadb commit rollback savepoint release
1621        slave master_def master_defs master_file_def slave_until_opts
1622        repair analyze opt_with_admin opt_with_admin_option
1623        analyze_table_list analyze_table_elem_spec
1624        opt_persistent_stat_clause persistent_stat_spec
1625        persistent_column_stat_spec persistent_index_stat_spec
1626        table_column_list table_index_list table_index_name
1627        check start checksum opt_returning
1628        field_list field_list_item kill key_def constraint_def
1629        keycache_list keycache_list_or_parts assign_to_keycache
1630        assign_to_keycache_parts
1631        preload_list preload_list_or_parts preload_keys preload_keys_parts
1632        select_item_list select_item values_list no_braces
1633        delete_limit_clause fields opt_values values
1634        no_braces_with_names opt_values_with_names values_with_names
1635        procedure_list procedure_list2 procedure_item
1636        field_def handler opt_generated_always
1637        opt_ignore opt_column opt_restrict
1638        grant revoke set lock unlock string_list
1639        opt_binary table_lock_list table_lock
1640        ref_list opt_match_clause opt_on_update_delete use
1641        opt_delete_options opt_delete_option varchar nchar nvarchar
1642        opt_outer table_list table_name table_alias_ref_list table_alias_ref
1643        attribute attribute_list
1644        compressed_deprecated_data_type_attribute
1645        compressed_deprecated_column_attribute
1646        grant_list
1647        user_list user_and_role_list
1648        rename_list table_or_tables
1649        clear_privileges flush_options flush_option
1650        opt_flush_lock flush_lock flush_options_list
1651        equal optional_braces
1652        opt_mi_check_type opt_to mi_check_types
1653        table_to_table_list table_to_table opt_table_list opt_as
1654        handler_rkey_function handler_read_or_scan
1655        single_multi table_wild_list table_wild_one opt_wild
1656        opt_and
1657        select_var_list select_var_list_init help
1658        opt_extended_describe shutdown
1659        opt_format_json
1660        prepare execute deallocate
1661        statement
1662        sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic xa
1663        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1664        view_list_opt view_list view_select
1665        trigger_tail event_tail
1666        install uninstall partition_entry binlog_base64_event
1667        normal_key_options normal_key_opts all_key_opt
1668        spatial_key_options fulltext_key_options normal_key_opt
1669        fulltext_key_opt spatial_key_opt fulltext_key_opts spatial_key_opts
1670	keep_gcc_happy
1671        key_using_alg
1672        part_column_list
1673        period_for_system_time
1674        period_for_application_time
1675        server_def server_options_list server_option
1676        definer_opt no_definer definer get_diagnostics
1677        parse_vcol_expr vcol_opt_specifier vcol_opt_attribute
1678        vcol_opt_attribute_list vcol_attribute
1679        opt_serial_attribute opt_serial_attribute_list serial_attribute
1680        explainable_command
1681        opt_lock_wait_timeout
1682        opt_delete_gtid_domain
1683        asrow_attribute
1684        opt_constraint_no_id
1685
1686%type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt
1687%type <NONE> sp_if_then_statements sp_case_then_statements
1688%type <NONE> sp_proc_stmt_statement sp_proc_stmt_return
1689%type <NONE> sp_proc_stmt_compound_ok
1690%type <NONE> sp_proc_stmt_if
1691%type <NONE> sp_labeled_control sp_unlabeled_control
1692%type <NONE> sp_labeled_block sp_unlabeled_block
1693%type <NONE> sp_proc_stmt_continue_oracle
1694%type <NONE> sp_proc_stmt_exit_oracle
1695%type <NONE> sp_proc_stmt_leave
1696%type <NONE> sp_proc_stmt_iterate
1697%type <NONE> sp_proc_stmt_goto_oracle
1698%type <NONE> sp_proc_stmt_with_cursor
1699%type <NONE> sp_proc_stmt_open sp_proc_stmt_fetch sp_proc_stmt_close
1700%type <NONE> case_stmt_specification
1701%type <NONE> loop_body while_body repeat_body
1702%type <NONE> for_loop_statements
1703
1704%type <num> view_algorithm view_check_option
1705%type <view_suid> view_suid opt_view_suid
1706
1707%type <plsql_cursor_attr> plsql_cursor_attr
1708%type <sp_suid> sp_suid
1709%type <sp_aggregate_type> opt_aggregate
1710
1711%type <num> sp_decl_idents sp_decl_idents_init_vars
1712%type <num> sp_handler_type sp_hcond_list
1713%type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value
1714%type <spname> sp_name
1715%type <spvar> sp_param_name sp_param_name_and_type
1716%type <spvar> sp_param_name_and_type_anchored
1717%type <for_loop> sp_for_loop_index_and_bounds
1718%type <for_loop_bounds> sp_for_loop_bounds
1719%type <trim> trim_operands
1720%type <num> opt_sp_for_loop_direction
1721%type <spvar_mode> sp_parameter_type
1722%type <index_hint> index_hint_type
1723%type <num> index_hint_clause normal_join inner_join
1724%type <filetype> data_or_xml
1725
1726%type <NONE> signal_stmt resignal_stmt raise_stmt_oracle
1727%type <diag_condition_item_name> signal_condition_information_item_name
1728
1729%type <trg_execution_order> trigger_follows_precedes_clause;
1730%type <trigger_action_order_type> trigger_action_order;
1731
1732%type <diag_area> which_area;
1733%type <diag_info> diagnostics_information;
1734%type <stmt_info_item> statement_information_item;
1735%type <stmt_info_item_name> statement_information_item_name;
1736%type <stmt_info_list> statement_information;
1737%type <cond_info_item> condition_information_item;
1738%type <cond_info_item_name> condition_information_item_name;
1739%type <cond_info_list> condition_information;
1740
1741%type <spvar_definition> row_field_name row_field_definition
1742%type <spvar_definition_list> row_field_definition_list row_type_body
1743
1744%type <NONE> opt_window_clause window_def_list window_def window_spec
1745%type <lex_str_ptr> window_name
1746%type <NONE> opt_window_ref opt_window_frame_clause
1747%type <frame_units> window_frame_units;
1748%type <NONE> window_frame_extent;
1749%type <frame_exclusion> opt_window_frame_exclusion;
1750%type <window_frame_bound> window_frame_start window_frame_bound;
1751
1752%type <kwd>
1753        '-' '+' '*' '/' '%' '(' ')'
1754        ',' '!' '{' '}' '&' '|'
1755
1756%type <with_clause> with_clause
1757
1758%type <with_element_head> with_element_head
1759
1760%type <ident_sys_list>
1761        comma_separated_ident_list
1762        opt_with_column_list
1763        with_column_list
1764        opt_cycle
1765
1766%type <vers_range_unit> opt_history_unit
1767%type <vers_history_point> history_point
1768%type <vers_column_versioning> with_or_without_system
1769
1770%ifdef MARIADB
1771%type <NONE> sp_tail_standalone
1772%type <NONE> sp_unlabeled_block_not_atomic
1773%type <NONE> sp_proc_stmt_in_returns_clause
1774%type <lex_str> sp_label
1775%type <spblock> sp_decl_handler
1776%type <spblock> sp_decls
1777%type <spblock> sp_decl
1778%type <spblock> sp_decl_body
1779%type <spblock> sp_decl_variable_list
1780%type <spblock> sp_decl_variable_list_anchored
1781%type <kwd> reserved_keyword_udt_param_type
1782%else
1783%type <NONE> set_assign
1784%type <spvar_mode> sp_opt_inout
1785%type <NONE> sp_tail_standalone
1786%type <NONE> sp_labelable_stmt
1787%type <simple_string> remember_end_opt
1788%type <lex_str> opt_package_routine_end_name
1789%type <lex_str> label_declaration_oracle
1790%type <lex_str> labels_declaration_oracle
1791%type <kwd> keyword_directly_assignable
1792%type <ident_sys> ident_directly_assignable
1793%type <ident_cli> ident_cli_directly_assignable
1794%type <spname> opt_sp_name
1795%type <spblock> sp_decl_body_list
1796%type <spblock> opt_sp_decl_body_list
1797%type <spblock> sp_decl_variable_list
1798%type <spblock> sp_decl_variable_list_anchored
1799%type <spblock> sp_decl_non_handler
1800%type <spblock> sp_decl_non_handler_list
1801%type <spblock> sp_decl_handler
1802%type <spblock> sp_decl_handler_list
1803%type <spblock> opt_sp_decl_handler_list
1804%type <spblock> package_implementation_routine_definition
1805%type <spblock> package_implementation_item_declaration
1806%type <spblock> package_implementation_declare_section
1807%type <spblock> package_implementation_declare_section_list1
1808%type <spblock> package_implementation_declare_section_list2
1809%type <spblock_handlers> sp_block_statements_and_exceptions
1810%type <spblock_handlers> package_implementation_executable_section
1811%type <sp_instr_addr> sp_instr_addr
1812%type <num> opt_exception_clause exception_handlers
1813%type <lex> remember_lex
1814%type <lex> package_routine_lex
1815%type <lex> package_specification_function
1816%type <lex> package_specification_procedure
1817%endif ORACLE
1818
1819%%
1820
1821
1822/*
1823  Indentation of grammar rules:
1824
1825rule: <-- starts at col 1
1826          rule1a rule1b rule1c <-- starts at col 11
1827          { <-- starts at col 11
1828            code <-- starts at col 13, indentation is 2 spaces
1829          }
1830        | rule2a rule2b
1831          {
1832            code
1833          }
1834        ; <-- on a line by itself, starts at col 9
1835
1836  Also, please do not use any <TAB>, but spaces.
1837  Having a uniform indentation in this file helps
1838  code reviews, patches, merges, and make maintenance easier.
1839  Tip: grep [[:cntrl:]] sql_yacc.yy
1840  Thanks.
1841*/
1842
1843query:
1844          END_OF_INPUT
1845          {
1846            if (!thd->bootstrap &&
1847              (!(thd->lex->lex_options & OPTION_LEX_FOUND_COMMENT)))
1848              my_yyabort_error((ER_EMPTY_QUERY, MYF(0)));
1849
1850            thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
1851            YYLIP->found_semicolon= NULL;
1852          }
1853        | directly_executable_statement
1854          {
1855            Lex_input_stream *lip = YYLIP;
1856
1857            if ((thd->client_capabilities & CLIENT_MULTI_QUERIES) &&
1858                lip->multi_statements &&
1859                ! lip->eof())
1860            {
1861              /*
1862                We found a well formed query, and multi queries are allowed:
1863                - force the parser to stop after the ';'
1864                - mark the start of the next query for the next invocation
1865                  of the parser.
1866              */
1867              lip->next_state= MY_LEX_END;
1868              lip->found_semicolon= lip->get_ptr();
1869            }
1870            else
1871            {
1872              /* Single query, terminated. */
1873              lip->found_semicolon= NULL;
1874            }
1875          }
1876          ';'
1877          opt_end_of_input
1878        | directly_executable_statement END_OF_INPUT
1879          {
1880            /* Single query, not terminated. */
1881            YYLIP->found_semicolon= NULL;
1882          }
1883        ;
1884
1885opt_end_of_input:
1886          /* empty */
1887        | END_OF_INPUT
1888        ;
1889
1890directly_executable_statement:
1891          statement
1892        | begin_stmt_mariadb
1893        | compound_statement
1894        ;
1895
1896/* Verb clauses, except begin and compound_statement */
1897verb_clause:
1898          alter
1899        | analyze
1900        | analyze_stmt_command
1901        | backup
1902        | binlog_base64_event
1903        | call
1904        | change
1905        | check
1906        | checksum
1907        | commit
1908        | create
1909        | deallocate
1910        | delete
1911        | describe
1912        | do
1913        | drop
1914        | execute
1915        | flush
1916        | get_diagnostics
1917        | grant
1918        | handler
1919        | help
1920        | insert
1921        | install
1922	| keep_gcc_happy
1923        | keycache
1924        | kill
1925        | load
1926        | lock
1927        | optimize
1928        | parse_vcol_expr
1929        | partition_entry
1930        | preload
1931        | prepare
1932        | purge
1933        | raise_stmt_oracle
1934        | release
1935        | rename
1936        | repair
1937        | replace
1938        | reset
1939        | resignal_stmt
1940        | revoke
1941        | rollback
1942        | savepoint
1943        | select
1944        | select_into
1945        | set
1946        | signal_stmt
1947        | show
1948        | shutdown
1949        | slave
1950        | start
1951        | truncate
1952        | uninstall
1953        | unlock
1954        | update
1955        | use
1956        | xa
1957        ;
1958
1959deallocate:
1960          deallocate_or_drop PREPARE_SYM ident
1961          {
1962            Lex->stmt_deallocate_prepare($3);
1963          }
1964        ;
1965
1966deallocate_or_drop:
1967          DEALLOCATE_SYM
1968        | DROP
1969        ;
1970
1971prepare:
1972          PREPARE_SYM ident FROM
1973          { Lex->clause_that_disallows_subselect= "PREPARE..FROM"; }
1974          expr
1975          {
1976            Lex->clause_that_disallows_subselect= NULL;
1977            if (Lex->stmt_prepare($2, $5))
1978              MYSQL_YYABORT;
1979          }
1980        ;
1981
1982execute:
1983          EXECUTE_SYM ident execute_using
1984          {
1985            if (Lex->stmt_execute($2, $3))
1986              MYSQL_YYABORT;
1987          }
1988        | EXECUTE_SYM IMMEDIATE_SYM
1989          { Lex->clause_that_disallows_subselect= "EXECUTE IMMEDIATE"; }
1990          expr
1991          { Lex->clause_that_disallows_subselect= NULL; }
1992          execute_using
1993          {
1994            if (Lex->stmt_execute_immediate($4, $6))
1995              MYSQL_YYABORT;
1996          }
1997        ;
1998
1999execute_using:
2000          /* nothing */    { $$= NULL; }
2001        | USING
2002          { Lex->clause_that_disallows_subselect= "EXECUTE..USING"; }
2003          execute_params
2004          {
2005            $$= $3;
2006            Lex->clause_that_disallows_subselect= NULL;
2007          }
2008        ;
2009
2010execute_params:
2011          expr_or_ignore_or_default
2012          {
2013            if (unlikely(!($$= List<Item>::make(thd->mem_root, $1))))
2014              MYSQL_YYABORT;
2015          }
2016        | execute_params ',' expr_or_ignore_or_default
2017          {
2018            if (($$= $1)->push_back($3, thd->mem_root))
2019              MYSQL_YYABORT;
2020          }
2021        ;
2022
2023
2024/* help */
2025
2026help:
2027          HELP_SYM
2028          {
2029            if (unlikely(Lex->sphead))
2030              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HELP"));
2031          }
2032          ident_or_text
2033          {
2034            LEX *lex= Lex;
2035            lex->sql_command= SQLCOM_HELP;
2036            lex->help_arg= $3.str;
2037          }
2038        ;
2039
2040/* change master */
2041
2042change:
2043          CHANGE MASTER_SYM optional_connection_name TO_SYM
2044          {
2045            Lex->sql_command = SQLCOM_CHANGE_MASTER;
2046          }
2047          master_defs
2048          {}
2049        ;
2050
2051master_defs:
2052          master_def
2053        | master_defs ',' master_def
2054        ;
2055
2056master_def:
2057          MASTER_HOST_SYM '=' TEXT_STRING_sys
2058          {
2059            Lex->mi.host = $3.str;
2060          }
2061        | MASTER_USER_SYM '=' TEXT_STRING_sys
2062          {
2063            Lex->mi.user = $3.str;
2064          }
2065        | MASTER_PASSWORD_SYM '=' TEXT_STRING_sys
2066          {
2067            Lex->mi.password = $3.str;
2068          }
2069        | MASTER_PORT_SYM '=' ulong_num
2070          {
2071            Lex->mi.port = $3;
2072          }
2073        | MASTER_CONNECT_RETRY_SYM '=' ulong_num
2074          {
2075            Lex->mi.connect_retry = $3;
2076          }
2077        | MASTER_DELAY_SYM '=' ulong_num
2078          {
2079            if ($3 > MASTER_DELAY_MAX)
2080            {
2081              my_error(ER_MASTER_DELAY_VALUE_OUT_OF_RANGE, MYF(0),
2082                       (ulong) $3, (ulong) MASTER_DELAY_MAX);
2083            }
2084            else
2085              Lex->mi.sql_delay = $3;
2086          }
2087        | MASTER_SSL_SYM '=' ulong_num
2088          {
2089            Lex->mi.ssl= $3 ?
2090              LEX_MASTER_INFO::LEX_MI_ENABLE : LEX_MASTER_INFO::LEX_MI_DISABLE;
2091          }
2092        | MASTER_SSL_CA_SYM '=' TEXT_STRING_sys
2093          {
2094            Lex->mi.ssl_ca= $3.str;
2095          }
2096        | MASTER_SSL_CAPATH_SYM '=' TEXT_STRING_sys
2097          {
2098            Lex->mi.ssl_capath= $3.str;
2099          }
2100        | MASTER_SSL_CERT_SYM '=' TEXT_STRING_sys
2101          {
2102            Lex->mi.ssl_cert= $3.str;
2103          }
2104        | MASTER_SSL_CIPHER_SYM '=' TEXT_STRING_sys
2105          {
2106            Lex->mi.ssl_cipher= $3.str;
2107          }
2108        | MASTER_SSL_KEY_SYM '=' TEXT_STRING_sys
2109          {
2110            Lex->mi.ssl_key= $3.str;
2111          }
2112        | MASTER_SSL_VERIFY_SERVER_CERT_SYM '=' ulong_num
2113          {
2114            Lex->mi.ssl_verify_server_cert= $3 ?
2115              LEX_MASTER_INFO::LEX_MI_ENABLE : LEX_MASTER_INFO::LEX_MI_DISABLE;
2116          }
2117        | MASTER_SSL_CRL_SYM '=' TEXT_STRING_sys
2118          {
2119            Lex->mi.ssl_crl= $3.str;
2120          }
2121        | MASTER_SSL_CRLPATH_SYM '=' TEXT_STRING_sys
2122          {
2123            Lex->mi.ssl_crlpath= $3.str;
2124          }
2125
2126        | MASTER_HEARTBEAT_PERIOD_SYM '=' NUM_literal
2127          {
2128            Lex->mi.heartbeat_period= (float) $3->val_real();
2129            if (unlikely(Lex->mi.heartbeat_period >
2130                         SLAVE_MAX_HEARTBEAT_PERIOD) ||
2131                unlikely(Lex->mi.heartbeat_period < 0.0))
2132               my_yyabort_error((ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, MYF(0),
2133                                 SLAVE_MAX_HEARTBEAT_PERIOD));
2134
2135            if (unlikely(Lex->mi.heartbeat_period > slave_net_timeout))
2136            {
2137              push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
2138                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX,
2139                                  ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX));
2140            }
2141            if (unlikely(Lex->mi.heartbeat_period < 0.001))
2142            {
2143              if (unlikely(Lex->mi.heartbeat_period != 0.0))
2144              {
2145                push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
2146                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN,
2147                                    ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN));
2148                Lex->mi.heartbeat_period= 0.0;
2149              }
2150              Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_DISABLE;
2151            }
2152            Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_ENABLE;
2153          }
2154        | IGNORE_SERVER_IDS_SYM '=' '(' ignore_server_id_list ')'
2155          {
2156            Lex->mi.repl_ignore_server_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
2157           }
2158        | DO_DOMAIN_IDS_SYM '=' '(' do_domain_id_list ')'
2159          {
2160            Lex->mi.repl_do_domain_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
2161          }
2162        | IGNORE_DOMAIN_IDS_SYM '=' '(' ignore_domain_id_list ')'
2163          {
2164            Lex->mi.repl_ignore_domain_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
2165          }
2166        |
2167        master_file_def
2168        ;
2169
2170ignore_server_id_list:
2171          /* Empty */
2172          | ignore_server_id
2173          | ignore_server_id_list ',' ignore_server_id
2174        ;
2175
2176ignore_server_id:
2177          ulong_num
2178          {
2179            insert_dynamic(&Lex->mi.repl_ignore_server_ids, (uchar*) &($1));
2180          }
2181          ;
2182
2183do_domain_id_list:
2184          /* Empty */
2185          | do_domain_id
2186          | do_domain_id_list ',' do_domain_id
2187        ;
2188
2189do_domain_id:
2190          ulong_num
2191          {
2192            insert_dynamic(&Lex->mi.repl_do_domain_ids, (uchar*) &($1));
2193          }
2194          ;
2195
2196ignore_domain_id_list:
2197          /* Empty */
2198          | ignore_domain_id
2199          | ignore_domain_id_list ',' ignore_domain_id
2200        ;
2201
2202ignore_domain_id:
2203          ulong_num
2204          {
2205            insert_dynamic(&Lex->mi.repl_ignore_domain_ids, (uchar*) &($1));
2206          }
2207          ;
2208
2209master_file_def:
2210          MASTER_LOG_FILE_SYM '=' TEXT_STRING_sys
2211          {
2212            Lex->mi.log_file_name = $3.str;
2213          }
2214        | MASTER_LOG_POS_SYM '=' ulonglong_num
2215          {
2216            /*
2217               If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
2218               instead of causing subsequent errors.
2219               We need to do it in this file, because only there we know that
2220               MASTER_LOG_POS has been explicitly specified. On the contrary
2221               in change_master() (sql_repl.cc) we cannot distinguish between 0
2222               (MASTER_LOG_POS explicitly specified as 0) and 0 (unspecified),
2223               whereas we want to distinguish (specified 0 means "read the binlog
2224               from 0" (4 in fact), unspecified means "don't change the position
2225               (keep the preceding value)").
2226            */
2227            Lex->mi.pos= MY_MAX(BIN_LOG_HEADER_SIZE, $3);
2228          }
2229        | RELAY_LOG_FILE_SYM '=' TEXT_STRING_sys
2230          {
2231            Lex->mi.relay_log_name = $3.str;
2232          }
2233        | RELAY_LOG_POS_SYM '=' ulong_num
2234          {
2235            Lex->mi.relay_log_pos = $3;
2236            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
2237            Lex->mi.relay_log_pos= MY_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
2238          }
2239        | MASTER_USE_GTID_SYM '=' CURRENT_POS_SYM
2240          {
2241            if (unlikely(Lex->mi.use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_UNCHANGED))
2242              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
2243            Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_CURRENT_POS;
2244          }
2245        | MASTER_USE_GTID_SYM '=' SLAVE_POS_SYM
2246          {
2247            if (unlikely(Lex->mi.use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_UNCHANGED))
2248              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
2249            Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_SLAVE_POS;
2250          }
2251        | MASTER_USE_GTID_SYM '=' NO_SYM
2252          {
2253            if (unlikely(Lex->mi.use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_UNCHANGED))
2254              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
2255            Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_NO;
2256          }
2257        ;
2258
2259optional_connection_name:
2260          /* empty */
2261          {
2262            LEX *lex= thd->lex;
2263            lex->mi.connection_name= null_clex_str;
2264          }
2265        | connection_name
2266        ;
2267
2268connection_name:
2269        TEXT_STRING_sys
2270        {
2271           Lex->mi.connection_name= $1;
2272#ifdef HAVE_REPLICATION
2273           if (unlikely(check_master_connection_name(&$1)))
2274              my_yyabort_error((ER_WRONG_ARGUMENTS, MYF(0), "MASTER_CONNECTION_NAME"));
2275#endif
2276         }
2277         ;
2278
2279/* create a table */
2280
2281create:
2282          create_or_replace opt_temporary TABLE_SYM opt_if_not_exists
2283          {
2284            LEX *lex= thd->lex;
2285            if (!(lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_create_table()))
2286              MYSQL_YYABORT;
2287            lex->create_info.init();
2288            if (lex->main_select_push())
2289              MYSQL_YYABORT;
2290            lex->current_select->parsing_place= BEFORE_OPT_LIST;
2291            if (lex->set_command_with_check(SQLCOM_CREATE_TABLE, $2, $1 | $4))
2292               MYSQL_YYABORT;
2293          }
2294          table_ident
2295          {
2296            LEX *lex= thd->lex;
2297            if (!lex->first_select_lex()->
2298                  add_table_to_list(thd, $6, NULL, TL_OPTION_UPDATING,
2299                                    TL_WRITE, MDL_SHARED_UPGRADABLE))
2300              MYSQL_YYABORT;
2301            lex->alter_info.reset();
2302            /*
2303              For CREATE TABLE we should not open the table even if it exists.
2304              If the table exists, we should either not create it or replace it
2305            */
2306            lex->query_tables->open_strategy= TABLE_LIST::OPEN_STUB;
2307            lex->create_info.default_table_charset= NULL;
2308            lex->name= null_clex_str;
2309            lex->create_last_non_select_table= lex->last_table();
2310          }
2311          create_body
2312          {
2313            LEX *lex= thd->lex;
2314            create_table_set_open_action_and_adjust_tables(lex);
2315            Lex->pop_select(); //main select
2316          }
2317       | create_or_replace opt_temporary SEQUENCE_SYM opt_if_not_exists table_ident
2318         {
2319           LEX *lex= thd->lex;
2320           if (lex->main_select_push())
2321             MYSQL_YYABORT;
2322           if (!(lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_create_sequence()))
2323              MYSQL_YYABORT;
2324           lex->create_info.init();
2325           if (unlikely(lex->set_command_with_check(SQLCOM_CREATE_SEQUENCE, $2,
2326                        $1 | $4)))
2327              MYSQL_YYABORT;
2328
2329           if (!lex->first_select_lex()->
2330                 add_table_to_list(thd, $5, NULL, TL_OPTION_UPDATING,
2331                                   TL_WRITE, MDL_EXCLUSIVE))
2332             MYSQL_YYABORT;
2333
2334               /*
2335                 For CREATE TABLE, an non-existing table is not an error.
2336                 Instruct open_tables() to just take an MDL lock if the
2337                 table does not exist.
2338               */
2339             lex->alter_info.reset();
2340             lex->query_tables->open_strategy= TABLE_LIST::OPEN_STUB;
2341             lex->name= null_clex_str;
2342             lex->create_last_non_select_table= lex->last_table();
2343             if (unlikely(!(lex->create_info.seq_create_info=
2344                            new (thd->mem_root) sequence_definition())))
2345               MYSQL_YYABORT;
2346         }
2347         opt_sequence opt_create_table_options
2348         {
2349            LEX *lex= thd->lex;
2350
2351            if (unlikely(lex->create_info.seq_create_info->check_and_adjust(1)))
2352            {
2353              my_error(ER_SEQUENCE_INVALID_DATA, MYF(0),
2354                       lex->first_select_lex()->table_list.first->db.str,
2355                       lex->first_select_lex()->table_list.first->
2356                         table_name.str);
2357              MYSQL_YYABORT;
2358            }
2359
2360            /* No fields specified, generate them */
2361            if (unlikely(prepare_sequence_fields(thd,
2362                         &lex->alter_info.create_list)))
2363               MYSQL_YYABORT;
2364
2365            /* CREATE SEQUENCE always creates a sequence */
2366	    Lex->create_info.used_fields|= HA_CREATE_USED_SEQUENCE;
2367            Lex->create_info.sequence= 1;
2368
2369            create_table_set_open_action_and_adjust_tables(lex);
2370            Lex->pop_select(); //main select
2371          }
2372        | create_or_replace INDEX_SYM opt_if_not_exists
2373          {
2374            if (Lex->main_select_push())
2375              MYSQL_YYABORT;
2376          }
2377          ident
2378          opt_key_algorithm_clause
2379          ON table_ident
2380          {
2381            if (Lex->add_create_index_prepare($8))
2382              MYSQL_YYABORT;
2383            if (Lex->add_create_index(Key::MULTIPLE, &$5, $6, $1 | $3))
2384              MYSQL_YYABORT;
2385          }
2386          '(' key_list ')' opt_lock_wait_timeout normal_key_options
2387          opt_index_lock_algorithm
2388          {
2389            Lex->pop_select(); //main select
2390          }
2391        | create_or_replace UNIQUE_SYM INDEX_SYM opt_if_not_exists
2392          {
2393            if (Lex->main_select_push())
2394              MYSQL_YYABORT;
2395          }
2396          ident
2397          opt_key_algorithm_clause
2398          ON table_ident
2399          {
2400            if (Lex->add_create_index_prepare($9))
2401              MYSQL_YYABORT;
2402            if (Lex->add_create_index(Key::UNIQUE, &$6, $7, $1 | $4))
2403              MYSQL_YYABORT;
2404          }
2405          '(' key_list opt_without_overlaps ')'
2406          opt_lock_wait_timeout normal_key_options
2407          opt_index_lock_algorithm
2408          {
2409            Lex->pop_select(); //main select
2410          }
2411        | create_or_replace fulltext INDEX_SYM
2412          {
2413            if (Lex->main_select_push())
2414              MYSQL_YYABORT;
2415          }
2416          opt_if_not_exists ident
2417          ON table_ident
2418          {
2419            if (Lex->add_create_index_prepare($8))
2420              MYSQL_YYABORT;
2421            if (Lex->add_create_index($2, &$6, HA_KEY_ALG_UNDEF, $1 | $5))
2422              MYSQL_YYABORT;
2423          }
2424          '(' key_list ')' opt_lock_wait_timeout fulltext_key_options
2425          opt_index_lock_algorithm
2426          {
2427            Lex->pop_select(); //main select
2428          }
2429        | create_or_replace spatial INDEX_SYM
2430          {
2431            if (Lex->main_select_push())
2432              MYSQL_YYABORT;
2433          }
2434          opt_if_not_exists ident
2435          ON table_ident
2436          {
2437            if (Lex->add_create_index_prepare($8))
2438              MYSQL_YYABORT;
2439            if (Lex->add_create_index($2, &$6, HA_KEY_ALG_UNDEF, $1 | $5))
2440              MYSQL_YYABORT;
2441          }
2442          '(' key_list ')' opt_lock_wait_timeout spatial_key_options
2443          opt_index_lock_algorithm
2444          {
2445            Lex->pop_select(); //main select
2446          }
2447        | create_or_replace DATABASE opt_if_not_exists ident
2448          {
2449            Lex->create_info.default_table_charset= NULL;
2450            Lex->create_info.schema_comment= NULL;
2451            Lex->create_info.used_fields= 0;
2452          }
2453          opt_create_database_options
2454          {
2455            LEX *lex=Lex;
2456            if (unlikely(lex->set_command_with_check(SQLCOM_CREATE_DB, 0,
2457                         $1 | $3)))
2458               MYSQL_YYABORT;
2459            lex->name= $4;
2460          }
2461        | create_or_replace definer_opt opt_view_suid VIEW_SYM
2462          opt_if_not_exists table_ident
2463          {
2464            if (Lex->main_select_push())
2465              MYSQL_YYABORT;
2466            if (Lex->add_create_view(thd, $1 | $5,
2467                                     DTYPE_ALGORITHM_UNDEFINED, $3, $6))
2468              MYSQL_YYABORT;
2469          }
2470          view_list_opt AS view_select
2471          {
2472            Lex->pop_select(); //main select
2473          }
2474        | create_or_replace view_algorithm definer_opt opt_view_suid VIEW_SYM
2475          opt_if_not_exists table_ident
2476          {
2477            if (unlikely(Lex->add_create_view(thd, $1 | $6, $2, $4, $7)))
2478              MYSQL_YYABORT;
2479            if (Lex->main_select_push())
2480              MYSQL_YYABORT;
2481          }
2482          view_list_opt AS view_select
2483          {
2484            Lex->pop_select(); //main select
2485          }
2486        | create_or_replace definer_opt TRIGGER_SYM
2487          {
2488            if (Lex->main_select_push())
2489              MYSQL_YYABORT;
2490            Lex->create_info.set($1);
2491          }
2492          trigger_tail
2493          {
2494            Lex->pop_select(); //main select
2495          }
2496        | create_or_replace definer_opt EVENT_SYM
2497          {
2498            if (Lex->main_select_push())
2499              MYSQL_YYABORT;
2500            Lex->create_info.set($1);
2501          }
2502          event_tail
2503          {
2504            Lex->pop_select(); //main select
2505          }
2506        | create_or_replace USER_SYM opt_if_not_exists clear_privileges
2507          grant_list opt_require_clause opt_resource_options opt_account_locking_and_opt_password_expiration
2508          {
2509            if (unlikely(Lex->set_command_with_check(SQLCOM_CREATE_USER,
2510                                                     $1 | $3)))
2511              MYSQL_YYABORT;
2512          }
2513        | create_or_replace ROLE_SYM opt_if_not_exists
2514          clear_privileges role_list opt_with_admin
2515          {
2516            if (unlikely(Lex->set_command_with_check(SQLCOM_CREATE_ROLE,
2517                         $1 | $3)))
2518              MYSQL_YYABORT;
2519          }
2520        | CREATE LOGFILE_SYM GROUP_SYM logfile_group_info
2521          {
2522            Lex->alter_tablespace_info->ts_cmd_type= CREATE_LOGFILE_GROUP;
2523          }
2524        | CREATE TABLESPACE tablespace_info
2525          {
2526            Lex->alter_tablespace_info->ts_cmd_type= CREATE_TABLESPACE;
2527          }
2528        | create_or_replace { Lex->set_command(SQLCOM_CREATE_SERVER, $1); }
2529          server_def
2530          { }
2531        | create_routine
2532        ;
2533
2534opt_sequence:
2535         /* empty */ { }
2536        | sequence_defs
2537        ;
2538
2539sequence_defs:
2540          sequence_def
2541        | sequence_defs sequence_def
2542        ;
2543
2544sequence_def:
2545        MINVALUE_SYM opt_equal longlong_num
2546          {
2547            Lex->create_info.seq_create_info->min_value= $3;
2548            Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
2549          }
2550        | NO_SYM MINVALUE_SYM
2551          {
2552            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_min_value))
2553              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
2554            Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
2555          }
2556        | NOMINVALUE_SYM
2557          {
2558            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_min_value))
2559              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
2560            Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
2561          }
2562        | MAXVALUE_SYM opt_equal longlong_num
2563          {
2564           if (unlikely(Lex->create_info.seq_create_info->used_fields &
2565               seq_field_used_max_value))
2566              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
2567            Lex->create_info.seq_create_info->max_value= $3;
2568            Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
2569          }
2570        | NO_SYM MAXVALUE_SYM
2571          {
2572            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_max_value))
2573              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
2574            Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
2575          }
2576        | NOMAXVALUE_SYM
2577          {
2578            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_max_value))
2579              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
2580            Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
2581          }
2582        | START_SYM opt_with longlong_num
2583          {
2584            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2585                         seq_field_used_start))
2586              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "START"));
2587            Lex->create_info.seq_create_info->start= $3;
2588            Lex->create_info.seq_create_info->used_fields|= seq_field_used_start;
2589          }
2590        | INCREMENT_SYM opt_by longlong_num
2591          {
2592             if (unlikely(Lex->create_info.seq_create_info->used_fields &
2593                seq_field_used_increment))
2594              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "INCREMENT"));
2595            Lex->create_info.seq_create_info->increment= $3;
2596            Lex->create_info.seq_create_info->used_fields|= seq_field_used_increment;
2597          }
2598        | CACHE_SYM opt_equal longlong_num
2599          {
2600            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2601                seq_field_used_cache))
2602              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CACHE"));
2603            Lex->create_info.seq_create_info->cache= $3;
2604            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cache;
2605          }
2606        | NOCACHE_SYM
2607          {
2608            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2609                seq_field_used_cache))
2610              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CACHE"));
2611            Lex->create_info.seq_create_info->cache= 0;
2612            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cache;
2613          }
2614        | CYCLE_SYM
2615          {
2616            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2617                seq_field_used_cycle))
2618              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CYCLE"));
2619            Lex->create_info.seq_create_info->cycle= 1;
2620            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cycle;
2621          }
2622        | NOCYCLE_SYM
2623          {
2624            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2625                seq_field_used_cycle))
2626              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CYCLE"));
2627            Lex->create_info.seq_create_info->cycle= 0;
2628            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cycle;
2629          }
2630        | RESTART_SYM
2631          {
2632            if (unlikely(Lex->sql_command != SQLCOM_ALTER_SEQUENCE))
2633            {
2634              thd->parse_error(ER_SYNTAX_ERROR, "RESTART");
2635              YYABORT;
2636            }
2637            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2638                         seq_field_used_restart))
2639              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "RESTART"));
2640            Lex->create_info.seq_create_info->used_fields|= seq_field_used_restart;
2641          }
2642        | RESTART_SYM opt_with longlong_num
2643          {
2644            if (unlikely(Lex->sql_command != SQLCOM_ALTER_SEQUENCE))
2645            {
2646              thd->parse_error(ER_SYNTAX_ERROR, "RESTART");
2647              YYABORT;
2648            }
2649            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2650                         seq_field_used_restart))
2651              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "RESTART"));
2652            Lex->create_info.seq_create_info->restart= $3;
2653            Lex->create_info.seq_create_info->used_fields|= seq_field_used_restart | seq_field_used_restart_value;
2654          }
2655        ;
2656
2657server_def:
2658          SERVER_SYM opt_if_not_exists ident_or_text
2659          {
2660            if (unlikely(Lex->add_create_options_with_check($2)))
2661              MYSQL_YYABORT;
2662            Lex->server_options.reset($3);
2663          }
2664          FOREIGN DATA_SYM WRAPPER_SYM ident_or_text
2665          OPTIONS_SYM '(' server_options_list ')'
2666          { Lex->server_options.scheme= $8; }
2667        ;
2668
2669server_options_list:
2670          server_option
2671        | server_options_list ',' server_option
2672        ;
2673
2674server_option:
2675          USER_SYM TEXT_STRING_sys
2676          {
2677            MYSQL_YYABORT_UNLESS(Lex->server_options.username.str == 0);
2678            Lex->server_options.username= $2;
2679          }
2680        | HOST_SYM TEXT_STRING_sys
2681          {
2682            MYSQL_YYABORT_UNLESS(Lex->server_options.host.str == 0);
2683            Lex->server_options.host= $2;
2684          }
2685        | DATABASE TEXT_STRING_sys
2686          {
2687            MYSQL_YYABORT_UNLESS(Lex->server_options.db.str == 0);
2688            Lex->server_options.db= $2;
2689          }
2690        | OWNER_SYM TEXT_STRING_sys
2691          {
2692            MYSQL_YYABORT_UNLESS(Lex->server_options.owner.str == 0);
2693            Lex->server_options.owner= $2;
2694          }
2695        | PASSWORD_SYM TEXT_STRING_sys
2696          {
2697            MYSQL_YYABORT_UNLESS(Lex->server_options.password.str == 0);
2698            Lex->server_options.password= $2;
2699          }
2700        | SOCKET_SYM TEXT_STRING_sys
2701          {
2702            MYSQL_YYABORT_UNLESS(Lex->server_options.socket.str == 0);
2703            Lex->server_options.socket= $2;
2704          }
2705        | PORT_SYM ulong_num
2706          {
2707            Lex->server_options.port= $2;
2708          }
2709        ;
2710
2711event_tail:
2712          remember_name opt_if_not_exists sp_name
2713          {
2714            LEX *lex=Lex;
2715
2716            lex->stmt_definition_begin= $1;
2717            if (unlikely(lex->add_create_options_with_check($2)))
2718              MYSQL_YYABORT;
2719            if (unlikely(!(lex->event_parse_data=
2720                           Event_parse_data::new_instance(thd))))
2721              MYSQL_YYABORT;
2722            lex->event_parse_data->identifier= $3;
2723            lex->event_parse_data->on_completion=
2724                                  Event_parse_data::ON_COMPLETION_DROP;
2725
2726            lex->sql_command= SQLCOM_CREATE_EVENT;
2727            /* We need that for disallowing subqueries */
2728          }
2729          ON SCHEDULE_SYM ev_schedule_time
2730          opt_ev_on_completion
2731          opt_ev_status
2732          opt_ev_comment
2733          DO_SYM ev_sql_stmt
2734          {
2735            /*
2736              sql_command is set here because some rules in ev_sql_stmt
2737              can overwrite it
2738            */
2739            Lex->sql_command= SQLCOM_CREATE_EVENT;
2740          }
2741        ;
2742
2743ev_schedule_time:
2744          EVERY_SYM expr interval
2745          {
2746            Lex->event_parse_data->item_expression= $2;
2747            Lex->event_parse_data->interval= $3;
2748          }
2749          ev_starts
2750          ev_ends
2751        | AT_SYM expr
2752          {
2753            Lex->event_parse_data->item_execute_at= $2;
2754          }
2755        ;
2756
2757opt_ev_status:
2758          /* empty */ { $$= 0; }
2759        | ENABLE_SYM
2760          {
2761            Lex->event_parse_data->status= Event_parse_data::ENABLED;
2762            Lex->event_parse_data->status_changed= true;
2763            $$= 1;
2764          }
2765        | DISABLE_SYM ON SLAVE
2766          {
2767            Lex->event_parse_data->status= Event_parse_data::SLAVESIDE_DISABLED;
2768            Lex->event_parse_data->status_changed= true;
2769            $$= 1;
2770          }
2771        | DISABLE_SYM
2772          {
2773            Lex->event_parse_data->status= Event_parse_data::DISABLED;
2774            Lex->event_parse_data->status_changed= true;
2775            $$= 1;
2776          }
2777        ;
2778
2779ev_starts:
2780          /* empty */
2781          {
2782            Item *item= new (thd->mem_root) Item_func_now_local(thd, 0);
2783            if (unlikely(item == NULL))
2784              MYSQL_YYABORT;
2785            Lex->event_parse_data->item_starts= item;
2786          }
2787        | STARTS_SYM expr
2788          {
2789            Lex->event_parse_data->item_starts= $2;
2790          }
2791        ;
2792
2793ev_ends:
2794          /* empty */
2795        | ENDS_SYM expr
2796          {
2797            Lex->event_parse_data->item_ends= $2;
2798          }
2799        ;
2800
2801opt_ev_on_completion:
2802          /* empty */ { $$= 0; }
2803        | ev_on_completion
2804        ;
2805
2806ev_on_completion:
2807          ON COMPLETION_SYM opt_not PRESERVE_SYM
2808          {
2809            Lex->event_parse_data->on_completion= $3
2810                                    ? Event_parse_data::ON_COMPLETION_DROP
2811                                    : Event_parse_data::ON_COMPLETION_PRESERVE;
2812            $$= 1;
2813          }
2814        ;
2815
2816opt_ev_comment:
2817          /* empty */ { $$= 0; }
2818        | COMMENT_SYM TEXT_STRING_sys
2819          {
2820            Lex->comment= Lex->event_parse_data->comment= $2;
2821            $$= 1;
2822          }
2823        ;
2824
2825ev_sql_stmt:
2826          {
2827            LEX *lex= thd->lex;
2828            Lex_input_stream *lip= YYLIP;
2829
2830            /*
2831              This stops the following :
2832              - CREATE EVENT ... DO CREATE EVENT ...;
2833              - ALTER  EVENT ... DO CREATE EVENT ...;
2834              - CREATE EVENT ... DO ALTER EVENT DO ....;
2835              - CREATE PROCEDURE ... BEGIN CREATE EVENT ... END|
2836              This allows:
2837              - CREATE EVENT ... DO DROP EVENT yyy;
2838              - CREATE EVENT ... DO ALTER EVENT yyy;
2839                (the nested ALTER EVENT can have anything but DO clause)
2840              - ALTER  EVENT ... DO ALTER EVENT yyy;
2841                (the nested ALTER EVENT can have anything but DO clause)
2842              - ALTER  EVENT ... DO DROP EVENT yyy;
2843              - CREATE PROCEDURE ... BEGIN ALTER EVENT ... END|
2844                (the nested ALTER EVENT can have anything but DO clause)
2845              - CREATE PROCEDURE ... BEGIN DROP EVENT ... END|
2846            */
2847            if (unlikely(lex->sphead))
2848              my_yyabort_error((ER_EVENT_RECURSION_FORBIDDEN, MYF(0)));
2849
2850            if (unlikely(!lex->make_sp_head(thd,
2851                                            lex->event_parse_data->identifier,
2852                                            &sp_handler_procedure,
2853                                            DEFAULT_AGGREGATE)))
2854              MYSQL_YYABORT;
2855
2856            lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
2857          }
2858          sp_proc_stmt
2859          {
2860            /* return back to the original memory root ASAP */
2861            if (Lex->sp_body_finalize_event(thd))
2862              MYSQL_YYABORT;
2863          }
2864        ;
2865
2866clear_privileges:
2867          /* Nothing */
2868          {
2869           LEX *lex=Lex;
2870           lex->users_list.empty();
2871           lex->first_select_lex()->db= null_clex_str;
2872           lex->account_options.reset();
2873         }
2874        ;
2875
2876opt_aggregate:
2877          /* Empty */   { $$= NOT_AGGREGATE; }
2878        | AGGREGATE_SYM { $$= GROUP_AGGREGATE; }
2879        ;
2880
2881
2882sp_handler:
2883          FUNCTION_SYM                       { $$= &sp_handler_function; }
2884        | PROCEDURE_SYM                      { $$= &sp_handler_procedure; }
2885        | PACKAGE_ORACLE_SYM                 { $$= &sp_handler_package_spec; }
2886        | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM { $$= &sp_handler_package_body; }
2887        ;
2888
2889
2890sp_name:
2891          ident '.' ident
2892          {
2893            if (unlikely(!($$= Lex->make_sp_name(thd, &$1, &$3))))
2894              MYSQL_YYABORT;
2895          }
2896        | ident
2897          {
2898            if (unlikely(!($$= Lex->make_sp_name(thd, &$1))))
2899              MYSQL_YYABORT;
2900          }
2901        ;
2902
2903sp_a_chistics:
2904          /* Empty */ {}
2905        | sp_a_chistics sp_chistic {}
2906        ;
2907
2908sp_c_chistics:
2909          /* Empty */ {}
2910        | sp_c_chistics sp_c_chistic {}
2911        ;
2912
2913/* Characteristics for both create and alter */
2914sp_chistic:
2915          COMMENT_SYM TEXT_STRING_sys
2916          { Lex->sp_chistics.comment= $2; }
2917        | LANGUAGE_SYM SQL_SYM
2918          { /* Just parse it, we only have one language for now. */ }
2919        | NO_SYM SQL_SYM
2920          { Lex->sp_chistics.daccess= SP_NO_SQL; }
2921        | CONTAINS_SYM SQL_SYM
2922          { Lex->sp_chistics.daccess= SP_CONTAINS_SQL; }
2923        | READS_SYM SQL_SYM DATA_SYM
2924          { Lex->sp_chistics.daccess= SP_READS_SQL_DATA; }
2925        | MODIFIES_SYM SQL_SYM DATA_SYM
2926          { Lex->sp_chistics.daccess= SP_MODIFIES_SQL_DATA; }
2927        | sp_suid
2928          { Lex->sp_chistics.suid= $1; }
2929        ;
2930
2931/* Create characteristics */
2932sp_c_chistic:
2933          sp_chistic            { }
2934        | opt_not DETERMINISTIC_SYM { Lex->sp_chistics.detistic= ! $1; }
2935        ;
2936
2937sp_suid:
2938          SQL_SYM SECURITY_SYM DEFINER_SYM { $$= SP_IS_SUID; }
2939        | SQL_SYM SECURITY_SYM INVOKER_SYM { $$= SP_IS_NOT_SUID; }
2940        ;
2941
2942call:
2943          CALL_SYM sp_name
2944          {
2945            if (unlikely(Lex->call_statement_start(thd, $2)))
2946              MYSQL_YYABORT;
2947          }
2948          opt_sp_cparam_list
2949          {
2950            if (Lex->check_cte_dependencies_and_resolve_references())
2951              MYSQL_YYABORT;
2952          }
2953        ;
2954
2955/* CALL parameters */
2956opt_sp_cparam_list:
2957          /* Empty */
2958        | '(' opt_sp_cparams ')'
2959        ;
2960
2961opt_sp_cparams:
2962          /* Empty */
2963        | sp_cparams
2964        ;
2965
2966sp_cparams:
2967          sp_cparams ',' expr
2968          {
2969           Lex->value_list.push_back($3, thd->mem_root);
2970          }
2971        | expr
2972          {
2973            Lex->value_list.push_back($1, thd->mem_root);
2974          }
2975        ;
2976
2977/* Stored FUNCTION parameter declaration list */
2978sp_fdparam_list:
2979          /* Empty */
2980          {
2981            Lex->sphead->m_param_begin= YYLIP->get_cpp_tok_start();
2982            Lex->sphead->m_param_end= Lex->sphead->m_param_begin;
2983          }
2984        |
2985          {
2986            Lex->sphead->m_param_begin= YYLIP->get_cpp_tok_start();
2987          }
2988          sp_fdparams
2989          {
2990            Lex->sphead->m_param_end= YYLIP->get_cpp_tok_start();
2991          }
2992        ;
2993
2994sp_fdparams:
2995          sp_fdparams ',' sp_param_name_and_type
2996        | sp_param_name_and_type
2997        ;
2998
2999sp_param_name:
3000          ident
3001          {
3002            if (unlikely(!($$= Lex->sp_param_init(&$1))))
3003              MYSQL_YYABORT;
3004          }
3005        ;
3006
3007sp_param_name_and_type:
3008          sp_param_name field_type
3009          {
3010            if (unlikely(Lex->sp_param_fill_definition($$= $1, $2)))
3011              MYSQL_YYABORT;
3012          }
3013        | sp_param_name ROW_SYM row_type_body
3014          {
3015            if (unlikely(Lex->sphead->spvar_fill_row(thd, $$= $1, $3)))
3016              MYSQL_YYABORT;
3017          }
3018        | sp_param_name_and_type_anchored
3019        ;
3020
3021/* Stored PROCEDURE parameter declaration list */
3022sp_pdparam_list:
3023          /* Empty */
3024        | sp_pdparams
3025        ;
3026
3027sp_pdparams:
3028          sp_pdparams ',' sp_pdparam
3029        | sp_pdparam
3030        ;
3031
3032sp_parameter_type:
3033          IN_SYM      { $$= sp_variable::MODE_IN; }
3034        | OUT_SYM     { $$= sp_variable::MODE_OUT; }
3035        | INOUT_SYM   { $$= sp_variable::MODE_INOUT; }
3036        ;
3037
3038sp_parenthesized_pdparam_list:
3039          '('
3040          {
3041            Lex->sphead->m_param_begin= YYLIP->get_cpp_tok_start() + 1;
3042          }
3043          sp_pdparam_list
3044          ')'
3045          {
3046            Lex->sphead->m_param_end= YYLIP->get_cpp_tok_start();
3047          }
3048        ;
3049
3050sp_parenthesized_fdparam_list:
3051        '(' sp_fdparam_list ')'
3052        ;
3053
3054sp_proc_stmts:
3055          /* Empty */ {}
3056        | sp_proc_stmts  sp_proc_stmt ';'
3057        ;
3058
3059sp_proc_stmts1:
3060          sp_proc_stmt ';' {}
3061        | sp_proc_stmts1  sp_proc_stmt ';'
3062        ;
3063
3064
3065optionally_qualified_column_ident:
3066          sp_decl_ident
3067          {
3068            if (unlikely(!($$= new (thd->mem_root)
3069                         Qualified_column_ident(&$1))))
3070              MYSQL_YYABORT;
3071          }
3072        | sp_decl_ident '.' ident
3073          {
3074            if (unlikely(!($$= new (thd->mem_root)
3075                           Qualified_column_ident(&$1, &$3))))
3076              MYSQL_YYABORT;
3077          }
3078        | sp_decl_ident '.' ident '.' ident
3079          {
3080            if (unlikely(!($$= new (thd->mem_root)
3081                           Qualified_column_ident(thd, &$1, &$3, &$5))))
3082              MYSQL_YYABORT;
3083          }
3084        ;
3085
3086
3087row_field_definition:
3088          row_field_name field_type
3089          {
3090            Lex->last_field->set_attributes(thd, $2, Lex->charset,
3091                                            COLUMN_DEFINITION_ROUTINE_LOCAL);
3092          }
3093        ;
3094
3095row_field_definition_list:
3096          row_field_definition
3097          {
3098            if (!($$= Row_definition_list::make(thd->mem_root, $1)))
3099              MYSQL_YYABORT;
3100          }
3101        | row_field_definition_list ',' row_field_definition
3102          {
3103            if (($$= $1)->append_uniq(thd->mem_root, $3))
3104              MYSQL_YYABORT;
3105          }
3106        ;
3107
3108row_type_body:
3109          '(' row_field_definition_list ')' { $$= $2; }
3110        ;
3111
3112sp_decl_idents_init_vars:
3113          sp_decl_idents
3114          {
3115            Lex->sp_variable_declarations_init(thd, $1);
3116          }
3117        ;
3118
3119sp_decl_variable_list:
3120          sp_decl_idents_init_vars
3121          field_type
3122          {
3123            Lex->last_field->set_attributes(thd, $2, Lex->charset,
3124                                            COLUMN_DEFINITION_ROUTINE_LOCAL);
3125          }
3126          sp_opt_default
3127          {
3128            if (unlikely(Lex->sp_variable_declarations_finalize(thd, $1,
3129                                                                &Lex->last_field[0],
3130                                                                $4)))
3131              MYSQL_YYABORT;
3132            $$.init_using_vars($1);
3133          }
3134        | sp_decl_idents_init_vars
3135          ROW_SYM row_type_body
3136          sp_opt_default
3137          {
3138            if (unlikely(Lex->sp_variable_declarations_row_finalize(thd, $1, $3, $4)))
3139              MYSQL_YYABORT;
3140            $$.init_using_vars($1);
3141          }
3142        | sp_decl_variable_list_anchored
3143        ;
3144
3145sp_decl_handler:
3146          sp_handler_type HANDLER_SYM FOR_SYM
3147          {
3148            if (unlikely(Lex->sp_handler_declaration_init(thd, $1)))
3149              MYSQL_YYABORT;
3150          }
3151          sp_hcond_list sp_proc_stmt
3152          {
3153            if (unlikely(Lex->sp_handler_declaration_finalize(thd, $1)))
3154              MYSQL_YYABORT;
3155            $$.vars= $$.conds= $$.curs= 0;
3156            $$.hndlrs= 1;
3157          }
3158        ;
3159
3160opt_parenthesized_cursor_formal_parameters:
3161          /* Empty */
3162        | '(' sp_fdparams ')'
3163        ;
3164
3165
3166sp_cursor_stmt_lex:
3167          {
3168            DBUG_ASSERT(thd->lex->sphead);
3169            if (unlikely(!($$= new (thd->mem_root)
3170                           sp_lex_cursor(thd, thd->lex))))
3171              MYSQL_YYABORT;
3172          }
3173        ;
3174
3175sp_cursor_stmt:
3176          sp_cursor_stmt_lex
3177          {
3178            DBUG_ASSERT(thd->free_list == NULL);
3179            Lex->sphead->reset_lex(thd, $1);
3180            if (Lex->main_select_push(true))
3181              MYSQL_YYABORT;
3182          }
3183          select
3184          {
3185            DBUG_ASSERT(Lex == $1);
3186            Lex->pop_select(); //main select
3187            if (unlikely($1->stmt_finalize(thd)) ||
3188                unlikely($1->sphead->restore_lex(thd)))
3189              MYSQL_YYABORT;
3190            $$= $1;
3191          }
3192        ;
3193
3194sp_handler_type:
3195          EXIT_MARIADB_SYM      { $$= sp_handler::EXIT; }
3196        | CONTINUE_MARIADB_SYM  { $$= sp_handler::CONTINUE; }
3197        | EXIT_ORACLE_SYM      { $$= sp_handler::EXIT; }
3198        | CONTINUE_ORACLE_SYM  { $$= sp_handler::CONTINUE; }
3199       /*| UNDO_SYM      { QQ No yet } */
3200        ;
3201
3202sp_hcond_list:
3203          sp_hcond_element
3204          { $$= 1; }
3205        | sp_hcond_list ',' sp_hcond_element
3206          { $$+= 1; }
3207        ;
3208
3209sp_hcond_element:
3210          sp_hcond
3211          {
3212            LEX *lex= Lex;
3213            sp_head *sp= lex->sphead;
3214            sp_pcontext *ctx= lex->spcont->parent_context();
3215
3216            if (unlikely(ctx->check_duplicate_handler($1)))
3217              my_yyabort_error((ER_SP_DUP_HANDLER, MYF(0)));
3218
3219            sp_instr_hpush_jump *i= (sp_instr_hpush_jump *)sp->last_instruction();
3220            i->add_condition($1);
3221          }
3222        ;
3223
3224sp_cond:
3225          ulong_num
3226          { /* mysql errno */
3227            if (unlikely($1 == 0))
3228              my_yyabort_error((ER_WRONG_VALUE, MYF(0), "CONDITION", "0"));
3229            $$= new (thd->mem_root) sp_condition_value($1);
3230            if (unlikely($$ == NULL))
3231              MYSQL_YYABORT;
3232          }
3233        | sqlstate
3234        ;
3235
3236sqlstate:
3237          SQLSTATE_SYM opt_value TEXT_STRING_literal
3238          { /* SQLSTATE */
3239
3240            /*
3241              An error is triggered:
3242                - if the specified string is not a valid SQLSTATE,
3243                - or if it represents the completion condition -- it is not
3244                  allowed to SIGNAL, or declare a handler for the completion
3245                  condition.
3246            */
3247            if (unlikely(!is_sqlstate_valid(&$3) ||
3248                         is_sqlstate_completion($3.str)))
3249              my_yyabort_error((ER_SP_BAD_SQLSTATE, MYF(0), $3.str));
3250            $$= new (thd->mem_root) sp_condition_value($3.str);
3251            if (unlikely($$ == NULL))
3252              MYSQL_YYABORT;
3253          }
3254        ;
3255
3256opt_value:
3257          /* Empty */  {}
3258        | VALUE_SYM    {}
3259        ;
3260
3261sp_hcond:
3262          sp_cond
3263          {
3264            $$= $1;
3265          }
3266        | ident /* CONDITION name */
3267          {
3268            $$= Lex->spcont->find_declared_or_predefined_condition(thd, &$1);
3269            if (unlikely($$ == NULL))
3270              my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str));
3271          }
3272        | SQLWARNING_SYM /* SQLSTATEs 01??? */
3273          {
3274            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::WARNING);
3275            if (unlikely($$ == NULL))
3276              MYSQL_YYABORT;
3277          }
3278        | not FOUND_SYM /* SQLSTATEs 02??? */
3279          {
3280            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::NOT_FOUND);
3281            if (unlikely($$ == NULL))
3282              MYSQL_YYABORT;
3283          }
3284        | SQLEXCEPTION_SYM /* All other SQLSTATEs */
3285          {
3286            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::EXCEPTION);
3287            if (unlikely($$ == NULL))
3288              MYSQL_YYABORT;
3289          }
3290        | OTHERS_ORACLE_SYM /* All other SQLSTATEs */
3291          {
3292            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::EXCEPTION);
3293            if (unlikely($$ == NULL))
3294              MYSQL_YYABORT;
3295          }
3296        ;
3297
3298
3299raise_stmt_oracle:
3300          RAISE_ORACLE_SYM opt_set_signal_information
3301          {
3302            if (unlikely(Lex->add_resignal_statement(thd, NULL)))
3303              MYSQL_YYABORT;
3304          }
3305        | RAISE_ORACLE_SYM signal_value opt_set_signal_information
3306          {
3307            if (unlikely(Lex->add_signal_statement(thd, $2)))
3308              MYSQL_YYABORT;
3309          }
3310        ;
3311
3312signal_stmt:
3313          SIGNAL_SYM signal_value opt_set_signal_information
3314          {
3315            if (Lex->add_signal_statement(thd, $2))
3316              MYSQL_YYABORT;
3317          }
3318        ;
3319
3320signal_value:
3321          ident
3322          {
3323            if (!($$= Lex->stmt_signal_value($1)))
3324              MYSQL_YYABORT;
3325          }
3326        | sqlstate
3327          { $$= $1; }
3328        ;
3329
3330opt_signal_value:
3331          /* empty */
3332          { $$= NULL; }
3333        | signal_value
3334          { $$= $1; }
3335        ;
3336
3337opt_set_signal_information:
3338          /* empty */
3339          {
3340            thd->m_parser_state->m_yacc.m_set_signal_info.clear();
3341          }
3342        | SET signal_information_item_list
3343        ;
3344
3345signal_information_item_list:
3346          signal_condition_information_item_name '=' signal_allowed_expr
3347          {
3348            Set_signal_information *info;
3349            info= &thd->m_parser_state->m_yacc.m_set_signal_info;
3350            int index= (int) $1;
3351            info->clear();
3352            info->m_item[index]= $3;
3353          }
3354        | signal_information_item_list ','
3355          signal_condition_information_item_name '=' signal_allowed_expr
3356          {
3357            Set_signal_information *info;
3358            info= &thd->m_parser_state->m_yacc.m_set_signal_info;
3359            int index= (int) $3;
3360            if (unlikely(info->m_item[index] != NULL))
3361              my_yyabort_error((ER_DUP_SIGNAL_SET, MYF(0),
3362                                Diag_condition_item_names[index].str));
3363            info->m_item[index]= $5;
3364          }
3365        ;
3366
3367/*
3368  Only a limited subset of <expr> are allowed in SIGNAL/RESIGNAL.
3369*/
3370signal_allowed_expr:
3371          literal
3372          { $$= $1; }
3373        | variable
3374          {
3375            if ($1->type() == Item::FUNC_ITEM)
3376            {
3377              Item_func *item= (Item_func*) $1;
3378              if (unlikely(item->functype() == Item_func::SUSERVAR_FUNC))
3379              {
3380                /*
3381                  Don't allow the following syntax:
3382                    SIGNAL/RESIGNAL ...
3383                    SET <signal condition item name> = @foo := expr
3384                */
3385                thd->parse_error();
3386                MYSQL_YYABORT;
3387              }
3388            }
3389            $$= $1;
3390          }
3391        | simple_ident
3392          { $$= $1; }
3393        ;
3394
3395/* conditions that can be set in signal / resignal */
3396signal_condition_information_item_name:
3397          CLASS_ORIGIN_SYM
3398          { $$= DIAG_CLASS_ORIGIN; }
3399        | SUBCLASS_ORIGIN_SYM
3400          { $$= DIAG_SUBCLASS_ORIGIN; }
3401        | CONSTRAINT_CATALOG_SYM
3402          { $$= DIAG_CONSTRAINT_CATALOG; }
3403        | CONSTRAINT_SCHEMA_SYM
3404          { $$= DIAG_CONSTRAINT_SCHEMA; }
3405        | CONSTRAINT_NAME_SYM
3406          { $$= DIAG_CONSTRAINT_NAME; }
3407        | CATALOG_NAME_SYM
3408          { $$= DIAG_CATALOG_NAME; }
3409        | SCHEMA_NAME_SYM
3410          { $$= DIAG_SCHEMA_NAME; }
3411        | TABLE_NAME_SYM
3412          { $$= DIAG_TABLE_NAME; }
3413        | COLUMN_NAME_SYM
3414          { $$= DIAG_COLUMN_NAME; }
3415        | CURSOR_NAME_SYM
3416          { $$= DIAG_CURSOR_NAME; }
3417        | MESSAGE_TEXT_SYM
3418          { $$= DIAG_MESSAGE_TEXT; }
3419        | MYSQL_ERRNO_SYM
3420          { $$= DIAG_MYSQL_ERRNO; }
3421        ;
3422
3423resignal_stmt:
3424          RESIGNAL_SYM opt_signal_value opt_set_signal_information
3425          {
3426            if (unlikely(Lex->add_resignal_statement(thd, $2)))
3427              MYSQL_YYABORT;
3428          }
3429        ;
3430
3431get_diagnostics:
3432          GET_SYM which_area DIAGNOSTICS_SYM diagnostics_information
3433          {
3434            Diagnostics_information *info= $4;
3435
3436            info->set_which_da($2);
3437
3438            Lex->sql_command= SQLCOM_GET_DIAGNOSTICS;
3439            Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_get_diagnostics(info);
3440
3441            if (unlikely(Lex->m_sql_cmd == NULL))
3442              MYSQL_YYABORT;
3443          }
3444        ;
3445
3446which_area:
3447        /* If <which area> is not specified, then CURRENT is implicit. */
3448          { $$= Diagnostics_information::CURRENT_AREA; }
3449        | CURRENT_SYM
3450          { $$= Diagnostics_information::CURRENT_AREA; }
3451        ;
3452
3453diagnostics_information:
3454          statement_information
3455          {
3456            $$= new (thd->mem_root) Statement_information($1);
3457            if (unlikely($$ == NULL))
3458              MYSQL_YYABORT;
3459          }
3460        | CONDITION_SYM condition_number condition_information
3461          {
3462            $$= new (thd->mem_root) Condition_information($2, $3);
3463            if (unlikely($$ == NULL))
3464              MYSQL_YYABORT;
3465          }
3466        ;
3467
3468statement_information:
3469          statement_information_item
3470          {
3471            $$= new (thd->mem_root) List<Statement_information_item>;
3472            if (unlikely($$ == NULL) ||
3473                unlikely($$->push_back($1, thd->mem_root)))
3474              MYSQL_YYABORT;
3475          }
3476        | statement_information ',' statement_information_item
3477          {
3478            if (unlikely($1->push_back($3, thd->mem_root)))
3479              MYSQL_YYABORT;
3480            $$= $1;
3481          }
3482        ;
3483
3484statement_information_item:
3485          simple_target_specification '=' statement_information_item_name
3486          {
3487            $$= new (thd->mem_root) Statement_information_item($3, $1);
3488            if (unlikely($$ == NULL))
3489              MYSQL_YYABORT;
3490          }
3491        ;
3492
3493simple_target_specification:
3494          ident_cli
3495          {
3496            if (unlikely(!($$= thd->lex->create_item_for_sp_var(&$1, NULL))))
3497              MYSQL_YYABORT;
3498          }
3499        | '@' ident_or_text
3500          {
3501            $$= new (thd->mem_root) Item_func_get_user_var(thd, &$2);
3502            if (unlikely($$ == NULL))
3503              MYSQL_YYABORT;
3504          }
3505        ;
3506
3507statement_information_item_name:
3508          NUMBER_MARIADB_SYM
3509          { $$= Statement_information_item::NUMBER; }
3510        | NUMBER_ORACLE_SYM
3511          { $$= Statement_information_item::NUMBER; }
3512        | ROW_COUNT_SYM
3513          { $$= Statement_information_item::ROW_COUNT; }
3514        ;
3515
3516/*
3517   Only a limited subset of <expr> are allowed in GET DIAGNOSTICS
3518   <condition number>, same subset as for SIGNAL/RESIGNAL.
3519*/
3520condition_number:
3521          signal_allowed_expr
3522          { $$= $1; }
3523        ;
3524
3525condition_information:
3526          condition_information_item
3527          {
3528            $$= new (thd->mem_root) List<Condition_information_item>;
3529            if (unlikely($$ == NULL) ||
3530                unlikely($$->push_back($1, thd->mem_root)))
3531              MYSQL_YYABORT;
3532          }
3533        | condition_information ',' condition_information_item
3534          {
3535            if (unlikely($1->push_back($3, thd->mem_root)))
3536              MYSQL_YYABORT;
3537            $$= $1;
3538          }
3539        ;
3540
3541condition_information_item:
3542          simple_target_specification '=' condition_information_item_name
3543          {
3544            $$= new (thd->mem_root) Condition_information_item($3, $1);
3545            if (unlikely($$ == NULL))
3546              MYSQL_YYABORT;
3547          }
3548        ;
3549
3550condition_information_item_name:
3551          CLASS_ORIGIN_SYM
3552          { $$= Condition_information_item::CLASS_ORIGIN; }
3553        | SUBCLASS_ORIGIN_SYM
3554          { $$= Condition_information_item::SUBCLASS_ORIGIN; }
3555        | CONSTRAINT_CATALOG_SYM
3556          { $$= Condition_information_item::CONSTRAINT_CATALOG; }
3557        | CONSTRAINT_SCHEMA_SYM
3558          { $$= Condition_information_item::CONSTRAINT_SCHEMA; }
3559        | CONSTRAINT_NAME_SYM
3560          { $$= Condition_information_item::CONSTRAINT_NAME; }
3561        | CATALOG_NAME_SYM
3562          { $$= Condition_information_item::CATALOG_NAME; }
3563        | SCHEMA_NAME_SYM
3564          { $$= Condition_information_item::SCHEMA_NAME; }
3565        | TABLE_NAME_SYM
3566          { $$= Condition_information_item::TABLE_NAME; }
3567        | COLUMN_NAME_SYM
3568          { $$= Condition_information_item::COLUMN_NAME; }
3569        | CURSOR_NAME_SYM
3570          { $$= Condition_information_item::CURSOR_NAME; }
3571        | MESSAGE_TEXT_SYM
3572          { $$= Condition_information_item::MESSAGE_TEXT; }
3573        | MYSQL_ERRNO_SYM
3574          { $$= Condition_information_item::MYSQL_ERRNO; }
3575        | RETURNED_SQLSTATE_SYM
3576          { $$= Condition_information_item::RETURNED_SQLSTATE; }
3577        ;
3578
3579sp_decl_ident:
3580          IDENT_sys
3581        | keyword_sp_decl
3582          {
3583            if (unlikely($$.copy_ident_cli(thd, &$1)))
3584              MYSQL_YYABORT;
3585          }
3586        ;
3587
3588sp_decl_idents:
3589          sp_decl_ident
3590          {
3591            /* NOTE: field definition is filled in sp_decl section. */
3592
3593            LEX *lex= Lex;
3594            sp_pcontext *spc= lex->spcont;
3595
3596            if (unlikely(spc->find_variable(&$1, TRUE)))
3597              my_yyabort_error((ER_SP_DUP_VAR, MYF(0), $1.str));
3598            spc->add_variable(thd, &$1);
3599            $$= 1;
3600          }
3601        | sp_decl_idents ',' ident
3602          {
3603            /* NOTE: field definition is filled in sp_decl section. */
3604
3605            LEX *lex= Lex;
3606            sp_pcontext *spc= lex->spcont;
3607
3608            if (unlikely(spc->find_variable(&$3, TRUE)))
3609              my_yyabort_error((ER_SP_DUP_VAR, MYF(0), $3.str));
3610            spc->add_variable(thd, &$3);
3611            $$= $1 + 1;
3612          }
3613        ;
3614
3615sp_proc_stmt_if:
3616          IF_SYM
3617          {
3618            if (unlikely(Lex->maybe_start_compound_statement(thd)))
3619              MYSQL_YYABORT;
3620            Lex->sphead->new_cont_backpatch(NULL);
3621          }
3622          sp_if END IF_SYM
3623          { Lex->sphead->do_cont_backpatch(); }
3624        ;
3625
3626sp_proc_stmt_statement:
3627          {
3628            LEX *lex= thd->lex;
3629            Lex_input_stream *lip= YYLIP;
3630
3631            lex->sphead->reset_lex(thd);
3632            /*
3633              We should not push main select here, it will be done or not
3634              done by the statement, we just provide only a new LEX for the
3635              statement here as if it is start of parsing a new statement.
3636            */
3637            lex->sphead->m_tmp_query= lip->get_tok_start();
3638          }
3639          sp_statement
3640          {
3641            if (Lex->sp_proc_stmt_statement_finalize(thd, yychar == YYEMPTY) ||
3642                Lex->sphead->restore_lex(thd))
3643              MYSQL_YYABORT;
3644          }
3645        ;
3646
3647
3648RETURN_ALLMODES_SYM:
3649          RETURN_MARIADB_SYM
3650        | RETURN_ORACLE_SYM
3651        ;
3652
3653sp_proc_stmt_return:
3654          RETURN_ALLMODES_SYM expr_lex
3655          {
3656            sp_head *sp= $2->sphead;
3657            if (unlikely(sp->m_handler->add_instr_freturn(thd, sp, $2->spcont,
3658                                                          $2->get_item(), $2)))
3659              MYSQL_YYABORT;
3660          }
3661        | RETURN_ORACLE_SYM
3662          {
3663            LEX *lex= Lex;
3664            sp_head *sp= lex->sphead;
3665            if (unlikely(sp->m_handler->add_instr_preturn(thd, sp,
3666                                                               lex->spcont)))
3667              MYSQL_YYABORT;
3668          }
3669        ;
3670
3671sp_proc_stmt_exit_oracle:
3672          EXIT_ORACLE_SYM
3673          {
3674            if (unlikely(Lex->sp_exit_statement(thd, NULL)))
3675              MYSQL_YYABORT;
3676          }
3677        | EXIT_ORACLE_SYM label_ident
3678          {
3679            if (unlikely(Lex->sp_exit_statement(thd, &$2, NULL)))
3680              MYSQL_YYABORT;
3681          }
3682        | EXIT_ORACLE_SYM WHEN_SYM expr_lex
3683          {
3684            if (unlikely($3->sp_exit_statement(thd, $3->get_item())))
3685              MYSQL_YYABORT;
3686          }
3687        | EXIT_ORACLE_SYM label_ident WHEN_SYM expr_lex
3688          {
3689            if (unlikely($4->sp_exit_statement(thd, &$2, $4->get_item())))
3690              MYSQL_YYABORT;
3691          }
3692        ;
3693
3694sp_proc_stmt_continue_oracle:
3695          CONTINUE_ORACLE_SYM
3696          {
3697            if (unlikely(Lex->sp_continue_statement(thd)))
3698              MYSQL_YYABORT;
3699          }
3700        | CONTINUE_ORACLE_SYM label_ident
3701          {
3702            if (unlikely(Lex->sp_continue_statement(thd, &$2)))
3703              MYSQL_YYABORT;
3704          }
3705        | CONTINUE_ORACLE_SYM WHEN_SYM expr_lex
3706          {
3707            if (unlikely($3->sp_continue_when_statement(thd)))
3708              MYSQL_YYABORT;
3709          }
3710        | CONTINUE_ORACLE_SYM label_ident WHEN_SYM expr_lex
3711          {
3712            if (unlikely($4->sp_continue_when_statement(thd, &$2)))
3713              MYSQL_YYABORT;
3714          }
3715        ;
3716
3717
3718sp_proc_stmt_leave:
3719          LEAVE_SYM label_ident
3720          {
3721            if (unlikely(Lex->sp_leave_statement(thd, &$2)))
3722              MYSQL_YYABORT;
3723          }
3724        ;
3725
3726sp_proc_stmt_iterate:
3727          ITERATE_SYM label_ident
3728          {
3729            if (unlikely(Lex->sp_iterate_statement(thd, &$2)))
3730              MYSQL_YYABORT;
3731          }
3732        ;
3733
3734sp_proc_stmt_goto_oracle:
3735          GOTO_ORACLE_SYM label_ident
3736          {
3737            if (unlikely(Lex->sp_goto_statement(thd, &$2)))
3738              MYSQL_YYABORT;
3739          }
3740        ;
3741
3742
3743expr_lex:
3744          {
3745            DBUG_ASSERT(Lex->sphead);
3746            if (unlikely(!($<expr_lex>$= new (thd->mem_root)
3747                           sp_expr_lex(thd, thd->lex))))
3748              MYSQL_YYABORT;
3749            Lex->sphead->reset_lex(thd, $<expr_lex>$);
3750            if (Lex->main_select_push(true))
3751              MYSQL_YYABORT;
3752          }
3753          expr
3754          {
3755            $$= $<expr_lex>1;
3756            $$->sp_lex_in_use= true;
3757            $$->set_item($2);
3758            Lex->pop_select(); //min select
3759            if (Lex->check_cte_dependencies_and_resolve_references())
3760              MYSQL_YYABORT;
3761            if ($$->sphead->restore_lex(thd))
3762              MYSQL_YYABORT;
3763          }
3764        ;
3765
3766
3767assignment_source_lex:
3768          {
3769            DBUG_ASSERT(Lex->sphead);
3770            if (unlikely(!($$= new (thd->mem_root)
3771                           sp_assignment_lex(thd, thd->lex))))
3772              MYSQL_YYABORT;
3773          }
3774        ;
3775
3776assignment_source_expr:
3777          assignment_source_lex
3778          {
3779            DBUG_ASSERT(thd->free_list == NULL);
3780            Lex->sphead->reset_lex(thd, $1);
3781            if (Lex->main_select_push(true))
3782              MYSQL_YYABORT;
3783          }
3784          expr
3785          {
3786            DBUG_ASSERT($1 == thd->lex);
3787            $$= $1;
3788            $$->sp_lex_in_use= true;
3789            $$->set_item_and_free_list($3, thd->free_list);
3790            thd->free_list= NULL;
3791            Lex->pop_select(); //min select
3792            if ($$->sphead->restore_lex(thd))
3793              MYSQL_YYABORT;
3794          }
3795        ;
3796
3797for_loop_bound_expr:
3798          assignment_source_lex
3799          {
3800            Lex->sphead->reset_lex(thd, $1);
3801            if (Lex->main_select_push(true))
3802              MYSQL_YYABORT;
3803            Lex->current_select->parsing_place= FOR_LOOP_BOUND;
3804          }
3805          expr
3806          {
3807            DBUG_ASSERT($1 == thd->lex);
3808            $$= $1;
3809            $$->sp_lex_in_use= true;
3810            $$->set_item_and_free_list($3, NULL);
3811            Lex->pop_select(); //main select
3812            if (unlikely($$->sphead->restore_lex(thd)))
3813              MYSQL_YYABORT;
3814            Lex->current_select->parsing_place= NO_MATTER;
3815          }
3816        ;
3817
3818cursor_actual_parameters:
3819          assignment_source_expr
3820          {
3821            if (unlikely(!($$= new (thd->mem_root) List<sp_assignment_lex>)))
3822              MYSQL_YYABORT;
3823            $$->push_back($1, thd->mem_root);
3824          }
3825        | cursor_actual_parameters ',' assignment_source_expr
3826          {
3827            $$= $1;
3828            $$->push_back($3, thd->mem_root);
3829          }
3830        ;
3831
3832opt_parenthesized_cursor_actual_parameters:
3833          /* Empty */                        { $$= NULL; }
3834        | '(' cursor_actual_parameters ')'   { $$= $2; }
3835        ;
3836
3837sp_proc_stmt_with_cursor:
3838         sp_proc_stmt_open
3839       | sp_proc_stmt_fetch
3840       | sp_proc_stmt_close
3841       ;
3842
3843sp_proc_stmt_open:
3844          OPEN_SYM ident opt_parenthesized_cursor_actual_parameters
3845          {
3846            if (unlikely(Lex->sp_open_cursor(thd, &$2, $3)))
3847              MYSQL_YYABORT;
3848          }
3849        ;
3850
3851sp_proc_stmt_fetch_head:
3852          FETCH_SYM ident INTO
3853          {
3854            if (unlikely(Lex->sp_add_cfetch(thd, &$2)))
3855              MYSQL_YYABORT;
3856          }
3857        | FETCH_SYM FROM ident INTO
3858          {
3859            if (unlikely(Lex->sp_add_cfetch(thd, &$3)))
3860              MYSQL_YYABORT;
3861          }
3862       | FETCH_SYM NEXT_SYM FROM ident INTO
3863          {
3864            if (unlikely(Lex->sp_add_cfetch(thd, &$4)))
3865              MYSQL_YYABORT;
3866          }
3867        ;
3868
3869sp_proc_stmt_fetch:
3870         sp_proc_stmt_fetch_head sp_fetch_list { }
3871       | FETCH_SYM GROUP_SYM NEXT_SYM ROW_SYM
3872         {
3873           if (unlikely(Lex->sp_add_agg_cfetch()))
3874             MYSQL_YYABORT;
3875         }
3876        ;
3877
3878sp_proc_stmt_close:
3879          CLOSE_SYM ident
3880          {
3881            LEX *lex= Lex;
3882            sp_head *sp= lex->sphead;
3883            uint offset;
3884            sp_instr_cclose *i;
3885
3886            if (unlikely(!lex->spcont->find_cursor(&$2, &offset, false)))
3887              my_yyabort_error((ER_SP_CURSOR_MISMATCH, MYF(0), $2.str));
3888            i= new (thd->mem_root)
3889              sp_instr_cclose(sp->instructions(), lex->spcont,  offset);
3890            if (unlikely(i == NULL) ||
3891                unlikely(sp->add_instr(i)))
3892              MYSQL_YYABORT;
3893          }
3894        ;
3895
3896sp_fetch_list:
3897          ident
3898          {
3899            LEX *lex= Lex;
3900            sp_head *sp= lex->sphead;
3901            sp_pcontext *spc= lex->spcont;
3902            sp_variable *spv= likely(spc != NULL)
3903              ? spc->find_variable(&$1, false)
3904              : NULL;
3905
3906            if (unlikely(!spv))
3907              my_yyabort_error((ER_SP_UNDECLARED_VAR, MYF(0), $1.str));
3908
3909            /* An SP local variable */
3910            sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction();
3911            i->add_to_varlist(spv);
3912          }
3913        | sp_fetch_list ',' ident
3914          {
3915            LEX *lex= Lex;
3916            sp_head *sp= lex->sphead;
3917            sp_pcontext *spc= lex->spcont;
3918            sp_variable *spv= likely(spc != NULL)
3919              ? spc->find_variable(&$3, false)
3920              : NULL;
3921
3922            if (unlikely(!spv))
3923              my_yyabort_error((ER_SP_UNDECLARED_VAR, MYF(0), $3.str));
3924
3925            /* An SP local variable */
3926            sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction();
3927            i->add_to_varlist(spv);
3928          }
3929        ;
3930
3931sp_if:
3932          expr_lex THEN_SYM
3933          {
3934            if (unlikely($1->sp_if_expr(thd)))
3935              MYSQL_YYABORT;
3936          }
3937          sp_if_then_statements
3938          {
3939            if (unlikely($1->sp_if_after_statements(thd)))
3940              MYSQL_YYABORT;
3941          }
3942          sp_elseifs
3943          {
3944            LEX *lex= Lex;
3945
3946            lex->sphead->backpatch(lex->spcont->pop_label());
3947          }
3948        ;
3949
3950sp_elseifs:
3951          /* Empty */
3952        | ELSEIF_MARIADB_SYM sp_if
3953        | ELSIF_ORACLE_SYM sp_if
3954        | ELSE sp_if_then_statements
3955        ;
3956
3957case_stmt_specification:
3958          CASE_SYM
3959          {
3960            if (unlikely(Lex->maybe_start_compound_statement(thd)))
3961              MYSQL_YYABORT;
3962
3963            /**
3964              An example of the CASE statement in use is
3965            <pre>
3966            CREATE PROCEDURE proc_19194_simple(i int)
3967            BEGIN
3968              DECLARE str CHAR(10);
3969
3970              CASE i
3971                WHEN 1 THEN SET str="1";
3972                WHEN 2 THEN SET str="2";
3973                WHEN 3 THEN SET str="3";
3974                ELSE SET str="unknown";
3975              END CASE;
3976
3977              SELECT str;
3978            END
3979            </pre>
3980              The actions are used to generate the following code:
3981            <pre>
3982            SHOW PROCEDURE CODE proc_19194_simple;
3983            Pos     Instruction
3984            0       set str@1 NULL
3985            1       set_case_expr (12) 0 i@0
3986            2       jump_if_not 5(12) (case_expr@0 = 1)
3987            3       set str@1 _latin1'1'
3988            4       jump 12
3989            5       jump_if_not 8(12) (case_expr@0 = 2)
3990            6       set str@1 _latin1'2'
3991            7       jump 12
3992            8       jump_if_not 11(12) (case_expr@0 = 3)
3993            9       set str@1 _latin1'3'
3994            10      jump 12
3995            11      set str@1 _latin1'unknown'
3996            12      stmt 0 "SELECT str"
3997            </pre>
3998            */
3999
4000            Lex->sphead->new_cont_backpatch(NULL);
4001
4002            /*
4003              BACKPATCH: Creating target label for the jump to after END CASE
4004              (instruction 12 in the example)
4005            */
4006            Lex->spcont->push_label(thd, &empty_clex_str, Lex->sphead->instructions());
4007          }
4008          case_stmt_body
4009          else_clause_opt
4010          END
4011          CASE_SYM
4012          {
4013            /*
4014              BACKPATCH: Resolving forward jump from
4015              "case_stmt_action_then" to after END CASE
4016              (jump from instruction 4 to 12, 7 to 12 ... in the example)
4017            */
4018            Lex->sphead->backpatch(Lex->spcont->pop_label());
4019
4020            if ($3)
4021              Lex->spcont->pop_case_expr_id();
4022
4023            Lex->sphead->do_cont_backpatch();
4024          }
4025        ;
4026
4027case_stmt_body:
4028          expr_lex
4029          {
4030            if (unlikely($1->case_stmt_action_expr()))
4031              MYSQL_YYABORT;
4032          }
4033          simple_when_clause_list
4034          { $$= 1; }
4035        | searched_when_clause_list
4036          { $$= 0; }
4037        ;
4038
4039simple_when_clause_list:
4040          simple_when_clause
4041        | simple_when_clause_list simple_when_clause
4042        ;
4043
4044searched_when_clause_list:
4045          searched_when_clause
4046        | searched_when_clause_list searched_when_clause
4047        ;
4048
4049simple_when_clause:
4050          WHEN_SYM expr_lex
4051          {
4052            /* Simple case: <caseval> = <whenval> */
4053            if (unlikely($2->case_stmt_action_when(true)))
4054              MYSQL_YYABORT;
4055          }
4056          THEN_SYM
4057          sp_case_then_statements
4058          {
4059            if (unlikely(Lex->case_stmt_action_then()))
4060              MYSQL_YYABORT;
4061          }
4062        ;
4063
4064searched_when_clause:
4065          WHEN_SYM expr_lex
4066          {
4067            if (unlikely($2->case_stmt_action_when(false)))
4068              MYSQL_YYABORT;
4069          }
4070          THEN_SYM
4071          sp_case_then_statements
4072          {
4073            if (unlikely(Lex->case_stmt_action_then()))
4074              MYSQL_YYABORT;
4075          }
4076        ;
4077
4078else_clause_opt:
4079          /* empty */
4080          {
4081            LEX *lex= Lex;
4082            sp_head *sp= lex->sphead;
4083            uint ip= sp->instructions();
4084            sp_instr_error *i= new (thd->mem_root)
4085              sp_instr_error(ip, lex->spcont, ER_SP_CASE_NOT_FOUND);
4086            if (unlikely(i == NULL) ||
4087                unlikely(sp->add_instr(i)))
4088              MYSQL_YYABORT;
4089          }
4090        | ELSE sp_case_then_statements
4091        ;
4092
4093sp_opt_label:
4094          /* Empty  */  { $$= null_clex_str; }
4095        | label_ident   { $$= $1; }
4096        ;
4097
4098/* This adds one shift/reduce conflict */
4099opt_sp_for_loop_direction:
4100            /* Empty */ { $$= 1; }
4101          | REVERSE_SYM { $$= -1; }
4102        ;
4103
4104sp_for_loop_index_and_bounds:
4105          ident_for_loop_index sp_for_loop_bounds
4106          {
4107            if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $2)))
4108              MYSQL_YYABORT;
4109          }
4110        ;
4111
4112sp_for_loop_bounds:
4113          IN_SYM opt_sp_for_loop_direction for_loop_bound_expr
4114          DOT_DOT_SYM for_loop_bound_expr
4115          {
4116            $$= Lex_for_loop_bounds_intrange($2, $3, $5);
4117          }
4118        | IN_SYM opt_sp_for_loop_direction for_loop_bound_expr
4119          {
4120            $$.m_direction= $2;
4121            $$.m_index= $3;
4122            $$.m_target_bound= NULL;
4123            $$.m_implicit_cursor= false;
4124          }
4125        | IN_SYM opt_sp_for_loop_direction '(' sp_cursor_stmt ')'
4126          {
4127            if (unlikely(Lex->sp_for_loop_implicit_cursor_statement(thd, &$$,
4128                                                                    $4)))
4129              MYSQL_YYABORT;
4130          }
4131        ;
4132
4133loop_body:
4134          sp_proc_stmts1 END LOOP_SYM
4135          {
4136            LEX *lex= Lex;
4137            uint ip= lex->sphead->instructions();
4138            sp_label *lab= lex->spcont->last_label();  /* Jumping back */
4139            sp_instr_jump *i= new (thd->mem_root)
4140              sp_instr_jump(ip, lex->spcont, lab->ip);
4141            if (unlikely(i == NULL) ||
4142                unlikely(lex->sphead->add_instr(i)))
4143              MYSQL_YYABORT;
4144          }
4145        ;
4146
4147repeat_body:
4148          sp_proc_stmts1 UNTIL_SYM expr_lex END REPEAT_SYM
4149          {
4150            if ($3->sp_repeat_loop_finalize(thd))
4151              MYSQL_YYABORT;
4152          }
4153        ;
4154
4155pop_sp_loop_label:
4156          sp_opt_label
4157          {
4158            if (unlikely(Lex->sp_pop_loop_label(thd, &$1)))
4159              MYSQL_YYABORT;
4160          }
4161        ;
4162
4163sp_labeled_control:
4164          sp_control_label LOOP_SYM
4165          {
4166            if (unlikely(Lex->sp_push_loop_label(thd, &$1)))
4167              MYSQL_YYABORT;
4168          }
4169          loop_body pop_sp_loop_label
4170          { }
4171        | sp_control_label WHILE_SYM
4172          {
4173            if (unlikely(Lex->sp_push_loop_label(thd, &$1)))
4174              MYSQL_YYABORT;
4175          }
4176          while_body pop_sp_loop_label
4177          { }
4178        | sp_control_label FOR_SYM
4179          {
4180            // See "The FOR LOOP statement" comments in sql_lex.cc
4181            Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block
4182          }
4183          sp_for_loop_index_and_bounds
4184          {
4185            if (unlikely(Lex->sp_push_loop_label(thd, &$1))) // The inner WHILE block
4186              MYSQL_YYABORT;
4187            if (unlikely(Lex->sp_for_loop_condition_test(thd, $4)))
4188              MYSQL_YYABORT;
4189          }
4190          for_loop_statements
4191          {
4192            if (unlikely(Lex->sp_for_loop_finalize(thd, $4)))
4193              MYSQL_YYABORT;
4194          }
4195          pop_sp_loop_label                    // The inner WHILE block
4196          {
4197            if (unlikely(Lex->sp_for_loop_outer_block_finalize(thd, $4)))
4198              MYSQL_YYABORT;
4199          }
4200        | sp_control_label REPEAT_SYM
4201          {
4202            if (unlikely(Lex->sp_push_loop_label(thd, &$1)))
4203              MYSQL_YYABORT;
4204          }
4205          repeat_body pop_sp_loop_label
4206          { }
4207        ;
4208
4209sp_unlabeled_control:
4210          LOOP_SYM
4211          {
4212            if (unlikely(Lex->sp_push_loop_empty_label(thd)))
4213              MYSQL_YYABORT;
4214          }
4215          loop_body
4216          {
4217            Lex->sp_pop_loop_empty_label(thd);
4218          }
4219        | WHILE_SYM
4220          {
4221            if (unlikely(Lex->sp_push_loop_empty_label(thd)))
4222              MYSQL_YYABORT;
4223          }
4224          while_body
4225          {
4226            Lex->sp_pop_loop_empty_label(thd);
4227          }
4228        | FOR_SYM
4229          {
4230            // See "The FOR LOOP statement" comments in sql_lex.cc
4231            if (unlikely(Lex->maybe_start_compound_statement(thd)))
4232              MYSQL_YYABORT;
4233            Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block
4234          }
4235          sp_for_loop_index_and_bounds
4236          {
4237            if (unlikely(Lex->sp_push_loop_empty_label(thd))) // The inner WHILE block
4238              MYSQL_YYABORT;
4239            if (unlikely(Lex->sp_for_loop_condition_test(thd, $3)))
4240              MYSQL_YYABORT;
4241          }
4242          for_loop_statements
4243          {
4244            if (unlikely(Lex->sp_for_loop_finalize(thd, $3)))
4245              MYSQL_YYABORT;
4246            Lex->sp_pop_loop_empty_label(thd); // The inner WHILE block
4247            if (unlikely(Lex->sp_for_loop_outer_block_finalize(thd, $3)))
4248              MYSQL_YYABORT;
4249          }
4250        | REPEAT_SYM
4251          {
4252            if (unlikely(Lex->sp_push_loop_empty_label(thd)))
4253              MYSQL_YYABORT;
4254          }
4255          repeat_body
4256          {
4257            Lex->sp_pop_loop_empty_label(thd);
4258          }
4259        ;
4260
4261trg_action_time:
4262            BEFORE_SYM
4263            { Lex->trg_chistics.action_time= TRG_ACTION_BEFORE; }
4264          | AFTER_SYM
4265            { Lex->trg_chistics.action_time= TRG_ACTION_AFTER; }
4266          ;
4267
4268trg_event:
4269            INSERT
4270            { Lex->trg_chistics.event= TRG_EVENT_INSERT; }
4271          | UPDATE_SYM
4272            { Lex->trg_chistics.event= TRG_EVENT_UPDATE; }
4273          | DELETE_SYM
4274            { Lex->trg_chistics.event= TRG_EVENT_DELETE; }
4275          ;
4276/*
4277  This part of the parser contains common code for all TABLESPACE
4278  commands.
4279  CREATE TABLESPACE name ...
4280  ALTER TABLESPACE name CHANGE DATAFILE ...
4281  ALTER TABLESPACE name ADD DATAFILE ...
4282  ALTER TABLESPACE name access_mode
4283  CREATE LOGFILE GROUP_SYM name ...
4284  ALTER LOGFILE GROUP_SYM name ADD UNDOFILE ..
4285  ALTER LOGFILE GROUP_SYM name ADD REDOFILE ..
4286  DROP TABLESPACE name
4287  DROP LOGFILE GROUP_SYM name
4288*/
4289change_tablespace_access:
4290          tablespace_name
4291          ts_access_mode
4292        ;
4293
4294change_tablespace_info:
4295          tablespace_name
4296          CHANGE ts_datafile
4297          change_ts_option_list
4298        ;
4299
4300tablespace_info:
4301          tablespace_name
4302          ADD ts_datafile
4303          opt_logfile_group_name
4304          tablespace_option_list
4305        ;
4306
4307opt_logfile_group_name:
4308          /* empty */ {}
4309        | USE_SYM LOGFILE_SYM GROUP_SYM ident
4310          {
4311            LEX *lex= Lex;
4312            lex->alter_tablespace_info->logfile_group_name= $4.str;
4313          }
4314        ;
4315
4316alter_tablespace_info:
4317          tablespace_name
4318          ADD ts_datafile
4319          alter_tablespace_option_list
4320          {
4321            Lex->alter_tablespace_info->ts_alter_tablespace_type= ALTER_TABLESPACE_ADD_FILE;
4322          }
4323        | tablespace_name
4324          DROP ts_datafile
4325          alter_tablespace_option_list
4326          {
4327            Lex->alter_tablespace_info->ts_alter_tablespace_type= ALTER_TABLESPACE_DROP_FILE;
4328          }
4329        ;
4330
4331logfile_group_info:
4332          logfile_group_name
4333          add_log_file
4334          logfile_group_option_list
4335        ;
4336
4337alter_logfile_group_info:
4338          logfile_group_name
4339          add_log_file
4340          alter_logfile_group_option_list
4341        ;
4342
4343add_log_file:
4344          ADD lg_undofile
4345        | ADD lg_redofile
4346        ;
4347
4348change_ts_option_list:
4349          /* empty */ {}
4350          change_ts_options
4351        ;
4352
4353change_ts_options:
4354          change_ts_option
4355        | change_ts_options change_ts_option
4356        | change_ts_options ',' change_ts_option
4357        ;
4358
4359change_ts_option:
4360          opt_ts_initial_size
4361        | opt_ts_autoextend_size
4362        | opt_ts_max_size
4363        ;
4364
4365tablespace_option_list:
4366        tablespace_options
4367        ;
4368
4369tablespace_options:
4370          tablespace_option
4371        | tablespace_options tablespace_option
4372        | tablespace_options ',' tablespace_option
4373        ;
4374
4375tablespace_option:
4376          opt_ts_initial_size
4377        | opt_ts_autoextend_size
4378        | opt_ts_max_size
4379        | opt_ts_extent_size
4380        | opt_ts_nodegroup
4381        | opt_ts_engine
4382        | ts_wait
4383        | opt_ts_comment
4384        ;
4385
4386alter_tablespace_option_list:
4387        alter_tablespace_options
4388        ;
4389
4390alter_tablespace_options:
4391          alter_tablespace_option
4392        | alter_tablespace_options alter_tablespace_option
4393        | alter_tablespace_options ',' alter_tablespace_option
4394        ;
4395
4396alter_tablespace_option:
4397          opt_ts_initial_size
4398        | opt_ts_autoextend_size
4399        | opt_ts_max_size
4400        | opt_ts_engine
4401        | ts_wait
4402        ;
4403
4404logfile_group_option_list:
4405        logfile_group_options
4406        ;
4407
4408logfile_group_options:
4409          logfile_group_option
4410        | logfile_group_options logfile_group_option
4411        | logfile_group_options ',' logfile_group_option
4412        ;
4413
4414logfile_group_option:
4415          opt_ts_initial_size
4416        | opt_ts_undo_buffer_size
4417        | opt_ts_redo_buffer_size
4418        | opt_ts_nodegroup
4419        | opt_ts_engine
4420        | ts_wait
4421        | opt_ts_comment
4422        ;
4423
4424alter_logfile_group_option_list:
4425          alter_logfile_group_options
4426        ;
4427
4428alter_logfile_group_options:
4429          alter_logfile_group_option
4430        | alter_logfile_group_options alter_logfile_group_option
4431        | alter_logfile_group_options ',' alter_logfile_group_option
4432        ;
4433
4434alter_logfile_group_option:
4435          opt_ts_initial_size
4436        | opt_ts_engine
4437        | ts_wait
4438        ;
4439
4440
4441ts_datafile:
4442          DATAFILE_SYM TEXT_STRING_sys
4443          {
4444            LEX *lex= Lex;
4445            lex->alter_tablespace_info->data_file_name= $2.str;
4446          }
4447        ;
4448
4449lg_undofile:
4450          UNDOFILE_SYM TEXT_STRING_sys
4451          {
4452            LEX *lex= Lex;
4453            lex->alter_tablespace_info->undo_file_name= $2.str;
4454          }
4455        ;
4456
4457lg_redofile:
4458          REDOFILE_SYM TEXT_STRING_sys
4459          {
4460            LEX *lex= Lex;
4461            lex->alter_tablespace_info->redo_file_name= $2.str;
4462          }
4463        ;
4464
4465tablespace_name:
4466          ident
4467          {
4468            LEX *lex= Lex;
4469            lex->alter_tablespace_info= (new (thd->mem_root)
4470                                         st_alter_tablespace());
4471            if (unlikely(lex->alter_tablespace_info == NULL))
4472              MYSQL_YYABORT;
4473            lex->alter_tablespace_info->tablespace_name= $1.str;
4474            lex->sql_command= SQLCOM_ALTER_TABLESPACE;
4475          }
4476        ;
4477
4478logfile_group_name:
4479          ident
4480          {
4481            LEX *lex= Lex;
4482            lex->alter_tablespace_info= (new (thd->mem_root)
4483                                         st_alter_tablespace());
4484            if (unlikely(lex->alter_tablespace_info == NULL))
4485              MYSQL_YYABORT;
4486            lex->alter_tablespace_info->logfile_group_name= $1.str;
4487            lex->sql_command= SQLCOM_ALTER_TABLESPACE;
4488          }
4489        ;
4490
4491ts_access_mode:
4492          READ_ONLY_SYM
4493          {
4494            LEX *lex= Lex;
4495            lex->alter_tablespace_info->ts_access_mode= TS_READ_ONLY;
4496          }
4497        | READ_WRITE_SYM
4498          {
4499            LEX *lex= Lex;
4500            lex->alter_tablespace_info->ts_access_mode= TS_READ_WRITE;
4501          }
4502        | NOT_SYM ACCESSIBLE_SYM
4503          {
4504            LEX *lex= Lex;
4505            lex->alter_tablespace_info->ts_access_mode= TS_NOT_ACCESSIBLE;
4506          }
4507        ;
4508
4509opt_ts_initial_size:
4510          INITIAL_SIZE_SYM opt_equal size_number
4511          {
4512            LEX *lex= Lex;
4513            lex->alter_tablespace_info->initial_size= $3;
4514          }
4515        ;
4516
4517opt_ts_autoextend_size:
4518          AUTOEXTEND_SIZE_SYM opt_equal size_number
4519          {
4520            LEX *lex= Lex;
4521            lex->alter_tablespace_info->autoextend_size= $3;
4522          }
4523        ;
4524
4525opt_ts_max_size:
4526          MAX_SIZE_SYM opt_equal size_number
4527          {
4528            LEX *lex= Lex;
4529            lex->alter_tablespace_info->max_size= $3;
4530          }
4531        ;
4532
4533opt_ts_extent_size:
4534          EXTENT_SIZE_SYM opt_equal size_number
4535          {
4536            LEX *lex= Lex;
4537            lex->alter_tablespace_info->extent_size= $3;
4538          }
4539        ;
4540
4541opt_ts_undo_buffer_size:
4542          UNDO_BUFFER_SIZE_SYM opt_equal size_number
4543          {
4544            LEX *lex= Lex;
4545            lex->alter_tablespace_info->undo_buffer_size= $3;
4546          }
4547        ;
4548
4549opt_ts_redo_buffer_size:
4550          REDO_BUFFER_SIZE_SYM opt_equal size_number
4551          {
4552            LEX *lex= Lex;
4553            lex->alter_tablespace_info->redo_buffer_size= $3;
4554          }
4555        ;
4556
4557opt_ts_nodegroup:
4558          NODEGROUP_SYM opt_equal real_ulong_num
4559          {
4560            LEX *lex= Lex;
4561            if (unlikely(lex->alter_tablespace_info->nodegroup_id != UNDEF_NODEGROUP))
4562              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE,MYF(0),"NODEGROUP"));
4563            lex->alter_tablespace_info->nodegroup_id= $3;
4564          }
4565        ;
4566
4567opt_ts_comment:
4568          COMMENT_SYM opt_equal TEXT_STRING_sys
4569          {
4570            LEX *lex= Lex;
4571            if (unlikely(lex->alter_tablespace_info->ts_comment != NULL))
4572              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE,MYF(0),"COMMENT"));
4573            lex->alter_tablespace_info->ts_comment= $3.str;
4574          }
4575        ;
4576
4577opt_ts_engine:
4578          opt_storage ENGINE_SYM opt_equal storage_engines
4579          {
4580            LEX *lex= Lex;
4581            if (unlikely(lex->alter_tablespace_info->storage_engine != NULL))
4582              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0),
4583                                "STORAGE ENGINE"));
4584            lex->alter_tablespace_info->storage_engine= $4;
4585          }
4586        ;
4587
4588opt_ts_wait:
4589          /* empty */
4590        | ts_wait
4591        ;
4592
4593ts_wait:
4594          WAIT_SYM
4595          {
4596            LEX *lex= Lex;
4597            lex->alter_tablespace_info->wait_until_completed= TRUE;
4598          }
4599        | NO_WAIT_SYM
4600          {
4601            LEX *lex= Lex;
4602            if (unlikely(!(lex->alter_tablespace_info->wait_until_completed)))
4603              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE,MYF(0),"NO_WAIT"));
4604            lex->alter_tablespace_info->wait_until_completed= FALSE;
4605          }
4606        ;
4607
4608size_number:
4609          real_ulonglong_num { $$= $1;}
4610        | IDENT_sys
4611          {
4612            if ($1.to_size_number(&$$))
4613              MYSQL_YYABORT;
4614          }
4615        ;
4616
4617/*
4618  End tablespace part
4619*/
4620
4621create_body:
4622          create_field_list_parens
4623          { Lex->create_info.option_list= NULL; }
4624          opt_create_table_options opt_create_partitioning opt_create_select {}
4625        | opt_create_table_options opt_create_partitioning opt_create_select {}
4626        | create_like
4627          {
4628
4629            Lex->create_info.add(DDL_options_st::OPT_LIKE);
4630            TABLE_LIST *src_table= Lex->first_select_lex()->
4631              add_table_to_list(thd, $1, NULL, 0, TL_READ, MDL_SHARED_READ);
4632            if (unlikely(! src_table))
4633              MYSQL_YYABORT;
4634            /* CREATE TABLE ... LIKE is not allowed for views. */
4635            src_table->required_type= TABLE_TYPE_NORMAL;
4636          }
4637        ;
4638
4639create_like:
4640          LIKE table_ident                      { $$= $2; }
4641        | LEFT_PAREN_LIKE LIKE table_ident ')'  { $$= $3; }
4642        ;
4643
4644opt_create_select:
4645          /* empty */ {}
4646        | opt_duplicate opt_as create_select_query_expression
4647        opt_versioning_option
4648          {
4649            if (Lex->check_cte_dependencies_and_resolve_references())
4650              MYSQL_YYABORT;
4651          }
4652        ;
4653
4654create_select_query_expression:
4655          query_expression
4656          {
4657            if (Lex->parsed_insert_select($1->first_select()))
4658              MYSQL_YYABORT;
4659          }
4660        | LEFT_PAREN_WITH with_clause query_expression_no_with_clause ')'
4661          {
4662            SELECT_LEX *first_select= $3->first_select();
4663            $3->set_with_clause($2);
4664            $2->attach_to(first_select);
4665            if (Lex->parsed_insert_select(first_select))
4666              MYSQL_YYABORT;
4667          }
4668        ;
4669
4670opt_create_partitioning:
4671          opt_partitioning
4672          {
4673            /*
4674              Remove all tables used in PARTITION clause from the global table
4675              list. Partitioning with subqueries is not allowed anyway.
4676            */
4677            TABLE_LIST *last_non_sel_table= Lex->create_last_non_select_table;
4678            last_non_sel_table->next_global= 0;
4679            Lex->query_tables_last= &last_non_sel_table->next_global;
4680          }
4681        ;
4682
4683/*
4684 This part of the parser is about handling of the partition information.
4685
4686 Its first version was written by Mikael Ronström with lots of answers to
4687 questions provided by Antony Curtis.
4688
4689 The partition grammar can be called from three places.
4690 1) CREATE TABLE ... PARTITION ..
4691 2) ALTER TABLE table_name PARTITION ...
4692 3) PARTITION ...
4693
4694 The first place is called when a new table is created from a MySQL client.
4695 The second place is called when a table is altered with the ALTER TABLE
4696 command from a MySQL client.
4697 The third place is called when opening an frm file and finding partition
4698 info in the .frm file. It is necessary to avoid allowing PARTITION to be
4699 an allowed entry point for SQL client queries. This is arranged by setting
4700 some state variables before arriving here.
4701
4702 To be able to handle errors we will only set error code in this code
4703 and handle the error condition in the function calling the parser. This
4704 is necessary to ensure we can also handle errors when calling the parser
4705 from the openfrm function.
4706*/
4707opt_partitioning:
4708          /* empty */ {}
4709        | partitioning
4710        ;
4711
4712partitioning:
4713          PARTITION_SYM have_partitioning
4714          {
4715            LEX *lex= Lex;
4716            lex->part_info= new (thd->mem_root) partition_info();
4717            if (unlikely(!lex->part_info))
4718              MYSQL_YYABORT;
4719            if (lex->sql_command == SQLCOM_ALTER_TABLE)
4720            {
4721              lex->alter_info.partition_flags|= ALTER_PARTITION_INFO;
4722            }
4723          }
4724          partition
4725        ;
4726
4727have_partitioning:
4728          /* empty */
4729          {
4730#ifdef WITH_PARTITION_STORAGE_ENGINE
4731            LEX_CSTRING partition_name={STRING_WITH_LEN("partition")};
4732            if (unlikely(!plugin_is_ready(&partition_name, MYSQL_STORAGE_ENGINE_PLUGIN)))
4733              my_yyabort_error((ER_OPTION_PREVENTS_STATEMENT, MYF(0),
4734                                "--skip-partition"));
4735#else
4736            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), "partitioning",
4737                              "--with-plugin-partition"));
4738#endif
4739          }
4740        ;
4741
4742partition_entry:
4743          PARTITION_SYM
4744          {
4745            if (unlikely(!Lex->part_info))
4746            {
4747              thd->parse_error(ER_PARTITION_ENTRY_ERROR);
4748              MYSQL_YYABORT;
4749            }
4750            if (Lex->main_select_push())
4751              MYSQL_YYABORT;
4752            /*
4753              We enter here when opening the frm file to translate
4754              partition info string into part_info data structure.
4755            */
4756          }
4757          partition
4758          {
4759            Lex->pop_select(); //main select
4760          }
4761        ;
4762
4763partition:
4764          BY
4765	  { Lex->safe_to_cache_query= 1; }
4766	   part_type_def opt_num_parts opt_sub_part part_defs
4767        ;
4768
4769part_type_def:
4770          opt_linear KEY_SYM opt_key_algo '(' part_field_list ')'
4771          {
4772            partition_info *part_info= Lex->part_info;
4773            part_info->list_of_part_fields= TRUE;
4774            part_info->column_list= FALSE;
4775            part_info->part_type= HASH_PARTITION;
4776          }
4777        | opt_linear HASH_SYM
4778          { Lex->part_info->part_type= HASH_PARTITION; }
4779          part_func {}
4780        | RANGE_SYM part_func
4781          { Lex->part_info->part_type= RANGE_PARTITION; }
4782        | RANGE_SYM part_column_list
4783          { Lex->part_info->part_type= RANGE_PARTITION; }
4784        | LIST_SYM
4785	  {
4786	    Select->parsing_place= IN_PART_FUNC;
4787          }
4788          part_func
4789          {
4790	    Lex->part_info->part_type= LIST_PARTITION;
4791	    Select->parsing_place= NO_MATTER;
4792	  }
4793        | LIST_SYM part_column_list
4794          { Lex->part_info->part_type= LIST_PARTITION; }
4795        | SYSTEM_TIME_SYM
4796          {
4797             if (unlikely(Lex->part_info->vers_init_info(thd)))
4798               MYSQL_YYABORT;
4799          }
4800          opt_versioning_rotation
4801        ;
4802
4803opt_linear:
4804          /* empty */ {}
4805        | LINEAR_SYM
4806          { Lex->part_info->linear_hash_ind= TRUE;}
4807        ;
4808
4809opt_key_algo:
4810          /* empty */
4811          { Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_NONE;}
4812        | ALGORITHM_SYM '=' real_ulong_num
4813          {
4814            switch ($3) {
4815            case 1:
4816              Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_51;
4817              break;
4818            case 2:
4819              Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_55;
4820              break;
4821            default:
4822              thd->parse_error();
4823              MYSQL_YYABORT;
4824            }
4825          }
4826        ;
4827
4828part_field_list:
4829          /* empty */ {}
4830        | part_field_item_list {}
4831        ;
4832
4833part_field_item_list:
4834          part_field_item {}
4835        | part_field_item_list ',' part_field_item {}
4836        ;
4837
4838part_field_item:
4839          ident
4840          {
4841            partition_info *part_info= Lex->part_info;
4842            part_info->num_columns++;
4843            if (unlikely(part_info->part_field_list.push_back($1.str,
4844                         thd->mem_root)))
4845              MYSQL_YYABORT;
4846            if (unlikely(part_info->num_columns > MAX_REF_PARTS))
4847              my_yyabort_error((ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0),
4848                                "list of partition fields"));
4849          }
4850        ;
4851
4852part_column_list:
4853          COLUMNS '(' part_field_list ')'
4854          {
4855            partition_info *part_info= Lex->part_info;
4856            part_info->column_list= TRUE;
4857            part_info->list_of_part_fields= TRUE;
4858          }
4859        ;
4860
4861
4862part_func:
4863          '(' part_func_expr ')'
4864          {
4865            partition_info *part_info= Lex->part_info;
4866            if (unlikely(part_info->set_part_expr(thd, $2, FALSE)))
4867              MYSQL_YYABORT;
4868            part_info->num_columns= 1;
4869            part_info->column_list= FALSE;
4870          }
4871        ;
4872
4873sub_part_func:
4874          '(' part_func_expr ')'
4875          {
4876            if (unlikely(Lex->part_info->set_part_expr(thd, $2, TRUE)))
4877              MYSQL_YYABORT;
4878          }
4879        ;
4880
4881
4882opt_num_parts:
4883          /* empty */ {}
4884        | PARTITIONS_SYM real_ulong_num
4885          {
4886            uint num_parts= $2;
4887            partition_info *part_info= Lex->part_info;
4888            if (unlikely(num_parts == 0))
4889              my_yyabort_error((ER_NO_PARTS_ERROR, MYF(0), "partitions"));
4890
4891            part_info->num_parts= num_parts;
4892            part_info->use_default_num_partitions= FALSE;
4893          }
4894        ;
4895
4896opt_sub_part:
4897          /* empty */ {}
4898        | SUBPARTITION_SYM BY opt_linear HASH_SYM sub_part_func
4899          { Lex->part_info->subpart_type= HASH_PARTITION; }
4900          opt_num_subparts {}
4901        | SUBPARTITION_SYM BY opt_linear KEY_SYM opt_key_algo
4902          '(' sub_part_field_list ')'
4903          {
4904            partition_info *part_info= Lex->part_info;
4905            part_info->subpart_type= HASH_PARTITION;
4906            part_info->list_of_subpart_fields= TRUE;
4907          }
4908          opt_num_subparts {}
4909        ;
4910
4911sub_part_field_list:
4912          sub_part_field_item {}
4913        | sub_part_field_list ',' sub_part_field_item {}
4914        ;
4915
4916sub_part_field_item:
4917          ident
4918          {
4919            partition_info *part_info= Lex->part_info;
4920            if (unlikely(part_info->subpart_field_list.push_back($1.str,
4921                         thd->mem_root)))
4922              MYSQL_YYABORT;
4923
4924            if (unlikely(part_info->subpart_field_list.elements > MAX_REF_PARTS))
4925              my_yyabort_error((ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0),
4926                                "list of subpartition fields"));
4927          }
4928        ;
4929
4930part_func_expr:
4931          bit_expr
4932          {
4933            if (unlikely(!Lex->safe_to_cache_query))
4934            {
4935              thd->parse_error(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR);
4936              MYSQL_YYABORT;
4937            }
4938            $$=$1;
4939          }
4940        ;
4941
4942opt_num_subparts:
4943          /* empty */ {}
4944        | SUBPARTITIONS_SYM real_ulong_num
4945          {
4946            uint num_parts= $2;
4947            LEX *lex= Lex;
4948            if (unlikely(num_parts == 0))
4949              my_yyabort_error((ER_NO_PARTS_ERROR, MYF(0), "subpartitions"));
4950            lex->part_info->num_subparts= num_parts;
4951            lex->part_info->use_default_num_subpartitions= FALSE;
4952          }
4953        ;
4954
4955part_defs:
4956          /* empty */
4957          {
4958            partition_info *part_info= Lex->part_info;
4959            if (unlikely(part_info->part_type == RANGE_PARTITION))
4960              my_yyabort_error((ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0),
4961                                "RANGE"));
4962            if (unlikely(part_info->part_type == LIST_PARTITION))
4963              my_yyabort_error((ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0),
4964                                "LIST"));
4965          }
4966        | '(' part_def_list ')'
4967          {
4968            partition_info *part_info= Lex->part_info;
4969            uint count_curr_parts= part_info->partitions.elements;
4970            if (part_info->num_parts != 0)
4971            {
4972              if (unlikely(part_info->num_parts !=
4973                           count_curr_parts))
4974              {
4975                thd->parse_error(ER_PARTITION_WRONG_NO_PART_ERROR);
4976                MYSQL_YYABORT;
4977              }
4978            }
4979            else if (count_curr_parts > 0)
4980            {
4981              part_info->num_parts= count_curr_parts;
4982            }
4983            part_info->count_curr_subparts= 0;
4984          }
4985        ;
4986
4987part_def_list:
4988          part_definition {}
4989        | part_def_list ',' part_definition {}
4990        ;
4991
4992part_definition:
4993          PARTITION_SYM
4994          {
4995            partition_info *part_info= Lex->part_info;
4996            partition_element *p_elem= new (thd->mem_root) partition_element();
4997
4998            if (unlikely(!p_elem) ||
4999                unlikely(part_info->partitions.push_back(p_elem, thd->mem_root)))
5000              MYSQL_YYABORT;
5001
5002            p_elem->part_state= PART_NORMAL;
5003            p_elem->id= part_info->partitions.elements - 1;
5004            part_info->curr_part_elem= p_elem;
5005            part_info->current_partition= p_elem;
5006            part_info->use_default_partitions= FALSE;
5007            part_info->use_default_num_partitions= FALSE;
5008          }
5009          part_name
5010          opt_part_values
5011          opt_part_options
5012          opt_sub_partition
5013          {}
5014        ;
5015
5016part_name:
5017          ident
5018          {
5019            partition_info *part_info= Lex->part_info;
5020            partition_element *p_elem= part_info->curr_part_elem;
5021            if (unlikely(check_ident_length(&$1)))
5022              MYSQL_YYABORT;
5023            p_elem->partition_name= $1.str;
5024          }
5025        ;
5026
5027opt_part_values:
5028          /* empty */
5029          {
5030            LEX *lex= Lex;
5031            partition_info *part_info= lex->part_info;
5032            if (! lex->is_partition_management())
5033            {
5034              if (unlikely(part_info->error_if_requires_values()))
5035                MYSQL_YYABORT;
5036              if (unlikely(part_info->part_type == VERSIONING_PARTITION))
5037                my_yyabort_error((ER_VERS_WRONG_PARTS, MYF(0),
5038                                  lex->create_last_non_select_table->
5039                                  table_name.str));
5040            }
5041            else
5042              part_info->part_type= HASH_PARTITION;
5043          }
5044        | VALUES_LESS_SYM THAN_SYM
5045          {
5046            LEX *lex= Lex;
5047            partition_info *part_info= lex->part_info;
5048            if (! lex->is_partition_management())
5049            {
5050              if (unlikely(part_info->part_type != RANGE_PARTITION))
5051                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
5052                                  "RANGE", "LESS THAN"));
5053            }
5054            else
5055              part_info->part_type= RANGE_PARTITION;
5056          }
5057          part_func_max {}
5058        | VALUES_IN_SYM
5059          {
5060            LEX *lex= Lex;
5061            partition_info *part_info= lex->part_info;
5062            if (! lex->is_partition_management())
5063            {
5064              if (unlikely(part_info->part_type != LIST_PARTITION))
5065                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
5066                                  "LIST", "IN"));
5067            }
5068            else
5069              part_info->part_type= LIST_PARTITION;
5070          }
5071          part_values_in {}
5072        | CURRENT_SYM
5073          {
5074            if (Lex->part_values_current(thd))
5075              MYSQL_YYABORT;
5076          }
5077        | HISTORY_SYM
5078          {
5079            if (Lex->part_values_history(thd))
5080              MYSQL_YYABORT;
5081          }
5082        | DEFAULT
5083         {
5084            LEX *lex= Lex;
5085            partition_info *part_info= lex->part_info;
5086            if (! lex->is_partition_management())
5087            {
5088              if (unlikely(part_info->part_type != LIST_PARTITION))
5089                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
5090                                  "LIST", "DEFAULT"));
5091            }
5092            else
5093              part_info->part_type= LIST_PARTITION;
5094            if (unlikely(part_info->init_column_part(thd)))
5095              MYSQL_YYABORT;
5096            if (unlikely(part_info->add_max_value(thd)))
5097              MYSQL_YYABORT;
5098         }
5099        ;
5100
5101part_func_max:
5102          MAXVALUE_SYM
5103          {
5104            partition_info *part_info= Lex->part_info;
5105
5106            if (unlikely(part_info->num_columns &&
5107                         part_info->num_columns != 1U))
5108            {
5109              part_info->print_debug("Kilroy II", NULL);
5110              thd->parse_error(ER_PARTITION_COLUMN_LIST_ERROR);
5111              MYSQL_YYABORT;
5112            }
5113            else
5114              part_info->num_columns= 1U;
5115            if (unlikely(part_info->init_column_part(thd)))
5116              MYSQL_YYABORT;
5117            if (unlikely(part_info->add_max_value(thd)))
5118              MYSQL_YYABORT;
5119          }
5120        | part_value_item {}
5121        ;
5122
5123part_values_in:
5124          part_value_item
5125          {
5126            LEX *lex= Lex;
5127            partition_info *part_info= lex->part_info;
5128            part_info->print_debug("part_values_in: part_value_item", NULL);
5129
5130            if (part_info->num_columns != 1U)
5131            {
5132              if (unlikely(!lex->is_partition_management() ||
5133                           part_info->num_columns == 0 ||
5134                           part_info->num_columns > MAX_REF_PARTS))
5135              {
5136                part_info->print_debug("Kilroy III", NULL);
5137                thd->parse_error(ER_PARTITION_COLUMN_LIST_ERROR);
5138                MYSQL_YYABORT;
5139              }
5140              /*
5141                Reorganize the current large array into a list of small
5142                arrays with one entry in each array. This can happen
5143                in the first partition of an ALTER TABLE statement where
5144                we ADD or REORGANIZE partitions. Also can only happen
5145                for LIST partitions.
5146              */
5147              if (unlikely(part_info->reorganize_into_single_field_col_val(thd)))
5148                MYSQL_YYABORT;
5149            }
5150          }
5151        | '(' part_value_list ')'
5152          {
5153            partition_info *part_info= Lex->part_info;
5154            if (unlikely(part_info->num_columns < 2U))
5155            {
5156              thd->parse_error(ER_ROW_SINGLE_PARTITION_FIELD_ERROR);
5157              MYSQL_YYABORT;
5158            }
5159          }
5160        ;
5161
5162part_value_list:
5163          part_value_item {}
5164        | part_value_list ',' part_value_item {}
5165        ;
5166
5167part_value_item:
5168          '('
5169          {
5170            partition_info *part_info= Lex->part_info;
5171            part_info->print_debug("( part_value_item", NULL);
5172            /* Initialisation code needed for each list of value expressions */
5173            if (unlikely(!(part_info->part_type == LIST_PARTITION &&
5174                           part_info->num_columns == 1U) &&
5175                           part_info->init_column_part(thd)))
5176              MYSQL_YYABORT;
5177          }
5178          part_value_item_list {}
5179          ')'
5180          {
5181            partition_info *part_info= Lex->part_info;
5182            part_info->print_debug(") part_value_item", NULL);
5183            if (part_info->num_columns == 0)
5184              part_info->num_columns= part_info->curr_list_object;
5185            if (unlikely(part_info->num_columns != part_info->curr_list_object))
5186            {
5187              /*
5188                All value items lists must be of equal length, in some cases
5189                which is covered by the above if-statement we don't know yet
5190                how many columns is in the partition so the assignment above
5191                ensures that we only report errors when we know we have an
5192                error.
5193              */
5194              part_info->print_debug("Kilroy I", NULL);
5195              thd->parse_error(ER_PARTITION_COLUMN_LIST_ERROR);
5196              MYSQL_YYABORT;
5197            }
5198            part_info->curr_list_object= 0;
5199          }
5200        ;
5201
5202part_value_item_list:
5203          part_value_expr_item {}
5204        | part_value_item_list ',' part_value_expr_item {}
5205        ;
5206
5207part_value_expr_item:
5208          MAXVALUE_SYM
5209          {
5210            partition_info *part_info= Lex->part_info;
5211            if (unlikely(part_info->part_type == LIST_PARTITION))
5212            {
5213              thd->parse_error(ER_MAXVALUE_IN_VALUES_IN);
5214              MYSQL_YYABORT;
5215            }
5216            if (unlikely(part_info->add_max_value(thd)))
5217              MYSQL_YYABORT;
5218          }
5219        | bit_expr
5220          {
5221            LEX *lex= Lex;
5222            partition_info *part_info= lex->part_info;
5223            Item *part_expr= $1;
5224
5225            if (unlikely(!lex->safe_to_cache_query))
5226            {
5227              thd->parse_error(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR);
5228              MYSQL_YYABORT;
5229            }
5230            if (unlikely(part_info->add_column_list_value(thd, part_expr)))
5231              MYSQL_YYABORT;
5232          }
5233        ;
5234
5235
5236opt_sub_partition:
5237          /* empty */
5238          {
5239            partition_info *part_info= Lex->part_info;
5240            if (unlikely(part_info->num_subparts != 0 &&
5241                         !part_info->use_default_subpartitions))
5242            {
5243              /*
5244                We come here when we have defined subpartitions on the first
5245                partition but not on all the subsequent partitions.
5246              */
5247              thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5248              MYSQL_YYABORT;
5249            }
5250          }
5251        | '(' sub_part_list ')'
5252          {
5253            partition_info *part_info= Lex->part_info;
5254            if (part_info->num_subparts != 0)
5255            {
5256              if (unlikely(part_info->num_subparts !=
5257                           part_info->count_curr_subparts))
5258              {
5259                thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5260                MYSQL_YYABORT;
5261              }
5262            }
5263            else if (part_info->count_curr_subparts > 0)
5264            {
5265              if (unlikely(part_info->partitions.elements > 1))
5266              {
5267                thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5268                MYSQL_YYABORT;
5269              }
5270              part_info->num_subparts= part_info->count_curr_subparts;
5271            }
5272            part_info->count_curr_subparts= 0;
5273          }
5274        ;
5275
5276sub_part_list:
5277          sub_part_definition {}
5278        | sub_part_list ',' sub_part_definition {}
5279        ;
5280
5281sub_part_definition:
5282          SUBPARTITION_SYM
5283          {
5284            partition_info *part_info= Lex->part_info;
5285            partition_element *curr_part= part_info->current_partition;
5286            partition_element *sub_p_elem= new (thd->mem_root)
5287                                           partition_element(curr_part);
5288            if (unlikely(part_info->use_default_subpartitions &&
5289                         part_info->partitions.elements >= 2))
5290            {
5291              /*
5292                create table t1 (a int)
5293                partition by list (a) subpartition by hash (a)
5294                (partition p0 values in (1),
5295                 partition p1 values in (2) subpartition sp11);
5296                causes use to arrive since we are on the second
5297                partition, but still use_default_subpartitions
5298                is set. When we come here we're processing at least
5299                the second partition (the current partition processed
5300                have already been put into the partitions list.
5301              */
5302              thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5303              MYSQL_YYABORT;
5304            }
5305            if (unlikely(!sub_p_elem) ||
5306                unlikely(curr_part->subpartitions.push_back(sub_p_elem, thd->mem_root)))
5307              MYSQL_YYABORT;
5308
5309            sub_p_elem->id= curr_part->subpartitions.elements - 1;
5310            part_info->curr_part_elem= sub_p_elem;
5311            part_info->use_default_subpartitions= FALSE;
5312            part_info->use_default_num_subpartitions= FALSE;
5313            part_info->count_curr_subparts++;
5314          }
5315          sub_name opt_part_options {}
5316        ;
5317
5318sub_name:
5319          ident_or_text
5320          {
5321            if (unlikely(check_ident_length(&$1)))
5322              MYSQL_YYABORT;
5323            Lex->part_info->curr_part_elem->partition_name= $1.str;
5324          }
5325        ;
5326
5327opt_part_options:
5328         /* empty */ {}
5329       | opt_part_option_list {}
5330       ;
5331
5332opt_part_option_list:
5333         opt_part_option_list opt_part_option {}
5334       | opt_part_option {}
5335       ;
5336
5337opt_part_option:
5338          TABLESPACE opt_equal ident_or_text
5339          { Lex->part_info->curr_part_elem->tablespace_name= $3.str; }
5340        | opt_storage ENGINE_SYM opt_equal storage_engines
5341          {
5342            partition_info *part_info= Lex->part_info;
5343            part_info->curr_part_elem->engine_type= $4;
5344            part_info->default_engine_type= $4;
5345          }
5346        | CONNECTION_SYM opt_equal TEXT_STRING_sys
5347          {
5348            LEX *lex= Lex;
5349            lex->part_info->curr_part_elem->connect_string.str= $3.str;
5350            lex->part_info->curr_part_elem->connect_string.length= $3.length;
5351          }
5352        | NODEGROUP_SYM opt_equal real_ulong_num
5353          { Lex->part_info->curr_part_elem->nodegroup_id= (uint16) $3; }
5354        | MAX_ROWS opt_equal real_ulonglong_num
5355          { Lex->part_info->curr_part_elem->part_max_rows= (ha_rows) $3; }
5356        | MIN_ROWS opt_equal real_ulonglong_num
5357          { Lex->part_info->curr_part_elem->part_min_rows= (ha_rows) $3; }
5358        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
5359          { Lex->part_info->curr_part_elem->data_file_name= $4.str; }
5360        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
5361          { Lex->part_info->curr_part_elem->index_file_name= $4.str; }
5362        | COMMENT_SYM opt_equal TEXT_STRING_sys
5363          { Lex->part_info->curr_part_elem->part_comment= $3.str; }
5364        ;
5365
5366opt_versioning_rotation:
5367         /* empty */ {}
5368       | INTERVAL_SYM expr interval opt_versioning_interval_start
5369         {
5370           partition_info *part_info= Lex->part_info;
5371           const char *table_name= Lex->create_last_non_select_table->table_name.str;
5372           if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4, table_name)))
5373             MYSQL_YYABORT;
5374         }
5375       | LIMIT ulonglong_num
5376       {
5377         partition_info *part_info= Lex->part_info;
5378         if (unlikely(part_info->vers_set_limit($2)))
5379         {
5380           my_error(ER_PART_WRONG_VALUE, MYF(0),
5381                    Lex->create_last_non_select_table->table_name.str,
5382                    "LIMIT");
5383           MYSQL_YYABORT;
5384         }
5385       }
5386       ;
5387
5388
5389opt_versioning_interval_start:
5390         /* empty */
5391         {
5392           $$= NULL;
5393         }
5394       | STARTS_SYM literal
5395         {
5396           $$= $2;
5397         }
5398       ;
5399
5400/*
5401 End of partition parser part
5402*/
5403
5404opt_as:
5405          /* empty */ {}
5406        | AS {}
5407        ;
5408
5409opt_create_database_options:
5410          /* empty */ {}
5411        | create_database_options {}
5412        ;
5413
5414create_database_options:
5415          create_database_option {}
5416        | create_database_options create_database_option {}
5417        ;
5418
5419create_database_option:
5420          default_collation {}
5421        | default_charset {}
5422        | COMMENT_SYM opt_equal TEXT_STRING_sys
5423          {
5424            Lex->create_info.schema_comment= thd->make_clex_string($3);
5425            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
5426          }
5427        ;
5428
5429opt_if_not_exists_table_element:
5430          /* empty */
5431          {
5432            Lex->check_exists= FALSE;
5433          }
5434        | IF_SYM not EXISTS
5435          {
5436            Lex->check_exists= TRUE;
5437          }
5438         ;
5439
5440opt_if_not_exists:
5441          /* empty */
5442          {
5443            $$.init();
5444          }
5445        | IF_SYM not EXISTS
5446          {
5447            $$.set(DDL_options_st::OPT_IF_NOT_EXISTS);
5448          }
5449         ;
5450
5451create_or_replace:
5452          CREATE /* empty */
5453          {
5454            $$.init();
5455          }
5456        | CREATE OR_SYM REPLACE
5457          {
5458            $$.set(DDL_options_st::OPT_OR_REPLACE);
5459          }
5460         ;
5461
5462opt_create_table_options:
5463          /* empty */
5464        | create_table_options
5465        ;
5466
5467create_table_options_space_separated:
5468          create_table_option
5469        | create_table_option create_table_options_space_separated
5470        ;
5471
5472create_table_options:
5473          create_table_option
5474        | create_table_option     create_table_options
5475        | create_table_option ',' create_table_options
5476        ;
5477
5478create_table_option:
5479          ENGINE_SYM opt_equal ident_or_text
5480          {
5481            LEX *lex= Lex;
5482            if (!lex->m_sql_cmd)
5483            {
5484              DBUG_ASSERT(lex->sql_command == SQLCOM_ALTER_TABLE);
5485              if (!(lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_table()))
5486                MYSQL_YYABORT;
5487            }
5488            Storage_engine_name *opt=
5489              lex->m_sql_cmd->option_storage_engine_name();
5490            DBUG_ASSERT(opt); // Expect a proper Sql_cmd
5491            *opt= Storage_engine_name($3);
5492            lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
5493          }
5494        | MAX_ROWS opt_equal ulonglong_num
5495          {
5496            Lex->create_info.max_rows= $3;
5497            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
5498          }
5499        | MIN_ROWS opt_equal ulonglong_num
5500          {
5501            Lex->create_info.min_rows= $3;
5502            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
5503          }
5504        | AVG_ROW_LENGTH opt_equal ulong_num
5505          {
5506            Lex->create_info.avg_row_length=$3;
5507            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
5508          }
5509        | PASSWORD_SYM opt_equal TEXT_STRING_sys
5510          {
5511            Lex->create_info.password=$3.str;
5512            Lex->create_info.used_fields|= HA_CREATE_USED_PASSWORD;
5513          }
5514        | COMMENT_SYM opt_equal TEXT_STRING_sys
5515          {
5516            Lex->create_info.comment=$3;
5517            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
5518          }
5519        | AUTO_INC opt_equal ulonglong_num
5520          {
5521            Lex->create_info.auto_increment_value=$3;
5522            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
5523          }
5524        | PACK_KEYS_SYM opt_equal ulong_num
5525          {
5526            switch($3) {
5527            case 0:
5528                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
5529                break;
5530            case 1:
5531                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
5532                break;
5533            default:
5534                thd->parse_error();
5535                MYSQL_YYABORT;
5536            }
5537            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
5538          }
5539        | PACK_KEYS_SYM opt_equal DEFAULT
5540          {
5541            Lex->create_info.table_options&=
5542              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
5543            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
5544          }
5545        | STATS_AUTO_RECALC_SYM opt_equal ulong_num
5546          {
5547            switch($3) {
5548            case 0:
5549                Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_OFF;
5550                break;
5551            case 1:
5552                Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_ON;
5553                break;
5554            default:
5555                thd->parse_error();
5556                MYSQL_YYABORT;
5557            }
5558            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_AUTO_RECALC;
5559          }
5560        | STATS_AUTO_RECALC_SYM opt_equal DEFAULT
5561          {
5562            Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_DEFAULT;
5563            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_AUTO_RECALC;
5564          }
5565        | STATS_PERSISTENT_SYM opt_equal ulong_num
5566          {
5567            switch($3) {
5568            case 0:
5569                Lex->create_info.table_options|= HA_OPTION_NO_STATS_PERSISTENT;
5570                break;
5571            case 1:
5572                Lex->create_info.table_options|= HA_OPTION_STATS_PERSISTENT;
5573                break;
5574            default:
5575                thd->parse_error();
5576                MYSQL_YYABORT;
5577            }
5578            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_PERSISTENT;
5579          }
5580        | STATS_PERSISTENT_SYM opt_equal DEFAULT
5581          {
5582            Lex->create_info.table_options&=
5583              ~(HA_OPTION_STATS_PERSISTENT | HA_OPTION_NO_STATS_PERSISTENT);
5584            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_PERSISTENT;
5585          }
5586        | STATS_SAMPLE_PAGES_SYM opt_equal ulong_num
5587          {
5588            /* From user point of view STATS_SAMPLE_PAGES can be specified as
5589            STATS_SAMPLE_PAGES=N (where 0<N<=65535, it does not make sense to
5590            scan 0 pages) or STATS_SAMPLE_PAGES=default. Internally we record
5591            =default as 0. See create_frm() in sql/table.cc, we use only two
5592            bytes for stats_sample_pages and this is why we do not allow
5593            larger values. 65535 pages, 16kb each means to sample 1GB, which
5594            is impractical. If at some point this needs to be extended, then
5595            we can store the higher bits from stats_sample_pages in .frm too. */
5596            if (unlikely($3 == 0 || $3 > 0xffff))
5597            {
5598              thd->parse_error();
5599              MYSQL_YYABORT;
5600            }
5601            Lex->create_info.stats_sample_pages=$3;
5602            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_SAMPLE_PAGES;
5603          }
5604        | STATS_SAMPLE_PAGES_SYM opt_equal DEFAULT
5605          {
5606            Lex->create_info.stats_sample_pages=0;
5607            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_SAMPLE_PAGES;
5608          }
5609        | CHECKSUM_SYM opt_equal ulong_num
5610          {
5611            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
5612            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
5613          }
5614        | TABLE_CHECKSUM_SYM opt_equal ulong_num
5615          {
5616             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
5617             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
5618          }
5619        | PAGE_CHECKSUM_SYM opt_equal choice
5620          {
5621            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
5622            Lex->create_info.page_checksum= $3;
5623          }
5624        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
5625          {
5626            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
5627            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
5628          }
5629        | ROW_FORMAT_SYM opt_equal row_types
5630          {
5631            Lex->create_info.row_type= $3;
5632            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
5633          }
5634        | UNION_SYM opt_equal
5635          {
5636            Lex->first_select_lex()->table_list.save_and_clear(&Lex->save_list);
5637          }
5638          '(' opt_table_list ')'
5639          {
5640            /*
5641              Move the union list to the merge_list and exclude its tables
5642              from the global list.
5643            */
5644            LEX *lex=Lex;
5645            lex->create_info.merge_list= lex->first_select_lex()->table_list.first;
5646            lex->first_select_lex()->table_list= lex->save_list;
5647            /*
5648              When excluding union list from the global list we assume that
5649              elements of the former immediately follow elements which represent
5650              table being created/altered and parent tables.
5651            */
5652            TABLE_LIST *last_non_sel_table= lex->create_last_non_select_table;
5653            DBUG_ASSERT(last_non_sel_table->next_global ==
5654                        lex->create_info.merge_list);
5655            last_non_sel_table->next_global= 0;
5656            Lex->query_tables_last= &last_non_sel_table->next_global;
5657
5658            lex->create_info.used_fields|= HA_CREATE_USED_UNION;
5659          }
5660        | default_charset
5661        | default_collation
5662        | INSERT_METHOD opt_equal merge_insert_types
5663          {
5664            Lex->create_info.merge_insert_method= $3;
5665            Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;
5666          }
5667        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
5668          {
5669            Lex->create_info.data_file_name= $4.str;
5670            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
5671          }
5672        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
5673          {
5674            Lex->create_info.index_file_name= $4.str;
5675            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
5676          }
5677        | TABLESPACE ident
5678          {Lex->create_info.tablespace= $2.str;}
5679        | STORAGE_SYM DISK_SYM
5680          {Lex->create_info.storage_media= HA_SM_DISK;}
5681        | STORAGE_SYM MEMORY_SYM
5682          {Lex->create_info.storage_media= HA_SM_MEMORY;}
5683        | CONNECTION_SYM opt_equal TEXT_STRING_sys
5684          {
5685            Lex->create_info.connect_string.str= $3.str;
5686            Lex->create_info.connect_string.length= $3.length;
5687            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
5688          }
5689        | KEY_BLOCK_SIZE opt_equal ulong_num
5690          {
5691            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
5692            Lex->create_info.key_block_size= $3;
5693          }
5694        | TRANSACTIONAL_SYM opt_equal choice
5695          {
5696	    Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
5697            Lex->create_info.transactional= $3;
5698          }
5699        | IDENT_sys equal TEXT_STRING_sys
5700          {
5701            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
5702              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
5703            (void) new (thd->mem_root)
5704                   engine_option_value($1, $3, true,
5705                                       &Lex->create_info.option_list,
5706                                       &Lex->option_list_last);
5707          }
5708        | IDENT_sys equal ident
5709          {
5710            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
5711              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
5712            (void) new (thd->mem_root)
5713                   engine_option_value($1, $3, false,
5714                                       &Lex->create_info.option_list,
5715                                       &Lex->option_list_last);
5716          }
5717        | IDENT_sys equal real_ulonglong_num
5718          {
5719            (void) new (thd->mem_root)
5720                   engine_option_value($1, $3, &Lex->create_info.option_list,
5721                                       &Lex->option_list_last, thd->mem_root);
5722          }
5723        | IDENT_sys equal DEFAULT
5724          {
5725            (void) new (thd->mem_root)
5726                   engine_option_value($1, &Lex->create_info.option_list,
5727                                       &Lex->option_list_last);
5728          }
5729        | SEQUENCE_SYM opt_equal choice
5730          {
5731	    Lex->create_info.used_fields|= HA_CREATE_USED_SEQUENCE;
5732            Lex->create_info.sequence= ($3 == HA_CHOICE_YES);
5733	  }
5734        | versioning_option
5735        ;
5736
5737opt_versioning_option:
5738          /* empty */
5739        | versioning_option
5740        ;
5741
5742versioning_option:
5743        WITH_SYSTEM_SYM VERSIONING_SYM
5744          {
5745            if (unlikely(Lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
5746            {
5747              if (DBUG_EVALUATE_IF("sysvers_force", 0, 1))
5748              {
5749                my_error(ER_VERS_NOT_SUPPORTED, MYF(0), "CREATE TEMPORARY TABLE");
5750                MYSQL_YYABORT;
5751              }
5752            }
5753            else
5754            {
5755              Lex->alter_info.flags|= ALTER_ADD_SYSTEM_VERSIONING;
5756              Lex->create_info.options|= HA_VERSIONED_TABLE;
5757            }
5758          }
5759        ;
5760
5761default_charset:
5762          opt_default charset opt_equal charset_name_or_default
5763          {
5764            if (unlikely(Lex->create_info.add_table_option_default_charset($4)))
5765              MYSQL_YYABORT;
5766          }
5767        ;
5768
5769default_collation:
5770          opt_default COLLATE_SYM opt_equal collation_name_or_default
5771          {
5772            HA_CREATE_INFO *cinfo= &Lex->create_info;
5773            if (unlikely((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
5774                         cinfo->default_table_charset && $4 &&
5775                         !($4= merge_charset_and_collation(cinfo->default_table_charset,
5776                                                           $4))))
5777              MYSQL_YYABORT;
5778
5779            Lex->create_info.default_table_charset= $4;
5780            Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
5781          }
5782        ;
5783
5784storage_engines:
5785          ident_or_text
5786          {
5787            if (Storage_engine_name($1).
5788                 resolve_storage_engine_with_error(thd, &$$,
5789                                            thd->lex->create_info.tmp_table()))
5790              MYSQL_YYABORT;
5791          }
5792        ;
5793
5794known_storage_engines:
5795          ident_or_text
5796          {
5797            plugin_ref plugin;
5798            if (likely((plugin= ha_resolve_by_name(thd, &$1, false))))
5799              $$= plugin_hton(plugin);
5800            else
5801              my_yyabort_error((ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str));
5802          }
5803        ;
5804
5805row_types:
5806          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
5807        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
5808        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
5809        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
5810        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
5811        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
5812        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
5813        ;
5814
5815merge_insert_types:
5816         NO_SYM          { $$= MERGE_INSERT_DISABLED; }
5817       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
5818       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; }
5819       ;
5820
5821udf_type:
5822          STRING_SYM {$$ = (int) STRING_RESULT; }
5823        | REAL {$$ = (int) REAL_RESULT; }
5824        | DECIMAL_SYM {$$ = (int) DECIMAL_RESULT; }
5825        | INT_SYM {$$ = (int) INT_RESULT; }
5826        ;
5827
5828
5829create_field_list:
5830        field_list
5831        {
5832          Lex->create_last_non_select_table= Lex->last_table();
5833        }
5834        ;
5835
5836create_field_list_parens:
5837        LEFT_PAREN_ALT field_list ')'
5838        {
5839          Lex->create_last_non_select_table= Lex->last_table();
5840        }
5841        ;
5842
5843field_list:
5844          field_list_item
5845        | field_list ',' field_list_item
5846        ;
5847
5848field_list_item:
5849          column_def { }
5850        | key_def
5851        | constraint_def
5852        | period_for_system_time
5853        | PERIOD_SYM period_for_application_time { }
5854        ;
5855
5856column_def:
5857          field_spec
5858          { $$= $1; }
5859        | field_spec opt_constraint references
5860          {
5861            if (unlikely(Lex->add_column_foreign_key(&($1->field_name), &$2,
5862                                                     $3, DDL_options())))
5863              MYSQL_YYABORT;
5864            $$= $1;
5865          }
5866        ;
5867
5868key_def:
5869          key_or_index opt_if_not_exists opt_ident opt_USING_key_algorithm
5870          {
5871            Lex->option_list= NULL;
5872            if (unlikely(Lex->add_key(Key::MULTIPLE, &$3, $4, $2)))
5873              MYSQL_YYABORT;
5874          }
5875          '(' key_list ')' normal_key_options { }
5876        | key_or_index opt_if_not_exists ident TYPE_SYM btree_or_rtree
5877          {
5878            Lex->option_list= NULL;
5879            if (unlikely(Lex->add_key(Key::MULTIPLE, &$3, $5, $2)))
5880              MYSQL_YYABORT;
5881          }
5882          '(' key_list ')' normal_key_options { }
5883        | fulltext opt_key_or_index opt_if_not_exists opt_ident
5884          {
5885            Lex->option_list= NULL;
5886            if (unlikely(Lex->add_key($1, &$4, HA_KEY_ALG_UNDEF, $3)))
5887              MYSQL_YYABORT;
5888          }
5889          '(' key_list ')' fulltext_key_options { }
5890        | spatial opt_key_or_index opt_if_not_exists opt_ident
5891          {
5892            Lex->option_list= NULL;
5893            if (unlikely(Lex->add_key($1, &$4, HA_KEY_ALG_UNDEF, $3)))
5894              MYSQL_YYABORT;
5895          }
5896          '(' key_list ')' spatial_key_options { }
5897        | opt_constraint constraint_key_type
5898          opt_if_not_exists opt_ident
5899          opt_USING_key_algorithm
5900          {
5901            Lex->option_list= NULL;
5902            if (unlikely(Lex->add_key($2, $4.str ? &$4 : &$1, $5, $3)))
5903              MYSQL_YYABORT;
5904          }
5905          '(' key_list opt_without_overlaps ')' normal_key_options { }
5906        | opt_constraint constraint_key_type opt_if_not_exists ident
5907          TYPE_SYM btree_or_rtree
5908          {
5909            Lex->option_list= NULL;
5910            if (unlikely(Lex->add_key($2, $4.str ? &$4 : &$1, $6, $3)))
5911              MYSQL_YYABORT;
5912          }
5913          '(' key_list opt_without_overlaps ')' normal_key_options { }
5914        | opt_constraint FOREIGN KEY_SYM opt_if_not_exists opt_ident
5915          {
5916            if (unlikely(Lex->check_add_key($4)) ||
5917                unlikely(!(Lex->last_key= (new (thd->mem_root)
5918                                           Key(Key::MULTIPLE,
5919                                           $1.str ? &$1 : &$5,
5920                                           HA_KEY_ALG_UNDEF, true, $4)))))
5921              MYSQL_YYABORT;
5922            Lex->option_list= NULL;
5923          }
5924          '(' key_list ')' references
5925          {
5926            if (unlikely(Lex->add_table_foreign_key($5.str ? &$5 : &$1,
5927                                                    $1.str ? &$1 : &$5, $10, $4)))
5928               MYSQL_YYABORT;
5929          }
5930	;
5931
5932constraint_def:
5933         opt_constraint check_constraint
5934         {
5935           Lex->add_constraint($1, $2, FALSE);
5936         }
5937       ;
5938
5939period_for_system_time:
5940          // If FOR_SYM is followed by SYSTEM_TIME_SYM then they are merged to: FOR_SYSTEM_TIME_SYM .
5941          PERIOD_SYM FOR_SYSTEM_TIME_SYM '(' ident ',' ident ')'
5942          {
5943            Vers_parse_info &info= Lex->vers_get_info();
5944            info.set_period($4, $6);
5945          }
5946        ;
5947
5948period_for_application_time:
5949          FOR_SYM ident '(' ident ',' ident ')'
5950          {
5951            if (Lex->add_period($2, $4, $6))
5952              MYSQL_YYABORT;
5953          }
5954        ;
5955
5956opt_check_constraint:
5957          /* empty */      { $$= (Virtual_column_info*) 0; }
5958        | check_constraint { $$= $1;}
5959        ;
5960
5961check_constraint:
5962          CHECK_SYM '(' expr ')'
5963          {
5964            Virtual_column_info *v= add_virtual_expression(thd, $3);
5965            if (unlikely(!v))
5966              MYSQL_YYABORT;
5967            $$= v;
5968          }
5969        ;
5970
5971opt_constraint_no_id:
5972          /* Empty */  {}
5973        | CONSTRAINT   {}
5974        ;
5975
5976opt_constraint:
5977          /* empty */ { $$= null_clex_str; }
5978        | constraint { $$= $1; }
5979        ;
5980
5981constraint:
5982          CONSTRAINT opt_ident { $$=$2; }
5983        ;
5984
5985field_spec:
5986          field_ident
5987          {
5988            LEX *lex=Lex;
5989            Create_field *f= new (thd->mem_root) Create_field();
5990
5991            if (unlikely(check_string_char_length(&$1, 0, NAME_CHAR_LEN,
5992                                                  system_charset_info, 1)))
5993              my_yyabort_error((ER_TOO_LONG_IDENT, MYF(0), $1.str));
5994
5995            if (unlikely(!f))
5996              MYSQL_YYABORT;
5997
5998            lex->init_last_field(f, &$1, NULL);
5999            $<create_field>$= f;
6000            lex->parsing_options.lookup_keywords_after_qualifier= true;
6001          }
6002          field_type_or_serial opt_check_constraint
6003          {
6004            LEX *lex=Lex;
6005            lex->parsing_options.lookup_keywords_after_qualifier= false;
6006            $$= $<create_field>2;
6007
6008            $$->check_constraint= $4;
6009
6010            if (unlikely($$->check(thd)))
6011              MYSQL_YYABORT;
6012
6013            lex->alter_info.create_list.push_back($$, thd->mem_root);
6014
6015            $$->create_if_not_exists= Lex->check_exists;
6016            if ($$->flags & PRI_KEY_FLAG)
6017              lex->add_key_to_list(&$1, Key::PRIMARY, lex->check_exists);
6018            else if ($$->flags & UNIQUE_KEY_FLAG)
6019              lex->add_key_to_list(&$1, Key::UNIQUE, lex->check_exists);
6020          }
6021        ;
6022
6023field_type_or_serial:
6024          qualified_field_type
6025          {
6026             Lex->last_field->set_attributes(thd, $1, Lex->charset,
6027                                             COLUMN_DEFINITION_TABLE_FIELD);
6028          }
6029          field_def
6030        | SERIAL_SYM
6031          {
6032            Lex->last_field->set_handler(&type_handler_ulonglong);
6033            Lex->last_field->flags|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG
6034                                     | UNSIGNED_FLAG | UNIQUE_KEY_FLAG;
6035            Lex->alter_info.flags|= ALTER_ADD_INDEX;
6036          }
6037          opt_serial_attribute
6038        ;
6039
6040opt_serial_attribute:
6041          /* empty */ {}
6042        | opt_serial_attribute_list {}
6043        ;
6044
6045opt_serial_attribute_list:
6046          opt_serial_attribute_list serial_attribute {}
6047        | serial_attribute
6048        ;
6049
6050opt_asrow_attribute:
6051          /* empty */ {}
6052        | opt_asrow_attribute_list {}
6053        ;
6054
6055opt_asrow_attribute_list:
6056          opt_asrow_attribute_list asrow_attribute {}
6057        | asrow_attribute
6058        ;
6059
6060field_def:
6061          /* empty */ { }
6062        | attribute_list
6063        | attribute_list compressed_deprecated_column_attribute
6064        | attribute_list compressed_deprecated_column_attribute attribute_list
6065        | opt_generated_always AS virtual_column_func
6066         {
6067           Lex->last_field->vcol_info= $3;
6068           Lex->last_field->flags&= ~NOT_NULL_FLAG; // undo automatic NOT NULL for timestamps
6069         }
6070          vcol_opt_specifier vcol_opt_attribute
6071        | opt_generated_always AS ROW_SYM START_SYM opt_asrow_attribute
6072          {
6073            if (Lex->last_field_generated_always_as_row_start())
6074              MYSQL_YYABORT;
6075          }
6076        | opt_generated_always AS ROW_SYM END opt_asrow_attribute
6077          {
6078            if (Lex->last_field_generated_always_as_row_end())
6079              MYSQL_YYABORT;
6080          }
6081        ;
6082
6083opt_generated_always:
6084          /* empty */ {}
6085        | GENERATED_SYM ALWAYS_SYM {}
6086        ;
6087
6088vcol_opt_specifier:
6089          /* empty */
6090          {
6091            Lex->last_field->vcol_info->set_stored_in_db_flag(FALSE);
6092          }
6093        | VIRTUAL_SYM
6094          {
6095            Lex->last_field->vcol_info->set_stored_in_db_flag(FALSE);
6096          }
6097        | PERSISTENT_SYM
6098          {
6099            Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE);
6100          }
6101        | STORED_SYM
6102          {
6103            Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE);
6104          }
6105        ;
6106
6107vcol_opt_attribute:
6108          /* empty */ {}
6109        | vcol_opt_attribute_list {}
6110        ;
6111
6112vcol_opt_attribute_list:
6113          vcol_opt_attribute_list vcol_attribute {}
6114        | vcol_attribute
6115        ;
6116
6117vcol_attribute:
6118          UNIQUE_SYM
6119          {
6120            LEX *lex=Lex;
6121            lex->last_field->flags|= UNIQUE_KEY_FLAG;
6122            lex->alter_info.flags|= ALTER_ADD_INDEX;
6123          }
6124        | UNIQUE_SYM KEY_SYM
6125          {
6126            LEX *lex=Lex;
6127            lex->last_field->flags|= UNIQUE_KEY_FLAG;
6128            lex->alter_info.flags|= ALTER_ADD_INDEX;
6129          }
6130        | COMMENT_SYM TEXT_STRING_sys { Lex->last_field->comment= $2; }
6131        | INVISIBLE_SYM
6132          {
6133            Lex->last_field->invisible= INVISIBLE_USER;
6134          }
6135        ;
6136
6137parse_vcol_expr:
6138          PARSE_VCOL_EXPR_SYM
6139          {
6140            /*
6141              "PARSE_VCOL_EXPR" can only be used by the SQL server
6142              when reading a '*.frm' file.
6143              Prevent the end user from invoking this command.
6144            */
6145            MYSQL_YYABORT_UNLESS(Lex->parse_vcol_expr);
6146            if (Lex->main_select_push())
6147              MYSQL_YYABORT;
6148          }
6149          expr
6150          {
6151            Virtual_column_info *v= add_virtual_expression(thd, $3);
6152            if (unlikely(!v))
6153              MYSQL_YYABORT;
6154            Lex->last_field->vcol_info= v;
6155            Lex->pop_select(); //main select
6156          }
6157        ;
6158
6159parenthesized_expr:
6160          expr
6161        | expr ',' expr_list
6162          {
6163            $3->push_front($1, thd->mem_root);
6164            $$= new (thd->mem_root) Item_row(thd, *$3);
6165            if (unlikely($$ == NULL))
6166              MYSQL_YYABORT;
6167          }
6168          ;
6169
6170virtual_column_func:
6171          '(' parenthesized_expr ')'
6172          {
6173            Virtual_column_info *v=
6174              add_virtual_expression(thd, $2);
6175            if (unlikely(!v))
6176              MYSQL_YYABORT;
6177            $$= v;
6178          }
6179        | subquery
6180          {
6181            Item *item;
6182            if (!(item= new (thd->mem_root) Item_singlerow_subselect(thd, $1)))
6183              MYSQL_YYABORT;
6184            Virtual_column_info *v= add_virtual_expression(thd, item);
6185            if (unlikely(!v))
6186              MYSQL_YYABORT;
6187            $$= v;
6188          }
6189        ;
6190
6191expr_or_literal: column_default_non_parenthesized_expr | signed_literal ;
6192
6193column_default_expr:
6194          virtual_column_func
6195        | expr_or_literal
6196          {
6197            if (unlikely(!($$= add_virtual_expression(thd, $1))))
6198              MYSQL_YYABORT;
6199          }
6200        ;
6201
6202field_type: field_type_all
6203        {
6204          Lex->map_data_type(Lex_ident_sys(), &($$= $1));
6205        }
6206        ;
6207
6208qualified_field_type:
6209          field_type_all
6210          {
6211            Lex->map_data_type(Lex_ident_sys(), &($$= $1));
6212          }
6213        | sp_decl_ident '.' field_type_all
6214          {
6215            if (Lex->map_data_type($1, &($$= $3)))
6216              MYSQL_YYABORT;
6217          }
6218        ;
6219
6220field_type_all:
6221          field_type_numeric
6222        | field_type_temporal
6223        | field_type_string
6224        | field_type_lob
6225        | field_type_misc
6226        | IDENT_sys float_options srid_option
6227          {
6228            if (Lex->set_field_type_udt(&$$, $1, $2))
6229              MYSQL_YYABORT;
6230          }
6231        | reserved_keyword_udt float_options srid_option
6232          {
6233            if (Lex->set_field_type_udt(&$$, $1, $2))
6234              MYSQL_YYABORT;
6235          }
6236        | non_reserved_keyword_udt float_options srid_option
6237          {
6238            if (Lex->set_field_type_udt(&$$, $1, $2))
6239              MYSQL_YYABORT;
6240          }
6241        ;
6242
6243field_type_numeric:
6244          int_type opt_field_length last_field_options
6245          {
6246            $$.set_handler_length_flags($1, $2, (uint32) $3);
6247          }
6248        | real_type opt_precision last_field_options   { $$.set($1, $2); }
6249        | FLOAT_SYM float_options last_field_options
6250          {
6251            $$.set(&type_handler_float, $2);
6252            if ($2.length() && !$2.dec())
6253            {
6254              int err;
6255              ulonglong tmp_length= my_strtoll10($2.length(), NULL, &err);
6256              if (unlikely(err || tmp_length > PRECISION_FOR_DOUBLE))
6257                my_yyabort_error((ER_WRONG_FIELD_SPEC, MYF(0),
6258                                  Lex->last_field->field_name.str));
6259              if (tmp_length > PRECISION_FOR_FLOAT)
6260                $$.set(&type_handler_double);
6261              else
6262                $$.set(&type_handler_float);
6263            }
6264          }
6265        | BIT_SYM opt_field_length
6266          {
6267            $$.set(&type_handler_bit, $2);
6268          }
6269        | BOOL_SYM
6270          {
6271            $$.set(&type_handler_stiny, "1");
6272          }
6273        | BOOLEAN_SYM
6274          {
6275            $$.set(&type_handler_stiny, "1");
6276          }
6277        | DECIMAL_SYM float_options last_field_options
6278          { $$.set(&type_handler_newdecimal, $2);}
6279        | NUMBER_ORACLE_SYM float_options last_field_options
6280          {
6281            if ($2.length() != 0)
6282              $$.set(&type_handler_newdecimal, $2);
6283            else
6284              $$.set(&type_handler_double);
6285          }
6286        | NUMERIC_SYM float_options last_field_options
6287          { $$.set(&type_handler_newdecimal, $2);}
6288        | FIXED_SYM float_options last_field_options
6289          { $$.set(&type_handler_newdecimal, $2);}
6290        ;
6291
6292
6293opt_binary_and_compression:
6294          /* empty */
6295        | binary
6296        | binary compressed_deprecated_data_type_attribute
6297        | compressed opt_binary
6298        ;
6299
6300field_type_string:
6301          char opt_field_length opt_binary
6302          {
6303            $$.set(&type_handler_string, $2);
6304          }
6305        | nchar opt_field_length opt_bin_mod
6306          {
6307            $$.set(&type_handler_string, $2);
6308            bincmp_collation(national_charset_info, $3);
6309          }
6310        | BINARY opt_field_length
6311          {
6312            Lex->charset=&my_charset_bin;
6313            $$.set(&type_handler_string, $2);
6314          }
6315        | varchar opt_field_length opt_binary_and_compression
6316          {
6317            $$.set(&type_handler_varchar, $2);
6318          }
6319        | VARCHAR2_ORACLE_SYM opt_field_length opt_binary_and_compression
6320          {
6321            $$.set(&type_handler_varchar, $2);
6322          }
6323        | nvarchar opt_field_length opt_compressed opt_bin_mod
6324          {
6325            $$.set(&type_handler_varchar, $2);
6326            bincmp_collation(national_charset_info, $4);
6327          }
6328        | VARBINARY opt_field_length opt_compressed
6329          {
6330            Lex->charset=&my_charset_bin;
6331            $$.set(&type_handler_varchar, $2);
6332          }
6333        | RAW_ORACLE_SYM opt_field_length opt_compressed
6334          {
6335            Lex->charset= &my_charset_bin;
6336            $$.set(&type_handler_varchar, $2);
6337          }
6338        ;
6339
6340field_type_temporal:
6341          YEAR_SYM opt_field_length last_field_options
6342          {
6343            if ($2)
6344            {
6345              errno= 0;
6346              ulong length= strtoul($2, NULL, 10);
6347              if (errno == 0 && length <= MAX_FIELD_BLOBLENGTH && length != 4)
6348              {
6349                char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1];
6350                my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length);
6351                push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
6352                                    ER_WARN_DEPRECATED_SYNTAX,
6353                                    ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
6354                                    buff, "YEAR(4)");
6355              }
6356            }
6357            $$.set(&type_handler_year, $2);
6358          }
6359        | DATE_SYM { $$.set(&type_handler_newdate); }
6360        | TIME_SYM opt_field_length
6361          {
6362            $$.set(opt_mysql56_temporal_format ?
6363                   static_cast<const Type_handler*>(&type_handler_time2) :
6364                   static_cast<const Type_handler*>(&type_handler_time),
6365                   $2);
6366          }
6367        | TIMESTAMP opt_field_length
6368          {
6369            $$.set(opt_mysql56_temporal_format ?
6370                   static_cast<const Type_handler*>(&type_handler_timestamp2):
6371                   static_cast<const Type_handler*>(&type_handler_timestamp),
6372                   $2);
6373          }
6374        | DATETIME opt_field_length
6375          {
6376            $$.set(thd->type_handler_for_datetime(), $2);
6377          }
6378        ;
6379
6380
6381field_type_lob:
6382          TINYBLOB opt_compressed
6383          {
6384            Lex->charset=&my_charset_bin;
6385            $$.set(&type_handler_tiny_blob);
6386          }
6387        | BLOB_MARIADB_SYM opt_field_length opt_compressed
6388          {
6389            Lex->charset=&my_charset_bin;
6390            $$.set(&type_handler_blob, $2);
6391          }
6392        | BLOB_ORACLE_SYM field_length opt_compressed
6393          {
6394            Lex->charset=&my_charset_bin;
6395            $$.set(&type_handler_blob, $2);
6396          }
6397        | BLOB_ORACLE_SYM opt_compressed
6398          {
6399            Lex->charset=&my_charset_bin;
6400            $$.set(&type_handler_long_blob);
6401          }
6402        | MEDIUMBLOB opt_compressed
6403          {
6404            Lex->charset=&my_charset_bin;
6405            $$.set(&type_handler_medium_blob);
6406          }
6407        | LONGBLOB opt_compressed
6408          {
6409            Lex->charset=&my_charset_bin;
6410            $$.set(&type_handler_long_blob);
6411          }
6412        | LONG_SYM VARBINARY opt_compressed
6413          {
6414            Lex->charset=&my_charset_bin;
6415            $$.set(&type_handler_medium_blob);
6416          }
6417        | LONG_SYM varchar opt_binary_and_compression
6418          { $$.set(&type_handler_medium_blob); }
6419        | TINYTEXT opt_binary_and_compression
6420          { $$.set(&type_handler_tiny_blob); }
6421        | TEXT_SYM opt_field_length opt_binary_and_compression
6422          { $$.set(&type_handler_blob, $2); }
6423        | MEDIUMTEXT opt_binary_and_compression
6424          { $$.set(&type_handler_medium_blob); }
6425        | LONGTEXT opt_binary_and_compression
6426          { $$.set(&type_handler_long_blob); }
6427        | CLOB_ORACLE_SYM opt_binary_and_compression
6428          { $$.set(&type_handler_long_blob); }
6429        | LONG_SYM opt_binary_and_compression
6430          { $$.set(&type_handler_medium_blob); }
6431        | JSON_SYM opt_compressed
6432          {
6433            Lex->charset= &my_charset_utf8mb4_bin;
6434            $$.set(&type_handler_long_blob_json);
6435          }
6436        ;
6437
6438field_type_misc:
6439          ENUM '(' string_list ')' opt_binary
6440          { $$.set(&type_handler_enum); }
6441        | SET '(' string_list ')' opt_binary
6442          { $$.set(&type_handler_set); }
6443        ;
6444
6445char:
6446          CHAR_SYM {}
6447        ;
6448
6449nchar:
6450          NCHAR_SYM {}
6451        | NATIONAL_SYM CHAR_SYM {}
6452        ;
6453
6454varchar:
6455          char VARYING {}
6456        | VARCHAR {}
6457        ;
6458
6459nvarchar:
6460          NATIONAL_SYM VARCHAR {}
6461        | NVARCHAR_SYM {}
6462        | NCHAR_SYM VARCHAR {}
6463        | NATIONAL_SYM CHAR_SYM VARYING {}
6464        | NCHAR_SYM VARYING {}
6465        ;
6466
6467int_type:
6468          INT_SYM   { $$= &type_handler_slong; }
6469        | TINYINT   { $$= &type_handler_stiny; }
6470        | SMALLINT  { $$= &type_handler_sshort; }
6471        | MEDIUMINT { $$= &type_handler_sint24; }
6472        | BIGINT    { $$= &type_handler_slonglong; }
6473        ;
6474
6475real_type:
6476          REAL
6477          {
6478            $$= thd->variables.sql_mode & MODE_REAL_AS_FLOAT ?
6479              static_cast<const Type_handler *>(&type_handler_float) :
6480              static_cast<const Type_handler *>(&type_handler_double);
6481          }
6482        | DOUBLE_SYM           { $$= &type_handler_double; }
6483        | DOUBLE_SYM PRECISION { $$= &type_handler_double; }
6484        ;
6485
6486srid_option:
6487          /* empty */
6488          { Lex->last_field->srid= 0; }
6489        |
6490          REF_SYSTEM_ID_SYM '=' NUM
6491          {
6492            Lex->last_field->srid=atoi($3.str);
6493          }
6494        ;
6495
6496float_options:
6497          /* empty */  { $$.set(0, 0);  }
6498        | field_length { $$.set($1, 0); }
6499        | precision    { $$= $1; }
6500        ;
6501
6502precision:
6503          '(' NUM ',' NUM ')' { $$.set($2.str, $4.str); }
6504        ;
6505
6506field_options:
6507          /* empty */       { $$= 0; }
6508        | SIGNED_SYM        { $$= 0; }
6509        | UNSIGNED          { $$= UNSIGNED_FLAG; }
6510        | ZEROFILL          { $$= UNSIGNED_FLAG | ZEROFILL_FLAG; }
6511        | UNSIGNED ZEROFILL { $$= UNSIGNED_FLAG | ZEROFILL_FLAG; }
6512        | ZEROFILL UNSIGNED { $$= UNSIGNED_FLAG | ZEROFILL_FLAG; }
6513        ;
6514
6515last_field_options:
6516          field_options { Lex->last_field->flags|= ($$= $1); }
6517        ;
6518
6519field_length:
6520          '(' LONG_NUM ')'      { $$= $2.str; }
6521        | '(' ULONGLONG_NUM ')' { $$= $2.str; }
6522        | '(' DECIMAL_NUM ')'   { $$= $2.str; }
6523        | '(' NUM ')'           { $$= $2.str; }
6524        ;
6525
6526opt_field_length:
6527          /* empty */  { $$= (char*) 0; /* use default length */ }
6528        | field_length { $$= $1; }
6529        ;
6530
6531opt_precision:
6532          /* empty */    { $$.set(0, 0); }
6533        | precision      { $$= $1; }
6534        ;
6535
6536
6537attribute_list:
6538          attribute_list attribute {}
6539        | attribute
6540        ;
6541
6542attribute:
6543          NULL_SYM { Lex->last_field->flags&= ~ NOT_NULL_FLAG; }
6544        | DEFAULT column_default_expr { Lex->last_field->default_value= $2; }
6545        | ON UPDATE_SYM NOW_SYM opt_default_time_precision
6546          {
6547            Item *item= new (thd->mem_root) Item_func_now_local(thd, $4);
6548            if (unlikely(item == NULL))
6549              MYSQL_YYABORT;
6550            Lex->last_field->on_update= item;
6551          }
6552        | AUTO_INC { Lex->last_field->flags|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
6553        | SERIAL_SYM DEFAULT VALUE_SYM
6554          {
6555            LEX *lex=Lex;
6556            lex->last_field->flags|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_KEY_FLAG;
6557            lex->alter_info.flags|= ALTER_ADD_INDEX;
6558          }
6559        | COLLATE_SYM collation_name
6560          {
6561            if (unlikely(Lex->charset && !my_charset_same(Lex->charset,$2)))
6562              my_yyabort_error((ER_COLLATION_CHARSET_MISMATCH, MYF(0),
6563                                $2->name,Lex->charset->csname));
6564            Lex->last_field->charset= $2;
6565          }
6566        | serial_attribute
6567        ;
6568
6569opt_compression_method:
6570          /* empty */ { $$= NULL; }
6571        | equal ident { $$= $2.str; }
6572        ;
6573
6574opt_compressed:
6575          /* empty */ {}
6576        | compressed { }
6577        ;
6578
6579opt_enable:
6580          /* empty */ {}
6581        | ENABLE_SYM { }
6582        ;
6583
6584compressed:
6585          COMPRESSED_SYM opt_compression_method
6586          {
6587            if (unlikely(Lex->last_field->set_compressed($2)))
6588              MYSQL_YYABORT;
6589          }
6590        ;
6591
6592compressed_deprecated_data_type_attribute:
6593          COMPRESSED_SYM opt_compression_method
6594          {
6595            if (unlikely(Lex->last_field->set_compressed_deprecated(thd, $2)))
6596              MYSQL_YYABORT;
6597          }
6598        ;
6599
6600compressed_deprecated_column_attribute:
6601          COMPRESSED_SYM opt_compression_method
6602          {
6603            if (unlikely(Lex->last_field->
6604                set_compressed_deprecated_column_attribute(thd, $1.pos(), $2)))
6605              MYSQL_YYABORT;
6606          }
6607        ;
6608
6609asrow_attribute:
6610          not NULL_SYM opt_enable
6611          {
6612            Lex->last_field->flags|= NOT_NULL_FLAG;
6613          }
6614        | opt_primary KEY_SYM
6615          {
6616            LEX *lex=Lex;
6617            lex->last_field->flags|= PRI_KEY_FLAG | NOT_NULL_FLAG;
6618            lex->alter_info.flags|= ALTER_ADD_INDEX;
6619          }
6620        | vcol_attribute
6621        ;
6622
6623serial_attribute:
6624          asrow_attribute
6625        | IDENT_sys equal TEXT_STRING_sys
6626          {
6627            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
6628              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
6629            (void) new (thd->mem_root)
6630                   engine_option_value($1, $3, true,
6631                                       &Lex->last_field->option_list,
6632                                       &Lex->option_list_last);
6633          }
6634        | IDENT_sys equal ident
6635          {
6636            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
6637              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
6638            (void) new (thd->mem_root)
6639                   engine_option_value($1, $3, false,
6640                                       &Lex->last_field->option_list,
6641                                       &Lex->option_list_last);
6642          }
6643        | IDENT_sys equal real_ulonglong_num
6644          {
6645            (void) new (thd->mem_root)
6646                   engine_option_value($1, $3, &Lex->last_field->option_list,
6647                                       &Lex->option_list_last, thd->mem_root);
6648          }
6649        | IDENT_sys equal DEFAULT
6650          {
6651            (void) new (thd->mem_root)
6652                   engine_option_value($1, &Lex->last_field->option_list,
6653                                       &Lex->option_list_last);
6654          }
6655        | with_or_without_system VERSIONING_SYM
6656          {
6657            Lex->last_field->versioning= $1;
6658            Lex->create_info.options|= HA_VERSIONED_TABLE;
6659            if (Lex->alter_info.flags & ALTER_DROP_SYSTEM_VERSIONING)
6660            {
6661              my_yyabort_error((ER_VERS_NOT_VERSIONED, MYF(0),
6662                       Lex->create_last_non_select_table->table_name.str));
6663            }
6664          }
6665        ;
6666
6667with_or_without_system:
6668        WITH_SYSTEM_SYM
6669          {
6670            Lex->alter_info.flags|= ALTER_COLUMN_UNVERSIONED;
6671            Lex->create_info.vers_info.versioned_fields= true;
6672            $$= Column_definition::WITH_VERSIONING;
6673          }
6674        | WITHOUT SYSTEM
6675          {
6676            Lex->alter_info.flags|= ALTER_COLUMN_UNVERSIONED;
6677            Lex->create_info.vers_info.unversioned_fields= true;
6678            $$= Column_definition::WITHOUT_VERSIONING;
6679          }
6680        ;
6681
6682
6683charset:
6684          CHAR_SYM SET { $$= $1; }
6685        | CHARSET { $$= $1; }
6686        ;
6687
6688charset_name:
6689          ident_or_text
6690          {
6691            if (unlikely(!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0)))))
6692              my_yyabort_error((ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str));
6693          }
6694        | BINARY { $$= &my_charset_bin; }
6695        ;
6696
6697charset_name_or_default:
6698          charset_name { $$=$1;   }
6699        | DEFAULT    { $$=NULL; }
6700        ;
6701
6702opt_load_data_charset:
6703          /* Empty */ { $$= NULL; }
6704        | charset charset_name_or_default { $$= $2; }
6705        ;
6706
6707old_or_new_charset_name:
6708          ident_or_text
6709          {
6710            if (unlikely(!($$=get_charset_by_csname($1.str,
6711                                                    MY_CS_PRIMARY,MYF(0))) &&
6712                         !($$=get_old_charset_by_name($1.str))))
6713              my_yyabort_error((ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str));
6714          }
6715        | BINARY { $$= &my_charset_bin; }
6716        ;
6717
6718old_or_new_charset_name_or_default:
6719          old_or_new_charset_name { $$=$1;   }
6720        | DEFAULT    { $$=NULL; }
6721        ;
6722
6723collation_name:
6724          ident_or_text
6725          {
6726            if (unlikely(!($$= mysqld_collation_get_by_name($1.str))))
6727              MYSQL_YYABORT;
6728          }
6729        ;
6730
6731opt_collate:
6732          /* empty */ { $$=NULL; }
6733        | COLLATE_SYM collation_name_or_default { $$=$2; }
6734        ;
6735
6736collation_name_or_default:
6737          collation_name { $$=$1; }
6738        | DEFAULT    { $$=NULL; }
6739        ;
6740
6741opt_default:
6742          /* empty */ {}
6743        | DEFAULT {}
6744        ;
6745
6746charset_or_alias:
6747          charset charset_name { $$= $2; }
6748        | ASCII_SYM { $$= &my_charset_latin1; }
6749        | UNICODE_SYM
6750          {
6751            if (unlikely(!($$= get_charset_by_csname("ucs2", MY_CS_PRIMARY,MYF(0)))))
6752              my_yyabort_error((ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2"));
6753          }
6754        ;
6755
6756collate: COLLATE_SYM collation_name_or_default
6757         {
6758           Lex->charset= $2;
6759         }
6760       ;
6761
6762opt_binary:
6763          /* empty */             { bincmp_collation(NULL, false); }
6764        | binary {}
6765        ;
6766
6767binary:
6768          BYTE_SYM                { bincmp_collation(&my_charset_bin, false); }
6769        | charset_or_alias opt_bin_mod { bincmp_collation($1, $2); }
6770        | BINARY                  { bincmp_collation(NULL, true); }
6771        | BINARY charset_or_alias { bincmp_collation($2, true); }
6772        | charset_or_alias collate
6773          {
6774            if (!my_charset_same(Lex->charset, $1))
6775              my_yyabort_error((ER_COLLATION_CHARSET_MISMATCH, MYF(0),
6776                                Lex->charset->name, $1->csname));
6777          }
6778        | collate { }
6779        ;
6780
6781opt_bin_mod:
6782          /* empty */   { $$= false; }
6783        | BINARY        { $$= true; }
6784        ;
6785
6786ws_nweights:
6787        '(' real_ulong_num
6788        {
6789          if (unlikely($2 == 0))
6790          {
6791            thd->parse_error();
6792            MYSQL_YYABORT;
6793          }
6794        }
6795        ')'
6796        { $$= $2; }
6797        ;
6798
6799ws_level_flag_desc:
6800        ASC { $$= 0; }
6801        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
6802        ;
6803
6804ws_level_flag_reverse:
6805        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
6806
6807ws_level_flags:
6808        /* empty */ { $$= 0; }
6809        | ws_level_flag_desc { $$= $1; }
6810        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
6811        | ws_level_flag_reverse { $$= $1 ; }
6812        ;
6813
6814ws_level_number:
6815        real_ulong_num
6816        {
6817          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
6818          $$--;
6819        }
6820        ;
6821
6822ws_level_list_item:
6823        ws_level_number ws_level_flags
6824        {
6825          $$= (1 | $2) << $1;
6826        }
6827        ;
6828
6829ws_level_list:
6830        ws_level_list_item { $$= $1; }
6831        | ws_level_list ',' ws_level_list_item { $$|= $3; }
6832        ;
6833
6834ws_level_range:
6835        ws_level_number '-' ws_level_number
6836        {
6837          uint start= $1;
6838          uint end= $3;
6839          for ($$= 0; start <= end; start++)
6840            $$|= (1 << start);
6841        }
6842        ;
6843
6844ws_level_list_or_range:
6845        ws_level_list { $$= $1; }
6846        | ws_level_range { $$= $1; }
6847        ;
6848
6849opt_ws_levels:
6850        /* empty*/ { $$= 0; }
6851        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
6852        ;
6853
6854opt_primary:
6855          /* empty */
6856        | PRIMARY_SYM
6857        ;
6858
6859references:
6860          REFERENCES
6861          table_ident
6862          opt_ref_list
6863          opt_match_clause
6864          opt_on_update_delete
6865          {
6866            $$=$2;
6867          }
6868        ;
6869
6870opt_ref_list:
6871          /* empty */
6872          { Lex->ref_list.empty(); }
6873        | '(' ref_list ')'
6874        ;
6875
6876ref_list:
6877          ref_list ',' ident
6878          {
6879            Key_part_spec *key= new (thd->mem_root) Key_part_spec(&$3, 0);
6880            if (unlikely(key == NULL))
6881              MYSQL_YYABORT;
6882            Lex->ref_list.push_back(key, thd->mem_root);
6883          }
6884        | ident
6885          {
6886            Key_part_spec *key= new (thd->mem_root) Key_part_spec(&$1, 0);
6887            if (unlikely(key == NULL))
6888              MYSQL_YYABORT;
6889            LEX *lex= Lex;
6890            lex->ref_list.empty();
6891            lex->ref_list.push_back(key, thd->mem_root);
6892          }
6893        ;
6894
6895opt_match_clause:
6896          /* empty */
6897          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
6898        | MATCH FULL
6899          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
6900        | MATCH PARTIAL
6901          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
6902        | MATCH SIMPLE_SYM
6903          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
6904        ;
6905
6906opt_on_update_delete:
6907          /* empty */
6908          {
6909            LEX *lex= Lex;
6910            lex->fk_update_opt= FK_OPTION_UNDEF;
6911            lex->fk_delete_opt= FK_OPTION_UNDEF;
6912          }
6913        | ON UPDATE_SYM delete_option
6914          {
6915            LEX *lex= Lex;
6916            lex->fk_update_opt= $3;
6917            lex->fk_delete_opt= FK_OPTION_UNDEF;
6918          }
6919        | ON DELETE_SYM delete_option
6920          {
6921            LEX *lex= Lex;
6922            lex->fk_update_opt= FK_OPTION_UNDEF;
6923            lex->fk_delete_opt= $3;
6924          }
6925        | ON UPDATE_SYM delete_option
6926          ON DELETE_SYM delete_option
6927          {
6928            LEX *lex= Lex;
6929            lex->fk_update_opt= $3;
6930            lex->fk_delete_opt= $6;
6931          }
6932        | ON DELETE_SYM delete_option
6933          ON UPDATE_SYM delete_option
6934          {
6935            LEX *lex= Lex;
6936            lex->fk_update_opt= $6;
6937            lex->fk_delete_opt= $3;
6938          }
6939        ;
6940
6941delete_option:
6942          RESTRICT      { $$= FK_OPTION_RESTRICT; }
6943        | CASCADE       { $$= FK_OPTION_CASCADE; }
6944        | SET NULL_SYM  { $$= FK_OPTION_SET_NULL; }
6945        | NO_SYM ACTION { $$= FK_OPTION_NO_ACTION; }
6946        | SET DEFAULT   { $$= FK_OPTION_SET_DEFAULT; }
6947        ;
6948
6949constraint_key_type:
6950          PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
6951        | UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; }
6952        ;
6953
6954key_or_index:
6955          KEY_SYM {}
6956        | INDEX_SYM {}
6957        ;
6958
6959opt_key_or_index:
6960          /* empty */ {}
6961        | key_or_index
6962        ;
6963
6964keys_or_index:
6965          KEYS {}
6966        | INDEX_SYM {}
6967        | INDEXES {}
6968        ;
6969
6970fulltext:
6971          FULLTEXT_SYM { $$= Key::FULLTEXT;}
6972        ;
6973
6974spatial:
6975          SPATIAL_SYM
6976          {
6977#ifdef HAVE_SPATIAL
6978            $$= Key::SPATIAL;
6979#else
6980            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), sym_group_geom.name,
6981                              sym_group_geom.needed_define));
6982#endif
6983          }
6984        ;
6985
6986normal_key_options:
6987          /* empty */ {}
6988        | normal_key_opts { Lex->last_key->option_list= Lex->option_list; }
6989        ;
6990
6991fulltext_key_options:
6992          /* empty */ {}
6993        | fulltext_key_opts { Lex->last_key->option_list= Lex->option_list; }
6994        ;
6995
6996spatial_key_options:
6997          /* empty */ {}
6998        | spatial_key_opts { Lex->last_key->option_list= Lex->option_list; }
6999        ;
7000
7001normal_key_opts:
7002          normal_key_opt
7003        | normal_key_opts normal_key_opt
7004        ;
7005
7006spatial_key_opts:
7007          spatial_key_opt
7008        | spatial_key_opts spatial_key_opt
7009        ;
7010
7011fulltext_key_opts:
7012          fulltext_key_opt
7013        | fulltext_key_opts fulltext_key_opt
7014        ;
7015
7016opt_USING_key_algorithm:
7017          /* Empty*/              { $$= HA_KEY_ALG_UNDEF; }
7018        | USING    btree_or_rtree { $$= $2; }
7019        ;
7020
7021/* TYPE is a valid identifier, so it's handled differently than USING */
7022opt_key_algorithm_clause:
7023          /* Empty*/              { $$= HA_KEY_ALG_UNDEF; }
7024        | USING    btree_or_rtree { $$= $2; }
7025        | TYPE_SYM btree_or_rtree { $$= $2; }
7026        ;
7027
7028key_using_alg:
7029          USING btree_or_rtree
7030          { Lex->last_key->key_create_info.algorithm= $2; }
7031        | TYPE_SYM btree_or_rtree
7032          { Lex->last_key->key_create_info.algorithm= $2; }
7033        ;
7034
7035all_key_opt:
7036          KEY_BLOCK_SIZE opt_equal ulong_num
7037          {
7038            Lex->last_key->key_create_info.block_size= $3;
7039            Lex->last_key->key_create_info.flags|= HA_USES_BLOCK_SIZE;
7040         }
7041        | COMMENT_SYM TEXT_STRING_sys
7042          { Lex->last_key->key_create_info.comment= $2; }
7043        | VISIBLE_SYM
7044          {
7045            /* This is mainly for MySQL 8.0 compatiblity */
7046          }
7047        | IDENT_sys equal TEXT_STRING_sys
7048          {
7049            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
7050              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
7051            (void) new (thd->mem_root)
7052                   engine_option_value($1, $3, true, &Lex->option_list,
7053                                       &Lex->option_list_last);
7054          }
7055        | IDENT_sys equal ident
7056          {
7057            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
7058              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
7059            (void) new (thd->mem_root)
7060                   engine_option_value($1, $3, false, &Lex->option_list,
7061                                       &Lex->option_list_last);
7062          }
7063        | IDENT_sys equal real_ulonglong_num
7064          {
7065            (void) new (thd->mem_root)
7066                  engine_option_value($1, $3, &Lex->option_list,
7067                                      &Lex->option_list_last, thd->mem_root);
7068          }
7069        | IDENT_sys equal DEFAULT
7070          {
7071            (void) new (thd->mem_root)
7072                   engine_option_value($1, &Lex->option_list,
7073                                       &Lex->option_list_last);
7074          }
7075        ;
7076
7077normal_key_opt:
7078          all_key_opt
7079        | key_using_alg
7080        ;
7081
7082spatial_key_opt:
7083          all_key_opt
7084        ;
7085
7086fulltext_key_opt:
7087          all_key_opt
7088        | WITH PARSER_SYM IDENT_sys
7089          {
7090            if (likely(plugin_is_ready(&$3, MYSQL_FTPARSER_PLUGIN)))
7091              Lex->last_key->key_create_info.parser_name= $3;
7092            else
7093              my_yyabort_error((ER_FUNCTION_NOT_DEFINED, MYF(0), $3.str));
7094          }
7095        ;
7096
7097btree_or_rtree:
7098          BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
7099        | RTREE_SYM { $$= HA_KEY_ALG_RTREE; }
7100        | HASH_SYM  { $$= HA_KEY_ALG_HASH; }
7101        ;
7102
7103key_list:
7104          key_list ',' key_part order_dir
7105          {
7106            Lex->last_key->columns.push_back($3, thd->mem_root);
7107          }
7108        | key_part order_dir
7109          {
7110            Lex->last_key->columns.push_back($1, thd->mem_root);
7111          }
7112        ;
7113
7114opt_without_overlaps:
7115         /* nothing */ {}
7116         | ',' ident WITHOUT OVERLAPS_SYM
7117          {
7118            Lex->last_key->without_overlaps= true;
7119            Lex->last_key->period= $2;
7120          }
7121         ;
7122
7123key_part:
7124          ident
7125          {
7126            $$= new (thd->mem_root) Key_part_spec(&$1, 0);
7127            if (unlikely($$ == NULL))
7128              MYSQL_YYABORT;
7129          }
7130        | ident '(' NUM ')'
7131          {
7132            int key_part_len= atoi($3.str);
7133            if (unlikely(!key_part_len))
7134              my_yyabort_error((ER_KEY_PART_0, MYF(0), $1.str));
7135            $$= new (thd->mem_root) Key_part_spec(&$1, (uint) key_part_len);
7136            if (unlikely($$ == NULL))
7137              MYSQL_YYABORT;
7138          }
7139        ;
7140
7141opt_ident:
7142          /* empty */ { $$= null_clex_str; }
7143        | field_ident { $$= $1; }
7144        ;
7145
7146string_list:
7147          text_string
7148          { Lex->last_field->interval_list.push_back($1, thd->mem_root); }
7149        | string_list ',' text_string
7150          { Lex->last_field->interval_list.push_back($3, thd->mem_root); }
7151        ;
7152
7153/*
7154** Alter table
7155*/
7156
7157alter:
7158          ALTER
7159          {
7160            Lex->name= null_clex_str;
7161            Lex->table_type= TABLE_TYPE_UNKNOWN;
7162            Lex->sql_command= SQLCOM_ALTER_TABLE;
7163            Lex->duplicates= DUP_ERROR;
7164            Lex->first_select_lex()->order_list.empty();
7165            Lex->create_info.init();
7166            Lex->create_info.row_type= ROW_TYPE_NOT_USED;
7167            Lex->alter_info.reset();
7168            Lex->no_write_to_binlog= 0;
7169            Lex->create_info.storage_media= HA_SM_DEFAULT;
7170            if (Lex->main_select_push())
7171              MYSQL_YYABORT;
7172            DBUG_ASSERT(!Lex->m_sql_cmd);
7173          }
7174          alter_options TABLE_SYM opt_if_exists table_ident opt_lock_wait_timeout
7175          {
7176            Lex->create_info.set($5);
7177            if (!Lex->first_select_lex()->
7178                 add_table_to_list(thd, $6, NULL, TL_OPTION_UPDATING,
7179                                   TL_READ_NO_INSERT, MDL_SHARED_UPGRADABLE))
7180              MYSQL_YYABORT;
7181            Lex->first_select_lex()->db=
7182              (Lex->first_select_lex()->table_list.first)->db;
7183            Lex->create_last_non_select_table= Lex->last_table();
7184            Lex->mark_first_table_as_inserting();
7185          }
7186          alter_commands
7187          {
7188            if (likely(!Lex->m_sql_cmd))
7189            {
7190              /* Create a generic ALTER TABLE statment. */
7191              Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_table();
7192              if (unlikely(Lex->m_sql_cmd == NULL))
7193                MYSQL_YYABORT;
7194            }
7195            Lex->pop_select(); //main select
7196          }
7197        | ALTER DATABASE ident_or_empty
7198          {
7199            Lex->create_info.default_table_charset= NULL;
7200            Lex->create_info.schema_comment= NULL;
7201            Lex->create_info.used_fields= 0;
7202            if (Lex->main_select_push(true))
7203              MYSQL_YYABORT;
7204          }
7205          create_database_options
7206          {
7207            LEX *lex=Lex;
7208            lex->sql_command=SQLCOM_ALTER_DB;
7209            lex->name= $3;
7210            if (lex->name.str == NULL &&
7211                unlikely(lex->copy_db_to(&lex->name)))
7212              MYSQL_YYABORT;
7213            Lex->pop_select(); //main select
7214          }
7215        | ALTER DATABASE COMMENT_SYM opt_equal TEXT_STRING_sys
7216          {
7217            Lex->create_info.default_table_charset= NULL;
7218            Lex->create_info.used_fields= 0;
7219            Lex->create_info.schema_comment= thd->make_clex_string($5);
7220            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
7221          }
7222          opt_create_database_options
7223          {
7224            LEX *lex=Lex;
7225            lex->sql_command=SQLCOM_ALTER_DB;
7226            lex->name= Lex_ident_sys();
7227            if (lex->name.str == NULL &&
7228                unlikely(lex->copy_db_to(&lex->name)))
7229              MYSQL_YYABORT;
7230          }
7231        | ALTER DATABASE ident UPGRADE_SYM DATA_SYM DIRECTORY_SYM NAME_SYM
7232          {
7233            LEX *lex= Lex;
7234            if (unlikely(lex->sphead))
7235              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "DATABASE"));
7236            lex->sql_command= SQLCOM_ALTER_DB_UPGRADE;
7237            lex->name= $3;
7238          }
7239        | ALTER PROCEDURE_SYM sp_name
7240          {
7241            if (Lex->stmt_alter_procedure_start($3))
7242              MYSQL_YYABORT;
7243          }
7244          sp_a_chistics
7245          stmt_end {}
7246        | ALTER FUNCTION_SYM sp_name
7247          {
7248            if (Lex->stmt_alter_function_start($3))
7249              MYSQL_YYABORT;
7250          }
7251          sp_a_chistics
7252          stmt_end {}
7253        | ALTER view_algorithm definer_opt opt_view_suid VIEW_SYM table_ident
7254          {
7255            if (Lex->main_select_push())
7256              MYSQL_YYABORT;
7257            if (Lex->add_alter_view(thd, $2, $4, $6))
7258              MYSQL_YYABORT;
7259          }
7260          view_list_opt AS view_select stmt_end {}
7261        | ALTER definer_opt opt_view_suid VIEW_SYM table_ident
7262          /*
7263            We have two separate rules for ALTER VIEW rather that
7264            optional view_algorithm above, to resolve the ambiguity
7265            with the ALTER EVENT below.
7266          */
7267          {
7268            if (Lex->main_select_push())
7269              MYSQL_YYABORT;
7270            if (Lex->add_alter_view(thd, VIEW_ALGORITHM_INHERIT, $3, $5))
7271              MYSQL_YYABORT;
7272          }
7273          view_list_opt AS view_select stmt_end {}
7274        | ALTER definer_opt remember_name EVENT_SYM sp_name
7275          {
7276            if (Lex->main_select_push())
7277              MYSQL_YYABORT;
7278            /*
7279              It is safe to use Lex->spname because
7280              ALTER EVENT xxx RENATE TO yyy DO ALTER EVENT RENAME TO
7281              is not allowed. Lex->spname is used in the case of RENAME TO
7282              If it had to be supported spname had to be added to
7283              Event_parse_data.
7284            */
7285
7286            if (unlikely(!(Lex->event_parse_data= Event_parse_data::new_instance(thd))))
7287              MYSQL_YYABORT;
7288            Lex->event_parse_data->identifier= $5;
7289
7290            Lex->sql_command= SQLCOM_ALTER_EVENT;
7291            Lex->stmt_definition_begin= $3;
7292          }
7293          ev_alter_on_schedule_completion
7294          opt_ev_rename_to
7295          opt_ev_status
7296          opt_ev_comment
7297          opt_ev_sql_stmt
7298          {
7299            if (unlikely(!($7 || $8 || $9 || $10 || $11)))
7300            {
7301              thd->parse_error();
7302              MYSQL_YYABORT;
7303            }
7304            /*
7305              sql_command is set here because some rules in ev_sql_stmt
7306              can overwrite it
7307            */
7308            Lex->sql_command= SQLCOM_ALTER_EVENT;
7309            Lex->stmt_definition_end= (char*)YYLIP->get_cpp_ptr();
7310
7311            Lex->pop_select(); //main select
7312          }
7313        | ALTER TABLESPACE alter_tablespace_info
7314          {
7315            LEX *lex= Lex;
7316            lex->alter_tablespace_info->ts_cmd_type= ALTER_TABLESPACE;
7317          }
7318        | ALTER LOGFILE_SYM GROUP_SYM alter_logfile_group_info
7319          {
7320            LEX *lex= Lex;
7321            lex->alter_tablespace_info->ts_cmd_type= ALTER_LOGFILE_GROUP;
7322          }
7323        | ALTER TABLESPACE change_tablespace_info
7324          {
7325            LEX *lex= Lex;
7326            lex->alter_tablespace_info->ts_cmd_type= CHANGE_FILE_TABLESPACE;
7327          }
7328        | ALTER TABLESPACE change_tablespace_access
7329          {
7330            LEX *lex= Lex;
7331            lex->alter_tablespace_info->ts_cmd_type= ALTER_ACCESS_MODE_TABLESPACE;
7332          }
7333        | ALTER SERVER_SYM ident_or_text
7334          {
7335            LEX *lex= Lex;
7336            lex->sql_command= SQLCOM_ALTER_SERVER;
7337            lex->server_options.reset($3);
7338          } OPTIONS_SYM '(' server_options_list ')' { }
7339          /* ALTER USER foo is allowed for MySQL compatibility. */
7340        | ALTER USER_SYM opt_if_exists clear_privileges grant_list
7341          opt_require_clause opt_resource_options opt_account_locking_and_opt_password_expiration
7342          {
7343            Lex->create_info.set($3);
7344            Lex->sql_command= SQLCOM_ALTER_USER;
7345          }
7346        | ALTER SEQUENCE_SYM opt_if_exists
7347          {
7348            LEX *lex= Lex;
7349            lex->name= null_clex_str;
7350            lex->table_type= TABLE_TYPE_UNKNOWN;
7351            lex->sql_command= SQLCOM_ALTER_SEQUENCE;
7352            lex->create_info.init();
7353            lex->no_write_to_binlog= 0;
7354            DBUG_ASSERT(!lex->m_sql_cmd);
7355            if (Lex->main_select_push())
7356              MYSQL_YYABORT;
7357          }
7358          table_ident
7359          {
7360            LEX *lex= Lex;
7361            if (!(lex->create_info.seq_create_info= new (thd->mem_root)
7362                                                     sequence_definition()) ||
7363                !lex->first_select_lex()->
7364                  add_table_to_list(thd, $5, NULL, TL_OPTION_SEQUENCE,
7365                                    TL_WRITE, MDL_EXCLUSIVE))
7366              MYSQL_YYABORT;
7367          }
7368          sequence_defs
7369          {
7370            /* Create a generic ALTER SEQUENCE statment. */
7371            Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_sequence($3);
7372            if (unlikely(Lex->m_sql_cmd == NULL))
7373              MYSQL_YYABORT;
7374          } stmt_end {}
7375        ;
7376
7377account_locking_option:
7378          LOCK_SYM
7379          {
7380            Lex->account_options.account_locked= ACCOUNTLOCK_LOCKED;
7381          }
7382        | UNLOCK_SYM
7383          {
7384            Lex->account_options.account_locked= ACCOUNTLOCK_UNLOCKED;
7385          }
7386        ;
7387
7388opt_password_expire_option:
7389          /* empty */
7390          {
7391            Lex->account_options.password_expire= PASSWORD_EXPIRE_NOW;
7392          }
7393        | NEVER_SYM
7394          {
7395            Lex->account_options.password_expire= PASSWORD_EXPIRE_NEVER;
7396          }
7397        | DEFAULT
7398          {
7399            Lex->account_options.password_expire= PASSWORD_EXPIRE_DEFAULT;
7400          }
7401        | INTERVAL_SYM NUM DAY_SYM
7402          {
7403            Lex->account_options.password_expire= PASSWORD_EXPIRE_INTERVAL;
7404            if (!(Lex->account_options.num_expiration_days= atoi($2.str)))
7405              my_yyabort_error((ER_WRONG_VALUE, MYF(0), "DAY", $2.str));
7406          }
7407        ;
7408
7409opt_account_locking_and_opt_password_expiration:
7410          /* empty */
7411        | ACCOUNT_SYM account_locking_option
7412        | PASSWORD_SYM EXPIRE_SYM opt_password_expire_option
7413        | ACCOUNT_SYM account_locking_option PASSWORD_SYM EXPIRE_SYM opt_password_expire_option
7414        | PASSWORD_SYM EXPIRE_SYM opt_password_expire_option ACCOUNT_SYM account_locking_option
7415        ;
7416
7417ev_alter_on_schedule_completion:
7418          /* empty */ { $$= 0;}
7419        | ON SCHEDULE_SYM ev_schedule_time { $$= 1; }
7420        | ev_on_completion { $$= 1; }
7421        | ON SCHEDULE_SYM ev_schedule_time ev_on_completion { $$= 1; }
7422        ;
7423
7424opt_ev_rename_to:
7425          /* empty */ { $$= 0;}
7426        | RENAME TO_SYM sp_name
7427          {
7428            /*
7429              Use lex's spname to hold the new name.
7430              The original name is in the Event_parse_data object
7431            */
7432            Lex->spname= $3;
7433            $$= 1;
7434          }
7435        ;
7436
7437opt_ev_sql_stmt:
7438          /* empty*/ { $$= 0;}
7439        | DO_SYM ev_sql_stmt { $$= 1; }
7440        ;
7441
7442ident_or_empty:
7443          /* empty */
7444          %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE { $$= Lex_ident_sys(); }
7445        | ident
7446        ;
7447
7448alter_commands:
7449          /* empty */
7450        | DISCARD TABLESPACE
7451          {
7452            Lex->m_sql_cmd= new (thd->mem_root)
7453              Sql_cmd_discard_import_tablespace(
7454                Sql_cmd_discard_import_tablespace::DISCARD_TABLESPACE);
7455            if (unlikely(Lex->m_sql_cmd == NULL))
7456              MYSQL_YYABORT;
7457          }
7458        | IMPORT TABLESPACE
7459          {
7460            Lex->m_sql_cmd= new (thd->mem_root)
7461              Sql_cmd_discard_import_tablespace(
7462                Sql_cmd_discard_import_tablespace::IMPORT_TABLESPACE);
7463            if (unlikely(Lex->m_sql_cmd == NULL))
7464              MYSQL_YYABORT;
7465          }
7466        | alter_list
7467          opt_partitioning
7468        | alter_list
7469          remove_partitioning
7470        | remove_partitioning
7471        | partitioning
7472/*
7473  This part was added for release 5.1 by Mikael Ronstrm.
7474  From here we insert a number of commands to manage the partitions of a
7475  partitioned table such as adding partitions, dropping partitions,
7476  reorganising partitions in various manners. In future releases the list
7477  will be longer.
7478*/
7479        | add_partition_rule
7480        | DROP PARTITION_SYM opt_if_exists alt_part_name_list
7481          {
7482            Lex->alter_info.partition_flags|= ALTER_PARTITION_DROP;
7483            DBUG_ASSERT(!Lex->if_exists());
7484            Lex->create_info.add($3);
7485          }
7486        | REBUILD_SYM PARTITION_SYM opt_no_write_to_binlog
7487          all_or_alt_part_name_list
7488          {
7489            LEX *lex= Lex;
7490            lex->alter_info.partition_flags|= ALTER_PARTITION_REBUILD;
7491            lex->no_write_to_binlog= $3;
7492          }
7493        | OPTIMIZE PARTITION_SYM opt_no_write_to_binlog
7494          all_or_alt_part_name_list
7495          {
7496            LEX *lex= thd->lex;
7497            lex->no_write_to_binlog= $3;
7498            lex->check_opt.init();
7499            DBUG_ASSERT(!lex->m_sql_cmd);
7500            lex->m_sql_cmd= new (thd->mem_root)
7501                              Sql_cmd_alter_table_optimize_partition();
7502            if (unlikely(lex->m_sql_cmd == NULL))
7503              MYSQL_YYABORT;
7504          }
7505          opt_no_write_to_binlog
7506        | ANALYZE_SYM PARTITION_SYM opt_no_write_to_binlog
7507          all_or_alt_part_name_list
7508          {
7509            LEX *lex= thd->lex;
7510            lex->no_write_to_binlog= $3;
7511            lex->check_opt.init();
7512            DBUG_ASSERT(!lex->m_sql_cmd);
7513            lex->m_sql_cmd= new (thd->mem_root)
7514                              Sql_cmd_alter_table_analyze_partition();
7515            if (unlikely(lex->m_sql_cmd == NULL))
7516               MYSQL_YYABORT;
7517          }
7518        | CHECK_SYM PARTITION_SYM all_or_alt_part_name_list
7519          {
7520            LEX *lex= thd->lex;
7521            lex->check_opt.init();
7522            DBUG_ASSERT(!lex->m_sql_cmd);
7523            lex->m_sql_cmd= new (thd->mem_root)
7524                              Sql_cmd_alter_table_check_partition();
7525            if (unlikely(lex->m_sql_cmd == NULL))
7526              MYSQL_YYABORT;
7527          }
7528          opt_mi_check_type
7529        | REPAIR PARTITION_SYM opt_no_write_to_binlog
7530          all_or_alt_part_name_list
7531          {
7532            LEX *lex= thd->lex;
7533            lex->no_write_to_binlog= $3;
7534            lex->check_opt.init();
7535            DBUG_ASSERT(!lex->m_sql_cmd);
7536            lex->m_sql_cmd= new (thd->mem_root)
7537                              Sql_cmd_alter_table_repair_partition();
7538            if (unlikely(lex->m_sql_cmd == NULL))
7539              MYSQL_YYABORT;
7540          }
7541          opt_mi_repair_type
7542        | COALESCE PARTITION_SYM opt_no_write_to_binlog real_ulong_num
7543          {
7544            LEX *lex= Lex;
7545            lex->alter_info.partition_flags|= ALTER_PARTITION_COALESCE;
7546            lex->no_write_to_binlog= $3;
7547            lex->alter_info.num_parts= $4;
7548          }
7549        | TRUNCATE_SYM PARTITION_SYM all_or_alt_part_name_list
7550          {
7551            LEX *lex= thd->lex;
7552            lex->check_opt.init();
7553            DBUG_ASSERT(!lex->m_sql_cmd);
7554            lex->m_sql_cmd= new (thd->mem_root)
7555                              Sql_cmd_alter_table_truncate_partition();
7556            if (unlikely(lex->m_sql_cmd == NULL))
7557              MYSQL_YYABORT;
7558          }
7559        | reorg_partition_rule
7560        | EXCHANGE_SYM PARTITION_SYM alt_part_name_item
7561          WITH TABLE_SYM table_ident have_partitioning
7562          {
7563            if (Lex->stmt_alter_table_exchange_partition($6))
7564              MYSQL_YYABORT;
7565          }
7566        ;
7567
7568remove_partitioning:
7569          REMOVE_SYM PARTITIONING_SYM
7570          {
7571            Lex->alter_info.partition_flags|= ALTER_PARTITION_REMOVE;
7572          }
7573        ;
7574
7575all_or_alt_part_name_list:
7576          ALL
7577          {
7578            Lex->alter_info.partition_flags|= ALTER_PARTITION_ALL;
7579          }
7580        | alt_part_name_list
7581        ;
7582
7583add_partition_rule:
7584          ADD PARTITION_SYM opt_if_not_exists
7585          opt_no_write_to_binlog
7586          {
7587            LEX *lex= Lex;
7588            lex->part_info= new (thd->mem_root) partition_info();
7589            if (unlikely(!lex->part_info))
7590              MYSQL_YYABORT;
7591
7592            lex->alter_info.partition_flags|= ALTER_PARTITION_ADD;
7593            DBUG_ASSERT(!Lex->create_info.if_not_exists());
7594            lex->create_info.set($3);
7595            lex->no_write_to_binlog= $4;
7596          }
7597          add_part_extra
7598          {}
7599        ;
7600
7601add_part_extra:
7602          /* empty */
7603        | '(' part_def_list ')'
7604          {
7605            LEX *lex= Lex;
7606            lex->part_info->num_parts= lex->part_info->partitions.elements;
7607          }
7608        | PARTITIONS_SYM real_ulong_num
7609          {
7610            Lex->part_info->num_parts= $2;
7611          }
7612        ;
7613
7614reorg_partition_rule:
7615          REORGANIZE_SYM PARTITION_SYM opt_no_write_to_binlog
7616          {
7617            LEX *lex= Lex;
7618            lex->part_info= new (thd->mem_root) partition_info();
7619            if (unlikely(!lex->part_info))
7620              MYSQL_YYABORT;
7621
7622            lex->no_write_to_binlog= $3;
7623          }
7624          reorg_parts_rule
7625        ;
7626
7627reorg_parts_rule:
7628          /* empty */
7629          {
7630            Lex->alter_info.partition_flags|= ALTER_PARTITION_TABLE_REORG;
7631          }
7632        | alt_part_name_list
7633          {
7634            Lex->alter_info.partition_flags|= ALTER_PARTITION_REORGANIZE;
7635          }
7636          INTO '(' part_def_list ')'
7637          {
7638            partition_info *part_info= Lex->part_info;
7639            part_info->num_parts= part_info->partitions.elements;
7640          }
7641        ;
7642
7643alt_part_name_list:
7644          alt_part_name_item {}
7645        | alt_part_name_list ',' alt_part_name_item {}
7646        ;
7647
7648alt_part_name_item:
7649          ident
7650          {
7651            if (unlikely(Lex->alter_info.partition_names.push_back($1.str,
7652                                                                   thd->mem_root)))
7653              MYSQL_YYABORT;
7654          }
7655        ;
7656
7657/*
7658  End of management of partition commands
7659*/
7660
7661alter_list:
7662          alter_list_item
7663        | alter_list ',' alter_list_item
7664        ;
7665
7666add_column:
7667          ADD opt_column opt_if_not_exists_table_element
7668        ;
7669
7670alter_list_item:
7671          add_column column_def opt_place
7672          {
7673            LEX *lex=Lex;
7674            lex->create_last_non_select_table= lex->last_table();
7675            lex->alter_info.flags|= ALTER_PARSER_ADD_COLUMN;
7676            $2->after= $3;
7677          }
7678        | ADD key_def
7679          {
7680            Lex->create_last_non_select_table= Lex->last_table();
7681            Lex->alter_info.flags|= ALTER_ADD_INDEX;
7682          }
7683        | ADD period_for_system_time
7684          {
7685            Lex->alter_info.flags|= ALTER_ADD_PERIOD;
7686          }
7687        | ADD
7688          PERIOD_SYM opt_if_not_exists_table_element period_for_application_time
7689          {
7690            Table_period_info &period= Lex->create_info.period_info;
7691            period.create_if_not_exists= Lex->check_exists;
7692            Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
7693          }
7694        | add_column '(' create_field_list ')'
7695          {
7696            LEX *lex=Lex;
7697            lex->alter_info.flags|= ALTER_PARSER_ADD_COLUMN;
7698            if (!lex->alter_info.key_list.is_empty())
7699              lex->alter_info.flags|= ALTER_ADD_INDEX;
7700          }
7701        | ADD constraint_def
7702          {
7703            Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
7704	  }
7705        | ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint
7706         {
7707           Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
7708           Lex->add_constraint($6, $7, TRUE);
7709         }
7710        | CHANGE opt_column opt_if_exists_table_element field_ident
7711          field_spec opt_place
7712          {
7713            Lex->alter_info.flags|= ALTER_CHANGE_COLUMN | ALTER_RENAME_COLUMN;
7714            Lex->create_last_non_select_table= Lex->last_table();
7715            $5->change= $4;
7716            $5->after= $6;
7717          }
7718        | MODIFY_SYM opt_column opt_if_exists_table_element
7719          field_spec opt_place
7720          {
7721            Lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
7722            Lex->create_last_non_select_table= Lex->last_table();
7723            $4->change= $4->field_name;
7724            $4->after= $5;
7725          }
7726        | DROP opt_column opt_if_exists_table_element field_ident opt_restrict
7727          {
7728            LEX *lex=Lex;
7729            Alter_drop *ad= (new (thd->mem_root)
7730                             Alter_drop(Alter_drop::COLUMN, $4.str, $3));
7731            if (unlikely(ad == NULL))
7732              MYSQL_YYABORT;
7733            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
7734            lex->alter_info.flags|= ALTER_PARSER_DROP_COLUMN;
7735          }
7736	| DROP CONSTRAINT opt_if_exists_table_element field_ident
7737          {
7738            LEX *lex=Lex;
7739            Alter_drop *ad= (new (thd->mem_root)
7740                             Alter_drop(Alter_drop::CHECK_CONSTRAINT,
7741                                        $4.str, $3));
7742            if (unlikely(ad == NULL))
7743              MYSQL_YYABORT;
7744            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
7745            lex->alter_info.flags|= ALTER_DROP_CHECK_CONSTRAINT;
7746          }
7747        | DROP FOREIGN KEY_SYM opt_if_exists_table_element field_ident
7748          {
7749            LEX *lex=Lex;
7750            Alter_drop *ad= (new (thd->mem_root)
7751                             Alter_drop(Alter_drop::FOREIGN_KEY, $5.str, $4));
7752            if (unlikely(ad == NULL))
7753              MYSQL_YYABORT;
7754            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
7755            lex->alter_info.flags|= ALTER_DROP_FOREIGN_KEY;
7756          }
7757        | DROP opt_constraint_no_id PRIMARY_SYM KEY_SYM
7758          {
7759            LEX *lex=Lex;
7760            Alter_drop *ad= (new (thd->mem_root)
7761                             Alter_drop(Alter_drop::KEY, primary_key_name,
7762                                        FALSE));
7763            if (unlikely(ad == NULL))
7764              MYSQL_YYABORT;
7765            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
7766            lex->alter_info.flags|= ALTER_DROP_INDEX;
7767          }
7768        | DROP key_or_index opt_if_exists_table_element field_ident
7769          {
7770            LEX *lex=Lex;
7771            Alter_drop *ad= (new (thd->mem_root)
7772                             Alter_drop(Alter_drop::KEY, $4.str, $3));
7773            if (unlikely(ad == NULL))
7774              MYSQL_YYABORT;
7775            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
7776            lex->alter_info.flags|= ALTER_DROP_INDEX;
7777          }
7778        | DISABLE_SYM KEYS
7779          {
7780            LEX *lex=Lex;
7781            lex->alter_info.keys_onoff= Alter_info::DISABLE;
7782            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
7783          }
7784        | ENABLE_SYM KEYS
7785          {
7786            LEX *lex=Lex;
7787            lex->alter_info.keys_onoff= Alter_info::ENABLE;
7788            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
7789          }
7790        | ALTER opt_column opt_if_exists_table_element field_ident SET DEFAULT column_default_expr
7791          {
7792            if (check_expression($7, &$4, VCOL_DEFAULT))
7793              MYSQL_YYABORT;
7794            if (unlikely(Lex->add_alter_list($4, $7, $3)))
7795              MYSQL_YYABORT;
7796          }
7797        | ALTER opt_column opt_if_exists_table_element field_ident DROP DEFAULT
7798          {
7799            if (unlikely(Lex->add_alter_list($4, (Virtual_column_info*) 0, $3)))
7800              MYSQL_YYABORT;
7801          }
7802        | RENAME opt_to table_ident
7803          {
7804            LEX *lex=Lex;
7805            lex->first_select_lex()->db= $3->db;
7806            if (lex->first_select_lex()->db.str == NULL &&
7807                lex->copy_db_to(&lex->first_select_lex()->db))
7808              MYSQL_YYABORT;
7809            if (unlikely(check_table_name($3->table.str,$3->table.length,
7810                                          FALSE)) ||
7811                ($3->db.str && unlikely(check_db_name((LEX_STRING*) &$3->db))))
7812              my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $3->table.str));
7813            lex->name= $3->table;
7814            lex->alter_info.flags|= ALTER_RENAME;
7815          }
7816        | RENAME COLUMN_SYM opt_if_exists_table_element ident TO_SYM ident
7817          {
7818            if (unlikely(Lex->add_alter_list($4, $6, $3)))
7819              MYSQL_YYABORT;
7820          }
7821        | RENAME key_or_index opt_if_exists_table_element field_ident TO_SYM field_ident
7822          {
7823            LEX *lex=Lex;
7824            Alter_rename_key *ak= new (thd->mem_root)
7825                                    Alter_rename_key($4, $6, $3);
7826            if (ak == NULL)
7827              MYSQL_YYABORT;
7828            lex->alter_info.alter_rename_key_list.push_back(ak);
7829            lex->alter_info.flags|= ALTER_RENAME_INDEX;
7830          }
7831        | CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
7832          {
7833            if (!$4)
7834            {
7835              $4= thd->variables.collation_database;
7836            }
7837            $5= $5 ? $5 : $4;
7838            if (unlikely(!my_charset_same($4,$5)))
7839              my_yyabort_error((ER_COLLATION_CHARSET_MISMATCH, MYF(0),
7840                                $5->name, $4->csname));
7841            if (unlikely(Lex->create_info.add_alter_list_item_convert_to_charset($5)))
7842              MYSQL_YYABORT;
7843            Lex->alter_info.flags|= ALTER_CONVERT_TO;
7844          }
7845        | create_table_options_space_separated
7846          {
7847            LEX *lex=Lex;
7848            lex->alter_info.flags|= ALTER_OPTIONS;
7849          }
7850        | FORCE_SYM
7851          {
7852            Lex->alter_info.flags|= ALTER_RECREATE;
7853          }
7854        | alter_order_clause
7855          {
7856            LEX *lex=Lex;
7857            lex->alter_info.flags|= ALTER_ORDER;
7858          }
7859        | alter_algorithm_option
7860        | alter_lock_option
7861        | ADD SYSTEM VERSIONING_SYM
7862          {
7863            Lex->alter_info.flags|= ALTER_ADD_SYSTEM_VERSIONING;
7864            Lex->create_info.options|= HA_VERSIONED_TABLE;
7865          }
7866        | DROP SYSTEM VERSIONING_SYM
7867          {
7868            Lex->alter_info.flags|= ALTER_DROP_SYSTEM_VERSIONING;
7869            Lex->create_info.options&= ~HA_VERSIONED_TABLE;
7870          }
7871        | DROP PERIOD_SYM FOR_SYSTEM_TIME_SYM
7872          {
7873            Lex->alter_info.flags|= ALTER_DROP_PERIOD;
7874          }
7875        | DROP PERIOD_SYM opt_if_exists_table_element FOR_SYM ident
7876          {
7877            Alter_drop *ad= new Alter_drop(Alter_drop::PERIOD, $5.str, $3);
7878            if (unlikely(ad == NULL))
7879              MYSQL_YYABORT;
7880            Lex->alter_info.drop_list.push_back(ad, thd->mem_root);
7881            Lex->alter_info.flags|= ALTER_DROP_CHECK_CONSTRAINT;
7882          }
7883        ;
7884
7885opt_index_lock_algorithm:
7886          /* empty */
7887        | alter_lock_option
7888        | alter_algorithm_option
7889        | alter_lock_option alter_algorithm_option
7890        | alter_algorithm_option alter_lock_option
7891        ;
7892
7893alter_algorithm_option:
7894          ALGORITHM_SYM opt_equal DEFAULT
7895          {
7896            Lex->alter_info.set_requested_algorithm(
7897              Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT);
7898          }
7899        | ALGORITHM_SYM opt_equal ident
7900          {
7901            if (unlikely(Lex->alter_info.set_requested_algorithm(&$3)))
7902              my_yyabort_error((ER_UNKNOWN_ALTER_ALGORITHM, MYF(0), $3.str));
7903          }
7904        ;
7905
7906alter_lock_option:
7907          LOCK_SYM opt_equal DEFAULT
7908          {
7909            Lex->alter_info.requested_lock=
7910              Alter_info::ALTER_TABLE_LOCK_DEFAULT;
7911          }
7912        | LOCK_SYM opt_equal ident
7913          {
7914            if (unlikely(Lex->alter_info.set_requested_lock(&$3)))
7915              my_yyabort_error((ER_UNKNOWN_ALTER_LOCK, MYF(0), $3.str));
7916          }
7917        ;
7918
7919opt_column:
7920          /* empty */ {}     %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
7921        | COLUMN_SYM {}
7922        ;
7923
7924opt_ignore:
7925          /* empty */ { Lex->ignore= 0;}
7926        | IGNORE_SYM { Lex->ignore= 1;}
7927        ;
7928
7929alter_options:
7930        { Lex->ignore= 0;} alter_options_part2
7931	;
7932
7933alter_options_part2:
7934          /* empty */
7935        | alter_option_list
7936        ;
7937
7938alter_option_list:
7939        alter_option_list alter_option
7940        | alter_option
7941        ;
7942
7943alter_option:
7944	  IGNORE_SYM { Lex->ignore= 1;}
7945        | ONLINE_SYM
7946          {
7947            Lex->alter_info.requested_lock=
7948              Alter_info::ALTER_TABLE_LOCK_NONE;
7949          }
7950        ;
7951
7952opt_restrict:
7953          /* empty */ { Lex->drop_mode= DROP_DEFAULT; }
7954        | RESTRICT    { Lex->drop_mode= DROP_RESTRICT; }
7955        | CASCADE     { Lex->drop_mode= DROP_CASCADE; }
7956        ;
7957
7958opt_place:
7959        /* empty */ { $$= null_clex_str; }
7960        | AFTER_SYM ident
7961          {
7962            $$= $2;
7963            Lex->alter_info.flags |= ALTER_COLUMN_ORDER;
7964          }
7965        | FIRST_SYM
7966          {
7967            $$.str=    first_keyword;
7968	    $$.length= 5; /* Length of "first" */
7969            Lex->alter_info.flags |= ALTER_COLUMN_ORDER;
7970          }
7971        ;
7972
7973opt_to:
7974          /* empty */ {}
7975        | TO_SYM {}
7976        | '=' {}
7977        | AS {}
7978        ;
7979
7980slave:
7981          START_SYM SLAVE optional_connection_name slave_thread_opts
7982          {
7983            LEX *lex=Lex;
7984            lex->sql_command = SQLCOM_SLAVE_START;
7985            lex->type = 0;
7986            /* If you change this code don't forget to update SLAVE START too */
7987          }
7988          slave_until
7989          {}
7990        | START_SYM ALL SLAVES slave_thread_opts
7991          {
7992            LEX *lex=Lex;
7993            lex->sql_command = SQLCOM_SLAVE_ALL_START;
7994            lex->type = 0;
7995            /* If you change this code don't forget to update STOP SLAVE too */
7996          }
7997          {}
7998        | STOP_SYM SLAVE optional_connection_name slave_thread_opts
7999          {
8000            LEX *lex=Lex;
8001            lex->sql_command = SQLCOM_SLAVE_STOP;
8002            lex->type = 0;
8003            /* If you change this code don't forget to update SLAVE STOP too */
8004          }
8005        | STOP_SYM ALL SLAVES slave_thread_opts
8006          {
8007            LEX *lex=Lex;
8008            lex->sql_command = SQLCOM_SLAVE_ALL_STOP;
8009            lex->type = 0;
8010            /* If you change this code don't forget to update SLAVE STOP too */
8011          }
8012        ;
8013
8014start:
8015          START_SYM TRANSACTION_SYM opt_start_transaction_option_list
8016          {
8017            LEX *lex= Lex;
8018            lex->sql_command= SQLCOM_BEGIN;
8019            /* READ ONLY and READ WRITE are mutually exclusive. */
8020            if (unlikely(($3 & MYSQL_START_TRANS_OPT_READ_WRITE) &&
8021                         ($3 & MYSQL_START_TRANS_OPT_READ_ONLY)))
8022            {
8023              thd->parse_error();
8024              MYSQL_YYABORT;
8025            }
8026            lex->start_transaction_opt= $3;
8027          }
8028        ;
8029
8030opt_start_transaction_option_list:
8031          /* empty */
8032          {
8033            $$= 0;
8034          }
8035        | start_transaction_option_list
8036          {
8037            $$= $1;
8038          }
8039        ;
8040
8041start_transaction_option_list:
8042          start_transaction_option
8043          {
8044            $$= $1;
8045          }
8046        | start_transaction_option_list ',' start_transaction_option
8047          {
8048            $$= $1 | $3;
8049          }
8050        ;
8051
8052start_transaction_option:
8053          WITH CONSISTENT_SYM SNAPSHOT_SYM
8054          {
8055            $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
8056          }
8057        | READ_SYM ONLY_SYM
8058          {
8059            $$= MYSQL_START_TRANS_OPT_READ_ONLY;
8060          }
8061        | READ_SYM WRITE_SYM
8062          {
8063            $$= MYSQL_START_TRANS_OPT_READ_WRITE;
8064          }
8065        ;
8066
8067slave_thread_opts:
8068          { Lex->slave_thd_opt= 0; }
8069          slave_thread_opt_list
8070          {}
8071        ;
8072
8073slave_thread_opt_list:
8074          slave_thread_opt
8075        | slave_thread_opt_list ',' slave_thread_opt
8076        ;
8077
8078slave_thread_opt:
8079          /*empty*/ {}
8080        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
8081        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
8082        ;
8083
8084slave_until:
8085          /*empty*/ {}
8086        | UNTIL_SYM slave_until_opts
8087          {
8088            LEX *lex=Lex;
8089            if (unlikely(((lex->mi.log_file_name || lex->mi.pos) &&
8090                         (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
8091                         !((lex->mi.log_file_name && lex->mi.pos) ||
8092                           (lex->mi.relay_log_name && lex->mi.relay_log_pos))))
8093               my_yyabort_error((ER_BAD_SLAVE_UNTIL_COND, MYF(0)));
8094          }
8095        | UNTIL_SYM MASTER_GTID_POS_SYM '=' TEXT_STRING_sys
8096          {
8097            Lex->mi.gtid_pos_str = $4;
8098          }
8099        ;
8100
8101slave_until_opts:
8102          master_file_def
8103        | slave_until_opts ',' master_file_def
8104        ;
8105
8106checksum:
8107          CHECKSUM_SYM table_or_tables
8108          {
8109            LEX *lex=Lex;
8110            lex->sql_command = SQLCOM_CHECKSUM;
8111            /* Will be overridden during execution. */
8112            YYPS->m_lock_type= TL_UNLOCK;
8113          }
8114          table_list opt_checksum_type
8115          {}
8116        ;
8117
8118opt_checksum_type:
8119          /* nothing */ { Lex->check_opt.flags= 0; }
8120        | QUICK         { Lex->check_opt.flags= T_QUICK; }
8121        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
8122        ;
8123
8124repair_table_or_view:
8125          table_or_tables table_list opt_mi_repair_type
8126        | VIEW_SYM
8127          { Lex->table_type= TABLE_TYPE_VIEW; }
8128          table_list opt_view_repair_type
8129        ;
8130
8131repair:
8132          REPAIR opt_no_write_to_binlog
8133          {
8134            LEX *lex=Lex;
8135            lex->sql_command = SQLCOM_REPAIR;
8136            lex->no_write_to_binlog= $2;
8137            lex->check_opt.init();
8138            lex->alter_info.reset();
8139            /* Will be overridden during execution. */
8140            YYPS->m_lock_type= TL_UNLOCK;
8141          }
8142          repair_table_or_view
8143          {
8144            LEX* lex= thd->lex;
8145            DBUG_ASSERT(!lex->m_sql_cmd);
8146            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_repair_table();
8147            if (unlikely(lex->m_sql_cmd == NULL))
8148              MYSQL_YYABORT;
8149          }
8150        ;
8151
8152opt_mi_repair_type:
8153          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
8154        | mi_repair_types {}
8155        ;
8156
8157mi_repair_types:
8158          mi_repair_type {}
8159        | mi_repair_type mi_repair_types {}
8160        ;
8161
8162mi_repair_type:
8163          QUICK        { Lex->check_opt.flags|= T_QUICK; }
8164        | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
8165        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; }
8166        ;
8167
8168opt_view_repair_type:
8169          /* empty */    { }
8170        | FROM MYSQL_SYM { Lex->check_opt.sql_flags|= TT_FROM_MYSQL; }
8171        ;
8172
8173analyze:
8174          ANALYZE_SYM opt_no_write_to_binlog table_or_tables
8175          {
8176            LEX *lex=Lex;
8177            lex->sql_command = SQLCOM_ANALYZE;
8178            lex->no_write_to_binlog= $2;
8179            lex->check_opt.init();
8180            lex->alter_info.reset();
8181            /* Will be overridden during execution. */
8182            YYPS->m_lock_type= TL_UNLOCK;
8183          }
8184          analyze_table_list
8185          {
8186            LEX* lex= thd->lex;
8187            DBUG_ASSERT(!lex->m_sql_cmd);
8188            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_analyze_table();
8189            if (unlikely(lex->m_sql_cmd == NULL))
8190              MYSQL_YYABORT;
8191          }
8192        ;
8193
8194analyze_table_list:
8195          analyze_table_elem_spec
8196        | analyze_table_list ',' analyze_table_elem_spec
8197        ;
8198
8199analyze_table_elem_spec:
8200          table_name opt_persistent_stat_clause
8201        ;
8202
8203opt_persistent_stat_clause:
8204          /* empty */
8205          {}
8206        | PERSISTENT_SYM FOR_SYM persistent_stat_spec
8207          {
8208            thd->lex->with_persistent_for_clause= TRUE;
8209          }
8210        ;
8211
8212persistent_stat_spec:
8213          ALL
8214          {}
8215        | COLUMNS persistent_column_stat_spec INDEXES persistent_index_stat_spec
8216          {}
8217        ;
8218
8219persistent_column_stat_spec:
8220          ALL {}
8221        | '('
8222          {
8223            LEX* lex= thd->lex;
8224            lex->column_list= new (thd->mem_root) List<LEX_STRING>;
8225            if (unlikely(lex->column_list == NULL))
8226              MYSQL_YYABORT;
8227          }
8228          table_column_list
8229          ')'
8230          { }
8231        ;
8232
8233persistent_index_stat_spec:
8234          ALL {}
8235        | '('
8236          {
8237            LEX* lex= thd->lex;
8238            lex->index_list= new (thd->mem_root) List<LEX_STRING>;
8239            if (unlikely(lex->index_list == NULL))
8240              MYSQL_YYABORT;
8241          }
8242          table_index_list
8243          ')'
8244          { }
8245        ;
8246
8247table_column_list:
8248          /* empty */
8249          {}
8250        | ident
8251          {
8252            Lex->column_list->push_back((LEX_STRING*)
8253                thd->memdup(&$1, sizeof(LEX_STRING)), thd->mem_root);
8254          }
8255        | table_column_list ',' ident
8256          {
8257            Lex->column_list->push_back((LEX_STRING*)
8258                thd->memdup(&$3, sizeof(LEX_STRING)), thd->mem_root);
8259          }
8260        ;
8261
8262table_index_list:
8263          /* empty */
8264          {}
8265        | table_index_name
8266        | table_index_list ',' table_index_name
8267        ;
8268
8269table_index_name:
8270          ident
8271          {
8272            Lex->index_list->push_back((LEX_STRING*)
8273                                       thd->memdup(&$1, sizeof(LEX_STRING)),
8274                                       thd->mem_root);
8275          }
8276        |
8277          PRIMARY_SYM
8278          {
8279            LEX_STRING str= {(char*) "PRIMARY", 7};
8280            Lex->index_list->push_back((LEX_STRING*)
8281                                        thd->memdup(&str, sizeof(LEX_STRING)),
8282                                        thd->mem_root);
8283          }
8284        ;
8285
8286binlog_base64_event:
8287          BINLOG_SYM TEXT_STRING_sys
8288          {
8289            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
8290            Lex->comment= $2;
8291            Lex->ident.str=    NULL;
8292            Lex->ident.length= 0;
8293          }
8294          |
8295          BINLOG_SYM '@' ident_or_text ',' '@' ident_or_text
8296          {
8297            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
8298            Lex->comment= $3;
8299            Lex->ident=   $6;
8300          }
8301          ;
8302
8303check_view_or_table:
8304          table_or_tables table_list opt_mi_check_type
8305        | VIEW_SYM
8306          { Lex->table_type= TABLE_TYPE_VIEW; }
8307          table_list opt_view_check_type
8308        ;
8309
8310check:    CHECK_SYM
8311          {
8312            LEX *lex=Lex;
8313
8314            lex->sql_command = SQLCOM_CHECK;
8315            lex->check_opt.init();
8316            lex->alter_info.reset();
8317            /* Will be overridden during execution. */
8318            YYPS->m_lock_type= TL_UNLOCK;
8319          }
8320          check_view_or_table
8321          {
8322            LEX* lex= thd->lex;
8323            if (unlikely(lex->sphead))
8324              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "CHECK"));
8325            DBUG_ASSERT(!lex->m_sql_cmd);
8326            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_check_table();
8327            if (unlikely(lex->m_sql_cmd == NULL))
8328              MYSQL_YYABORT;
8329          }
8330        ;
8331
8332opt_mi_check_type:
8333          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
8334        | mi_check_types {}
8335        ;
8336
8337mi_check_types:
8338          mi_check_type {}
8339        | mi_check_type mi_check_types {}
8340        ;
8341
8342mi_check_type:
8343          QUICK               { Lex->check_opt.flags|= T_QUICK; }
8344        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
8345        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
8346        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
8347        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
8348        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
8349        ;
8350
8351opt_view_check_type:
8352          /* empty */         { }
8353        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
8354        ;
8355
8356optimize:
8357          OPTIMIZE opt_no_write_to_binlog table_or_tables
8358          {
8359            LEX *lex=Lex;
8360            lex->sql_command = SQLCOM_OPTIMIZE;
8361            lex->no_write_to_binlog= $2;
8362            lex->check_opt.init();
8363            lex->alter_info.reset();
8364            /* Will be overridden during execution. */
8365            YYPS->m_lock_type= TL_UNLOCK;
8366          }
8367          table_list opt_lock_wait_timeout
8368          {
8369            LEX* lex= thd->lex;
8370            DBUG_ASSERT(!lex->m_sql_cmd);
8371            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_optimize_table();
8372            if (unlikely(lex->m_sql_cmd == NULL))
8373              MYSQL_YYABORT;
8374          }
8375        ;
8376
8377opt_no_write_to_binlog:
8378          /* empty */ { $$= 0; }
8379        | NO_WRITE_TO_BINLOG { $$= 1; }
8380        | LOCAL_SYM { $$= 1; }
8381        ;
8382
8383rename:
8384          RENAME table_or_tables opt_if_exists
8385          {
8386            Lex->sql_command= SQLCOM_RENAME_TABLE;
8387            Lex->create_info.set($3);
8388            if (Lex->main_select_push())
8389              MYSQL_YYABORT;
8390          }
8391          table_to_table_list
8392          {
8393            Lex->pop_select(); //main select
8394          }
8395        | RENAME USER_SYM clear_privileges rename_list
8396          {
8397            Lex->sql_command = SQLCOM_RENAME_USER;
8398          }
8399        ;
8400
8401rename_list:
8402          user TO_SYM user
8403          {
8404            if (unlikely(Lex->users_list.push_back($1, thd->mem_root) ||
8405                         Lex->users_list.push_back($3, thd->mem_root)))
8406              MYSQL_YYABORT;
8407          }
8408        | rename_list ',' user TO_SYM user
8409          {
8410            if (unlikely(Lex->users_list.push_back($3, thd->mem_root) ||
8411                         Lex->users_list.push_back($5, thd->mem_root)))
8412              MYSQL_YYABORT;
8413          }
8414        ;
8415
8416table_to_table_list:
8417          table_to_table
8418        | table_to_table_list ',' table_to_table
8419        ;
8420
8421table_to_table:
8422          table_ident opt_lock_wait_timeout TO_SYM table_ident
8423          {
8424            LEX *lex=Lex;
8425            SELECT_LEX *sl= lex->current_select;
8426            if (unlikely(!sl->add_table_to_list(thd, $1,NULL,
8427                                                TL_OPTION_UPDATING,
8428                                                TL_IGNORE, MDL_EXCLUSIVE)) ||
8429                unlikely(!sl->add_table_to_list(thd, $4, NULL,
8430                                                TL_OPTION_UPDATING,
8431                                                TL_IGNORE, MDL_EXCLUSIVE)))
8432              MYSQL_YYABORT;
8433          }
8434        ;
8435
8436keycache:
8437          CACHE_SYM INDEX_SYM
8438          {
8439            Lex->alter_info.reset();
8440          }
8441          keycache_list_or_parts IN_SYM key_cache_name
8442          {
8443            LEX *lex=Lex;
8444            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
8445            lex->ident= $6;
8446          }
8447        ;
8448
8449keycache_list_or_parts:
8450          keycache_list
8451        | assign_to_keycache_parts
8452        ;
8453
8454keycache_list:
8455          assign_to_keycache
8456        | keycache_list ',' assign_to_keycache
8457        ;
8458
8459assign_to_keycache:
8460          table_ident cache_keys_spec
8461          {
8462            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, 0, TL_READ,
8463                                                    MDL_SHARED_READ,
8464                                                    Select->
8465                                                    pop_index_hints())))
8466              MYSQL_YYABORT;
8467          }
8468        ;
8469
8470assign_to_keycache_parts:
8471          table_ident adm_partition cache_keys_spec
8472          {
8473            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, 0, TL_READ,
8474                                                    MDL_SHARED_READ,
8475                                                    Select->
8476                                                    pop_index_hints())))
8477              MYSQL_YYABORT;
8478          }
8479        ;
8480
8481key_cache_name:
8482          ident    { $$= $1; }
8483        | DEFAULT  { $$ = default_key_cache_base; }
8484        ;
8485
8486preload:
8487          LOAD INDEX_SYM INTO CACHE_SYM
8488          {
8489            LEX *lex=Lex;
8490            lex->sql_command=SQLCOM_PRELOAD_KEYS;
8491            lex->alter_info.reset();
8492            if (lex->main_select_push())
8493              MYSQL_YYABORT;
8494          }
8495          preload_list_or_parts
8496          {
8497            Lex->pop_select(); //main select
8498          }
8499        ;
8500
8501preload_list_or_parts:
8502          preload_keys_parts
8503        | preload_list
8504        ;
8505
8506preload_list:
8507          preload_keys
8508        | preload_list ',' preload_keys
8509        ;
8510
8511preload_keys:
8512          table_ident cache_keys_spec opt_ignore_leaves
8513          {
8514            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, $3, TL_READ,
8515                                                    MDL_SHARED_READ,
8516                                                    Select->
8517                                                    pop_index_hints())))
8518              MYSQL_YYABORT;
8519          }
8520        ;
8521
8522preload_keys_parts:
8523          table_ident adm_partition cache_keys_spec opt_ignore_leaves
8524          {
8525            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, $4, TL_READ,
8526                                                    MDL_SHARED_READ,
8527                                                    Select->
8528                                                    pop_index_hints())))
8529              MYSQL_YYABORT;
8530          }
8531        ;
8532
8533adm_partition:
8534          PARTITION_SYM have_partitioning
8535          {
8536            Lex->alter_info.partition_flags|= ALTER_PARTITION_ADMIN;
8537          }
8538          '(' all_or_alt_part_name_list ')'
8539        ;
8540
8541cache_keys_spec:
8542          {
8543            Lex->first_select_lex()->alloc_index_hints(thd);
8544            Select->set_index_hint_type(INDEX_HINT_USE,
8545                                        INDEX_HINT_MASK_ALL);
8546          }
8547          cache_key_list_or_empty
8548        ;
8549
8550cache_key_list_or_empty:
8551          /* empty */ { }
8552        | key_or_index '(' opt_key_usage_list ')'
8553        ;
8554
8555opt_ignore_leaves:
8556          /* empty */
8557          { $$= 0; }
8558        | IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
8559        ;
8560
8561/*
8562  Select : retrieve data from table
8563*/
8564
8565
8566select:
8567          query_expression_no_with_clause
8568          {
8569            if (Lex->push_select($1->fake_select_lex ?
8570                                 $1->fake_select_lex :
8571                                 $1->first_select()))
8572              MYSQL_YYABORT;
8573          }
8574          opt_procedure_or_into
8575          {
8576            Lex->pop_select();
8577            $1->set_with_clause(NULL);
8578            if (Lex->select_finalize($1, $3))
8579              MYSQL_YYABORT;
8580          }
8581        | with_clause query_expression_no_with_clause
8582          {
8583            if (Lex->push_select($2->fake_select_lex ?
8584                                 $2->fake_select_lex :
8585                                 $2->first_select()))
8586              MYSQL_YYABORT;
8587          }
8588          opt_procedure_or_into
8589          {
8590            Lex->pop_select();
8591            $2->set_with_clause($1);
8592            $1->attach_to($2->first_select());
8593            if (Lex->select_finalize($2, $4))
8594              MYSQL_YYABORT;
8595          }
8596        ;
8597
8598select_into:
8599          select_into_query_specification
8600          {
8601            if (Lex->push_select($1))
8602              MYSQL_YYABORT;
8603          }
8604          opt_order_limit_lock
8605          {
8606            SELECT_LEX_UNIT *unit;
8607            if (!(unit  = Lex->create_unit($1)))
8608              MYSQL_YYABORT;
8609            if ($3)
8610              unit= Lex->add_tail_to_query_expression_body(unit, $3);
8611            if (Lex->select_finalize(unit))
8612              MYSQL_YYABORT;
8613          }
8614        | with_clause
8615          select_into_query_specification
8616          {
8617            if (Lex->push_select($2))
8618              MYSQL_YYABORT;
8619          }
8620          opt_order_limit_lock
8621          {
8622            SELECT_LEX_UNIT *unit;
8623            if (!(unit  = Lex->create_unit($2)))
8624              MYSQL_YYABORT;
8625            if ($4)
8626              unit= Lex->add_tail_to_query_expression_body(unit, $4);
8627            unit->set_with_clause($1);
8628            $1->attach_to($2);
8629            if (Lex->select_finalize(unit))
8630              MYSQL_YYABORT;
8631          }
8632        ;
8633
8634simple_table:
8635          query_specification      { $$= $1; }
8636        | table_value_constructor  { $$= $1; }
8637        ;
8638
8639table_value_constructor:
8640	  VALUES
8641	  {
8642            if (Lex->parsed_TVC_start())
8643              MYSQL_YYABORT;
8644	  }
8645	  values_list
8646	  {
8647            if (!($$= Lex->parsed_TVC_end()))
8648	      MYSQL_YYABORT;
8649	  }
8650	;
8651
8652query_specification_start:
8653          SELECT_SYM
8654          {
8655            SELECT_LEX *sel;
8656            LEX *lex= Lex;
8657            if (!(sel= lex->alloc_select(TRUE)) || lex->push_select(sel))
8658              MYSQL_YYABORT;
8659            sel->init_select();
8660            sel->braces= FALSE;
8661          }
8662          select_options
8663          {
8664            Select->parsing_place= SELECT_LIST;
8665          }
8666          select_item_list
8667          {
8668            Select->parsing_place= NO_MATTER;
8669          }
8670          ;
8671
8672query_specification:
8673          query_specification_start
8674          opt_from_clause
8675          opt_where_clause
8676          opt_group_clause
8677          opt_having_clause
8678          opt_window_clause
8679          {
8680            $$= Lex->pop_select();
8681          }
8682        ;
8683
8684select_into_query_specification:
8685          query_specification_start
8686          into
8687          opt_from_clause
8688          opt_where_clause
8689          opt_group_clause
8690          opt_having_clause
8691          opt_window_clause
8692          {
8693            $$= Lex->pop_select();
8694          }
8695        ;
8696
8697/**
8698
8699  The following grammar for query expressions conformant to
8700  the latest SQL Standard is supported:
8701
8702    <query expression> ::=
8703     [ <with clause> ] <query expression body>
8704       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
8705
8706   <with clause> ::=
8707     WITH [ RECURSIVE ] <with_list
8708
8709   <with list> ::=
8710     <with list element> [ { <comma> <with list element> }... ]
8711
8712   <with list element> ::=
8713     <query name> [ '(' <with column list> ')' ]
8714         AS <table subquery>
8715
8716   <with column list> ::=
8717     <column name list>
8718
8719   <query expression body> ::
8720       <query term>
8721     | <query expression body> UNION [ ALL | DISTINCT ] <query term>
8722     | <query expression body> EXCEPT [ DISTINCT ] <query term>
8723
8724   <query term> ::=
8725       <query primary>
8726     | <query term> INTERSECT [ DISTINCT ] <query primary>
8727
8728   <query primary> ::=
8729       <simple table>
8730     | '(' <query expression body>
8731       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
8732       ')'
8733
8734   <simple table>
8735       <query specification>
8736     | <table value constructor>
8737
8738  <subquery>
8739       '(' <query_expression> ')'
8740
8741*/
8742
8743/*
8744  query_expression produces the same expressions as
8745      <query expression>
8746*/
8747
8748query_expression:
8749          query_expression_no_with_clause
8750          {
8751            $1->set_with_clause(NULL);
8752            $$= $1;
8753          }
8754        | with_clause
8755          query_expression_no_with_clause
8756          {
8757            $2->set_with_clause($1);
8758            $1->attach_to($2->first_select());
8759            $$= $2;
8760          }
8761        ;
8762
8763/*
8764   query_expression_no_with_clause produces the same expressions as
8765       <query expression> without [ <with clause> ]
8766*/
8767
8768query_expression_no_with_clause:
8769          query_expression_body_ext { $$= $1; }
8770        | query_expression_body_ext_parens { $$= $1; }
8771        ;
8772
8773/*
8774  query_expression_body_ext produces the same expressions as
8775      <query expression body>
8776       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
8777    | '('... <query expression body>
8778       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
8779      ')'...
8780  Note: number of ')' must be equal to the number of '(' in the rule above
8781*/
8782
8783query_expression_body_ext:
8784          query_expression_body
8785          {
8786            if ($1->first_select()->next_select())
8787            {
8788              if (Lex->parsed_multi_operand_query_expression_body($1))
8789                MYSQL_YYABORT;
8790            }
8791          }
8792          opt_query_expression_tail
8793          {
8794            if (!$3)
8795              $$= $1;
8796            else
8797              $$= Lex->add_tail_to_query_expression_body($1, $3);
8798          }
8799        | query_expression_body_ext_parens
8800          {
8801            Lex->push_select(!$1->first_select()->next_select() ?
8802                               $1->first_select() : $1->fake_select_lex);
8803          }
8804          query_expression_tail
8805          {
8806            if (!($$= Lex->add_tail_to_query_expression_body_ext_parens($1, $3)))
8807               MYSQL_YYABORT;
8808          }
8809        ;
8810
8811query_expression_body_ext_parens:
8812          '(' query_expression_body_ext_parens ')'
8813          { $$= $2; }
8814        | '(' query_expression_body_ext ')'
8815          {
8816            SELECT_LEX *sel= $2->first_select()->next_select() ?
8817                               $2->fake_select_lex : $2->first_select();
8818            sel->braces= true;
8819            $$= $2;
8820          }
8821        ;
8822
8823/*
8824  query_expression_body produces the same expressions as
8825      <query expression body>
8826*/
8827
8828query_expression_body:
8829          query_simple
8830          {
8831            Lex->push_select($1);
8832            if (!($$= Lex->create_unit($1)))
8833              MYSQL_YYABORT;
8834          }
8835        | query_expression_body
8836          unit_type_decl
8837          {
8838            if (!$1->first_select()->next_select())
8839            {
8840              Lex->pop_select();
8841            }
8842          }
8843          query_primary
8844          {
8845            if (!($$= Lex->add_primary_to_query_expression_body($1, $4,
8846                                                                $2.unit_type,
8847                                                                $2.distinct)))
8848              MYSQL_YYABORT;
8849          }
8850        | query_expression_body_ext_parens
8851          unit_type_decl
8852          query_primary
8853          {
8854            if (!($$= Lex->add_primary_to_query_expression_body_ext_parens(
8855                                                                $1, $3,
8856                                                                $2.unit_type,
8857                                                                $2.distinct)))
8858              MYSQL_YYABORT;
8859          }
8860        ;
8861
8862/*
8863  query_primary produces the same expressions as
8864      <query primary>
8865*/
8866
8867query_primary:
8868          query_simple
8869          { $$= $1; }
8870        | query_expression_body_ext_parens
8871          { $$= $1->first_select(); }
8872        ;
8873
8874/*
8875  query_simple produces the same expressions as
8876      <simple table>
8877*/
8878
8879query_simple:
8880          simple_table { $$= $1;}
8881        ;
8882
8883subselect:
8884          query_expression
8885          {
8886            if (!($$= Lex->parsed_subselect($1)))
8887              YYABORT;
8888          }
8889        ;
8890
8891/*
8892  subquery produces the same expressions as
8893     <subquery>
8894
8895  Consider the production rule of the SQL Standard
8896     subquery:
8897        '(' query_expression ')'
8898
8899  This rule is equivalent to the rule
8900     subquery:
8901          '(' query_expression_no_with_clause ')'
8902        | '(' with_clause query_expression_no_with_clause ')'
8903  that in its turn is equivalent to
8904     subquery:
8905          '(' query_expression_body_ext ')'
8906        | query_expression_body_ext_parens
8907        | '(' with_clause query_expression_no_with_clause ')'
8908
8909  The latter can be re-written into
8910     subquery:
8911          query_expression_body_ext_parens
8912        | '(' with_clause query_expression_no_with_clause ')'
8913
8914  The last rule allows us to resolve properly the shift/reduce conflict
8915  when subquery is used in expressions such as in the following queries
8916     select (select * from t1 limit 1) + t2.a from t2
8917     select * from t1 where t1.a [not] in (select t2.a from t2)
8918
8919  In the rule below %prec SUBQUERY_AS_EXPR forces the parser to perform a shift
8920  operation rather then a reduce operation when ')' is encountered and can be
8921  considered as the last symbol a query expression.
8922*/
8923
8924subquery:
8925          query_expression_body_ext_parens %prec SUBQUERY_AS_EXPR
8926          {
8927            if (!$1->fake_select_lex)
8928              $1->first_select()->braces= false;
8929            else
8930              $1->fake_select_lex->braces= false;
8931            if (!($$= Lex->parsed_subselect($1)))
8932              YYABORT;
8933          }
8934        | '(' with_clause query_expression_no_with_clause ')'
8935          {
8936            $3->set_with_clause($2);
8937            $2->attach_to($3->first_select());
8938            if (!($$= Lex->parsed_subselect($3)))
8939              YYABORT;
8940          }
8941        ;
8942
8943opt_from_clause:
8944        /* empty */ %prec EMPTY_FROM_CLAUSE
8945        | from_clause
8946        ;
8947
8948from_clause:
8949          FROM table_reference_list
8950        ;
8951
8952table_reference_list:
8953          join_table_list
8954          {
8955            Select->context.table_list=
8956              Select->context.first_name_resolution_table=
8957                Select->table_list.first;
8958          }
8959        | DUAL_SYM
8960          /* oracle compatibility: oracle always requires FROM clause,
8961             and DUAL is system table without fields.
8962             Is "SELECT 1 FROM DUAL" any better than "SELECT 1" ?
8963          Hmmm :) */
8964        ;
8965
8966select_options:
8967          /* empty*/
8968        | select_option_list
8969          {
8970            if (unlikely((Select->options & SELECT_DISTINCT) &&
8971                         (Select->options & SELECT_ALL)))
8972              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT"));
8973          }
8974        ;
8975
8976opt_history_unit:
8977          /* empty*/         %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
8978          {
8979            $$= VERS_TIMESTAMP;
8980          }
8981        | TRANSACTION_SYM
8982          {
8983            $$= VERS_TRX_ID;
8984          }
8985        | TIMESTAMP
8986          {
8987            $$= VERS_TIMESTAMP;
8988          }
8989        ;
8990
8991history_point:
8992          TIMESTAMP TEXT_STRING
8993          {
8994            Item *item;
8995            if (!(item= type_handler_datetime.create_literal_item(thd,
8996                                                     $2.str, $2.length,
8997                                                     YYCSCL, true)))
8998              MYSQL_YYABORT;
8999            $$= Vers_history_point(VERS_TIMESTAMP, item);
9000          }
9001        | function_call_keyword_timestamp
9002          {
9003            $$= Vers_history_point(VERS_TIMESTAMP, $1);
9004          }
9005        | opt_history_unit bit_expr
9006          {
9007            $$= Vers_history_point($1, $2);
9008          }
9009        ;
9010
9011for_portion_of_time_clause:
9012          FOR_SYM PORTION_SYM OF_SYM remember_tok_start ident FROM
9013          bit_expr TO_SYM bit_expr
9014          {
9015            if (unlikely(0 == strcasecmp($5.str, "SYSTEM_TIME")))
9016            {
9017              thd->parse_error(ER_SYNTAX_ERROR, $4);
9018              MYSQL_YYABORT;
9019            }
9020            Lex->period_conditions.init(SYSTEM_TIME_FROM_TO,
9021                                        Vers_history_point(VERS_TIMESTAMP, $7),
9022                                        Vers_history_point(VERS_TIMESTAMP, $9),
9023                                        $5);
9024          }
9025        ;
9026
9027opt_for_portion_of_time_clause:
9028          /* empty */
9029          {
9030            $$= false;
9031          }
9032        | for_portion_of_time_clause
9033          {
9034            $$= true;
9035          }
9036        ;
9037
9038opt_for_system_time_clause:
9039          /* empty */
9040          {
9041            $$= false;
9042          }
9043        | FOR_SYSTEM_TIME_SYM system_time_expr
9044          {
9045            $$= true;
9046          }
9047        ;
9048
9049system_time_expr:
9050          AS OF_SYM history_point
9051          {
9052            Lex->vers_conditions.init(SYSTEM_TIME_AS_OF, $3);
9053          }
9054        | ALL
9055          {
9056            Lex->vers_conditions.init(SYSTEM_TIME_ALL);
9057          }
9058        | FROM history_point TO_SYM history_point
9059          {
9060            Lex->vers_conditions.init(SYSTEM_TIME_FROM_TO, $2, $4);
9061          }
9062        | BETWEEN_SYM history_point AND_SYM history_point
9063          {
9064            Lex->vers_conditions.init(SYSTEM_TIME_BETWEEN, $2, $4);
9065          }
9066        ;
9067
9068select_option_list:
9069          select_option_list select_option
9070        | select_option
9071        ;
9072
9073select_option:
9074          query_expression_option
9075        | SQL_NO_CACHE_SYM
9076          {
9077            /*
9078              Allow this flag once per query.
9079            */
9080            if (Select->options & OPTION_NO_QUERY_CACHE)
9081              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "SQL_NO_CACHE"));
9082            Select->options|= OPTION_NO_QUERY_CACHE;
9083          }
9084        | SQL_CACHE_SYM
9085          {
9086            /*
9087              Allow this flag once per query.
9088            */
9089            if (Select->options & OPTION_TO_QUERY_CACHE)
9090              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "SQL_CACHE"));
9091            Select->options|= OPTION_TO_QUERY_CACHE;
9092          }
9093        ;
9094
9095
9096select_lock_type:
9097          FOR_SYM UPDATE_SYM opt_lock_wait_timeout_new
9098          {
9099            $$= $3;
9100            $$.defined_lock= TRUE;
9101            $$.update_lock= TRUE;
9102          }
9103        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM opt_lock_wait_timeout_new
9104          {
9105            $$= $5;
9106            $$.defined_lock= TRUE;
9107            $$.update_lock= FALSE;
9108          }
9109        ;
9110
9111
9112opt_select_lock_type:
9113        /* empty */
9114        {
9115          $$.empty();
9116        }
9117        | select_lock_type
9118        {
9119          $$= $1;
9120        }
9121        ;
9122
9123
9124opt_lock_wait_timeout_new:
9125        /* empty */
9126        {
9127          $$.empty();
9128        }
9129        | WAIT_SYM ulong_num
9130        {
9131          $$.defined_timeout= TRUE;
9132          $$.timeout= $2;
9133        }
9134        | NOWAIT_SYM
9135        {
9136          $$.defined_timeout= TRUE;
9137          $$.timeout= 0;
9138        }
9139      ;
9140
9141select_item_list:
9142          select_item_list ',' select_item
9143        | select_item
9144        | '*'
9145          {
9146            Item *item= new (thd->mem_root)
9147                          Item_field(thd, &thd->lex->current_select->context,
9148                                     star_clex_str);
9149            if (unlikely(item == NULL))
9150              MYSQL_YYABORT;
9151            if (unlikely(add_item_to_list(thd, item)))
9152              MYSQL_YYABORT;
9153            (thd->lex->current_select->with_wild)++;
9154          }
9155        ;
9156
9157select_item:
9158          remember_name select_sublist_qualified_asterisk remember_end
9159          {
9160            if (unlikely(add_item_to_list(thd, $2)))
9161              MYSQL_YYABORT;
9162          }
9163        | remember_name expr remember_end select_alias
9164          {
9165            DBUG_ASSERT($1 < $3);
9166
9167            if (unlikely(add_item_to_list(thd, $2)))
9168              MYSQL_YYABORT;
9169            if ($4.str)
9170            {
9171              if (unlikely(Lex->sql_command == SQLCOM_CREATE_VIEW &&
9172                          check_column_name($4.str)))
9173                my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), $4.str));
9174              $2->common_flags&= ~IS_AUTO_GENERATED_NAME;
9175              $2->set_name(thd, $4);
9176            }
9177            else if (!$2->name.str || $2->name.str == item_empty_name)
9178            {
9179              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
9180            }
9181          }
9182        ;
9183
9184remember_tok_start:
9185          {
9186            $$= (char*) YYLIP->get_tok_start();
9187          }
9188        ;
9189
9190remember_name:
9191          {
9192            $$= (char*) YYLIP->get_cpp_tok_start();
9193          }
9194        ;
9195
9196remember_end:
9197          {
9198            $$= (char*) YYLIP->get_cpp_tok_end_rtrim();
9199          }
9200        ;
9201
9202select_alias:
9203          /* empty */ { $$=null_clex_str;}
9204        | AS ident { $$=$2; }
9205        | AS TEXT_STRING_sys { $$=$2; }
9206        | ident { $$=$1; }
9207        | TEXT_STRING_sys { $$=$1; }
9208        ;
9209
9210opt_default_time_precision:
9211          /* empty */             { $$= NOT_FIXED_DEC;  }
9212        | '(' ')'                 { $$= NOT_FIXED_DEC;  }
9213        | '(' real_ulong_num ')'  { $$= $2; }
9214        ;
9215
9216opt_time_precision:
9217          /* empty */             { $$= 0;  }
9218        | '(' ')'                 { $$= 0;  }
9219        | '(' real_ulong_num ')'  { $$= $2; }
9220        ;
9221
9222optional_braces:
9223          /* empty */ {}
9224        | '(' ')' {}
9225        ;
9226
9227/* all possible expressions */
9228expr:
9229          expr or expr %prec OR_SYM
9230          {
9231            /*
9232              Design notes:
9233              Do not use a manually maintained stack like thd->lex->xxx_list,
9234              but use the internal bison stack ($$, $1 and $3) instead.
9235              Using the bison stack is:
9236              - more robust to changes in the grammar,
9237              - guaranteed to be in sync with the parser state,
9238              - better for performances (no memory allocation).
9239            */
9240            Item_cond_or *item1;
9241            Item_cond_or *item3;
9242            if (is_cond_or($1))
9243            {
9244              item1= (Item_cond_or*) $1;
9245              if (is_cond_or($3))
9246              {
9247                item3= (Item_cond_or*) $3;
9248                /*
9249                  (X1 OR X2) OR (Y1 OR Y2) ==> OR (X1, X2, Y1, Y2)
9250                */
9251                item3->add_at_head(item1->argument_list());
9252                $$ = $3;
9253              }
9254              else
9255              {
9256                /*
9257                  (X1 OR X2) OR Y ==> OR (X1, X2, Y)
9258                */
9259                item1->add($3, thd->mem_root);
9260                $$ = $1;
9261              }
9262            }
9263            else if (is_cond_or($3))
9264            {
9265              item3= (Item_cond_or*) $3;
9266              /*
9267                X OR (Y1 OR Y2) ==> OR (X, Y1, Y2)
9268              */
9269              item3->add_at_head($1, thd->mem_root);
9270              $$ = $3;
9271            }
9272            else
9273            {
9274              /* X OR Y */
9275              $$= new (thd->mem_root) Item_cond_or(thd, $1, $3);
9276              if (unlikely($$ == NULL))
9277                MYSQL_YYABORT;
9278            }
9279          }
9280        | expr XOR expr %prec XOR
9281          {
9282            /* XOR is a proprietary extension */
9283            $$= new (thd->mem_root) Item_func_xor(thd, $1, $3);
9284            if (unlikely($$ == NULL))
9285              MYSQL_YYABORT;
9286          }
9287        | expr and expr %prec AND_SYM
9288          {
9289            /* See comments in rule expr: expr or expr */
9290            Item_cond_and *item1;
9291            Item_cond_and *item3;
9292            if (is_cond_and($1))
9293            {
9294              item1= (Item_cond_and*) $1;
9295              if (is_cond_and($3))
9296              {
9297                item3= (Item_cond_and*) $3;
9298                /*
9299                  (X1 AND X2) AND (Y1 AND Y2) ==> AND (X1, X2, Y1, Y2)
9300                */
9301                item3->add_at_head(item1->argument_list());
9302                $$ = $3;
9303              }
9304              else
9305              {
9306                /*
9307                  (X1 AND X2) AND Y ==> AND (X1, X2, Y)
9308                */
9309                item1->add($3, thd->mem_root);
9310                $$ = $1;
9311              }
9312            }
9313            else if (is_cond_and($3))
9314            {
9315              item3= (Item_cond_and*) $3;
9316              /*
9317                X AND (Y1 AND Y2) ==> AND (X, Y1, Y2)
9318              */
9319              item3->add_at_head($1, thd->mem_root);
9320              $$ = $3;
9321            }
9322            else
9323            {
9324              /* X AND Y */
9325              $$= new (thd->mem_root) Item_cond_and(thd, $1, $3);
9326              if (unlikely($$ == NULL))
9327                MYSQL_YYABORT;
9328            }
9329          }
9330        | NOT_SYM expr %prec NOT_SYM
9331          {
9332            $$= negate_expression(thd, $2);
9333            if (unlikely($$ == NULL))
9334              MYSQL_YYABORT;
9335          }
9336        | expr IS TRUE_SYM %prec IS
9337          {
9338            $$= new (thd->mem_root) Item_func_istrue(thd, $1);
9339            if (unlikely($$ == NULL))
9340              MYSQL_YYABORT;
9341          }
9342        | expr IS not TRUE_SYM %prec IS
9343          {
9344            $$= new (thd->mem_root) Item_func_isnottrue(thd, $1);
9345            if (unlikely($$ == NULL))
9346              MYSQL_YYABORT;
9347          }
9348        | expr IS FALSE_SYM %prec IS
9349          {
9350            $$= new (thd->mem_root) Item_func_isfalse(thd, $1);
9351            if (unlikely($$ == NULL))
9352              MYSQL_YYABORT;
9353          }
9354        | expr IS not FALSE_SYM %prec IS
9355          {
9356            $$= new (thd->mem_root) Item_func_isnotfalse(thd, $1);
9357            if (unlikely($$ == NULL))
9358              MYSQL_YYABORT;
9359          }
9360        | expr IS UNKNOWN_SYM %prec IS
9361          {
9362            $$= new (thd->mem_root) Item_func_isnull(thd, $1);
9363            if (unlikely($$ == NULL))
9364              MYSQL_YYABORT;
9365          }
9366        | expr IS not UNKNOWN_SYM %prec IS
9367          {
9368            $$= new (thd->mem_root) Item_func_isnotnull(thd, $1);
9369            if (unlikely($$ == NULL))
9370              MYSQL_YYABORT;
9371          }
9372        | expr IS NULL_SYM %prec PREC_BELOW_NOT
9373          {
9374            $$= new (thd->mem_root) Item_func_isnull(thd, $1);
9375            if (unlikely($$ == NULL))
9376              MYSQL_YYABORT;
9377          }
9378        | expr IS not NULL_SYM %prec IS
9379          {
9380            $$= new (thd->mem_root) Item_func_isnotnull(thd, $1);
9381            if (unlikely($$ == NULL))
9382              MYSQL_YYABORT;
9383          }
9384        | expr EQUAL_SYM predicate %prec EQUAL_SYM
9385          {
9386            $$= new (thd->mem_root) Item_func_equal(thd, $1, $3);
9387            if (unlikely($$ == NULL))
9388              MYSQL_YYABORT;
9389          }
9390        | expr comp_op predicate %prec '='
9391          {
9392            $$= (*$2)(0)->create(thd, $1, $3);
9393            if (unlikely($$ == NULL))
9394              MYSQL_YYABORT;
9395          }
9396        | expr comp_op all_or_any '(' subselect ')' %prec '='
9397          {
9398            $$= all_any_subquery_creator(thd, $1, $2, $3, $5);
9399            if (unlikely($$ == NULL))
9400              MYSQL_YYABORT;
9401          }
9402        | predicate
9403        ;
9404
9405predicate:
9406          predicate IN_SYM subquery
9407          {
9408            $$= new (thd->mem_root) Item_in_subselect(thd, $1, $3);
9409            if (unlikely(!$$))
9410              MYSQL_YYABORT;
9411          }
9412        | predicate not IN_SYM subquery
9413          {
9414            Item *item= new (thd->mem_root) Item_in_subselect(thd, $1, $4);
9415            if (unlikely(!item))
9416              MYSQL_YYABORT;
9417            $$= negate_expression(thd, item);
9418            if (unlikely(!$$))
9419              MYSQL_YYABORT;
9420          }
9421        | predicate IN_SYM '(' expr ')'
9422          {
9423            $$= handle_sql2003_note184_exception(thd, $1, true, $4);
9424            if (unlikely($$ == NULL))
9425              MYSQL_YYABORT;
9426          }
9427        | predicate IN_SYM '(' expr ',' expr_list ')'
9428          {
9429            $6->push_front($4, thd->mem_root);
9430            $6->push_front($1, thd->mem_root);
9431            $$= new (thd->mem_root) Item_func_in(thd, *$6);
9432            if (unlikely($$ == NULL))
9433              MYSQL_YYABORT;
9434          }
9435        | predicate not IN_SYM '(' expr ')'
9436          {
9437            $$= handle_sql2003_note184_exception(thd, $1, false, $5);
9438            if (unlikely($$ == NULL))
9439              MYSQL_YYABORT;
9440          }
9441        | predicate not IN_SYM '(' expr ',' expr_list ')'
9442          {
9443            $7->push_front($5, thd->mem_root);
9444            $7->push_front($1, thd->mem_root);
9445            Item_func_in *item= new (thd->mem_root) Item_func_in(thd, *$7);
9446            if (unlikely(item == NULL))
9447              MYSQL_YYABORT;
9448            $$= item->neg_transformer(thd);
9449          }
9450        | predicate BETWEEN_SYM predicate AND_SYM predicate %prec BETWEEN_SYM
9451          {
9452            $$= new (thd->mem_root) Item_func_between(thd, $1, $3, $5);
9453            if (unlikely($$ == NULL))
9454              MYSQL_YYABORT;
9455          }
9456        | predicate not BETWEEN_SYM predicate AND_SYM predicate %prec BETWEEN_SYM
9457          {
9458            Item_func_between *item;
9459            item= new (thd->mem_root) Item_func_between(thd, $1, $4, $6);
9460            if (unlikely(item == NULL))
9461              MYSQL_YYABORT;
9462            $$= item->neg_transformer(thd);
9463          }
9464        | predicate SOUNDS_SYM LIKE predicate
9465          {
9466            Item *item1= new (thd->mem_root) Item_func_soundex(thd, $1);
9467            Item *item4= new (thd->mem_root) Item_func_soundex(thd, $4);
9468            if (unlikely(item1 == NULL) || unlikely(item4 == NULL))
9469              MYSQL_YYABORT;
9470            $$= new (thd->mem_root) Item_func_eq(thd, item1, item4);
9471            if (unlikely($$ == NULL))
9472              MYSQL_YYABORT;
9473          }
9474        | predicate LIKE predicate
9475          {
9476            $$= new (thd->mem_root) Item_func_like(thd, $1, $3, escape(thd), false);
9477            if (unlikely(!$$))
9478              MYSQL_YYABORT;
9479          }
9480        | predicate LIKE predicate ESCAPE_SYM predicate %prec LIKE
9481          {
9482            Lex->escape_used= true;
9483            $$= new (thd->mem_root) Item_func_like(thd, $1, $3, $5, true);
9484            if (unlikely(!$$))
9485              MYSQL_YYABORT;
9486          }
9487        | predicate not LIKE predicate
9488          {
9489            Item *item= new (thd->mem_root) Item_func_like(thd, $1, $4, escape(thd), false);
9490            if (unlikely(!item))
9491              MYSQL_YYABORT;
9492            $$= item->neg_transformer(thd);
9493          }
9494        | predicate not LIKE predicate ESCAPE_SYM predicate %prec LIKE
9495          {
9496            Lex->escape_used= true;
9497            Item *item= new (thd->mem_root) Item_func_like(thd, $1, $4, $6, true);
9498            if (unlikely(!item))
9499              MYSQL_YYABORT;
9500            $$= item->neg_transformer(thd);
9501          }
9502        | predicate REGEXP predicate
9503          {
9504            $$= new (thd->mem_root) Item_func_regex(thd, $1, $3);
9505            if (unlikely($$ == NULL))
9506              MYSQL_YYABORT;
9507          }
9508        | predicate not REGEXP predicate
9509          {
9510            Item *item= new (thd->mem_root) Item_func_regex(thd, $1, $4);
9511            if (unlikely(item == NULL))
9512              MYSQL_YYABORT;
9513            $$= negate_expression(thd, item);
9514            if (unlikely($$ == NULL))
9515              MYSQL_YYABORT;
9516          }
9517        | bit_expr %prec PREC_BELOW_NOT
9518        ;
9519
9520bit_expr:
9521          bit_expr '|' bit_expr %prec '|'
9522          {
9523            $$= new (thd->mem_root) Item_func_bit_or(thd, $1, $3);
9524            if (unlikely($$ == NULL))
9525              MYSQL_YYABORT;
9526          }
9527        | bit_expr '&' bit_expr %prec '&'
9528          {
9529            $$= new (thd->mem_root) Item_func_bit_and(thd, $1, $3);
9530            if (unlikely($$ == NULL))
9531              MYSQL_YYABORT;
9532          }
9533        | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
9534          {
9535            $$= new (thd->mem_root) Item_func_shift_left(thd, $1, $3);
9536            if (unlikely($$ == NULL))
9537              MYSQL_YYABORT;
9538          }
9539        | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
9540          {
9541            $$= new (thd->mem_root) Item_func_shift_right(thd, $1, $3);
9542            if (unlikely($$ == NULL))
9543              MYSQL_YYABORT;
9544          }
9545        | bit_expr ORACLE_CONCAT_SYM bit_expr
9546          {
9547            $$= new (thd->mem_root) Item_func_concat_operator_oracle(thd,
9548                                                                     $1, $3);
9549            if (unlikely($$ == NULL))
9550              MYSQL_YYABORT;
9551          }
9552        | bit_expr '+' bit_expr %prec '+'
9553          {
9554            $$= new (thd->mem_root) Item_func_plus(thd, $1, $3);
9555            if (unlikely($$ == NULL))
9556              MYSQL_YYABORT;
9557          }
9558        | bit_expr '-' bit_expr %prec '-'
9559          {
9560            $$= new (thd->mem_root) Item_func_minus(thd, $1, $3);
9561            if (unlikely($$ == NULL))
9562              MYSQL_YYABORT;
9563          }
9564        | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
9565          {
9566            $$= new (thd->mem_root) Item_date_add_interval(thd, $1, $4, $5, 0);
9567            if (unlikely($$ == NULL))
9568              MYSQL_YYABORT;
9569          }
9570        | bit_expr '-' INTERVAL_SYM expr interval %prec '-'
9571          {
9572            $$= new (thd->mem_root) Item_date_add_interval(thd, $1, $4, $5, 1);
9573            if (unlikely($$ == NULL))
9574              MYSQL_YYABORT;
9575          }
9576        | INTERVAL_SYM expr interval '+' expr
9577          /* we cannot put interval before - */
9578          {
9579            $$= new (thd->mem_root) Item_date_add_interval(thd, $5, $2, $3, 0);
9580            if (unlikely($$ == NULL))
9581              MYSQL_YYABORT;
9582          }
9583        | '+' INTERVAL_SYM expr interval '+' expr %prec NEG
9584          {
9585            $$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 0);
9586            if (unlikely($$ == NULL))
9587              MYSQL_YYABORT;
9588          }
9589        | '-' INTERVAL_SYM expr interval '+' expr %prec NEG
9590          {
9591            $$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 1);
9592            if (unlikely($$ == NULL))
9593              MYSQL_YYABORT;
9594          }
9595        | bit_expr '*' bit_expr %prec '*'
9596          {
9597            $$= new (thd->mem_root) Item_func_mul(thd, $1, $3);
9598            if (unlikely($$ == NULL))
9599              MYSQL_YYABORT;
9600          }
9601        | bit_expr '/' bit_expr %prec '/'
9602          {
9603            $$= new (thd->mem_root) Item_func_div(thd, $1, $3);
9604            if (unlikely($$ == NULL))
9605              MYSQL_YYABORT;
9606          }
9607        | bit_expr '%' bit_expr %prec '%'
9608          {
9609            $$= new (thd->mem_root) Item_func_mod(thd, $1, $3);
9610            if (unlikely($$ == NULL))
9611              MYSQL_YYABORT;
9612          }
9613        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
9614          {
9615            $$= new (thd->mem_root) Item_func_int_div(thd, $1, $3);
9616            if (unlikely($$ == NULL))
9617              MYSQL_YYABORT;
9618          }
9619        | bit_expr MOD_SYM bit_expr %prec MOD_SYM
9620          {
9621            $$= new (thd->mem_root) Item_func_mod(thd, $1, $3);
9622            if (unlikely($$ == NULL))
9623              MYSQL_YYABORT;
9624          }
9625        | bit_expr '^' bit_expr
9626          {
9627            $$= new (thd->mem_root) Item_func_bit_xor(thd, $1, $3);
9628            if (unlikely($$ == NULL))
9629              MYSQL_YYABORT;
9630          }
9631        | mysql_concatenation_expr %prec '^'
9632        ;
9633
9634or:
9635          OR_SYM
9636       | OR2_SYM
9637       ;
9638
9639and:
9640          AND_SYM
9641       | AND_AND_SYM
9642       ;
9643
9644not:
9645          NOT_SYM
9646        | NOT2_SYM
9647        ;
9648
9649not2:
9650          '!'
9651        | NOT2_SYM
9652        ;
9653
9654comp_op:
9655          '='     { $$ = &comp_eq_creator; }
9656        | GE     { $$ = &comp_ge_creator; }
9657        | '>' { $$ = &comp_gt_creator; }
9658        | LE     { $$ = &comp_le_creator; }
9659        | '<'     { $$ = &comp_lt_creator; }
9660        | NE     { $$ = &comp_ne_creator; }
9661        ;
9662
9663all_or_any:
9664          ALL     { $$ = 1; }
9665        | ANY_SYM { $$ = 0; }
9666        ;
9667
9668opt_dyncol_type:
9669          /* empty */
9670          {
9671            $$.set(DYN_COL_NULL); /* automatic type */
9672            Lex->charset= NULL;
9673	  }
9674        | AS dyncol_type { $$= $2; }
9675        ;
9676
9677dyncol_type:
9678          numeric_dyncol_type             { $$= $1; Lex->charset= NULL; }
9679        | temporal_dyncol_type            { $$= $1; Lex->charset= NULL; }
9680        | string_dyncol_type              { $$= $1; }
9681        ;
9682
9683numeric_dyncol_type:
9684          INT_SYM                         { $$.set(DYN_COL_INT); }
9685        | UNSIGNED INT_SYM                { $$.set(DYN_COL_UINT);  }
9686        | DOUBLE_SYM                      { $$.set(DYN_COL_DOUBLE);  }
9687        | REAL                            { $$.set(DYN_COL_DOUBLE); }
9688        | FLOAT_SYM                       { $$.set(DYN_COL_DOUBLE); }
9689        | DECIMAL_SYM float_options       { $$.set(DYN_COL_DECIMAL, $2); }
9690        ;
9691
9692temporal_dyncol_type:
9693          DATE_SYM                        { $$.set(DYN_COL_DATE); }
9694        | TIME_SYM opt_field_length       { $$.set(DYN_COL_TIME, 0, $2); }
9695        | DATETIME opt_field_length       { $$.set(DYN_COL_DATETIME, 0, $2); }
9696        ;
9697
9698string_dyncol_type:
9699          char
9700          { Lex->charset= thd->variables.collation_connection; }
9701          opt_binary
9702          {
9703            $$.set(DYN_COL_STRING);
9704          }
9705        | nchar
9706          {
9707            $$.set(DYN_COL_STRING);
9708            Lex->charset= national_charset_info;
9709          }
9710        ;
9711
9712dyncall_create_element:
9713   expr ',' expr opt_dyncol_type
9714   {
9715     LEX *lex= Lex;
9716     $$= (DYNCALL_CREATE_DEF *)
9717       alloc_root(thd->mem_root, sizeof(DYNCALL_CREATE_DEF));
9718     if (unlikely($$ == NULL))
9719       MYSQL_YYABORT;
9720     $$->key= $1;
9721     $$->value= $3;
9722     $$->type= (DYNAMIC_COLUMN_TYPE)$4.dyncol_type();
9723     $$->cs= lex->charset;
9724     if ($4.length())
9725       $$->len= strtoul($4.length(), NULL, 10);
9726     else
9727       $$->len= 0;
9728     if ($4.dec())
9729       $$->frac= strtoul($4.dec(), NULL, 10);
9730     else
9731       $$->len= 0;
9732   }
9733   ;
9734
9735dyncall_create_list:
9736     dyncall_create_element
9737       {
9738         $$= new (thd->mem_root) List<DYNCALL_CREATE_DEF>;
9739         if (unlikely($$ == NULL))
9740           MYSQL_YYABORT;
9741         $$->push_back($1, thd->mem_root);
9742       }
9743   | dyncall_create_list ',' dyncall_create_element
9744       {
9745         $1->push_back($3, thd->mem_root);
9746         $$= $1;
9747       }
9748   ;
9749
9750
9751plsql_cursor_attr:
9752          ISOPEN_SYM    { $$= PLSQL_CURSOR_ATTR_ISOPEN; }
9753        | FOUND_SYM     { $$= PLSQL_CURSOR_ATTR_FOUND; }
9754        | NOTFOUND_SYM  { $$= PLSQL_CURSOR_ATTR_NOTFOUND; }
9755        | ROWCOUNT_SYM  { $$= PLSQL_CURSOR_ATTR_ROWCOUNT; }
9756        ;
9757
9758explicit_cursor_attr:
9759          ident PERCENT_ORACLE_SYM plsql_cursor_attr
9760          {
9761            if (unlikely(!($$= Lex->make_item_plsql_cursor_attr(thd, &$1, $3))))
9762              MYSQL_YYABORT;
9763          }
9764        ;
9765
9766
9767trim_operands:
9768          expr                     { $$.set(TRIM_BOTH, $1);         }
9769        | LEADING  expr FROM expr  { $$.set(TRIM_LEADING, $2, $4);  }
9770        | TRAILING expr FROM expr  { $$.set(TRIM_TRAILING, $2, $4); }
9771        | BOTH     expr FROM expr  { $$.set(TRIM_BOTH, $2, $4);     }
9772        | LEADING       FROM expr  { $$.set(TRIM_LEADING, $3);      }
9773        | TRAILING      FROM expr  { $$.set(TRIM_TRAILING, $3);     }
9774        | BOTH          FROM expr  { $$.set(TRIM_BOTH, $3);         }
9775        | expr          FROM expr  { $$.set(TRIM_BOTH, $1, $3);     }
9776        ;
9777
9778/*
9779  Expressions that the parser allows in a column DEFAULT clause
9780  without parentheses. These expressions cannot end with a COLLATE clause.
9781
9782  If we allowed any "expr" in DEFAULT clause, there would be a confusion
9783  in queries like this:
9784    CREATE TABLE t1 (a TEXT DEFAULT 'a' COLLATE latin1_bin);
9785  It would be not clear what COLLATE stands for:
9786  - the collation of the column `a`, or
9787  - the collation of the string literal 'a'
9788
9789  This restriction allows to parse the above query unambiguiusly:
9790  COLLATE belongs to the column rather than the literal.
9791  If one needs COLLATE to belong to the literal, parentheses must be used:
9792    CREATE TABLE t1 (a TEXT DEFAULT ('a' COLLATE latin1_bin));
9793  Note: the COLLATE clause is rather meaningless here, but the query
9794  is syntactically correct.
9795
9796  Note, some of the expressions are not actually allowed in DEFAULT,
9797  e.g. sum_expr, window_func_expr, ROW(...), VALUES().
9798  We could move them to simple_expr, but that would make
9799  these two queries return a different error messages:
9800    CREATE TABLE t1 (a INT DEFAULT AVG(1));
9801    CREATE TABLE t1 (a INT DEFAULT (AVG(1)));
9802  The first query would return "syntax error".
9803  Currenly both return:
9804   Function or expression 'avg(' is not allowed for 'DEFAULT' ...
9805*/
9806column_default_non_parenthesized_expr:
9807          simple_ident
9808        | function_call_keyword
9809        | function_call_nonkeyword
9810        | function_call_generic
9811        | function_call_conflict
9812        | literal
9813        | param_marker { $$= $1; }
9814        | variable
9815        | sum_expr
9816          {
9817            if (!Lex->select_stack_top)
9818            {
9819              my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0));
9820              MYSQL_YYABORT;
9821            }
9822          }
9823        | window_func_expr
9824          {
9825            if (!Lex->select_stack_top)
9826            {
9827               my_error(ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION, MYF(0));
9828               MYSQL_YYABORT;
9829            }
9830          }
9831        | inverse_distribution_function
9832        | ROW_SYM '(' expr ',' expr_list ')'
9833          {
9834            $5->push_front($3, thd->mem_root);
9835            $$= new (thd->mem_root) Item_row(thd, *$5);
9836            if (unlikely($$ == NULL))
9837              MYSQL_YYABORT;
9838          }
9839        | EXISTS '(' subselect ')'
9840          {
9841            $$= new (thd->mem_root) Item_exists_subselect(thd, $3);
9842            if (unlikely($$ == NULL))
9843              MYSQL_YYABORT;
9844          }
9845        | '{' ident expr '}'
9846          {
9847            if (unlikely(!($$= $3->make_odbc_literal(thd, &$2))))
9848              MYSQL_YYABORT;
9849          }
9850        | MATCH ident_list_arg AGAINST '(' bit_expr fulltext_options ')'
9851          {
9852            $2->push_front($5, thd->mem_root);
9853            Item_func_match *i1= new (thd->mem_root) Item_func_match(thd, *$2,
9854                                                                     $6);
9855            if (unlikely(i1 == NULL))
9856              MYSQL_YYABORT;
9857            Select->add_ftfunc_to_list(thd, i1);
9858            $$= i1;
9859          }
9860        | CAST_SYM '(' expr AS cast_type ')'
9861          {
9862            if (unlikely(!($$= $5.create_typecast_item_or_error(thd, $3,
9863                                                                Lex->charset))))
9864              MYSQL_YYABORT;
9865          }
9866        | CASE_SYM when_list_opt_else END
9867          {
9868            if (unlikely(!($$= new(thd->mem_root) Item_func_case_searched(thd, *$2))))
9869              MYSQL_YYABORT;
9870          }
9871        | CASE_SYM expr when_list_opt_else END
9872          {
9873            $3->push_front($2, thd->mem_root);
9874            if (unlikely(!($$= new (thd->mem_root) Item_func_case_simple(thd, *$3))))
9875              MYSQL_YYABORT;
9876          }
9877        | CONVERT_SYM '(' expr ',' cast_type ')'
9878          {
9879            if (unlikely(!($$= $5.create_typecast_item_or_error(thd, $3,
9880                                                                Lex->charset))))
9881              MYSQL_YYABORT;
9882          }
9883        | CONVERT_SYM '(' expr USING charset_name ')'
9884          {
9885            $$= new (thd->mem_root) Item_func_conv_charset(thd, $3, $5);
9886            if (unlikely($$ == NULL))
9887              MYSQL_YYABORT;
9888          }
9889        | DEFAULT '(' simple_ident ')'
9890          {
9891            Item_splocal *il= $3->get_item_splocal();
9892            if (unlikely(il))
9893              my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), il->my_name()->str));
9894            $$= new (thd->mem_root) Item_default_value(thd, Lex->current_context(),
9895                                                         $3, 0);
9896            if (unlikely($$ == NULL))
9897              MYSQL_YYABORT;
9898            Lex->default_used= TRUE;
9899          }
9900        | VALUE_SYM '(' simple_ident_nospvar ')'
9901          {
9902            $$= new (thd->mem_root) Item_insert_value(thd, Lex->current_context(),
9903                                                        $3);
9904            if (unlikely($$ == NULL))
9905              MYSQL_YYABORT;
9906          }
9907        | NEXT_SYM VALUE_SYM FOR_SYM table_ident
9908          {
9909            if (unlikely(!($$= Lex->create_item_func_nextval(thd, $4))))
9910              MYSQL_YYABORT;
9911          }
9912        | NEXTVAL_SYM '(' table_ident ')'
9913          {
9914            if (unlikely(!($$= Lex->create_item_func_nextval(thd, $3))))
9915              MYSQL_YYABORT;
9916          }
9917        | PREVIOUS_SYM VALUE_SYM FOR_SYM table_ident
9918          {
9919            if (unlikely(!($$= Lex->create_item_func_lastval(thd, $4))))
9920              MYSQL_YYABORT;
9921          }
9922        | LASTVAL_SYM '(' table_ident ')'
9923          {
9924            if (unlikely(!($$= Lex->create_item_func_lastval(thd, $3))))
9925              MYSQL_YYABORT;
9926          }
9927        | SETVAL_SYM '(' table_ident ',' longlong_num ')'
9928          {
9929            if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0, 1))))
9930              MYSQL_YYABORT;
9931          }
9932        | SETVAL_SYM '(' table_ident ',' longlong_num ',' bool ')'
9933          {
9934            if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0, $7))))
9935              MYSQL_YYABORT;
9936          }
9937        | SETVAL_SYM '(' table_ident ',' longlong_num ',' bool ',' ulonglong_num ')'
9938          {
9939            if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, $9, $7))))
9940              MYSQL_YYABORT;
9941          }
9942        ;
9943
9944primary_expr:
9945          column_default_non_parenthesized_expr
9946        | explicit_cursor_attr
9947        | '(' parenthesized_expr ')' { $$= $2; }
9948        | subquery
9949          {
9950            if (!($$= Lex->create_item_query_expression(thd, $1->master_unit())))
9951              MYSQL_YYABORT;
9952          }
9953        ;
9954
9955string_factor_expr:
9956          primary_expr
9957        | string_factor_expr COLLATE_SYM collation_name
9958          {
9959            if (unlikely(!($$= new (thd->mem_root) Item_func_set_collation(thd, $1, $3))))
9960              MYSQL_YYABORT;
9961          }
9962        ;
9963
9964simple_expr:
9965          string_factor_expr %prec NEG
9966        | BINARY simple_expr
9967          {
9968            Type_cast_attributes at(&my_charset_bin);
9969            if (unlikely(!($$= type_handler_long_blob.create_typecast_item(thd, $2, at))))
9970              MYSQL_YYABORT;
9971          }
9972        | '+' simple_expr %prec NEG
9973          {
9974            $$= $2;
9975          }
9976        | '-' simple_expr %prec NEG
9977          {
9978            $$= $2->neg(thd);
9979            if (unlikely($$ == NULL))
9980              MYSQL_YYABORT;
9981          }
9982        | '~' simple_expr %prec NEG
9983          {
9984            $$= new (thd->mem_root) Item_func_bit_neg(thd, $2);
9985            if (unlikely($$ == NULL))
9986              MYSQL_YYABORT;
9987          }
9988        | not2 simple_expr %prec NEG
9989          {
9990            $$= negate_expression(thd, $2);
9991            if (unlikely($$ == NULL))
9992              MYSQL_YYABORT;
9993          }
9994        ;
9995
9996mysql_concatenation_expr:
9997          simple_expr
9998        | mysql_concatenation_expr MYSQL_CONCAT_SYM simple_expr
9999          {
10000            $$= new (thd->mem_root) Item_func_concat(thd, $1, $3);
10001            if (unlikely($$ == NULL))
10002              MYSQL_YYABORT;
10003          }
10004        ;
10005
10006function_call_keyword_timestamp:
10007          TIMESTAMP '(' expr ')'
10008          {
10009            $$= new (thd->mem_root) Item_datetime_typecast(thd, $3,
10010                                      AUTO_SEC_PART_DIGITS);
10011            if (unlikely($$ == NULL))
10012              MYSQL_YYABORT;
10013          }
10014        | TIMESTAMP '(' expr ',' expr ')'
10015          {
10016            $$= new (thd->mem_root) Item_func_timestamp(thd, $3, $5);
10017            if (unlikely($$ == NULL))
10018              MYSQL_YYABORT;
10019          }
10020        ;
10021/*
10022  Function call syntax using official SQL 2003 keywords.
10023  Because the function name is an official token,
10024  a dedicated grammar rule is needed in the parser.
10025  There is no potential for conflicts
10026*/
10027function_call_keyword:
10028          CHAR_SYM '(' expr_list ')'
10029          {
10030            $$= new (thd->mem_root) Item_func_char(thd, *$3);
10031            if (unlikely($$ == NULL))
10032              MYSQL_YYABORT;
10033          }
10034        | CHAR_SYM '(' expr_list USING charset_name ')'
10035          {
10036            $$= new (thd->mem_root) Item_func_char(thd, *$3, $5);
10037            if (unlikely($$ == NULL))
10038              MYSQL_YYABORT;
10039          }
10040        | CURRENT_USER optional_braces
10041          {
10042            $$= new (thd->mem_root) Item_func_current_user(thd,
10043                                      Lex->current_context());
10044            if (unlikely($$ == NULL))
10045              MYSQL_YYABORT;
10046            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10047            Lex->safe_to_cache_query= 0;
10048          }
10049        | CURRENT_ROLE optional_braces
10050          {
10051            $$= new (thd->mem_root) Item_func_current_role(thd,
10052                                      Lex->current_context());
10053            if (unlikely($$ == NULL))
10054              MYSQL_YYABORT;
10055            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10056            Lex->safe_to_cache_query= 0;
10057          }
10058        | DATE_SYM '(' expr ')'
10059          {
10060            $$= new (thd->mem_root) Item_date_typecast(thd, $3);
10061            if (unlikely($$ == NULL))
10062              MYSQL_YYABORT;
10063          }
10064        | DAY_SYM '(' expr ')'
10065          {
10066            $$= new (thd->mem_root) Item_func_dayofmonth(thd, $3);
10067            if (unlikely($$ == NULL))
10068              MYSQL_YYABORT;
10069          }
10070        | HOUR_SYM '(' expr ')'
10071          {
10072            $$= new (thd->mem_root) Item_func_hour(thd, $3);
10073            if (unlikely($$ == NULL))
10074              MYSQL_YYABORT;
10075          }
10076        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
10077          {
10078            $$= new (thd->mem_root) Item_func_insert(thd, $3, $5, $7, $9);
10079            if (unlikely($$ == NULL))
10080              MYSQL_YYABORT;
10081          }
10082        | INTERVAL_SYM '(' expr ',' expr ')'
10083          {
10084            List<Item> *list= new (thd->mem_root) List<Item>;
10085            if (unlikely(list == NULL))
10086              MYSQL_YYABORT;
10087            if (unlikely(list->push_front($5, thd->mem_root)) ||
10088                unlikely(list->push_front($3, thd->mem_root)))
10089              MYSQL_YYABORT;
10090            Item_row *item= new (thd->mem_root) Item_row(thd, *list);
10091            if (unlikely(item == NULL))
10092              MYSQL_YYABORT;
10093            $$= new (thd->mem_root) Item_func_interval(thd, item);
10094            if (unlikely($$ == NULL))
10095              MYSQL_YYABORT;
10096          }
10097        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')'
10098          {
10099            $7->push_front($5, thd->mem_root);
10100            $7->push_front($3, thd->mem_root);
10101            Item_row *item= new (thd->mem_root) Item_row(thd, *$7);
10102            if (unlikely(item == NULL))
10103              MYSQL_YYABORT;
10104            $$= new (thd->mem_root) Item_func_interval(thd, item);
10105            if (unlikely($$ == NULL))
10106              MYSQL_YYABORT;
10107          }
10108        | LEFT '(' expr ',' expr ')'
10109          {
10110            $$= new (thd->mem_root) Item_func_left(thd, $3, $5);
10111            if (unlikely($$ == NULL))
10112              MYSQL_YYABORT;
10113          }
10114        | MINUTE_SYM '(' expr ')'
10115          {
10116            $$= new (thd->mem_root) Item_func_minute(thd, $3);
10117            if (unlikely($$ == NULL))
10118              MYSQL_YYABORT;
10119          }
10120        | MONTH_SYM '(' expr ')'
10121          {
10122            $$= new (thd->mem_root) Item_func_month(thd, $3);
10123            if (unlikely($$ == NULL))
10124              MYSQL_YYABORT;
10125          }
10126        | RIGHT '(' expr ',' expr ')'
10127          {
10128            $$= new (thd->mem_root) Item_func_right(thd, $3, $5);
10129            if (unlikely($$ == NULL))
10130              MYSQL_YYABORT;
10131          }
10132        | SECOND_SYM '(' expr ')'
10133          {
10134            $$= new (thd->mem_root) Item_func_second(thd, $3);
10135            if (unlikely($$ == NULL))
10136              MYSQL_YYABORT;
10137          }
10138        | SQL_SYM PERCENT_ORACLE_SYM ROWCOUNT_SYM
10139          {
10140            $$= new (thd->mem_root) Item_func_oracle_sql_rowcount(thd);
10141            if (unlikely($$ == NULL))
10142              MYSQL_YYABORT;
10143            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10144            Lex->safe_to_cache_query= 0;
10145          }
10146        | TIME_SYM '(' expr ')'
10147          {
10148            $$= new (thd->mem_root) Item_time_typecast(thd, $3,
10149                                      AUTO_SEC_PART_DIGITS);
10150            if (unlikely($$ == NULL))
10151              MYSQL_YYABORT;
10152          }
10153        | function_call_keyword_timestamp
10154          {
10155            $$= $1;
10156          }
10157        | TRIM '(' trim_operands ')'
10158          {
10159            if (unlikely(!($$= $3.make_item_func_trim(thd))))
10160              MYSQL_YYABORT;
10161          }
10162        | USER_SYM '(' ')'
10163          {
10164            $$= new (thd->mem_root) Item_func_user(thd);
10165            if (unlikely($$ == NULL))
10166              MYSQL_YYABORT;
10167            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10168            Lex->safe_to_cache_query=0;
10169          }
10170        | YEAR_SYM '(' expr ')'
10171          {
10172            $$= new (thd->mem_root) Item_func_year(thd, $3);
10173            if (unlikely($$ == NULL))
10174              MYSQL_YYABORT;
10175          }
10176        ;
10177
10178/*
10179  Function calls using non reserved keywords, with special syntaxic forms.
10180  Dedicated grammar rules are needed because of the syntax,
10181  but also have the potential to cause incompatibilities with other
10182  parts of the language.
10183  MAINTAINER:
10184  The only reasons a function should be added here are:
10185  - for compatibility reasons with another SQL syntax (CURDATE),
10186  - for typing reasons (GET_FORMAT)
10187  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
10188  discouraged.
10189*/
10190function_call_nonkeyword:
10191          ADDDATE_SYM '(' expr ',' expr ')'
10192          {
10193            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $5,
10194                                                             INTERVAL_DAY, 0);
10195            if (unlikely($$ == NULL))
10196              MYSQL_YYABORT;
10197          }
10198        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
10199          {
10200            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 0);
10201            if (unlikely($$ == NULL))
10202              MYSQL_YYABORT;
10203          }
10204        | CURDATE optional_braces
10205          {
10206            $$= new (thd->mem_root) Item_func_curdate_local(thd);
10207            if (unlikely($$ == NULL))
10208              MYSQL_YYABORT;
10209            Lex->safe_to_cache_query=0;
10210          }
10211        | CURTIME opt_time_precision
10212          {
10213            $$= new (thd->mem_root) Item_func_curtime_local(thd, $2);
10214            if (unlikely($$ == NULL))
10215              MYSQL_YYABORT;
10216            Lex->safe_to_cache_query=0;
10217          }
10218        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
10219          {
10220            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 0);
10221            if (unlikely($$ == NULL))
10222              MYSQL_YYABORT;
10223          }
10224        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
10225          {
10226            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 1);
10227            if (unlikely($$ == NULL))
10228              MYSQL_YYABORT;
10229          }
10230        | DATE_FORMAT_SYM '(' expr ',' expr ')'
10231          {
10232            $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5);
10233            if (unlikely($$ == NULL))
10234              MYSQL_YYABORT;
10235          }
10236        | DATE_FORMAT_SYM '(' expr ',' expr ',' expr ')'
10237          {
10238            $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5, $7);
10239            if (unlikely($$ == NULL))
10240              MYSQL_YYABORT;
10241          }
10242        | DECODE_MARIADB_SYM '(' expr ',' expr ')'
10243          {
10244            $$= new (thd->mem_root) Item_func_decode(thd, $3, $5);
10245            if (unlikely($$ == NULL))
10246              MYSQL_YYABORT;
10247          }
10248        | DECODE_ORACLE_SYM '(' expr ',' decode_when_list_oracle ')'
10249          {
10250            $5->push_front($3, thd->mem_root);
10251            if (unlikely(!($$= new (thd->mem_root) Item_func_decode_oracle(thd, *$5))))
10252              MYSQL_YYABORT;
10253          }
10254        | EXTRACT_SYM '(' interval FROM expr ')'
10255          {
10256            $$=new (thd->mem_root) Item_extract(thd, $3, $5);
10257            if (unlikely($$ == NULL))
10258              MYSQL_YYABORT;
10259          }
10260        | GET_FORMAT '(' date_time_type  ',' expr ')'
10261          {
10262            $$= new (thd->mem_root) Item_func_get_format(thd, $3, $5);
10263            if (unlikely($$ == NULL))
10264              MYSQL_YYABORT;
10265          }
10266        | NOW_SYM opt_time_precision
10267          {
10268            $$= new (thd->mem_root) Item_func_now_local(thd, $2);
10269            if (unlikely($$ == NULL))
10270              MYSQL_YYABORT;
10271            Lex->safe_to_cache_query=0;
10272          }
10273        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
10274          {
10275            $$= new (thd->mem_root) Item_func_locate(thd, $5, $3);
10276            if (unlikely($$ == NULL))
10277              MYSQL_YYABORT;
10278          }
10279        | SUBDATE_SYM '(' expr ',' expr ')'
10280          {
10281            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $5,
10282                                                             INTERVAL_DAY, 1);
10283            if (unlikely($$ == NULL))
10284              MYSQL_YYABORT;
10285          }
10286        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
10287          {
10288            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 1);
10289            if (unlikely($$ == NULL))
10290              MYSQL_YYABORT;
10291          }
10292        | SUBSTRING '(' expr ',' expr ',' expr ')'
10293          {
10294            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5, $7))))
10295              MYSQL_YYABORT;
10296          }
10297        | SUBSTRING '(' expr ',' expr ')'
10298          {
10299            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5))))
10300              MYSQL_YYABORT;
10301          }
10302        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
10303          {
10304            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5, $7))))
10305              MYSQL_YYABORT;
10306          }
10307        | SUBSTRING '(' expr FROM expr ')'
10308          {
10309            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5))))
10310              MYSQL_YYABORT;
10311          }
10312        | SYSDATE opt_time_precision
10313          {
10314            /*
10315              Unlike other time-related functions, SYSDATE() is
10316              replication-unsafe because it is not affected by the
10317              TIMESTAMP variable.  It is unsafe even if
10318              sysdate_is_now=1, because the slave may have
10319              sysdate_is_now=0.
10320            */
10321            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10322            if (global_system_variables.sysdate_is_now == 0)
10323              $$= new (thd->mem_root) Item_func_sysdate_local(thd, $2);
10324            else
10325              $$= new (thd->mem_root) Item_func_now_local(thd, $2);
10326            if (unlikely($$ == NULL))
10327              MYSQL_YYABORT;
10328            Lex->safe_to_cache_query=0;
10329          }
10330        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
10331          {
10332            $$= new (thd->mem_root) Item_date_add_interval(thd, $7, $5, $3, 0);
10333            if (unlikely($$ == NULL))
10334              MYSQL_YYABORT;
10335          }
10336        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
10337          {
10338            $$= new (thd->mem_root) Item_func_timestamp_diff(thd, $5, $7, $3);
10339            if (unlikely($$ == NULL))
10340              MYSQL_YYABORT;
10341          }
10342        | TRIM_ORACLE '(' trim_operands ')'
10343          {
10344            if (unlikely(!($$= $3.make_item_func_trim_oracle(thd))))
10345              MYSQL_YYABORT;
10346          }
10347        | UTC_DATE_SYM optional_braces
10348          {
10349            $$= new (thd->mem_root) Item_func_curdate_utc(thd);
10350            if (unlikely($$ == NULL))
10351              MYSQL_YYABORT;
10352            Lex->safe_to_cache_query=0;
10353          }
10354        | UTC_TIME_SYM opt_time_precision
10355          {
10356            $$= new (thd->mem_root) Item_func_curtime_utc(thd, $2);
10357            if (unlikely($$ == NULL))
10358              MYSQL_YYABORT;
10359            Lex->safe_to_cache_query=0;
10360          }
10361        | UTC_TIMESTAMP_SYM opt_time_precision
10362          {
10363            $$= new (thd->mem_root) Item_func_now_utc(thd, $2);
10364            if (unlikely($$ == NULL))
10365              MYSQL_YYABORT;
10366            Lex->safe_to_cache_query=0;
10367          }
10368        |
10369          COLUMN_ADD_SYM '(' expr ',' dyncall_create_list ')'
10370          {
10371            $$= create_func_dyncol_add(thd, $3, *$5);
10372            if (unlikely($$ == NULL))
10373              MYSQL_YYABORT;
10374          }
10375        |
10376          COLUMN_DELETE_SYM '(' expr ',' expr_list ')'
10377          {
10378            $$= create_func_dyncol_delete(thd, $3, *$5);
10379            if (unlikely($$ == NULL))
10380              MYSQL_YYABORT;
10381          }
10382        |
10383          COLUMN_CHECK_SYM '(' expr ')'
10384          {
10385            $$= new (thd->mem_root) Item_func_dyncol_check(thd, $3);
10386            if (unlikely($$ == NULL))
10387              MYSQL_YYABORT;
10388          }
10389        |
10390          COLUMN_CREATE_SYM '(' dyncall_create_list ')'
10391          {
10392            $$= create_func_dyncol_create(thd, *$3);
10393            if (unlikely($$ == NULL))
10394              MYSQL_YYABORT;
10395          }
10396        |
10397          COLUMN_GET_SYM '(' expr ',' expr AS cast_type ')'
10398          {
10399            LEX *lex= Lex;
10400            $$= create_func_dyncol_get(thd, $3, $5, $7.type_handler(),
10401                                        $7.length(), $7.dec(),
10402                                        lex->charset);
10403            if (unlikely($$ == NULL))
10404              MYSQL_YYABORT;
10405          }
10406        ;
10407
10408/*
10409  Functions calls using a non reserved keyword, and using a regular syntax.
10410  Because the non reserved keyword is used in another part of the grammar,
10411  a dedicated rule is needed here.
10412*/
10413function_call_conflict:
10414          ASCII_SYM '(' expr ')'
10415          {
10416            $$= new (thd->mem_root) Item_func_ascii(thd, $3);
10417            if (unlikely($$ == NULL))
10418              MYSQL_YYABORT;
10419          }
10420        | CHARSET '(' expr ')'
10421          {
10422            $$= new (thd->mem_root) Item_func_charset(thd, $3);
10423            if (unlikely($$ == NULL))
10424              MYSQL_YYABORT;
10425          }
10426        | COALESCE '(' expr_list ')'
10427          {
10428            $$= new (thd->mem_root) Item_func_coalesce(thd, *$3);
10429            if (unlikely($$ == NULL))
10430              MYSQL_YYABORT;
10431          }
10432        | COLLATION_SYM '(' expr ')'
10433          {
10434            $$= new (thd->mem_root) Item_func_collation(thd, $3);
10435            if (unlikely($$ == NULL))
10436              MYSQL_YYABORT;
10437          }
10438        | DATABASE '(' ')'
10439          {
10440            $$= new (thd->mem_root) Item_func_database(thd);
10441            if (unlikely($$ == NULL))
10442              MYSQL_YYABORT;
10443            Lex->safe_to_cache_query=0;
10444          }
10445        | IF_SYM '(' expr ',' expr ',' expr ')'
10446          {
10447            $$= new (thd->mem_root) Item_func_if(thd, $3, $5, $7);
10448            if (unlikely($$ == NULL))
10449              MYSQL_YYABORT;
10450          }
10451        | FORMAT_SYM '(' expr ',' expr ')'
10452          {
10453            $$= new (thd->mem_root) Item_func_format(thd, $3, $5);
10454            if (unlikely($$ == NULL))
10455              MYSQL_YYABORT;
10456          }
10457        | FORMAT_SYM '(' expr ',' expr ',' expr ')'
10458          {
10459            $$= new (thd->mem_root) Item_func_format(thd, $3, $5, $7);
10460            if (unlikely($$ == NULL))
10461              MYSQL_YYABORT;
10462          }
10463          /* LAST_VALUE here conflicts with the definition for window functions.
10464             We have these 2 separate rules to remove the shift/reduce conflict.
10465          */
10466        | LAST_VALUE '(' expr ')'
10467          {
10468            List<Item> *list= new (thd->mem_root) List<Item>;
10469            if (unlikely(list == NULL))
10470              MYSQL_YYABORT;
10471            list->push_back($3, thd->mem_root);
10472
10473            $$= new (thd->mem_root) Item_func_last_value(thd, *list);
10474            if (unlikely($$ == NULL))
10475              MYSQL_YYABORT;
10476          }
10477        | LAST_VALUE '(' expr_list ',' expr ')'
10478          {
10479            $3->push_back($5, thd->mem_root);
10480            $$= new (thd->mem_root) Item_func_last_value(thd, *$3);
10481            if (unlikely($$ == NULL))
10482              MYSQL_YYABORT;
10483          }
10484        | MICROSECOND_SYM '(' expr ')'
10485          {
10486            $$= new (thd->mem_root) Item_func_microsecond(thd, $3);
10487            if (unlikely($$ == NULL))
10488              MYSQL_YYABORT;
10489          }
10490        | MOD_SYM '(' expr ',' expr ')'
10491          {
10492            $$= new (thd->mem_root) Item_func_mod(thd, $3, $5);
10493            if (unlikely($$ == NULL))
10494              MYSQL_YYABORT;
10495          }
10496        | OLD_PASSWORD_SYM '(' expr ')'
10497          {
10498            $$=  new (thd->mem_root)
10499              Item_func_password(thd, $3, Item_func_password::OLD);
10500            if (unlikely($$ == NULL))
10501              MYSQL_YYABORT;
10502          }
10503        | PASSWORD_SYM '(' expr ')'
10504          {
10505            Item* i1;
10506            i1= new (thd->mem_root) Item_func_password(thd, $3);
10507            if (unlikely(i1 == NULL))
10508              MYSQL_YYABORT;
10509            $$= i1;
10510          }
10511        | QUARTER_SYM '(' expr ')'
10512          {
10513            $$= new (thd->mem_root) Item_func_quarter(thd, $3);
10514            if (unlikely($$ == NULL))
10515              MYSQL_YYABORT;
10516          }
10517        | REPEAT_SYM '(' expr ',' expr ')'
10518          {
10519            $$= new (thd->mem_root) Item_func_repeat(thd, $3, $5);
10520            if (unlikely($$ == NULL))
10521              MYSQL_YYABORT;
10522          }
10523        | REPLACE '(' expr ',' expr ',' expr ')'
10524          {
10525            if (unlikely(!($$= Lex->make_item_func_replace(thd, $3, $5, $7))))
10526              MYSQL_YYABORT;
10527          }
10528        | REVERSE_SYM '(' expr ')'
10529          {
10530            $$= new (thd->mem_root) Item_func_reverse(thd, $3);
10531            if (unlikely($$ == NULL))
10532              MYSQL_YYABORT;
10533          }
10534        | ROW_COUNT_SYM '(' ')'
10535          {
10536            $$= new (thd->mem_root) Item_func_row_count(thd);
10537            if (unlikely($$ == NULL))
10538              MYSQL_YYABORT;
10539            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10540            Lex->safe_to_cache_query= 0;
10541          }
10542        | TRUNCATE_SYM '(' expr ',' expr ')'
10543          {
10544            $$= new (thd->mem_root) Item_func_round(thd, $3, $5, 1);
10545            if (unlikely($$ == NULL))
10546              MYSQL_YYABORT;
10547          }
10548        | WEEK_SYM '(' expr ')'
10549          {
10550            $$= new (thd->mem_root) Item_func_week(thd, $3);
10551            if (unlikely($$ == NULL))
10552              MYSQL_YYABORT;
10553          }
10554        | WEEK_SYM '(' expr ',' expr ')'
10555          {
10556            $$= new (thd->mem_root) Item_func_week(thd, $3, $5);
10557            if (unlikely($$ == NULL))
10558              MYSQL_YYABORT;
10559          }
10560        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
10561          {
10562            $$= new (thd->mem_root) Item_func_weight_string(thd, $3, 0, 0, $4);
10563            if (unlikely($$ == NULL))
10564              MYSQL_YYABORT;
10565          }
10566        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
10567          {
10568            $$= new (thd->mem_root)
10569                Item_func_weight_string(thd, $3, 0, $6,
10570                                        $7 | MY_STRXFRM_PAD_WITH_SPACE);
10571            if (unlikely($$ == NULL))
10572              MYSQL_YYABORT;
10573          }
10574        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
10575          {
10576            Item *item= new (thd->mem_root) Item_char_typecast(thd, $3, $6,
10577                                                               &my_charset_bin);
10578            if (unlikely(item == NULL))
10579              MYSQL_YYABORT;
10580            $$= new (thd->mem_root)
10581                Item_func_weight_string(thd, item, 0, $6,
10582                                        MY_STRXFRM_PAD_WITH_SPACE);
10583            if (unlikely($$ == NULL))
10584              MYSQL_YYABORT;
10585          }
10586        | WEIGHT_STRING_SYM '(' expr ',' ulong_num ',' ulong_num ',' ulong_num ')'
10587          {
10588            $$= new (thd->mem_root) Item_func_weight_string(thd, $3, $5, $7,
10589                                                            $9);
10590            if (unlikely($$ == NULL))
10591              MYSQL_YYABORT;
10592          }
10593        ;
10594
10595/*
10596  Regular function calls.
10597  The function name is *not* a token, and therefore is guaranteed to not
10598  introduce side effects to the language in general.
10599  MAINTAINER:
10600  All the new functions implemented for new features should fit into
10601  this category. The place to implement the function itself is
10602  in sql/item_create.cc
10603*/
10604function_call_generic:
10605          IDENT_sys '('
10606          {
10607#ifdef HAVE_DLOPEN
10608            udf_func *udf= 0;
10609            LEX *lex= Lex;
10610            if (using_udf_functions &&
10611                (udf= find_udf($1.str, $1.length)) &&
10612                udf->type == UDFTYPE_AGGREGATE)
10613            {
10614              if (unlikely(lex->current_select->inc_in_sum_expr()))
10615              {
10616                thd->parse_error();
10617                MYSQL_YYABORT;
10618              }
10619            }
10620            /* Temporary placing the result of find_udf in $3 */
10621            $<udf>$= udf;
10622#endif
10623          }
10624          opt_udf_expr_list ')'
10625          {
10626            const Type_handler *h;
10627            Create_func *builder;
10628            Item *item= NULL;
10629
10630            if (unlikely(check_routine_name(&$1)))
10631              MYSQL_YYABORT;
10632
10633            /*
10634              Implementation note:
10635              names are resolved with the following order:
10636              - MySQL native functions,
10637              - User Defined Functions,
10638              - Constructors, like POINT(1,1)
10639              - Stored Functions (assuming the current <use> database)
10640
10641              This will be revised with WL#2128 (SQL PATH)
10642            */
10643            if ((builder= find_native_function_builder(thd, &$1)))
10644            {
10645              item= builder->create_func(thd, &$1, $4);
10646            }
10647            else if ((h= Type_handler::handler_by_name(thd, $1)) &&
10648                     (item= h->make_constructor_item(thd, $4)))
10649            {
10650              // Found a constructor with a proper argument count
10651            }
10652            else
10653            {
10654#ifdef HAVE_DLOPEN
10655              /* Retrieving the result of find_udf */
10656              udf_func *udf= $<udf>3;
10657
10658              if (udf)
10659              {
10660                if (udf->type == UDFTYPE_AGGREGATE)
10661                {
10662                  Select->in_sum_expr--;
10663                }
10664
10665                item= Create_udf_func::s_singleton.create(thd, udf, $4);
10666              }
10667              else
10668#endif
10669              {
10670                builder= find_qualified_function_builder(thd);
10671                DBUG_ASSERT(builder);
10672                item= builder->create_func(thd, &$1, $4);
10673              }
10674            }
10675
10676            if (unlikely(! ($$= item)))
10677              MYSQL_YYABORT;
10678          }
10679        | CONTAINS_SYM '(' opt_expr_list ')'
10680          {
10681            if (!($$= Lex->make_item_func_call_native_or_parse_error(thd,
10682                                                                     $1, $3)))
10683              MYSQL_YYABORT;
10684          }
10685        | OVERLAPS_SYM '(' opt_expr_list ')'
10686          {
10687            if (!($$= Lex->make_item_func_call_native_or_parse_error(thd,
10688                                                                     $1, $3)))
10689              MYSQL_YYABORT;
10690          }
10691        | WITHIN '(' opt_expr_list ')'
10692          {
10693            if (!($$= Lex->make_item_func_call_native_or_parse_error(thd,
10694                                                                     $1, $3)))
10695              MYSQL_YYABORT;
10696          }
10697        | ident_cli '.' ident_cli '(' opt_expr_list ')'
10698          {
10699            if (unlikely(!($$= Lex->make_item_func_call_generic(thd, &$1, &$3, $5))))
10700              MYSQL_YYABORT;
10701          }
10702        ;
10703
10704fulltext_options:
10705          opt_natural_language_mode opt_query_expansion
10706          { $$= $1 | $2; }
10707        | IN_SYM BOOLEAN_SYM MODE_SYM
10708          { $$= FT_BOOL; }
10709        ;
10710
10711opt_natural_language_mode:
10712          /* nothing */                         { $$= FT_NL; }
10713        | IN_SYM NATURAL LANGUAGE_SYM MODE_SYM  { $$= FT_NL; }
10714        ;
10715
10716opt_query_expansion:
10717          /* nothing */                         { $$= 0;         }
10718        | WITH QUERY_SYM EXPANSION_SYM          { $$= FT_EXPAND; }
10719        ;
10720
10721opt_udf_expr_list:
10722        /* empty */     { $$= NULL; }
10723        | udf_expr_list { $$= $1; }
10724        ;
10725
10726udf_expr_list:
10727          udf_expr
10728          {
10729            $$= new (thd->mem_root) List<Item>;
10730            if (unlikely($$ == NULL))
10731              MYSQL_YYABORT;
10732            $$->push_back($1, thd->mem_root);
10733          }
10734        | udf_expr_list ',' udf_expr
10735          {
10736            $1->push_back($3, thd->mem_root);
10737            $$= $1;
10738          }
10739        ;
10740
10741udf_expr:
10742          remember_name expr remember_end select_alias
10743          {
10744            /*
10745             Use Item::name as a storage for the attribute value of user
10746             defined function argument. It is safe to use Item::name
10747             because the syntax will not allow having an explicit name here.
10748             See WL#1017 re. udf attributes.
10749            */
10750            if ($4.str)
10751            {
10752              $2->common_flags&= ~IS_AUTO_GENERATED_NAME;
10753              $2->set_name(thd, $4);
10754            }
10755            /*
10756               A field has to have its proper name in order for name
10757               resolution to work, something we are only guaranteed if we
10758               parse it out. If we hijack the input stream with
10759               remember_name we may get quoted or escaped names.
10760            */
10761            else if ($2->type() != Item::FIELD_ITEM &&
10762                     $2->type() != Item::REF_ITEM /* For HAVING */ )
10763              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
10764            $$= $2;
10765          }
10766        ;
10767
10768sum_expr:
10769          AVG_SYM '(' in_sum_expr ')'
10770          {
10771            $$= new (thd->mem_root) Item_sum_avg(thd, $3, FALSE);
10772            if (unlikely($$ == NULL))
10773              MYSQL_YYABORT;
10774          }
10775        | AVG_SYM '(' DISTINCT in_sum_expr ')'
10776          {
10777            $$= new (thd->mem_root) Item_sum_avg(thd, $4, TRUE);
10778            if (unlikely($$ == NULL))
10779              MYSQL_YYABORT;
10780          }
10781        | BIT_AND  '(' in_sum_expr ')'
10782          {
10783            $$= new (thd->mem_root) Item_sum_and(thd, $3);
10784            if (unlikely($$ == NULL))
10785              MYSQL_YYABORT;
10786          }
10787        | BIT_OR  '(' in_sum_expr ')'
10788          {
10789            $$= new (thd->mem_root) Item_sum_or(thd, $3);
10790            if (unlikely($$ == NULL))
10791              MYSQL_YYABORT;
10792          }
10793        | BIT_XOR  '(' in_sum_expr ')'
10794          {
10795            $$= new (thd->mem_root) Item_sum_xor(thd, $3);
10796            if (unlikely($$ == NULL))
10797              MYSQL_YYABORT;
10798          }
10799        | COUNT_SYM '(' opt_all '*' ')'
10800          {
10801            Item *item= new (thd->mem_root) Item_int(thd, (int32) 0L, 1);
10802            if (unlikely(item == NULL))
10803              MYSQL_YYABORT;
10804            $$= new (thd->mem_root) Item_sum_count(thd, item);
10805            if (unlikely($$ == NULL))
10806              MYSQL_YYABORT;
10807          }
10808        | COUNT_SYM '(' in_sum_expr ')'
10809          {
10810            $$= new (thd->mem_root) Item_sum_count(thd, $3);
10811            if (unlikely($$ == NULL))
10812              MYSQL_YYABORT;
10813          }
10814        | COUNT_SYM '(' DISTINCT
10815          { Select->in_sum_expr++; }
10816          expr_list
10817          { Select->in_sum_expr--; }
10818          ')'
10819          {
10820            $$= new (thd->mem_root) Item_sum_count(thd, *$5);
10821            if (unlikely($$ == NULL))
10822              MYSQL_YYABORT;
10823          }
10824        | MIN_SYM '(' in_sum_expr ')'
10825          {
10826            $$= new (thd->mem_root) Item_sum_min(thd, $3);
10827            if (unlikely($$ == NULL))
10828              MYSQL_YYABORT;
10829          }
10830        /*
10831          According to ANSI SQL, DISTINCT is allowed and has
10832          no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
10833          is processed like an ordinary MIN | MAX()
10834        */
10835        | MIN_SYM '(' DISTINCT in_sum_expr ')'
10836          {
10837            $$= new (thd->mem_root) Item_sum_min(thd, $4);
10838            if (unlikely($$ == NULL))
10839              MYSQL_YYABORT;
10840          }
10841        | MAX_SYM '(' in_sum_expr ')'
10842          {
10843            $$= new (thd->mem_root) Item_sum_max(thd, $3);
10844            if (unlikely($$ == NULL))
10845              MYSQL_YYABORT;
10846          }
10847        | MAX_SYM '(' DISTINCT in_sum_expr ')'
10848          {
10849            $$= new (thd->mem_root) Item_sum_max(thd, $4);
10850            if (unlikely($$ == NULL))
10851              MYSQL_YYABORT;
10852          }
10853        | STD_SYM '(' in_sum_expr ')'
10854          {
10855            $$= new (thd->mem_root) Item_sum_std(thd, $3, 0);
10856            if (unlikely($$ == NULL))
10857              MYSQL_YYABORT;
10858          }
10859        | VARIANCE_SYM '(' in_sum_expr ')'
10860          {
10861            $$= new (thd->mem_root) Item_sum_variance(thd, $3, 0);
10862            if (unlikely($$ == NULL))
10863              MYSQL_YYABORT;
10864          }
10865        | STDDEV_SAMP_SYM '(' in_sum_expr ')'
10866          {
10867            $$= new (thd->mem_root) Item_sum_std(thd, $3, 1);
10868            if (unlikely($$ == NULL))
10869              MYSQL_YYABORT;
10870          }
10871        | VAR_SAMP_SYM '(' in_sum_expr ')'
10872          {
10873            $$= new (thd->mem_root) Item_sum_variance(thd, $3, 1);
10874            if (unlikely($$ == NULL))
10875              MYSQL_YYABORT;
10876          }
10877        | SUM_SYM '(' in_sum_expr ')'
10878          {
10879            $$= new (thd->mem_root) Item_sum_sum(thd, $3, FALSE);
10880            if (unlikely($$ == NULL))
10881              MYSQL_YYABORT;
10882          }
10883        | SUM_SYM '(' DISTINCT in_sum_expr ')'
10884          {
10885            $$= new (thd->mem_root) Item_sum_sum(thd, $4, TRUE);
10886            if (unlikely($$ == NULL))
10887              MYSQL_YYABORT;
10888          }
10889        | GROUP_CONCAT_SYM '(' opt_distinct
10890          { Select->in_sum_expr++; }
10891          expr_list opt_gorder_clause
10892          opt_gconcat_separator opt_glimit_clause
10893          ')'
10894          {
10895            SELECT_LEX *sel= Select;
10896            sel->in_sum_expr--;
10897            $$= new (thd->mem_root)
10898                  Item_func_group_concat(thd, Lex->current_context(),
10899                                        $3, $5,
10900                                        sel->gorder_list, $7, $8,
10901                                        sel->select_limit,
10902                                        sel->offset_limit);
10903            if (unlikely($$ == NULL))
10904              MYSQL_YYABORT;
10905            sel->select_limit= NULL;
10906            sel->offset_limit= NULL;
10907            sel->explicit_limit= 0;
10908            $5->empty();
10909            sel->gorder_list.empty();
10910          }
10911        | JSON_ARRAYAGG_SYM '(' opt_distinct
10912          { Select->in_sum_expr++; }
10913          expr_list opt_gorder_clause opt_glimit_clause
10914          ')'
10915          {
10916            SELECT_LEX *sel= Select;
10917            List<Item> *args= $5;
10918            sel->in_sum_expr--;
10919            if (args && args->elements > 1)
10920            {
10921              /* JSON_ARRAYAGG supports only one parameter */
10922              my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), "JSON_ARRAYAGG");
10923              MYSQL_YYABORT;
10924            }
10925            String* s= new (thd->mem_root) String(",", 1, &my_charset_latin1);
10926            if (unlikely(s == NULL))
10927              MYSQL_YYABORT;
10928
10929            $$= new (thd->mem_root)
10930                  Item_func_json_arrayagg(thd, Lex->current_context(),
10931                                          $3, args,
10932                                          sel->gorder_list, s, $7,
10933                                          sel->select_limit,
10934                                          sel->offset_limit);
10935            if (unlikely($$ == NULL))
10936              MYSQL_YYABORT;
10937            sel->select_limit= NULL;
10938            sel->offset_limit= NULL;
10939            sel->explicit_limit= 0;
10940            $5->empty();
10941            sel->gorder_list.empty();
10942          }
10943        | JSON_OBJECTAGG_SYM '('
10944          { Select->in_sum_expr++; }
10945          expr ',' expr ')'
10946          {
10947            SELECT_LEX *sel= Select;
10948            sel->in_sum_expr--;
10949
10950            $$= new (thd->mem_root) Item_func_json_objectagg(thd, $4, $6);
10951            if (unlikely($$ == NULL))
10952              MYSQL_YYABORT;
10953          }
10954        ;
10955
10956window_func_expr:
10957          window_func OVER_SYM window_name
10958          {
10959            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1, $3);
10960            if (unlikely($$ == NULL))
10961              MYSQL_YYABORT;
10962            if (unlikely(Select->add_window_func((Item_window_func *) $$)))
10963              MYSQL_YYABORT;
10964          }
10965        |
10966          window_func OVER_SYM window_spec
10967          {
10968            LEX *lex= Lex;
10969            if (unlikely(Select->add_window_spec(thd, lex->win_ref,
10970                                                 Select->group_list,
10971                                                 Select->order_list,
10972                                                 lex->win_frame)))
10973              MYSQL_YYABORT;
10974            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1,
10975                                                      thd->lex->win_spec);
10976            if (unlikely($$ == NULL))
10977              MYSQL_YYABORT;
10978            if (unlikely(Select->add_window_func((Item_window_func *) $$)))
10979              MYSQL_YYABORT;
10980          }
10981        ;
10982
10983window_func:
10984          simple_window_func
10985        |
10986          sum_expr
10987        |
10988          function_call_generic
10989          {
10990            Item* item = (Item*)$1;
10991            /* Only UDF aggregate here possible */
10992            if ((item == NULL) ||
10993                (item->type() != Item::SUM_FUNC_ITEM)
10994                || (((Item_sum *)item)->sum_func() != Item_sum::UDF_SUM_FUNC))
10995            {
10996              thd->parse_error();
10997              MYSQL_YYABORT;
10998            }
10999          }
11000        ;
11001
11002simple_window_func:
11003          ROW_NUMBER_SYM '(' ')'
11004          {
11005            $$= new (thd->mem_root) Item_sum_row_number(thd);
11006            if (unlikely($$ == NULL))
11007              MYSQL_YYABORT;
11008          }
11009        |
11010          RANK_SYM '(' ')'
11011          {
11012            $$= new (thd->mem_root) Item_sum_rank(thd);
11013            if (unlikely($$ == NULL))
11014              MYSQL_YYABORT;
11015          }
11016        |
11017          DENSE_RANK_SYM '(' ')'
11018          {
11019            $$= new (thd->mem_root) Item_sum_dense_rank(thd);
11020            if (unlikely($$ == NULL))
11021              MYSQL_YYABORT;
11022          }
11023        |
11024          PERCENT_RANK_SYM '(' ')'
11025          {
11026            $$= new (thd->mem_root) Item_sum_percent_rank(thd);
11027            if (unlikely($$ == NULL))
11028              MYSQL_YYABORT;
11029          }
11030        |
11031          CUME_DIST_SYM '(' ')'
11032          {
11033            $$= new (thd->mem_root) Item_sum_cume_dist(thd);
11034            if (unlikely($$ == NULL))
11035              MYSQL_YYABORT;
11036          }
11037        |
11038          NTILE_SYM '(' expr ')'
11039          {
11040            $$= new (thd->mem_root) Item_sum_ntile(thd, $3);
11041            if (unlikely($$ == NULL))
11042              MYSQL_YYABORT;
11043          }
11044        |
11045          FIRST_VALUE_SYM '(' expr ')'
11046          {
11047            $$= new (thd->mem_root) Item_sum_first_value(thd, $3);
11048            if (unlikely($$ == NULL))
11049              MYSQL_YYABORT;
11050          }
11051        |
11052          LAST_VALUE '(' expr ')'
11053          {
11054            $$= new (thd->mem_root) Item_sum_last_value(thd, $3);
11055            if (unlikely($$ == NULL))
11056              MYSQL_YYABORT;
11057          }
11058        |
11059          NTH_VALUE_SYM '(' expr ',' expr ')'
11060          {
11061            $$= new (thd->mem_root) Item_sum_nth_value(thd, $3, $5);
11062            if (unlikely($$ == NULL))
11063              MYSQL_YYABORT;
11064          }
11065        |
11066          LEAD_SYM '(' expr ')'
11067          {
11068            /* No second argument defaults to 1. */
11069            Item* item_offset= new (thd->mem_root) Item_uint(thd, 1);
11070            if (unlikely(item_offset == NULL))
11071              MYSQL_YYABORT;
11072            $$= new (thd->mem_root) Item_sum_lead(thd, $3, item_offset);
11073            if (unlikely($$ == NULL))
11074              MYSQL_YYABORT;
11075          }
11076        |
11077          LEAD_SYM '(' expr ',' expr ')'
11078          {
11079            $$= new (thd->mem_root) Item_sum_lead(thd, $3, $5);
11080            if (unlikely($$ == NULL))
11081              MYSQL_YYABORT;
11082          }
11083        |
11084          LAG_SYM '(' expr ')'
11085          {
11086            /* No second argument defaults to 1. */
11087            Item* item_offset= new (thd->mem_root) Item_uint(thd, 1);
11088            if (unlikely(item_offset == NULL))
11089              MYSQL_YYABORT;
11090            $$= new (thd->mem_root) Item_sum_lag(thd, $3, item_offset);
11091            if (unlikely($$ == NULL))
11092              MYSQL_YYABORT;
11093          }
11094        |
11095          LAG_SYM '(' expr ',' expr ')'
11096          {
11097            $$= new (thd->mem_root) Item_sum_lag(thd, $3, $5);
11098            if (unlikely($$ == NULL))
11099              MYSQL_YYABORT;
11100          }
11101        ;
11102
11103
11104
11105inverse_distribution_function:
11106          percentile_function OVER_SYM
11107          '(' opt_window_partition_clause ')'
11108          {
11109            LEX *lex= Lex;
11110            if (unlikely(Select->add_window_spec(thd, lex->win_ref,
11111                                                 Select->group_list,
11112                                                 Select->order_list,
11113                                                 NULL)))
11114              MYSQL_YYABORT;
11115            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1,
11116                                                     thd->lex->win_spec);
11117            if (unlikely($$ == NULL))
11118              MYSQL_YYABORT;
11119            if (unlikely(Select->add_window_func((Item_window_func *) $$)))
11120              MYSQL_YYABORT;
11121          }
11122        ;
11123
11124percentile_function:
11125          inverse_distribution_function_def  WITHIN GROUP_SYM '('
11126           { Select->prepare_add_window_spec(thd); }
11127           order_by_single_element_list ')'
11128           {
11129             $$= $1;
11130           }
11131        | MEDIAN_SYM '(' expr ')'
11132          {
11133            Item *args= new (thd->mem_root) Item_decimal(thd, "0.5", 3,
11134                                                   thd->charset());
11135            if (unlikely(args == NULL) || unlikely(thd->is_error()))
11136              MYSQL_YYABORT;
11137            Select->prepare_add_window_spec(thd);
11138            if (unlikely(add_order_to_list(thd, $3,FALSE)))
11139              MYSQL_YYABORT;
11140
11141            $$= new (thd->mem_root) Item_sum_percentile_cont(thd, args);
11142            if (unlikely($$ == NULL))
11143              MYSQL_YYABORT;
11144          }
11145        ;
11146
11147inverse_distribution_function_def:
11148          PERCENTILE_CONT_SYM '(' expr ')'
11149          {
11150            $$= new (thd->mem_root) Item_sum_percentile_cont(thd, $3);
11151            if (unlikely($$ == NULL))
11152              MYSQL_YYABORT;
11153          }
11154        |  PERCENTILE_DISC_SYM '(' expr ')'
11155          {
11156            $$= new (thd->mem_root) Item_sum_percentile_disc(thd, $3);
11157            if (unlikely($$ == NULL))
11158              MYSQL_YYABORT;
11159          }
11160        ;
11161
11162order_by_single_element_list:
11163          ORDER_SYM BY order_ident order_dir
11164          {
11165            if (unlikely(add_order_to_list(thd, $3,(bool) $4)))
11166              MYSQL_YYABORT;
11167          }
11168        ;
11169
11170
11171window_name:
11172          ident
11173          {
11174            $$= (LEX_CSTRING *) thd->memdup(&$1, sizeof(LEX_CSTRING));
11175            if (unlikely($$ == NULL))
11176              MYSQL_YYABORT;
11177          }
11178        ;
11179
11180variable:
11181          '@'
11182          {
11183            if (unlikely(! Lex->parsing_options.allows_variable))
11184              my_yyabort_error((ER_VIEW_SELECT_VARIABLE, MYF(0)));
11185          }
11186          variable_aux
11187          {
11188            $$= $3;
11189          }
11190        ;
11191
11192variable_aux:
11193          ident_or_text SET_VAR expr
11194          {
11195            Item_func_set_user_var *item;
11196            $$= item= new (thd->mem_root) Item_func_set_user_var(thd, &$1, $3);
11197            if (unlikely($$ == NULL))
11198              MYSQL_YYABORT;
11199            LEX *lex= Lex;
11200            lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
11201            lex->set_var_list.push_back(item, thd->mem_root);
11202          }
11203        | ident_or_text
11204          {
11205            $$= new (thd->mem_root) Item_func_get_user_var(thd, &$1);
11206            if (unlikely($$ == NULL))
11207              MYSQL_YYABORT;
11208            LEX *lex= Lex;
11209            lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
11210          }
11211        | '@' opt_var_ident_type ident_sysvar_name
11212          {
11213            if (unlikely(!($$= Lex->make_item_sysvar(thd, $2, &$3))))
11214              MYSQL_YYABORT;
11215          }
11216        | '@' opt_var_ident_type ident_sysvar_name '.' ident
11217          {
11218            if (unlikely(!($$= Lex->make_item_sysvar(thd, $2, &$3, &$5))))
11219              MYSQL_YYABORT;
11220          }
11221        ;
11222
11223opt_distinct:
11224          /* empty */ { $$ = 0; }
11225        | DISTINCT    { $$ = 1; }
11226        ;
11227
11228opt_gconcat_separator:
11229          /* empty */
11230          {
11231            $$= new (thd->mem_root) String(",", 1, &my_charset_latin1);
11232            if (unlikely($$ == NULL))
11233              MYSQL_YYABORT;
11234          }
11235        | SEPARATOR_SYM text_string { $$ = $2; }
11236        ;
11237
11238opt_gorder_clause:
11239          /* empty */
11240        | ORDER_SYM BY gorder_list
11241        ;
11242
11243gorder_list:
11244          gorder_list ',' order_ident order_dir
11245          {
11246            if (unlikely(add_gorder_to_list(thd, $3,(bool) $4)))
11247              MYSQL_YYABORT;
11248           }
11249        | order_ident order_dir
11250          {
11251            if (unlikely(add_gorder_to_list(thd, $1,(bool) $2)))
11252              MYSQL_YYABORT;
11253           }
11254        ;
11255
11256opt_glimit_clause:
11257          /* empty */ { $$ = 0; }
11258        | glimit_clause { $$ = 1; }
11259        ;
11260
11261glimit_clause_init:
11262          LIMIT{}
11263        ;
11264
11265glimit_clause:
11266          glimit_clause_init glimit_options
11267          {
11268            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
11269          }
11270        ;
11271
11272glimit_options:
11273          limit_option
11274          {
11275            SELECT_LEX *sel= Select;
11276            sel->select_limit= $1;
11277            sel->offset_limit= 0;
11278            sel->explicit_limit= 1;
11279          }
11280        | limit_option ',' limit_option
11281          {
11282            SELECT_LEX *sel= Select;
11283            sel->select_limit= $3;
11284            sel->offset_limit= $1;
11285            sel->explicit_limit= 1;
11286          }
11287        | limit_option OFFSET_SYM limit_option
11288          {
11289            SELECT_LEX *sel= Select;
11290            sel->select_limit= $1;
11291            sel->offset_limit= $3;
11292            sel->explicit_limit= 1;
11293          }
11294        ;
11295
11296
11297
11298in_sum_expr:
11299          opt_all
11300          {
11301            LEX *lex= Lex;
11302            if (unlikely(lex->current_select->inc_in_sum_expr()))
11303            {
11304              thd->parse_error();
11305              MYSQL_YYABORT;
11306            }
11307          }
11308          expr
11309          {
11310            Select->in_sum_expr--;
11311            $$= $3;
11312          }
11313        ;
11314
11315cast_type:
11316          BINARY opt_field_length
11317          { $$.set(&type_handler_long_blob, $2); Lex->charset= &my_charset_bin; }
11318        | CHAR_SYM opt_field_length
11319          { Lex->charset= thd->variables.collation_connection; }
11320          opt_binary
11321          { $$.set(&type_handler_long_blob, $2); }
11322        | VARCHAR field_length
11323          { Lex->charset= thd->variables.collation_connection; }
11324          opt_binary
11325          { $$.set(&type_handler_long_blob, $2); }
11326        | VARCHAR2_ORACLE_SYM field_length
11327          { Lex->charset= thd->variables.collation_connection; }
11328          opt_binary
11329          { $$.set(&type_handler_long_blob, $2); }
11330        | NCHAR_SYM opt_field_length
11331          {
11332            Lex->charset= national_charset_info;
11333            $$.set(&type_handler_long_blob, $2, 0);
11334          }
11335        | cast_type_numeric  { $$= $1; Lex->charset= NULL; }
11336        | cast_type_temporal { $$= $1; Lex->charset= NULL; }
11337        | IDENT_sys
11338          {
11339            if (Lex->set_cast_type_udt(&$$, $1))
11340              MYSQL_YYABORT;
11341          }
11342        | reserved_keyword_udt
11343          {
11344            if (Lex->set_cast_type_udt(&$$, $1))
11345              MYSQL_YYABORT;
11346          }
11347        | non_reserved_keyword_udt
11348          {
11349            if (Lex->set_cast_type_udt(&$$, $1))
11350              MYSQL_YYABORT;
11351          }
11352        ;
11353
11354cast_type_numeric:
11355          INT_SYM                        { $$.set(&type_handler_slonglong); }
11356        | SIGNED_SYM                     { $$.set(&type_handler_slonglong); }
11357        | SIGNED_SYM INT_SYM             { $$.set(&type_handler_slonglong); }
11358        | UNSIGNED                       { $$.set(&type_handler_ulonglong); }
11359        | UNSIGNED INT_SYM               { $$.set(&type_handler_ulonglong); }
11360        | DECIMAL_SYM float_options      { $$.set(&type_handler_newdecimal, $2); }
11361        | FLOAT_SYM                      { $$.set(&type_handler_float); }
11362        | DOUBLE_SYM opt_precision       { $$.set(&type_handler_double, $2);  }
11363        ;
11364
11365cast_type_temporal:
11366          DATE_SYM                       { $$.set(&type_handler_newdate); }
11367        | TIME_SYM opt_field_length      { $$.set(&type_handler_time2, 0, $2); }
11368        | DATETIME opt_field_length      { $$.set(&type_handler_datetime2, 0, $2); }
11369        | INTERVAL_SYM DAY_SECOND_SYM field_length
11370          {
11371            $$.set(&type_handler_interval_DDhhmmssff, 0, $3);
11372          }
11373        ;
11374
11375opt_expr_list:
11376          /* empty */ { $$= NULL; }
11377        | expr_list { $$= $1;}
11378        ;
11379
11380expr_list:
11381          expr
11382          {
11383            if (unlikely(!($$= List<Item>::make(thd->mem_root, $1))))
11384              MYSQL_YYABORT;
11385          }
11386        | expr_list ',' expr
11387          {
11388            $1->push_back($3, thd->mem_root);
11389            $$= $1;
11390          }
11391        ;
11392
11393ident_list_arg:
11394          ident_list          { $$= $1; }
11395        | '(' ident_list ')'  { $$= $2; }
11396        ;
11397
11398ident_list:
11399          simple_ident
11400          {
11401            $$= new (thd->mem_root) List<Item>;
11402            if (unlikely($$ == NULL) ||
11403                unlikely($$->push_back($1, thd->mem_root)))
11404              MYSQL_YYABORT;
11405          }
11406        | ident_list ',' simple_ident
11407          {
11408            $1->push_back($3, thd->mem_root);
11409            $$= $1;
11410          }
11411        ;
11412
11413when_list:
11414          WHEN_SYM expr THEN_SYM expr
11415          {
11416            $$= new (thd->mem_root) List<Item>;
11417            if (unlikely($$ == NULL))
11418              MYSQL_YYABORT;
11419            if (unlikely($$->push_back($2, thd->mem_root) ||
11420                         $$->push_back($4, thd->mem_root)))
11421              MYSQL_YYABORT;
11422          }
11423        | when_list WHEN_SYM expr THEN_SYM expr
11424          {
11425            if (unlikely($1->push_back($3, thd->mem_root) ||
11426                         $1->push_back($5, thd->mem_root)))
11427              MYSQL_YYABORT;
11428            $$= $1;
11429          }
11430        ;
11431
11432when_list_opt_else:
11433          when_list
11434        | when_list ELSE expr
11435          {
11436            if (unlikely($1->push_back($3, thd->mem_root)))
11437              MYSQL_YYABORT;
11438            $$= $1;
11439          }
11440        ;
11441
11442decode_when_list_oracle:
11443          expr ',' expr
11444          {
11445            $$= new (thd->mem_root) List<Item>;
11446            if (unlikely($$ == NULL) ||
11447                unlikely($$->push_back($1, thd->mem_root)) ||
11448                unlikely($$->push_back($3, thd->mem_root)))
11449              MYSQL_YYABORT;
11450
11451          }
11452        | decode_when_list_oracle ',' expr
11453          {
11454            $$= $1;
11455            if (unlikely($$->push_back($3, thd->mem_root)))
11456              MYSQL_YYABORT;
11457          }
11458        ;
11459
11460
11461/* Equivalent to <table reference> in the SQL:2003 standard. */
11462/* Warning - may return NULL in case of incomplete SELECT */
11463table_ref:
11464          table_factor     { $$= $1; }
11465        | join_table
11466          {
11467            LEX *lex= Lex;
11468            if (unlikely(!($$= lex->current_select->nest_last_join(thd))))
11469            {
11470              thd->parse_error();
11471              MYSQL_YYABORT;
11472            }
11473          }
11474        ;
11475
11476join_table_list:
11477          derived_table_list { MYSQL_YYABORT_UNLESS($$=$1); }
11478        ;
11479
11480/*
11481  The ODBC escape syntax for Outer Join is: '{' OJ join_table '}'
11482  The parser does not define OJ as a token, any ident is accepted
11483  instead in $2 (ident). Also, all productions from table_ref can
11484  be escaped, not only join_table. Both syntax extensions are safe
11485  and are ignored.
11486*/
11487esc_table_ref:
11488          table_ref { $$=$1; }
11489        | '{' ident table_ref '}' { $$=$3; }
11490        ;
11491
11492/* Equivalent to <table reference list> in the SQL:2003 standard. */
11493/* Warning - may return NULL in case of incomplete SELECT */
11494derived_table_list:
11495          esc_table_ref
11496          {
11497            $$=$1;
11498            Select->add_joined_table($1);
11499          }
11500        | derived_table_list ',' esc_table_ref
11501          {
11502            MYSQL_YYABORT_UNLESS($1 && ($$=$3));
11503            Select->add_joined_table($3);
11504          }
11505        ;
11506
11507/*
11508  Notice that JOIN can be a left-associative operator in one context and
11509  a right-associative operator in another context (see the comment for
11510  st_select_lex::add_cross_joined_table).
11511*/
11512join_table:
11513          /* INNER JOIN variants */
11514          table_ref normal_join table_ref %prec CONDITIONLESS_JOIN
11515          {
11516            MYSQL_YYABORT_UNLESS($1 && ($$=$3));
11517            if (unlikely(Select->add_cross_joined_table($1, $3, $2)))
11518              MYSQL_YYABORT;
11519          }
11520        | table_ref normal_join table_ref
11521          ON
11522          {
11523            MYSQL_YYABORT_UNLESS($1 && $3);
11524            Select->add_joined_table($1);
11525            Select->add_joined_table($3);
11526            /* Change the current name resolution context to a local context. */
11527            if (unlikely(push_new_name_resolution_context(thd, $1, $3)))
11528              MYSQL_YYABORT;
11529            Select->parsing_place= IN_ON;
11530          }
11531          expr
11532          {
11533            $3->straight=$2;
11534            add_join_on(thd, $3, $6);
11535            $3->on_context= Lex->pop_context();
11536            Select->parsing_place= NO_MATTER;
11537          }
11538        | table_ref normal_join table_ref
11539          USING
11540          {
11541            MYSQL_YYABORT_UNLESS($1 && $3);
11542            Select->add_joined_table($1);
11543            Select->add_joined_table($3);
11544          }
11545          '(' using_list ')'
11546          {
11547	    $3->straight=$2;
11548            add_join_natural($1,$3,$7,Select);
11549	    $$=$3;
11550          }
11551        | table_ref NATURAL inner_join table_factor
11552          {
11553            MYSQL_YYABORT_UNLESS($1 && ($$=$4));
11554            Select->add_joined_table($1);
11555            Select->add_joined_table($4);
11556	    $4->straight=$3;
11557            add_join_natural($1,$4,NULL,Select);
11558          }
11559
11560          /* LEFT JOIN variants */
11561        | table_ref LEFT opt_outer JOIN_SYM table_ref
11562          ON
11563          {
11564            MYSQL_YYABORT_UNLESS($1 && $5);
11565            Select->add_joined_table($1);
11566            Select->add_joined_table($5);
11567            /* Change the current name resolution context to a local context. */
11568            if (unlikely(push_new_name_resolution_context(thd, $1, $5)))
11569              MYSQL_YYABORT;
11570            Select->parsing_place= IN_ON;
11571          }
11572          expr
11573          {
11574            add_join_on(thd, $5, $8);
11575            $5->on_context= Lex->pop_context();
11576            $5->outer_join|=JOIN_TYPE_LEFT;
11577            $$=$5;
11578            Select->parsing_place= NO_MATTER;
11579          }
11580        | table_ref LEFT opt_outer JOIN_SYM table_factor
11581          {
11582            MYSQL_YYABORT_UNLESS($1 && $5);
11583            Select->add_joined_table($1);
11584            Select->add_joined_table($5);
11585          }
11586          USING '(' using_list ')'
11587          {
11588            add_join_natural($1,$5,$9,Select);
11589            $5->outer_join|=JOIN_TYPE_LEFT;
11590            $$=$5;
11591          }
11592        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
11593          {
11594            MYSQL_YYABORT_UNLESS($1 && $6);
11595            Select->add_joined_table($1);
11596            Select->add_joined_table($6);
11597            add_join_natural($1,$6,NULL,Select);
11598            $6->outer_join|=JOIN_TYPE_LEFT;
11599            $$=$6;
11600          }
11601
11602          /* RIGHT JOIN variants */
11603        | table_ref RIGHT opt_outer JOIN_SYM table_ref
11604          ON
11605          {
11606            MYSQL_YYABORT_UNLESS($1 && $5);
11607            Select->add_joined_table($1);
11608            Select->add_joined_table($5);
11609            /* Change the current name resolution context to a local context. */
11610            if (unlikely(push_new_name_resolution_context(thd, $1, $5)))
11611              MYSQL_YYABORT;
11612            Select->parsing_place= IN_ON;
11613          }
11614          expr
11615          {
11616            LEX *lex= Lex;
11617            if (unlikely(!($$= lex->current_select->convert_right_join())))
11618              MYSQL_YYABORT;
11619            add_join_on(thd, $$, $8);
11620            $1->on_context= Lex->pop_context();
11621            Select->parsing_place= NO_MATTER;
11622          }
11623        | table_ref RIGHT opt_outer JOIN_SYM table_factor
11624          {
11625            MYSQL_YYABORT_UNLESS($1 && $5);
11626            Select->add_joined_table($1);
11627            Select->add_joined_table($5);
11628          }
11629          USING '(' using_list ')'
11630          {
11631            LEX *lex= Lex;
11632            if (unlikely(!($$= lex->current_select->convert_right_join())))
11633              MYSQL_YYABORT;
11634            add_join_natural($$,$5,$9,Select);
11635          }
11636        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
11637          {
11638            MYSQL_YYABORT_UNLESS($1 && $6);
11639            Select->add_joined_table($1);
11640            Select->add_joined_table($6);
11641            add_join_natural($6,$1,NULL,Select);
11642            LEX *lex= Lex;
11643            if (unlikely(!($$= lex->current_select->convert_right_join())))
11644              MYSQL_YYABORT;
11645          }
11646        ;
11647
11648
11649inner_join: /* $$ set if using STRAIGHT_JOIN, false otherwise */
11650          JOIN_SYM           { $$ = 0; }
11651        | INNER_SYM JOIN_SYM { $$ = 0; }
11652        | STRAIGHT_JOIN      { $$ = 1; }
11653        ;
11654
11655normal_join:
11656          inner_join         { $$ = $1; }
11657        | CROSS JOIN_SYM     { $$ = 0; }
11658        ;
11659
11660/*
11661  table PARTITION (list of partitions), reusing using_list instead of creating
11662  a new rule for partition_list.
11663*/
11664opt_use_partition:
11665          /* empty */ { $$= 0;}
11666        | use_partition
11667        ;
11668
11669use_partition:
11670          PARTITION_SYM '(' using_list ')' have_partitioning
11671          {
11672            $$= $3;
11673            Select->parsing_place= Select->save_parsing_place;
11674            Select->save_parsing_place= NO_MATTER;
11675          }
11676        ;
11677
11678table_factor:
11679          table_primary_ident_opt_parens { $$= $1; }
11680        | table_primary_derived_opt_parens { $$= $1; }
11681        | join_table_parens
11682          {
11683            $1->nested_join->nest_type= 0;
11684            $$= $1;
11685          }
11686        | table_reference_list_parens { $$= $1; }
11687        ;
11688
11689table_primary_ident_opt_parens:
11690          table_primary_ident { $$= $1; }
11691        | '(' table_primary_ident_opt_parens ')' { $$= $2; }
11692        ;
11693
11694table_primary_derived_opt_parens:
11695          table_primary_derived { $$= $1; }
11696        | '(' table_primary_derived_opt_parens ')' { $$= $2; }
11697        ;
11698
11699table_reference_list_parens:
11700          '(' table_reference_list_parens ')' { $$= $2; }
11701        | '(' nested_table_reference_list ')'
11702          {
11703            if (!($$= Select->end_nested_join(thd)))
11704              MYSQL_YYABORT;
11705          }
11706        ;
11707
11708nested_table_reference_list:
11709          table_ref ',' table_ref
11710          {
11711            if (Select->init_nested_join(thd))
11712              MYSQL_YYABORT;
11713            Select->add_joined_table($1);
11714            Select->add_joined_table($3);
11715            $$= $1->embedding;
11716          }
11717        | nested_table_reference_list ',' table_ref
11718          {
11719            Select->add_joined_table($3);
11720            $$= $1;
11721          }
11722        ;
11723
11724join_table_parens:
11725          '(' join_table_parens ')' { $$= $2; }
11726        | '(' join_table ')'
11727          {
11728            LEX *lex= Lex;
11729            if (!($$= lex->current_select->nest_last_join(thd)))
11730            {
11731              thd->parse_error();
11732              MYSQL_YYABORT;
11733            }
11734          }
11735        ;
11736
11737
11738table_primary_ident:
11739          table_ident opt_use_partition opt_for_system_time_clause
11740          opt_table_alias_clause opt_key_definition
11741          {
11742            SELECT_LEX *sel= Select;
11743            sel->table_join_options= 0;
11744            if (!($$= Select->add_table_to_list(thd, $1, $4,
11745                                                Select->get_table_join_options(),
11746                                                YYPS->m_lock_type,
11747                                                YYPS->m_mdl_type,
11748                                                Select->pop_index_hints(),
11749                                                $2)))
11750              MYSQL_YYABORT;
11751            if ($3)
11752              $$->vers_conditions= Lex->vers_conditions;
11753          }
11754        ;
11755
11756table_primary_derived:
11757          subquery
11758          opt_for_system_time_clause table_alias_clause
11759          {
11760            if (!($$= Lex->parsed_derived_table($1->master_unit(), $2, $3)))
11761              MYSQL_YYABORT;
11762          }
11763        ;
11764
11765opt_outer:
11766          /* empty */ {}
11767        | OUTER {}
11768        ;
11769
11770index_hint_clause:
11771          /* empty */
11772          {
11773            $$= thd->variables.old_mode ?  INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL;
11774          }
11775        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
11776        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
11777        | FOR_SYM GROUP_SYM BY  { $$= INDEX_HINT_MASK_GROUP; }
11778        ;
11779
11780index_hint_type:
11781          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
11782        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
11783        ;
11784
11785index_hint_definition:
11786          index_hint_type key_or_index index_hint_clause
11787          {
11788            Select->set_index_hint_type($1, $3);
11789          }
11790          '(' key_usage_list ')'
11791        | USE_SYM key_or_index index_hint_clause
11792          {
11793            Select->set_index_hint_type(INDEX_HINT_USE, $3);
11794          }
11795          '(' opt_key_usage_list ')'
11796       ;
11797
11798index_hints_list:
11799          index_hint_definition
11800        | index_hints_list index_hint_definition
11801        ;
11802
11803opt_index_hints_list:
11804          /* empty */
11805        | { Select->alloc_index_hints(thd); } index_hints_list
11806        ;
11807
11808opt_key_definition:
11809          {  Select->clear_index_hints(); }
11810          opt_index_hints_list
11811        ;
11812
11813opt_key_usage_list:
11814          /* empty */ { Select->add_index_hint(thd, NULL, 0); }
11815        | key_usage_list {}
11816        ;
11817
11818key_usage_element:
11819          ident
11820          { Select->add_index_hint(thd, $1.str, $1.length); }
11821        | PRIMARY_SYM
11822          { Select->add_index_hint(thd, "PRIMARY", 7); }
11823        ;
11824
11825key_usage_list:
11826          key_usage_element
11827        | key_usage_list ',' key_usage_element
11828        ;
11829
11830using_list:
11831          ident
11832          {
11833            if (unlikely(!($$= new (thd->mem_root) List<String>)))
11834              MYSQL_YYABORT;
11835            String *s= new (thd->mem_root) String((const char *) $1.str,
11836                                                    $1.length,
11837                                                    system_charset_info);
11838            if (unlikely(unlikely(s == NULL)))
11839              MYSQL_YYABORT;
11840            $$->push_back(s, thd->mem_root);
11841          }
11842        | using_list ',' ident
11843          {
11844            String *s= new (thd->mem_root) String((const char *) $3.str,
11845                                                    $3.length,
11846                                                    system_charset_info);
11847            if (unlikely(unlikely(s == NULL)))
11848              MYSQL_YYABORT;
11849            if (unlikely($1->push_back(s, thd->mem_root)))
11850              MYSQL_YYABORT;
11851            $$= $1;
11852          }
11853        ;
11854
11855interval:
11856          interval_time_stamp    {}
11857        | DAY_HOUR_SYM           { $$=INTERVAL_DAY_HOUR; }
11858        | DAY_MICROSECOND_SYM    { $$=INTERVAL_DAY_MICROSECOND; }
11859        | DAY_MINUTE_SYM         { $$=INTERVAL_DAY_MINUTE; }
11860        | DAY_SECOND_SYM         { $$=INTERVAL_DAY_SECOND; }
11861        | HOUR_MICROSECOND_SYM   { $$=INTERVAL_HOUR_MICROSECOND; }
11862        | HOUR_MINUTE_SYM        { $$=INTERVAL_HOUR_MINUTE; }
11863        | HOUR_SECOND_SYM        { $$=INTERVAL_HOUR_SECOND; }
11864        | MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
11865        | MINUTE_SECOND_SYM      { $$=INTERVAL_MINUTE_SECOND; }
11866        | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
11867        | YEAR_MONTH_SYM         { $$=INTERVAL_YEAR_MONTH; }
11868        ;
11869
11870interval_time_stamp:
11871          DAY_SYM         { $$=INTERVAL_DAY; }
11872        | WEEK_SYM        { $$=INTERVAL_WEEK; }
11873        | HOUR_SYM        { $$=INTERVAL_HOUR; }
11874        | MINUTE_SYM      { $$=INTERVAL_MINUTE; }
11875        | MONTH_SYM       { $$=INTERVAL_MONTH; }
11876        | QUARTER_SYM     { $$=INTERVAL_QUARTER; }
11877        | SECOND_SYM      { $$=INTERVAL_SECOND; }
11878        | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
11879        | YEAR_SYM        { $$=INTERVAL_YEAR; }
11880        ;
11881
11882date_time_type:
11883          DATE_SYM  {$$=MYSQL_TIMESTAMP_DATE;}
11884        | TIME_SYM  {$$=MYSQL_TIMESTAMP_TIME;}
11885        | DATETIME  {$$=MYSQL_TIMESTAMP_DATETIME;}
11886        | TIMESTAMP {$$=MYSQL_TIMESTAMP_DATETIME;}
11887        ;
11888
11889table_alias:
11890          /* empty */
11891        | AS
11892        | '='
11893        ;
11894
11895opt_table_alias_clause:
11896          /* empty */ { $$=0; }
11897        | table_alias_clause { $$= $1; }
11898        ;
11899
11900table_alias_clause:
11901          table_alias ident_table_alias
11902          {
11903            $$= (LEX_CSTRING*) thd->memdup(&$2,sizeof(LEX_STRING));
11904            if (unlikely($$ == NULL))
11905              MYSQL_YYABORT;
11906          }
11907        ;
11908
11909opt_all:
11910          /* empty */
11911        | ALL
11912        ;
11913
11914opt_where_clause:
11915          /* empty */  { Select->where= 0; }
11916        | WHERE
11917          {
11918            Select->parsing_place= IN_WHERE;
11919          }
11920          expr
11921          {
11922            SELECT_LEX *select= Select;
11923            select->where= normalize_cond(thd, $3);
11924            select->parsing_place= NO_MATTER;
11925            if ($3)
11926              $3->top_level_item();
11927          }
11928        ;
11929
11930opt_having_clause:
11931          /* empty */
11932        | HAVING
11933          {
11934            Select->parsing_place= IN_HAVING;
11935          }
11936          expr
11937          {
11938            SELECT_LEX *sel= Select;
11939            sel->having= normalize_cond(thd, $3);
11940            sel->parsing_place= NO_MATTER;
11941            if ($3)
11942              $3->top_level_item();
11943          }
11944        ;
11945
11946/*
11947   group by statement in select
11948*/
11949
11950opt_group_clause:
11951          /* empty */
11952        | GROUP_SYM BY group_list olap_opt
11953        ;
11954
11955group_list:
11956          group_list ',' order_ident order_dir
11957          {
11958             if (unlikely(add_group_to_list(thd, $3,(bool) $4)))
11959               MYSQL_YYABORT;
11960           }
11961        | order_ident order_dir
11962          {
11963            if (unlikely(add_group_to_list(thd, $1,(bool) $2)))
11964              MYSQL_YYABORT;
11965           }
11966        ;
11967
11968olap_opt:
11969          /* empty */ {}
11970        | WITH_CUBE_SYM
11971          {
11972            /*
11973              'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
11974              and cause LALR(2) conflicts.
11975              This syntax is not standard.
11976              MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
11977              SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
11978            */
11979            LEX *lex=Lex;
11980            if (unlikely(lex->current_select->get_linkage() == GLOBAL_OPTIONS_TYPE))
11981              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "WITH CUBE",
11982                                "global union parameters"));
11983            lex->current_select->olap= CUBE_TYPE;
11984
11985            my_yyabort_error((ER_NOT_SUPPORTED_YET, MYF(0), "CUBE"));
11986          }
11987        | WITH_ROLLUP_SYM
11988          {
11989            /*
11990              'WITH ROLLUP' is needed for backward compatibility,
11991              and cause LALR(2) conflicts.
11992              This syntax is not standard.
11993              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
11994              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
11995            */
11996            LEX *lex= Lex;
11997            if (unlikely(lex->current_select->get_linkage() == GLOBAL_OPTIONS_TYPE))
11998              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
11999                                "global union parameters"));
12000            lex->current_select->olap= ROLLUP_TYPE;
12001          }
12002        ;
12003
12004/*
12005  optional window clause in select
12006*/
12007
12008opt_window_clause:
12009          /* empty */
12010          {}
12011        | WINDOW_SYM
12012          window_def_list
12013          {}
12014        ;
12015
12016window_def_list:
12017          window_def_list ',' window_def
12018        | window_def
12019        ;
12020
12021window_def:
12022          window_name AS window_spec
12023          {
12024            LEX *lex= Lex;
12025            if (unlikely(Select->add_window_def(thd, $1, lex->win_ref,
12026                                                Select->group_list,
12027                                                Select->order_list,
12028                                                lex->win_frame)))
12029              MYSQL_YYABORT;
12030          }
12031        ;
12032
12033window_spec:
12034          '('
12035          { Select->prepare_add_window_spec(thd); }
12036          opt_window_ref opt_window_partition_clause
12037          opt_window_order_clause opt_window_frame_clause
12038          ')'
12039          { }
12040        ;
12041
12042opt_window_ref:
12043          /* empty */ {}
12044        | ident
12045          {
12046            thd->lex->win_ref= (LEX_CSTRING *) thd->memdup(&$1, sizeof(LEX_CSTRING));
12047            if (unlikely(thd->lex->win_ref == NULL))
12048              MYSQL_YYABORT;
12049          }
12050        ;
12051
12052opt_window_partition_clause:
12053          /* empty */ { }
12054        | PARTITION_SYM BY group_list
12055        ;
12056
12057opt_window_order_clause:
12058          /* empty */ { }
12059        | ORDER_SYM BY order_list { Select->order_list= *($3); }
12060        ;
12061
12062opt_window_frame_clause:
12063          /* empty */ {}
12064        | window_frame_units window_frame_extent opt_window_frame_exclusion
12065          {
12066            LEX *lex= Lex;
12067            lex->win_frame=
12068              new (thd->mem_root) Window_frame($1,
12069                                               lex->frame_top_bound,
12070                                               lex->frame_bottom_bound,
12071                                               $3);
12072            if (unlikely(lex->win_frame == NULL))
12073              MYSQL_YYABORT;
12074          }
12075        ;
12076
12077window_frame_units:
12078          ROWS_SYM { $$= Window_frame::UNITS_ROWS; }
12079        | RANGE_SYM { $$= Window_frame::UNITS_RANGE; }
12080        ;
12081
12082window_frame_extent:
12083          window_frame_start
12084          {
12085            LEX *lex= Lex;
12086            lex->frame_top_bound= $1;
12087            lex->frame_bottom_bound=
12088              new (thd->mem_root)
12089                Window_frame_bound(Window_frame_bound::CURRENT, NULL);
12090            if (unlikely(lex->frame_bottom_bound == NULL))
12091              MYSQL_YYABORT;
12092          }
12093        | BETWEEN_SYM window_frame_bound AND_SYM window_frame_bound
12094          {
12095            LEX *lex= Lex;
12096            lex->frame_top_bound= $2;
12097            lex->frame_bottom_bound= $4;
12098          }
12099        ;
12100
12101window_frame_start:
12102          UNBOUNDED_SYM PRECEDING_SYM
12103          {
12104            $$= new (thd->mem_root)
12105                  Window_frame_bound(Window_frame_bound::PRECEDING, NULL);
12106            if (unlikely($$ == NULL))
12107              MYSQL_YYABORT;
12108          }
12109        | CURRENT_SYM ROW_SYM
12110          {
12111            $$= new (thd->mem_root)
12112                  Window_frame_bound(Window_frame_bound::CURRENT, NULL);
12113            if (unlikely($$ == NULL))
12114              MYSQL_YYABORT;
12115          }
12116        | literal PRECEDING_SYM
12117          {
12118            $$= new (thd->mem_root)
12119                  Window_frame_bound(Window_frame_bound::PRECEDING, $1);
12120            if (unlikely($$ == NULL))
12121              MYSQL_YYABORT;
12122          }
12123        ;
12124
12125window_frame_bound:
12126          window_frame_start { $$= $1; }
12127        | UNBOUNDED_SYM FOLLOWING_SYM
12128          {
12129            $$= new (thd->mem_root)
12130                  Window_frame_bound(Window_frame_bound::FOLLOWING, NULL);
12131            if (unlikely($$ == NULL))
12132              MYSQL_YYABORT;
12133          }
12134        | literal FOLLOWING_SYM
12135          {
12136            $$= new (thd->mem_root)
12137                  Window_frame_bound(Window_frame_bound::FOLLOWING, $1);
12138            if (unlikely($$ == NULL))
12139              MYSQL_YYABORT;
12140          }
12141        ;
12142
12143opt_window_frame_exclusion:
12144          /* empty */ { $$= Window_frame::EXCL_NONE; }
12145        | EXCLUDE_SYM CURRENT_SYM ROW_SYM
12146          { $$= Window_frame::EXCL_CURRENT_ROW; }
12147        | EXCLUDE_SYM GROUP_SYM
12148          { $$= Window_frame::EXCL_GROUP; }
12149        | EXCLUDE_SYM TIES_SYM
12150          { $$= Window_frame::EXCL_TIES; }
12151        | EXCLUDE_SYM NO_SYM OTHERS_MARIADB_SYM
12152          { $$= Window_frame::EXCL_NONE; }
12153        | EXCLUDE_SYM NO_SYM OTHERS_ORACLE_SYM
12154          { $$= Window_frame::EXCL_NONE; }
12155        ;
12156
12157/*
12158  Order by statement in ALTER TABLE
12159*/
12160
12161alter_order_clause:
12162          ORDER_SYM BY alter_order_list
12163        ;
12164
12165alter_order_list:
12166          alter_order_list ',' alter_order_item
12167        | alter_order_item
12168        ;
12169
12170alter_order_item:
12171          simple_ident_nospvar order_dir
12172          {
12173            bool ascending= ($2 == 1) ? true : false;
12174            if (unlikely(add_order_to_list(thd, $1, ascending)))
12175              MYSQL_YYABORT;
12176          }
12177        ;
12178
12179/*
12180   Order by statement in select
12181*/
12182
12183opt_order_clause:
12184          /* empty */
12185          { $$= NULL; }
12186        | order_clause
12187          { $$= $1; }
12188        ;
12189
12190order_clause:
12191          ORDER_SYM BY
12192          {
12193            thd->where= "ORDER clause";
12194          }
12195          order_list
12196          {
12197            $$= $4;
12198          }
12199         ;
12200
12201order_list:
12202          order_list ',' order_ident order_dir
12203          {
12204            $$= $1;
12205            if (add_to_list(thd, *$$, $3,(bool) $4))
12206              MYSQL_YYABORT;
12207          }
12208        | order_ident order_dir
12209          {
12210            $$= new (thd->mem_root) SQL_I_List<ORDER>();
12211            if (add_to_list(thd, *$$, $1, (bool) $2))
12212              MYSQL_YYABORT;
12213          }
12214        ;
12215
12216order_dir:
12217          /* empty */ { $$ =  1; }
12218        | ASC  { $$ =1; }
12219        | DESC { $$ =0; }
12220        ;
12221
12222opt_limit_clause:
12223          /* empty */
12224          { $$.empty(); }
12225        | limit_clause
12226          { $$= $1; }
12227        ;
12228
12229limit_clause:
12230          LIMIT limit_options
12231          {
12232            $$= $2;
12233            if (!$$.select_limit->basic_const_item() ||
12234                $$.select_limit->val_int() > 0)
12235              Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
12236          }
12237        | LIMIT limit_options
12238          ROWS_SYM EXAMINED_SYM limit_rows_option
12239          {
12240            $$= $2;
12241            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
12242          }
12243        | LIMIT ROWS_SYM EXAMINED_SYM limit_rows_option
12244          {
12245            $$.select_limit= 0;
12246            $$.offset_limit= 0;
12247            $$.explicit_limit= 0;
12248            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
12249          }
12250        ;
12251
12252opt_global_limit_clause:
12253          opt_limit_clause
12254          {
12255            Select->explicit_limit= $1.explicit_limit;
12256            Select->select_limit= $1.select_limit;
12257            Select->offset_limit= $1.offset_limit;
12258          }
12259        ;
12260
12261limit_options:
12262          limit_option
12263          {
12264            $$.select_limit= $1;
12265            $$.offset_limit= 0;
12266            $$.explicit_limit= 1;
12267          }
12268        | limit_option ',' limit_option
12269          {
12270            $$.select_limit= $3;
12271            $$.offset_limit= $1;
12272            $$.explicit_limit= 1;
12273          }
12274        | limit_option OFFSET_SYM limit_option
12275          {
12276            $$.select_limit= $1;
12277            $$.offset_limit= $3;
12278            $$.explicit_limit= 1;
12279          }
12280        ;
12281
12282limit_option:
12283          ident_cli
12284          {
12285            if (unlikely(!($$= Lex->create_item_limit(thd, &$1))))
12286              MYSQL_YYABORT;
12287          }
12288        | ident_cli '.' ident_cli
12289          {
12290            if (unlikely(!($$= Lex->create_item_limit(thd, &$1, &$3))))
12291              MYSQL_YYABORT;
12292          }
12293        | param_marker
12294          {
12295            $1->limit_clause_param= TRUE;
12296          }
12297        | ULONGLONG_NUM
12298          {
12299            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
12300            if (unlikely($$ == NULL))
12301              MYSQL_YYABORT;
12302          }
12303        | LONG_NUM
12304          {
12305            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
12306            if (unlikely($$ == NULL))
12307              MYSQL_YYABORT;
12308          }
12309        | NUM
12310          {
12311            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
12312            if (unlikely($$ == NULL))
12313              MYSQL_YYABORT;
12314          }
12315        ;
12316
12317limit_rows_option:
12318          limit_option
12319          {
12320            LEX *lex=Lex;
12321            lex->limit_rows_examined= $1;
12322          }
12323        ;
12324
12325delete_limit_clause:
12326          /* empty */
12327          {
12328            LEX *lex=Lex;
12329            lex->current_select->select_limit= 0;
12330          }
12331        | LIMIT limit_option
12332          {
12333            SELECT_LEX *sel= Select;
12334            sel->select_limit= $2;
12335            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
12336            sel->explicit_limit= 1;
12337          }
12338       | LIMIT ROWS_SYM EXAMINED_SYM { thd->parse_error(); MYSQL_YYABORT; }
12339       | LIMIT limit_option ROWS_SYM EXAMINED_SYM { thd->parse_error(); MYSQL_YYABORT; }
12340        ;
12341
12342order_limit_lock:
12343          order_or_limit
12344          {
12345            $$= $1;
12346            $$->lock.empty();
12347          }
12348        | order_or_limit select_lock_type
12349          {
12350            $$= $1;
12351            $$->lock= $2;
12352          }
12353        | select_lock_type
12354          {
12355            $$= new(thd->mem_root) Lex_order_limit_lock;
12356            if (!$$)
12357              YYABORT;
12358            $$->order_list= NULL;
12359            $$->limit.empty();
12360            $$->lock= $1;
12361          }
12362        ;
12363
12364opt_order_limit_lock:
12365          /* empty */
12366          {
12367            Lex->pop_select();
12368            $$= NULL;
12369          }
12370        | order_limit_lock { $$= $1; }
12371        ;
12372
12373query_expression_tail:
12374          order_limit_lock
12375        ;
12376
12377opt_query_expression_tail:
12378          opt_order_limit_lock
12379        ;
12380
12381opt_procedure_or_into:
12382          /* empty */
12383          {
12384            $$.empty();
12385          }
12386        | procedure_clause opt_select_lock_type
12387          {
12388            $$= $2;
12389          }
12390        | into opt_select_lock_type
12391          {
12392            push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
12393                                ER_WARN_DEPRECATED_SYNTAX,
12394                                ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
12395                                "<select expression> INTO <destination>;",
12396                                "'SELECT <select list> INTO <destination>"
12397                                " FROM...'");
12398            $$= $2;
12399          }
12400        ;
12401
12402order_or_limit:
12403          order_clause opt_limit_clause
12404          {
12405            $$= new(thd->mem_root) Lex_order_limit_lock;
12406            if (!$$)
12407              YYABORT;
12408            $$->order_list= $1;
12409            $$->limit= $2;
12410          }
12411        | limit_clause
12412          {
12413            Lex_order_limit_lock *op= $$= new(thd->mem_root) Lex_order_limit_lock;
12414            if (!$$)
12415              YYABORT;
12416            op->order_list= NULL;
12417            op->limit= $1;
12418            $$->order_list= NULL;
12419            $$->limit= $1;
12420          }
12421        ;
12422
12423
12424opt_plus:
12425          /* empty */
12426        | '+'
12427        ;
12428
12429int_num:
12430          opt_plus NUM           { int error; $$= (int) my_strtoll10($2.str, (char**) 0, &error); }
12431        | '-' NUM       { int error; $$= -(int) my_strtoll10($2.str, (char**) 0, &error); }
12432        ;
12433
12434ulong_num:
12435          opt_plus NUM           { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
12436        | HEX_NUM       { $$= strtoul($1.str, (char**) 0, 16); }
12437        | opt_plus LONG_NUM      { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
12438        | opt_plus ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
12439        | opt_plus DECIMAL_NUM   { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
12440        | opt_plus FLOAT_NUM     { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
12441        ;
12442
12443real_ulong_num:
12444          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
12445        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
12446        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
12447        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
12448        | dec_num_error { MYSQL_YYABORT; }
12449        ;
12450
12451longlong_num:
12452          opt_plus NUM           { int error; $$= (longlong) my_strtoll10($2.str, (char**) 0, &error); }
12453        | LONG_NUM      { int error; $$= (longlong) my_strtoll10($1.str, (char**) 0, &error); }
12454        | '-' NUM         { int error; $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error); }
12455        | '-' LONG_NUM  { int error; $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error); }
12456        ;
12457
12458ulonglong_num:
12459          opt_plus NUM           { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
12460        | opt_plus ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
12461        | opt_plus LONG_NUM      { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
12462        | opt_plus DECIMAL_NUM   { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
12463        | opt_plus FLOAT_NUM     { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
12464        ;
12465
12466real_ulonglong_num:
12467          NUM           { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
12468        | ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
12469        | HEX_NUM       { $$= strtoull($1.str, (char**) 0, 16); }
12470        | LONG_NUM      { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
12471        | dec_num_error { MYSQL_YYABORT; }
12472        ;
12473
12474dec_num_error:
12475          dec_num
12476          { thd->parse_error(ER_ONLY_INTEGERS_ALLOWED); }
12477        ;
12478
12479dec_num:
12480          DECIMAL_NUM
12481        | FLOAT_NUM
12482        ;
12483
12484choice:
12485	ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
12486	| DEFAULT { $$= HA_CHOICE_UNDEF; }
12487	;
12488
12489bool:
12490        ulong_num   { $$= $1 != 0; }
12491        | TRUE_SYM  { $$= 1; }
12492        | FALSE_SYM { $$= 0; }
12493        ;
12494
12495procedure_clause:
12496          PROCEDURE_SYM ident /* Procedure name */
12497          {
12498            LEX *lex=Lex;
12499
12500            lex->proc_list.elements=0;
12501            lex->proc_list.first=0;
12502            lex->proc_list.next= &lex->proc_list.first;
12503            Item_field *item= new (thd->mem_root)
12504                                Item_field(thd, &lex->current_select->context,
12505                                           $2);
12506            if (unlikely(item == NULL))
12507              MYSQL_YYABORT;
12508            if (unlikely(add_proc_to_list(thd, item)))
12509              MYSQL_YYABORT;
12510            Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
12511
12512            /*
12513              PROCEDURE CLAUSE cannot handle subquery as one of its parameter,
12514              so disallow any subqueries further.
12515              Alow subqueries back once the parameters are reduced.
12516            */
12517            Lex->clause_that_disallows_subselect= "PROCEDURE";
12518            Select->options|= OPTION_PROCEDURE_CLAUSE;
12519          }
12520          '(' procedure_list ')'
12521          {
12522            /* Subqueries are allowed from now.*/
12523            Lex->clause_that_disallows_subselect= NULL;
12524          }
12525        ;
12526
12527procedure_list:
12528          /* empty */ {}
12529        | procedure_list2 {}
12530        ;
12531
12532procedure_list2:
12533          procedure_list2 ',' procedure_item
12534        | procedure_item
12535        ;
12536
12537procedure_item:
12538          remember_name expr remember_end
12539          {
12540            if (unlikely(add_proc_to_list(thd, $2)))
12541              MYSQL_YYABORT;
12542            if (!$2->name.str || $2->name.str == item_empty_name)
12543              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
12544          }
12545        ;
12546
12547select_var_list_init:
12548          {
12549            LEX *lex=Lex;
12550            if (!lex->describe &&
12551                unlikely((!(lex->result= new (thd->mem_root)
12552                            select_dumpvar(thd)))))
12553              MYSQL_YYABORT;
12554          }
12555          select_var_list
12556          {}
12557        ;
12558
12559select_var_list:
12560          select_var_list ',' select_var_ident
12561        | select_var_ident {}
12562        ;
12563
12564select_var_ident: select_outvar
12565          {
12566            if (Lex->result)
12567            {
12568              if (unlikely($1 == NULL))
12569                MYSQL_YYABORT;
12570              ((select_dumpvar *)Lex->result)->var_list.push_back($1, thd->mem_root);
12571            }
12572            else
12573            {
12574              /*
12575                The parser won't create select_result instance only
12576                if it's an EXPLAIN.
12577              */
12578              DBUG_ASSERT(Lex->describe);
12579            }
12580          }
12581        ;
12582
12583select_outvar:
12584          '@' ident_or_text
12585          {
12586            $$ = Lex->result ? new (thd->mem_root) my_var_user(&$2) : NULL;
12587          }
12588        | ident_or_text
12589          {
12590            if (unlikely(!($$= Lex->create_outvar(thd, &$1)) && Lex->result))
12591              MYSQL_YYABORT;
12592          }
12593        | ident '.' ident
12594          {
12595            if (unlikely(!($$= Lex->create_outvar(thd, &$1, &$3)) && Lex->result))
12596              MYSQL_YYABORT;
12597          }
12598        ;
12599
12600into:
12601          INTO into_destination
12602          {}
12603        ;
12604
12605into_destination:
12606          OUTFILE TEXT_STRING_filesystem
12607          {
12608            LEX *lex= Lex;
12609            lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
12610            if (unlikely(!(lex->exchange=
12611                         new (thd->mem_root) sql_exchange($2.str, 0))) ||
12612                unlikely(!(lex->result=
12613                         new (thd->mem_root)
12614                         select_export(thd, lex->exchange))))
12615              MYSQL_YYABORT;
12616          }
12617          opt_load_data_charset
12618          { Lex->exchange->cs= $4; }
12619          opt_field_term opt_line_term
12620        | DUMPFILE TEXT_STRING_filesystem
12621          {
12622            LEX *lex=Lex;
12623            if (!lex->describe)
12624            {
12625              lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
12626              if (unlikely(!(lex->exchange=
12627                             new (thd->mem_root) sql_exchange($2.str,1))))
12628                MYSQL_YYABORT;
12629              if (unlikely(!(lex->result=
12630                           new (thd->mem_root)
12631                           select_dump(thd, lex->exchange))))
12632                MYSQL_YYABORT;
12633            }
12634          }
12635        | select_var_list_init
12636          {
12637            Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
12638          }
12639        ;
12640
12641/*
12642  DO statement
12643*/
12644
12645do:
12646          DO_SYM
12647          {
12648            LEX *lex=Lex;
12649            lex->sql_command = SQLCOM_DO;
12650            if (lex->main_select_push(true))
12651              MYSQL_YYABORT;
12652            mysql_init_select(lex);
12653          }
12654          expr_list
12655          {
12656            Lex->insert_list= $3;
12657            Lex->pop_select(); //main select
12658            if (Lex->check_cte_dependencies_and_resolve_references())
12659              MYSQL_YYABORT;
12660          }
12661        ;
12662
12663/*
12664  Drop : delete tables or index or user
12665*/
12666
12667drop:
12668          DROP opt_temporary table_or_tables opt_if_exists
12669          {
12670            LEX *lex=Lex;
12671            lex->set_command(SQLCOM_DROP_TABLE, $2, $4);
12672            YYPS->m_lock_type= TL_UNLOCK;
12673            YYPS->m_mdl_type= MDL_EXCLUSIVE;
12674          }
12675          table_list opt_lock_wait_timeout opt_restrict
12676          {}
12677        | DROP INDEX_SYM
12678          {
12679            if (Lex->main_select_push())
12680              MYSQL_YYABORT;
12681          }
12682          opt_if_exists_table_element ident ON table_ident opt_lock_wait_timeout
12683          {
12684            LEX *lex=Lex;
12685            Alter_drop *ad= (new (thd->mem_root)
12686                             Alter_drop(Alter_drop::KEY, $5.str, $4));
12687            if (unlikely(ad == NULL))
12688              MYSQL_YYABORT;
12689            lex->sql_command= SQLCOM_DROP_INDEX;
12690            lex->alter_info.reset();
12691            lex->alter_info.flags= ALTER_DROP_INDEX;
12692            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
12693            if (unlikely(!lex->current_select->
12694                         add_table_to_list(thd, $7, NULL, TL_OPTION_UPDATING,
12695                                           TL_READ_NO_INSERT,
12696                                           MDL_SHARED_UPGRADABLE)))
12697              MYSQL_YYABORT;
12698            Lex->pop_select(); //main select
12699          }
12700        | DROP DATABASE opt_if_exists ident
12701          {
12702            LEX *lex=Lex;
12703            lex->set_command(SQLCOM_DROP_DB, $3);
12704            lex->name= $4;
12705          }
12706        | DROP USER_SYM opt_if_exists clear_privileges user_list
12707          {
12708            Lex->set_command(SQLCOM_DROP_USER, $3);
12709          }
12710        | DROP ROLE_SYM opt_if_exists clear_privileges role_list
12711          {
12712            Lex->set_command(SQLCOM_DROP_ROLE, $3);
12713          }
12714        | DROP VIEW_SYM opt_if_exists
12715          {
12716            LEX *lex= Lex;
12717            lex->set_command(SQLCOM_DROP_VIEW, $3);
12718            YYPS->m_lock_type= TL_UNLOCK;
12719            YYPS->m_mdl_type= MDL_EXCLUSIVE;
12720          }
12721          table_list opt_restrict
12722          {}
12723        | DROP EVENT_SYM opt_if_exists sp_name
12724          {
12725            Lex->spname= $4;
12726            Lex->set_command(SQLCOM_DROP_EVENT, $3);
12727          }
12728        | DROP TRIGGER_SYM opt_if_exists sp_name
12729          {
12730            LEX *lex= Lex;
12731            lex->set_command(SQLCOM_DROP_TRIGGER, $3);
12732            lex->spname= $4;
12733          }
12734        | DROP TABLESPACE tablespace_name opt_ts_engine opt_ts_wait
12735          {
12736            LEX *lex= Lex;
12737            lex->alter_tablespace_info->ts_cmd_type= DROP_TABLESPACE;
12738          }
12739        | DROP LOGFILE_SYM GROUP_SYM logfile_group_name opt_ts_engine opt_ts_wait
12740          {
12741            LEX *lex= Lex;
12742            lex->alter_tablespace_info->ts_cmd_type= DROP_LOGFILE_GROUP;
12743          }
12744        | DROP SERVER_SYM opt_if_exists ident_or_text
12745          {
12746            Lex->set_command(SQLCOM_DROP_SERVER, $3);
12747            Lex->server_options.reset($4);
12748          }
12749        | DROP opt_temporary SEQUENCE_SYM opt_if_exists
12750
12751          {
12752            LEX *lex= Lex;
12753            lex->set_command(SQLCOM_DROP_SEQUENCE, $2, $4);
12754            lex->table_type= TABLE_TYPE_SEQUENCE;
12755            YYPS->m_lock_type= TL_UNLOCK;
12756            YYPS->m_mdl_type= MDL_EXCLUSIVE;
12757          }
12758          table_list
12759          {}
12760        | drop_routine
12761        ;
12762
12763table_list:
12764          table_name
12765        | table_list ',' table_name
12766        ;
12767
12768table_name:
12769          table_ident
12770          {
12771            if (!thd->lex->current_select_or_default()->
12772                                           add_table_to_list(thd, $1, NULL,
12773                                           TL_OPTION_UPDATING,
12774                                           YYPS->m_lock_type,
12775                                           YYPS->m_mdl_type))
12776              MYSQL_YYABORT;
12777          }
12778        ;
12779
12780table_name_with_opt_use_partition:
12781          table_ident opt_use_partition
12782          {
12783            if (unlikely(!Select->add_table_to_list(thd, $1, NULL,
12784                                                    TL_OPTION_UPDATING,
12785                                                    YYPS->m_lock_type,
12786                                                    YYPS->m_mdl_type,
12787                                                    NULL,
12788                                                    $2)))
12789              MYSQL_YYABORT;
12790          }
12791        ;
12792
12793table_alias_ref_list:
12794          table_alias_ref
12795        | table_alias_ref_list ',' table_alias_ref
12796        ;
12797
12798table_alias_ref:
12799          table_ident_opt_wild
12800          {
12801            if (unlikely(!Select->
12802                         add_table_to_list(thd, $1, NULL,
12803                                           (TL_OPTION_UPDATING |
12804                                            TL_OPTION_ALIAS),
12805                                           YYPS->m_lock_type,
12806                                           YYPS->m_mdl_type)))
12807              MYSQL_YYABORT;
12808          }
12809        ;
12810
12811opt_if_exists_table_element:
12812          /* empty */
12813        {
12814          Lex->check_exists= FALSE;
12815          $$= 0;
12816        }
12817        | IF_SYM EXISTS
12818        {
12819          Lex->check_exists= TRUE;
12820          $$= 1;
12821        }
12822        ;
12823
12824opt_if_exists:
12825          /* empty */
12826        {
12827          $$.set(DDL_options_st::OPT_NONE);
12828        }
12829        | IF_SYM EXISTS
12830        {
12831          $$.set(DDL_options_st::OPT_IF_EXISTS);
12832        }
12833        ;
12834
12835opt_temporary:
12836          /* empty */ { $$= 0; }
12837        | TEMPORARY { $$= HA_LEX_CREATE_TMP_TABLE; }
12838        ;
12839/*
12840** Insert : add new data to table
12841*/
12842
12843insert:
12844          INSERT
12845          {
12846            Lex->sql_command= SQLCOM_INSERT;
12847            Lex->duplicates= DUP_ERROR;
12848          }
12849          insert_start insert_lock_option opt_ignore opt_into insert_table
12850          {
12851            Select->set_lock_for_tables($4, true);
12852          }
12853          insert_field_spec opt_insert_update opt_returning
12854          stmt_end
12855          {
12856            Lex->mark_first_table_as_inserting();
12857          }
12858          ;
12859
12860replace:
12861          REPLACE
12862          {
12863            Lex->sql_command = SQLCOM_REPLACE;
12864            Lex->duplicates= DUP_REPLACE;
12865          }
12866          insert_start replace_lock_option opt_into insert_table
12867          {
12868            Select->set_lock_for_tables($4, true);
12869          }
12870          insert_field_spec opt_returning
12871          stmt_end
12872          {
12873            Lex->mark_first_table_as_inserting();
12874          }
12875          ;
12876
12877insert_start: {
12878                if (Lex->main_select_push())
12879                  MYSQL_YYABORT;
12880                mysql_init_select(Lex);
12881                Lex->current_select->parsing_place= BEFORE_OPT_LIST;
12882              }
12883              ;
12884
12885stmt_end: {
12886              Lex->pop_select(); //main select
12887              if (Lex->check_main_unit_semantics())
12888                MYSQL_YYABORT;
12889            }
12890            ;
12891
12892insert_lock_option:
12893          /* empty */
12894          {
12895            /*
12896              If it is SP we do not allow insert optimisation when result of
12897              insert visible only after the table unlocking but everyone can
12898              read table.
12899            */
12900            $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT);
12901          }
12902        | insert_replace_option
12903        | HIGH_PRIORITY { $$= TL_WRITE; }
12904        ;
12905
12906replace_lock_option:
12907          /* empty */ { $$= TL_WRITE_DEFAULT; }
12908        | insert_replace_option
12909        ;
12910
12911insert_replace_option:
12912          LOW_PRIORITY  { $$= TL_WRITE_LOW_PRIORITY; }
12913        | DELAYED_SYM
12914        {
12915          Lex->keyword_delayed_begin_offset= (uint)($1.pos() - thd->query());
12916          Lex->keyword_delayed_end_offset= (uint)($1.end() - thd->query());
12917          $$= TL_WRITE_DELAYED;
12918        }
12919        ;
12920
12921opt_into: /* nothing */ | INTO ;
12922
12923insert_table:
12924          {
12925            Select->save_parsing_place= Select->parsing_place;
12926          }
12927          table_name_with_opt_use_partition
12928          {
12929            LEX *lex=Lex;
12930            //lex->field_list.empty();
12931            lex->many_values.empty();
12932            lex->insert_list=0;
12933          }
12934        ;
12935
12936insert_field_spec:
12937          insert_values {}
12938        | insert_field_list insert_values {}
12939        | SET
12940          {
12941            LEX *lex=Lex;
12942            if (unlikely(!(lex->insert_list= new (thd->mem_root) List_item)) ||
12943                unlikely(lex->many_values.push_back(lex->insert_list,
12944                         thd->mem_root)))
12945              MYSQL_YYABORT;
12946            lex->current_select->parsing_place= NO_MATTER;
12947          }
12948          ident_eq_list
12949        ;
12950
12951insert_field_list:
12952          LEFT_PAREN_ALT opt_fields ')'
12953          {
12954            Lex->current_select->parsing_place= AFTER_LIST;
12955          }
12956        ;
12957
12958opt_fields:
12959          /* empty */
12960        | fields
12961        ;
12962
12963fields:
12964          fields ',' insert_ident
12965          { Lex->field_list.push_back($3, thd->mem_root); }
12966        | insert_ident { Lex->field_list.push_back($1, thd->mem_root); }
12967        ;
12968
12969
12970
12971insert_values:
12972         create_select_query_expression {}
12973        ;
12974
12975values_list:
12976          values_list ','  no_braces
12977        | no_braces_with_names
12978        ;
12979
12980ident_eq_list:
12981          ident_eq_list ',' ident_eq_value
12982        | ident_eq_value
12983        ;
12984
12985ident_eq_value:
12986          simple_ident_nospvar equal expr_or_ignore_or_default
12987          {
12988            LEX *lex=Lex;
12989            if (unlikely(lex->field_list.push_back($1, thd->mem_root)) ||
12990                unlikely(lex->insert_list->push_back($3, thd->mem_root)))
12991              MYSQL_YYABORT;
12992          }
12993        ;
12994
12995equal:
12996          '=' {}
12997        | SET_VAR {}
12998        ;
12999
13000opt_equal:
13001          /* empty */ {}
13002        | equal {}
13003        ;
13004
13005opt_with:
13006          opt_equal {}
13007        | WITH {}
13008        ;
13009
13010opt_by:
13011          opt_equal {}
13012        | BY {}
13013        ;
13014
13015no_braces:
13016          '('
13017          {
13018            if (unlikely(!(Lex->insert_list= new (thd->mem_root) List_item)))
13019              MYSQL_YYABORT;
13020          }
13021          opt_values ')'
13022          {
13023            LEX *lex=Lex;
13024            if (unlikely(lex->many_values.push_back(lex->insert_list,
13025                                                    thd->mem_root)))
13026              MYSQL_YYABORT;
13027          }
13028        ;
13029
13030no_braces_with_names:
13031          '('
13032          {
13033            if (unlikely(!(Lex->insert_list= new (thd->mem_root) List_item)))
13034              MYSQL_YYABORT;
13035          }
13036          opt_values_with_names ')'
13037          {
13038            LEX *lex=Lex;
13039            if (unlikely(lex->many_values.push_back(lex->insert_list,
13040                                                    thd->mem_root)))
13041              MYSQL_YYABORT;
13042          }
13043        ;
13044
13045opt_values:
13046          /* empty */ {}
13047        | values
13048        ;
13049
13050opt_values_with_names:
13051          /* empty */ {}
13052        | values_with_names
13053        ;
13054
13055values:
13056          values ','  expr_or_ignore_or_default
13057          {
13058            if (unlikely(Lex->insert_list->push_back($3, thd->mem_root)))
13059              MYSQL_YYABORT;
13060          }
13061        | expr_or_ignore_or_default
13062          {
13063            if (unlikely(Lex->insert_list->push_back($1, thd->mem_root)))
13064              MYSQL_YYABORT;
13065          }
13066        ;
13067
13068values_with_names:
13069          values_with_names ','  remember_name expr_or_ignore_or_default remember_end
13070          {
13071            if (unlikely(Lex->insert_list->push_back($4, thd->mem_root)))
13072               MYSQL_YYABORT;
13073            // give some name in case of using in table value constuctor (TVC)
13074            if (!$4->name.str || $4->name.str == item_empty_name)
13075              $4->set_name(thd, $3, (uint) ($5 - $3), thd->charset());
13076           }
13077        | remember_name expr_or_ignore_or_default remember_end
13078          {
13079            if (unlikely(Lex->insert_list->push_back($2, thd->mem_root)))
13080               MYSQL_YYABORT;
13081            // give some name in case of using in table value constuctor (TVC)
13082            if (!$2->name.str || $2->name.str == item_empty_name)
13083              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
13084          }
13085        ;
13086
13087expr_or_ignore:
13088          expr { $$= $1;}
13089        | IGNORE_SYM
13090          {
13091            $$= new (thd->mem_root) Item_ignore_specification(thd);
13092            if (unlikely($$ == NULL))
13093              MYSQL_YYABORT;
13094          }
13095        ;
13096
13097expr_or_ignore_or_default:
13098          expr_or_ignore { $$= $1;}
13099        | DEFAULT
13100          {
13101            $$= new (thd->mem_root) Item_default_specification(thd);
13102            if (unlikely($$ == NULL))
13103              MYSQL_YYABORT;
13104          }
13105        ;
13106
13107opt_insert_update:
13108          /* empty */
13109        | ON DUPLICATE_SYM { Lex->duplicates= DUP_UPDATE; }
13110          KEY_SYM UPDATE_SYM
13111          {
13112	    Select->parsing_place= IN_UPDATE_ON_DUP_KEY;
13113          }
13114          insert_update_list
13115          {
13116	    Select->parsing_place= NO_MATTER;
13117          }
13118        ;
13119
13120update_table_list:
13121          table_ident opt_use_partition for_portion_of_time_clause
13122          opt_table_alias_clause opt_key_definition
13123          {
13124            SELECT_LEX *sel= Select;
13125            sel->table_join_options= 0;
13126            if (!($$= Select->add_table_to_list(thd, $1, $4,
13127                                                Select->get_table_join_options(),
13128                                                YYPS->m_lock_type,
13129                                                YYPS->m_mdl_type,
13130                                                Select->pop_index_hints(),
13131                                                $2)))
13132              MYSQL_YYABORT;
13133            $$->period_conditions= Lex->period_conditions;
13134          }
13135        | join_table_list { $$= $1; }
13136        ;
13137
13138/* Update rows in a table */
13139
13140update:
13141          UPDATE_SYM
13142          {
13143            LEX *lex= Lex;
13144            if (Lex->main_select_push())
13145              MYSQL_YYABORT;
13146            mysql_init_select(lex);
13147            lex->sql_command= SQLCOM_UPDATE;
13148            lex->duplicates= DUP_ERROR;
13149          }
13150          opt_low_priority opt_ignore update_table_list
13151          SET update_list
13152          {
13153            SELECT_LEX *slex= Lex->first_select_lex();
13154            if (slex->table_list.elements > 1)
13155              Lex->sql_command= SQLCOM_UPDATE_MULTI;
13156            else if (slex->get_table_list()->derived)
13157            {
13158              /* it is single table update and it is update of derived table */
13159              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
13160                       slex->get_table_list()->alias.str, "UPDATE");
13161              MYSQL_YYABORT;
13162            }
13163            /*
13164              In case of multi-update setting write lock for all tables may
13165              be too pessimistic. We will decrease lock level if possible in
13166              mysql_multi_update().
13167            */
13168            slex->set_lock_for_tables($3, slex->table_list.elements == 1);
13169          }
13170          opt_where_clause opt_order_clause delete_limit_clause
13171          {
13172            if ($10)
13173              Select->order_list= *($10);
13174          } stmt_end {}
13175        ;
13176
13177update_list:
13178          update_list ',' update_elem
13179        | update_elem
13180        ;
13181
13182update_elem:
13183          simple_ident_nospvar equal DEFAULT
13184          {
13185            Item *def= new (thd->mem_root) Item_default_value(thd,
13186                                             Lex->current_context(), $1, 1);
13187            if (!def || add_item_to_list(thd, $1) || add_value_to_list(thd, def))
13188              MYSQL_YYABORT;
13189          }
13190        | simple_ident_nospvar equal expr_or_ignore
13191          {
13192            if (add_item_to_list(thd, $1) || add_value_to_list(thd, $3))
13193              MYSQL_YYABORT;
13194          }
13195        ;
13196
13197insert_update_list:
13198          insert_update_list ',' insert_update_elem
13199        | insert_update_elem
13200        ;
13201
13202insert_update_elem:
13203          simple_ident_nospvar equal expr_or_ignore_or_default
13204          {
13205          LEX *lex= Lex;
13206          if (unlikely(lex->update_list.push_back($1, thd->mem_root)) ||
13207              unlikely(lex->value_list.push_back($3, thd->mem_root)))
13208              MYSQL_YYABORT;
13209          }
13210        ;
13211
13212opt_low_priority:
13213          /* empty */ { $$= TL_WRITE_DEFAULT; }
13214        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
13215        ;
13216
13217/* Delete rows from a table */
13218
13219delete:
13220          DELETE_SYM
13221          {
13222            LEX *lex= Lex;
13223            lex->sql_command= SQLCOM_DELETE;
13224            YYPS->m_lock_type= TL_WRITE_DEFAULT;
13225            YYPS->m_mdl_type= MDL_SHARED_WRITE;
13226            if (Lex->main_select_push())
13227              MYSQL_YYABORT;
13228            mysql_init_select(lex);
13229            lex->ignore= 0;
13230            lex->first_select_lex()->order_list.empty();
13231          }
13232          delete_part2
13233          {
13234            if (Lex->check_cte_dependencies_and_resolve_references())
13235              MYSQL_YYABORT;
13236          }
13237          ;
13238
13239opt_delete_system_time:
13240            /* empty */
13241          {
13242            Lex->vers_conditions.init(SYSTEM_TIME_HISTORY);
13243          }
13244          | BEFORE_SYM SYSTEM_TIME_SYM history_point
13245          {
13246            Lex->vers_conditions.init(SYSTEM_TIME_BEFORE, $3);
13247          }
13248          ;
13249
13250delete_part2:
13251          opt_delete_options single_multi {}
13252        | HISTORY_SYM delete_single_table opt_delete_system_time
13253          {
13254            Lex->last_table()->vers_conditions= Lex->vers_conditions;
13255            Lex->pop_select(); //main select
13256          }
13257        ;
13258
13259delete_single_table:
13260          FROM table_ident opt_use_partition
13261          {
13262            if (unlikely(!Select->
13263                         add_table_to_list(thd, $2, NULL, TL_OPTION_UPDATING,
13264                                           YYPS->m_lock_type,
13265                                           YYPS->m_mdl_type,
13266                                           NULL,
13267                                           $3)))
13268              MYSQL_YYABORT;
13269            YYPS->m_lock_type= TL_READ_DEFAULT;
13270            YYPS->m_mdl_type= MDL_SHARED_READ;
13271          }
13272        ;
13273
13274delete_single_table_for_period:
13275          delete_single_table opt_for_portion_of_time_clause
13276          {
13277            if ($2)
13278              Lex->last_table()->period_conditions= Lex->period_conditions;
13279          }
13280        ;
13281
13282single_multi:
13283          delete_single_table_for_period
13284          opt_where_clause
13285          opt_order_clause
13286          delete_limit_clause
13287          opt_returning
13288          {
13289            if ($3)
13290              Select->order_list= *($3);
13291            Lex->pop_select(); //main select
13292          }
13293        | table_wild_list
13294          {
13295            mysql_init_multi_delete(Lex);
13296            YYPS->m_lock_type= TL_READ_DEFAULT;
13297            YYPS->m_mdl_type= MDL_SHARED_READ;
13298          }
13299          FROM join_table_list opt_where_clause
13300          {
13301            if (unlikely(multi_delete_set_locks_and_link_aux_tables(Lex)))
13302              MYSQL_YYABORT;
13303          } stmt_end {}
13304        | FROM table_alias_ref_list
13305          {
13306            mysql_init_multi_delete(Lex);
13307            YYPS->m_lock_type= TL_READ_DEFAULT;
13308            YYPS->m_mdl_type= MDL_SHARED_READ;
13309          }
13310          USING join_table_list opt_where_clause
13311          {
13312            if (unlikely(multi_delete_set_locks_and_link_aux_tables(Lex)))
13313              MYSQL_YYABORT;
13314          } stmt_end {}
13315        ;
13316
13317opt_returning:
13318          /* empty */
13319          {
13320            DBUG_ASSERT(!Lex->has_returning());
13321          }
13322        | RETURNING_SYM
13323          {
13324            DBUG_ASSERT(!Lex->has_returning());
13325            if (($<num>$= (Select != Lex->returning())))
13326            {
13327              SELECT_LEX *sl= Lex->returning();
13328              sl->set_master_unit(0);
13329              Select->add_slave(Lex->create_unit(sl));
13330              sl->include_global((st_select_lex_node**)&Lex->all_selects_list);
13331              Lex->push_select(sl);
13332            }
13333          }
13334          select_item_list
13335          {
13336            if ($<num>2)
13337              Lex->pop_select();
13338          }
13339        ;
13340
13341table_wild_list:
13342          table_wild_one
13343        | table_wild_list ',' table_wild_one
13344        ;
13345
13346table_wild_one:
13347          ident opt_wild
13348          {
13349            Table_ident *ti= new (thd->mem_root) Table_ident(&$1);
13350            if (unlikely(ti == NULL))
13351              MYSQL_YYABORT;
13352            if (unlikely(!Select->
13353                         add_table_to_list(thd,
13354                                           ti,
13355                                           NULL,
13356                                           (TL_OPTION_UPDATING |
13357                                            TL_OPTION_ALIAS),
13358                                           YYPS->m_lock_type,
13359                                           YYPS->m_mdl_type)))
13360              MYSQL_YYABORT;
13361          }
13362        | ident '.' ident opt_wild
13363          {
13364            Table_ident *ti= new (thd->mem_root) Table_ident(thd, &$1, &$3, 0);
13365            if (unlikely(ti == NULL))
13366              MYSQL_YYABORT;
13367            if (unlikely(!Select->
13368                         add_table_to_list(thd,
13369                                           ti,
13370                                           NULL,
13371                                           (TL_OPTION_UPDATING |
13372                                            TL_OPTION_ALIAS),
13373                                           YYPS->m_lock_type,
13374                                           YYPS->m_mdl_type)))
13375              MYSQL_YYABORT;
13376          }
13377        ;
13378
13379opt_wild:
13380          /* empty */ {}
13381        | '.' '*' {}
13382        ;
13383
13384opt_delete_options:
13385          /* empty */ {}
13386        | opt_delete_option opt_delete_options {}
13387        ;
13388
13389opt_delete_option:
13390          QUICK        { Select->options|= OPTION_QUICK; }
13391        | LOW_PRIORITY { YYPS->m_lock_type= TL_WRITE_LOW_PRIORITY; }
13392        | IGNORE_SYM   { Lex->ignore= 1; }
13393        ;
13394
13395truncate:
13396          TRUNCATE_SYM
13397          {
13398            LEX* lex= Lex;
13399            lex->sql_command= SQLCOM_TRUNCATE;
13400            lex->alter_info.reset();
13401            lex->first_select_lex()->options= 0;
13402            lex->sql_cache= LEX::SQL_CACHE_UNSPECIFIED;
13403            lex->first_select_lex()->order_list.empty();
13404            YYPS->m_lock_type= TL_WRITE;
13405            YYPS->m_mdl_type= MDL_EXCLUSIVE;
13406          }
13407          opt_table_sym table_name opt_lock_wait_timeout
13408          {
13409            LEX* lex= thd->lex;
13410            DBUG_ASSERT(!lex->m_sql_cmd);
13411            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_truncate_table();
13412            if (unlikely(lex->m_sql_cmd == NULL))
13413              MYSQL_YYABORT;
13414          }
13415          opt_truncate_table_storage_clause { }
13416        ;
13417
13418opt_table_sym:
13419          /* empty */
13420        | TABLE_SYM
13421        ;
13422
13423opt_profile_defs:
13424  /* empty */
13425  | profile_defs;
13426
13427profile_defs:
13428  profile_def
13429  | profile_defs ',' profile_def;
13430
13431profile_def:
13432  CPU_SYM
13433    {
13434      Lex->profile_options|= PROFILE_CPU;
13435    }
13436  | MEMORY_SYM
13437    {
13438      Lex->profile_options|= PROFILE_MEMORY;
13439    }
13440  | BLOCK_SYM IO_SYM
13441    {
13442      Lex->profile_options|= PROFILE_BLOCK_IO;
13443    }
13444  | CONTEXT_SYM SWITCHES_SYM
13445    {
13446      Lex->profile_options|= PROFILE_CONTEXT;
13447    }
13448  | PAGE_SYM FAULTS_SYM
13449    {
13450      Lex->profile_options|= PROFILE_PAGE_FAULTS;
13451    }
13452  | IPC_SYM
13453    {
13454      Lex->profile_options|= PROFILE_IPC;
13455    }
13456  | SWAPS_SYM
13457    {
13458      Lex->profile_options|= PROFILE_SWAPS;
13459    }
13460  | SOURCE_SYM
13461    {
13462      Lex->profile_options|= PROFILE_SOURCE;
13463    }
13464  | ALL
13465    {
13466      Lex->profile_options|= PROFILE_ALL;
13467    }
13468  ;
13469
13470opt_profile_args:
13471  /* empty */
13472    {
13473      Lex->profile_query_id= 0;
13474    }
13475  | FOR_SYM QUERY_SYM NUM
13476    {
13477      Lex->profile_query_id= atoi($3.str);
13478    }
13479  ;
13480
13481/* Show things */
13482
13483show:
13484          SHOW
13485          {
13486            LEX *lex=Lex;
13487            lex->wild=0;
13488            lex->ident= null_clex_str;
13489            if (Lex->main_select_push())
13490              MYSQL_YYABORT;
13491            mysql_init_select(lex);
13492            lex->current_select->parsing_place= SELECT_LIST;
13493            lex->create_info.init();
13494          }
13495          show_param
13496          {
13497            Select->parsing_place= NO_MATTER;
13498            Lex->pop_select(); //main select
13499          }
13500        ;
13501
13502show_param:
13503           DATABASES wild_and_where
13504           {
13505             LEX *lex= Lex;
13506             lex->sql_command= SQLCOM_SHOW_DATABASES;
13507             if (unlikely(prepare_schema_table(thd, lex, 0, SCH_SCHEMATA)))
13508               MYSQL_YYABORT;
13509           }
13510         | opt_full TABLES opt_db wild_and_where
13511           {
13512             LEX *lex= Lex;
13513             lex->sql_command= SQLCOM_SHOW_TABLES;
13514             lex->first_select_lex()->db= $3;
13515             if (prepare_schema_table(thd, lex, 0, SCH_TABLE_NAMES))
13516               MYSQL_YYABORT;
13517           }
13518         | opt_full TRIGGERS_SYM opt_db wild_and_where
13519           {
13520             LEX *lex= Lex;
13521             lex->sql_command= SQLCOM_SHOW_TRIGGERS;
13522             lex->first_select_lex()->db= $3;
13523             if (prepare_schema_table(thd, lex, 0, SCH_TRIGGERS))
13524               MYSQL_YYABORT;
13525           }
13526         | EVENTS_SYM opt_db wild_and_where
13527           {
13528             LEX *lex= Lex;
13529             lex->sql_command= SQLCOM_SHOW_EVENTS;
13530             lex->first_select_lex()->db= $2;
13531             if (prepare_schema_table(thd, lex, 0, SCH_EVENTS))
13532               MYSQL_YYABORT;
13533           }
13534         | TABLE_SYM STATUS_SYM opt_db wild_and_where
13535           {
13536             LEX *lex= Lex;
13537             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
13538             lex->first_select_lex()->db= $3;
13539             if (prepare_schema_table(thd, lex, 0, SCH_TABLES))
13540               MYSQL_YYABORT;
13541           }
13542        | OPEN_SYM TABLES opt_db wild_and_where
13543          {
13544            LEX *lex= Lex;
13545            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
13546            lex->first_select_lex()->db= $3;
13547            if (prepare_schema_table(thd, lex, 0, SCH_OPEN_TABLES))
13548              MYSQL_YYABORT;
13549          }
13550        | PLUGINS_SYM
13551          {
13552            LEX *lex= Lex;
13553            lex->sql_command= SQLCOM_SHOW_PLUGINS;
13554            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PLUGINS)))
13555              MYSQL_YYABORT;
13556          }
13557        | PLUGINS_SYM SONAME_SYM TEXT_STRING_sys
13558          {
13559            Lex->ident= $3;
13560            Lex->sql_command= SQLCOM_SHOW_PLUGINS;
13561            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_ALL_PLUGINS)))
13562              MYSQL_YYABORT;
13563          }
13564        | PLUGINS_SYM SONAME_SYM wild_and_where
13565          {
13566            Lex->sql_command= SQLCOM_SHOW_PLUGINS;
13567            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_ALL_PLUGINS)))
13568              MYSQL_YYABORT;
13569          }
13570        | ENGINE_SYM known_storage_engines show_engine_param
13571          { Lex->create_info.db_type= $2; }
13572        | ENGINE_SYM ALL show_engine_param
13573          { Lex->create_info.db_type= NULL; }
13574        | opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
13575          {
13576            LEX *lex= Lex;
13577            lex->sql_command= SQLCOM_SHOW_FIELDS;
13578            if ($5.str)
13579              $4->change_db(&$5);
13580            if (unlikely(prepare_schema_table(thd, lex, $4, SCH_COLUMNS)))
13581              MYSQL_YYABORT;
13582          }
13583        | master_or_binary LOGS_SYM
13584          {
13585            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
13586          }
13587        | SLAVE HOSTS_SYM
13588          {
13589            Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
13590          }
13591        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
13592          {
13593            LEX *lex= Lex;
13594            lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
13595          }
13596          opt_global_limit_clause
13597        | RELAYLOG_SYM optional_connection_name EVENTS_SYM binlog_in binlog_from
13598          {
13599            LEX *lex= Lex;
13600            lex->sql_command= SQLCOM_SHOW_RELAYLOG_EVENTS;
13601          }
13602          opt_global_limit_clause
13603        | keys_or_index from_or_in table_ident opt_db opt_where_clause
13604          {
13605            LEX *lex= Lex;
13606            lex->sql_command= SQLCOM_SHOW_KEYS;
13607            if ($4.str)
13608              $3->change_db(&$4);
13609            if (unlikely(prepare_schema_table(thd, lex, $3, SCH_STATISTICS)))
13610              MYSQL_YYABORT;
13611          }
13612        | opt_storage ENGINES_SYM
13613          {
13614            LEX *lex=Lex;
13615            lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
13616            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_ENGINES)))
13617              MYSQL_YYABORT;
13618          }
13619        | AUTHORS_SYM
13620          {
13621            LEX *lex=Lex;
13622            lex->sql_command= SQLCOM_SHOW_AUTHORS;
13623          }
13624        | CONTRIBUTORS_SYM
13625          {
13626            LEX *lex=Lex;
13627            lex->sql_command= SQLCOM_SHOW_CONTRIBUTORS;
13628          }
13629        | PRIVILEGES
13630          {
13631            LEX *lex=Lex;
13632            lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
13633          }
13634        | COUNT_SYM '(' '*' ')' WARNINGS
13635          {
13636            LEX_CSTRING var= {STRING_WITH_LEN("warning_count")};
13637            (void) create_select_for_variable(thd, &var);
13638          }
13639        | COUNT_SYM '(' '*' ')' ERRORS
13640          {
13641            LEX_CSTRING var= {STRING_WITH_LEN("error_count")};
13642            (void) create_select_for_variable(thd, &var);
13643          }
13644        | WARNINGS opt_global_limit_clause
13645          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
13646        | ERRORS opt_global_limit_clause
13647          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
13648        | PROFILES_SYM
13649          { Lex->sql_command = SQLCOM_SHOW_PROFILES; }
13650        | PROFILE_SYM opt_profile_defs opt_profile_args opt_global_limit_clause
13651          {
13652            LEX *lex= Lex;
13653            lex->sql_command= SQLCOM_SHOW_PROFILE;
13654            if (unlikely(prepare_schema_table(thd, lex, NULL, SCH_PROFILES)))
13655              MYSQL_YYABORT;
13656          }
13657        | opt_var_type STATUS_SYM wild_and_where
13658          {
13659            LEX *lex= Lex;
13660            lex->sql_command= SQLCOM_SHOW_STATUS;
13661            lex->option_type= $1;
13662            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_SESSION_STATUS)))
13663              MYSQL_YYABORT;
13664          }
13665        | opt_full PROCESSLIST_SYM
13666          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
13667        | opt_var_type  VARIABLES wild_and_where
13668          {
13669            LEX *lex= Lex;
13670            lex->sql_command= SQLCOM_SHOW_VARIABLES;
13671            lex->option_type= $1;
13672            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_SESSION_VARIABLES)))
13673              MYSQL_YYABORT;
13674          }
13675        | charset wild_and_where
13676          {
13677            LEX *lex= Lex;
13678            lex->sql_command= SQLCOM_SHOW_CHARSETS;
13679            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_CHARSETS)))
13680              MYSQL_YYABORT;
13681          }
13682        | COLLATION_SYM wild_and_where
13683          {
13684            LEX *lex= Lex;
13685            lex->sql_command= SQLCOM_SHOW_COLLATIONS;
13686            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_COLLATIONS)))
13687              MYSQL_YYABORT;
13688          }
13689        | GRANTS
13690          {
13691            Lex->sql_command= SQLCOM_SHOW_GRANTS;
13692            if (unlikely(!(Lex->grant_user=
13693                          (LEX_USER*)thd->alloc(sizeof(LEX_USER)))))
13694              MYSQL_YYABORT;
13695            Lex->grant_user->user= current_user_and_current_role;
13696          }
13697        | GRANTS FOR_SYM user_or_role clear_privileges
13698          {
13699            LEX *lex=Lex;
13700            lex->sql_command= SQLCOM_SHOW_GRANTS;
13701            lex->grant_user=$3;
13702          }
13703        | CREATE DATABASE opt_if_not_exists ident
13704          {
13705            Lex->set_command(SQLCOM_SHOW_CREATE_DB, $3);
13706            Lex->name= $4;
13707          }
13708        | CREATE TABLE_SYM table_ident
13709          {
13710            LEX *lex= Lex;
13711            lex->sql_command = SQLCOM_SHOW_CREATE;
13712            if (!lex->first_select_lex()->add_table_to_list(thd, $3, NULL,0))
13713              MYSQL_YYABORT;
13714            lex->create_info.storage_media= HA_SM_DEFAULT;
13715          }
13716        | CREATE VIEW_SYM table_ident
13717          {
13718            LEX *lex= Lex;
13719            lex->sql_command = SQLCOM_SHOW_CREATE;
13720            if (!lex->first_select_lex()->add_table_to_list(thd, $3, NULL, 0))
13721              MYSQL_YYABORT;
13722            lex->table_type= TABLE_TYPE_VIEW;
13723          }
13724        | CREATE SEQUENCE_SYM table_ident
13725          {
13726            LEX *lex= Lex;
13727            lex->sql_command = SQLCOM_SHOW_CREATE;
13728            if (!lex->first_select_lex()->add_table_to_list(thd, $3, NULL, 0))
13729              MYSQL_YYABORT;
13730            lex->table_type= TABLE_TYPE_SEQUENCE;
13731          }
13732        | BINLOG_SYM STATUS_SYM
13733          {
13734            Lex->sql_command = SQLCOM_SHOW_BINLOG_STAT;
13735          }
13736        | MASTER_SYM STATUS_SYM
13737          {
13738            Lex->sql_command = SQLCOM_SHOW_BINLOG_STAT;
13739          }
13740        | ALL SLAVES STATUS_SYM
13741          {
13742            if (!(Lex->m_sql_cmd= new (thd->mem_root)
13743                  Sql_cmd_show_slave_status(true)))
13744              MYSQL_YYABORT;
13745            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
13746          }
13747        | SLAVE STATUS_SYM
13748          {
13749            LEX *lex= thd->lex;
13750            lex->mi.connection_name= null_clex_str;
13751            if (!(lex->m_sql_cmd= new (thd->mem_root)
13752                  Sql_cmd_show_slave_status()))
13753              MYSQL_YYABORT;
13754            lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
13755          }
13756        | SLAVE connection_name STATUS_SYM
13757          {
13758            if (!(Lex->m_sql_cmd= new (thd->mem_root)
13759                  Sql_cmd_show_slave_status()))
13760              MYSQL_YYABORT;
13761            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
13762          }
13763        | CREATE PROCEDURE_SYM sp_name
13764          {
13765            LEX *lex= Lex;
13766
13767            lex->sql_command = SQLCOM_SHOW_CREATE_PROC;
13768            lex->spname= $3;
13769          }
13770        | CREATE FUNCTION_SYM sp_name
13771          {
13772            LEX *lex= Lex;
13773
13774            lex->sql_command = SQLCOM_SHOW_CREATE_FUNC;
13775            lex->spname= $3;
13776          }
13777        | CREATE PACKAGE_MARIADB_SYM sp_name
13778          {
13779            LEX *lex= Lex;
13780            lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE;
13781            lex->spname= $3;
13782          }
13783        | CREATE PACKAGE_ORACLE_SYM sp_name
13784          {
13785            LEX *lex= Lex;
13786            lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE;
13787            lex->spname= $3;
13788          }
13789        | CREATE PACKAGE_MARIADB_SYM BODY_MARIADB_SYM sp_name
13790          {
13791            LEX *lex= Lex;
13792            lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE_BODY;
13793            lex->spname= $4;
13794          }
13795        | CREATE PACKAGE_ORACLE_SYM BODY_ORACLE_SYM sp_name
13796          {
13797            LEX *lex= Lex;
13798            lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE_BODY;
13799            lex->spname= $4;
13800          }
13801        | CREATE TRIGGER_SYM sp_name
13802          {
13803            LEX *lex= Lex;
13804            lex->sql_command= SQLCOM_SHOW_CREATE_TRIGGER;
13805            lex->spname= $3;
13806          }
13807        | CREATE USER_SYM
13808          {
13809            Lex->sql_command= SQLCOM_SHOW_CREATE_USER;
13810            if (unlikely(!(Lex->grant_user=
13811                          (LEX_USER*)thd->alloc(sizeof(LEX_USER)))))
13812              MYSQL_YYABORT;
13813            Lex->grant_user->user= current_user;
13814          }
13815        | CREATE USER_SYM user
13816          {
13817             Lex->sql_command= SQLCOM_SHOW_CREATE_USER;
13818             Lex->grant_user= $3;
13819          }
13820        | PROCEDURE_SYM STATUS_SYM wild_and_where
13821          {
13822            LEX *lex= Lex;
13823            lex->sql_command= SQLCOM_SHOW_STATUS_PROC;
13824            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
13825              MYSQL_YYABORT;
13826          }
13827        | FUNCTION_SYM STATUS_SYM wild_and_where
13828          {
13829            LEX *lex= Lex;
13830            lex->sql_command= SQLCOM_SHOW_STATUS_FUNC;
13831            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
13832              MYSQL_YYABORT;
13833          }
13834        | PACKAGE_MARIADB_SYM STATUS_SYM wild_and_where
13835          {
13836            LEX *lex= Lex;
13837            lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE;
13838            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
13839              MYSQL_YYABORT;
13840          }
13841        | PACKAGE_ORACLE_SYM STATUS_SYM wild_and_where
13842          {
13843            LEX *lex= Lex;
13844            lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE;
13845            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
13846              MYSQL_YYABORT;
13847          }
13848        | PACKAGE_MARIADB_SYM BODY_MARIADB_SYM STATUS_SYM wild_and_where
13849          {
13850            LEX *lex= Lex;
13851            lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE_BODY;
13852            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
13853              MYSQL_YYABORT;
13854          }
13855        | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM STATUS_SYM wild_and_where
13856          {
13857            LEX *lex= Lex;
13858            lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE_BODY;
13859            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
13860              MYSQL_YYABORT;
13861          }
13862        | PROCEDURE_SYM CODE_SYM sp_name
13863          {
13864            Lex->sql_command= SQLCOM_SHOW_PROC_CODE;
13865            Lex->spname= $3;
13866          }
13867        | FUNCTION_SYM CODE_SYM sp_name
13868          {
13869            Lex->sql_command= SQLCOM_SHOW_FUNC_CODE;
13870            Lex->spname= $3;
13871          }
13872        | PACKAGE_MARIADB_SYM BODY_MARIADB_SYM CODE_SYM sp_name
13873          {
13874            Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE;
13875            Lex->spname= $4;
13876          }
13877        | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM CODE_SYM sp_name
13878          {
13879            Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE;
13880            Lex->spname= $4;
13881          }
13882        | CREATE EVENT_SYM sp_name
13883          {
13884            Lex->spname= $3;
13885            Lex->sql_command = SQLCOM_SHOW_CREATE_EVENT;
13886          }
13887        | describe_command FOR_SYM expr
13888          {
13889            Lex->sql_command= SQLCOM_SHOW_EXPLAIN;
13890            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_EXPLAIN)))
13891              MYSQL_YYABORT;
13892            add_value_to_list(thd, $3);
13893          }
13894        | IDENT_sys remember_tok_start wild_and_where
13895           {
13896             LEX *lex= Lex;
13897             bool in_plugin;
13898             lex->sql_command= SQLCOM_SHOW_GENERIC;
13899             ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1, &in_plugin);
13900             if (unlikely(!table || !table->old_format || !in_plugin))
13901             {
13902               thd->parse_error(ER_SYNTAX_ERROR, $2);
13903               MYSQL_YYABORT;
13904             }
13905             if (unlikely(lex->wild && table->idx_field1 < 0))
13906             {
13907               thd->parse_error(ER_SYNTAX_ERROR, $3);
13908               MYSQL_YYABORT;
13909             }
13910             if (unlikely(make_schema_select(thd, Lex->current_select, table)))
13911               MYSQL_YYABORT;
13912           }
13913        ;
13914
13915show_engine_param:
13916          STATUS_SYM
13917          { Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS; }
13918        | MUTEX_SYM
13919          { Lex->sql_command= SQLCOM_SHOW_ENGINE_MUTEX; }
13920        | LOGS_SYM
13921          { Lex->sql_command= SQLCOM_SHOW_ENGINE_LOGS; }
13922        ;
13923
13924master_or_binary:
13925          MASTER_SYM
13926        | BINARY
13927        ;
13928
13929opt_storage:
13930          /* empty */
13931        | STORAGE_SYM
13932        ;
13933
13934opt_db:
13935          /* empty */      { $$= null_clex_str; }
13936        | from_or_in ident { $$= $2; }
13937        ;
13938
13939opt_full:
13940          /* empty */ { Lex->verbose=0; }
13941        | FULL        { Lex->verbose=1; }
13942        ;
13943
13944from_or_in:
13945          FROM
13946        | IN_SYM
13947        ;
13948
13949binlog_in:
13950          /* empty */            { Lex->mi.log_file_name = 0; }
13951        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
13952        ;
13953
13954binlog_from:
13955          /* empty */        { Lex->mi.pos = 4; /* skip magic number */ }
13956        | FROM ulonglong_num { Lex->mi.pos = $2; }
13957        ;
13958
13959wild_and_where:
13960          /* empty */ { $$= 0; }
13961        | LIKE remember_tok_start TEXT_STRING_sys
13962          {
13963            Lex->wild= new (thd->mem_root) String($3.str, $3.length,
13964                                                    system_charset_info);
13965            if (unlikely(Lex->wild == NULL))
13966              MYSQL_YYABORT;
13967            $$= $2;
13968          }
13969        | WHERE remember_tok_start expr
13970          {
13971            Select->where= normalize_cond(thd, $3);
13972            if ($3)
13973              $3->top_level_item();
13974            $$= $2;
13975          }
13976        ;
13977
13978/* A Oracle compatible synonym for show */
13979describe:
13980          describe_command table_ident
13981          {
13982            LEX *lex= Lex;
13983            if (lex->main_select_push())
13984              MYSQL_YYABORT;
13985            mysql_init_select(lex);
13986            lex->current_select->parsing_place= SELECT_LIST;
13987            lex->sql_command= SQLCOM_SHOW_FIELDS;
13988            lex->first_select_lex()->db= null_clex_str;
13989            lex->verbose= 0;
13990            if (unlikely(prepare_schema_table(thd, lex, $2, SCH_COLUMNS)))
13991              MYSQL_YYABORT;
13992          }
13993          opt_describe_column
13994          {
13995            Select->parsing_place= NO_MATTER;
13996            Lex->pop_select(); //main select
13997          }
13998        | describe_command opt_extended_describe
13999          { Lex->describe|= DESCRIBE_NORMAL; }
14000          explainable_command
14001          {
14002            LEX *lex=Lex;
14003            lex->first_select_lex()->options|= SELECT_DESCRIBE;
14004          }
14005        ;
14006
14007explainable_command:
14008          select
14009        | select_into
14010        | insert
14011        | replace
14012        | update
14013        | delete
14014        ;
14015
14016describe_command:
14017          DESC
14018        | DESCRIBE
14019        ;
14020
14021analyze_stmt_command:
14022          ANALYZE_SYM opt_format_json explainable_command
14023          {
14024            Lex->analyze_stmt= true;
14025          }
14026        ;
14027
14028opt_extended_describe:
14029          EXTENDED_SYM   { Lex->describe|= DESCRIBE_EXTENDED; }
14030        | EXTENDED_SYM ALL
14031          { Lex->describe|= DESCRIBE_EXTENDED | DESCRIBE_EXTENDED2; }
14032        | PARTITIONS_SYM { Lex->describe|= DESCRIBE_PARTITIONS; }
14033        | opt_format_json {}
14034        ;
14035
14036opt_format_json:
14037          /* empty */ {}
14038        | FORMAT_SYM '=' ident_or_text
14039          {
14040            if (lex_string_eq(&$3, STRING_WITH_LEN("JSON")))
14041              Lex->explain_json= true;
14042            else if (lex_string_eq(&$3, STRING_WITH_LEN("TRADITIONAL")))
14043              DBUG_ASSERT(Lex->explain_json==false);
14044            else
14045              my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN",
14046                               $3.str));
14047          }
14048        ;
14049
14050opt_describe_column:
14051          /* empty */ {}
14052        | text_string { Lex->wild= $1; }
14053        | ident
14054          {
14055            Lex->wild= new (thd->mem_root) String((const char*) $1.str,
14056                                                    $1.length,
14057                                                    system_charset_info);
14058            if (unlikely(Lex->wild == NULL))
14059              MYSQL_YYABORT;
14060          }
14061        ;
14062
14063
14064/* flush things */
14065
14066flush:
14067          FLUSH_SYM opt_no_write_to_binlog
14068          {
14069            LEX *lex=Lex;
14070            lex->sql_command= SQLCOM_FLUSH;
14071            lex->type= 0;
14072            lex->no_write_to_binlog= $2;
14073          }
14074          flush_options {}
14075        ;
14076
14077flush_options:
14078          table_or_tables
14079          {
14080            Lex->type|= REFRESH_TABLES;
14081            /*
14082              Set type of metadata and table locks for
14083              FLUSH TABLES table_list [WITH READ LOCK].
14084            */
14085            YYPS->m_lock_type= TL_READ_NO_INSERT;
14086            YYPS->m_mdl_type= MDL_SHARED_HIGH_PRIO;
14087          }
14088          opt_table_list opt_flush_lock
14089          {}
14090        | flush_options_list
14091          {}
14092        ;
14093
14094opt_flush_lock:
14095          /* empty */ {}
14096        | flush_lock
14097        {
14098          TABLE_LIST *tables= Lex->query_tables;
14099          for (; tables; tables= tables->next_global)
14100          {
14101            tables->mdl_request.set_type(MDL_SHARED_NO_WRITE);
14102            /* Don't try to flush views. */
14103            tables->required_type= TABLE_TYPE_NORMAL;
14104            /* Ignore temporary tables. */
14105            tables->open_type= OT_BASE_ONLY;
14106          }
14107        }
14108        ;
14109
14110flush_lock:
14111          WITH READ_SYM LOCK_SYM optional_flush_tables_arguments
14112          { Lex->type|= REFRESH_READ_LOCK | $4; }
14113        | FOR_SYM
14114          {
14115            if (unlikely(Lex->query_tables == NULL))
14116            {
14117              // Table list can't be empty
14118              thd->parse_error(ER_NO_TABLES_USED);
14119              MYSQL_YYABORT;
14120            }
14121            Lex->type|= REFRESH_FOR_EXPORT;
14122          } EXPORT_SYM {}
14123        ;
14124
14125flush_options_list:
14126          flush_options_list ',' flush_option
14127        | flush_option
14128          {}
14129        ;
14130
14131flush_option:
14132          ERROR_SYM LOGS_SYM
14133          { Lex->type|= REFRESH_ERROR_LOG; }
14134        | ENGINE_SYM LOGS_SYM
14135          { Lex->type|= REFRESH_ENGINE_LOG; }
14136        | GENERAL LOGS_SYM
14137          { Lex->type|= REFRESH_GENERAL_LOG; }
14138        | SLOW LOGS_SYM
14139          { Lex->type|= REFRESH_SLOW_LOG; }
14140        | BINARY LOGS_SYM opt_delete_gtid_domain
14141          { Lex->type|= REFRESH_BINARY_LOG; }
14142        | RELAY LOGS_SYM optional_connection_name
14143          {
14144            LEX *lex= Lex;
14145            if (unlikely(lex->type & REFRESH_RELAY_LOG))
14146              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "FLUSH", "RELAY LOGS"));
14147            lex->type|= REFRESH_RELAY_LOG;
14148            lex->relay_log_connection_name= lex->mi.connection_name;
14149           }
14150        | QUERY_SYM CACHE_SYM
14151          { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
14152        | HOSTS_SYM
14153          { Lex->type|= REFRESH_HOSTS; }
14154        | PRIVILEGES
14155          { Lex->type|= REFRESH_GRANT; }
14156        | LOGS_SYM
14157          {
14158            Lex->type|= REFRESH_LOG;
14159            Lex->relay_log_connection_name= empty_clex_str;
14160          }
14161        | STATUS_SYM
14162          { Lex->type|= REFRESH_STATUS; }
14163        | SLAVE optional_connection_name
14164          {
14165            LEX *lex= Lex;
14166            if (unlikely(lex->type & REFRESH_SLAVE))
14167              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "FLUSH","SLAVE"));
14168            lex->type|= REFRESH_SLAVE;
14169            lex->reset_slave_info.all= false;
14170          }
14171        | MASTER_SYM
14172          { Lex->type|= REFRESH_MASTER; }
14173        | DES_KEY_FILE
14174          { Lex->type|= REFRESH_DES_KEY_FILE; }
14175        | RESOURCES
14176          { Lex->type|= REFRESH_USER_RESOURCES; }
14177        | SSL_SYM
14178          { Lex->type|= REFRESH_SSL;}
14179        | THREADS_SYM
14180          { Lex->type|= REFRESH_THREADS;}
14181        | IDENT_sys remember_tok_start
14182           {
14183             Lex->type|= REFRESH_GENERIC;
14184             ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1);
14185             if (unlikely(!table || !table->reset_table))
14186             {
14187               thd->parse_error(ER_SYNTAX_ERROR, $2);
14188               MYSQL_YYABORT;
14189             }
14190             if (unlikely(Lex->view_list.push_back((LEX_CSTRING*)
14191                                                   thd->memdup(&$1, sizeof(LEX_CSTRING)),
14192                                                   thd->mem_root)))
14193               MYSQL_YYABORT;
14194           }
14195        ;
14196
14197opt_table_list:
14198          /* empty */  {}
14199        | table_list {}
14200        ;
14201
14202backup:
14203        BACKUP_SYM backup_statements {}
14204	;
14205
14206backup_statements:
14207	STAGE_SYM ident
14208        {
14209          int type;
14210          if (unlikely(Lex->sphead))
14211            my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "BACKUP STAGE"));
14212          if ((type= find_type($2.str, &backup_stage_names,
14213                               FIND_TYPE_NO_PREFIX)) <= 0)
14214            my_yyabort_error((ER_BACKUP_UNKNOWN_STAGE, MYF(0), $2.str));
14215          Lex->sql_command= SQLCOM_BACKUP;
14216          Lex->backup_stage= (backup_stages) (type-1);
14217          break;
14218        }
14219	| LOCK_SYM
14220          {
14221            if (unlikely(Lex->sphead))
14222              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "BACKUP LOCK"));
14223            if (Lex->main_select_push())
14224              MYSQL_YYABORT;
14225          }
14226          table_ident
14227          {
14228	    if (unlikely(!Select->add_table_to_list(thd, $3, NULL, 0,
14229                                                    TL_READ, MDL_SHARED_HIGH_PRIO)))
14230             MYSQL_YYABORT;
14231            Lex->sql_command= SQLCOM_BACKUP_LOCK;
14232            Lex->pop_select(); //main select
14233          }
14234        | UNLOCK_SYM
14235          {
14236            if (unlikely(Lex->sphead))
14237              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "BACKUP UNLOCK"));
14238	    /* Table list is empty for unlock */
14239            Lex->sql_command= SQLCOM_BACKUP_LOCK;
14240          }
14241        ;
14242
14243opt_delete_gtid_domain:
14244          /* empty */ {}
14245        | DELETE_DOMAIN_ID_SYM '=' '(' delete_domain_id_list ')'
14246          {}
14247        ;
14248delete_domain_id_list:
14249          /* Empty */
14250        | delete_domain_id
14251        | delete_domain_id_list ',' delete_domain_id
14252        ;
14253
14254delete_domain_id:
14255          ulonglong_num
14256          {
14257            uint32 value= (uint32) $1;
14258            if ($1 > UINT_MAX32)
14259            {
14260              my_printf_error(ER_BINLOG_CANT_DELETE_GTID_DOMAIN,
14261                              "The value of gtid domain being deleted ('%llu') "
14262                              "exceeds its maximum size "
14263                              "of 32 bit unsigned integer", MYF(0), $1);
14264              MYSQL_YYABORT;
14265            }
14266            insert_dynamic(&Lex->delete_gtid_domain, (uchar*) &value);
14267          }
14268        ;
14269
14270optional_flush_tables_arguments:
14271          /* empty */        {$$= 0;}
14272        | AND_SYM DISABLE_SYM CHECKPOINT_SYM {$$= REFRESH_CHECKPOINT; }
14273        ;
14274
14275reset:
14276          RESET_SYM
14277          {
14278            LEX *lex=Lex;
14279            lex->sql_command= SQLCOM_RESET; lex->type=0;
14280          }
14281          reset_options
14282          {}
14283        ;
14284
14285reset_options:
14286          reset_options ',' reset_option
14287        | reset_option
14288        ;
14289
14290reset_option:
14291          SLAVE               { Lex->type|= REFRESH_SLAVE; }
14292          optional_connection_name
14293          slave_reset_options { }
14294        | MASTER_SYM
14295          {
14296             Lex->type|= REFRESH_MASTER;
14297             Lex->next_binlog_file_number= 0;
14298          }
14299          master_reset_options
14300        | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;}
14301        ;
14302
14303slave_reset_options:
14304          /* empty */ { Lex->reset_slave_info.all= false; }
14305        | ALL         { Lex->reset_slave_info.all= true; }
14306        ;
14307
14308master_reset_options:
14309          /* empty */ {}
14310        | TO_SYM ulong_num
14311          {
14312            Lex->next_binlog_file_number = $2;
14313          }
14314        ;
14315
14316purge:
14317          PURGE master_or_binary LOGS_SYM TO_SYM TEXT_STRING_sys
14318          {
14319            Lex->stmt_purge_to($5);
14320          }
14321        | PURGE master_or_binary LOGS_SYM BEFORE_SYM
14322          { Lex->clause_that_disallows_subselect= "PURGE..BEFORE"; }
14323          expr
14324          {
14325            Lex->clause_that_disallows_subselect= NULL;
14326            if (Lex->stmt_purge_before($6))
14327              MYSQL_YYABORT;
14328          }
14329        ;
14330
14331
14332/* kill threads */
14333
14334kill:
14335          KILL_SYM
14336          {
14337            LEX *lex=Lex;
14338            lex->value_list.empty();
14339            lex->users_list.empty();
14340            lex->sql_command= SQLCOM_KILL;
14341            lex->kill_type= KILL_TYPE_ID;
14342          }
14343          kill_type kill_option
14344          {
14345            Lex->kill_signal= (killed_state) ($3 | $4);
14346          }
14347        ;
14348
14349kill_type:
14350        /* Empty */    { $$= (int) KILL_HARD_BIT; }
14351        | HARD_SYM     { $$= (int) KILL_HARD_BIT; }
14352        | SOFT_SYM     { $$= 0; }
14353        ;
14354
14355kill_option:
14356          opt_connection kill_expr { $$= (int) KILL_CONNECTION; }
14357        | QUERY_SYM      kill_expr { $$= (int) KILL_QUERY; }
14358        | QUERY_SYM ID_SYM expr
14359          {
14360            $$= (int) KILL_QUERY;
14361            Lex->kill_type= KILL_TYPE_QUERY;
14362            Lex->value_list.push_front($3, thd->mem_root);
14363          }
14364        ;
14365
14366opt_connection:
14367          /* empty */    { }
14368        | CONNECTION_SYM { }
14369        ;
14370
14371kill_expr:
14372        expr
14373        {
14374          Lex->value_list.push_front($$, thd->mem_root);
14375         }
14376        | USER_SYM user
14377          {
14378            Lex->users_list.push_back($2, thd->mem_root);
14379            Lex->kill_type= KILL_TYPE_USER;
14380          }
14381        ;
14382
14383shutdown:
14384        SHUTDOWN { Lex->sql_command= SQLCOM_SHUTDOWN; }
14385        shutdown_option {}
14386        ;
14387
14388shutdown_option:
14389        /*  Empty */    { Lex->is_shutdown_wait_for_slaves= false; }
14390        | WAIT_SYM FOR_SYM ALL SLAVES
14391        {
14392          Lex->is_shutdown_wait_for_slaves= true;
14393        }
14394        ;
14395
14396/* change database */
14397
14398use:
14399          USE_SYM ident
14400          {
14401            LEX *lex=Lex;
14402            lex->sql_command=SQLCOM_CHANGE_DB;
14403            lex->first_select_lex()->db= $2;
14404          }
14405        ;
14406
14407/* import, export of files */
14408
14409load:
14410          LOAD data_or_xml
14411          {
14412            LEX *lex= thd->lex;
14413
14414            if (unlikely(lex->sphead))
14415            {
14416              my_error(ER_SP_BADSTATEMENT, MYF(0),
14417                       $2 == FILETYPE_CSV ? "LOAD DATA" : "LOAD XML");
14418              MYSQL_YYABORT;
14419            }
14420            if (lex->main_select_push())
14421              MYSQL_YYABORT;
14422            mysql_init_select(lex);
14423          }
14424          load_data_lock opt_local INFILE TEXT_STRING_filesystem
14425          {
14426            LEX *lex=Lex;
14427            lex->sql_command= SQLCOM_LOAD;
14428            lex->local_file=  $5;
14429            lex->duplicates= DUP_ERROR;
14430            lex->ignore= 0;
14431            if (unlikely(!(lex->exchange= new (thd->mem_root)
14432                         sql_exchange($7.str, 0, $2))))
14433              MYSQL_YYABORT;
14434          }
14435          opt_duplicate INTO TABLE_SYM table_ident opt_use_partition
14436          {
14437            LEX *lex=Lex;
14438            if (unlikely(!Select->add_table_to_list(thd, $12, NULL,
14439                                                   TL_OPTION_UPDATING,
14440                                                   $4, MDL_SHARED_WRITE,
14441                                                   NULL, $13)))
14442              MYSQL_YYABORT;
14443            lex->field_list.empty();
14444            lex->update_list.empty();
14445            lex->value_list.empty();
14446            lex->many_values.empty();
14447          }
14448          opt_load_data_charset
14449          { Lex->exchange->cs= $15; }
14450          opt_xml_rows_identified_by
14451          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
14452          opt_load_data_set_spec
14453          stmt_end
14454          {
14455            Lex->mark_first_table_as_inserting();
14456          }
14457          ;
14458
14459data_or_xml:
14460        DATA_SYM  { $$= FILETYPE_CSV; }
14461        | XML_SYM { $$= FILETYPE_XML; }
14462        ;
14463
14464opt_local:
14465          /* empty */ { $$=0;}
14466        | LOCAL_SYM { $$=1;}
14467        ;
14468
14469load_data_lock:
14470          /* empty */ { $$= TL_WRITE_DEFAULT; }
14471        | CONCURRENT
14472          {
14473            /*
14474              Ignore this option in SP to avoid problem with query cache and
14475              triggers with non default priority locks
14476            */
14477            $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT);
14478          }
14479        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
14480        ;
14481
14482opt_duplicate:
14483          /* empty */ { Lex->duplicates=DUP_ERROR; }
14484        | REPLACE { Lex->duplicates=DUP_REPLACE; }
14485        | IGNORE_SYM { Lex->ignore= 1; }
14486        ;
14487
14488opt_field_term:
14489          /* empty */
14490        | COLUMNS field_term_list
14491        ;
14492
14493field_term_list:
14494          field_term_list field_term
14495        | field_term
14496        ;
14497
14498field_term:
14499          TERMINATED BY text_string
14500          {
14501            DBUG_ASSERT(Lex->exchange != 0);
14502            Lex->exchange->field_term= $3;
14503          }
14504        | OPTIONALLY ENCLOSED BY text_string
14505          {
14506            LEX *lex= Lex;
14507            DBUG_ASSERT(lex->exchange != 0);
14508            lex->exchange->enclosed= $4;
14509            lex->exchange->opt_enclosed= 1;
14510          }
14511        | ENCLOSED BY text_string
14512          {
14513            DBUG_ASSERT(Lex->exchange != 0);
14514            Lex->exchange->enclosed= $3;
14515          }
14516        | ESCAPED BY text_string
14517          {
14518            DBUG_ASSERT(Lex->exchange != 0);
14519            Lex->exchange->escaped= $3;
14520          }
14521        ;
14522
14523opt_line_term:
14524          /* empty */
14525        | LINES line_term_list
14526        ;
14527
14528line_term_list:
14529          line_term_list line_term
14530        | line_term
14531        ;
14532
14533line_term:
14534          TERMINATED BY text_string
14535          {
14536            DBUG_ASSERT(Lex->exchange != 0);
14537            Lex->exchange->line_term= $3;
14538          }
14539        | STARTING BY text_string
14540          {
14541            DBUG_ASSERT(Lex->exchange != 0);
14542            Lex->exchange->line_start= $3;
14543          }
14544        ;
14545
14546opt_xml_rows_identified_by:
14547        /* empty */ { }
14548        | ROWS_SYM IDENTIFIED_SYM BY text_string
14549          { Lex->exchange->line_term = $4; }
14550        ;
14551
14552opt_ignore_lines:
14553          /* empty */
14554        | IGNORE_SYM NUM lines_or_rows
14555          {
14556            DBUG_ASSERT(Lex->exchange != 0);
14557            Lex->exchange->skip_lines= atol($2.str);
14558          }
14559        ;
14560
14561lines_or_rows:
14562          LINES { }
14563        | ROWS_SYM { }
14564        ;
14565
14566opt_field_or_var_spec:
14567          /* empty */ {}
14568        | '(' fields_or_vars ')' {}
14569        | '(' ')' {}
14570        ;
14571
14572fields_or_vars:
14573          fields_or_vars ',' field_or_var
14574          { Lex->field_list.push_back($3, thd->mem_root); }
14575        | field_or_var
14576          { Lex->field_list.push_back($1, thd->mem_root); }
14577        ;
14578
14579field_or_var:
14580          simple_ident_nospvar {$$= $1;}
14581        | '@' ident_or_text
14582          {
14583            $$= new (thd->mem_root) Item_user_var_as_out_param(thd, &$2);
14584            if (unlikely($$ == NULL))
14585              MYSQL_YYABORT;
14586          }
14587        ;
14588
14589opt_load_data_set_spec:
14590          /* empty */ {}
14591        | SET load_data_set_list {}
14592        ;
14593
14594load_data_set_list:
14595          load_data_set_list ',' load_data_set_elem
14596        | load_data_set_elem
14597        ;
14598
14599load_data_set_elem:
14600          simple_ident_nospvar equal remember_name expr_or_ignore_or_default remember_end
14601          {
14602            LEX *lex= Lex;
14603            if (unlikely(lex->update_list.push_back($1, thd->mem_root)) ||
14604                unlikely(lex->value_list.push_back($4, thd->mem_root)))
14605                MYSQL_YYABORT;
14606            $4->set_name_no_truncate(thd, $3, (uint) ($5 - $3), thd->charset());
14607          }
14608        ;
14609
14610/* Common definitions */
14611
14612text_literal:
14613          TEXT_STRING
14614          {
14615            if (unlikely(!($$= thd->make_string_literal($1))))
14616              MYSQL_YYABORT;
14617          }
14618        | NCHAR_STRING
14619          {
14620            if (unlikely(!($$= thd->make_string_literal_nchar($1))))
14621              MYSQL_YYABORT;
14622          }
14623        | UNDERSCORE_CHARSET TEXT_STRING
14624          {
14625            if (unlikely(!($$= thd->make_string_literal_charset($2, $1))))
14626              MYSQL_YYABORT;
14627          }
14628        | text_literal TEXT_STRING_literal
14629          {
14630            if (unlikely(!($$= $1->make_string_literal_concat(thd, &$2))))
14631              MYSQL_YYABORT;
14632          }
14633        ;
14634
14635text_string:
14636          TEXT_STRING_literal
14637          {
14638            $$= new (thd->mem_root) String($1.str,
14639                                             $1.length,
14640                                             thd->variables.collation_connection);
14641            if (unlikely($$ == NULL))
14642              MYSQL_YYABORT;
14643          }
14644          | hex_or_bin_String { $$= $1; }
14645          ;
14646
14647
14648hex_or_bin_String:
14649          HEX_NUM
14650          {
14651            Item *tmp= new (thd->mem_root) Item_hex_hybrid(thd, $1.str,
14652                                                           $1.length);
14653            if (unlikely(tmp == NULL))
14654              MYSQL_YYABORT;
14655            $$= tmp->val_str((String*) 0);
14656          }
14657        | HEX_STRING
14658          {
14659            Item *tmp= new (thd->mem_root) Item_hex_string(thd, $1.str,
14660                                                           $1.length);
14661            if (unlikely(tmp == NULL))
14662              MYSQL_YYABORT;
14663            $$= tmp->val_str((String*) 0);
14664          }
14665        | BIN_NUM
14666          {
14667            Item *tmp= new (thd->mem_root) Item_bin_string(thd, $1.str,
14668                                                           $1.length);
14669            if (unlikely(tmp == NULL))
14670              MYSQL_YYABORT;
14671            /*
14672              it is OK only emulate fix_fields, because we need only
14673              value of constant
14674            */
14675            $$= tmp->val_str((String*) 0);
14676          }
14677        ;
14678
14679param_marker:
14680          PARAM_MARKER
14681          {
14682            if (unlikely(!($$= Lex->add_placeholder(thd, &param_clex_str,
14683                                                    YYLIP->get_tok_start(),
14684                                                    YYLIP->get_tok_start() + 1))))
14685              MYSQL_YYABORT;
14686          }
14687        | COLON_ORACLE_SYM ident_cli
14688          {
14689            if (unlikely(!($$= Lex->add_placeholder(thd, &null_clex_str,
14690                                                    $1.pos(), $2.end()))))
14691              MYSQL_YYABORT;
14692          }
14693        | COLON_ORACLE_SYM NUM
14694          {
14695            if (unlikely(!($$= Lex->add_placeholder(thd, &null_clex_str,
14696                                                    $1.pos(),
14697                                                    YYLIP->get_ptr()))))
14698              MYSQL_YYABORT;
14699          }
14700        ;
14701
14702signed_literal:
14703        '+' NUM_literal { $$ = $2; }
14704        | '-' NUM_literal
14705          {
14706            $2->max_length++;
14707            $$= $2->neg(thd);
14708          }
14709        ;
14710
14711literal:
14712          text_literal { $$ = $1; }
14713        | NUM_literal { $$ = $1; }
14714        | temporal_literal { $$= $1; }
14715        | NULL_SYM
14716          {
14717            /*
14718              For the digest computation, in this context only,
14719              NULL is considered a literal, hence reduced to '?'
14720              REDUCE:
14721                TOK_GENERIC_VALUE := NULL_SYM
14722            */
14723            YYLIP->reduce_digest_token(TOK_GENERIC_VALUE, NULL_SYM);
14724            $$= new (thd->mem_root) Item_null(thd);
14725            if (unlikely($$ == NULL))
14726              MYSQL_YYABORT;
14727            YYLIP->next_state= MY_LEX_OPERATOR_OR_IDENT;
14728          }
14729        | FALSE_SYM
14730          {
14731            $$= new (thd->mem_root) Item_bool(thd, (char*) "FALSE",0);
14732            if (unlikely($$ == NULL))
14733              MYSQL_YYABORT;
14734          }
14735        | TRUE_SYM
14736          {
14737            $$= new (thd->mem_root) Item_bool(thd, (char*) "TRUE",1);
14738            if (unlikely($$ == NULL))
14739              MYSQL_YYABORT;
14740          }
14741        | HEX_NUM
14742          {
14743            $$= new (thd->mem_root) Item_hex_hybrid(thd, $1.str, $1.length);
14744            if (unlikely($$ == NULL))
14745              MYSQL_YYABORT;
14746          }
14747        | HEX_STRING
14748          {
14749            $$= new (thd->mem_root) Item_hex_string(thd, $1.str, $1.length);
14750            if (unlikely($$ == NULL))
14751              MYSQL_YYABORT;
14752          }
14753        | BIN_NUM
14754          {
14755            $$= new (thd->mem_root) Item_bin_string(thd, $1.str, $1.length);
14756            if (unlikely($$ == NULL))
14757              MYSQL_YYABORT;
14758          }
14759        | UNDERSCORE_CHARSET hex_or_bin_String
14760          {
14761            Item_string_with_introducer *item_str;
14762            LEX_CSTRING tmp;
14763            $2->get_value(&tmp);
14764            /*
14765              Pass NULL as name. Name will be set in the "select_item" rule and
14766              will include the introducer and the original hex/bin notation.
14767            */
14768            item_str= new (thd->mem_root)
14769               Item_string_with_introducer(thd, null_clex_str,
14770                                           tmp, $1);
14771            if (unlikely(!item_str ||
14772                         !item_str->check_well_formed_result(true)))
14773              MYSQL_YYABORT;
14774
14775            $$= item_str;
14776          }
14777        ;
14778
14779NUM_literal:
14780          NUM
14781          {
14782            int error;
14783            $$= new (thd->mem_root)
14784                  Item_int(thd, $1.str,
14785                           (longlong) my_strtoll10($1.str, NULL, &error),
14786                           $1.length);
14787            if (unlikely($$ == NULL))
14788              MYSQL_YYABORT;
14789          }
14790        | LONG_NUM
14791          {
14792            int error;
14793            $$= new (thd->mem_root)
14794                  Item_int(thd, $1.str,
14795                           (longlong) my_strtoll10($1.str, NULL, &error),
14796                           $1.length);
14797            if (unlikely($$ == NULL))
14798              MYSQL_YYABORT;
14799          }
14800        | ULONGLONG_NUM
14801          {
14802            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
14803            if (unlikely($$ == NULL))
14804              MYSQL_YYABORT;
14805          }
14806        | DECIMAL_NUM
14807          {
14808            $$= new (thd->mem_root) Item_decimal(thd, $1.str, $1.length,
14809                                                   thd->charset());
14810            if (unlikely($$ == NULL) || unlikely(thd->is_error()))
14811              MYSQL_YYABORT;
14812          }
14813        | FLOAT_NUM
14814          {
14815            $$= new (thd->mem_root) Item_float(thd, $1.str, $1.length);
14816            if (unlikely($$ == NULL) || unlikely(thd->is_error()))
14817              MYSQL_YYABORT;
14818          }
14819        ;
14820
14821
14822temporal_literal:
14823        DATE_SYM TEXT_STRING
14824          {
14825            if (unlikely(!($$= type_handler_newdate.create_literal_item(thd,
14826                                                           $2.str, $2.length,
14827                                                           YYCSCL, true))))
14828              MYSQL_YYABORT;
14829          }
14830        | TIME_SYM TEXT_STRING
14831          {
14832            if (unlikely(!($$= type_handler_time2.create_literal_item(thd,
14833                                                         $2.str, $2.length,
14834                                                         YYCSCL, true))))
14835              MYSQL_YYABORT;
14836          }
14837        | TIMESTAMP TEXT_STRING
14838          {
14839            if (unlikely(!($$= type_handler_datetime.create_literal_item(thd,
14840                                                            $2.str, $2.length,
14841                                                            YYCSCL, true))))
14842              MYSQL_YYABORT;
14843          }
14844        ;
14845
14846with_clause:
14847          WITH opt_recursive
14848          {
14849             LEX *lex= Lex;
14850             With_clause *with_clause=
14851             new With_clause($2, Lex->curr_with_clause);
14852             if (unlikely(with_clause == NULL))
14853               MYSQL_YYABORT;
14854             lex->derived_tables|= DERIVED_WITH;
14855             lex->with_cte_resolution= true;
14856             lex->curr_with_clause= with_clause;
14857             with_clause->add_to_list(Lex->with_clauses_list_last_next);
14858             if (lex->current_select &&
14859                 lex->current_select->parsing_place == BEFORE_OPT_LIST)
14860               lex->current_select->parsing_place= NO_MATTER;
14861          }
14862          with_list
14863          {
14864            $$= Lex->curr_with_clause;
14865            Lex->curr_with_clause= Lex->curr_with_clause->pop();
14866          }
14867        ;
14868
14869
14870opt_recursive:
14871 	  /*empty*/ { $$= 0; }
14872	| RECURSIVE_SYM { $$= 1; }
14873	;
14874
14875
14876with_list:
14877	  with_list_element
14878	| with_list ',' with_list_element
14879	;
14880
14881
14882with_list_element:
14883          with_element_head
14884	  opt_with_column_list
14885          AS '(' query_expression ')' opt_cycle
14886 	  {
14887            LEX *lex= thd->lex;
14888            const char *query_start= lex->sphead ? lex->sphead->m_tmp_query
14889                                                 : thd->query();
14890            const char *spec_start= $4.pos() + 1;
14891            With_element *elem= new With_element($1, *$2, $5);
14892	    if (elem == NULL || Lex->curr_with_clause->add_with_element(elem))
14893	      MYSQL_YYABORT;
14894            if (elem->set_unparsed_spec(thd, spec_start, $6.pos(),
14895                                        spec_start - query_start))
14896              MYSQL_YYABORT;
14897            if ($7)
14898            {
14899              elem->set_cycle_list($7);
14900            }
14901            elem->set_tables_end_pos(lex->query_tables_last);
14902	  }
14903	;
14904
14905opt_cycle:
14906         /* empty */
14907         { $$= NULL; }
14908         |
14909         CYCLE_SYM
14910         {
14911           if (!Lex->curr_with_clause->with_recursive)
14912           {
14913             thd->parse_error(ER_SYNTAX_ERROR, $1.pos());
14914           }
14915         }
14916         comma_separated_ident_list RESTRICT
14917         {
14918           $$= $3;
14919         }
14920         ;
14921
14922
14923opt_with_column_list:
14924          /* empty */
14925          {
14926            if (($$= new (thd->mem_root) List<Lex_ident_sys>) == NULL)
14927              MYSQL_YYABORT;
14928          }
14929        | '(' with_column_list ')'
14930          { $$= $2; }
14931        ;
14932
14933with_column_list:
14934          comma_separated_ident_list
14935        ;
14936
14937ident_sys_alloc:
14938          ident_cli
14939          {
14940            void *buf= thd->alloc(sizeof(Lex_ident_sys));
14941            if (!buf)
14942              MYSQL_YYABORT;
14943            $$= new (buf) Lex_ident_sys(thd, &$1);
14944          }
14945        ;
14946
14947comma_separated_ident_list:
14948          ident_sys_alloc
14949          {
14950            $$= new (thd->mem_root) List<Lex_ident_sys>;
14951            if (unlikely($$ == NULL || $$->push_back($1)))
14952              MYSQL_YYABORT;
14953	  }
14954        | comma_separated_ident_list ',' ident_sys_alloc
14955          {
14956            if (($$= $1)->push_back($3))
14957              MYSQL_YYABORT;
14958          }
14959        ;
14960
14961
14962with_element_head:
14963          ident
14964          {
14965            LEX_CSTRING *name=
14966              (LEX_CSTRING *) thd->memdup(&$1, sizeof(LEX_CSTRING));
14967            $$= new (thd->mem_root) With_element_head(name);
14968            if (unlikely(name == NULL || $$ == NULL))
14969              MYSQL_YYABORT;
14970            $$->tables_pos.set_start_pos(Lex->query_tables_last);
14971          }
14972        ;
14973
14974
14975
14976/**********************************************************************
14977** Creating different items.
14978**********************************************************************/
14979
14980insert_ident:
14981          simple_ident_nospvar { $$=$1; }
14982        | table_wild { $$=$1; }
14983        ;
14984
14985table_wild:
14986          ident '.' '*'
14987          {
14988            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1))))
14989              MYSQL_YYABORT;
14990          }
14991        | ident '.' ident '.' '*'
14992          {
14993            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1, &$3))))
14994              MYSQL_YYABORT;
14995          }
14996        ;
14997
14998select_sublist_qualified_asterisk:
14999          ident_cli '.' '*'
15000          {
15001            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1))))
15002              MYSQL_YYABORT;
15003          }
15004        | ident_cli '.' ident_cli '.' '*'
15005          {
15006            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1, &$3))))
15007              MYSQL_YYABORT;
15008          }
15009        ;
15010
15011order_ident:
15012          expr { $$=$1; }
15013        ;
15014
15015
15016simple_ident:
15017          ident_cli
15018          {
15019            if (unlikely(!($$= Lex->create_item_ident(thd, &$1))))
15020              MYSQL_YYABORT;
15021          }
15022        | ident_cli '.' ident_cli
15023          {
15024            if (unlikely(!($$= Lex->create_item_ident(thd, &$1, &$3))))
15025              MYSQL_YYABORT;
15026          }
15027        | '.' ident_cli '.' ident_cli
15028          {
15029            Lex_ident_cli empty($2.pos(), 0);
15030            if (unlikely(!($$= Lex->create_item_ident(thd, &empty, &$2, &$4))))
15031              MYSQL_YYABORT;
15032          }
15033        | ident_cli '.' ident_cli '.' ident_cli
15034          {
15035            if (unlikely(!($$= Lex->create_item_ident(thd, &$1, &$3, &$5))))
15036              MYSQL_YYABORT;
15037          }
15038        | COLON_ORACLE_SYM ident_cli '.' ident_cli
15039          {
15040            if (unlikely(!($$= Lex->make_item_colon_ident_ident(thd, &$2, &$4))))
15041              MYSQL_YYABORT;
15042          }
15043        ;
15044
15045simple_ident_nospvar:
15046          ident
15047          {
15048            if (unlikely(!($$= Lex->create_item_ident_nosp(thd, &$1))))
15049              MYSQL_YYABORT;
15050          }
15051        | ident '.' ident
15052          {
15053            if (unlikely(!($$= Lex->create_item_ident_nospvar(thd, &$1, &$3))))
15054              MYSQL_YYABORT;
15055          }
15056        | COLON_ORACLE_SYM ident_cli '.' ident_cli
15057          {
15058            if (unlikely(!($$= Lex->make_item_colon_ident_ident(thd, &$2, &$4))))
15059              MYSQL_YYABORT;
15060          }
15061        | '.' ident '.' ident
15062          {
15063            Lex_ident_sys none;
15064            if (unlikely(!($$= Lex->create_item_ident(thd, &none, &$2, &$4))))
15065              MYSQL_YYABORT;
15066          }
15067        | ident '.' ident '.' ident
15068          {
15069            if (unlikely(!($$= Lex->create_item_ident(thd, &$1, &$3, &$5))))
15070              MYSQL_YYABORT;
15071          }
15072        ;
15073
15074field_ident:
15075          ident { $$=$1;}
15076        | ident '.' ident '.' ident
15077          {
15078            TABLE_LIST *table= Select->table_list.first;
15079            if (unlikely(my_strcasecmp(table_alias_charset, $1.str,
15080                                       table->db.str)))
15081              my_yyabort_error((ER_WRONG_DB_NAME, MYF(0), $1.str));
15082            if (unlikely(my_strcasecmp(table_alias_charset, $3.str,
15083                                       table->table_name.str)))
15084              my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $3.str));
15085            $$=$5;
15086          }
15087        | ident '.' ident
15088          {
15089            TABLE_LIST *table= Select->table_list.first;
15090            if (unlikely(my_strcasecmp(table_alias_charset, $1.str,
15091                         table->alias.str)))
15092              my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $1.str));
15093            $$=$3;
15094          }
15095        | '.' ident { $$=$2;} /* For Delphi */
15096        ;
15097
15098table_ident:
15099          ident
15100          {
15101            $$= new (thd->mem_root) Table_ident(&$1);
15102            if (unlikely($$ == NULL))
15103              MYSQL_YYABORT;
15104          }
15105        | ident '.' ident
15106          {
15107            $$= new (thd->mem_root) Table_ident(thd, &$1, &$3, 0);
15108            if (unlikely($$ == NULL))
15109              MYSQL_YYABORT;
15110          }
15111        | '.' ident
15112          {
15113            /* For Delphi */
15114            $$= new (thd->mem_root) Table_ident(&$2);
15115            if (unlikely($$ == NULL))
15116              MYSQL_YYABORT;
15117          }
15118        ;
15119
15120table_ident_opt_wild:
15121          ident opt_wild
15122          {
15123            $$= new (thd->mem_root) Table_ident(&$1);
15124            if (unlikely($$ == NULL))
15125              MYSQL_YYABORT;
15126          }
15127        | ident '.' ident opt_wild
15128          {
15129            $$= new (thd->mem_root) Table_ident(thd, &$1, &$3, 0);
15130            if (unlikely($$ == NULL))
15131              MYSQL_YYABORT;
15132          }
15133        ;
15134
15135table_ident_nodb:
15136          ident
15137          {
15138            LEX_CSTRING db={(char*) any_db,3};
15139            $$= new (thd->mem_root) Table_ident(thd, &db, &$1, 0);
15140            if (unlikely($$ == NULL))
15141              MYSQL_YYABORT;
15142          }
15143        ;
15144
15145IDENT_cli:
15146          IDENT
15147        | IDENT_QUOTED
15148        ;
15149
15150ident_cli:
15151          IDENT
15152        | IDENT_QUOTED
15153        | keyword_ident { $$= $1; }
15154        ;
15155
15156IDENT_sys:
15157          IDENT_cli
15158          {
15159            if (unlikely(thd->to_ident_sys_alloc(&$$, &$1)))
15160              MYSQL_YYABORT;
15161          }
15162        ;
15163
15164TEXT_STRING_sys:
15165          TEXT_STRING
15166          {
15167            if (thd->make_text_string_sys(&$$, &$1))
15168              MYSQL_YYABORT;
15169          }
15170        ;
15171
15172TEXT_STRING_literal:
15173          TEXT_STRING
15174          {
15175            if (thd->make_text_string_connection(&$$, &$1))
15176              MYSQL_YYABORT;
15177          }
15178        ;
15179
15180TEXT_STRING_filesystem:
15181          TEXT_STRING
15182          {
15183            if (thd->make_text_string_filesystem(&$$, &$1))
15184              MYSQL_YYABORT;
15185          }
15186        ;
15187
15188ident_table_alias:
15189          IDENT_sys
15190        | keyword_table_alias
15191          {
15192            if (unlikely($$.copy_keyword(thd, &$1)))
15193              MYSQL_YYABORT;
15194          }
15195        ;
15196
15197ident_cli_set_usual_case:
15198          IDENT_cli { $$= $1; }
15199        | keyword_set_usual_case { $$= $1; }
15200        ;
15201
15202ident_sysvar_name:
15203          IDENT_sys
15204        | keyword_sysvar_name
15205          {
15206            if (unlikely($$.copy_keyword(thd, &$1)))
15207              MYSQL_YYABORT;
15208          }
15209        | TEXT_STRING_sys
15210          {
15211            if (unlikely($$.copy_sys(thd, &$1)))
15212              MYSQL_YYABORT;
15213          }
15214        ;
15215
15216
15217ident:
15218          IDENT_sys
15219        | keyword_ident
15220          {
15221            if (unlikely($$.copy_keyword(thd, &$1)))
15222              MYSQL_YYABORT;
15223          }
15224        ;
15225
15226label_ident:
15227          IDENT_sys
15228        | keyword_label
15229          {
15230            if (unlikely($$.copy_keyword(thd, &$1)))
15231              MYSQL_YYABORT;
15232          }
15233        ;
15234
15235ident_or_text:
15236          ident           { $$=$1;}
15237        | TEXT_STRING_sys { $$=$1;}
15238        | LEX_HOSTNAME { $$=$1;}
15239        ;
15240
15241user_maybe_role:
15242          ident_or_text
15243          {
15244            if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER)))))
15245              MYSQL_YYABORT;
15246            $$->user = $1;
15247
15248            if (unlikely(check_string_char_length(&$$->user, ER_USERNAME,
15249                                                  username_char_length,
15250                                                  system_charset_info, 0)))
15251              MYSQL_YYABORT;
15252          }
15253        | ident_or_text '@' ident_or_text
15254          {
15255            if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER)))))
15256              MYSQL_YYABORT;
15257            $$->user = $1; $$->host=$3;
15258
15259            if (unlikely(check_string_char_length(&$$->user, ER_USERNAME,
15260                                                  username_char_length,
15261                                                 system_charset_info, 0)) ||
15262                unlikely(check_host_name(&$$->host)))
15263              MYSQL_YYABORT;
15264            if ($$->host.str[0])
15265            {
15266              /*
15267                Convert hostname part of username to lowercase.
15268                It's OK to use in-place lowercase as long as
15269                the character set is utf8.
15270              */
15271              my_casedn_str(system_charset_info, (char*) $$->host.str);
15272            }
15273            else
15274            {
15275              /*
15276                fix historical undocumented convention that empty host is the
15277                same as '%'
15278              */
15279              $$->host= host_not_specified;
15280            }
15281          }
15282        | CURRENT_USER optional_braces
15283          {
15284            if (unlikely(!($$=(LEX_USER*)thd->calloc(sizeof(LEX_USER)))))
15285              MYSQL_YYABORT;
15286            $$->user= current_user;
15287            $$->auth= new (thd->mem_root) USER_AUTH();
15288          }
15289        ;
15290
15291user_or_role: user_maybe_role | current_role;
15292
15293user: user_maybe_role
15294         {
15295           if ($1->user.str != current_user.str && $1->host.str == 0)
15296             $1->host= host_not_specified;
15297           $$= $1;
15298         }
15299         ;
15300
15301/* Keywords which we allow as table aliases. */
15302keyword_table_alias:
15303          keyword_data_type
15304        | keyword_cast_type
15305        | keyword_set_special_case
15306        | keyword_sp_block_section
15307        | keyword_sp_head
15308        | keyword_sp_var_and_label
15309        | keyword_sp_var_not_label
15310        | keyword_sysvar_type
15311        | keyword_verb_clause
15312        | FUNCTION_SYM
15313        | EXCEPTION_ORACLE_SYM
15314        ;
15315
15316/* Keyword that we allow for identifiers (except SP labels) */
15317keyword_ident:
15318          keyword_data_type
15319        | keyword_cast_type
15320        | keyword_set_special_case
15321        | keyword_sp_block_section
15322        | keyword_sp_head
15323        | keyword_sp_var_and_label
15324        | keyword_sp_var_not_label
15325        | keyword_sysvar_type
15326        | keyword_verb_clause
15327        | FUNCTION_SYM
15328        | WINDOW_SYM
15329        | EXCEPTION_ORACLE_SYM
15330        ;
15331
15332keyword_sysvar_name:
15333          keyword_data_type
15334        | keyword_cast_type
15335        | keyword_set_special_case
15336        | keyword_sp_block_section
15337        | keyword_sp_head
15338        | keyword_sp_var_and_label
15339        | keyword_sp_var_not_label
15340        | keyword_verb_clause
15341        | FUNCTION_SYM
15342        | WINDOW_SYM
15343        | EXCEPTION_ORACLE_SYM
15344        ;
15345
15346keyword_set_usual_case:
15347          keyword_data_type
15348        | keyword_cast_type
15349        | keyword_sp_block_section
15350        | keyword_sp_head
15351        | keyword_sp_var_and_label
15352        | keyword_sp_var_not_label
15353        | keyword_sysvar_type
15354        | keyword_verb_clause
15355        | FUNCTION_SYM
15356        | WINDOW_SYM
15357        | EXCEPTION_ORACLE_SYM
15358        ;
15359
15360non_reserved_keyword_udt:
15361          keyword_sp_var_not_label
15362        | keyword_sp_head
15363        | keyword_verb_clause
15364        | keyword_set_special_case
15365        | keyword_sp_block_section
15366        | keyword_sysvar_type
15367        | keyword_sp_var_and_label
15368        ;
15369
15370/*
15371  Keywords that we allow in Oracle-style direct assignments:
15372    xxx := 10;
15373  but do not allow in labels in the default sql_mode:
15374    label:
15375      stmt1;
15376      stmt2;
15377  TODO: check if some of them can migrate to keyword_sp_var_and_label.
15378*/
15379keyword_sp_var_not_label:
15380          ASCII_SYM
15381        | BACKUP_SYM
15382        | BINLOG_SYM
15383        | BYTE_SYM
15384        | CACHE_SYM
15385        | CHECKSUM_SYM
15386        | CHECKPOINT_SYM
15387        | COLUMN_ADD_SYM
15388        | COLUMN_CHECK_SYM
15389        | COLUMN_CREATE_SYM
15390        | COLUMN_DELETE_SYM
15391        | COLUMN_GET_SYM
15392        | COMMENT_SYM
15393        | COMPRESSED_SYM
15394        | DEALLOCATE_SYM
15395        | EXAMINED_SYM
15396        | EXCLUDE_SYM
15397        | EXECUTE_SYM
15398        | FLUSH_SYM
15399        | FOLLOWING_SYM
15400        | FORMAT_SYM
15401        | GET_SYM
15402        | HELP_SYM
15403        | HOST_SYM
15404        | INSTALL_SYM
15405        | OPTION
15406        | OPTIONS_SYM
15407        | OTHERS_MARIADB_SYM
15408        | OWNER_SYM
15409        | PARSER_SYM
15410        | PERIOD_SYM
15411        | PORT_SYM
15412        | PRECEDING_SYM
15413        | PREPARE_SYM
15414        | REMOVE_SYM
15415        | RESET_SYM
15416        | RESTORE_SYM
15417        | SECURITY_SYM
15418        | SERVER_SYM
15419        | SOCKET_SYM
15420        | SLAVE
15421        | SLAVES
15422        | SONAME_SYM
15423        | START_SYM
15424        | STOP_SYM
15425        | STORED_SYM
15426        | TIES_SYM
15427        | UNICODE_SYM
15428        | UNINSTALL_SYM
15429        | UNBOUNDED_SYM
15430        | WITHIN
15431        | WRAPPER_SYM
15432        | XA_SYM
15433        | UPGRADE_SYM
15434        ;
15435
15436/*
15437  Keywords that can start optional clauses in SP or trigger declarations
15438  Allowed as identifiers (e.g. table, column names),
15439  but:
15440  - not allowed as SP label names
15441  - not allowed as variable names in Oracle-style assignments:
15442    xxx := 10;
15443
15444  If we allowed these variables in assignments, there would be conflicts
15445  with SP characteristics, or verb clauses, or compound statements, e.g.:
15446    CREATE PROCEDURE p1 LANGUAGE ...
15447  would be either:
15448    CREATE PROCEDURE p1 LANGUAGE SQL BEGIN END;
15449  or
15450    CREATE PROCEDURE p1 LANGUAGE:=10;
15451
15452  Note, these variables can still be assigned using quoted identifiers:
15453    `do`:= 10;
15454    "do":= 10; (when ANSI_QUOTES)
15455  or using a SET statement:
15456    SET do= 10;
15457
15458  Note, some of these keywords are reserved keywords in Oracle.
15459  In case if heavy grammar conflicts are found in the future,
15460  we'll possibly need to make them reserved for sql_mode=ORACLE.
15461
15462  TODO: Allow these variables as SP lables when sql_mode=ORACLE.
15463  TODO: Allow assigning of "SP characteristics" marked variables
15464        inside compound blocks.
15465  TODO: Allow "follows" and "precedes" as variables in compound blocks:
15466        BEGIN
15467          follows := 10;
15468        END;
15469        as they conflict only with non-block FOR EACH ROW statement:
15470          CREATE TRIGGER .. FOR EACH ROW follows:= 10;
15471          CREATE TRIGGER .. FOR EACH ROW FOLLOWS tr1 a:= 10;
15472*/
15473keyword_sp_head:
15474          CONTAINS_SYM           /* SP characteristic               */
15475        | LANGUAGE_SYM           /* SP characteristic               */
15476        | NO_SYM                 /* SP characteristic               */
15477        | CHARSET                /* SET CHARSET utf8;               */
15478        | FOLLOWS_SYM            /* Conflicts with assignment in FOR EACH */
15479        | PRECEDES_SYM           /* Conflicts with assignment in FOR EACH */
15480        ;
15481
15482/*
15483  Keywords that start a statement.
15484  Generally allowed as identifiers (e.g. table, column names)
15485  - not allowed as SP label names
15486  - not allowed as variable names in Oracle-style assignments:
15487    xxx:=10
15488*/
15489keyword_verb_clause:
15490          CLOSE_SYM             /* Verb clause. Reserved in Oracle */
15491        | COMMIT_SYM            /* Verb clause. Reserved in Oracle */
15492        | DO_SYM                /* Verb clause                     */
15493        | HANDLER_SYM           /* Verb clause                     */
15494        | OPEN_SYM              /* Verb clause. Reserved in Oracle */
15495        | REPAIR                /* Verb clause                     */
15496        | ROLLBACK_SYM          /* Verb clause. Reserved in Oracle */
15497        | SAVEPOINT_SYM         /* Verb clause. Reserved in Oracle */
15498        | SHUTDOWN              /* Verb clause                     */
15499        | TRUNCATE_SYM          /* Verb clause. Reserved in Oracle */
15500        ;
15501
15502keyword_set_special_case:
15503          NAMES_SYM
15504        | ROLE_SYM
15505        | PASSWORD_SYM
15506        ;
15507
15508keyword_sysvar_type:
15509          GLOBAL_SYM
15510        | LOCAL_SYM
15511        | SESSION_SYM
15512        ;
15513
15514
15515/*
15516  These keywords are generally allowed as identifiers,
15517  but not allowed as non-delimited SP variable names in sql_mode=ORACLE.
15518*/
15519keyword_data_type:
15520          BIT_SYM
15521        | BOOLEAN_SYM
15522        | BOOL_SYM
15523        | CLOB_MARIADB_SYM
15524        | CLOB_ORACLE_SYM
15525        | DATE_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
15526        | DATETIME
15527        | ENUM
15528        | FIXED_SYM
15529        | JSON_SYM
15530        | MEDIUM_SYM
15531        | NATIONAL_SYM
15532        | NCHAR_SYM
15533        | NUMBER_MARIADB_SYM
15534        | NUMBER_ORACLE_SYM
15535        | NVARCHAR_SYM
15536        | RAW_MARIADB_SYM
15537        | RAW_ORACLE_SYM
15538        | ROW_SYM
15539        | SERIAL_SYM
15540        | TEXT_SYM
15541        | TIMESTAMP          %prec PREC_BELOW_CONTRACTION_TOKEN2
15542        | TIME_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
15543        | VARCHAR2_MARIADB_SYM
15544        | VARCHAR2_ORACLE_SYM
15545        | YEAR_SYM
15546        ;
15547
15548
15549keyword_cast_type:
15550          SIGNED_SYM
15551        ;
15552
15553
15554/*
15555  These keywords are fine for both SP variable names and SP labels.
15556*/
15557keyword_sp_var_and_label:
15558          ACTION
15559        | ACCOUNT_SYM
15560        | ADDDATE_SYM
15561        | ADMIN_SYM
15562        | AFTER_SYM
15563        | AGAINST
15564        | AGGREGATE_SYM
15565        | ALGORITHM_SYM
15566        | ALWAYS_SYM
15567        | ANY_SYM
15568        | AT_SYM
15569        | ATOMIC_SYM
15570        | AUTHORS_SYM
15571        | AUTO_INC
15572        | AUTOEXTEND_SIZE_SYM
15573        | AUTO_SYM
15574        | AVG_ROW_LENGTH
15575        | AVG_SYM
15576        | BLOCK_SYM
15577        | BODY_MARIADB_SYM
15578        | BTREE_SYM
15579        | CASCADED
15580        | CATALOG_NAME_SYM
15581        | CHAIN_SYM
15582        | CHANGED
15583        | CIPHER_SYM
15584        | CLIENT_SYM
15585        | CLASS_ORIGIN_SYM
15586        | COALESCE
15587        | CODE_SYM
15588        | COLLATION_SYM
15589        | COLUMN_NAME_SYM
15590        | COLUMNS
15591        | COMMITTED_SYM
15592        | COMPACT_SYM
15593        | COMPLETION_SYM
15594        | CONCURRENT
15595        | CONNECTION_SYM
15596        | CONSISTENT_SYM
15597        | CONSTRAINT_CATALOG_SYM
15598        | CONSTRAINT_SCHEMA_SYM
15599        | CONSTRAINT_NAME_SYM
15600        | CONTEXT_SYM
15601        | CONTRIBUTORS_SYM
15602        | CURRENT_POS_SYM
15603        | CPU_SYM
15604        | CUBE_SYM
15605        /*
15606          Although a reserved keyword in SQL:2003 (and :2008),
15607          not reserved in MySQL per WL#2111 specification.
15608        */
15609        | CURRENT_SYM
15610        | CURSOR_NAME_SYM
15611        | CYCLE_SYM
15612        | DATA_SYM
15613        | DATAFILE_SYM
15614        | DATE_FORMAT_SYM
15615        | DAY_SYM
15616        | DECODE_MARIADB_SYM
15617        | DECODE_ORACLE_SYM
15618        | DEFINER_SYM
15619        | DELAY_KEY_WRITE_SYM
15620        | DES_KEY_FILE
15621        | DIAGNOSTICS_SYM
15622        | DIRECTORY_SYM
15623        | DISABLE_SYM
15624        | DISCARD
15625        | DISK_SYM
15626        | DUMPFILE
15627        | DUPLICATE_SYM
15628        | DYNAMIC_SYM
15629        | ELSEIF_ORACLE_SYM
15630        | ELSIF_MARIADB_SYM
15631        | ENDS_SYM
15632        | ENGINE_SYM
15633        | ENGINES_SYM
15634        | ERROR_SYM
15635        | ERRORS
15636        | ESCAPE_SYM
15637        | EVENT_SYM
15638        | EVENTS_SYM
15639        | EVERY_SYM
15640        | EXCEPTION_MARIADB_SYM
15641        | EXCHANGE_SYM
15642        | EXPANSION_SYM
15643        | EXPIRE_SYM
15644        | EXPORT_SYM
15645        | EXTENDED_SYM
15646        | EXTENT_SIZE_SYM
15647        | FAULTS_SYM
15648        | FAST_SYM
15649        | FOUND_SYM
15650        | ENABLE_SYM
15651        | FEDERATED_SYM
15652        | FULL
15653        | FILE_SYM
15654        | FIRST_SYM
15655        | GENERAL
15656        | GENERATED_SYM
15657        | GET_FORMAT
15658        | GRANTS
15659        | GOTO_MARIADB_SYM
15660        | HASH_SYM
15661        | HARD_SYM
15662        | HISTORY_SYM
15663        | HOSTS_SYM
15664        | HOUR_SYM
15665        | ID_SYM
15666        | IDENTIFIED_SYM
15667        | IGNORE_SERVER_IDS_SYM
15668        | INCREMENT_SYM
15669        | IMMEDIATE_SYM
15670        | INVOKER_SYM
15671        | IMPORT
15672        | INDEXES
15673        | INITIAL_SIZE_SYM
15674        | IO_SYM
15675        | IPC_SYM
15676        | ISOLATION
15677        | ISOPEN_SYM
15678        | ISSUER_SYM
15679        | INSERT_METHOD
15680        | INVISIBLE_SYM
15681        | KEY_BLOCK_SIZE
15682        | LAST_VALUE
15683        | LAST_SYM
15684        | LASTVAL_SYM
15685        | LEAVES
15686        | LESS_SYM
15687        | LEVEL_SYM
15688        | LIST_SYM
15689        | LOCKS_SYM
15690        | LOGFILE_SYM
15691        | LOGS_SYM
15692        | MAX_ROWS
15693        | MASTER_SYM
15694        | MASTER_HEARTBEAT_PERIOD_SYM
15695        | MASTER_GTID_POS_SYM
15696        | MASTER_HOST_SYM
15697        | MASTER_PORT_SYM
15698        | MASTER_LOG_FILE_SYM
15699        | MASTER_LOG_POS_SYM
15700        | MASTER_USER_SYM
15701        | MASTER_USE_GTID_SYM
15702        | MASTER_PASSWORD_SYM
15703        | MASTER_SERVER_ID_SYM
15704        | MASTER_CONNECT_RETRY_SYM
15705        | MASTER_DELAY_SYM
15706        | MASTER_SSL_SYM
15707        | MASTER_SSL_CA_SYM
15708        | MASTER_SSL_CAPATH_SYM
15709        | MASTER_SSL_CERT_SYM
15710        | MASTER_SSL_CIPHER_SYM
15711        | MASTER_SSL_CRL_SYM
15712        | MASTER_SSL_CRLPATH_SYM
15713        | MASTER_SSL_KEY_SYM
15714        | MAX_CONNECTIONS_PER_HOUR
15715        | MAX_QUERIES_PER_HOUR
15716        | MAX_SIZE_SYM
15717        | MAX_STATEMENT_TIME_SYM
15718        | MAX_UPDATES_PER_HOUR
15719        | MAX_USER_CONNECTIONS_SYM
15720        | MEMORY_SYM
15721        | MERGE_SYM
15722        | MESSAGE_TEXT_SYM
15723        | MICROSECOND_SYM
15724        | MIGRATE_SYM
15725        | MINUTE_SYM
15726        | MINVALUE_SYM
15727        | MIN_ROWS
15728        | MODIFY_SYM
15729        | MODE_SYM
15730        | MONITOR_SYM
15731        | MONTH_SYM
15732        | MUTEX_SYM
15733        | MYSQL_SYM
15734        | MYSQL_ERRNO_SYM
15735        | NAME_SYM
15736        | NEVER_SYM
15737        | NEXT_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
15738        | NEXTVAL_SYM
15739        | NEW_SYM
15740        | NOCACHE_SYM
15741        | NOCYCLE_SYM
15742        | NOMINVALUE_SYM
15743        | NOMAXVALUE_SYM
15744        | NO_WAIT_SYM
15745        | NOWAIT_SYM
15746        | NODEGROUP_SYM
15747        | NONE_SYM
15748        | NOTFOUND_SYM
15749        | OF_SYM
15750        | OFFSET_SYM
15751        | OLD_PASSWORD_SYM
15752        | ONE_SYM
15753        | ONLINE_SYM
15754        | ONLY_SYM
15755        | OVERLAPS_SYM
15756        | PACKAGE_MARIADB_SYM
15757        | PACK_KEYS_SYM
15758        | PAGE_SYM
15759        | PARTIAL
15760        | PARTITIONING_SYM
15761        | PARTITIONS_SYM
15762        | PERSISTENT_SYM
15763        | PHASE_SYM
15764        | PLUGIN_SYM
15765        | PLUGINS_SYM
15766        | PRESERVE_SYM
15767        | PREV_SYM
15768        | PREVIOUS_SYM       %prec PREC_BELOW_CONTRACTION_TOKEN2
15769        | PRIVILEGES
15770        | PROCESS
15771        | PROCESSLIST_SYM
15772        | PROFILE_SYM
15773        | PROFILES_SYM
15774        | PROXY_SYM
15775        | QUARTER_SYM
15776        | QUERY_SYM
15777        | QUICK
15778        | RAISE_MARIADB_SYM
15779        | READ_ONLY_SYM
15780        | REBUILD_SYM
15781        | RECOVER_SYM
15782        | REDO_BUFFER_SIZE_SYM
15783        | REDOFILE_SYM
15784        | REDUNDANT_SYM
15785        | RELAY
15786        | RELAYLOG_SYM
15787        | RELAY_LOG_FILE_SYM
15788        | RELAY_LOG_POS_SYM
15789        | RELAY_THREAD
15790        | RELOAD
15791        | REORGANIZE_SYM
15792        | REPEATABLE_SYM
15793        | REPLAY_SYM
15794        | REPLICATION
15795        | RESOURCES
15796        | RESTART_SYM
15797        | RESUME_SYM
15798        | RETURNED_SQLSTATE_SYM
15799        | RETURNS_SYM
15800        | REUSE_SYM
15801        | REVERSE_SYM
15802        | ROLLUP_SYM
15803        | ROUTINE_SYM
15804        | ROWCOUNT_SYM
15805        | ROWTYPE_MARIADB_SYM
15806        | ROW_COUNT_SYM
15807        | ROW_FORMAT_SYM
15808        | RTREE_SYM
15809        | SCHEDULE_SYM
15810        | SCHEMA_NAME_SYM
15811        | SECOND_SYM
15812        | SEQUENCE_SYM
15813        | SERIALIZABLE_SYM
15814        | SETVAL_SYM
15815        | SIMPLE_SYM
15816        | SHARE_SYM
15817        | SLAVE_POS_SYM
15818        | SLOW
15819        | SNAPSHOT_SYM
15820        | SOFT_SYM
15821        | SOUNDS_SYM
15822        | SOURCE_SYM
15823        | SQL_CACHE_SYM
15824        | SQL_BUFFER_RESULT
15825        | SQL_NO_CACHE_SYM
15826        | SQL_THREAD
15827        | STAGE_SYM
15828        | STARTS_SYM
15829        | STATEMENT_SYM
15830        | STATUS_SYM
15831        | STORAGE_SYM
15832        | STRING_SYM
15833        | SUBCLASS_ORIGIN_SYM
15834        | SUBDATE_SYM
15835        | SUBJECT_SYM
15836        | SUBPARTITION_SYM
15837        | SUBPARTITIONS_SYM
15838        | SUPER_SYM
15839        | SUSPEND_SYM
15840        | SWAPS_SYM
15841        | SWITCHES_SYM
15842        | SYSTEM
15843        | SYSTEM_TIME_SYM
15844        | TABLE_NAME_SYM
15845        | TABLES
15846        | TABLE_CHECKSUM_SYM
15847        | TABLESPACE
15848        | TEMPORARY
15849        | TEMPTABLE_SYM
15850        | THAN_SYM
15851        | TRANSACTION_SYM    %prec PREC_BELOW_CONTRACTION_TOKEN2
15852        | TRANSACTIONAL_SYM
15853        | THREADS_SYM
15854        | TRIGGERS_SYM
15855        | TRIM_ORACLE
15856        | TIMESTAMP_ADD
15857        | TIMESTAMP_DIFF
15858        | TYPES_SYM
15859        | TYPE_SYM
15860        | UDF_RETURNS_SYM
15861        | UNCOMMITTED_SYM
15862        | UNDEFINED_SYM
15863        | UNDO_BUFFER_SIZE_SYM
15864        | UNDOFILE_SYM
15865        | UNKNOWN_SYM
15866        | UNTIL_SYM
15867        | USER_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
15868        | USE_FRM
15869        | VARIABLES
15870        | VERSIONING_SYM
15871        | VIEW_SYM
15872        | VIRTUAL_SYM
15873        | VISIBLE_SYM
15874        | VALUE_SYM
15875        | WARNINGS
15876        | WAIT_SYM
15877        | WEEK_SYM
15878        | WEIGHT_STRING_SYM
15879        | WITHOUT
15880        | WORK_SYM
15881        | X509_SYM
15882        | XML_SYM
15883        | VIA_SYM
15884        ;
15885
15886
15887reserved_keyword_udt_not_param_type:
15888          ACCESSIBLE_SYM
15889        | ADD
15890        | ALL
15891        | ALTER
15892        | ANALYZE_SYM
15893        | AND_SYM
15894        | AS
15895        | ASC
15896        | ASENSITIVE_SYM
15897        | BEFORE_SYM
15898        | BETWEEN_SYM
15899        | BIT_AND
15900        | BIT_OR
15901        | BIT_XOR
15902        | BODY_ORACLE_SYM
15903        | BOTH
15904        | BY
15905        | CALL_SYM
15906        | CASCADE
15907        | CASE_SYM
15908        | CAST_SYM
15909        | CHANGE
15910        | CHECK_SYM
15911        | COLLATE_SYM
15912        | CONSTRAINT
15913        | CONTINUE_MARIADB_SYM
15914        | CONTINUE_ORACLE_SYM
15915        | CONVERT_SYM
15916        | COUNT_SYM
15917        | CREATE
15918        | CROSS
15919        | CUME_DIST_SYM
15920        | CURDATE
15921        | CURRENT_USER
15922        | CURRENT_ROLE
15923        | CURTIME
15924        | DATABASE
15925        | DATABASES
15926        | DATE_ADD_INTERVAL
15927        | DATE_SUB_INTERVAL
15928        | DAY_HOUR_SYM
15929        | DAY_MICROSECOND_SYM
15930        | DAY_MINUTE_SYM
15931        | DAY_SECOND_SYM
15932        | DECLARE_MARIADB_SYM
15933        | DECLARE_ORACLE_SYM
15934        | DEFAULT
15935        | DELETE_DOMAIN_ID_SYM
15936        | DELETE_SYM
15937        | DENSE_RANK_SYM
15938        | DESC
15939        | DESCRIBE
15940        | DETERMINISTIC_SYM
15941        | DISTINCT
15942        | DIV_SYM
15943        | DO_DOMAIN_IDS_SYM
15944        | DROP
15945        | DUAL_SYM
15946        | EACH_SYM
15947        | ELSE
15948        | ELSEIF_MARIADB_SYM
15949        | ELSIF_ORACLE_SYM
15950        | ENCLOSED
15951        | ESCAPED
15952        | EXCEPT_SYM
15953        | EXISTS
15954        | EXTRACT_SYM
15955        | FALSE_SYM
15956        | FETCH_SYM
15957        | FIRST_VALUE_SYM
15958        | FOREIGN
15959        | FROM
15960        | FULLTEXT_SYM
15961        | GOTO_ORACLE_SYM
15962        | GRANT
15963        | GROUP_SYM
15964        | GROUP_CONCAT_SYM
15965        | LAG_SYM
15966        | LEAD_SYM
15967        | HAVING
15968        | HOUR_MICROSECOND_SYM
15969        | HOUR_MINUTE_SYM
15970        | HOUR_SECOND_SYM
15971        | IF_SYM
15972        | IGNORE_DOMAIN_IDS_SYM
15973        | IGNORE_SYM
15974        | INDEX_SYM
15975        | INFILE
15976        | INNER_SYM
15977        | INSENSITIVE_SYM
15978        | INSERT
15979        | INTERSECT_SYM
15980        | INTERVAL_SYM
15981        | INTO
15982        | IS
15983        | ITERATE_SYM
15984        | JOIN_SYM
15985        | KEYS
15986        | KEY_SYM
15987        | KILL_SYM
15988        | LEADING
15989        | LEAVE_SYM
15990        | LEFT
15991        | LIKE
15992        | LIMIT
15993        | LINEAR_SYM
15994        | LINES
15995        | LOAD
15996        | LOCATOR_SYM
15997        | LOCK_SYM
15998        | LOOP_SYM
15999        | LOW_PRIORITY
16000        | MASTER_SSL_VERIFY_SERVER_CERT_SYM
16001        | MATCH
16002        | MAX_SYM
16003        | MAXVALUE_SYM
16004        | MEDIAN_SYM
16005        | MINUTE_MICROSECOND_SYM
16006        | MINUTE_SECOND_SYM
16007        | MIN_SYM
16008        | MODIFIES_SYM
16009        | MOD_SYM
16010        | NATURAL
16011        | NEG
16012        | NOT_SYM
16013        | NOW_SYM
16014        | NO_WRITE_TO_BINLOG
16015        | NTILE_SYM
16016        | NULL_SYM
16017        | NTH_VALUE_SYM
16018        | ON
16019        | OPTIMIZE
16020        | OPTIONALLY
16021        | ORDER_SYM
16022        | OR_SYM
16023        | OTHERS_ORACLE_SYM
16024        | OUTER
16025        | OUTFILE
16026        | OVER_SYM
16027        | PACKAGE_ORACLE_SYM
16028        | PAGE_CHECKSUM_SYM
16029        | PARSE_VCOL_EXPR_SYM
16030        | PARTITION_SYM
16031        | PERCENT_RANK_SYM
16032        | PERCENTILE_CONT_SYM
16033        | PERCENTILE_DISC_SYM
16034        | PORTION_SYM
16035        | POSITION_SYM
16036        | PRECISION
16037        | PRIMARY_SYM
16038        | PROCEDURE_SYM
16039        | PURGE
16040        | RAISE_ORACLE_SYM
16041        | RANGE_SYM
16042        | RANK_SYM
16043        | READS_SYM
16044        | READ_SYM
16045        | READ_WRITE_SYM
16046        | RECURSIVE_SYM
16047        | REF_SYSTEM_ID_SYM
16048        | REFERENCES
16049        | REGEXP
16050        | RELEASE_SYM
16051        | RENAME
16052        | REPEAT_SYM
16053        | REPLACE
16054        | REQUIRE_SYM
16055        | RESIGNAL_SYM
16056        | RESTRICT
16057        | RETURNING_SYM
16058        | RETURN_MARIADB_SYM
16059        | RETURN_ORACLE_SYM
16060        | REVOKE
16061        | RIGHT
16062        | ROWS_SYM
16063        | ROWTYPE_ORACLE_SYM
16064        | ROW_NUMBER_SYM
16065        | SECOND_MICROSECOND_SYM
16066        | SELECT_SYM
16067        | SENSITIVE_SYM
16068        | SEPARATOR_SYM
16069        | SERVER_OPTIONS
16070        | SHOW
16071        | SIGNAL_SYM
16072        | SPATIAL_SYM
16073        | SPECIFIC_SYM
16074        | SQLEXCEPTION_SYM
16075        | SQLSTATE_SYM
16076        | SQLWARNING_SYM
16077        | SQL_BIG_RESULT
16078        | SQL_SMALL_RESULT
16079        | SQL_SYM
16080        | SSL_SYM
16081        | STARTING
16082        | STATS_AUTO_RECALC_SYM
16083        | STATS_PERSISTENT_SYM
16084        | STATS_SAMPLE_PAGES_SYM
16085        | STDDEV_SAMP_SYM
16086        | STD_SYM
16087        | STRAIGHT_JOIN
16088        | SUBSTRING
16089        | SUM_SYM
16090        | SYSDATE
16091        | TABLE_REF_PRIORITY
16092        | TABLE_SYM
16093        | TERMINATED
16094        | THEN_SYM
16095        | TO_SYM
16096        | TRAILING
16097        | TRIGGER_SYM
16098        | TRIM
16099        | TRUE_SYM
16100        | UNDO_SYM
16101        | UNION_SYM
16102        | UNIQUE_SYM
16103        | UNLOCK_SYM
16104        | UPDATE_SYM
16105        | USAGE
16106        | USE_SYM
16107        | USING
16108        | UTC_DATE_SYM
16109        | UTC_TIMESTAMP_SYM
16110        | UTC_TIME_SYM
16111        | VALUES
16112        | VALUES_IN_SYM
16113        | VALUES_LESS_SYM
16114        | VARIANCE_SYM
16115        | VARYING
16116        | VAR_SAMP_SYM
16117        | WHEN_SYM
16118        | WHERE
16119        | WHILE_SYM
16120        | WITH
16121        | XOR
16122        | YEAR_MONTH_SYM
16123        | ZEROFILL
16124        ;
16125
16126/*
16127  SQLCOM_SET_OPTION statement.
16128
16129  Note that to avoid shift/reduce conflicts, we have separate rules for the
16130  first option listed in the statement.
16131*/
16132
16133set:
16134          SET
16135          {
16136            LEX *lex=Lex;
16137            lex->set_stmt_init();
16138          }
16139          set_param
16140          {
16141            if (Lex->check_main_unit_semantics())
16142              MYSQL_YYABORT;
16143          }
16144        ;
16145
16146set_param:
16147          option_value_no_option_type
16148        | option_value_no_option_type ',' option_value_list
16149        | TRANSACTION_SYM
16150          {
16151            Lex->option_type= OPT_DEFAULT;
16152            if (sp_create_assignment_lex(thd, $1.pos()))
16153              MYSQL_YYABORT;
16154          }
16155          transaction_characteristics
16156          {
16157            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16158              MYSQL_YYABORT;
16159          }
16160        | option_type
16161          {
16162            Lex->option_type= $1;
16163          }
16164          start_option_value_list_following_option_type
16165        | STATEMENT_SYM
16166          set_stmt_option_list
16167          {
16168            LEX *lex= Lex;
16169            if (unlikely(lex->table_or_sp_used()))
16170              my_yyabort_error((ER_SUBQUERIES_NOT_SUPPORTED, MYF(0), "SET STATEMENT"));
16171            lex->stmt_var_list= lex->var_list;
16172            lex->var_list.empty();
16173            if (Lex->check_main_unit_semantics())
16174              MYSQL_YYABORT;
16175          }
16176          FOR_SYM directly_executable_statement
16177        ;
16178
16179set_stmt_option_list:
16180       /*
16181         Only system variables can be used here. If this condition is changed
16182         please check careful code under lex->option_type == OPT_STATEMENT
16183         condition on wrong type casts.
16184       */
16185          set_stmt_option
16186        | set_stmt_option_list ',' set_stmt_option
16187        ;
16188
16189/* Start of option value list, option_type was given */
16190start_option_value_list_following_option_type:
16191          option_value_following_option_type
16192        | option_value_following_option_type ',' option_value_list
16193        | TRANSACTION_SYM
16194          {
16195            if (sp_create_assignment_lex(thd, $1.pos()))
16196              MYSQL_YYABORT;
16197          }
16198          transaction_characteristics
16199          {
16200            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16201              MYSQL_YYABORT;
16202          }
16203        ;
16204
16205/* Repeating list of option values after first option value. */
16206option_value_list:
16207          option_value
16208        | option_value_list ',' option_value
16209        ;
16210
16211/* Wrapper around option values following the first option value in the stmt. */
16212option_value:
16213          option_type
16214          {
16215            Lex->option_type= $1;
16216          }
16217          option_value_following_option_type
16218        | option_value_no_option_type
16219        ;
16220
16221option_type:
16222          GLOBAL_SYM  { $$=OPT_GLOBAL; }
16223        | LOCAL_SYM   { $$=OPT_SESSION; }
16224        | SESSION_SYM { $$=OPT_SESSION; }
16225        ;
16226
16227opt_var_type:
16228          /* empty */ { $$=OPT_SESSION; }
16229        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
16230        | LOCAL_SYM   { $$=OPT_SESSION; }
16231        | SESSION_SYM { $$=OPT_SESSION; }
16232        ;
16233
16234opt_var_ident_type:
16235          /* empty */     { $$=OPT_DEFAULT; }
16236        | GLOBAL_SYM '.'  { $$=OPT_GLOBAL; }
16237        | LOCAL_SYM '.'   { $$=OPT_SESSION; }
16238        | SESSION_SYM '.' { $$=OPT_SESSION; }
16239        ;
16240
16241/*
16242  SET STATEMENT options do not need their own LEX or Query_arena.
16243  Let's put them to the main ones.
16244*/
16245set_stmt_option:
16246          ident_cli equal
16247          {
16248            if (Lex->main_select_push(false))
16249              MYSQL_YYABORT;
16250          }
16251          set_expr_or_default
16252          {
16253            Lex_ident_sys tmp(thd, &$1);
16254            if (unlikely(!tmp.str) ||
16255                unlikely(Lex->set_system_variable(Lex->option_type, &tmp, $4)))
16256              MYSQL_YYABORT;
16257            Lex->pop_select(); //min select
16258          }
16259        | ident_cli '.' ident equal
16260          {
16261            if (Lex->main_select_push(false))
16262              MYSQL_YYABORT;
16263          }
16264          set_expr_or_default
16265          {
16266            Lex_ident_sys tmp(thd, &$1);
16267            if (unlikely(!tmp.str) ||
16268                unlikely(Lex->set_system_variable(thd, Lex->option_type,
16269                         &tmp, &$3, $6)))
16270              MYSQL_YYABORT;
16271            Lex->pop_select(); //min select
16272          }
16273        | DEFAULT '.' ident equal
16274          {
16275            if (Lex->main_select_push(false))
16276              MYSQL_YYABORT;
16277          }
16278          set_expr_or_default
16279          {
16280            if (unlikely(Lex->set_default_system_variable(Lex->option_type,
16281                                                          &$3, $6)))
16282              MYSQL_YYABORT;
16283            Lex->pop_select(); //min select
16284          }
16285        ;
16286
16287
16288/* Option values with preceding option_type. */
16289option_value_following_option_type:
16290          ident_cli equal
16291          {
16292            if (sp_create_assignment_lex(thd, $1.pos()))
16293              MYSQL_YYABORT;
16294          }
16295          set_expr_or_default
16296          {
16297            Lex_ident_sys tmp(thd, &$1);
16298            if (unlikely(!tmp.str) ||
16299                unlikely(Lex->set_system_variable(Lex->option_type, &tmp, $4)) ||
16300                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16301              MYSQL_YYABORT;
16302          }
16303        | ident_cli '.' ident equal
16304          {
16305            if (sp_create_assignment_lex(thd, $1.pos()))
16306              MYSQL_YYABORT;
16307          }
16308          set_expr_or_default
16309          {
16310            Lex_ident_sys tmp(thd, &$1);
16311            if (unlikely(!tmp.str) ||
16312                unlikely(Lex->set_system_variable(thd, Lex->option_type, &tmp, &$3, $6)) ||
16313                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16314              MYSQL_YYABORT;
16315          }
16316        | DEFAULT '.' ident equal
16317          {
16318            if (sp_create_assignment_lex(thd, $1.pos()))
16319              MYSQL_YYABORT;
16320          }
16321          set_expr_or_default
16322          {
16323            if (unlikely(Lex->set_default_system_variable(Lex->option_type, &$3, $6)) ||
16324                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16325              MYSQL_YYABORT;
16326          }
16327        ;
16328
16329/* Option values without preceding option_type. */
16330option_value_no_option_type:
16331          ident_cli_set_usual_case equal
16332          {
16333            if (sp_create_assignment_lex(thd, $1.pos()))
16334              MYSQL_YYABORT;
16335          }
16336          set_expr_or_default
16337          {
16338            Lex_ident_sys tmp(thd, &$1);
16339            if (unlikely(!tmp.str) ||
16340                unlikely(Lex->set_variable(&tmp, $4)) ||
16341                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16342              MYSQL_YYABORT;
16343          }
16344        | ident_cli_set_usual_case '.' ident equal
16345          {
16346            if (sp_create_assignment_lex(thd, $1.pos()))
16347              MYSQL_YYABORT;
16348          }
16349          set_expr_or_default
16350          {
16351            Lex_ident_sys tmp(thd, &$1);
16352            if (unlikely(!tmp.str) ||
16353                unlikely(Lex->set_variable(&tmp, &$3, $6)) ||
16354                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16355              MYSQL_YYABORT;
16356          }
16357        | DEFAULT '.' ident equal
16358          {
16359            if (sp_create_assignment_lex(thd, $1.pos()))
16360              MYSQL_YYABORT;
16361          }
16362          set_expr_or_default
16363          {
16364            if (unlikely(Lex->set_default_system_variable(Lex->option_type, &$3, $6)))
16365              MYSQL_YYABORT;
16366            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16367              MYSQL_YYABORT;
16368          }
16369        | '@' ident_or_text equal
16370          {
16371            if (sp_create_assignment_lex(thd, $1.str))
16372              MYSQL_YYABORT;
16373          }
16374          expr
16375          {
16376            if (unlikely(Lex->set_user_variable(thd, &$2, $5)) ||
16377                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16378              MYSQL_YYABORT;
16379          }
16380        | '@' '@' opt_var_ident_type ident_sysvar_name equal
16381          {
16382            if (sp_create_assignment_lex(thd, $1.str))
16383              MYSQL_YYABORT;
16384          }
16385          set_expr_or_default
16386          {
16387            if (unlikely(Lex->set_system_variable($3, &$4, $7)) ||
16388                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16389              MYSQL_YYABORT;
16390          }
16391        | '@' '@' opt_var_ident_type ident_sysvar_name '.' ident equal
16392          {
16393            if (sp_create_assignment_lex(thd, $1.str))
16394              MYSQL_YYABORT;
16395          }
16396          set_expr_or_default
16397          {
16398            if (unlikely(Lex->set_system_variable(thd, $3, &$4, &$6, $9)) ||
16399                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16400              MYSQL_YYABORT;
16401          }
16402        | '@' '@' opt_var_ident_type DEFAULT '.' ident equal
16403          {
16404            if (sp_create_assignment_lex(thd, $1.str))
16405              MYSQL_YYABORT;
16406          }
16407          set_expr_or_default
16408          {
16409            if (unlikely(Lex->set_default_system_variable($3, &$6, $9)) ||
16410                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16411              MYSQL_YYABORT;
16412          }
16413        | charset old_or_new_charset_name_or_default
16414          {
16415            if (sp_create_assignment_lex(thd, $1.pos()))
16416              MYSQL_YYABORT;
16417            LEX *lex= thd->lex;
16418            CHARSET_INFO *cs2;
16419            cs2= $2 ? $2: global_system_variables.character_set_client;
16420            set_var_collation_client *var;
16421            var= (new (thd->mem_root)
16422                  set_var_collation_client(cs2,
16423                                           thd->variables.collation_database,
16424                                            cs2));
16425            if (unlikely(var == NULL))
16426              MYSQL_YYABORT;
16427            lex->var_list.push_back(var, thd->mem_root);
16428            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16429              MYSQL_YYABORT;
16430          }
16431        | NAMES_SYM equal expr
16432          {
16433            LEX *lex= Lex;
16434            sp_pcontext *spc= lex->spcont;
16435            LEX_CSTRING names= { STRING_WITH_LEN("names") };
16436            if (unlikely(spc && spc->find_variable(&names, false)))
16437              my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str);
16438            else
16439              thd->parse_error();
16440            MYSQL_YYABORT;
16441          }
16442        | NAMES_SYM charset_name_or_default opt_collate
16443          {
16444            if (sp_create_assignment_lex(thd, $1.pos()))
16445              MYSQL_YYABORT;
16446            LEX *lex= Lex;
16447            CHARSET_INFO *cs2;
16448            CHARSET_INFO *cs3;
16449            cs2= $2 ? $2 : global_system_variables.character_set_client;
16450            cs3= $3 ? $3 : cs2;
16451            if (unlikely(!my_charset_same(cs2, cs3)))
16452            {
16453              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
16454                       cs3->name, cs2->csname);
16455              MYSQL_YYABORT;
16456            }
16457            set_var_collation_client *var;
16458            var= new (thd->mem_root) set_var_collation_client(cs3, cs3, cs3);
16459            if (unlikely(var == NULL) ||
16460                unlikely(lex->var_list.push_back(var, thd->mem_root)) ||
16461                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16462              MYSQL_YYABORT;
16463          }
16464        | DEFAULT ROLE_SYM grant_role
16465          {
16466            if (sp_create_assignment_lex(thd, $1.pos()))
16467              MYSQL_YYABORT;
16468            LEX *lex = Lex;
16469            LEX_USER *user;
16470            if (unlikely(!(user=(LEX_USER *) thd->calloc(sizeof(LEX_USER)))))
16471              MYSQL_YYABORT;
16472            user->user= current_user;
16473            set_var_default_role *var= (new (thd->mem_root)
16474                                        set_var_default_role(user,
16475                                                             $3->user));
16476            if (unlikely(var == NULL) ||
16477                unlikely(lex->var_list.push_back(var, thd->mem_root)))
16478              MYSQL_YYABORT;
16479
16480            thd->lex->autocommit= TRUE;
16481            if (lex->sphead)
16482              lex->sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;
16483            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16484              MYSQL_YYABORT;
16485          }
16486        | DEFAULT ROLE_SYM grant_role FOR_SYM user
16487          {
16488            if (sp_create_assignment_lex(thd, $1.pos()))
16489              MYSQL_YYABORT;
16490            LEX *lex = Lex;
16491            set_var_default_role *var= (new (thd->mem_root)
16492                                        set_var_default_role($5, $3->user));
16493            if (unlikely(var == NULL) ||
16494                unlikely(lex->var_list.push_back(var, thd->mem_root)))
16495              MYSQL_YYABORT;
16496            thd->lex->autocommit= TRUE;
16497            if (lex->sphead)
16498              lex->sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;
16499            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16500              MYSQL_YYABORT;
16501          }
16502        | ROLE_SYM ident_or_text
16503          {
16504            if (sp_create_assignment_lex(thd, $1.pos()))
16505              MYSQL_YYABORT;
16506            LEX *lex = Lex;
16507            set_var_role *var= new (thd->mem_root) set_var_role($2);
16508            if (unlikely(var == NULL) ||
16509                unlikely(lex->var_list.push_back(var, thd->mem_root)) ||
16510                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16511              MYSQL_YYABORT;
16512          }
16513        | ROLE_SYM equal
16514          {
16515            if (sp_create_assignment_lex(thd, $1.pos()))
16516              MYSQL_YYABORT;
16517          }
16518          set_expr_or_default
16519          {
16520            Lex_ident_sys tmp(thd, &$1);
16521            if (unlikely(!tmp.str) ||
16522                unlikely(Lex->set_variable(&tmp, $4)) ||
16523                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16524              MYSQL_YYABORT;
16525          }
16526        | PASSWORD_SYM equal
16527          {
16528            if (sp_create_assignment_lex(thd, $1.pos()))
16529              MYSQL_YYABORT;
16530          }
16531          text_or_password
16532          {
16533            if (unlikely(Lex->sp_create_set_password_instr(thd, $4,
16534                                                           yychar == YYEMPTY)))
16535              MYSQL_YYABORT;
16536          }
16537        | PASSWORD_SYM FOR_SYM
16538          {
16539            if (sp_create_assignment_lex(thd, $1.pos()))
16540              MYSQL_YYABORT;
16541          }
16542          user equal text_or_password
16543          {
16544            if (unlikely(Lex->sp_create_set_password_instr(thd, $4, $6,
16545                                                           yychar == YYEMPTY)))
16546              MYSQL_YYABORT;
16547          }
16548        ;
16549
16550transaction_characteristics:
16551          transaction_access_mode
16552        | isolation_level
16553        | transaction_access_mode ',' isolation_level
16554        | isolation_level ',' transaction_access_mode
16555        ;
16556
16557transaction_access_mode:
16558          transaction_access_mode_types
16559          {
16560            LEX *lex=Lex;
16561            Item *item= new (thd->mem_root) Item_int(thd, (int32) $1);
16562            if (unlikely(item == NULL))
16563              MYSQL_YYABORT;
16564            set_var *var= (new (thd->mem_root)
16565                           set_var(thd, lex->option_type,
16566                                   find_sys_var(thd, "tx_read_only"),
16567                                   &null_clex_str,
16568                                   item));
16569            if (unlikely(var == NULL))
16570              MYSQL_YYABORT;
16571            if (unlikely(lex->var_list.push_back(var, thd->mem_root)))
16572              MYSQL_YYABORT;
16573          }
16574        ;
16575
16576isolation_level:
16577          ISOLATION LEVEL_SYM isolation_types
16578          {
16579            LEX *lex=Lex;
16580            Item *item= new (thd->mem_root) Item_int(thd, (int32) $3);
16581            if (unlikely(item == NULL))
16582              MYSQL_YYABORT;
16583            set_var *var= (new (thd->mem_root)
16584                           set_var(thd, lex->option_type,
16585                                   find_sys_var(thd, "tx_isolation"),
16586                                   &null_clex_str,
16587                                   item));
16588            if (unlikely(var == NULL) ||
16589                unlikely(lex->var_list.push_back(var, thd->mem_root)))
16590              MYSQL_YYABORT;
16591          }
16592        ;
16593
16594transaction_access_mode_types:
16595          READ_SYM ONLY_SYM { $$= true; }
16596        | READ_SYM WRITE_SYM { $$= false; }
16597        ;
16598
16599isolation_types:
16600          READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
16601        | READ_SYM COMMITTED_SYM   { $$= ISO_READ_COMMITTED; }
16602        | REPEATABLE_SYM READ_SYM  { $$= ISO_REPEATABLE_READ; }
16603        | SERIALIZABLE_SYM         { $$= ISO_SERIALIZABLE; }
16604        ;
16605
16606
16607text_or_password:
16608          TEXT_STRING
16609          {
16610            $$= new (thd->mem_root) USER_AUTH();
16611            $$->auth_str= $1;
16612          }
16613        | PASSWORD_SYM '(' TEXT_STRING ')'
16614          {
16615            $$= new (thd->mem_root) USER_AUTH();
16616            $$->pwtext= $3;
16617          }
16618        | OLD_PASSWORD_SYM '(' TEXT_STRING ')'
16619          {
16620            $$= new (thd->mem_root) USER_AUTH();
16621            $$->pwtext= $3;
16622            $$->auth_str.str= Item_func_password::alloc(thd,
16623                                   $3.str, $3.length, Item_func_password::OLD);
16624            $$->auth_str.length=  SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
16625          }
16626        ;
16627
16628set_expr_or_default:
16629          expr { $$=$1; }
16630        | DEFAULT { $$=0; }
16631        | ON
16632          {
16633            $$=new (thd->mem_root) Item_string_sys(thd, "ON",  2);
16634            if (unlikely($$ == NULL))
16635              MYSQL_YYABORT;
16636          }
16637        | ALL
16638          {
16639            $$=new (thd->mem_root) Item_string_sys(thd, "ALL", 3);
16640            if (unlikely($$ == NULL))
16641              MYSQL_YYABORT;
16642          }
16643        | BINARY
16644          {
16645            $$=new (thd->mem_root) Item_string_sys(thd, "binary", 6);
16646            if (unlikely($$ == NULL))
16647              MYSQL_YYABORT;
16648          }
16649        ;
16650
16651/* Lock function */
16652
16653lock:
16654          LOCK_SYM table_or_tables
16655          {
16656            LEX *lex= Lex;
16657
16658            if (unlikely(lex->sphead))
16659              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "LOCK"));
16660            lex->sql_command= SQLCOM_LOCK_TABLES;
16661          }
16662          table_lock_list opt_lock_wait_timeout
16663          {}
16664        ;
16665
16666opt_lock_wait_timeout:
16667        /* empty */
16668        {}
16669        | WAIT_SYM ulong_num
16670        {
16671          if (unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("lock_wait_timeout"), $2)) ||
16672              unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("innodb_lock_wait_timeout"), $2)))
16673            MYSQL_YYABORT;
16674        }
16675        | NOWAIT_SYM
16676        {
16677          if (unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("lock_wait_timeout"), 0)) ||
16678              unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("innodb_lock_wait_timeout"), 0)))
16679            MYSQL_YYABORT;
16680        }
16681      ;
16682
16683table_or_tables:
16684          TABLE_SYM        { }
16685        | TABLES           { }
16686        ;
16687
16688table_lock_list:
16689          table_lock
16690        | table_lock_list ',' table_lock
16691        ;
16692
16693table_lock:
16694          table_ident opt_table_alias_clause lock_option
16695          {
16696            thr_lock_type lock_type= (thr_lock_type) $3;
16697            bool lock_for_write= (lock_type >= TL_WRITE_ALLOW_WRITE);
16698            ulong table_options= lock_for_write ? TL_OPTION_UPDATING : 0;
16699            enum_mdl_type mdl_type= !lock_for_write
16700                                    ? MDL_SHARED_READ
16701                                    : lock_type == TL_WRITE_CONCURRENT_INSERT
16702                                      ? MDL_SHARED_WRITE
16703                                      : MDL_SHARED_NO_READ_WRITE;
16704
16705            if (unlikely(!Lex->current_select_or_default()->
16706                         add_table_to_list(thd, $1, $2, table_options,
16707                                           lock_type, mdl_type)))
16708              MYSQL_YYABORT;
16709          }
16710        ;
16711
16712lock_option:
16713          READ_SYM               { $$= TL_READ_NO_INSERT; }
16714        | WRITE_SYM              { $$= TL_WRITE_DEFAULT; }
16715        | WRITE_SYM CONCURRENT
16716          {
16717            $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT);
16718          }
16719
16720        | LOW_PRIORITY WRITE_SYM { $$= TL_WRITE_LOW_PRIORITY; }
16721        | READ_SYM LOCAL_SYM     { $$= TL_READ; }
16722        ;
16723
16724unlock:
16725          UNLOCK_SYM
16726          {
16727            LEX *lex= Lex;
16728
16729            if (unlikely(lex->sphead))
16730              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "UNLOCK"));
16731            lex->sql_command= SQLCOM_UNLOCK_TABLES;
16732          }
16733          table_or_tables
16734          {}
16735        ;
16736
16737/*
16738** Handler: direct access to ISAM functions
16739*/
16740
16741handler:
16742          HANDLER_SYM
16743          {
16744            if (Lex->main_select_push())
16745              MYSQL_YYABORT;
16746          }
16747          handler_tail
16748          {
16749            Lex->pop_select(); //main select
16750          }
16751        ;
16752
16753handler_tail:
16754          table_ident OPEN_SYM opt_table_alias_clause
16755          {
16756            LEX *lex= Lex;
16757            if (unlikely(lex->sphead))
16758              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER"));
16759            lex->sql_command = SQLCOM_HA_OPEN;
16760            if (!lex->current_select->add_table_to_list(thd, $1, $3, 0))
16761              MYSQL_YYABORT;
16762          }
16763        | table_ident_nodb CLOSE_SYM
16764          {
16765            LEX *lex= Lex;
16766            if (unlikely(lex->sphead))
16767              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER"));
16768            lex->sql_command = SQLCOM_HA_CLOSE;
16769            if (!lex->current_select->add_table_to_list(thd, $1, 0, 0))
16770              MYSQL_YYABORT;
16771          }
16772        | table_ident_nodb READ_SYM
16773          {
16774            LEX *lex=Lex;
16775            if (unlikely(lex->sphead))
16776              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER"));
16777            lex->clause_that_disallows_subselect= "HANDLER..READ";
16778            lex->sql_command = SQLCOM_HA_READ;
16779            lex->ha_rkey_mode= HA_READ_KEY_EXACT; /* Avoid purify warnings */
16780            Item *one= new (thd->mem_root) Item_int(thd, (int32) 1);
16781            if (unlikely(one == NULL))
16782              MYSQL_YYABORT;
16783            lex->current_select->select_limit= one;
16784            lex->current_select->offset_limit= 0;
16785            lex->limit_rows_examined= 0;
16786            if (!lex->current_select->add_table_to_list(thd, $1, 0, 0))
16787              MYSQL_YYABORT;
16788          }
16789          handler_read_or_scan opt_where_clause opt_global_limit_clause
16790          {
16791            LEX *lex=Lex;
16792            lex->clause_that_disallows_subselect= NULL;
16793            if (!lex->current_select->explicit_limit)
16794            {
16795              Item *one= new (thd->mem_root) Item_int(thd, (int32) 1);
16796              if (one == NULL)
16797                MYSQL_YYABORT;
16798              lex->current_select->select_limit= one;
16799              lex->current_select->offset_limit= 0;
16800              lex->limit_rows_examined= 0;
16801            }
16802            /* Stored functions are not supported for HANDLER READ. */
16803            if (lex->uses_stored_routines())
16804            {
16805              my_error(ER_NOT_SUPPORTED_YET, MYF(0),
16806                       "stored functions in HANDLER ... READ");
16807              MYSQL_YYABORT;
16808            }
16809          }
16810        ;
16811
16812handler_read_or_scan:
16813          handler_scan_function       { Lex->ident= null_clex_str; }
16814        | ident handler_rkey_function { Lex->ident= $1; }
16815        ;
16816
16817handler_scan_function:
16818          FIRST_SYM { Lex->ha_read_mode = RFIRST; }
16819        | NEXT_SYM  { Lex->ha_read_mode = RNEXT;  }
16820        ;
16821
16822handler_rkey_function:
16823          FIRST_SYM { Lex->ha_read_mode = RFIRST; }
16824        | NEXT_SYM  { Lex->ha_read_mode = RNEXT;  }
16825        | PREV_SYM  { Lex->ha_read_mode = RPREV;  }
16826        | LAST_SYM  { Lex->ha_read_mode = RLAST;  }
16827        | handler_rkey_mode
16828          {
16829            LEX *lex=Lex;
16830            lex->ha_read_mode = RKEY;
16831            lex->ha_rkey_mode=$1;
16832            if (unlikely(!(lex->insert_list= new (thd->mem_root) List_item)))
16833              MYSQL_YYABORT;
16834          }
16835          '(' values ')'
16836          {}
16837        ;
16838
16839handler_rkey_mode:
16840          '='     { $$=HA_READ_KEY_EXACT;   }
16841        | GE     { $$=HA_READ_KEY_OR_NEXT; }
16842        | LE     { $$=HA_READ_KEY_OR_PREV; }
16843        | '>' { $$=HA_READ_AFTER_KEY;   }
16844        | '<'     { $$=HA_READ_BEFORE_KEY;  }
16845        ;
16846
16847/* GRANT / REVOKE */
16848
16849revoke:
16850          REVOKE clear_privileges revoke_command
16851          {}
16852        ;
16853
16854revoke_command:
16855          grant_privileges ON opt_table grant_ident FROM user_and_role_list
16856          {
16857            if (Lex->stmt_revoke_table(thd, $1, *$4))
16858              MYSQL_YYABORT;
16859          }
16860        | grant_privileges ON sp_handler grant_ident FROM user_and_role_list
16861          {
16862            if (Lex->stmt_revoke_sp(thd, $1, *$4, *$3))
16863              MYSQL_YYABORT;
16864          }
16865        | ALL opt_privileges ',' GRANT OPTION FROM user_and_role_list
16866          {
16867            Lex->sql_command = SQLCOM_REVOKE_ALL;
16868          }
16869        | PROXY_SYM ON user FROM user_list
16870          {
16871            if (Lex->stmt_revoke_proxy(thd, $3))
16872              MYSQL_YYABORT;
16873          }
16874        | admin_option_for_role FROM user_and_role_list
16875          {
16876            Lex->sql_command= SQLCOM_REVOKE_ROLE;
16877            if (unlikely(Lex->users_list.push_front($1, thd->mem_root)))
16878              MYSQL_YYABORT;
16879          }
16880        ;
16881
16882admin_option_for_role:
16883        ADMIN_SYM OPTION FOR_SYM grant_role
16884        { Lex->with_admin_option= true; $$= $4; }
16885      | grant_role
16886        { Lex->with_admin_option= false; $$= $1; }
16887      ;
16888
16889grant:
16890          GRANT clear_privileges grant_command
16891          {}
16892        ;
16893
16894grant_command:
16895          grant_privileges ON opt_table grant_ident TO_SYM grant_list
16896          opt_require_clause opt_grant_options
16897          {
16898            if (Lex->stmt_grant_table(thd, $1, *$4, $8))
16899              MYSQL_YYABORT;
16900          }
16901        | grant_privileges ON sp_handler grant_ident TO_SYM grant_list
16902          opt_require_clause opt_grant_options
16903          {
16904            if (Lex->stmt_grant_sp(thd, $1, *$4, *$3, $8))
16905              MYSQL_YYABORT;
16906          }
16907        | PROXY_SYM ON user TO_SYM grant_list opt_grant_option
16908          {
16909            if (Lex->stmt_grant_proxy(thd, $3, $6))
16910              MYSQL_YYABORT;
16911          }
16912        | grant_role TO_SYM grant_list opt_with_admin_option
16913          {
16914            LEX *lex= Lex;
16915            lex->sql_command= SQLCOM_GRANT_ROLE;
16916            /* The first role is the one that is granted */
16917            if (unlikely(Lex->users_list.push_front($1, thd->mem_root)))
16918              MYSQL_YYABORT;
16919          }
16920
16921        ;
16922
16923opt_with_admin:
16924          /* nothing */               { Lex->definer = 0; }
16925        | WITH ADMIN_SYM user_or_role { Lex->definer = $3; }
16926        ;
16927
16928opt_with_admin_option:
16929          /* nothing */               { Lex->with_admin_option= false; }
16930        | WITH ADMIN_SYM OPTION       { Lex->with_admin_option= true; }
16931        ;
16932
16933role_list:
16934          grant_role
16935          {
16936            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
16937              MYSQL_YYABORT;
16938          }
16939        | role_list ',' grant_role
16940          {
16941            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
16942              MYSQL_YYABORT;
16943          }
16944        ;
16945
16946current_role:
16947          CURRENT_ROLE optional_braces
16948          {
16949            if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER)))))
16950              MYSQL_YYABORT;
16951            $$->user= current_role;
16952            $$->auth= NULL;
16953          }
16954          ;
16955
16956grant_role:
16957          ident_or_text
16958          {
16959            CHARSET_INFO *cs= system_charset_info;
16960            /* trim end spaces (as they'll be lost in mysql.user anyway) */
16961            $1.length= cs->lengthsp($1.str, $1.length);
16962            ((char*) $1.str)[$1.length] = '\0';
16963            if (unlikely($1.length == 0))
16964              my_yyabort_error((ER_INVALID_ROLE, MYF(0), ""));
16965            if (unlikely(!($$=(LEX_USER*) thd->alloc(sizeof(LEX_USER)))))
16966              MYSQL_YYABORT;
16967            $$->user= $1;
16968            $$->host= empty_clex_str;
16969            $$->auth= NULL;
16970
16971            if (unlikely(check_string_char_length(&$$->user, ER_USERNAME,
16972                                                  username_char_length,
16973                                                  cs, 0)))
16974              MYSQL_YYABORT;
16975          }
16976        | current_role
16977        ;
16978
16979opt_table:
16980          /* Empty */
16981        | TABLE_SYM
16982        ;
16983
16984grant_privileges:
16985          object_privilege_list
16986        | ALL opt_privileges
16987          {
16988            if (!($$= new (thd->mem_root) Lex_grant_privilege(GLOBAL_ACLS, true)))
16989              MYSQL_YYABORT;
16990          }
16991        ;
16992
16993opt_privileges:
16994          /* empty */
16995        | PRIVILEGES
16996        ;
16997
16998object_privilege_list:
16999          object_privilege
17000          {
17001            if (!($$= new (thd->mem_root) Lex_grant_privilege($1)))
17002              MYSQL_YYABORT;
17003          }
17004        | column_list_privilege
17005          {
17006            if (!($$= new (thd->mem_root) Lex_grant_privilege()) ||
17007                $$->add_column_list_privilege(thd, $1.m_columns[0],
17008                                                   $1.m_privilege))
17009              MYSQL_YYABORT;
17010          }
17011        | object_privilege_list ',' object_privilege
17012          {
17013            ($$= $1)->add_object_privilege($3);
17014          }
17015        | object_privilege_list ',' column_list_privilege
17016          {
17017            if (($$= $1)->add_column_list_privilege(thd, $3.m_columns[0],
17018                                                         $3.m_privilege))
17019              MYSQL_YYABORT;
17020          }
17021        ;
17022
17023column_list_privilege:
17024          column_privilege '(' comma_separated_ident_list ')'
17025          {
17026            $$= Lex_column_list_privilege($3, $1);
17027          }
17028        ;
17029
17030column_privilege:
17031          SELECT_SYM              { $$= SELECT_ACL; }
17032        | INSERT                  { $$= INSERT_ACL; }
17033        | UPDATE_SYM              { $$= UPDATE_ACL; }
17034        | REFERENCES              { $$= REFERENCES_ACL; }
17035        ;
17036
17037object_privilege:
17038          SELECT_SYM              { $$= SELECT_ACL; }
17039        | INSERT                  { $$= INSERT_ACL; }
17040        | UPDATE_SYM              { $$= UPDATE_ACL; }
17041        | REFERENCES              { $$= REFERENCES_ACL; }
17042        | DELETE_SYM              { $$= DELETE_ACL;}
17043        | USAGE                   { $$= NO_ACL; }
17044        | INDEX_SYM               { $$= INDEX_ACL;}
17045        | ALTER                   { $$= ALTER_ACL;}
17046        | CREATE                  { $$= CREATE_ACL;}
17047        | DROP                    { $$= DROP_ACL;}
17048        | EXECUTE_SYM             { $$= EXECUTE_ACL;}
17049        | RELOAD                  { $$= RELOAD_ACL;}
17050        | SHUTDOWN                { $$= SHUTDOWN_ACL;}
17051        | PROCESS                 { $$= PROCESS_ACL;}
17052        | FILE_SYM                { $$= FILE_ACL;}
17053        | GRANT OPTION            { $$= GRANT_ACL;}
17054        | SHOW DATABASES          { $$= SHOW_DB_ACL;}
17055        | SUPER_SYM               { $$= SUPER_ACL;}
17056        | CREATE TEMPORARY TABLES { $$= CREATE_TMP_ACL;}
17057        | LOCK_SYM TABLES         { $$= LOCK_TABLES_ACL; }
17058        | REPLICATION SLAVE       { $$= REPL_SLAVE_ACL; }
17059        | REPLICATION CLIENT_SYM  { $$= BINLOG_MONITOR_ACL; /*Compatibility*/ }
17060        | CREATE VIEW_SYM         { $$= CREATE_VIEW_ACL; }
17061        | SHOW VIEW_SYM           { $$= SHOW_VIEW_ACL; }
17062        | CREATE ROUTINE_SYM      { $$= CREATE_PROC_ACL; }
17063        | ALTER ROUTINE_SYM       { $$= ALTER_PROC_ACL; }
17064        | CREATE USER_SYM         { $$= CREATE_USER_ACL; }
17065        | EVENT_SYM               { $$= EVENT_ACL;}
17066        | TRIGGER_SYM             { $$= TRIGGER_ACL; }
17067        | CREATE TABLESPACE       { $$= CREATE_TABLESPACE_ACL; }
17068        | DELETE_SYM HISTORY_SYM  { $$= DELETE_HISTORY_ACL; }
17069        | SET USER_SYM            { $$= SET_USER_ACL; }
17070        | FEDERATED_SYM ADMIN_SYM { $$= FEDERATED_ADMIN_ACL; }
17071        | CONNECTION_SYM ADMIN_SYM         { $$= CONNECTION_ADMIN_ACL; }
17072        | READ_SYM ONLY_SYM ADMIN_SYM      { $$= READ_ONLY_ADMIN_ACL; }
17073        | READ_ONLY_SYM ADMIN_SYM          { $$= READ_ONLY_ADMIN_ACL; }
17074        | BINLOG_SYM MONITOR_SYM           { $$= BINLOG_MONITOR_ACL; }
17075        | BINLOG_SYM ADMIN_SYM             { $$= BINLOG_ADMIN_ACL; }
17076        | BINLOG_SYM REPLAY_SYM            { $$= BINLOG_REPLAY_ACL; }
17077        | REPLICATION MASTER_SYM ADMIN_SYM { $$= REPL_MASTER_ADMIN_ACL; }
17078        | REPLICATION SLAVE ADMIN_SYM      { $$= REPL_SLAVE_ADMIN_ACL; }
17079        | SLAVE MONITOR_SYM                { $$= SLAVE_MONITOR_ACL; }
17080        ;
17081
17082opt_and:
17083          /* empty */ {}
17084        | AND_SYM {}
17085        ;
17086
17087require_list:
17088          require_list_element opt_and require_list
17089        | require_list_element
17090        ;
17091
17092require_list_element:
17093          SUBJECT_SYM TEXT_STRING
17094          {
17095            LEX *lex=Lex;
17096            if (lex->account_options.x509_subject.str)
17097              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "SUBJECT"));
17098            lex->account_options.x509_subject= $2;
17099          }
17100        | ISSUER_SYM TEXT_STRING
17101          {
17102            LEX *lex=Lex;
17103            if (lex->account_options.x509_issuer.str)
17104              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "ISSUER"));
17105            lex->account_options.x509_issuer= $2;
17106          }
17107        | CIPHER_SYM TEXT_STRING
17108          {
17109            LEX *lex=Lex;
17110            if (lex->account_options.ssl_cipher.str)
17111              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CIPHER"));
17112            lex->account_options.ssl_cipher= $2;
17113          }
17114        ;
17115
17116grant_ident:
17117          '*'
17118          {
17119            LEX_CSTRING db;
17120            if (unlikely(Lex->copy_db_to(&db)))
17121              MYSQL_YYABORT;
17122            if (!($$= new (thd->mem_root) Lex_grant_object_name(db,
17123                                            Lex_grant_object_name::STAR)))
17124              MYSQL_YYABORT;
17125          }
17126        | ident '.' '*'
17127          {
17128            if (!($$= new (thd->mem_root) Lex_grant_object_name($1,
17129                                            Lex_grant_object_name::IDENT_STAR)))
17130              MYSQL_YYABORT;
17131          }
17132        | '*' '.' '*'
17133          {
17134            if (!($$= new (thd->mem_root) Lex_grant_object_name(
17135                                            null_clex_str,
17136                                            Lex_grant_object_name::STAR_STAR)))
17137              MYSQL_YYABORT;
17138          }
17139        | table_ident
17140          {
17141            if (!($$= new (thd->mem_root) Lex_grant_object_name($1)))
17142              MYSQL_YYABORT;
17143          }
17144        ;
17145
17146user_list:
17147          user
17148          {
17149            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17150              MYSQL_YYABORT;
17151          }
17152        | user_list ',' user
17153          {
17154            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17155              MYSQL_YYABORT;
17156          }
17157        ;
17158
17159grant_list:
17160          grant_user
17161          {
17162            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17163              MYSQL_YYABORT;
17164          }
17165        | grant_list ',' grant_user
17166          {
17167            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17168              MYSQL_YYABORT;
17169          }
17170        ;
17171
17172user_and_role_list:
17173          user_or_role
17174          {
17175            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17176              MYSQL_YYABORT;
17177          }
17178        | user_and_role_list ',' user_or_role
17179          {
17180            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17181              MYSQL_YYABORT;
17182          }
17183        ;
17184
17185via_or_with: VIA_SYM | WITH ;
17186using_or_as: USING | AS ;
17187
17188grant_user:
17189          user IDENTIFIED_SYM BY TEXT_STRING
17190          {
17191            $$= $1;
17192            $1->auth= new (thd->mem_root) USER_AUTH();
17193            $1->auth->pwtext= $4;
17194          }
17195        | user IDENTIFIED_SYM BY PASSWORD_SYM TEXT_STRING
17196          {
17197            $$= $1;
17198            $1->auth= new (thd->mem_root) USER_AUTH();
17199            $1->auth->auth_str= $5;
17200          }
17201        | user IDENTIFIED_SYM via_or_with auth_expression
17202          {
17203            $$= $1;
17204            $1->auth= $4;
17205          }
17206        | user_or_role
17207          {
17208            $$= $1;
17209          }
17210        ;
17211
17212auth_expression:
17213          auth_token OR_SYM auth_expression
17214          {
17215            $$= $1;
17216            DBUG_ASSERT($$->next == NULL);
17217            $$->next= $3;
17218          }
17219        | auth_token
17220          {
17221            $$= $1;
17222          }
17223        ;
17224
17225auth_token:
17226          ident_or_text opt_auth_str
17227        {
17228          $$= $2;
17229          $$->plugin= $1;
17230        }
17231        ;
17232
17233opt_auth_str:
17234        /* empty */
17235        {
17236          if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH))))
17237            MYSQL_YYABORT;
17238        }
17239      | using_or_as TEXT_STRING_sys
17240        {
17241          if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH))))
17242            MYSQL_YYABORT;
17243          $$->auth_str= $2;
17244        }
17245      | using_or_as PASSWORD_SYM '(' TEXT_STRING ')'
17246        {
17247          if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH))))
17248            MYSQL_YYABORT;
17249          $$->pwtext= $4;
17250        }
17251      ;
17252
17253opt_require_clause:
17254          /* empty */
17255        | REQUIRE_SYM require_list
17256          {
17257            Lex->account_options.ssl_type= SSL_TYPE_SPECIFIED;
17258          }
17259        | REQUIRE_SYM SSL_SYM
17260          {
17261            Lex->account_options.ssl_type= SSL_TYPE_ANY;
17262          }
17263        | REQUIRE_SYM X509_SYM
17264          {
17265            Lex->account_options.ssl_type= SSL_TYPE_X509;
17266          }
17267        | REQUIRE_SYM NONE_SYM
17268          {
17269            Lex->account_options.ssl_type= SSL_TYPE_NONE;
17270          }
17271        ;
17272
17273resource_option:
17274        MAX_QUERIES_PER_HOUR ulong_num
17275          {
17276            Lex->account_options.questions=$2;
17277            Lex->account_options.specified_limits|= USER_RESOURCES::QUERIES_PER_HOUR;
17278          }
17279        | MAX_UPDATES_PER_HOUR ulong_num
17280          {
17281            Lex->account_options.updates=$2;
17282            Lex->account_options.specified_limits|= USER_RESOURCES::UPDATES_PER_HOUR;
17283          }
17284        | MAX_CONNECTIONS_PER_HOUR ulong_num
17285          {
17286            Lex->account_options.conn_per_hour= $2;
17287            Lex->account_options.specified_limits|= USER_RESOURCES::CONNECTIONS_PER_HOUR;
17288          }
17289        | MAX_USER_CONNECTIONS_SYM int_num
17290          {
17291            Lex->account_options.user_conn= $2;
17292            Lex->account_options.specified_limits|= USER_RESOURCES::USER_CONNECTIONS;
17293          }
17294        | MAX_STATEMENT_TIME_SYM NUM_literal
17295          {
17296            Lex->account_options.max_statement_time= $2->val_real();
17297            Lex->account_options.specified_limits|= USER_RESOURCES::MAX_STATEMENT_TIME;
17298          }
17299        ;
17300
17301resource_option_list:
17302	  resource_option_list resource_option {}
17303	| resource_option {}
17304        ;
17305
17306opt_resource_options:
17307	  /* empty */ {}
17308	| WITH resource_option_list
17309        ;
17310
17311
17312opt_grant_options:
17313          /* empty */            { $$= NO_ACL;  }
17314        | WITH grant_option_list { $$= $2; }
17315        ;
17316
17317opt_grant_option:
17318          /* empty */       { $$= NO_ACL;    }
17319        | WITH GRANT OPTION { $$= GRANT_ACL; }
17320        ;
17321
17322grant_option_list:
17323          grant_option_list grant_option { $$= $1 | $2; }
17324        | grant_option
17325        ;
17326
17327grant_option:
17328          GRANT OPTION    { $$= GRANT_ACL;}
17329	| resource_option { $$= NO_ACL; }
17330        ;
17331
17332begin_stmt_mariadb:
17333          BEGIN_MARIADB_SYM
17334          {
17335            LEX *lex=Lex;
17336            lex->sql_command = SQLCOM_BEGIN;
17337            lex->start_transaction_opt= 0;
17338          }
17339          opt_work {}
17340          ;
17341
17342compound_statement:
17343          sp_proc_stmt_compound_ok
17344          {
17345            Lex->sql_command= SQLCOM_COMPOUND;
17346            if (Lex->sp_body_finalize_procedure(thd))
17347              MYSQL_YYABORT;
17348          }
17349        ;
17350
17351opt_not:
17352        /* nothing */  { $$= 0; }
17353        | not          { $$= 1; }
17354        ;
17355
17356opt_work:
17357          /* empty */ {}
17358        | WORK_SYM  {}
17359        ;
17360
17361opt_chain:
17362          /* empty */
17363          { $$= TVL_UNKNOWN; }
17364        | AND_SYM NO_SYM CHAIN_SYM { $$= TVL_NO; }
17365        | AND_SYM CHAIN_SYM        { $$= TVL_YES; }
17366        ;
17367
17368opt_release:
17369          /* empty */
17370          { $$= TVL_UNKNOWN; }
17371        | RELEASE_SYM        { $$= TVL_YES; }
17372        | NO_SYM RELEASE_SYM { $$= TVL_NO; }
17373        ;
17374
17375commit:
17376          COMMIT_SYM opt_work opt_chain opt_release
17377          {
17378            LEX *lex=Lex;
17379            lex->sql_command= SQLCOM_COMMIT;
17380            /* Don't allow AND CHAIN RELEASE. */
17381            MYSQL_YYABORT_UNLESS($3 != TVL_YES || $4 != TVL_YES);
17382            lex->tx_chain= $3;
17383            lex->tx_release= $4;
17384          }
17385        ;
17386
17387rollback:
17388          ROLLBACK_SYM opt_work opt_chain opt_release
17389          {
17390            LEX *lex=Lex;
17391            lex->sql_command= SQLCOM_ROLLBACK;
17392            /* Don't allow AND CHAIN RELEASE. */
17393            MYSQL_YYABORT_UNLESS($3 != TVL_YES || $4 != TVL_YES);
17394            lex->tx_chain= $3;
17395            lex->tx_release= $4;
17396          }
17397        | ROLLBACK_SYM opt_work TO_SYM SAVEPOINT_SYM ident
17398          {
17399            LEX *lex=Lex;
17400            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
17401            lex->ident= $5;
17402          }
17403        | ROLLBACK_SYM opt_work TO_SYM ident
17404          {
17405            LEX *lex=Lex;
17406            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
17407            lex->ident= $4;
17408          }
17409        ;
17410
17411savepoint:
17412          SAVEPOINT_SYM ident
17413          {
17414            LEX *lex=Lex;
17415            lex->sql_command= SQLCOM_SAVEPOINT;
17416            lex->ident= $2;
17417          }
17418        ;
17419
17420release:
17421          RELEASE_SYM SAVEPOINT_SYM ident
17422          {
17423            LEX *lex=Lex;
17424            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
17425            lex->ident= $3;
17426          }
17427        ;
17428
17429/*
17430   UNIONS : glue selects together
17431*/
17432
17433unit_type_decl:
17434          UNION_SYM union_option
17435          { $$.unit_type= UNION_TYPE; $$.distinct= $2; }
17436        | INTERSECT_SYM union_option
17437          { $$.unit_type= INTERSECT_TYPE; $$.distinct= $2; }
17438        | EXCEPT_SYM union_option
17439          { $$.unit_type= EXCEPT_TYPE; $$.distinct= $2; }
17440        ;
17441
17442/*
17443  Start a UNION, for non-top level query expressions.
17444*/
17445union_option:
17446          /* empty */ { $$=1; }
17447        | DISTINCT  { $$=1; }
17448        | ALL       { $$=0; }
17449        ;
17450
17451query_expression_option:
17452          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
17453        | HIGH_PRIORITY
17454          {
17455            YYPS->m_lock_type= TL_READ_HIGH_PRIORITY;
17456            YYPS->m_mdl_type= MDL_SHARED_READ;
17457            Select->options|= SELECT_HIGH_PRIORITY;
17458          }
17459        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
17460        | UNIQUE_SYM       { Select->options|= SELECT_DISTINCT; }
17461        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
17462        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
17463        | SQL_BUFFER_RESULT { Select->options|= OPTION_BUFFER_RESULT; }
17464        | SQL_CALC_FOUND_ROWS { Select->options|= OPTION_FOUND_ROWS; }
17465        | ALL { Select->options|= SELECT_ALL; }
17466        ;
17467
17468/**************************************************************************
17469
17470 DEFINER clause support.
17471
17472**************************************************************************/
17473
17474definer_opt:
17475          no_definer
17476        | definer
17477        ;
17478
17479no_definer:
17480          /* empty */
17481          {
17482            /*
17483              We have to distinguish missing DEFINER-clause from case when
17484              CURRENT_USER specified as definer explicitly in order to properly
17485              handle CREATE TRIGGER statements which come to replication thread
17486              from older master servers (i.e. to create non-suid trigger in this
17487              case).
17488            */
17489            thd->lex->definer= 0;
17490          }
17491        ;
17492
17493definer:
17494          DEFINER_SYM '=' user_or_role
17495          {
17496            Lex->definer= $3;
17497            Lex->account_options.reset();
17498          }
17499        ;
17500
17501/**************************************************************************
17502
17503 CREATE VIEW statement parts.
17504
17505**************************************************************************/
17506
17507view_algorithm:
17508          ALGORITHM_SYM '=' UNDEFINED_SYM { $$= DTYPE_ALGORITHM_UNDEFINED; }
17509        | ALGORITHM_SYM '=' MERGE_SYM     { $$= VIEW_ALGORITHM_MERGE; }
17510        | ALGORITHM_SYM '=' TEMPTABLE_SYM { $$= VIEW_ALGORITHM_TMPTABLE; }
17511        ;
17512
17513opt_view_suid:
17514          /* empty */                      { $$= VIEW_SUID_DEFAULT; }
17515        | view_suid                        { $$= $1; }
17516        ;
17517
17518view_suid:
17519          SQL_SYM SECURITY_SYM DEFINER_SYM { $$= VIEW_SUID_DEFINER; }
17520        | SQL_SYM SECURITY_SYM INVOKER_SYM { $$= VIEW_SUID_INVOKER; }
17521        ;
17522
17523view_list_opt:
17524          /* empty */
17525          {}
17526        | '(' view_list ')' { }
17527        ;
17528
17529view_list:
17530          ident
17531          {
17532            Lex->view_list.push_back((LEX_CSTRING*)
17533                                     thd->memdup(&$1, sizeof(LEX_CSTRING)),
17534                                     thd->mem_root);
17535          }
17536        | view_list ',' ident
17537          {
17538            Lex->view_list.push_back((LEX_CSTRING*)
17539                                     thd->memdup(&$3, sizeof(LEX_CSTRING)),
17540                                     thd->mem_root);
17541          }
17542        ;
17543
17544view_select:
17545          {
17546            LEX *lex= Lex;
17547            lex->parsing_options.allows_variable= FALSE;
17548            lex->create_view->select.str= (char *) YYLIP->get_cpp_ptr();
17549          }
17550          query_expression
17551          view_check_option
17552          {
17553            if (Lex->parsed_create_view($2, $3))
17554              MYSQL_YYABORT;
17555          }
17556        ;
17557
17558view_check_option:
17559          /* empty */                     { $$= VIEW_CHECK_NONE; }
17560        | WITH CHECK_SYM OPTION           { $$= VIEW_CHECK_CASCADED; }
17561        | WITH CASCADED CHECK_SYM OPTION  { $$= VIEW_CHECK_CASCADED; }
17562        | WITH LOCAL_SYM CHECK_SYM OPTION { $$= VIEW_CHECK_LOCAL; }
17563        ;
17564
17565/**************************************************************************
17566
17567 CREATE TRIGGER statement parts.
17568
17569**************************************************************************/
17570
17571trigger_action_order:
17572            FOLLOWS_SYM
17573            { $$= TRG_ORDER_FOLLOWS; }
17574          | PRECEDES_SYM
17575            { $$= TRG_ORDER_PRECEDES; }
17576          ;
17577
17578trigger_follows_precedes_clause:
17579            /* empty */
17580            {
17581              $$.ordering_clause= TRG_ORDER_NONE;
17582              $$.anchor_trigger_name.str= NULL;
17583              $$.anchor_trigger_name.length= 0;
17584            }
17585          |
17586            trigger_action_order ident_or_text
17587            {
17588              $$.ordering_clause= $1;
17589              $$.anchor_trigger_name= $2;
17590            }
17591          ;
17592
17593trigger_tail:
17594          remember_name
17595          opt_if_not_exists
17596          {
17597            if (unlikely(Lex->add_create_options_with_check($2)))
17598              MYSQL_YYABORT;
17599          }
17600          sp_name
17601          trg_action_time
17602          trg_event
17603          ON
17604          remember_name /* $8 */
17605          { /* $9 */
17606            Lex->raw_trg_on_table_name_begin= YYLIP->get_tok_start();
17607          }
17608          table_ident /* $10 */
17609          FOR_SYM
17610          remember_name /* $12 */
17611          { /* $13 */
17612            Lex->raw_trg_on_table_name_end= YYLIP->get_tok_start();
17613          }
17614          EACH_SYM
17615          ROW_SYM
17616          {
17617            Lex->trg_chistics.ordering_clause_begin= YYLIP->get_cpp_ptr();
17618          }
17619          trigger_follows_precedes_clause /* $17 */
17620          { /* $18 */
17621            LEX *lex= thd->lex;
17622            Lex_input_stream *lip= YYLIP;
17623
17624            if (unlikely(lex->sphead))
17625              my_yyabort_error((ER_SP_NO_RECURSIVE_CREATE, MYF(0), "TRIGGER"));
17626
17627            lex->stmt_definition_begin= $1;
17628            lex->ident.str= $8;
17629            lex->ident.length= $12 - $8;
17630            lex->spname= $4;
17631            (*static_cast<st_trg_execution_order*>(&lex->trg_chistics))= ($17);
17632            lex->trg_chistics.ordering_clause_end= lip->get_cpp_ptr();
17633
17634            if (unlikely(!lex->make_sp_head(thd, $4, &sp_handler_trigger,
17635                                            DEFAULT_AGGREGATE)))
17636              MYSQL_YYABORT;
17637
17638            lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
17639          }
17640          sp_proc_stmt /* $19 */
17641          { /* $20 */
17642            LEX *lex= Lex;
17643
17644            lex->sql_command= SQLCOM_CREATE_TRIGGER;
17645            if (lex->sp_body_finalize_trigger(thd))
17646              MYSQL_YYABORT;
17647
17648            /*
17649              We have to do it after parsing trigger body, because some of
17650              sp_proc_stmt alternatives are not saving/restoring LEX, so
17651              lex->query_tables can be wiped out.
17652            */
17653            if (!lex->first_select_lex()->
17654                 add_table_to_list(thd, $10, (LEX_CSTRING*) 0,
17655                                   TL_OPTION_UPDATING, TL_READ_NO_INSERT,
17656                                   MDL_SHARED_NO_WRITE))
17657              MYSQL_YYABORT;
17658          }
17659        ;
17660
17661/**************************************************************************
17662
17663 CREATE FUNCTION | PROCEDURE statements parts.
17664
17665**************************************************************************/
17666
17667
17668sf_return_type:
17669          {
17670            LEX *lex= Lex;
17671            lex->init_last_field(&lex->sphead->m_return_field_def,
17672                                 &empty_clex_str,
17673                                 thd->variables.collation_database);
17674          }
17675          field_type
17676          {
17677            if (unlikely(Lex->sf_return_fill_definition($2)))
17678              MYSQL_YYABORT;
17679          }
17680        ;
17681
17682
17683/*************************************************************************/
17684
17685xa:
17686          XA_SYM begin_or_start xid opt_join_or_resume
17687          {
17688            Lex->sql_command = SQLCOM_XA_START;
17689          }
17690        | XA_SYM END xid opt_suspend
17691          {
17692            Lex->sql_command = SQLCOM_XA_END;
17693          }
17694        | XA_SYM PREPARE_SYM xid
17695          {
17696            Lex->sql_command = SQLCOM_XA_PREPARE;
17697          }
17698        | XA_SYM COMMIT_SYM xid opt_one_phase
17699          {
17700            Lex->sql_command = SQLCOM_XA_COMMIT;
17701          }
17702        | XA_SYM ROLLBACK_SYM xid
17703          {
17704            Lex->sql_command = SQLCOM_XA_ROLLBACK;
17705          }
17706        | XA_SYM RECOVER_SYM opt_format_xid
17707          {
17708            Lex->sql_command = SQLCOM_XA_RECOVER;
17709            Lex->verbose= $3;
17710          }
17711        ;
17712
17713opt_format_xid:
17714         /* empty */ { $$= false; }
17715        | FORMAT_SYM '=' ident_or_text
17716          {
17717            if (lex_string_eq(&$3, STRING_WITH_LEN("SQL")))
17718              $$= true;
17719            else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW")))
17720              $$= false;
17721            else
17722            {
17723              my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0),
17724                               "XA RECOVER", $3.str));
17725              $$= false;
17726            }
17727          }
17728        ;
17729
17730xid:
17731          text_string
17732          {
17733            MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE);
17734            if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID)))))
17735              MYSQL_YYABORT;
17736            Lex->xid->set(1L, $1->ptr(), $1->length(), 0, 0);
17737          }
17738          | text_string ',' text_string
17739          {
17740            MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
17741            if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID)))))
17742              MYSQL_YYABORT;
17743            Lex->xid->set(1L, $1->ptr(), $1->length(), $3->ptr(), $3->length());
17744          }
17745          | text_string ',' text_string ',' ulong_num
17746          {
17747            MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE &&
17748                                 $3->length() <= MAXBQUALSIZE &&
17749                                 $5 <= static_cast<ulong>(
17750                                         std::numeric_limits<int32_t>::max()));
17751            if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID)))))
17752              MYSQL_YYABORT;
17753            Lex->xid->set($5, $1->ptr(), $1->length(), $3->ptr(), $3->length());
17754          }
17755        ;
17756
17757begin_or_start:
17758          BEGIN_MARIADB_SYM {}
17759        | BEGIN_ORACLE_SYM {}
17760        | START_SYM {}
17761        ;
17762
17763opt_join_or_resume:
17764          /* nothing */ { Lex->xa_opt=XA_NONE;        }
17765        | JOIN_SYM      { Lex->xa_opt=XA_JOIN;        }
17766        | RESUME_SYM    { Lex->xa_opt=XA_RESUME;      }
17767        ;
17768
17769opt_one_phase:
17770          /* nothing */     { Lex->xa_opt=XA_NONE;        }
17771        | ONE_SYM PHASE_SYM { Lex->xa_opt=XA_ONE_PHASE;   }
17772        ;
17773
17774opt_suspend:
17775          /* nothing */
17776          { Lex->xa_opt=XA_NONE;        }
17777        | SUSPEND_SYM
17778          { Lex->xa_opt=XA_SUSPEND;     }
17779          opt_migrate
17780        ;
17781
17782opt_migrate:
17783          /* nothing */       {}
17784        | FOR_SYM MIGRATE_SYM { Lex->xa_opt=XA_FOR_MIGRATE; }
17785        ;
17786
17787install:
17788          INSTALL_SYM PLUGIN_SYM opt_if_not_exists ident SONAME_SYM TEXT_STRING_sys
17789          {
17790            if (Lex->stmt_install_plugin($3, $4, $6))
17791              MYSQL_YYABORT;
17792          }
17793        | INSTALL_SYM SONAME_SYM TEXT_STRING_sys
17794          {
17795            Lex->stmt_install_plugin($3);
17796          }
17797        ;
17798
17799uninstall:
17800          UNINSTALL_SYM PLUGIN_SYM opt_if_exists ident
17801          {
17802            if (Lex->stmt_uninstall_plugin_by_name($3, $4))
17803              MYSQL_YYABORT;
17804          }
17805        | UNINSTALL_SYM SONAME_SYM opt_if_exists TEXT_STRING_sys
17806          {
17807            if (Lex->stmt_uninstall_plugin_by_soname($3, $4))
17808              MYSQL_YYABORT;
17809          }
17810        ;
17811
17812/* Avoid compiler warning from yy_*.cc where yyerrlab1 is not used */
17813keep_gcc_happy:
17814          IMPOSSIBLE_ACTION
17815          {
17816            YYERROR;
17817          }
17818        ;
17819
17820_empty:
17821          /* Empty */
17822        ;
17823
17824%ifdef MARIADB
17825
17826
17827statement:
17828          verb_clause
17829        ;
17830
17831sp_statement:
17832          statement
17833        ;
17834
17835sp_if_then_statements:
17836          sp_proc_stmts1
17837        ;
17838
17839sp_case_then_statements:
17840          sp_proc_stmts1
17841        ;
17842
17843reserved_keyword_udt_param_type:
17844          INOUT_SYM
17845        | IN_SYM
17846        | OUT_SYM
17847        ;
17848
17849reserved_keyword_udt:
17850          reserved_keyword_udt_not_param_type
17851        | reserved_keyword_udt_param_type
17852        ;
17853
17854// Keywords that start an SP block section
17855keyword_sp_block_section:
17856          BEGIN_MARIADB_SYM
17857        | END
17858        ;
17859
17860// Keywords that we allow for labels in SPs.
17861// Should not include keywords that start a statement or SP characteristics.
17862keyword_label:
17863          keyword_data_type
17864        | keyword_set_special_case
17865        | keyword_sp_var_and_label
17866        | keyword_sysvar_type
17867        | FUNCTION_SYM
17868        | EXCEPTION_ORACLE_SYM
17869        ;
17870
17871keyword_sp_decl:
17872          keyword_data_type
17873        | keyword_cast_type
17874        | keyword_set_special_case
17875        | keyword_sp_block_section
17876        | keyword_sp_head
17877        | keyword_sp_var_and_label
17878        | keyword_sp_var_not_label
17879        | keyword_sysvar_type
17880        | keyword_verb_clause
17881        | FUNCTION_SYM
17882        | WINDOW_SYM
17883        ;
17884
17885opt_truncate_table_storage_clause:
17886          _empty
17887        ;
17888
17889
17890ident_for_loop_index:
17891          ident
17892        ;
17893
17894row_field_name:
17895          ident
17896          {
17897            if (!($$= Lex->row_field_name(thd, $1)))
17898              MYSQL_YYABORT;
17899          }
17900        ;
17901
17902while_body:
17903          expr_lex DO_SYM
17904          {
17905            if (unlikely($1->sp_while_loop_expression(thd)))
17906              MYSQL_YYABORT;
17907          }
17908          sp_proc_stmts1 END WHILE_SYM
17909          {
17910            if (unlikely(Lex->sp_while_loop_finalize(thd)))
17911              MYSQL_YYABORT;
17912          }
17913        ;
17914
17915for_loop_statements:
17916          DO_SYM sp_proc_stmts1 END FOR_SYM
17917          { }
17918        ;
17919
17920sp_label:
17921          label_ident ':' { $$= $1; }
17922        ;
17923
17924sp_control_label:
17925          sp_label
17926        ;
17927
17928sp_block_label:
17929          sp_label
17930          {
17931            if (unlikely(Lex->spcont->block_label_declare(&$1)))
17932              MYSQL_YYABORT;
17933            $$= $1;
17934          }
17935        ;
17936
17937sp_opt_default:
17938          _empty       { $$ = NULL; }
17939        | DEFAULT expr { $$ = $2; }
17940        ;
17941
17942sp_pdparam:
17943          sp_parameter_type sp_param_name_and_type { $2->mode=$1; }
17944        | sp_param_name_and_type { $1->mode= sp_variable::MODE_IN; }
17945        ;
17946
17947sp_decl_variable_list_anchored:
17948          sp_decl_idents_init_vars
17949          TYPE_SYM OF_SYM optionally_qualified_column_ident
17950          sp_opt_default
17951          {
17952            if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $4, $5)))
17953              MYSQL_YYABORT;
17954            $$.init_using_vars($1);
17955          }
17956        | sp_decl_idents_init_vars
17957          ROW_SYM TYPE_SYM OF_SYM optionally_qualified_column_ident
17958          sp_opt_default
17959          {
17960            if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $5, $6)))
17961              MYSQL_YYABORT;
17962            $$.init_using_vars($1);
17963          }
17964        ;
17965
17966sp_param_name_and_type_anchored:
17967          sp_param_name TYPE_SYM OF_SYM ident '.' ident
17968          {
17969            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd,
17970                                                                $$= $1, $4,
17971                                                                $6)))
17972              MYSQL_YYABORT;
17973          }
17974        | sp_param_name TYPE_SYM OF_SYM ident '.' ident '.' ident
17975          {
17976            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1,
17977                                                                $4, $6, $8)))
17978              MYSQL_YYABORT;
17979          }
17980        | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident
17981          {
17982            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5)))
17983              MYSQL_YYABORT;
17984          }
17985        | sp_param_name ROW_SYM TYPE_SYM OF_SYM ident '.' ident
17986          {
17987            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $5, $7)))
17988              MYSQL_YYABORT;
17989          }
17990        ;
17991
17992
17993sf_c_chistics_and_body_standalone:
17994          sp_c_chistics
17995          {
17996            LEX *lex= thd->lex;
17997            lex->sphead->set_c_chistics(lex->sp_chistics);
17998            lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
17999          }
18000          sp_proc_stmt_in_returns_clause
18001          {
18002            if (unlikely(Lex->sp_body_finalize_function(thd)))
18003              MYSQL_YYABORT;
18004          }
18005        ;
18006
18007sp_tail_standalone:
18008          sp_name
18009          {
18010            if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1,
18011                                                         &sp_handler_procedure,
18012                                                         DEFAULT_AGGREGATE)))
18013              MYSQL_YYABORT;
18014          }
18015          sp_parenthesized_pdparam_list
18016          sp_c_chistics
18017          {
18018            Lex->sphead->set_c_chistics(Lex->sp_chistics);
18019            Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
18020          }
18021          sp_proc_stmt
18022          {
18023            if (unlikely(Lex->sp_body_finalize_procedure(thd)))
18024              MYSQL_YYABORT;
18025          }
18026        ;
18027
18028drop_routine:
18029          DROP FUNCTION_SYM opt_if_exists ident '.' ident
18030          {
18031            if (Lex->stmt_drop_function($3, $4, $6))
18032              MYSQL_YYABORT;
18033          }
18034        | DROP FUNCTION_SYM opt_if_exists ident
18035          {
18036            if (Lex->stmt_drop_function($3, $4))
18037              MYSQL_YYABORT;
18038          }
18039        | DROP PROCEDURE_SYM opt_if_exists sp_name
18040          {
18041            if (Lex->stmt_drop_procedure($3, $4))
18042              MYSQL_YYABORT;
18043          }
18044        ;
18045
18046
18047create_routine:
18048          create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists
18049          {
18050            if (Lex->stmt_create_procedure_start($1 | $4))
18051              MYSQL_YYABORT;
18052          }
18053          sp_tail_standalone
18054          {
18055            Lex->stmt_create_routine_finalize();
18056          }
18057        | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists
18058          sp_name
18059          {
18060            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
18061              MYSQL_YYABORT;
18062          }
18063          sp_parenthesized_fdparam_list
18064          RETURNS_SYM sf_return_type
18065          sf_c_chistics_and_body_standalone
18066          {
18067            Lex->stmt_create_routine_finalize();
18068          }
18069        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
18070          sp_name
18071          {
18072            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
18073              MYSQL_YYABORT;
18074          }
18075          sp_parenthesized_fdparam_list
18076          RETURNS_SYM sf_return_type
18077          sf_c_chistics_and_body_standalone
18078          {
18079            Lex->stmt_create_routine_finalize();
18080          }
18081        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
18082          ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys
18083          {
18084            if (Lex->stmt_create_udf_function($1 | $5, $3, $6,
18085                                              (Item_result) $8, $10))
18086              MYSQL_YYABORT;
18087          }
18088        ;
18089
18090
18091sp_decls:
18092          _empty
18093          {
18094            $$.init();
18095          }
18096        | sp_decls sp_decl ';'
18097          {
18098            // We check for declarations out of (standard) order this way
18099            // because letting the grammar rules reflect it caused tricky
18100            //  shift/reduce conflicts with the wrong result. (And we get
18101            //  better error handling this way.)
18102            if (unlikely(Lex->sp_declarations_join(&$$, $1, $2)))
18103              MYSQL_YYABORT;
18104          }
18105        ;
18106
18107sp_decl:
18108          DECLARE_MARIADB_SYM sp_decl_body { $$= $2; }
18109        ;
18110
18111
18112sp_decl_body:
18113          sp_decl_variable_list
18114        | sp_decl_ident CONDITION_SYM FOR_SYM sp_cond
18115          {
18116            if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4)))
18117              MYSQL_YYABORT;
18118            $$.vars= $$.hndlrs= $$.curs= 0;
18119            $$.conds= 1;
18120          }
18121        | sp_decl_handler
18122        | sp_decl_ident CURSOR_SYM
18123          {
18124            Lex->sp_block_init(thd);
18125          }
18126          opt_parenthesized_cursor_formal_parameters
18127          FOR_SYM sp_cursor_stmt
18128          {
18129            sp_pcontext *param_ctx= Lex->spcont;
18130            if (unlikely(Lex->sp_block_finalize(thd)))
18131              MYSQL_YYABORT;
18132            if (unlikely(Lex->sp_declare_cursor(thd, &$1, $6, param_ctx, true)))
18133              MYSQL_YYABORT;
18134            $$.vars= $$.conds= $$.hndlrs= 0;
18135            $$.curs= 1;
18136          }
18137        ;
18138
18139
18140
18141//  ps_proc_stmt_in_returns_clause is a statement that is allowed
18142//  in the RETURNS clause of a stored function definition directly,
18143//  without the BEGIN..END  block.
18144//  It should not include any syntax structures starting with '(', to avoid
18145//  shift/reduce conflicts with the rule "field_type" and its sub-rules
18146//  that scan an optional length, like CHAR(1) or YEAR(4).
18147//  See MDEV-9166.
18148
18149sp_proc_stmt_in_returns_clause:
18150          sp_proc_stmt_return
18151        | sp_labeled_block
18152        | sp_unlabeled_block
18153        | sp_labeled_control
18154        | sp_proc_stmt_compound_ok
18155        ;
18156
18157sp_proc_stmt:
18158          sp_proc_stmt_in_returns_clause
18159        | sp_proc_stmt_statement
18160        | sp_proc_stmt_continue_oracle
18161        | sp_proc_stmt_exit_oracle
18162        | sp_proc_stmt_leave
18163        | sp_proc_stmt_iterate
18164        | sp_proc_stmt_goto_oracle
18165        | sp_proc_stmt_with_cursor
18166        ;
18167
18168sp_proc_stmt_compound_ok:
18169          sp_proc_stmt_if
18170        | case_stmt_specification
18171        | sp_unlabeled_block_not_atomic
18172        | sp_unlabeled_control
18173        ;
18174
18175
18176sp_labeled_block:
18177          sp_block_label
18178          BEGIN_MARIADB_SYM
18179          {
18180            Lex->sp_block_init(thd, &$1);
18181          }
18182          sp_decls
18183          sp_proc_stmts
18184          END
18185          sp_opt_label
18186          {
18187            if (unlikely(Lex->sp_block_finalize(thd, $4, &$7)))
18188              MYSQL_YYABORT;
18189          }
18190        ;
18191
18192sp_unlabeled_block:
18193          BEGIN_MARIADB_SYM
18194          {
18195            Lex->sp_block_init(thd);
18196          }
18197          sp_decls
18198          sp_proc_stmts
18199          END
18200          {
18201            if (unlikely(Lex->sp_block_finalize(thd, $3)))
18202              MYSQL_YYABORT;
18203          }
18204        ;
18205
18206sp_unlabeled_block_not_atomic:
18207          BEGIN_MARIADB_SYM not ATOMIC_SYM // TODO: BEGIN ATOMIC (not -> opt_not)
18208          {
18209            if (unlikely(Lex->maybe_start_compound_statement(thd)))
18210              MYSQL_YYABORT;
18211            Lex->sp_block_init(thd);
18212          }
18213          sp_decls
18214          sp_proc_stmts
18215          END
18216          {
18217            if (unlikely(Lex->sp_block_finalize(thd, $5)))
18218              MYSQL_YYABORT;
18219          }
18220        ;
18221
18222
18223%endif MARIADB
18224
18225
18226%ifdef ORACLE
18227
18228statement:
18229          verb_clause
18230        | set_assign
18231        ;
18232
18233sp_statement:
18234          statement
18235        | ident_cli_directly_assignable
18236          {
18237            // Direct procedure call (without the CALL keyword)
18238            Lex_ident_sys tmp(thd, &$1);
18239            if (unlikely(!tmp.str) ||
18240                unlikely(Lex->call_statement_start(thd, &tmp)))
18241              MYSQL_YYABORT;
18242          }
18243          opt_sp_cparam_list
18244        | ident_cli_directly_assignable '.' ident
18245          {
18246            Lex_ident_sys tmp(thd, &$1);
18247            if (unlikely(!tmp.str) ||
18248                unlikely(Lex->call_statement_start(thd, &tmp, &$3)))
18249              MYSQL_YYABORT;
18250          }
18251          opt_sp_cparam_list
18252        ;
18253
18254sp_if_then_statements:
18255          sp_proc_stmts1_implicit_block { }
18256        ;
18257
18258sp_case_then_statements:
18259          sp_proc_stmts1_implicit_block { }
18260        ;
18261
18262reserved_keyword_udt:
18263          reserved_keyword_udt_not_param_type
18264        ;
18265
18266// Keywords that start an SP block section.
18267keyword_sp_block_section:
18268          BEGIN_ORACLE_SYM
18269        | END
18270        ;
18271
18272// Keywords that we allow for labels in SPs.
18273// Should not include keywords that start a statement or SP characteristics.
18274keyword_label:
18275          keyword_data_type
18276        | keyword_set_special_case
18277        | keyword_sp_var_and_label
18278        | keyword_sysvar_type
18279        | FUNCTION_SYM
18280        | COMPRESSED_SYM
18281        | EXCEPTION_ORACLE_SYM
18282        ;
18283
18284keyword_sp_decl:
18285          keyword_sp_head
18286        | keyword_set_special_case
18287        | keyword_sp_var_and_label
18288        | keyword_sp_var_not_label
18289        | keyword_sysvar_type
18290        | keyword_verb_clause
18291        | WINDOW_SYM
18292        ;
18293
18294opt_truncate_table_storage_clause:
18295          _empty
18296        | DROP STORAGE_SYM
18297        | REUSE_SYM STORAGE_SYM
18298        ;
18299
18300
18301ident_for_loop_index:
18302          ident_directly_assignable
18303        ;
18304
18305row_field_name:
18306          ident_directly_assignable
18307          {
18308            if (!($$= Lex->row_field_name(thd, $1)))
18309              MYSQL_YYABORT;
18310          }
18311        ;
18312
18313while_body:
18314          expr_lex LOOP_SYM
18315          {
18316            if (unlikely($1->sp_while_loop_expression(thd)))
18317              MYSQL_YYABORT;
18318          }
18319          sp_proc_stmts1 END LOOP_SYM
18320          {
18321            if (unlikely(Lex->sp_while_loop_finalize(thd)))
18322              MYSQL_YYABORT;
18323          }
18324        ;
18325
18326for_loop_statements:
18327          LOOP_SYM sp_proc_stmts1 END LOOP_SYM
18328          { }
18329        ;
18330
18331
18332sp_control_label:
18333          labels_declaration_oracle
18334        ;
18335
18336sp_block_label:
18337          labels_declaration_oracle
18338          {
18339            if (unlikely(Lex->spcont->block_label_declare(&$1)))
18340              MYSQL_YYABORT;
18341            $$= $1;
18342          }
18343        ;
18344
18345
18346remember_end_opt:
18347          {
18348            if (yychar == YYEMPTY)
18349              $$= (char*) YYLIP->get_cpp_ptr_rtrim();
18350            else
18351              $$= (char*) YYLIP->get_cpp_tok_end_rtrim();
18352          }
18353        ;
18354
18355sp_opt_default:
18356          _empty       { $$ = NULL; }
18357        | DEFAULT expr { $$ = $2; }
18358        | SET_VAR expr { $$ = $2; }
18359        ;
18360
18361sp_opt_inout:
18362          _empty         { $$= sp_variable::MODE_IN; }
18363        | sp_parameter_type
18364        | IN_SYM OUT_SYM { $$= sp_variable::MODE_INOUT; }
18365        ;
18366
18367sp_pdparam:
18368          sp_param_name sp_opt_inout field_type
18369          {
18370            $1->mode= $2;
18371            if (unlikely(Lex->sp_param_fill_definition($1, $3)))
18372              MYSQL_YYABORT;
18373          }
18374        | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
18375          {
18376            $1->mode= $2;
18377            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5)))
18378              MYSQL_YYABORT;
18379          }
18380        | sp_param_name sp_opt_inout sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
18381          {
18382            $1->mode= $2;
18383            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5, $7)))
18384              MYSQL_YYABORT;
18385          }
18386        | sp_param_name sp_opt_inout sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
18387          {
18388            $1->mode= $2;
18389            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3)))
18390              MYSQL_YYABORT;
18391          }
18392        | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
18393          {
18394            $1->mode= $2;
18395            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3, $5)))
18396              MYSQL_YYABORT;
18397          }
18398        | sp_param_name sp_opt_inout ROW_SYM row_type_body
18399          {
18400            $1->mode= $2;
18401            if (unlikely(Lex->sphead->spvar_fill_row(thd, $1, $4)))
18402              MYSQL_YYABORT;
18403          }
18404        ;
18405
18406
18407sp_proc_stmts1_implicit_block:
18408          {
18409            Lex->sp_block_init(thd);
18410          }
18411          sp_proc_stmts1
18412          {
18413            if (unlikely(Lex->sp_block_finalize(thd)))
18414              MYSQL_YYABORT;
18415          }
18416        ;
18417
18418
18419remember_lex:
18420          {
18421            $$= thd->lex;
18422          }
18423        ;
18424
18425keyword_directly_assignable:
18426          keyword_data_type
18427        | keyword_cast_type
18428        | keyword_set_special_case
18429        | keyword_sp_var_and_label
18430        | keyword_sp_var_not_label
18431        | keyword_sysvar_type
18432        | FUNCTION_SYM
18433        | WINDOW_SYM
18434        ;
18435
18436ident_directly_assignable:
18437          IDENT_sys
18438        | keyword_directly_assignable
18439          {
18440            if (unlikely($$.copy_keyword(thd, &$1)))
18441              MYSQL_YYABORT;
18442          }
18443        ;
18444
18445ident_cli_directly_assignable:
18446          IDENT_cli
18447        | keyword_directly_assignable { $$= $1; }
18448        ;
18449
18450
18451set_assign:
18452          ident_cli_directly_assignable SET_VAR
18453          {
18454            LEX *lex=Lex;
18455            lex->set_stmt_init();
18456            if (sp_create_assignment_lex(thd, $1.pos()))
18457              MYSQL_YYABORT;
18458          }
18459          set_expr_or_default
18460          {
18461            Lex_ident_sys tmp(thd, &$1);
18462            if (unlikely(!tmp.str) ||
18463                unlikely(Lex->set_variable(&tmp, $4)) ||
18464                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY,
18465                                                    false)))
18466              MYSQL_YYABORT;
18467          }
18468        | ident_cli_directly_assignable '.' ident SET_VAR
18469          {
18470            LEX *lex=Lex;
18471            lex->set_stmt_init();
18472            if (sp_create_assignment_lex(thd, $1.pos()))
18473              MYSQL_YYABORT;
18474          }
18475          set_expr_or_default
18476          {
18477            LEX *lex= Lex;
18478            DBUG_ASSERT(lex->var_list.is_empty());
18479            Lex_ident_sys tmp(thd, &$1);
18480            if (unlikely(!tmp.str) ||
18481                unlikely(lex->set_variable(&tmp, &$3, $6)) ||
18482                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY,
18483                                                    false)))
18484              MYSQL_YYABORT;
18485          }
18486        | COLON_ORACLE_SYM ident '.' ident SET_VAR
18487          {
18488            LEX *lex= Lex;
18489            if (unlikely(!lex->is_trigger_new_or_old_reference(&$2)))
18490            {
18491              thd->parse_error(ER_SYNTAX_ERROR, $1.pos());
18492              MYSQL_YYABORT;
18493            }
18494            lex->set_stmt_init();
18495            if (sp_create_assignment_lex(thd, $1.pos()))
18496              MYSQL_YYABORT;
18497          }
18498          set_expr_or_default
18499          {
18500            LEX_CSTRING tmp= { $2.str, $2.length };
18501            if (unlikely(Lex->set_trigger_field(&tmp, &$4, $7)) ||
18502                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY,
18503                                                    false)))
18504              MYSQL_YYABORT;
18505          }
18506        ;
18507
18508
18509labels_declaration_oracle:
18510          label_declaration_oracle { $$= $1; }
18511        | labels_declaration_oracle label_declaration_oracle { $$= $2; }
18512        ;
18513
18514label_declaration_oracle:
18515          SHIFT_LEFT label_ident SHIFT_RIGHT
18516          {
18517            if (unlikely(Lex->sp_push_goto_label(thd, &$2)))
18518              MYSQL_YYABORT;
18519            $$= $2;
18520          }
18521        ;
18522
18523opt_exception_clause:
18524          _empty                                  { $$= 0; }
18525        | EXCEPTION_ORACLE_SYM exception_handlers { $$= $2; }
18526        ;
18527
18528exception_handlers:
18529           exception_handler                    { $$= 1; }
18530         | exception_handlers exception_handler { $$= $1 + 1; }
18531        ;
18532
18533exception_handler:
18534          WHEN_SYM
18535          {
18536            if (unlikely(Lex->sp_handler_declaration_init(thd, sp_handler::EXIT)))
18537              MYSQL_YYABORT;
18538          }
18539          sp_hcond_list
18540          THEN_SYM
18541          sp_proc_stmts1_implicit_block
18542          {
18543            if (unlikely(Lex->sp_handler_declaration_finalize(thd, sp_handler::EXIT)))
18544              MYSQL_YYABORT;
18545          }
18546        ;
18547
18548sp_no_param:
18549          _empty
18550          {
18551            Lex->sphead->m_param_begin= Lex->sphead->m_param_end=
18552              YYLIP->get_cpp_tok_start() + 1;
18553          }
18554        ;
18555
18556opt_sp_parenthesized_fdparam_list:
18557          sp_no_param
18558        | sp_parenthesized_fdparam_list
18559        ;
18560
18561opt_sp_parenthesized_pdparam_list:
18562          sp_no_param
18563        | sp_parenthesized_pdparam_list
18564        ;
18565
18566
18567opt_sp_name:
18568          _empty      { $$= NULL; }
18569        | sp_name     { $$= $1; }
18570        ;
18571
18572
18573opt_package_routine_end_name:
18574          _empty      { $$= null_clex_str; }
18575        | ident       { $$= $1; }
18576        ;
18577
18578sp_tail_is:
18579          IS
18580        | AS
18581        ;
18582
18583sp_instr_addr:
18584          { $$= Lex->sphead->instructions(); }
18585        ;
18586
18587sp_body:
18588          {
18589            Lex->sp_block_init(thd);
18590          }
18591          opt_sp_decl_body_list
18592          {
18593            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
18594              MYSQL_YYABORT;
18595          }
18596          BEGIN_ORACLE_SYM
18597          sp_block_statements_and_exceptions
18598          {
18599            $2.hndlrs+= $5.hndlrs;
18600            if (unlikely(Lex->sp_block_finalize(thd, $2)))
18601              MYSQL_YYABORT;
18602          }
18603          END
18604        ;
18605
18606create_package_chistic:
18607          COMMENT_SYM TEXT_STRING_sys
18608          { Lex->sp_chistics.comment= $2; }
18609        | sp_suid
18610          { Lex->sp_chistics.suid= $1; }
18611        ;
18612
18613create_package_chistics:
18614          create_package_chistic {}
18615        | create_package_chistics create_package_chistic { }
18616        ;
18617
18618opt_create_package_chistics:
18619          _empty
18620        | create_package_chistics { }
18621        ;
18622
18623opt_create_package_chistics_init:
18624          { Lex->sp_chistics.init(); }
18625          opt_create_package_chistics
18626        ;
18627
18628
18629package_implementation_executable_section:
18630          END
18631          {
18632            if (unlikely(Lex->sp_block_with_exceptions_add_empty(thd)))
18633              MYSQL_YYABORT;
18634            $$.init(0);
18635          }
18636        | BEGIN_ORACLE_SYM sp_block_statements_and_exceptions END { $$= $2; }
18637        ;
18638
18639
18640//  Inside CREATE PACKAGE BODY, package-wide items (e.g. variables)
18641//  must be declared before routine definitions.
18642
18643package_implementation_declare_section:
18644          package_implementation_declare_section_list1
18645        | package_implementation_declare_section_list2
18646        | package_implementation_declare_section_list1
18647          package_implementation_declare_section_list2
18648          { $$.join($1, $2); }
18649        ;
18650
18651package_implementation_declare_section_list1:
18652          package_implementation_item_declaration
18653        | package_implementation_declare_section_list1
18654          package_implementation_item_declaration
18655          { $$.join($1, $2); }
18656        ;
18657
18658package_implementation_declare_section_list2:
18659          package_implementation_routine_definition
18660        | package_implementation_declare_section_list2
18661          package_implementation_routine_definition
18662          { $$.join($1, $2); }
18663        ;
18664
18665package_routine_lex:
18666          {
18667            if (unlikely(!($$= new (thd->mem_root)
18668                           sp_lex_local(thd, thd->lex))))
18669              MYSQL_YYABORT;
18670            thd->m_parser_state->m_yacc.reset_before_substatement();
18671          }
18672        ;
18673
18674
18675package_specification_function:
18676          remember_lex package_routine_lex ident
18677          {
18678            DBUG_ASSERT($1->sphead->get_package());
18679            $2->sql_command= SQLCOM_CREATE_FUNCTION;
18680            sp_name *spname= $1->make_sp_name_package_routine(thd, &$3);
18681            if (unlikely(!spname))
18682              MYSQL_YYABORT;
18683            thd->lex= $2;
18684            if (unlikely(!$2->make_sp_head_no_recursive(thd, spname,
18685                                                        &sp_handler_package_function,
18686                                                        NOT_AGGREGATE)))
18687              MYSQL_YYABORT;
18688            $1->sphead->get_package()->m_current_routine= $2;
18689            (void) is_native_function_with_warn(thd, &$3);
18690          }
18691          opt_sp_parenthesized_fdparam_list
18692          RETURN_ORACLE_SYM sf_return_type
18693          sp_c_chistics
18694          {
18695            sp_head *sp= thd->lex->sphead;
18696            sp->restore_thd_mem_root(thd);
18697            thd->lex= $1;
18698            $$= $2;
18699          }
18700        ;
18701
18702package_specification_procedure:
18703          remember_lex package_routine_lex ident
18704          {
18705            DBUG_ASSERT($1->sphead->get_package());
18706            $2->sql_command= SQLCOM_CREATE_PROCEDURE;
18707            sp_name *spname= $1->make_sp_name_package_routine(thd, &$3);
18708            if (unlikely(!spname))
18709              MYSQL_YYABORT;
18710            thd->lex= $2;
18711            if (unlikely(!$2->make_sp_head_no_recursive(thd, spname,
18712                                                        &sp_handler_package_procedure,
18713                                                        DEFAULT_AGGREGATE)))
18714              MYSQL_YYABORT;
18715            $1->sphead->get_package()->m_current_routine= $2;
18716          }
18717          opt_sp_parenthesized_pdparam_list
18718          sp_c_chistics
18719          {
18720            sp_head *sp= thd->lex->sphead;
18721            sp->restore_thd_mem_root(thd);
18722            thd->lex= $1;
18723            $$= $2;
18724          }
18725        ;
18726
18727
18728package_implementation_routine_definition:
18729          FUNCTION_SYM package_specification_function
18730                       package_implementation_function_body   ';'
18731          {
18732            sp_package *pkg= Lex->get_sp_package();
18733            if (unlikely(pkg->add_routine_implementation($2)))
18734              MYSQL_YYABORT;
18735            pkg->m_current_routine= NULL;
18736            $$.init();
18737          }
18738        | PROCEDURE_SYM package_specification_procedure
18739                        package_implementation_procedure_body ';'
18740          {
18741            sp_package *pkg= Lex->get_sp_package();
18742            if (unlikely(pkg->add_routine_implementation($2)))
18743              MYSQL_YYABORT;
18744            pkg->m_current_routine= NULL;
18745            $$.init();
18746          }
18747        | package_specification_element { $$.init(); }
18748        ;
18749
18750
18751package_implementation_function_body:
18752          sp_tail_is remember_lex
18753          {
18754            sp_package *pkg= Lex->get_sp_package();
18755            sp_head *sp= pkg->m_current_routine->sphead;
18756            thd->lex= pkg->m_current_routine;
18757            sp->reset_thd_mem_root(thd);
18758            sp->set_body_start(thd, YYLIP->get_cpp_tok_start());
18759          }
18760          sp_body opt_package_routine_end_name
18761          {
18762            if (unlikely(thd->lex->sp_body_finalize_function(thd) ||
18763                         thd->lex->sphead->check_package_routine_end_name($5)))
18764              MYSQL_YYABORT;
18765            thd->lex= $2;
18766          }
18767        ;
18768
18769package_implementation_procedure_body:
18770          sp_tail_is remember_lex
18771          {
18772            sp_package *pkg= Lex->get_sp_package();
18773            sp_head *sp= pkg->m_current_routine->sphead;
18774            thd->lex= pkg->m_current_routine;
18775            sp->reset_thd_mem_root(thd);
18776            sp->set_body_start(thd, YYLIP->get_cpp_tok_start());
18777          }
18778          sp_body opt_package_routine_end_name
18779          {
18780            if (unlikely(thd->lex->sp_body_finalize_procedure(thd) ||
18781                         thd->lex->sphead->check_package_routine_end_name($5)))
18782              MYSQL_YYABORT;
18783            thd->lex= $2;
18784          }
18785        ;
18786
18787
18788package_implementation_item_declaration:
18789          sp_decl_variable_list ';'
18790        ;
18791
18792opt_package_specification_element_list:
18793          _empty
18794        | package_specification_element_list
18795        ;
18796
18797package_specification_element_list:
18798          package_specification_element
18799        | package_specification_element_list package_specification_element
18800        ;
18801
18802package_specification_element:
18803          FUNCTION_SYM package_specification_function ';'
18804          {
18805            sp_package *pkg= Lex->get_sp_package();
18806            if (unlikely(pkg->add_routine_declaration($2)))
18807              MYSQL_YYABORT;
18808            pkg->m_current_routine= NULL;
18809          }
18810        | PROCEDURE_SYM package_specification_procedure ';'
18811          {
18812            sp_package *pkg= Lex->get_sp_package();
18813            if (unlikely(pkg->add_routine_declaration($2)))
18814              MYSQL_YYABORT;
18815            pkg->m_current_routine= NULL;
18816          }
18817        ;
18818
18819sp_decl_variable_list_anchored:
18820          sp_decl_idents_init_vars
18821          optionally_qualified_column_ident PERCENT_ORACLE_SYM TYPE_SYM
18822          sp_opt_default
18823          {
18824            if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $2, $5)))
18825              MYSQL_YYABORT;
18826            $$.init_using_vars($1);
18827          }
18828        | sp_decl_idents_init_vars
18829          optionally_qualified_column_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
18830          sp_opt_default
18831          {
18832            if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $2, $5)))
18833              MYSQL_YYABORT;
18834            $$.init_using_vars($1);
18835          }
18836        ;
18837
18838sp_param_name_and_type_anchored:
18839          sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
18840          {
18841            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4)))
18842              MYSQL_YYABORT;
18843          }
18844        | sp_param_name sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
18845          {
18846            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4, $6)))
18847              MYSQL_YYABORT;
18848          }
18849        | sp_param_name sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
18850          {
18851            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2)))
18852              MYSQL_YYABORT;
18853          }
18854        | sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
18855          {
18856            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2, $4)))
18857              MYSQL_YYABORT;
18858          }
18859        ;
18860
18861
18862sf_c_chistics_and_body_standalone:
18863          sp_c_chistics
18864          {
18865            LEX *lex= thd->lex;
18866            lex->sphead->set_c_chistics(lex->sp_chistics);
18867            lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
18868          }
18869          sp_tail_is
18870          sp_body
18871          {
18872            if (unlikely(Lex->sp_body_finalize_function(thd)))
18873              MYSQL_YYABORT;
18874          }
18875        ;
18876
18877sp_tail_standalone:
18878          sp_name
18879          {
18880            if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1,
18881                                                         &sp_handler_procedure,
18882                                                         DEFAULT_AGGREGATE)))
18883              MYSQL_YYABORT;
18884          }
18885          opt_sp_parenthesized_pdparam_list
18886          sp_c_chistics
18887          {
18888            Lex->sphead->set_c_chistics(Lex->sp_chistics);
18889            Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
18890          }
18891          sp_tail_is
18892          sp_body
18893          opt_sp_name
18894          {
18895            if (unlikely(Lex->sp_body_finalize_procedure_standalone(thd, $8)))
18896              MYSQL_YYABORT;
18897          }
18898        ;
18899
18900drop_routine:
18901          DROP FUNCTION_SYM opt_if_exists ident '.' ident
18902          {
18903            if (Lex->stmt_drop_function($3, $4, $6))
18904              MYSQL_YYABORT;
18905          }
18906        | DROP FUNCTION_SYM opt_if_exists ident
18907          {
18908            if (Lex->stmt_drop_function($3, $4))
18909              MYSQL_YYABORT;
18910          }
18911        | DROP PROCEDURE_SYM opt_if_exists sp_name
18912          {
18913            if (Lex->stmt_drop_procedure($3, $4))
18914              MYSQL_YYABORT;
18915          }
18916        | DROP PACKAGE_ORACLE_SYM opt_if_exists sp_name
18917          {
18918            LEX *lex= Lex;
18919            lex->set_command(SQLCOM_DROP_PACKAGE, $3);
18920            if (unlikely(lex->sphead))
18921              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE"));
18922            lex->spname= $4;
18923          }
18924        | DROP PACKAGE_ORACLE_SYM BODY_ORACLE_SYM opt_if_exists sp_name
18925          {
18926            LEX *lex= Lex;
18927            lex->set_command(SQLCOM_DROP_PACKAGE_BODY, $4);
18928            if (unlikely(lex->sphead))
18929              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE BODY"));
18930            lex->spname= $5;
18931          }
18932        ;
18933
18934
18935create_routine:
18936          create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists
18937          {
18938            if (Lex->stmt_create_procedure_start($1 | $4))
18939              MYSQL_YYABORT;
18940          }
18941          sp_tail_standalone
18942          {
18943            Lex->stmt_create_routine_finalize();
18944          }
18945        | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists
18946          sp_name
18947          {
18948            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
18949              MYSQL_YYABORT;
18950          }
18951          opt_sp_parenthesized_fdparam_list
18952          RETURN_ORACLE_SYM sf_return_type
18953          sf_c_chistics_and_body_standalone
18954          opt_sp_name
18955          {
18956            if (Lex->stmt_create_stored_function_finalize_standalone($12))
18957              MYSQL_YYABORT;
18958          }
18959        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
18960          sp_name
18961          {
18962            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
18963              MYSQL_YYABORT;
18964          }
18965          opt_sp_parenthesized_fdparam_list
18966          RETURN_ORACLE_SYM sf_return_type
18967          sf_c_chistics_and_body_standalone
18968          opt_sp_name
18969          {
18970            if (Lex->stmt_create_stored_function_finalize_standalone($12))
18971              MYSQL_YYABORT;
18972          }
18973        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
18974          ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys
18975          {
18976            if (Lex->stmt_create_udf_function($1 | $5, $3, $6,
18977                                              (Item_result) $8, $10))
18978              MYSQL_YYABORT;
18979          }
18980        | create_or_replace definer_opt PACKAGE_ORACLE_SYM
18981          opt_if_not_exists sp_name opt_create_package_chistics_init
18982          sp_tail_is
18983          remember_name
18984          {
18985            sp_package *pkg;
18986            if (unlikely(!(pkg= Lex->
18987                           create_package_start(thd,
18988                                                SQLCOM_CREATE_PACKAGE,
18989                                                &sp_handler_package_spec,
18990                                                $5, $1 | $4))))
18991              MYSQL_YYABORT;
18992            pkg->set_c_chistics(Lex->sp_chistics);
18993          }
18994          opt_package_specification_element_list END
18995          remember_end_opt opt_sp_name
18996          {
18997            if (unlikely(Lex->create_package_finalize(thd, $5, $13, $8, $12)))
18998              MYSQL_YYABORT;
18999          }
19000        | create_or_replace definer_opt PACKAGE_ORACLE_SYM BODY_ORACLE_SYM
19001          opt_if_not_exists sp_name opt_create_package_chistics_init
19002          sp_tail_is
19003          remember_name
19004          {
19005            sp_package *pkg;
19006            if (unlikely(!(pkg= Lex->
19007                           create_package_start(thd,
19008                                                SQLCOM_CREATE_PACKAGE_BODY,
19009                                                &sp_handler_package_body,
19010                                                $6, $1 | $5))))
19011              MYSQL_YYABORT;
19012            pkg->set_c_chistics(Lex->sp_chistics);
19013            Lex->sp_block_init(thd);
19014          }
19015          package_implementation_declare_section
19016          {
19017            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
19018              MYSQL_YYABORT;
19019          }
19020          package_implementation_executable_section
19021          {
19022            $11.hndlrs+= $13.hndlrs;
19023            if (unlikely(Lex->sp_block_finalize(thd, $11)))
19024              MYSQL_YYABORT;
19025          }
19026          remember_end_opt opt_sp_name
19027          {
19028            if (unlikely(Lex->create_package_finalize(thd, $6, $16, $9, $15)))
19029              MYSQL_YYABORT;
19030          }
19031        ;
19032
19033opt_sp_decl_body_list:
19034          _empty
19035          {
19036            $$.init();
19037          }
19038        | sp_decl_body_list { $$= $1; }
19039        ;
19040
19041sp_decl_body_list:
19042          sp_decl_non_handler_list
19043          {
19044            if (unlikely(Lex->sphead->sp_add_instr_cpush_for_cursors(thd, Lex->spcont)))
19045              MYSQL_YYABORT;
19046          }
19047          opt_sp_decl_handler_list
19048          {
19049            $$.join($1, $3);
19050          }
19051        | sp_decl_handler_list
19052        ;
19053
19054sp_decl_non_handler_list:
19055          sp_decl_non_handler ';' { $$= $1; }
19056        | sp_decl_non_handler_list sp_decl_non_handler ';'
19057          {
19058            $$.join($1, $2);
19059          }
19060        ;
19061
19062sp_decl_handler_list:
19063          sp_decl_handler ';' { $$= $1; }
19064        | sp_decl_handler_list sp_decl_handler ';'
19065          {
19066            $$.join($1, $2);
19067          }
19068        ;
19069
19070opt_sp_decl_handler_list:
19071          _empty   { $$.init(); }
19072        | sp_decl_handler_list
19073        ;
19074
19075sp_decl_non_handler:
19076          sp_decl_variable_list
19077        | ident_directly_assignable CONDITION_SYM FOR_SYM sp_cond
19078          {
19079            if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4)))
19080              MYSQL_YYABORT;
19081            $$.vars= $$.hndlrs= $$.curs= 0;
19082            $$.conds= 1;
19083          }
19084        | ident_directly_assignable EXCEPTION_ORACLE_SYM
19085          {
19086            sp_condition_value *spcond= new (thd->mem_root)
19087                                        sp_condition_value_user_defined();
19088            if (unlikely(!spcond) ||
19089                unlikely(Lex->spcont->declare_condition(thd, &$1, spcond)))
19090              MYSQL_YYABORT;
19091            $$.vars= $$.hndlrs= $$.curs= 0;
19092            $$.conds= 1;
19093          }
19094        | CURSOR_SYM ident_directly_assignable
19095          {
19096            Lex->sp_block_init(thd);
19097          }
19098          opt_parenthesized_cursor_formal_parameters
19099          IS sp_cursor_stmt
19100          {
19101            sp_pcontext *param_ctx= Lex->spcont;
19102            if (unlikely(Lex->sp_block_finalize(thd)))
19103              MYSQL_YYABORT;
19104            if (unlikely(Lex->sp_declare_cursor(thd, &$2, $6, param_ctx, false)))
19105              MYSQL_YYABORT;
19106            $$.vars= $$.conds= $$.hndlrs= 0;
19107            $$.curs= 1;
19108          }
19109        ;
19110
19111
19112sp_proc_stmt:
19113          sp_labeled_block
19114        | sp_unlabeled_block
19115        | sp_labeled_control
19116        | sp_unlabeled_control
19117        | sp_labelable_stmt
19118        | labels_declaration_oracle sp_labelable_stmt {}
19119        ;
19120
19121sp_labelable_stmt:
19122          sp_proc_stmt_statement
19123        | sp_proc_stmt_continue_oracle
19124        | sp_proc_stmt_exit_oracle
19125        | sp_proc_stmt_leave
19126        | sp_proc_stmt_iterate
19127        | sp_proc_stmt_goto_oracle
19128        | sp_proc_stmt_with_cursor
19129        | sp_proc_stmt_return
19130        | sp_proc_stmt_if
19131        | case_stmt_specification
19132        | NULL_SYM { }
19133        ;
19134
19135sp_proc_stmt_compound_ok:
19136          sp_proc_stmt_if
19137        | case_stmt_specification
19138        | sp_unlabeled_block
19139        | sp_unlabeled_control
19140        ;
19141
19142
19143sp_labeled_block:
19144          sp_block_label
19145          BEGIN_ORACLE_SYM
19146          {
19147            Lex->sp_block_init(thd, &$1);
19148            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
19149              MYSQL_YYABORT;
19150          }
19151          sp_block_statements_and_exceptions
19152          END
19153          sp_opt_label
19154          {
19155            if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4), &$6)))
19156              MYSQL_YYABORT;
19157          }
19158        | sp_block_label
19159          DECLARE_ORACLE_SYM
19160          {
19161            Lex->sp_block_init(thd, &$1);
19162          }
19163          opt_sp_decl_body_list
19164          {
19165            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
19166              MYSQL_YYABORT;
19167          }
19168          BEGIN_ORACLE_SYM
19169          sp_block_statements_and_exceptions
19170          END
19171          sp_opt_label
19172          {
19173            $4.hndlrs+= $7.hndlrs;
19174            if (unlikely(Lex->sp_block_finalize(thd, $4, &$9)))
19175              MYSQL_YYABORT;
19176          }
19177        ;
19178
19179opt_not_atomic:
19180          _empty
19181        | not ATOMIC_SYM // TODO: BEGIN ATOMIC (not -> opt_not)
19182        ;
19183
19184sp_unlabeled_block:
19185          BEGIN_ORACLE_SYM opt_not_atomic
19186          {
19187            if (unlikely(Lex->maybe_start_compound_statement(thd)))
19188              MYSQL_YYABORT;
19189            Lex->sp_block_init(thd);
19190            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
19191              MYSQL_YYABORT;
19192          }
19193          sp_block_statements_and_exceptions
19194          END
19195          {
19196            if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4))))
19197              MYSQL_YYABORT;
19198          }
19199        | DECLARE_ORACLE_SYM
19200          {
19201            if (unlikely(Lex->maybe_start_compound_statement(thd)))
19202              MYSQL_YYABORT;
19203            Lex->sp_block_init(thd);
19204          }
19205          opt_sp_decl_body_list
19206          {
19207            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
19208              MYSQL_YYABORT;
19209          }
19210          BEGIN_ORACLE_SYM
19211          sp_block_statements_and_exceptions
19212          END
19213          {
19214            $3.hndlrs+= $6.hndlrs;
19215            if (unlikely(Lex->sp_block_finalize(thd, $3)))
19216              MYSQL_YYABORT;
19217          }
19218        ;
19219
19220sp_block_statements_and_exceptions:
19221          sp_instr_addr
19222          sp_proc_stmts
19223          {
19224            if (unlikely(Lex->sp_block_with_exceptions_finalize_executable_section(thd, $1)))
19225              MYSQL_YYABORT;
19226          }
19227          opt_exception_clause
19228          {
19229            if (unlikely(Lex->sp_block_with_exceptions_finalize_exceptions(thd, $1, $4)))
19230              MYSQL_YYABORT;
19231            $$.init($4);
19232          }
19233        ;
19234
19235%endif ORACLE
19236
19237/**
19238  @} (end of group Parser)
19239*/
19240