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_acl.h"                          /* *_ACL */
42#include "sql_class.h"      /* Key_part_spec, enum_filetype, Diag_condition_item_name */
43#include "slave.h"
44#include "lex_symbol.h"
45#include "item_create.h"
46#include "sp_head.h"
47#include "sp_rcontext.h"
48#include "sp.h"
49#include "sql_show.h"
50#include "sql_alter.h"                         // Sql_cmd_alter_table*
51#include "sql_truncate.h"                      // Sql_cmd_truncate_table
52#include "sql_admin.h"                         // Sql_cmd_analyze/Check..._table
53#include "sql_partition_admin.h"               // Sql_cmd_alter_table_*_part.
54#include "sql_handler.h"                       // Sql_cmd_handler_*
55#include "sql_signal.h"
56#include "sql_get_diagnostics.h"               // Sql_cmd_get_diagnostics
57#include "sql_cte.h"
58#include "sql_window.h"
59#include "item_windowfunc.h"
60#include "event_parse_data.h"
61#include "create_options.h"
62#include <myisam.h>
63#include <myisammrg.h>
64#include "keycaches.h"
65#include "set_var.h"
66#include "rpl_mi.h"
67#include "lex_token.h"
68#include "sql_lex.h"
69#include "sql_sequence.h"
70#include "my_base.h"
71#include "sql_type_json.h"
72
73/* this is to get the bison compilation windows warnings out */
74#ifdef _MSC_VER
75/* warning C4065: switch statement contains 'default' but no 'case' labels */
76/* warning C4102: 'yyexhaustedlab': unreferenced label */
77#pragma warning (disable : 4065 4102)
78#endif
79#ifdef __GNUC__
80#pragma GCC diagnostic ignored "-Wunused-label" /* yyexhaustedlab: */
81#endif
82
83int yylex(void *yylval, void *yythd);
84
85#define yyoverflow(A,B,C,D,E,F)               \
86  {                                           \
87    size_t val= *(F);                          \
88    if (unlikely(my_yyoverflow((B), (D), &val))) \
89    {                                         \
90      yyerror(thd, (char*) (A));              \
91      return 2;                               \
92    }                                         \
93    else                                      \
94    {                                         \
95      *(F)= (YYSIZE_T)val;                    \
96    }                                         \
97  }
98
99#define MYSQL_YYABORT                         \
100  do                                          \
101  {                                           \
102    LEX::cleanup_lex_after_parse_error(thd);  \
103    YYABORT;                                  \
104  } while (0)
105
106#define MYSQL_YYABORT_UNLESS(A)                  \
107  if (unlikely(!(A)))                            \
108  {                                              \
109    thd->parse_error();                          \
110    MYSQL_YYABORT;                               \
111  }
112
113#define my_yyabort_error(A)                      \
114  do { my_error A; MYSQL_YYABORT; } while(0)
115
116#ifndef DBUG_OFF
117#define YYDEBUG 1
118#else
119#define YYDEBUG 0
120#endif
121
122
123static Item* escape(THD *thd)
124{
125  thd->lex->escape_used= false;
126  const char *esc= thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES ? "" : "\\";
127  return new (thd->mem_root) Item_string_ascii(thd, esc, MY_TEST(esc[0]));
128}
129
130
131/**
132  @brief Bison callback to report a syntax/OOM error
133
134  This function is invoked by the bison-generated parser
135  when a syntax error, a parse error or an out-of-memory
136  condition occurs. This function is not invoked when the
137  parser is requested to abort by semantic action code
138  by means of YYABORT or YYACCEPT macros. This is why these
139  macros should not be used (use MYSQL_YYABORT/MYSQL_YYACCEPT
140  instead).
141
142  The parser will abort immediately after invoking this callback.
143
144  This function is not for use in semantic actions and is internal to
145  the parser, as it performs some pre-return cleanup.
146  In semantic actions, please use thd->parse_error() or my_error to
147  push an error into the error stack and MYSQL_YYABORT
148  to abort from the parser.
149*/
150
151void ORAerror(THD *thd, const char *s)
152{
153  /*
154    Restore the original LEX if it was replaced when parsing
155    a stored procedure. We must ensure that a parsing error
156    does not leave any side effects in the THD.
157  */
158  LEX::cleanup_lex_after_parse_error(thd);
159
160  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
161  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
162    s= ER_THD(thd, ER_SYNTAX_ERROR);
163  thd->parse_error(s, 0);
164}
165
166
167
168
169#define bincmp_collation(X,Y)           \
170  do                                    \
171  {                                     \
172     if (unlikely(Lex->set_bincmp(X,Y))) \
173       MYSQL_YYABORT;                   \
174  } while(0)
175
176%}
177%union {
178  int  num;
179  ulong ulong_num;
180  ulonglong ulonglong_number;
181  longlong longlong_number;
182  uint sp_instr_addr;
183
184  /* structs */
185  LEX_CSTRING lex_str;
186  Lex_ident_cli_st kwd;
187  Lex_ident_cli_st ident_cli;
188  Lex_ident_sys_st ident_sys;
189  Lex_string_with_metadata_st lex_string_with_metadata;
190  Lex_spblock_st spblock;
191  Lex_spblock_handlers_st spblock_handlers;
192  Lex_length_and_dec_st Lex_length_and_dec;
193  Lex_cast_type_st Lex_cast_type;
194  Lex_field_type_st Lex_field_type;
195  Lex_dyncol_type_st Lex_dyncol_type;
196  Lex_for_loop_st for_loop;
197  Lex_for_loop_bounds_st for_loop_bounds;
198  Lex_trim_st trim;
199  vers_history_point_t vers_history_point;
200  struct
201  {
202    enum sub_select_type unit_type;
203    bool distinct;
204  } unit_operation;
205  struct
206  {
207    SELECT_LEX *first;
208    SELECT_LEX *prev_last;
209  } select_list;
210  SQL_I_List<ORDER> *select_order;
211  Lex_select_lock select_lock;
212  Lex_select_limit select_limit;
213  Lex_order_limit_lock *order_limit_lock;
214
215  /* pointers */
216  Create_field *create_field;
217  Spvar_definition *spvar_definition;
218  Row_definition_list *spvar_definition_list;
219  const Type_handler *type_handler;
220  CHARSET_INFO *charset;
221  Condition_information_item *cond_info_item;
222  DYNCALL_CREATE_DEF *dyncol_def;
223  Diagnostics_information *diag_info;
224  Item *item;
225  Item_num *item_num;
226  Item_param *item_param;
227  Item_basic_constant *item_basic_constant;
228  Key_part_spec *key_part;
229  LEX *lex;
230  sp_assignment_lex *assignment_lex;
231  class sp_lex_cursor *sp_cursor_stmt;
232  LEX_CSTRING *lex_str_ptr;
233  LEX_USER *lex_user;
234  USER_AUTH *user_auth;
235  List<Condition_information_item> *cond_info_list;
236  List<DYNCALL_CREATE_DEF> *dyncol_def_list;
237  List<Item> *item_list;
238  List<sp_assignment_lex> *sp_assignment_lex_list;
239  List<Statement_information_item> *stmt_info_list;
240  List<String> *string_list;
241  List<LEX_CSTRING> *lex_str_list;
242  Statement_information_item *stmt_info_item;
243  String *string;
244  TABLE_LIST *table_list;
245  Table_ident *table;
246  Qualified_column_ident *qualified_column_ident;
247  char *simple_string;
248  const char *const_simple_string;
249  chooser_compare_func_creator boolfunc2creator;
250  class my_var *myvar;
251  class sp_condition_value *spcondvalue;
252  class sp_head *sphead;
253  class sp_name *spname;
254  class sp_variable *spvar;
255  class With_element_head *with_element_head;
256  class With_clause *with_clause;
257  class Virtual_column_info *virtual_column;
258
259  handlerton *db_type;
260  st_select_lex *select_lex;
261  st_select_lex_unit *select_lex_unit;
262  struct p_elem_val *p_elem_value;
263  class Window_frame *window_frame;
264  class Window_frame_bound *window_frame_bound;
265  udf_func *udf;
266  st_trg_execution_order trg_execution_order;
267
268  /* enums */
269  enum enum_sp_suid_behaviour sp_suid;
270  enum enum_sp_aggregate_type sp_aggregate_type;
271  enum enum_view_suid view_suid;
272  enum Condition_information_item::Name cond_info_item_name;
273  enum enum_diag_condition_item_name diag_condition_item_name;
274  enum Diagnostics_information::Which_area diag_area;
275  enum Field::geometry_type geom_type;
276  enum enum_fk_option m_fk_option;
277  enum Item_udftype udf_type;
278  enum Key::Keytype key_type;
279  enum Statement_information_item::Name stmt_info_item_name;
280  enum enum_filetype filetype;
281  enum enum_tx_isolation tx_isolation;
282  enum enum_var_type var_type;
283  enum enum_yes_no_unknown m_yes_no_unk;
284  enum ha_choice choice;
285  enum ha_key_alg key_alg;
286  enum ha_rkey_function ha_rkey_mode;
287  enum index_hint_type index_hint;
288  enum interval_type interval, interval_time_st;
289  enum row_type row_type;
290  enum sp_variable::enum_mode spvar_mode;
291  enum thr_lock_type lock_type;
292  enum enum_mysql_timestamp_type date_time_type;
293  enum Window_frame_bound::Bound_precedence_type bound_precedence_type;
294  enum Window_frame::Frame_units frame_units;
295  enum Window_frame::Frame_exclusion frame_exclusion;
296  enum trigger_order_type trigger_action_order_type;
297  DDL_options_st object_ddl_options;
298  enum vers_sys_type_t vers_range_unit;
299  enum Column_definition::enum_column_versioning vers_column_versioning;
300  enum plsql_cursor_attr_t plsql_cursor_attr;
301}
302
303%{
304bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
305%}
306
307%pure-parser                                    /* We have threads */
308%parse-param { THD *thd }
309%lex-param { THD *thd }
310/*
311  We should not introduce any further shift/reduce conflicts.
312*/
313%expect 70
314
315/*
316   Comments for TOKENS.
317   For each token, please include in the same line a comment that contains
318   the following tags:
319   SQL-2011-R : Reserved keyword as per SQL-2011
320   SQL-2011-N : Non Reserved keyword as per SQL-2011
321   SQL-2003-R : Reserved keyword as per SQL-2003
322   SQL-2003-N : Non Reserved keyword as per SQL-2003
323   SQL-1999-R : Reserved keyword as per SQL-1999
324   SQL-1999-N : Non Reserved keyword as per SQL-1999
325   MYSQL      : MySQL extention (unspecified)
326   MYSQL-FUNC : MySQL extention, function
327   INTERNAL   : Not a real token, lex optimization
328   OPERATOR   : SQL operator
329   FUTURE-USE : Reserved for future use
330
331   This makes the code grep-able, and helps maintenance.
332*/
333
334
335/*
336  Reserved keywords and operators
337*/
338%token  ABORT_SYM                     /* INTERNAL (used in lex) */
339%token  ACCESSIBLE_SYM
340%token  ADD                           /* SQL-2003-R */
341%token  ALL                           /* SQL-2003-R */
342%token  ALTER                         /* SQL-2003-R */
343%token  ANALYZE_SYM
344%token  AND_AND_SYM                   /* OPERATOR */
345%token  AND_SYM                       /* SQL-2003-R */
346%token  AS                            /* SQL-2003-R */
347%token  ASC                           /* SQL-2003-N */
348%token  ASENSITIVE_SYM                /* FUTURE-USE */
349%token  BEFORE_SYM                    /* SQL-2003-N */
350%token  BETWEEN_SYM                   /* SQL-2003-R */
351%token  BIGINT                        /* SQL-2003-R */
352%token  BINARY                        /* SQL-2003-R */
353%token  BIN_NUM
354%token  BIT_AND                       /* MYSQL-FUNC */
355%token  BIT_OR                        /* MYSQL-FUNC */
356%token  BIT_XOR                       /* MYSQL-FUNC */
357%token  BLOB_MARIADB_SYM              /* SQL-2003-R */
358%token  BLOB_ORACLE_SYM               /* Oracle-R   */
359%token  BODY_ORACLE_SYM               /* Oracle-R   */
360%token  BOTH                          /* SQL-2003-R */
361%token  BY                            /* SQL-2003-R */
362%token  CALL_SYM                      /* SQL-2003-R */
363%token  CASCADE                       /* SQL-2003-N */
364%token  CASE_SYM                      /* SQL-2003-R */
365%token  CAST_SYM                      /* SQL-2003-R */
366%token  CHANGE
367%token  CHAR_SYM                      /* SQL-2003-R */
368%token  CHECK_SYM                     /* SQL-2003-R */
369%token  COLLATE_SYM                   /* SQL-2003-R */
370%token  CONDITION_SYM                 /* SQL-2003-R, SQL-2008-R */
371%token  CONSTRAINT                    /* SQL-2003-R */
372%token  CONTINUE_MARIADB_SYM          /* SQL-2003-R, Oracle-R */
373%token  CONTINUE_ORACLE_SYM           /* SQL-2003-R, Oracle-R */
374%token  CONVERT_SYM                   /* SQL-2003-N */
375%token  COUNT_SYM                     /* SQL-2003-N */
376%token  CREATE                        /* SQL-2003-R */
377%token  CROSS                         /* SQL-2003-R */
378%token  CUME_DIST_SYM
379%token  CURDATE                       /* MYSQL-FUNC */
380%token  CURRENT_USER                  /* SQL-2003-R */
381%token  CURRENT_ROLE                  /* SQL-2003-R */
382%token  CURSOR_SYM                    /* SQL-2003-R */
383%token  CURTIME                       /* MYSQL-FUNC */
384%token  DATABASE
385%token  DATABASES
386%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
387%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
388%token  DAY_HOUR_SYM
389%token  DAY_MICROSECOND_SYM
390%token  DAY_MINUTE_SYM
391%token  DAY_SECOND_SYM
392%token  DECIMAL_NUM
393%token  DECIMAL_SYM                   /* SQL-2003-R */
394%token  DECLARE_MARIADB_SYM           /* SQL-2003-R */
395%token  DECLARE_ORACLE_SYM            /* Oracle-R   */
396%token  DEFAULT                       /* SQL-2003-R */
397%token  DELETE_DOMAIN_ID_SYM
398%token  DELETE_SYM                    /* SQL-2003-R */
399%token  DENSE_RANK_SYM
400%token  DESC                          /* SQL-2003-N */
401%token  DESCRIBE                      /* SQL-2003-R */
402%token  DETERMINISTIC_SYM             /* SQL-2003-R */
403%token  DISTINCT                      /* SQL-2003-R */
404%token  DIV_SYM
405%token  DOUBLE_SYM                    /* SQL-2003-R */
406%token  DO_DOMAIN_IDS_SYM
407%token  DOT_DOT_SYM
408%token  DROP                          /* SQL-2003-R */
409%token  DUAL_SYM
410%token  EACH_SYM                      /* SQL-2003-R */
411%token  ELSE                          /* SQL-2003-R */
412%token  ELSEIF_MARIADB_SYM
413%token  ELSIF_ORACLE_SYM              /* PLSQL-R    */
414%token  ENCLOSED
415%token  END_OF_INPUT                  /* INTERNAL */
416%token  EQUAL_SYM                     /* OPERATOR */
417%token  ESCAPED
418%token  EXCEPT_SYM                    /* SQL-2003-R */
419%token  EXISTS                        /* SQL-2003-R */
420%token  EXTRACT_SYM                   /* SQL-2003-N */
421%token  FALSE_SYM                     /* SQL-2003-R */
422%token  FETCH_SYM                     /* SQL-2003-R */
423%token  FIRST_VALUE_SYM               /* SQL-2011 */
424%token  FLOAT_NUM
425%token  FLOAT_SYM                     /* SQL-2003-R */
426%token  FOREIGN                       /* SQL-2003-R */
427%token  FOR_SYM                       /* SQL-2003-R */
428%token  FOR_SYSTEM_TIME_SYM           /* INTERNAL */
429%token  FROM
430%token  FULLTEXT_SYM
431%token  GE
432%token  GOTO_ORACLE_SYM               /* Oracle-R   */
433%token  GRANT                         /* SQL-2003-R */
434%token  GROUP_SYM                     /* SQL-2003-R */
435%token  GROUP_CONCAT_SYM
436%token  LAG_SYM                       /* SQL-2011 */
437%token  LEAD_SYM                      /* SQL-2011 */
438%token  HAVING                        /* SQL-2003-R */
439%token  HEX_NUM
440%token  HEX_STRING
441%token  HOUR_MICROSECOND_SYM
442%token  HOUR_MINUTE_SYM
443%token  HOUR_SECOND_SYM
444%token  IDENT
445%token  IDENT_QUOTED
446%token  IF_SYM
447%token  IGNORE_DOMAIN_IDS_SYM
448%token  IGNORE_SYM
449%token  INDEX_SYM
450%token  INFILE
451%token  INNER_SYM                     /* SQL-2003-R */
452%token  INOUT_SYM                     /* SQL-2003-R */
453%token  INSENSITIVE_SYM               /* SQL-2003-R */
454%token  INSERT                        /* SQL-2003-R */
455%token  INTERSECT_SYM                 /* SQL-2003-R */
456%token  INTERVAL_SYM                  /* SQL-2003-R */
457%token  INTO                          /* SQL-2003-R */
458%token  INT_SYM                       /* SQL-2003-R */
459%token  IN_SYM                        /* SQL-2003-R */
460%token  IS                            /* SQL-2003-R */
461%token  ITERATE_SYM
462%token  JOIN_SYM                      /* SQL-2003-R */
463%token  KEYS
464%token  KEY_SYM                       /* SQL-2003-N */
465%token  KILL_SYM
466%token  LE                            /* OPERATOR */
467%token  LEADING                       /* SQL-2003-R */
468%token  LEAVE_SYM
469%token  LEFT                          /* SQL-2003-R */
470%token  LEFT_PAREN_ALT                /* INTERNAL */
471%token  LEFT_PAREN_WITH               /* INTERNAL */
472%token  LEFT_PAREN_LIKE               /* INTERNAL */
473%token  LEX_HOSTNAME
474%token  LIKE                          /* SQL-2003-R */
475%token  LIMIT
476%token  LINEAR_SYM
477%token  LINES
478%token  LOAD
479%token  LOCATOR_SYM                   /* SQL-2003-N */
480%token  LOCK_SYM
481%token  LONGBLOB
482%token  LONGTEXT
483%token  LONG_NUM
484%token  LONG_SYM
485%token  LOOP_SYM
486%token  LOW_PRIORITY
487%token  MASTER_SSL_VERIFY_SERVER_CERT_SYM
488%token  MATCH                         /* SQL-2003-R */
489%token  MAX_SYM                       /* SQL-2003-N */
490%token  MAXVALUE_SYM                 /* SQL-2003-N */
491%token  MEDIAN_SYM
492%token  MEDIUMBLOB
493%token  MEDIUMINT
494%token  MEDIUMTEXT
495%token  MINUTE_MICROSECOND_SYM
496%token  MINUTE_SECOND_SYM
497%token  MIN_SYM                       /* SQL-2003-N */
498%token  MODIFIES_SYM                  /* SQL-2003-R */
499%token  MOD_SYM                       /* SQL-2003-N */
500%token  MYSQL_CONCAT_SYM              /* OPERATOR */
501%token  NATURAL                       /* SQL-2003-R */
502%token  NCHAR_STRING
503%token  NE                            /* OPERATOR */
504%token  NEG
505%token  NOT2_SYM
506%token  NOT_SYM                       /* SQL-2003-R */
507%token  NOW_SYM
508%token  NO_WRITE_TO_BINLOG
509%token  NTILE_SYM
510%token  NULL_SYM                      /* SQL-2003-R */
511%token  NUM
512%token  NUMERIC_SYM                   /* SQL-2003-R */
513%token  NTH_VALUE_SYM                 /* SQL-2011 */
514%token  ON                            /* SQL-2003-R */
515%token  OPTIMIZE
516%token  OPTIONALLY
517%token  ORACLE_CONCAT_SYM             /* INTERNAL */
518%token  OR2_SYM
519%token  ORDER_SYM                     /* SQL-2003-R */
520%token  OR_SYM                        /* SQL-2003-R */
521%token  OTHERS_ORACLE_SYM             /* SQL-2011-N, PLSQL-R */
522%token  OUTER
523%token  OUTFILE
524%token  OUT_SYM                       /* SQL-2003-R */
525%token  OVER_SYM
526%token  PACKAGE_ORACLE_SYM            /* Oracle-R   */
527%token  PAGE_CHECKSUM_SYM
528%token  PARAM_MARKER
529%token  PARSE_VCOL_EXPR_SYM
530%token  PARTITION_SYM                 /* SQL-2003-R */
531%token  PERCENT_ORACLE_SYM            /* INTERNAL   */
532%token  PERCENT_RANK_SYM
533%token  PERCENTILE_CONT_SYM
534%token  PERCENTILE_DISC_SYM
535%token  PORTION_SYM                   /* SQL-2016-R */
536%token  POSITION_SYM                  /* SQL-2003-N */
537%token  PRECISION                     /* SQL-2003-R */
538%token  PRIMARY_SYM                   /* SQL-2003-R */
539%token  PROCEDURE_SYM                 /* SQL-2003-R */
540%token  PURGE
541%token  RAISE_ORACLE_SYM              /* PLSQL-R    */
542%token  RANGE_SYM                     /* SQL-2003-R */
543%token  RANK_SYM
544%token  READS_SYM                     /* SQL-2003-R */
545%token  READ_SYM                      /* SQL-2003-N */
546%token  READ_WRITE_SYM
547%token  REAL                          /* SQL-2003-R */
548%token  RECURSIVE_SYM
549%token  REF_SYSTEM_ID_SYM
550%token  REFERENCES                    /* SQL-2003-R */
551%token  REGEXP
552%token  RELEASE_SYM                   /* SQL-2003-R */
553%token  RENAME
554%token  REPEAT_SYM                    /* MYSQL-FUNC */
555%token  REPLACE                       /* MYSQL-FUNC */
556%token  REQUIRE_SYM
557%token  RESIGNAL_SYM                  /* SQL-2003-R */
558%token  RESTRICT
559%token  RETURNING_SYM
560%token  RETURN_MARIADB_SYM            /* SQL-2003-R, PLSQL-R */
561%token  RETURN_ORACLE_SYM             /* SQL-2003-R, PLSQL-R */
562%token  REVOKE                        /* SQL-2003-R */
563%token  RIGHT                         /* SQL-2003-R */
564%token  ROWS_SYM                      /* SQL-2003-R */
565%token  ROWTYPE_ORACLE_SYM            /* PLSQL-R    */
566%token  ROW_NUMBER_SYM
567%token  SECOND_MICROSECOND_SYM
568%token  SELECT_SYM                    /* SQL-2003-R */
569%token  SENSITIVE_SYM                 /* FUTURE-USE */
570%token  SEPARATOR_SYM
571%token  SERVER_OPTIONS
572%token  SET                           /* SQL-2003-R */
573%token  SET_VAR
574%token  SHIFT_LEFT                    /* OPERATOR */
575%token  SHIFT_RIGHT                   /* OPERATOR */
576%token  SHOW
577%token  SIGNAL_SYM                    /* SQL-2003-R */
578%token  SMALLINT                      /* SQL-2003-R */
579%token  SPATIAL_SYM
580%token  SPECIFIC_SYM                  /* SQL-2003-R */
581%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
582%token  SQLSTATE_SYM                  /* SQL-2003-R */
583%token  SQLWARNING_SYM                /* SQL-2003-R */
584%token  SQL_BIG_RESULT
585%token  SQL_SMALL_RESULT
586%token  SQL_SYM                       /* SQL-2003-R */
587%token  SSL_SYM
588%token  STARTING
589%token  STATS_AUTO_RECALC_SYM
590%token  STATS_PERSISTENT_SYM
591%token  STATS_SAMPLE_PAGES_SYM
592%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
593%token  STD_SYM
594%token  STRAIGHT_JOIN
595%token  SUBSTRING                     /* SQL-2003-N */
596%token  SUM_SYM                       /* SQL-2003-N */
597%token  SYSDATE
598%token  TABLE_REF_PRIORITY
599%token  TABLE_SYM                     /* SQL-2003-R */
600%token  TERMINATED
601%token  TEXT_STRING
602%token  THEN_SYM                      /* SQL-2003-R */
603%token  TINYBLOB
604%token  TINYINT
605%token  TINYTEXT
606%token  TO_SYM                        /* SQL-2003-R */
607%token  TRAILING                      /* SQL-2003-R */
608%token  TRIGGER_SYM                   /* SQL-2003-R */
609%token  TRIM                          /* SQL-2003-N */
610%token  TRUE_SYM                      /* SQL-2003-R */
611%token  ULONGLONG_NUM
612%token  UNDERSCORE_CHARSET
613%token  UNDO_SYM                      /* FUTURE-USE */
614%token  UNION_SYM                     /* SQL-2003-R */
615%token  UNIQUE_SYM
616%token  UNLOCK_SYM
617%token  UNSIGNED
618%token  UPDATE_SYM                    /* SQL-2003-R */
619%token  USAGE                         /* SQL-2003-N */
620%token  USE_SYM
621%token  USING                         /* SQL-2003-R */
622%token  UTC_DATE_SYM
623%token  UTC_TIMESTAMP_SYM
624%token  UTC_TIME_SYM
625%token  VALUES                        /* SQL-2003-R */
626%token  VALUES_IN_SYM
627%token  VALUES_LESS_SYM
628%token  VARBINARY
629%token  VARCHAR                       /* SQL-2003-R */
630%token  VARIANCE_SYM
631%token  VARYING                       /* SQL-2003-R */
632%token  VAR_SAMP_SYM
633%token  WHEN_SYM                      /* SQL-2003-R */
634%token  WHERE                         /* SQL-2003-R */
635%token  WHILE_SYM
636%token  WITH                          /* SQL-2003-R */
637%token  WITH_CUBE_SYM                 /* INTERNAL */
638%token  WITH_ROLLUP_SYM               /* INTERNAL */
639%token  WITH_SYSTEM_SYM               /* INTERNAL */
640%token  XOR
641%token  YEAR_MONTH_SYM
642%token  ZEROFILL
643
644%token IMPOSSIBLE_ACTION                /* To avoid warning for yyerrlab1 */
645
646
647/*
648  Keywords that have different reserved status in std/oracle modes.
649*/
650%token  <kwd>  BODY_MARIADB_SYM              // Oracle-R
651%token  <kwd>  ELSEIF_ORACLE_SYM
652%token  <kwd>  ELSIF_MARIADB_SYM             // PLSQL-R
653%token  <kwd>  EXCEPTION_ORACLE_SYM          // SQL-2003-N, PLSQL-R
654%token  <kwd>  GOTO_MARIADB_SYM              // Oracle-R
655%token  <kwd>  OTHERS_MARIADB_SYM            // SQL-2011-N, PLSQL-R
656%token  <kwd>  PACKAGE_MARIADB_SYM           // Oracle-R
657%token  <kwd>  RAISE_MARIADB_SYM             // PLSQL-R
658%token  <kwd>  ROWTYPE_MARIADB_SYM           // PLSQL-R
659
660/*
661  Non-reserved keywords
662*/
663
664%token  <kwd>  ACCOUNT_SYM                   /* MYSQL */
665%token  <kwd>  ACTION                        /* SQL-2003-N */
666%token  <kwd>  ADMIN_SYM                     /* SQL-2003-N */
667%token  <kwd>  ADDDATE_SYM                   /* MYSQL-FUNC */
668%token  <kwd>  AFTER_SYM                     /* SQL-2003-N */
669%token  <kwd>  AGAINST
670%token  <kwd>  AGGREGATE_SYM
671%token  <kwd>  ALGORITHM_SYM
672%token  <kwd>  ALWAYS_SYM
673%token  <kwd>  ANY_SYM                       /* SQL-2003-R */
674%token  <kwd>  ASCII_SYM                     /* MYSQL-FUNC */
675%token  <kwd>  AT_SYM                        /* SQL-2003-R */
676%token  <kwd>  ATOMIC_SYM                    /* SQL-2003-R */
677%token  <kwd>  AUTHORS_SYM
678%token  <kwd>  AUTOEXTEND_SIZE_SYM
679%token  <kwd>  AUTO_INC
680%token  <kwd>  AUTO_SYM
681%token  <kwd>  AVG_ROW_LENGTH
682%token  <kwd>  AVG_SYM                       /* SQL-2003-N */
683%token  <kwd>  BACKUP_SYM
684%token  <kwd>  BEGIN_MARIADB_SYM             /* SQL-2003-R, PLSQL-R */
685%token  <kwd>  BEGIN_ORACLE_SYM              /* SQL-2003-R, PLSQL-R */
686%token  <kwd>  BINLOG_SYM
687%token  <kwd>  BIT_SYM                       /* MYSQL-FUNC */
688%token  <kwd>  BLOCK_SYM
689%token  <kwd>  BOOL_SYM
690%token  <kwd>  BOOLEAN_SYM                   /* SQL-2003-R, PLSQL-R */
691%token  <kwd>  BTREE_SYM
692%token  <kwd>  BYTE_SYM
693%token  <kwd>  CACHE_SYM
694%token  <kwd>  CASCADED                      /* SQL-2003-R */
695%token  <kwd>  CATALOG_NAME_SYM              /* SQL-2003-N */
696%token  <kwd>  CHAIN_SYM                     /* SQL-2003-N */
697%token  <kwd>  CHANGED
698%token  <kwd>  CHARSET
699%token  <kwd>  CHECKPOINT_SYM
700%token  <kwd>  CHECKSUM_SYM
701%token  <kwd>  CIPHER_SYM
702%token  <kwd>  CLASS_ORIGIN_SYM              /* SQL-2003-N */
703%token  <kwd>  CLIENT_SYM
704%token  <kwd>  CLOB_MARIADB_SYM              /* SQL-2003-R */
705%token  <kwd>  CLOB_ORACLE_SYM               /* Oracle-R   */
706%token  <kwd>  CLOSE_SYM                     /* SQL-2003-R */
707%token  <kwd>  COALESCE                      /* SQL-2003-N */
708%token  <kwd>  CODE_SYM
709%token  <kwd>  COLLATION_SYM                 /* SQL-2003-N */
710%token  <kwd>  COLON_ORACLE_SYM              /* INTERNAL   */
711%token  <kwd>  COLUMNS
712%token  <kwd>  COLUMN_ADD_SYM
713%token  <kwd>  COLUMN_CHECK_SYM
714%token  <kwd>  COLUMN_CREATE_SYM
715%token  <kwd>  COLUMN_DELETE_SYM
716%token  <kwd>  COLUMN_GET_SYM
717%token  <kwd>  COLUMN_SYM                    /* SQL-2003-R */
718%token  <kwd>  COLUMN_NAME_SYM               /* SQL-2003-N */
719%token  <kwd>  COMMENT_SYM                   /* Oracle-R   */
720%token  <kwd>  COMMITTED_SYM                 /* SQL-2003-N */
721%token  <kwd>  COMMIT_SYM                    /* SQL-2003-R */
722%token  <kwd>  COMPACT_SYM
723%token  <kwd>  COMPLETION_SYM
724%token  <kwd>  COMPRESSED_SYM
725%token  <kwd>  CONCURRENT
726%token  <kwd>  CONNECTION_SYM
727%token  <kwd>  CONSISTENT_SYM
728%token  <kwd>  CONSTRAINT_CATALOG_SYM        /* SQL-2003-N */
729%token  <kwd>  CONSTRAINT_NAME_SYM           /* SQL-2003-N */
730%token  <kwd>  CONSTRAINT_SCHEMA_SYM         /* SQL-2003-N */
731%token  <kwd>  CONTAINS_SYM                  /* SQL-2003-N */
732%token  <kwd>  CONTEXT_SYM
733%token  <kwd>  CONTRIBUTORS_SYM
734%token  <kwd>  CPU_SYM
735%token  <kwd>  CUBE_SYM                      /* SQL-2003-R */
736%token  <kwd>  CURRENT_SYM                   /* SQL-2003-R */
737%token  <kwd>  CURRENT_POS_SYM
738%token  <kwd>  CURSOR_NAME_SYM               /* SQL-2003-N */
739%token  <kwd>  CYCLE_SYM
740%token  <kwd>  DATAFILE_SYM
741%token  <kwd>  DATA_SYM                      /* SQL-2003-N */
742%token  <kwd>  DATETIME
743%token  <kwd>  DATE_FORMAT_SYM               /* MYSQL-FUNC */
744%token  <kwd>  DATE_SYM                      /* SQL-2003-R, Oracle-R, PLSQL-R */
745%token  <kwd>  DAY_SYM                       /* SQL-2003-R */
746%token  <kwd>  DEALLOCATE_SYM                /* SQL-2003-R */
747%token  <kwd>  DECODE_MARIADB_SYM            /* Function, non-reserved */
748%token  <kwd>  DECODE_ORACLE_SYM             /* Function, non-reserved */
749%token  <kwd>  DEFINER_SYM
750%token  <kwd>  DELAYED_SYM
751%token  <kwd>  DELAY_KEY_WRITE_SYM
752%token  <kwd>  DES_KEY_FILE
753%token  <kwd>  DIAGNOSTICS_SYM               /* SQL-2003-N */
754%token  <kwd>  DIRECTORY_SYM
755%token  <kwd>  DISABLE_SYM
756%token  <kwd>  DISCARD
757%token  <kwd>  DISK_SYM
758%token  <kwd>  DO_SYM
759%token  <kwd>  DUMPFILE
760%token  <kwd>  DUPLICATE_SYM
761%token  <kwd>  DYNAMIC_SYM                   /* SQL-2003-R */
762%token  <kwd>  ENABLE_SYM
763%token  <kwd>  END                           /* SQL-2003-R, PLSQL-R */
764%token  <kwd>  ENDS_SYM
765%token  <kwd>  ENGINES_SYM
766%token  <kwd>  ENGINE_SYM
767%token  <kwd>  ENUM
768%token  <kwd>  ERROR_SYM
769%token  <kwd>  ERRORS
770%token  <kwd>  ESCAPE_SYM                    /* SQL-2003-R */
771%token  <kwd>  EVENTS_SYM
772%token  <kwd>  EVENT_SYM
773%token  <kwd>  EVERY_SYM                     /* SQL-2003-N */
774%token  <kwd>  EXCHANGE_SYM
775%token  <kwd>  EXAMINED_SYM
776%token  <kwd>  EXCLUDE_SYM                   /* SQL-2011-N */
777%token  <kwd>  EXECUTE_SYM                   /* SQL-2003-R */
778%token  <kwd>  EXCEPTION_MARIADB_SYM         /* SQL-2003-N, PLSQL-R */
779%token  <kwd>  EXIT_MARIADB_SYM              /* PLSQL-R */
780%token  <kwd>  EXIT_ORACLE_SYM               /* PLSQL-R */
781%token  <kwd>  EXPANSION_SYM
782%token  <kwd>  EXPIRE_SYM                    /* MySQL */
783%token  <kwd>  EXPORT_SYM
784%token  <kwd>  EXTENDED_SYM
785%token  <kwd>  EXTENT_SIZE_SYM
786%token  <kwd>  FAST_SYM
787%token  <kwd>  FAULTS_SYM
788%token  <kwd>  FILE_SYM
789%token  <kwd>  FIRST_SYM                     /* SQL-2003-N */
790%token  <kwd>  FIXED_SYM
791%token  <kwd>  FLUSH_SYM
792%token  <kwd>  FOLLOWS_SYM                   /* MYSQL trigger*/
793%token  <kwd>  FOLLOWING_SYM                 /* SQL-2011-N */
794%token  <kwd>  FORCE_SYM
795%token  <kwd>  FORMAT_SYM
796%token  <kwd>  FOUND_SYM                     /* SQL-2003-R */
797%token  <kwd>  FULL                          /* SQL-2003-R */
798%token  <kwd>  FUNCTION_SYM                  /* SQL-2003-R, Oracle-R */
799%token  <kwd>  GENERAL
800%token  <kwd>  GENERATED_SYM
801%token  <kwd>  GEOMETRYCOLLECTION
802%token  <kwd>  GEOMETRY_SYM
803%token  <kwd>  GET_FORMAT                    /* MYSQL-FUNC */
804%token  <kwd>  GET_SYM                       /* SQL-2003-R */
805%token  <kwd>  GLOBAL_SYM                    /* SQL-2003-R */
806%token  <kwd>  GRANTS
807%token  <kwd>  HANDLER_SYM
808%token  <kwd>  HARD_SYM
809%token  <kwd>  HASH_SYM
810%token  <kwd>  HELP_SYM
811%token  <kwd>  HIGH_PRIORITY
812%token  <kwd>  HISTORY_SYM                   /* MYSQL */
813%token  <kwd>  HOST_SYM
814%token  <kwd>  HOSTS_SYM
815%token  <kwd>  HOUR_SYM                      /* SQL-2003-R */
816%token  <kwd>  ID_SYM                        /* MYSQL */
817%token  <kwd>  IDENTIFIED_SYM
818%token  <kwd>  IGNORE_SERVER_IDS_SYM
819%token  <kwd>  IMMEDIATE_SYM                 /* SQL-2003-R */
820%token  <kwd>  IMPORT
821%token  <kwd>  INCREMENT_SYM
822%token  <kwd>  INDEXES
823%token  <kwd>  INITIAL_SIZE_SYM
824%token  <kwd>  INSERT_METHOD
825%token  <kwd>  INSTALL_SYM
826%token  <kwd>  INVOKER_SYM
827%token  <kwd>  IO_SYM
828%token  <kwd>  IPC_SYM
829%token  <kwd>  ISOLATION                     /* SQL-2003-R */
830%token  <kwd>  ISOPEN_SYM                    /* Oracle-N   */
831%token  <kwd>  ISSUER_SYM
832%token  <kwd>  INVISIBLE_SYM
833%token  <kwd>  JSON_SYM
834%token  <kwd>  KEY_BLOCK_SIZE
835%token  <kwd>  LANGUAGE_SYM                  /* SQL-2003-R */
836%token  <kwd>  LAST_SYM                      /* SQL-2003-N */
837%token  <kwd>  LAST_VALUE
838%token  <kwd>  LASTVAL_SYM                   /* PostgreSQL sequence function */
839%token  <kwd>  LEAVES
840%token  <kwd>  LESS_SYM
841%token  <kwd>  LEVEL_SYM
842%token  <kwd>  LINESTRING
843%token  <kwd>  LIST_SYM
844%token  <kwd>  LOCAL_SYM                     /* SQL-2003-R */
845%token  <kwd>  LOCKS_SYM
846%token  <kwd>  LOGFILE_SYM
847%token  <kwd>  LOGS_SYM
848%token  <kwd>  MASTER_CONNECT_RETRY_SYM
849%token  <kwd>  MASTER_DELAY_SYM
850%token  <kwd>  MASTER_GTID_POS_SYM
851%token  <kwd>  MASTER_HOST_SYM
852%token  <kwd>  MASTER_LOG_FILE_SYM
853%token  <kwd>  MASTER_LOG_POS_SYM
854%token  <kwd>  MASTER_PASSWORD_SYM
855%token  <kwd>  MASTER_PORT_SYM
856%token  <kwd>  MASTER_SERVER_ID_SYM
857%token  <kwd>  MASTER_SSL_CAPATH_SYM
858%token  <kwd>  MASTER_SSL_CA_SYM
859%token  <kwd>  MASTER_SSL_CERT_SYM
860%token  <kwd>  MASTER_SSL_CIPHER_SYM
861%token  <kwd>  MASTER_SSL_CRL_SYM
862%token  <kwd>  MASTER_SSL_CRLPATH_SYM
863%token  <kwd>  MASTER_SSL_KEY_SYM
864%token  <kwd>  MASTER_SSL_SYM
865%token  <kwd>  MASTER_SYM
866%token  <kwd>  MASTER_USER_SYM
867%token  <kwd>  MASTER_USE_GTID_SYM
868%token  <kwd>  MASTER_HEARTBEAT_PERIOD_SYM
869%token  <kwd>  MAX_CONNECTIONS_PER_HOUR
870%token  <kwd>  MAX_QUERIES_PER_HOUR
871%token  <kwd>  MAX_ROWS
872%token  <kwd>  MAX_SIZE_SYM
873%token  <kwd>  MAX_UPDATES_PER_HOUR
874%token  <kwd>  MAX_STATEMENT_TIME_SYM
875%token  <kwd>  MAX_USER_CONNECTIONS_SYM
876%token  <kwd>  MEDIUM_SYM
877%token  <kwd>  MEMORY_SYM
878%token  <kwd>  MERGE_SYM                     /* SQL-2003-R */
879%token  <kwd>  MESSAGE_TEXT_SYM              /* SQL-2003-N */
880%token  <kwd>  MICROSECOND_SYM               /* MYSQL-FUNC */
881%token  <kwd>  MIGRATE_SYM
882%token  <kwd>  MINUTE_SYM                    /* SQL-2003-R */
883%token  <kwd>  MINVALUE_SYM
884%token  <kwd>  MIN_ROWS
885%token  <kwd>  MODE_SYM
886%token  <kwd>  MODIFY_SYM
887%token  <kwd>  MONTH_SYM                     /* SQL-2003-R */
888%token  <kwd>  MULTILINESTRING
889%token  <kwd>  MULTIPOINT
890%token  <kwd>  MULTIPOLYGON
891%token  <kwd>  MUTEX_SYM
892%token  <kwd>  MYSQL_SYM
893%token  <kwd>  MYSQL_ERRNO_SYM
894%token  <kwd>  NAMES_SYM                     /* SQL-2003-N */
895%token  <kwd>  NAME_SYM                      /* SQL-2003-N */
896%token  <kwd>  NATIONAL_SYM                  /* SQL-2003-R */
897%token  <kwd>  NCHAR_SYM                     /* SQL-2003-R */
898%token  <kwd>  NEVER_SYM                     /* MySQL */
899%token  <kwd>  NEW_SYM                       /* SQL-2003-R */
900%token  <kwd>  NEXT_SYM                      /* SQL-2003-N */
901%token  <kwd>  NEXTVAL_SYM                   /* PostgreSQL sequence function */
902%token  <kwd>  NOCACHE_SYM
903%token  <kwd>  NOCYCLE_SYM
904%token  <kwd>  NODEGROUP_SYM
905%token  <kwd>  NONE_SYM                      /* SQL-2003-R */
906%token  <kwd>  NOTFOUND_SYM                  /* Oracle-R   */
907%token  <kwd>  NO_SYM                        /* SQL-2003-R */
908%token  <kwd>  NOMAXVALUE_SYM
909%token  <kwd>  NOMINVALUE_SYM
910%token  <kwd>  NO_WAIT_SYM
911%token  <kwd>  NOWAIT_SYM
912%token  <kwd>  NUMBER_MARIADB_SYM            /* SQL-2003-N  */
913%token  <kwd>  NUMBER_ORACLE_SYM             /* Oracle-R, PLSQL-R */
914%token  <kwd>  NVARCHAR_SYM
915%token  <kwd>  OF_SYM                        /* SQL-1992-R, Oracle-R */
916%token  <kwd>  OFFSET_SYM
917%token  <kwd>  OLD_PASSWORD_SYM
918%token  <kwd>  ONE_SYM
919%token  <kwd>  ONLY_SYM                      /* SQL-2003-R */
920%token  <kwd>  ONLINE_SYM
921%token  <kwd>  OPEN_SYM                      /* SQL-2003-R */
922%token  <kwd>  OPTIONS_SYM
923%token  <kwd>  OPTION                        /* SQL-2003-N */
924%token  <kwd>  OWNER_SYM
925%token  <kwd>  PACK_KEYS_SYM
926%token  <kwd>  PAGE_SYM
927%token  <kwd>  PARSER_SYM
928%token  <kwd>  PARTIAL                       /* SQL-2003-N */
929%token  <kwd>  PARTITIONS_SYM
930%token  <kwd>  PARTITIONING_SYM
931%token  <kwd>  PASSWORD_SYM
932%token  <kwd>  PERIOD_SYM                    /* SQL-2011-R */
933%token  <kwd>  PERSISTENT_SYM
934%token  <kwd>  PHASE_SYM
935%token  <kwd>  PLUGINS_SYM
936%token  <kwd>  PLUGIN_SYM
937%token  <kwd>  POINT_SYM
938%token  <kwd>  POLYGON
939%token  <kwd>  PORT_SYM
940%token  <kwd>  PRECEDES_SYM                  /* MYSQL */
941%token  <kwd>  PRECEDING_SYM                 /* SQL-2011-N */
942%token  <kwd>  PREPARE_SYM                   /* SQL-2003-R */
943%token  <kwd>  PRESERVE_SYM
944%token  <kwd>  PREV_SYM
945%token  <kwd>  PREVIOUS_SYM
946%token  <kwd>  PRIVILEGES                    /* SQL-2003-N */
947%token  <kwd>  PROCESS
948%token  <kwd>  PROCESSLIST_SYM
949%token  <kwd>  PROFILE_SYM
950%token  <kwd>  PROFILES_SYM
951%token  <kwd>  PROXY_SYM
952%token  <kwd>  QUARTER_SYM
953%token  <kwd>  QUERY_SYM
954%token  <kwd>  QUICK
955%token  <kwd>  RAW_MARIADB_SYM
956%token  <kwd>  RAW_ORACLE_SYM                /* Oracle-R */
957%token  <kwd>  READ_ONLY_SYM
958%token  <kwd>  REBUILD_SYM
959%token  <kwd>  RECOVER_SYM
960%token  <kwd>  REDOFILE_SYM
961%token  <kwd>  REDO_BUFFER_SIZE_SYM
962%token  <kwd>  REDUNDANT_SYM
963%token  <kwd>  RELAY
964%token  <kwd>  RELAYLOG_SYM
965%token  <kwd>  RELAY_LOG_FILE_SYM
966%token  <kwd>  RELAY_LOG_POS_SYM
967%token  <kwd>  RELAY_THREAD
968%token  <kwd>  RELOAD
969%token  <kwd>  REMOVE_SYM
970%token  <kwd>  REORGANIZE_SYM
971%token  <kwd>  REPAIR
972%token  <kwd>  REPEATABLE_SYM                /* SQL-2003-N */
973%token  <kwd>  REPLICATION
974%token  <kwd>  RESET_SYM
975%token  <kwd>  RESTART_SYM
976%token  <kwd>  RESOURCES
977%token  <kwd>  RESTORE_SYM
978%token  <kwd>  RESUME_SYM
979%token  <kwd>  RETURNED_SQLSTATE_SYM         /* SQL-2003-N */
980%token  <kwd>  RETURNS_SYM                   /* SQL-2003-R */
981%token  <kwd>  REUSE_SYM                     /* Oracle-R   */
982%token  <kwd>  REVERSE_SYM
983%token  <kwd>  ROLE_SYM
984%token  <kwd>  ROLLBACK_SYM                  /* SQL-2003-R */
985%token  <kwd>  ROLLUP_SYM                    /* SQL-2003-R */
986%token  <kwd>  ROUTINE_SYM                   /* SQL-2003-N */
987%token  <kwd>  ROWCOUNT_SYM                  /* Oracle-N   */
988%token  <kwd>  ROW_SYM                       /* SQL-2003-R */
989%token  <kwd>  ROW_COUNT_SYM                 /* SQL-2003-N */
990%token  <kwd>  ROW_FORMAT_SYM
991%token  <kwd>  RTREE_SYM
992%token  <kwd>  SAVEPOINT_SYM                 /* SQL-2003-R */
993%token  <kwd>  SCHEDULE_SYM
994%token  <kwd>  SCHEMA_NAME_SYM               /* SQL-2003-N */
995%token  <kwd>  SECOND_SYM                    /* SQL-2003-R */
996%token  <kwd>  SECURITY_SYM                  /* SQL-2003-N */
997%token  <kwd>  SEQUENCE_SYM
998%token  <kwd>  SERIALIZABLE_SYM              /* SQL-2003-N */
999%token  <kwd>  SERIAL_SYM
1000%token  <kwd>  SESSION_SYM                   /* SQL-2003-N */
1001%token  <kwd>  SERVER_SYM
1002%token  <kwd>  SETVAL_SYM                    /* PostgreSQL sequence function */
1003%token  <kwd>  SHARE_SYM
1004%token  <kwd>  SHUTDOWN
1005%token  <kwd>  SIGNED_SYM
1006%token  <kwd>  SIMPLE_SYM                    /* SQL-2003-N */
1007%token  <kwd>  SLAVE
1008%token  <kwd>  SLAVES
1009%token  <kwd>  SLAVE_POS_SYM
1010%token  <kwd>  SLOW
1011%token  <kwd>  SNAPSHOT_SYM
1012%token  <kwd>  SOCKET_SYM
1013%token  <kwd>  SOFT_SYM
1014%token  <kwd>  SONAME_SYM
1015%token  <kwd>  SOUNDS_SYM
1016%token  <kwd>  SOURCE_SYM
1017%token  <kwd>  SQL_BUFFER_RESULT
1018%token  <kwd>  SQL_CACHE_SYM
1019%token  <kwd>  SQL_CALC_FOUND_ROWS
1020%token  <kwd>  SQL_NO_CACHE_SYM
1021%token  <kwd>  SQL_THREAD
1022%token  <kwd>  STAGE_SYM
1023%token  <kwd>  STARTS_SYM
1024%token  <kwd>  START_SYM                     /* SQL-2003-R */
1025%token  <kwd>  STATEMENT_SYM
1026%token  <kwd>  STATUS_SYM
1027%token  <kwd>  STOP_SYM
1028%token  <kwd>  STORAGE_SYM
1029%token  <kwd>  STORED_SYM
1030%token  <kwd>  STRING_SYM
1031%token  <kwd>  SUBCLASS_ORIGIN_SYM           /* SQL-2003-N */
1032%token  <kwd>  SUBDATE_SYM
1033%token  <kwd>  SUBJECT_SYM
1034%token  <kwd>  SUBPARTITIONS_SYM
1035%token  <kwd>  SUBPARTITION_SYM
1036%token  <kwd>  SUPER_SYM
1037%token  <kwd>  SUSPEND_SYM
1038%token  <kwd>  SWAPS_SYM
1039%token  <kwd>  SWITCHES_SYM
1040%token  <kwd>  SYSTEM                        /* SQL-2011-R */
1041%token  <kwd>  SYSTEM_TIME_SYM               /* SQL-2011-R */
1042%token  <kwd>  TABLES
1043%token  <kwd>  TABLESPACE
1044%token  <kwd>  TABLE_CHECKSUM_SYM
1045%token  <kwd>  TABLE_NAME_SYM                /* SQL-2003-N */
1046%token  <kwd>  TEMPORARY                     /* SQL-2003-N */
1047%token  <kwd>  TEMPTABLE_SYM
1048%token  <kwd>  TEXT_SYM
1049%token  <kwd>  THAN_SYM
1050%token  <kwd>  TIES_SYM                      /* SQL-2011-N */
1051%token  <kwd>  TIMESTAMP                     /* SQL-2003-R */
1052%token  <kwd>  TIMESTAMP_ADD
1053%token  <kwd>  TIMESTAMP_DIFF
1054%token  <kwd>  TIME_SYM                      /* SQL-2003-R, Oracle-R */
1055%token  <kwd>  TRANSACTION_SYM
1056%token  <kwd>  TRANSACTIONAL_SYM
1057%token  <kwd>  TRIGGERS_SYM
1058%token  <kwd>  TRIM_ORACLE
1059%token  <kwd>  TRUNCATE_SYM
1060%token  <kwd>  TYPES_SYM
1061%token  <kwd>  TYPE_SYM                      /* SQL-2003-N */
1062%token  <kwd>  UDF_RETURNS_SYM
1063%token  <kwd>  UNBOUNDED_SYM                 /* SQL-2011-N */
1064%token  <kwd>  UNCOMMITTED_SYM               /* SQL-2003-N */
1065%token  <kwd>  UNDEFINED_SYM
1066%token  <kwd>  UNDOFILE_SYM
1067%token  <kwd>  UNDO_BUFFER_SIZE_SYM
1068%token  <kwd>  UNICODE_SYM
1069%token  <kwd>  UNINSTALL_SYM
1070%token  <kwd>  UNKNOWN_SYM                   /* SQL-2003-R */
1071%token  <kwd>  UNTIL_SYM
1072%token  <kwd>  UPGRADE_SYM
1073%token  <kwd>  USER_SYM                      /* SQL-2003-R */
1074%token  <kwd>  USE_FRM
1075%token  <kwd>  VALUE_SYM                     /* SQL-2003-R */
1076%token  <kwd>  VARCHAR2_MARIADB_SYM
1077%token  <kwd>  VARCHAR2_ORACLE_SYM           /* Oracle-R, PLSQL-R */
1078%token  <kwd>  VARIABLES
1079%token  <kwd>  VERSIONING_SYM                /* SQL-2011-R */
1080%token  <kwd>  VIA_SYM
1081%token  <kwd>  VIEW_SYM                      /* SQL-2003-N */
1082%token  <kwd>  VIRTUAL_SYM
1083%token  <kwd>  WAIT_SYM
1084%token  <kwd>  WARNINGS
1085%token  <kwd>  WEEK_SYM
1086%token  <kwd>  WEIGHT_STRING_SYM
1087%token  <kwd>  WINDOW_SYM                    /* SQL-2003-R */
1088%token  <kwd>  WITHIN
1089%token  <kwd>  WITHOUT                       /* SQL-2003-R */
1090%token  <kwd>  WORK_SYM                      /* SQL-2003-N */
1091%token  <kwd>  WRAPPER_SYM
1092%token  <kwd>  WRITE_SYM                     /* SQL-2003-N */
1093%token  <kwd>  X509_SYM
1094%token  <kwd>  XA_SYM
1095%token  <kwd>  XML_SYM
1096%token  <kwd>  YEAR_SYM                      /* SQL-2003-R */
1097
1098/* A dummy token to force the priority of table_ref production in a join. */
1099%left   CONDITIONLESS_JOIN
1100%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT ON_SYM USING
1101
1102%left   SET_VAR
1103%left   OR_SYM OR2_SYM
1104%left   XOR
1105%left   AND_SYM AND_AND_SYM
1106
1107%left   PREC_BELOW_NOT
1108
1109%nonassoc NOT_SYM
1110%left   '=' EQUAL_SYM GE '>' LE '<' NE
1111%nonassoc IS
1112%right BETWEEN_SYM
1113%left   LIKE SOUNDS_SYM REGEXP IN_SYM
1114%left   '|'
1115%left   '&'
1116%left   SHIFT_LEFT SHIFT_RIGHT
1117%left   '-' '+' ORACLE_CONCAT_SYM
1118%left   '*' '/' '%' DIV_SYM MOD_SYM
1119%left   '^'
1120%left   MYSQL_CONCAT_SYM
1121%nonassoc NEG '~' NOT2_SYM BINARY
1122%nonassoc COLLATE_SYM
1123%nonassoc SUBQUERY_AS_EXPR
1124
1125/*
1126  Tokens that can change their meaning from identifier to something else
1127  in certain context.
1128
1129  - TRANSACTION: identifier, history unit:
1130      SELECT transaction FROM t1;
1131      SELECT * FROM t1 FOR SYSTEM_TIME AS OF TRANSACTION @var;
1132
1133  - TIMESTAMP: identifier, literal, history unit:
1134      SELECT timestamp FROM t1;
1135      SELECT TIMESTAMP '2001-01-01 10:20:30';
1136      SELECT * FROM t1 FOR SYSTEM_TIME AS OF TIMESTAMP CONCAT(@date,' ',@time);
1137
1138  - PERIOD: identifier, period for system time:
1139      SELECT period FROM t1;
1140      ALTER TABLE DROP PERIOD FOR SYSTEM TIME;
1141
1142  - SYSTEM: identifier, system versioning:
1143      SELECT system FROM t1;
1144      ALTER TABLE DROP SYSTEM VERSIONIONG;
1145
1146  - USER: identifier, user:
1147      SELECT user FROM t1;
1148      KILL USER foo;
1149
1150   Note, we need here only tokens that cause shift/reduce conflicts
1151   with keyword identifiers. For example:
1152      opt_clause1: %empty | KEYWORD ... ;
1153      clause2: opt_clause1 ident;
1154   KEYWORD can appear both in opt_clause1 and in "ident" through the "keyword"
1155   rule. So the parser reports a conflict on how to interpret KEYWORD:
1156     - as a start of non-empty branch in opt_clause1, or
1157     - as an identifier which follows the empty branch in opt_clause1.
1158
1159   Example#1:
1160     alter_list_item:
1161       DROP opt_column opt_if_exists_table_element field_ident
1162     | DROP SYSTEM VERSIONING_SYM
1163   SYSTEM can be a keyword in field_ident, or can be a start of
1164   SYSTEM VERSIONING.
1165
1166   Example#2:
1167     system_time_expr: AS OF_SYM history_point
1168     history_point: opt_history_unit bit_expr
1169     opt_history_unit: | TRANSACTION_SYM
1170   TRANSACTION can be a non-empty history unit, or can be an identifier
1171   in bit_expr.
1172
1173   In the grammar below we use %prec to explicitely tell Bison to go
1174   through the empty branch in the optional rule only when the lookahead
1175   token does not belong to a small set of selected tokens.
1176
1177   Tokens NEXT_SYM and PREVIOUS_SYM also change their meaning from
1178   identifiers to sequence operations when followed by VALUE_SYM:
1179      SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1180   but we don't need to list them here as they do not seem to cause
1181   conflicts (according to bison -v), as both meanings
1182   (as identifier, and as a sequence operation) are parts of the same target
1183   column_default_non_parenthesized_expr, and there are no any optional
1184   clauses between the start of column_default_non_parenthesized_expr
1185   and until NEXT_SYM / PREVIOUS_SYM.
1186*/
1187%left   PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
1188%left   TRANSACTION_SYM TIMESTAMP PERIOD_SYM SYSTEM USER
1189
1190
1191/*
1192  Tokens that can appear in a token contraction on the second place
1193  and change the meaning of the previous token.
1194
1195  - TEXT_STRING: changes the meaning of TIMESTAMP/TIME/DATE
1196    from identifier to literal:
1197      SELECT timestamp FROM t1;
1198      SELECT TIMESTAMP'2001-01-01 00:00:00' FROM t1;
1199
1200  - Parenthesis: changes the meaning of TIMESTAMP/TIME/DATE
1201    from identifiers to CAST-alike functions:
1202      SELECT timestamp FROM t1;
1203      SELECT timestamp(1) FROM t1;
1204
1205  - VALUE: changes NEXT and PREVIOUS from identifier to sequence operation:
1206      SELECT next, previous FROM t1;
1207      SELECT NEXT VALUE FOR s1, PREVIOUS VALUE FOR s1;
1208
1209  - VERSIONING: changes SYSTEM from identifier to SYSTEM VERSIONING
1210      SELECT system FROM t1;
1211      ALTER TABLE t1 ADD SYSTEM VERSIONING;
1212*/
1213%left   PREC_BELOW_CONTRACTION_TOKEN2
1214%left   TEXT_STRING '(' ')' VALUE_SYM VERSIONING_SYM
1215%left EMPTY_FROM_CLAUSE
1216%right INTO
1217
1218%type <lex_str>
1219        DECIMAL_NUM FLOAT_NUM NUM LONG_NUM
1220        HEX_NUM HEX_STRING
1221        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident_or_text
1222        TEXT_STRING_sys TEXT_STRING_literal
1223        key_cache_name
1224        sp_opt_label BIN_NUM TEXT_STRING_filesystem
1225        opt_constraint constraint opt_ident
1226        opt_package_routine_end_name
1227        sp_block_label opt_place opt_db
1228
1229%type <lex_str>
1230        label_declaration_oracle
1231        labels_declaration_oracle
1232
1233%type <ident_sys>
1234        IDENT_sys
1235        ident
1236        label_ident
1237        sp_decl_ident
1238        ident_set_usual_case
1239        ident_or_empty
1240        ident_table_alias
1241        ident_sysvar_name
1242        ident_directly_assignable
1243
1244%type <lex_string_with_metadata>
1245        TEXT_STRING
1246        NCHAR_STRING
1247
1248%type <lex_str_ptr>
1249        opt_table_alias_clause
1250        table_alias_clause
1251
1252%type <ident_cli>
1253        IDENT
1254        IDENT_QUOTED
1255        IDENT_cli
1256        ident_cli
1257
1258%type <kwd>
1259        keyword_data_type
1260        keyword_ident
1261        keyword_label
1262        keyword_set_special_case
1263        keyword_set_usual_case
1264        keyword_sp_block_section
1265        keyword_sp_decl
1266        keyword_sp_head
1267        keyword_sp_var_and_label
1268        keyword_sp_var_not_label
1269        keyword_sysvar_name
1270        keyword_sysvar_type
1271        keyword_table_alias
1272        keyword_verb_clause
1273        keyword_directly_assignable
1274
1275%type <table>
1276        table_ident table_ident_nodb references xid
1277        table_ident_opt_wild create_like
1278
1279%type <qualified_column_ident>
1280        optionally_qualified_column_ident
1281
1282%type <simple_string>
1283        remember_name remember_end remember_end_opt
1284        remember_tok_start
1285        wild_and_where
1286
1287%type <const_simple_string>
1288        field_length opt_field_length opt_field_length_default_1
1289        opt_compression_method
1290
1291%type <string>
1292        text_string hex_or_bin_String opt_gconcat_separator
1293
1294%type <type_handler> int_type real_type
1295
1296%type <Lex_field_type> field_type field_type_all
1297        qualified_field_type
1298        sp_param_type
1299        sp_param_field_type
1300        sp_param_field_type_string
1301        field_type_numeric
1302        field_type_string
1303        field_type_lob
1304        field_type_temporal
1305        field_type_misc
1306
1307%type <Lex_dyncol_type> opt_dyncol_type dyncol_type
1308        numeric_dyncol_type temporal_dyncol_type string_dyncol_type
1309
1310%type <create_field> field_spec column_def
1311
1312%type <geom_type> spatial_type
1313
1314%type <num>
1315        order_dir lock_option
1316        udf_type opt_local opt_no_write_to_binlog
1317        opt_temporary all_or_any opt_distinct opt_glimit_clause
1318        opt_ignore_leaves fulltext_options union_option
1319        opt_not
1320        transaction_access_mode_types
1321        opt_natural_language_mode opt_query_expansion
1322        opt_ev_status opt_ev_on_completion ev_on_completion opt_ev_comment
1323        ev_alter_on_schedule_completion opt_ev_rename_to opt_ev_sql_stmt
1324        optional_flush_tables_arguments
1325        opt_time_precision kill_type kill_option int_num
1326        opt_default_time_precision
1327        case_stmt_body opt_bin_mod opt_for_system_time_clause
1328        opt_if_exists_table_element opt_if_not_exists_table_element
1329        opt_recursive opt_format_xid opt_for_portion_of_time_clause
1330
1331%type <object_ddl_options>
1332        create_or_replace
1333        opt_if_not_exists
1334        opt_if_exists
1335
1336/*
1337  Bit field of MYSQL_START_TRANS_OPT_* flags.
1338*/
1339%type <num> opt_start_transaction_option_list
1340%type <num> start_transaction_option_list
1341%type <num> start_transaction_option
1342
1343%type <m_yes_no_unk>
1344        opt_chain opt_release
1345
1346%type <m_fk_option>
1347        delete_option
1348
1349%type <ulong_num>
1350        ulong_num real_ulong_num merge_insert_types
1351        ws_nweights opt_versioning_interval_start
1352        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
1353        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
1354        ws_level_range ws_level_list_or_range bool
1355
1356%type <ulonglong_number>
1357        ulonglong_num real_ulonglong_num size_number
1358
1359%type <longlong_number>
1360        longlong_num
1361
1362%type <choice> choice
1363
1364%type <lock_type>
1365        replace_lock_option opt_low_priority insert_lock_option load_data_lock
1366
1367%type <item>
1368        literal insert_ident order_ident temporal_literal
1369        simple_ident expr sum_expr in_sum_expr
1370        variable variable_aux
1371        predicate bit_expr parenthesized_expr
1372        table_wild simple_expr column_default_non_parenthesized_expr udf_expr
1373        primary_expr string_factor_expr mysql_concatenation_expr
1374        select_sublist_qualified_asterisk
1375        expr_or_ignore expr_or_ignore_or_default set_expr_or_default
1376        geometry_function signed_literal expr_or_literal
1377        sp_opt_default
1378        simple_ident_nospvar
1379        field_or_var limit_option
1380        part_func_expr
1381        window_func_expr
1382        window_func
1383        simple_window_func
1384        inverse_distribution_function
1385        percentile_function
1386        inverse_distribution_function_def
1387        explicit_cursor_attr
1388        function_call_keyword
1389        function_call_keyword_timestamp
1390        function_call_nonkeyword
1391        function_call_generic
1392        function_call_conflict kill_expr
1393        signal_allowed_expr
1394        simple_target_specification
1395        condition_number
1396        reset_lex_expr
1397
1398%type <item_param> param_marker
1399
1400%type <item_num>
1401        NUM_literal
1402
1403%type <item_basic_constant> text_literal
1404
1405%type <item_list>
1406        expr_list opt_udf_expr_list udf_expr_list when_list when_list_opt_else
1407        ident_list ident_list_arg opt_expr_list
1408        decode_when_list_oracle
1409        execute_using
1410        execute_params
1411
1412%type <sp_cursor_stmt>
1413        sp_cursor_stmt_lex
1414        sp_cursor_stmt
1415
1416%type <assignment_lex>
1417        assignment_source_lex
1418        assignment_source_expr
1419        for_loop_bound_expr
1420
1421%type <sp_assignment_lex_list>
1422        cursor_actual_parameters
1423        opt_parenthesized_cursor_actual_parameters
1424
1425%type <var_type>
1426        option_type opt_var_type opt_var_ident_type
1427
1428%type <key_type>
1429        opt_unique constraint_key_type fulltext spatial
1430
1431%type <key_alg>
1432        btree_or_rtree opt_key_algorithm_clause opt_USING_key_algorithm
1433
1434%type <string_list>
1435        using_list opt_use_partition use_partition
1436
1437%type <key_part>
1438        key_part
1439
1440%type <table_list>
1441        join_table_list  join_table
1442        table_factor table_ref esc_table_ref
1443        table_primary_ident table_primary_ident_opt_parens
1444        table_primary_derived table_primary_derived_opt_parens
1445        derived_table_list table_reference_list_parens
1446        nested_table_reference_list join_table_parens
1447        update_table_list
1448%type <date_time_type> date_time_type;
1449%type <interval> interval
1450
1451%type <interval_time_st> interval_time_stamp
1452
1453%type <db_type> storage_engines known_storage_engines
1454
1455%type <row_type> row_types
1456
1457%type <tx_isolation> isolation_types
1458
1459%type <ha_rkey_mode> handler_rkey_mode
1460
1461%type <Lex_cast_type> cast_type cast_type_numeric cast_type_temporal
1462
1463%type <Lex_length_and_dec> precision opt_precision float_options
1464        opt_field_length_default_sp_param_varchar
1465        opt_field_length_default_sp_param_char
1466
1467%type <lex_user> user grant_user grant_role user_or_role current_role
1468                 admin_option_for_role user_maybe_role
1469
1470%type <user_auth> opt_auth_str auth_expression auth_token
1471
1472%type <charset>
1473        opt_collate
1474        charset_name
1475        charset_or_alias
1476        charset_name_or_default
1477        old_or_new_charset_name
1478        old_or_new_charset_name_or_default
1479        collation_name
1480        collation_name_or_default
1481        opt_load_data_charset
1482        UNDERSCORE_CHARSET
1483
1484%type <select_lex> subselect
1485        query_specification
1486        table_value_constructor
1487        simple_table
1488        query_simple
1489        query_primary
1490        subquery
1491        select_into_query_specification
1492
1493%type <select_lex_unit>
1494        query_expression
1495        query_expression_no_with_clause
1496        query_expression_body_ext
1497        query_expression_body_ext_parens
1498        query_expression_body
1499        query_specification_start
1500
1501%type <boolfunc2creator> comp_op
1502
1503%type <dyncol_def> dyncall_create_element
1504
1505%type <dyncol_def_list> dyncall_create_list
1506
1507%type <myvar> select_outvar
1508
1509%type <virtual_column> opt_check_constraint check_constraint virtual_column_func
1510        column_default_expr
1511
1512%type <unit_operation> unit_type_decl
1513
1514%type <select_lock>
1515        opt_procedure_or_into
1516        opt_select_lock_type
1517        select_lock_type
1518        opt_lock_wait_timeout_new
1519
1520%type <select_limit> opt_limit_clause limit_clause limit_options
1521
1522%type <order_limit_lock>
1523        query_expression_tail
1524        opt_query_expression_tail
1525        order_or_limit
1526        order_limit_lock
1527        opt_order_limit_lock
1528
1529%type <select_order> opt_order_clause order_clause order_list
1530
1531%type <NONE>
1532        analyze_stmt_command backup backup_statements
1533        query verb_clause create change select select_into
1534        do drop insert replace insert2
1535        insert_values update delete truncate rename compound_statement
1536        show describe load alter optimize keycache preload flush
1537        reset purge begin_stmt_mariadb commit rollback savepoint release
1538        slave master_def master_defs master_file_def slave_until_opts
1539        repair analyze opt_with_admin opt_with_admin_option
1540        analyze_table_list analyze_table_elem_spec
1541        opt_persistent_stat_clause persistent_stat_spec
1542        persistent_column_stat_spec persistent_index_stat_spec
1543        table_column_list table_index_list table_index_name
1544        check start checksum
1545        field_list field_list_item kill key_def constraint_def
1546        keycache_list keycache_list_or_parts assign_to_keycache
1547        assign_to_keycache_parts
1548        preload_list preload_list_or_parts preload_keys preload_keys_parts
1549        select_item_list select_item values_list no_braces
1550        delete_limit_clause fields opt_values values
1551        no_braces_with_names opt_values_with_names values_with_names
1552        procedure_list procedure_list2 procedure_item
1553        field_def handler opt_generated_always
1554        opt_ignore opt_column opt_restrict
1555        grant revoke set lock unlock string_list field_options
1556        opt_binary table_lock_list table_lock
1557        ref_list opt_match_clause opt_on_update_delete use
1558        opt_delete_options opt_delete_option varchar nchar nvarchar
1559        opt_outer table_list table_name table_alias_ref_list table_alias_ref
1560        attribute attribute_list
1561        compressed_deprecated_data_type_attribute
1562        compressed_deprecated_column_attribute
1563        column_list column_list_id
1564        opt_column_list grant_privileges grant_ident grant_list grant_option
1565        object_privilege object_privilege_list user_list user_and_role_list
1566        rename_list table_or_tables
1567        clear_privileges flush_options flush_option
1568        opt_flush_lock flush_lock flush_options_list
1569        equal optional_braces
1570        opt_mi_check_type opt_to mi_check_types
1571        table_to_table_list table_to_table opt_table_list opt_as
1572        handler_rkey_function handler_read_or_scan
1573        single_multi table_wild_list table_wild_one opt_wild
1574        opt_and charset
1575        select_var_list select_var_list_init help
1576        opt_extended_describe shutdown
1577        opt_format_json
1578        prepare execute deallocate
1579        statement
1580        sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic xa
1581        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1582        view_list_opt view_list view_select
1583        trigger_tail event_tail
1584        install uninstall partition_entry binlog_base64_event
1585        normal_key_options normal_key_opts all_key_opt
1586        spatial_key_options fulltext_key_options normal_key_opt
1587        fulltext_key_opt spatial_key_opt fulltext_key_opts spatial_key_opts
1588	keep_gcc_happy
1589        key_using_alg
1590        part_column_list
1591        period_for_system_time
1592        period_for_application_time
1593        server_def server_options_list server_option
1594        definer_opt no_definer definer get_diagnostics
1595        parse_vcol_expr vcol_opt_specifier vcol_opt_attribute
1596        vcol_opt_attribute_list vcol_attribute
1597        opt_serial_attribute opt_serial_attribute_list serial_attribute
1598        explainable_command
1599        opt_lock_wait_timeout
1600        opt_delete_gtid_domain
1601        asrow_attribute
1602        set_assign
1603        sp_tail_standalone
1604        opt_constraint_no_id
1605END_OF_INPUT
1606
1607%type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt
1608%type <NONE> sp_proc_stmt_statement sp_proc_stmt_return
1609%type <NONE> sp_proc_stmt_compound_ok
1610%type <NONE> sp_proc_stmt_if
1611%type <NONE> sp_labeled_control sp_unlabeled_control
1612%type <NONE> sp_labeled_block sp_unlabeled_block
1613%type <NONE> sp_labelable_stmt
1614%type <NONE> sp_proc_stmt_continue_oracle
1615%type <NONE> sp_proc_stmt_exit_oracle
1616%type <NONE> sp_proc_stmt_leave
1617%type <NONE> sp_proc_stmt_iterate
1618%type <NONE> sp_proc_stmt_goto_oracle
1619%type <NONE> sp_proc_stmt_open sp_proc_stmt_fetch sp_proc_stmt_close
1620%type <NONE> case_stmt_specification
1621%type <NONE> loop_body while_body repeat_body
1622
1623%type <num> view_algorithm view_check_option
1624%type <view_suid> view_suid opt_view_suid
1625
1626%type <plsql_cursor_attr> plsql_cursor_attr
1627%type <sp_suid> sp_suid
1628%type <sp_aggregate_type> opt_aggregate
1629
1630%type <num> sp_decl_idents sp_decl_idents_init_vars
1631%type <num> sp_handler_type sp_hcond_list
1632%type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value
1633%type <spblock> sp_decl_body_list opt_sp_decl_body_list
1634%type <spblock> sp_decl_vars
1635%type <spblock> sp_decl_non_handler sp_decl_non_handler_list
1636%type <spblock> sp_decl_handler sp_decl_handler_list opt_sp_decl_handler_list
1637%type <spblock> package_implementation_routine_definition
1638%type <spblock> package_implementation_item_declaration
1639%type <spblock> package_implementation_declare_section
1640%type <spblock> package_implementation_declare_section_list1
1641%type <spblock> package_implementation_declare_section_list2
1642%type <spblock_handlers> sp_block_statements_and_exceptions
1643%type <spblock_handlers> package_implementation_executable_section
1644%type <sp_instr_addr> sp_instr_addr
1645%type <num> opt_exception_clause exception_handlers
1646%type <lex> remember_lex package_routine_lex
1647            package_specification_function
1648            package_specification_procedure
1649%type <spname> sp_name opt_sp_name
1650%type <spvar> sp_param_name sp_param_name_and_type
1651%type <for_loop> sp_for_loop_index_and_bounds
1652%type <for_loop_bounds> sp_for_loop_bounds
1653%type <trim> trim_operands
1654%type <num> opt_sp_for_loop_direction
1655%type <spvar_mode> sp_opt_inout
1656%type <index_hint> index_hint_type
1657%type <num> index_hint_clause normal_join inner_join
1658%type <filetype> data_or_xml
1659
1660%type <NONE> signal_stmt resignal_stmt raise_stmt_oracle
1661%type <diag_condition_item_name> signal_condition_information_item_name
1662
1663%type <trg_execution_order> trigger_follows_precedes_clause;
1664%type <trigger_action_order_type> trigger_action_order;
1665
1666%type <diag_area> which_area;
1667%type <diag_info> diagnostics_information;
1668%type <stmt_info_item> statement_information_item;
1669%type <stmt_info_item_name> statement_information_item_name;
1670%type <stmt_info_list> statement_information;
1671%type <cond_info_item> condition_information_item;
1672%type <cond_info_item_name> condition_information_item_name;
1673%type <cond_info_list> condition_information;
1674
1675%type <spvar_definition> row_field_name row_field_definition
1676%type <spvar_definition_list> row_field_definition_list row_type_body
1677
1678%type <NONE> opt_window_clause window_def_list window_def window_spec
1679%type <lex_str_ptr> window_name
1680%type <NONE> opt_window_ref opt_window_frame_clause
1681%type <frame_units> window_frame_units;
1682%type <NONE> window_frame_extent;
1683%type <frame_exclusion> opt_window_frame_exclusion;
1684%type <window_frame_bound> window_frame_start window_frame_bound;
1685
1686%type <kwd>
1687        '-' '+' '*' '/' '%' '(' ')'
1688        ',' '!' '{' '}' '&' '|'
1689
1690%type <NONE>
1691        AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
1692        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM OR2_SYM AND_AND_SYM DELETE_SYM
1693        MYSQL_CONCAT_SYM ORACLE_CONCAT_SYM
1694
1695%type <with_clause> with_clause
1696
1697%type <with_element_head> with_element_head
1698
1699%type <lex_str_list> opt_with_column_list
1700
1701%type <vers_range_unit> opt_history_unit
1702%type <vers_history_point> history_point
1703%type <vers_column_versioning> with_or_without_system
1704%%
1705
1706
1707/*
1708  Indentation of grammar rules:
1709
1710rule: <-- starts at col 1
1711          rule1a rule1b rule1c <-- starts at col 11
1712          { <-- starts at col 11
1713            code <-- starts at col 13, indentation is 2 spaces
1714          }
1715        | rule2a rule2b
1716          {
1717            code
1718          }
1719        ; <-- on a line by itself, starts at col 9
1720
1721  Also, please do not use any <TAB>, but spaces.
1722  Having a uniform indentation in this file helps
1723  code reviews, patches, merges, and make maintenance easier.
1724  Tip: grep [[:cntrl:]] sql_yacc.yy
1725  Thanks.
1726*/
1727
1728query:
1729          END_OF_INPUT
1730          {
1731            if (!thd->bootstrap &&
1732              (!(thd->lex->lex_options & OPTION_LEX_FOUND_COMMENT)))
1733              my_yyabort_error((ER_EMPTY_QUERY, MYF(0)));
1734
1735            thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
1736            YYLIP->found_semicolon= NULL;
1737          }
1738        | verb_clause
1739          {
1740            Lex_input_stream *lip = YYLIP;
1741
1742            if ((thd->client_capabilities & CLIENT_MULTI_QUERIES) &&
1743                lip->multi_statements &&
1744                ! lip->eof())
1745            {
1746              /*
1747                We found a well formed query, and multi queries are allowed:
1748                - force the parser to stop after the ';'
1749                - mark the start of the next query for the next invocation
1750                  of the parser.
1751              */
1752              lip->next_state= MY_LEX_END;
1753              lip->found_semicolon= lip->get_ptr();
1754            }
1755            else
1756            {
1757              /* Single query, terminated. */
1758              lip->found_semicolon= NULL;
1759            }
1760          }
1761          ';'
1762          opt_end_of_input
1763        | verb_clause END_OF_INPUT
1764          {
1765            /* Single query, not terminated. */
1766            YYLIP->found_semicolon= NULL;
1767          }
1768        ;
1769
1770opt_end_of_input:
1771          /* empty */
1772        | END_OF_INPUT
1773        ;
1774
1775verb_clause:
1776          statement
1777        | begin_stmt_mariadb
1778        | compound_statement
1779        ;
1780
1781/* Verb clauses, except begin and compound_statement */
1782statement:
1783          alter
1784        | analyze
1785        | analyze_stmt_command
1786        | backup
1787        | binlog_base64_event
1788        | call
1789        | change
1790        | check
1791        | checksum
1792        | commit
1793        | create
1794        | deallocate
1795        | delete
1796        | describe
1797        | do
1798        | drop
1799        | execute
1800        | flush
1801        | get_diagnostics
1802        | grant
1803        | handler
1804        | help
1805        | insert
1806        | install
1807	| keep_gcc_happy
1808        | keycache
1809        | kill
1810        | load
1811        | lock
1812        | optimize
1813        | parse_vcol_expr
1814        | partition_entry
1815        | preload
1816        | prepare
1817        | purge
1818        | raise_stmt_oracle
1819        | release
1820        | rename
1821        | repair
1822        | replace
1823        | reset
1824        | resignal_stmt
1825        | revoke
1826        | rollback
1827        | savepoint
1828        | select
1829        | select_into
1830        | set
1831        | set_assign
1832        | signal_stmt
1833        | show
1834        | shutdown
1835        | slave
1836        | start
1837        | truncate
1838        | uninstall
1839        | unlock
1840        | update
1841        | use
1842        | xa
1843        ;
1844
1845deallocate:
1846          deallocate_or_drop PREPARE_SYM ident
1847          {
1848            Lex->stmt_deallocate_prepare($3);
1849          }
1850        ;
1851
1852deallocate_or_drop:
1853          DEALLOCATE_SYM
1854        | DROP
1855        ;
1856
1857prepare:
1858          PREPARE_SYM ident FROM
1859          { Lex->clause_that_disallows_subselect= "PREPARE..FROM"; }
1860          expr
1861          {
1862            Lex->clause_that_disallows_subselect= NULL;
1863            if (Lex->stmt_prepare($2, $5))
1864              MYSQL_YYABORT;
1865          }
1866        ;
1867
1868execute:
1869          EXECUTE_SYM ident execute_using
1870          {
1871            if (Lex->stmt_execute($2, $3))
1872              MYSQL_YYABORT;
1873          }
1874        | EXECUTE_SYM IMMEDIATE_SYM
1875          { Lex->clause_that_disallows_subselect= "EXECUTE IMMEDIATE"; }
1876          expr
1877          { Lex->clause_that_disallows_subselect= NULL; }
1878          execute_using
1879          {
1880            if (Lex->stmt_execute_immediate($4, $6))
1881              MYSQL_YYABORT;
1882          }
1883        ;
1884
1885execute_using:
1886          /* nothing */    { $$= NULL; }
1887        | USING
1888          { Lex->clause_that_disallows_subselect= "EXECUTE..USING"; }
1889          execute_params
1890          {
1891            $$= $3;
1892            Lex->clause_that_disallows_subselect= NULL;
1893          }
1894        ;
1895
1896execute_params:
1897          expr_or_ignore_or_default
1898          {
1899            if (unlikely(!($$= List<Item>::make(thd->mem_root, $1))))
1900              MYSQL_YYABORT;
1901          }
1902        | execute_params ',' expr_or_ignore_or_default
1903          {
1904            if (($$= $1)->push_back($3, thd->mem_root))
1905              MYSQL_YYABORT;
1906          }
1907        ;
1908
1909
1910/* help */
1911
1912help:
1913          HELP_SYM
1914          {
1915            if (unlikely(Lex->sphead))
1916              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HELP"));
1917          }
1918          ident_or_text
1919          {
1920            LEX *lex= Lex;
1921            lex->sql_command= SQLCOM_HELP;
1922            lex->help_arg= $3.str;
1923          }
1924        ;
1925
1926/* change master */
1927
1928change:
1929          CHANGE MASTER_SYM optional_connection_name TO_SYM
1930          {
1931            Lex->sql_command = SQLCOM_CHANGE_MASTER;
1932          }
1933          master_defs
1934          {}
1935        ;
1936
1937master_defs:
1938          master_def
1939        | master_defs ',' master_def
1940        ;
1941
1942master_def:
1943          MASTER_HOST_SYM '=' TEXT_STRING_sys
1944          {
1945            Lex->mi.host = $3.str;
1946          }
1947        | MASTER_USER_SYM '=' TEXT_STRING_sys
1948          {
1949            Lex->mi.user = $3.str;
1950          }
1951        | MASTER_PASSWORD_SYM '=' TEXT_STRING_sys
1952          {
1953            Lex->mi.password = $3.str;
1954          }
1955        | MASTER_PORT_SYM '=' ulong_num
1956          {
1957            Lex->mi.port = $3;
1958          }
1959        | MASTER_CONNECT_RETRY_SYM '=' ulong_num
1960          {
1961            Lex->mi.connect_retry = $3;
1962          }
1963        | MASTER_DELAY_SYM '=' ulong_num
1964          {
1965            if ($3 > MASTER_DELAY_MAX)
1966            {
1967              my_error(ER_MASTER_DELAY_VALUE_OUT_OF_RANGE, MYF(0),
1968                       (ulong) $3, (ulong) MASTER_DELAY_MAX);
1969            }
1970            else
1971              Lex->mi.sql_delay = $3;
1972          }
1973        | MASTER_SSL_SYM '=' ulong_num
1974          {
1975            Lex->mi.ssl= $3 ?
1976              LEX_MASTER_INFO::LEX_MI_ENABLE : LEX_MASTER_INFO::LEX_MI_DISABLE;
1977          }
1978        | MASTER_SSL_CA_SYM '=' TEXT_STRING_sys
1979          {
1980            Lex->mi.ssl_ca= $3.str;
1981          }
1982        | MASTER_SSL_CAPATH_SYM '=' TEXT_STRING_sys
1983          {
1984            Lex->mi.ssl_capath= $3.str;
1985          }
1986        | MASTER_SSL_CERT_SYM '=' TEXT_STRING_sys
1987          {
1988            Lex->mi.ssl_cert= $3.str;
1989          }
1990        | MASTER_SSL_CIPHER_SYM '=' TEXT_STRING_sys
1991          {
1992            Lex->mi.ssl_cipher= $3.str;
1993          }
1994        | MASTER_SSL_KEY_SYM '=' TEXT_STRING_sys
1995          {
1996            Lex->mi.ssl_key= $3.str;
1997          }
1998        | MASTER_SSL_VERIFY_SERVER_CERT_SYM '=' ulong_num
1999          {
2000            Lex->mi.ssl_verify_server_cert= $3 ?
2001              LEX_MASTER_INFO::LEX_MI_ENABLE : LEX_MASTER_INFO::LEX_MI_DISABLE;
2002          }
2003        | MASTER_SSL_CRL_SYM '=' TEXT_STRING_sys
2004          {
2005            Lex->mi.ssl_crl= $3.str;
2006          }
2007        | MASTER_SSL_CRLPATH_SYM '=' TEXT_STRING_sys
2008          {
2009            Lex->mi.ssl_crlpath= $3.str;
2010          }
2011
2012        | MASTER_HEARTBEAT_PERIOD_SYM '=' NUM_literal
2013          {
2014            Lex->mi.heartbeat_period= (float) $3->val_real();
2015            if (unlikely(Lex->mi.heartbeat_period >
2016                         SLAVE_MAX_HEARTBEAT_PERIOD) ||
2017                unlikely(Lex->mi.heartbeat_period < 0.0))
2018               my_yyabort_error((ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, MYF(0),
2019                                 SLAVE_MAX_HEARTBEAT_PERIOD));
2020
2021            if (unlikely(Lex->mi.heartbeat_period > slave_net_timeout))
2022            {
2023              push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
2024                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX,
2025                                  ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX));
2026            }
2027            if (unlikely(Lex->mi.heartbeat_period < 0.001))
2028            {
2029              if (unlikely(Lex->mi.heartbeat_period != 0.0))
2030              {
2031                push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
2032                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN,
2033                                    ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN));
2034                Lex->mi.heartbeat_period= 0.0;
2035              }
2036              Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_DISABLE;
2037            }
2038            Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_ENABLE;
2039          }
2040        | IGNORE_SERVER_IDS_SYM '=' '(' ignore_server_id_list ')'
2041          {
2042            Lex->mi.repl_ignore_server_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
2043           }
2044        | DO_DOMAIN_IDS_SYM '=' '(' do_domain_id_list ')'
2045          {
2046            Lex->mi.repl_do_domain_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
2047          }
2048        | IGNORE_DOMAIN_IDS_SYM '=' '(' ignore_domain_id_list ')'
2049          {
2050            Lex->mi.repl_ignore_domain_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
2051          }
2052        |
2053        master_file_def
2054        ;
2055
2056ignore_server_id_list:
2057          /* Empty */
2058          | ignore_server_id
2059          | ignore_server_id_list ',' ignore_server_id
2060        ;
2061
2062ignore_server_id:
2063          ulong_num
2064          {
2065            insert_dynamic(&Lex->mi.repl_ignore_server_ids, (uchar*) &($1));
2066          }
2067          ;
2068
2069do_domain_id_list:
2070          /* Empty */
2071          | do_domain_id
2072          | do_domain_id_list ',' do_domain_id
2073        ;
2074
2075do_domain_id:
2076          ulong_num
2077          {
2078            insert_dynamic(&Lex->mi.repl_do_domain_ids, (uchar*) &($1));
2079          }
2080          ;
2081
2082ignore_domain_id_list:
2083          /* Empty */
2084          | ignore_domain_id
2085          | ignore_domain_id_list ',' ignore_domain_id
2086        ;
2087
2088ignore_domain_id:
2089          ulong_num
2090          {
2091            insert_dynamic(&Lex->mi.repl_ignore_domain_ids, (uchar*) &($1));
2092          }
2093          ;
2094
2095master_file_def:
2096          MASTER_LOG_FILE_SYM '=' TEXT_STRING_sys
2097          {
2098            Lex->mi.log_file_name = $3.str;
2099          }
2100        | MASTER_LOG_POS_SYM '=' ulonglong_num
2101          {
2102            /*
2103               If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
2104               instead of causing subsequent errors.
2105               We need to do it in this file, because only there we know that
2106               MASTER_LOG_POS has been explicitly specified. On the contrary
2107               in change_master() (sql_repl.cc) we cannot distinguish between 0
2108               (MASTER_LOG_POS explicitly specified as 0) and 0 (unspecified),
2109               whereas we want to distinguish (specified 0 means "read the binlog
2110               from 0" (4 in fact), unspecified means "don't change the position
2111               (keep the preceding value)").
2112            */
2113            Lex->mi.pos= MY_MAX(BIN_LOG_HEADER_SIZE, $3);
2114          }
2115        | RELAY_LOG_FILE_SYM '=' TEXT_STRING_sys
2116          {
2117            Lex->mi.relay_log_name = $3.str;
2118          }
2119        | RELAY_LOG_POS_SYM '=' ulong_num
2120          {
2121            Lex->mi.relay_log_pos = $3;
2122            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
2123            Lex->mi.relay_log_pos= MY_MAX(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
2124          }
2125        | MASTER_USE_GTID_SYM '=' CURRENT_POS_SYM
2126          {
2127            if (unlikely(Lex->mi.use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_UNCHANGED))
2128              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
2129            Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_CURRENT_POS;
2130          }
2131        | MASTER_USE_GTID_SYM '=' SLAVE_POS_SYM
2132          {
2133            if (unlikely(Lex->mi.use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_UNCHANGED))
2134              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
2135            Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_SLAVE_POS;
2136          }
2137        | MASTER_USE_GTID_SYM '=' NO_SYM
2138          {
2139            if (unlikely(Lex->mi.use_gtid_opt != LEX_MASTER_INFO::LEX_GTID_UNCHANGED))
2140              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MASTER_use_gtid"));
2141            Lex->mi.use_gtid_opt= LEX_MASTER_INFO::LEX_GTID_NO;
2142          }
2143        ;
2144
2145optional_connection_name:
2146          /* empty */
2147          {
2148            LEX *lex= thd->lex;
2149            lex->mi.connection_name= null_clex_str;
2150          }
2151        | connection_name
2152        ;
2153
2154connection_name:
2155        TEXT_STRING_sys
2156        {
2157           Lex->mi.connection_name= $1;
2158#ifdef HAVE_REPLICATION
2159           if (unlikely(check_master_connection_name(&$1)))
2160              my_yyabort_error((ER_WRONG_ARGUMENTS, MYF(0), "MASTER_CONNECTION_NAME"));
2161#endif
2162         }
2163         ;
2164
2165/* create a table */
2166
2167create:
2168          create_or_replace opt_temporary TABLE_SYM opt_if_not_exists
2169          {
2170            LEX *lex= thd->lex;
2171            if (!(lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_create_table()))
2172              MYSQL_YYABORT;
2173            lex->create_info.init();
2174            if (lex->main_select_push())
2175              MYSQL_YYABORT;
2176            lex->current_select->parsing_place= BEFORE_OPT_LIST;
2177            if (lex->set_command_with_check(SQLCOM_CREATE_TABLE, $2, $1 | $4))
2178               MYSQL_YYABORT;
2179          }
2180          table_ident
2181          {
2182            LEX *lex= thd->lex;
2183            if (!lex->first_select_lex()->
2184                add_table_to_list(thd, $6, NULL, TL_OPTION_UPDATING,
2185                                  TL_WRITE, MDL_SHARED_UPGRADABLE))
2186              MYSQL_YYABORT;
2187            lex->alter_info.reset();
2188            /*
2189              For CREATE TABLE we should not open the table even if it exists.
2190              If the table exists, we should either not create it or replace it
2191            */
2192            lex->query_tables->open_strategy= TABLE_LIST::OPEN_STUB;
2193            lex->create_info.default_table_charset= NULL;
2194            lex->name= null_clex_str;
2195            lex->create_last_non_select_table= lex->last_table();
2196          }
2197          create_body
2198          {
2199            LEX *lex= thd->lex;
2200            create_table_set_open_action_and_adjust_tables(lex);
2201            Lex->pop_select(); //main select
2202          }
2203       | create_or_replace opt_temporary SEQUENCE_SYM opt_if_not_exists table_ident
2204         {
2205           LEX *lex= thd->lex;
2206           if (lex->main_select_push())
2207             MYSQL_YYABORT;
2208           if (!(lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_create_sequence()))
2209              MYSQL_YYABORT;
2210           lex->create_info.init();
2211           if (unlikely(lex->set_command_with_check(SQLCOM_CREATE_SEQUENCE, $2,
2212                        $1 | $4)))
2213              MYSQL_YYABORT;
2214
2215           if (!lex->first_select_lex()->
2216               add_table_to_list(thd, $5, NULL, TL_OPTION_UPDATING,
2217                                 TL_WRITE, MDL_EXCLUSIVE))
2218             MYSQL_YYABORT;
2219
2220               /*
2221                 For CREATE TABLE, an non-existing table is not an error.
2222                 Instruct open_tables() to just take an MDL lock if the
2223                 table does not exist.
2224               */
2225             lex->alter_info.reset();
2226             lex->query_tables->open_strategy= TABLE_LIST::OPEN_STUB;
2227             lex->name= null_clex_str;
2228             lex->create_last_non_select_table= lex->last_table();
2229             if (unlikely(!(lex->create_info.seq_create_info=
2230                            new (thd->mem_root) sequence_definition())))
2231               MYSQL_YYABORT;
2232         }
2233         opt_sequence opt_create_table_options
2234         {
2235            LEX *lex= thd->lex;
2236
2237            if (unlikely(lex->create_info.seq_create_info->check_and_adjust(1)))
2238            {
2239              my_error(ER_SEQUENCE_INVALID_DATA, MYF(0),
2240                       lex->first_select_lex()->table_list.first->db.str,
2241                       lex->first_select_lex()->table_list.first->
2242                         table_name.str);
2243              MYSQL_YYABORT;
2244            }
2245
2246            /* No fields specified, generate them */
2247            if (unlikely(prepare_sequence_fields(thd,
2248                         &lex->alter_info.create_list)))
2249               MYSQL_YYABORT;
2250
2251            /* CREATE SEQUENCE always creates a sequence */
2252	    Lex->create_info.used_fields|= HA_CREATE_USED_SEQUENCE;
2253            Lex->create_info.sequence= 1;
2254
2255            create_table_set_open_action_and_adjust_tables(lex);
2256            Lex->pop_select(); //main select
2257          }
2258        | create_or_replace opt_unique INDEX_SYM opt_if_not_exists
2259          {
2260            if (Lex->main_select_push())
2261              MYSQL_YYABORT;
2262          }
2263          ident
2264          opt_key_algorithm_clause
2265          ON table_ident
2266          {
2267            if (Lex->add_create_index_prepare($9))
2268              MYSQL_YYABORT;
2269            if (Lex->add_create_index($2, &$6, $7, $1 | $4))
2270              MYSQL_YYABORT;
2271          }
2272          '(' key_list ')' opt_lock_wait_timeout normal_key_options
2273          opt_index_lock_algorithm
2274          {
2275            Lex->pop_select(); //main select
2276          }
2277        | create_or_replace fulltext INDEX_SYM
2278          {
2279            if (Lex->main_select_push())
2280              MYSQL_YYABORT;
2281          }
2282          opt_if_not_exists ident
2283          ON table_ident
2284          {
2285            if (Lex->add_create_index_prepare($8))
2286              MYSQL_YYABORT;
2287            if (Lex->add_create_index($2, &$6, HA_KEY_ALG_UNDEF, $1 | $5))
2288              MYSQL_YYABORT;
2289          }
2290          '(' key_list ')' opt_lock_wait_timeout fulltext_key_options
2291          opt_index_lock_algorithm
2292          {
2293            Lex->pop_select(); //main select
2294          }
2295        | create_or_replace spatial INDEX_SYM
2296          {
2297            if (Lex->main_select_push())
2298              MYSQL_YYABORT;
2299          }
2300          opt_if_not_exists ident
2301          ON table_ident
2302          {
2303            if (Lex->add_create_index_prepare($8))
2304              MYSQL_YYABORT;
2305            if (Lex->add_create_index($2, &$6, HA_KEY_ALG_UNDEF, $1 | $5))
2306              MYSQL_YYABORT;
2307          }
2308          '(' key_list ')' opt_lock_wait_timeout spatial_key_options
2309          opt_index_lock_algorithm
2310          {
2311            Lex->pop_select(); //main select
2312          }
2313        | create_or_replace DATABASE opt_if_not_exists ident
2314          {
2315            Lex->create_info.default_table_charset= NULL;
2316            Lex->create_info.used_fields= 0;
2317          }
2318          opt_create_database_options
2319          {
2320            LEX *lex=Lex;
2321            if (unlikely(lex->set_command_with_check(SQLCOM_CREATE_DB, 0,
2322                         $1 | $3)))
2323               MYSQL_YYABORT;
2324            lex->name= $4;
2325          }
2326        | create_or_replace definer_opt opt_view_suid VIEW_SYM
2327          opt_if_not_exists table_ident
2328          {
2329            if (Lex->main_select_push())
2330              MYSQL_YYABORT;
2331            if (Lex->add_create_view(thd, $1 | $5,
2332                                     DTYPE_ALGORITHM_UNDEFINED, $3, $6))
2333              MYSQL_YYABORT;
2334          }
2335          view_list_opt AS view_select
2336          {
2337            Lex->pop_select(); //main select
2338          }
2339        | create_or_replace view_algorithm definer_opt opt_view_suid VIEW_SYM
2340          opt_if_not_exists table_ident
2341          {
2342            if (Lex->main_select_push())
2343              MYSQL_YYABORT;
2344            if (Lex->add_create_view(thd, $1 | $6, $2, $4, $7))
2345              MYSQL_YYABORT;
2346          }
2347          view_list_opt AS view_select
2348          {
2349            Lex->pop_select(); //main select
2350          }
2351        | create_or_replace definer_opt TRIGGER_SYM
2352          {
2353            if (Lex->main_select_push())
2354              MYSQL_YYABORT;
2355            Lex->create_info.set($1);
2356          }
2357          trigger_tail
2358          {
2359            Lex->pop_select(); //main select
2360          }
2361        | create_or_replace definer_opt PROCEDURE_SYM opt_if_not_exists
2362          {
2363            if (Lex->stmt_create_procedure_start($1 | $4))
2364              MYSQL_YYABORT;
2365          }
2366          sp_tail_standalone
2367          {
2368            Lex->stmt_create_routine_finalize();
2369          }
2370        | create_or_replace definer_opt EVENT_SYM
2371          {
2372            if (Lex->main_select_push())
2373              MYSQL_YYABORT;
2374            Lex->create_info.set($1);
2375          }
2376          event_tail
2377          {
2378            Lex->pop_select(); //main select
2379          }
2380        | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists
2381          sp_name RETURN_ORACLE_SYM
2382          {
2383            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
2384              MYSQL_YYABORT;
2385          }
2386          sf_return_type
2387          sf_c_chistics_and_body_standalone
2388          opt_sp_name
2389          {
2390            if (Lex->stmt_create_stored_function_finalize_standalone($11))
2391              MYSQL_YYABORT;
2392          }
2393        | create_or_replace definer opt_aggregate FUNCTION_SYM opt_if_not_exists
2394          sp_name '('
2395          {
2396            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
2397              MYSQL_YYABORT;
2398          }
2399          sp_fdparam_list ')'
2400          RETURN_ORACLE_SYM sf_return_type
2401          sf_c_chistics_and_body_standalone
2402          opt_sp_name
2403          {
2404            if (Lex->stmt_create_stored_function_finalize_standalone($14))
2405              MYSQL_YYABORT;
2406          }
2407        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
2408          sp_name RETURN_ORACLE_SYM
2409          {
2410            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
2411              MYSQL_YYABORT;
2412          }
2413          sf_return_type
2414          sf_c_chistics_and_body_standalone
2415          opt_sp_name
2416          {
2417            if (Lex->stmt_create_stored_function_finalize_standalone($11))
2418              MYSQL_YYABORT;
2419          }
2420        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
2421          sp_name '('
2422          {
2423            if (Lex->stmt_create_stored_function_start($1 | $5, $3, $6))
2424              MYSQL_YYABORT;
2425          }
2426          sp_fdparam_list ')'
2427          RETURN_ORACLE_SYM sf_return_type
2428          sf_c_chistics_and_body_standalone
2429          opt_sp_name
2430          {
2431            if (Lex->stmt_create_stored_function_finalize_standalone($14))
2432              MYSQL_YYABORT;
2433          }
2434        | create_or_replace no_definer opt_aggregate FUNCTION_SYM opt_if_not_exists
2435          ident RETURNS_SYM udf_type SONAME_SYM TEXT_STRING_sys
2436          {
2437            if (Lex->stmt_create_udf_function($1 | $5, $3, $6,
2438                                              (Item_result) $8, $10))
2439              MYSQL_YYABORT;
2440          }
2441        | create_or_replace USER_SYM opt_if_not_exists clear_privileges
2442          grant_list opt_require_clause opt_resource_options opt_account_locking_and_opt_password_expiration
2443          {
2444            if (unlikely(Lex->set_command_with_check(SQLCOM_CREATE_USER,
2445                                                     $1 | $3)))
2446              MYSQL_YYABORT;
2447          }
2448        | create_or_replace ROLE_SYM opt_if_not_exists
2449          clear_privileges role_list opt_with_admin
2450          {
2451            if (unlikely(Lex->set_command_with_check(SQLCOM_CREATE_ROLE,
2452                         $1 | $3)))
2453              MYSQL_YYABORT;
2454          }
2455        | CREATE LOGFILE_SYM GROUP_SYM logfile_group_info
2456          {
2457            Lex->alter_tablespace_info->ts_cmd_type= CREATE_LOGFILE_GROUP;
2458          }
2459        | CREATE TABLESPACE tablespace_info
2460          {
2461            Lex->alter_tablespace_info->ts_cmd_type= CREATE_TABLESPACE;
2462          }
2463        | create_or_replace { Lex->set_command(SQLCOM_CREATE_SERVER, $1); }
2464          server_def
2465          { }
2466        | create_or_replace definer_opt PACKAGE_ORACLE_SYM
2467          opt_if_not_exists sp_name opt_create_package_chistics_init
2468          sp_tail_is
2469          remember_name
2470          {
2471            sp_package *pkg;
2472            if (unlikely(!(pkg= Lex->
2473                           create_package_start(thd,
2474                                                SQLCOM_CREATE_PACKAGE,
2475                                                &sp_handler_package_spec,
2476                                                $5, $1 | $4))))
2477              MYSQL_YYABORT;
2478            pkg->set_c_chistics(Lex->sp_chistics);
2479          }
2480          opt_package_specification_element_list END
2481          remember_end_opt opt_sp_name
2482          {
2483            if (unlikely(Lex->create_package_finalize(thd, $5, $13, $8, $12)))
2484              MYSQL_YYABORT;
2485          }
2486        | create_or_replace definer_opt PACKAGE_ORACLE_SYM BODY_ORACLE_SYM
2487          opt_if_not_exists sp_name opt_create_package_chistics_init
2488          sp_tail_is
2489          remember_name
2490          {
2491            sp_package *pkg;
2492            if (unlikely(!(pkg= Lex->
2493                           create_package_start(thd,
2494                                                SQLCOM_CREATE_PACKAGE_BODY,
2495                                                &sp_handler_package_body,
2496                                                $6, $1 | $5))))
2497              MYSQL_YYABORT;
2498            pkg->set_c_chistics(Lex->sp_chistics);
2499            Lex->sp_block_init(thd);
2500          }
2501          package_implementation_declare_section
2502          {
2503            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
2504              MYSQL_YYABORT;
2505          }
2506          package_implementation_executable_section
2507          {
2508            $11.hndlrs+= $13.hndlrs;
2509            if (unlikely(Lex->sp_block_finalize(thd, $11)))
2510              MYSQL_YYABORT;
2511          }
2512          remember_end_opt opt_sp_name
2513          {
2514            if (unlikely(Lex->create_package_finalize(thd, $6, $16, $9, $15)))
2515              MYSQL_YYABORT;
2516          }
2517        ;
2518
2519package_implementation_executable_section:
2520          END
2521          {
2522            if (unlikely(Lex->sp_block_with_exceptions_add_empty(thd)))
2523              MYSQL_YYABORT;
2524            $$.init(0);
2525          }
2526        | BEGIN_ORACLE_SYM sp_block_statements_and_exceptions END { $$= $2; }
2527        ;
2528
2529/*
2530  Inside CREATE PACKAGE BODY, package-wide items (e.g. variables)
2531  must be declared before routine definitions.
2532*/
2533package_implementation_declare_section:
2534          package_implementation_declare_section_list1
2535        | package_implementation_declare_section_list2
2536        | package_implementation_declare_section_list1
2537          package_implementation_declare_section_list2
2538          { $$.join($1, $2); }
2539        ;
2540
2541package_implementation_declare_section_list1:
2542          package_implementation_item_declaration
2543        | package_implementation_declare_section_list1
2544          package_implementation_item_declaration
2545          { $$.join($1, $2); }
2546        ;
2547
2548package_implementation_declare_section_list2:
2549          package_implementation_routine_definition
2550        | package_implementation_declare_section_list2
2551          package_implementation_routine_definition
2552          { $$.join($1, $2); }
2553        ;
2554
2555package_routine_lex:
2556          {
2557            if (unlikely(!($$= new (thd->mem_root)
2558                           sp_lex_local(thd, thd->lex))))
2559              MYSQL_YYABORT;
2560            thd->m_parser_state->m_yacc.reset_before_substatement();
2561          }
2562        ;
2563
2564
2565package_specification_function:
2566          remember_lex package_routine_lex ident
2567          {
2568            DBUG_ASSERT($1->sphead->get_package());
2569            $2->sql_command= SQLCOM_CREATE_FUNCTION;
2570            sp_name *spname= $1->make_sp_name_package_routine(thd, &$3);
2571            if (unlikely(!spname))
2572              MYSQL_YYABORT;
2573            thd->lex= $2;
2574            if (unlikely(!$2->make_sp_head_no_recursive(thd, spname,
2575                                                        &sp_handler_package_function,
2576                                                        NOT_AGGREGATE)))
2577              MYSQL_YYABORT;
2578            $1->sphead->get_package()->m_current_routine= $2;
2579            (void) is_native_function_with_warn(thd, &$3);
2580          }
2581          opt_sp_parenthesized_fdparam_list
2582          RETURN_ORACLE_SYM sf_return_type
2583          sp_c_chistics
2584          {
2585            sp_head *sp= thd->lex->sphead;
2586            sp->restore_thd_mem_root(thd);
2587            thd->lex= $1;
2588            $$= $2;
2589          }
2590        ;
2591
2592package_specification_procedure:
2593          remember_lex package_routine_lex ident
2594          {
2595            DBUG_ASSERT($1->sphead->get_package());
2596            $2->sql_command= SQLCOM_CREATE_PROCEDURE;
2597            sp_name *spname= $1->make_sp_name_package_routine(thd, &$3);
2598            if (unlikely(!spname))
2599              MYSQL_YYABORT;
2600            thd->lex= $2;
2601            if (unlikely(!$2->make_sp_head_no_recursive(thd, spname,
2602                                                        &sp_handler_package_procedure,
2603                                                        DEFAULT_AGGREGATE)))
2604              MYSQL_YYABORT;
2605            $1->sphead->get_package()->m_current_routine= $2;
2606          }
2607          opt_sp_parenthesized_pdparam_list
2608          sp_c_chistics
2609          {
2610            sp_head *sp= thd->lex->sphead;
2611            sp->restore_thd_mem_root(thd);
2612            thd->lex= $1;
2613            $$= $2;
2614
2615          }
2616        ;
2617
2618
2619package_implementation_routine_definition:
2620          FUNCTION_SYM package_specification_function
2621                       package_implementation_function_body   ';'
2622          {
2623            sp_package *pkg= Lex->get_sp_package();
2624            if (unlikely(pkg->add_routine_implementation($2)))
2625              MYSQL_YYABORT;
2626            pkg->m_current_routine= NULL;
2627            $$.init();
2628          }
2629        | PROCEDURE_SYM package_specification_procedure
2630                        package_implementation_procedure_body ';'
2631          {
2632            sp_package *pkg= Lex->get_sp_package();
2633            if (unlikely(pkg->add_routine_implementation($2)))
2634              MYSQL_YYABORT;
2635            pkg->m_current_routine= NULL;
2636            $$.init();
2637          }
2638        | package_specification_element { $$.init(); }
2639        ;
2640
2641
2642package_implementation_function_body:
2643          sp_tail_is remember_lex
2644          {
2645            sp_package *pkg= Lex->get_sp_package();
2646            sp_head *sp= pkg->m_current_routine->sphead;
2647            thd->lex= pkg->m_current_routine;
2648            sp->reset_thd_mem_root(thd);
2649            sp->set_body_start(thd, YYLIP->get_cpp_tok_start());
2650          }
2651          sp_body opt_package_routine_end_name
2652          {
2653            if (unlikely(thd->lex->sp_body_finalize_function(thd) ||
2654                         thd->lex->sphead->check_package_routine_end_name($5)))
2655              MYSQL_YYABORT;
2656            thd->lex= $2;
2657          }
2658        ;
2659
2660package_implementation_procedure_body:
2661          sp_tail_is remember_lex
2662          {
2663            sp_package *pkg= Lex->get_sp_package();
2664            sp_head *sp= pkg->m_current_routine->sphead;
2665            thd->lex= pkg->m_current_routine;
2666            sp->reset_thd_mem_root(thd);
2667            sp->set_body_start(thd, YYLIP->get_cpp_tok_start());
2668          }
2669          sp_body opt_package_routine_end_name
2670          {
2671            if (unlikely(thd->lex->sp_body_finalize_procedure(thd) ||
2672                         thd->lex->sphead->check_package_routine_end_name($5)))
2673              MYSQL_YYABORT;
2674            thd->lex= $2;
2675          }
2676        ;
2677
2678
2679package_implementation_item_declaration:
2680          sp_decl_vars ';'
2681        ;
2682
2683opt_package_specification_element_list:
2684          /* Empty */
2685        | package_specification_element_list
2686        ;
2687
2688package_specification_element_list:
2689          package_specification_element
2690        | package_specification_element_list package_specification_element
2691        ;
2692
2693package_specification_element:
2694          FUNCTION_SYM package_specification_function ';'
2695          {
2696            sp_package *pkg= Lex->get_sp_package();
2697            if (unlikely(pkg->add_routine_declaration($2)))
2698              MYSQL_YYABORT;
2699            pkg->m_current_routine= NULL;
2700          }
2701        | PROCEDURE_SYM package_specification_procedure ';'
2702          {
2703            sp_package *pkg= Lex->get_sp_package();
2704            if (unlikely(pkg->add_routine_declaration($2)))
2705              MYSQL_YYABORT;
2706            pkg->m_current_routine= NULL;
2707          }
2708        ;
2709
2710
2711opt_sequence:
2712         /* empty */ { }
2713        | sequence_defs
2714        ;
2715
2716sequence_defs:
2717          sequence_def
2718        | sequence_defs sequence_def
2719        ;
2720
2721sequence_def:
2722        MINVALUE_SYM opt_equal longlong_num
2723          {
2724            Lex->create_info.seq_create_info->min_value= $3;
2725            Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
2726          }
2727        | NO_SYM MINVALUE_SYM
2728          {
2729            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_min_value))
2730              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
2731            Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
2732          }
2733        | NOMINVALUE_SYM
2734          {
2735            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_min_value))
2736              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
2737            Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
2738          }
2739        | MAXVALUE_SYM opt_equal longlong_num
2740          {
2741           if (unlikely(Lex->create_info.seq_create_info->used_fields &
2742               seq_field_used_max_value))
2743              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
2744            Lex->create_info.seq_create_info->max_value= $3;
2745            Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
2746          }
2747        | NO_SYM MAXVALUE_SYM
2748          {
2749            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_max_value))
2750              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
2751            Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
2752          }
2753        | NOMAXVALUE_SYM
2754          {
2755            if (unlikely(Lex->create_info.seq_create_info->used_fields & seq_field_used_max_value))
2756              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
2757            Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
2758          }
2759        | START_SYM opt_with longlong_num
2760          {
2761            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2762                         seq_field_used_start))
2763              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "START"));
2764            Lex->create_info.seq_create_info->start= $3;
2765            Lex->create_info.seq_create_info->used_fields|= seq_field_used_start;
2766          }
2767        | INCREMENT_SYM opt_by longlong_num
2768          {
2769             if (unlikely(Lex->create_info.seq_create_info->used_fields &
2770                seq_field_used_increment))
2771              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "INCREMENT"));
2772            Lex->create_info.seq_create_info->increment= $3;
2773            Lex->create_info.seq_create_info->used_fields|= seq_field_used_increment;
2774          }
2775        | CACHE_SYM opt_equal longlong_num
2776          {
2777            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2778                seq_field_used_cache))
2779              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CACHE"));
2780            Lex->create_info.seq_create_info->cache= $3;
2781            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cache;
2782          }
2783        | NOCACHE_SYM
2784          {
2785            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2786                seq_field_used_cache))
2787              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CACHE"));
2788            Lex->create_info.seq_create_info->cache= 0;
2789            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cache;
2790          }
2791        | CYCLE_SYM
2792          {
2793            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2794                seq_field_used_cycle))
2795              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CYCLE"));
2796            Lex->create_info.seq_create_info->cycle= 1;
2797            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cycle;
2798          }
2799        | NOCYCLE_SYM
2800          {
2801            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2802                seq_field_used_cycle))
2803              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CYCLE"));
2804            Lex->create_info.seq_create_info->cycle= 0;
2805            Lex->create_info.seq_create_info->used_fields|= seq_field_used_cycle;
2806          }
2807        | RESTART_SYM
2808          {
2809            if (unlikely(Lex->sql_command != SQLCOM_ALTER_SEQUENCE))
2810            {
2811              thd->parse_error(ER_SYNTAX_ERROR, "RESTART");
2812              YYABORT;
2813            }
2814            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2815                         seq_field_used_restart))
2816              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "RESTART"));
2817            Lex->create_info.seq_create_info->used_fields|= seq_field_used_restart;
2818          }
2819        | RESTART_SYM opt_with longlong_num
2820          {
2821            if (unlikely(Lex->sql_command != SQLCOM_ALTER_SEQUENCE))
2822            {
2823              thd->parse_error(ER_SYNTAX_ERROR, "RESTART");
2824              YYABORT;
2825            }
2826            if (unlikely(Lex->create_info.seq_create_info->used_fields &
2827                         seq_field_used_restart))
2828              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "RESTART"));
2829            Lex->create_info.seq_create_info->restart= $3;
2830            Lex->create_info.seq_create_info->used_fields|= seq_field_used_restart | seq_field_used_restart_value;
2831          }
2832        ;
2833
2834server_def:
2835          SERVER_SYM opt_if_not_exists ident_or_text
2836          {
2837            if (unlikely(Lex->add_create_options_with_check($2)))
2838              MYSQL_YYABORT;
2839            Lex->server_options.reset($3);
2840          }
2841          FOREIGN DATA_SYM WRAPPER_SYM ident_or_text
2842          OPTIONS_SYM '(' server_options_list ')'
2843          { Lex->server_options.scheme= $8; }
2844        ;
2845
2846server_options_list:
2847          server_option
2848        | server_options_list ',' server_option
2849        ;
2850
2851server_option:
2852          USER_SYM TEXT_STRING_sys
2853          {
2854            MYSQL_YYABORT_UNLESS(Lex->server_options.username.str == 0);
2855            Lex->server_options.username= $2;
2856          }
2857        | HOST_SYM TEXT_STRING_sys
2858          {
2859            MYSQL_YYABORT_UNLESS(Lex->server_options.host.str == 0);
2860            Lex->server_options.host= $2;
2861          }
2862        | DATABASE TEXT_STRING_sys
2863          {
2864            MYSQL_YYABORT_UNLESS(Lex->server_options.db.str == 0);
2865            Lex->server_options.db= $2;
2866          }
2867        | OWNER_SYM TEXT_STRING_sys
2868          {
2869            MYSQL_YYABORT_UNLESS(Lex->server_options.owner.str == 0);
2870            Lex->server_options.owner= $2;
2871          }
2872        | PASSWORD_SYM TEXT_STRING_sys
2873          {
2874            MYSQL_YYABORT_UNLESS(Lex->server_options.password.str == 0);
2875            Lex->server_options.password= $2;
2876          }
2877        | SOCKET_SYM TEXT_STRING_sys
2878          {
2879            MYSQL_YYABORT_UNLESS(Lex->server_options.socket.str == 0);
2880            Lex->server_options.socket= $2;
2881          }
2882        | PORT_SYM ulong_num
2883          {
2884            Lex->server_options.port= $2;
2885          }
2886        ;
2887
2888event_tail:
2889          remember_name opt_if_not_exists sp_name
2890          {
2891            LEX *lex=Lex;
2892
2893            lex->stmt_definition_begin= $1;
2894            if (unlikely(lex->add_create_options_with_check($2)))
2895              MYSQL_YYABORT;
2896            if (unlikely(!(lex->event_parse_data=
2897                           Event_parse_data::new_instance(thd))))
2898              MYSQL_YYABORT;
2899            lex->event_parse_data->identifier= $3;
2900            lex->event_parse_data->on_completion=
2901                                  Event_parse_data::ON_COMPLETION_DROP;
2902
2903            lex->sql_command= SQLCOM_CREATE_EVENT;
2904            /* We need that for disallowing subqueries */
2905          }
2906          ON SCHEDULE_SYM ev_schedule_time
2907          opt_ev_on_completion
2908          opt_ev_status
2909          opt_ev_comment
2910          DO_SYM ev_sql_stmt
2911          {
2912            /*
2913              sql_command is set here because some rules in ev_sql_stmt
2914              can overwrite it
2915            */
2916            Lex->sql_command= SQLCOM_CREATE_EVENT;
2917          }
2918        ;
2919
2920ev_schedule_time:
2921          EVERY_SYM expr interval
2922          {
2923            Lex->event_parse_data->item_expression= $2;
2924            Lex->event_parse_data->interval= $3;
2925          }
2926          ev_starts
2927          ev_ends
2928        | AT_SYM expr
2929          {
2930            Lex->event_parse_data->item_execute_at= $2;
2931          }
2932        ;
2933
2934opt_ev_status:
2935          /* empty */ { $$= 0; }
2936        | ENABLE_SYM
2937          {
2938            Lex->event_parse_data->status= Event_parse_data::ENABLED;
2939            Lex->event_parse_data->status_changed= true;
2940            $$= 1;
2941          }
2942        | DISABLE_SYM ON SLAVE
2943          {
2944            Lex->event_parse_data->status= Event_parse_data::SLAVESIDE_DISABLED;
2945            Lex->event_parse_data->status_changed= true;
2946            $$= 1;
2947          }
2948        | DISABLE_SYM
2949          {
2950            Lex->event_parse_data->status= Event_parse_data::DISABLED;
2951            Lex->event_parse_data->status_changed= true;
2952            $$= 1;
2953          }
2954        ;
2955
2956ev_starts:
2957          /* empty */
2958          {
2959            Item *item= new (thd->mem_root) Item_func_now_local(thd, 0);
2960            if (unlikely(item == NULL))
2961              MYSQL_YYABORT;
2962            Lex->event_parse_data->item_starts= item;
2963          }
2964        | STARTS_SYM expr
2965          {
2966            Lex->event_parse_data->item_starts= $2;
2967          }
2968        ;
2969
2970ev_ends:
2971          /* empty */
2972        | ENDS_SYM expr
2973          {
2974            Lex->event_parse_data->item_ends= $2;
2975          }
2976        ;
2977
2978opt_ev_on_completion:
2979          /* empty */ { $$= 0; }
2980        | ev_on_completion
2981        ;
2982
2983ev_on_completion:
2984          ON COMPLETION_SYM opt_not PRESERVE_SYM
2985          {
2986            Lex->event_parse_data->on_completion= $3
2987                                    ? Event_parse_data::ON_COMPLETION_DROP
2988                                    : Event_parse_data::ON_COMPLETION_PRESERVE;
2989            $$= 1;
2990          }
2991        ;
2992
2993opt_ev_comment:
2994          /* empty */ { $$= 0; }
2995        | COMMENT_SYM TEXT_STRING_sys
2996          {
2997            Lex->comment= Lex->event_parse_data->comment= $2;
2998            $$= 1;
2999          }
3000        ;
3001
3002ev_sql_stmt:
3003          {
3004            LEX *lex= thd->lex;
3005            Lex_input_stream *lip= YYLIP;
3006
3007            /*
3008              This stops the following :
3009              - CREATE EVENT ... DO CREATE EVENT ...;
3010              - ALTER  EVENT ... DO CREATE EVENT ...;
3011              - CREATE EVENT ... DO ALTER EVENT DO ....;
3012              - CREATE PROCEDURE ... BEGIN CREATE EVENT ... END|
3013              This allows:
3014              - CREATE EVENT ... DO DROP EVENT yyy;
3015              - CREATE EVENT ... DO ALTER EVENT yyy;
3016                (the nested ALTER EVENT can have anything but DO clause)
3017              - ALTER  EVENT ... DO ALTER EVENT yyy;
3018                (the nested ALTER EVENT can have anything but DO clause)
3019              - ALTER  EVENT ... DO DROP EVENT yyy;
3020              - CREATE PROCEDURE ... BEGIN ALTER EVENT ... END|
3021                (the nested ALTER EVENT can have anything but DO clause)
3022              - CREATE PROCEDURE ... BEGIN DROP EVENT ... END|
3023            */
3024            if (unlikely(lex->sphead))
3025              my_yyabort_error((ER_EVENT_RECURSION_FORBIDDEN, MYF(0)));
3026
3027            if (unlikely(!lex->make_sp_head(thd,
3028                                            lex->event_parse_data->identifier,
3029                                            &sp_handler_procedure,
3030                                            DEFAULT_AGGREGATE)))
3031              MYSQL_YYABORT;
3032
3033            lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
3034          }
3035          sp_proc_stmt
3036          {
3037            /* return back to the original memory root ASAP */
3038            if (Lex->sp_body_finalize_event(thd))
3039              MYSQL_YYABORT;
3040          }
3041        ;
3042
3043clear_privileges:
3044          /* Nothing */
3045          {
3046           LEX *lex=Lex;
3047           lex->users_list.empty();
3048           lex->columns.empty();
3049           lex->grant= lex->grant_tot_col= 0;
3050           lex->all_privileges= 0;
3051           lex->first_select_lex()->db= null_clex_str;
3052           lex->account_options.reset();
3053         }
3054        ;
3055
3056opt_aggregate:
3057          /* Empty */   { $$= NOT_AGGREGATE; }
3058        | AGGREGATE_SYM { $$= GROUP_AGGREGATE; }
3059        ;
3060
3061sp_name:
3062          ident '.' ident
3063          {
3064            if (unlikely(!($$= Lex->make_sp_name(thd, &$1, &$3))))
3065              MYSQL_YYABORT;
3066          }
3067        | ident
3068          {
3069            if (unlikely(!($$= Lex->make_sp_name(thd, &$1))))
3070              MYSQL_YYABORT;
3071          }
3072        ;
3073
3074opt_sp_name:
3075          /* Empty */ { $$= NULL; }
3076        | sp_name     { $$= $1; }
3077        ;
3078
3079sp_a_chistics:
3080          /* Empty */ {}
3081        | sp_a_chistics sp_chistic {}
3082        ;
3083
3084sp_c_chistics:
3085          /* Empty */ {}
3086        | sp_c_chistics sp_c_chistic {}
3087        ;
3088
3089/* Characteristics for both create and alter */
3090sp_chistic:
3091          COMMENT_SYM TEXT_STRING_sys
3092          { Lex->sp_chistics.comment= $2; }
3093        | LANGUAGE_SYM SQL_SYM
3094          { /* Just parse it, we only have one language for now. */ }
3095        | NO_SYM SQL_SYM
3096          { Lex->sp_chistics.daccess= SP_NO_SQL; }
3097        | CONTAINS_SYM SQL_SYM
3098          { Lex->sp_chistics.daccess= SP_CONTAINS_SQL; }
3099        | READS_SYM SQL_SYM DATA_SYM
3100          { Lex->sp_chistics.daccess= SP_READS_SQL_DATA; }
3101        | MODIFIES_SYM SQL_SYM DATA_SYM
3102          { Lex->sp_chistics.daccess= SP_MODIFIES_SQL_DATA; }
3103        | sp_suid
3104          { Lex->sp_chistics.suid= $1; }
3105        ;
3106
3107create_package_chistic:
3108          COMMENT_SYM TEXT_STRING_sys
3109          { Lex->sp_chistics.comment= $2; }
3110        | sp_suid
3111          { Lex->sp_chistics.suid= $1; }
3112        ;
3113
3114create_package_chistics:
3115          create_package_chistic {}
3116        | create_package_chistics create_package_chistic { }
3117        ;
3118
3119opt_create_package_chistics:
3120          /* Empty */
3121        | create_package_chistics { }
3122        ;
3123
3124opt_create_package_chistics_init:
3125          { Lex->sp_chistics.init(); }
3126          opt_create_package_chistics
3127        ;
3128
3129/* Create characteristics */
3130sp_c_chistic:
3131          sp_chistic            { }
3132        | opt_not DETERMINISTIC_SYM { Lex->sp_chistics.detistic= ! $1; }
3133        ;
3134
3135sp_suid:
3136          SQL_SYM SECURITY_SYM DEFINER_SYM { $$= SP_IS_SUID; }
3137        | SQL_SYM SECURITY_SYM INVOKER_SYM { $$= SP_IS_NOT_SUID; }
3138        ;
3139
3140call:
3141          CALL_SYM sp_name
3142          {
3143            if (unlikely(Lex->call_statement_start(thd, $2)))
3144              MYSQL_YYABORT;
3145          }
3146          opt_sp_cparam_list
3147          {
3148            if (Lex->check_cte_dependencies_and_resolve_references())
3149              MYSQL_YYABORT;
3150          }
3151        ;
3152
3153/* CALL parameters */
3154opt_sp_cparam_list:
3155          /* Empty */
3156        | '(' opt_sp_cparams ')'
3157        ;
3158
3159opt_sp_cparams:
3160          /* Empty */
3161        | sp_cparams
3162        ;
3163
3164sp_cparams:
3165          sp_cparams ',' expr
3166          {
3167           Lex->value_list.push_back($3, thd->mem_root);
3168          }
3169        | expr
3170          {
3171            Lex->value_list.push_back($1, thd->mem_root);
3172          }
3173        ;
3174
3175/* Stored FUNCTION parameter declaration list */
3176sp_fdparam_list:
3177          /* Empty */
3178          {
3179            Lex->sphead->m_param_begin= YYLIP->get_cpp_tok_start();
3180            Lex->sphead->m_param_end= Lex->sphead->m_param_begin;
3181          }
3182        |
3183          {
3184            Lex->sphead->m_param_begin= YYLIP->get_cpp_tok_start();
3185          }
3186          sp_fdparams
3187          {
3188            Lex->sphead->m_param_end= YYLIP->get_cpp_tok_start();
3189          }
3190        ;
3191
3192sp_fdparams:
3193          sp_fdparams ',' sp_param_name_and_type
3194        | sp_param_name_and_type
3195        ;
3196
3197sp_param_name:
3198          ident
3199          {
3200            if (unlikely(!($$= Lex->sp_param_init(&$1))))
3201              MYSQL_YYABORT;
3202          }
3203        ;
3204
3205sp_param_name_and_type:
3206          sp_param_name sp_param_type
3207          {
3208            if (unlikely(Lex->sp_param_fill_definition($$= $1)))
3209              MYSQL_YYABORT;
3210          }
3211        | sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
3212          {
3213            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4)))
3214              MYSQL_YYABORT;
3215          }
3216        | sp_param_name sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
3217          {
3218            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $$= $1, $2, $4, $6)))
3219              MYSQL_YYABORT;
3220          }
3221        | sp_param_name sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
3222          {
3223            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2)))
3224              MYSQL_YYABORT;
3225          }
3226        | sp_param_name sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
3227          {
3228            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $$= $1, $2, $4)))
3229              MYSQL_YYABORT;
3230          }
3231        | sp_param_name ROW_SYM row_type_body
3232          {
3233            if (unlikely(Lex->sphead->spvar_fill_row(thd, $$= $1, $3)))
3234              MYSQL_YYABORT;
3235          }
3236        ;
3237
3238/* Stored PROCEDURE parameter declaration list */
3239sp_pdparam_list:
3240          /* Empty */
3241        | sp_pdparams
3242        ;
3243
3244sp_pdparams:
3245          sp_pdparams ',' sp_pdparam
3246        | sp_pdparam
3247        ;
3248
3249sp_pdparam:
3250          sp_param_name sp_opt_inout sp_param_type
3251          {
3252            $1->mode= $2;
3253            if (unlikely(Lex->sp_param_fill_definition($1)))
3254              MYSQL_YYABORT;
3255          }
3256        | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
3257          {
3258            $1->mode= $2;
3259            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5)))
3260              MYSQL_YYABORT;
3261          }
3262        | sp_param_name sp_opt_inout sp_decl_ident '.' ident '.' ident PERCENT_ORACLE_SYM TYPE_SYM
3263          {
3264            $1->mode= $2;
3265            if (unlikely(Lex->sphead->spvar_fill_type_reference(thd, $1, $3, $5, $7)))
3266              MYSQL_YYABORT;
3267          }
3268        | sp_param_name sp_opt_inout sp_decl_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
3269          {
3270            $1->mode= $2;
3271            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3)))
3272              MYSQL_YYABORT;
3273          }
3274        | sp_param_name sp_opt_inout sp_decl_ident '.' ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
3275          {
3276            $1->mode= $2;
3277            if (unlikely(Lex->sphead->spvar_fill_table_rowtype_reference(thd, $1, $3, $5)))
3278              MYSQL_YYABORT;
3279          }
3280        | sp_param_name sp_opt_inout ROW_SYM row_type_body
3281          {
3282            $1->mode= $2;
3283            if (unlikely(Lex->sphead->spvar_fill_row(thd, $1, $4)))
3284              MYSQL_YYABORT;
3285          }
3286        ;
3287
3288sp_opt_inout:
3289          /* Empty */ { $$= sp_variable::MODE_IN; }
3290        | IN_SYM      { $$= sp_variable::MODE_IN; }
3291        | OUT_SYM     { $$= sp_variable::MODE_OUT; }
3292        | INOUT_SYM   { $$= sp_variable::MODE_INOUT; }
3293        | IN_SYM OUT_SYM { $$= sp_variable::MODE_INOUT; }
3294        ;
3295
3296sp_parenthesized_pdparam_list:
3297          '('
3298          {
3299            Lex->sphead->m_param_begin= YYLIP->get_cpp_tok_start() + 1;
3300          }
3301          sp_pdparam_list
3302          ')'
3303          {
3304            Lex->sphead->m_param_end= YYLIP->get_cpp_tok_start();
3305          }
3306        ;
3307
3308sp_no_param:
3309          /* Empty */
3310          {
3311            Lex->sphead->m_param_begin= Lex->sphead->m_param_end=
3312              YYLIP->get_cpp_tok_start() + 1;
3313          }
3314        ;
3315
3316opt_sp_parenthesized_fdparam_list:
3317          sp_no_param
3318        | '(' sp_fdparam_list ')'
3319        ;
3320
3321opt_sp_parenthesized_pdparam_list:
3322          sp_no_param
3323        | sp_parenthesized_pdparam_list
3324        ;
3325
3326sp_proc_stmts:
3327          /* Empty */ {}
3328        | sp_proc_stmts  sp_proc_stmt ';'
3329        ;
3330
3331sp_proc_stmts1:
3332          sp_proc_stmt ';' {}
3333        | sp_proc_stmts1  sp_proc_stmt ';'
3334        ;
3335
3336sp_proc_stmts1_implicit_block:
3337          {
3338            Lex->sp_block_init(thd);
3339          }
3340          sp_proc_stmts1
3341          {
3342            if (unlikely(Lex->sp_block_finalize(thd)))
3343              MYSQL_YYABORT;
3344          }
3345        ;
3346
3347opt_sp_decl_body_list:
3348          /* Empty */
3349          {
3350            $$.init();
3351          }
3352        | sp_decl_body_list { $$= $1; }
3353        ;
3354
3355sp_decl_body_list:
3356          sp_decl_non_handler_list
3357          {
3358            if (unlikely(Lex->sphead->sp_add_instr_cpush_for_cursors(thd, Lex->spcont)))
3359              MYSQL_YYABORT;
3360          }
3361          opt_sp_decl_handler_list
3362          {
3363            $$.join($1, $3);
3364          }
3365        | sp_decl_handler_list
3366        ;
3367
3368sp_decl_non_handler_list:
3369          sp_decl_non_handler ';' { $$= $1; }
3370        | sp_decl_non_handler_list sp_decl_non_handler ';'
3371          {
3372            $$.join($1, $2);
3373          }
3374        ;
3375
3376sp_decl_handler_list:
3377          sp_decl_handler ';' { $$= $1; }
3378        | sp_decl_handler_list sp_decl_handler ';'
3379          {
3380            $$.join($1, $2);
3381          }
3382        ;
3383
3384opt_sp_decl_handler_list:
3385          /* Empty*/ { $$.init(); }
3386        | sp_decl_handler_list
3387        ;
3388
3389optionally_qualified_column_ident:
3390          sp_decl_ident
3391          {
3392            if (unlikely(!($$= new (thd->mem_root)
3393                         Qualified_column_ident(&$1))))
3394              MYSQL_YYABORT;
3395          }
3396        | sp_decl_ident '.' ident
3397          {
3398            if (unlikely(!($$= new (thd->mem_root)
3399                           Qualified_column_ident(&$1, &$3))))
3400              MYSQL_YYABORT;
3401          }
3402        | sp_decl_ident '.' ident '.' ident
3403          {
3404            if (unlikely(!($$= new (thd->mem_root)
3405                           Qualified_column_ident(thd, &$1, &$3, &$5))))
3406              MYSQL_YYABORT;
3407          }
3408        ;
3409
3410row_field_name:
3411          ident_directly_assignable
3412          {
3413            if (!($$= Lex->row_field_name(thd, $1)))
3414              MYSQL_YYABORT;
3415          }
3416        ;
3417
3418row_field_definition:
3419          row_field_name field_type
3420        ;
3421
3422row_field_definition_list:
3423          row_field_definition
3424          {
3425            if (!($$= Row_definition_list::make(thd->mem_root, $1)))
3426              MYSQL_YYABORT;
3427          }
3428        | row_field_definition_list ',' row_field_definition
3429          {
3430            if (($$= $1)->append_uniq(thd->mem_root, $3))
3431              MYSQL_YYABORT;
3432          }
3433        ;
3434
3435row_type_body:
3436          '(' row_field_definition_list ')' { $$= $2; }
3437        ;
3438
3439sp_decl_idents_init_vars:
3440          sp_decl_idents
3441          {
3442            Lex->sp_variable_declarations_init(thd, $1);
3443          }
3444        ;
3445
3446sp_decl_vars:
3447          sp_decl_idents_init_vars
3448          field_type
3449          sp_opt_default
3450          {
3451            if (unlikely(Lex->sp_variable_declarations_finalize(thd, $1,
3452                                                                &Lex->last_field[0],
3453                                                                $3)))
3454              MYSQL_YYABORT;
3455            $$.init_using_vars($1);
3456          }
3457        | sp_decl_idents_init_vars
3458          optionally_qualified_column_ident PERCENT_ORACLE_SYM TYPE_SYM
3459          sp_opt_default
3460          {
3461            if (unlikely(Lex->sp_variable_declarations_with_ref_finalize(thd, $1, $2, $5)))
3462              MYSQL_YYABORT;
3463            $$.init_using_vars($1);
3464          }
3465        | sp_decl_idents_init_vars
3466          optionally_qualified_column_ident PERCENT_ORACLE_SYM ROWTYPE_ORACLE_SYM
3467          sp_opt_default
3468          {
3469            if (unlikely(Lex->sp_variable_declarations_rowtype_finalize(thd, $1, $2, $5)))
3470              MYSQL_YYABORT;
3471            $$.init_using_vars($1);
3472          }
3473        | sp_decl_idents_init_vars
3474          ROW_SYM row_type_body
3475          sp_opt_default
3476          {
3477            if (unlikely(Lex->sp_variable_declarations_row_finalize(thd, $1, $3, $4)))
3478              MYSQL_YYABORT;
3479            $$.init_using_vars($1);
3480          }
3481        ;
3482
3483sp_decl_non_handler:
3484          sp_decl_vars
3485        | ident_directly_assignable CONDITION_SYM FOR_SYM sp_cond
3486          {
3487            if (unlikely(Lex->spcont->declare_condition(thd, &$1, $4)))
3488              MYSQL_YYABORT;
3489            $$.vars= $$.hndlrs= $$.curs= 0;
3490            $$.conds= 1;
3491          }
3492        | ident_directly_assignable EXCEPTION_ORACLE_SYM
3493          {
3494            sp_condition_value *spcond= new (thd->mem_root)
3495                                        sp_condition_value_user_defined();
3496            if (unlikely(!spcond) ||
3497                unlikely(Lex->spcont->declare_condition(thd, &$1, spcond)))
3498              MYSQL_YYABORT;
3499            $$.vars= $$.hndlrs= $$.curs= 0;
3500            $$.conds= 1;
3501          }
3502        | CURSOR_SYM ident_directly_assignable
3503          {
3504            Lex->sp_block_init(thd);
3505          }
3506          opt_parenthesized_cursor_formal_parameters
3507          IS sp_cursor_stmt
3508          {
3509            sp_pcontext *param_ctx= Lex->spcont;
3510            if (unlikely(Lex->sp_block_finalize(thd)))
3511              MYSQL_YYABORT;
3512            if (unlikely(Lex->sp_declare_cursor(thd, &$2, $6, param_ctx, false)))
3513              MYSQL_YYABORT;
3514            $$.vars= $$.conds= $$.hndlrs= 0;
3515            $$.curs= 1;
3516          }
3517        ;
3518
3519sp_decl_handler:
3520          sp_handler_type HANDLER_SYM FOR_SYM
3521          {
3522            if (unlikely(Lex->sp_handler_declaration_init(thd, $1)))
3523              MYSQL_YYABORT;
3524          }
3525          sp_hcond_list sp_proc_stmt
3526          {
3527            if (unlikely(Lex->sp_handler_declaration_finalize(thd, $1)))
3528              MYSQL_YYABORT;
3529            $$.vars= $$.conds= $$.curs= 0;
3530            $$.hndlrs= 1;
3531          }
3532        ;
3533
3534opt_parenthesized_cursor_formal_parameters:
3535          /* Empty */
3536        | '(' sp_fdparams ')'
3537        ;
3538
3539
3540sp_cursor_stmt_lex:
3541          {
3542            DBUG_ASSERT(thd->lex->sphead);
3543            if (unlikely(!($$= new (thd->mem_root)
3544                           sp_lex_cursor(thd, thd->lex))))
3545              MYSQL_YYABORT;
3546          }
3547        ;
3548
3549sp_cursor_stmt:
3550          sp_cursor_stmt_lex
3551          {
3552            DBUG_ASSERT(thd->free_list == NULL);
3553            Lex->sphead->reset_lex(thd, $1);
3554            if (Lex->main_select_push(true))
3555              MYSQL_YYABORT;
3556          }
3557          select
3558          {
3559            DBUG_ASSERT(Lex == $1);
3560            Lex->pop_select(); //main select
3561            if (unlikely($1->stmt_finalize(thd)) ||
3562                unlikely($1->sphead->restore_lex(thd)))
3563              MYSQL_YYABORT;
3564            $$= $1;
3565          }
3566        ;
3567
3568sp_handler_type:
3569          EXIT_MARIADB_SYM      { $$= sp_handler::EXIT; }
3570        | CONTINUE_MARIADB_SYM  { $$= sp_handler::CONTINUE; }
3571        | EXIT_ORACLE_SYM      { $$= sp_handler::EXIT; }
3572        | CONTINUE_ORACLE_SYM  { $$= sp_handler::CONTINUE; }
3573       /*| UNDO_SYM      { QQ No yet } */
3574        ;
3575
3576sp_hcond_list:
3577          sp_hcond_element
3578          { $$= 1; }
3579        | sp_hcond_list ',' sp_hcond_element
3580          { $$+= 1; }
3581        ;
3582
3583sp_hcond_element:
3584          sp_hcond
3585          {
3586            LEX *lex= Lex;
3587            sp_head *sp= lex->sphead;
3588            sp_pcontext *ctx= lex->spcont->parent_context();
3589
3590            if (unlikely(ctx->check_duplicate_handler($1)))
3591              my_yyabort_error((ER_SP_DUP_HANDLER, MYF(0)));
3592
3593            sp_instr_hpush_jump *i= (sp_instr_hpush_jump *)sp->last_instruction();
3594            i->add_condition($1);
3595          }
3596        ;
3597
3598sp_cond:
3599          ulong_num
3600          { /* mysql errno */
3601            if (unlikely($1 == 0))
3602              my_yyabort_error((ER_WRONG_VALUE, MYF(0), "CONDITION", "0"));
3603            $$= new (thd->mem_root) sp_condition_value($1);
3604            if (unlikely($$ == NULL))
3605              MYSQL_YYABORT;
3606          }
3607        | sqlstate
3608        ;
3609
3610sqlstate:
3611          SQLSTATE_SYM opt_value TEXT_STRING_literal
3612          { /* SQLSTATE */
3613
3614            /*
3615              An error is triggered:
3616                - if the specified string is not a valid SQLSTATE,
3617                - or if it represents the completion condition -- it is not
3618                  allowed to SIGNAL, or declare a handler for the completion
3619                  condition.
3620            */
3621            if (unlikely(!is_sqlstate_valid(&$3) ||
3622                         is_sqlstate_completion($3.str)))
3623              my_yyabort_error((ER_SP_BAD_SQLSTATE, MYF(0), $3.str));
3624            $$= new (thd->mem_root) sp_condition_value($3.str);
3625            if (unlikely($$ == NULL))
3626              MYSQL_YYABORT;
3627          }
3628        ;
3629
3630opt_value:
3631          /* Empty */  {}
3632        | VALUE_SYM    {}
3633        ;
3634
3635sp_hcond:
3636          sp_cond
3637          {
3638            $$= $1;
3639          }
3640        | ident /* CONDITION name */
3641          {
3642            $$= Lex->spcont->find_declared_or_predefined_condition(thd, &$1);
3643            if (unlikely($$ == NULL))
3644              my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str));
3645          }
3646        | SQLWARNING_SYM /* SQLSTATEs 01??? */
3647          {
3648            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::WARNING);
3649            if (unlikely($$ == NULL))
3650              MYSQL_YYABORT;
3651          }
3652        | not FOUND_SYM /* SQLSTATEs 02??? */
3653          {
3654            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::NOT_FOUND);
3655            if (unlikely($$ == NULL))
3656              MYSQL_YYABORT;
3657          }
3658        | SQLEXCEPTION_SYM /* All other SQLSTATEs */
3659          {
3660            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::EXCEPTION);
3661            if (unlikely($$ == NULL))
3662              MYSQL_YYABORT;
3663          }
3664        | OTHERS_ORACLE_SYM /* All other SQLSTATEs */
3665          {
3666            $$= new (thd->mem_root) sp_condition_value(sp_condition_value::EXCEPTION);
3667            if (unlikely($$ == NULL))
3668              MYSQL_YYABORT;
3669          }
3670        ;
3671
3672
3673raise_stmt_oracle:
3674          RAISE_ORACLE_SYM opt_set_signal_information
3675          {
3676            if (unlikely(Lex->add_resignal_statement(thd, NULL)))
3677              MYSQL_YYABORT;
3678          }
3679        | RAISE_ORACLE_SYM signal_value opt_set_signal_information
3680          {
3681            if (unlikely(Lex->add_signal_statement(thd, $2)))
3682              MYSQL_YYABORT;
3683          }
3684        ;
3685
3686signal_stmt:
3687          SIGNAL_SYM signal_value opt_set_signal_information
3688          {
3689            if (Lex->add_signal_statement(thd, $2))
3690              MYSQL_YYABORT;
3691          }
3692        ;
3693
3694signal_value:
3695          ident
3696          {
3697            LEX *lex= Lex;
3698            sp_condition_value *cond;
3699
3700            /* SIGNAL foo cannot be used outside of stored programs */
3701            if (unlikely(lex->spcont == NULL))
3702              my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str));
3703            cond= lex->spcont->find_declared_or_predefined_condition(thd, &$1);
3704            if (unlikely(cond == NULL))
3705              my_yyabort_error((ER_SP_COND_MISMATCH, MYF(0), $1.str));
3706            if (unlikely(!cond->has_sql_state()))
3707              my_yyabort_error((ER_SIGNAL_BAD_CONDITION_TYPE, MYF(0)));
3708            $$= cond;
3709          }
3710        | sqlstate
3711          { $$= $1; }
3712        ;
3713
3714opt_signal_value:
3715          /* empty */
3716          { $$= NULL; }
3717        | signal_value
3718          { $$= $1; }
3719        ;
3720
3721opt_set_signal_information:
3722          /* empty */
3723          {
3724            thd->m_parser_state->m_yacc.m_set_signal_info.clear();
3725          }
3726        | SET signal_information_item_list
3727        ;
3728
3729signal_information_item_list:
3730          signal_condition_information_item_name '=' signal_allowed_expr
3731          {
3732            Set_signal_information *info;
3733            info= &thd->m_parser_state->m_yacc.m_set_signal_info;
3734            int index= (int) $1;
3735            info->clear();
3736            info->m_item[index]= $3;
3737          }
3738        | signal_information_item_list ','
3739          signal_condition_information_item_name '=' signal_allowed_expr
3740          {
3741            Set_signal_information *info;
3742            info= &thd->m_parser_state->m_yacc.m_set_signal_info;
3743            int index= (int) $3;
3744            if (unlikely(info->m_item[index] != NULL))
3745              my_yyabort_error((ER_DUP_SIGNAL_SET, MYF(0),
3746                                Diag_condition_item_names[index].str));
3747            info->m_item[index]= $5;
3748          }
3749        ;
3750
3751/*
3752  Only a limited subset of <expr> are allowed in SIGNAL/RESIGNAL.
3753*/
3754signal_allowed_expr:
3755          literal
3756          { $$= $1; }
3757        | variable
3758          {
3759            if ($1->type() == Item::FUNC_ITEM)
3760            {
3761              Item_func *item= (Item_func*) $1;
3762              if (unlikely(item->functype() == Item_func::SUSERVAR_FUNC))
3763              {
3764                /*
3765                  Don't allow the following syntax:
3766                    SIGNAL/RESIGNAL ...
3767                    SET <signal condition item name> = @foo := expr
3768                */
3769                thd->parse_error();
3770                MYSQL_YYABORT;
3771              }
3772            }
3773            $$= $1;
3774          }
3775        | simple_ident
3776          { $$= $1; }
3777        ;
3778
3779/* conditions that can be set in signal / resignal */
3780signal_condition_information_item_name:
3781          CLASS_ORIGIN_SYM
3782          { $$= DIAG_CLASS_ORIGIN; }
3783        | SUBCLASS_ORIGIN_SYM
3784          { $$= DIAG_SUBCLASS_ORIGIN; }
3785        | CONSTRAINT_CATALOG_SYM
3786          { $$= DIAG_CONSTRAINT_CATALOG; }
3787        | CONSTRAINT_SCHEMA_SYM
3788          { $$= DIAG_CONSTRAINT_SCHEMA; }
3789        | CONSTRAINT_NAME_SYM
3790          { $$= DIAG_CONSTRAINT_NAME; }
3791        | CATALOG_NAME_SYM
3792          { $$= DIAG_CATALOG_NAME; }
3793        | SCHEMA_NAME_SYM
3794          { $$= DIAG_SCHEMA_NAME; }
3795        | TABLE_NAME_SYM
3796          { $$= DIAG_TABLE_NAME; }
3797        | COLUMN_NAME_SYM
3798          { $$= DIAG_COLUMN_NAME; }
3799        | CURSOR_NAME_SYM
3800          { $$= DIAG_CURSOR_NAME; }
3801        | MESSAGE_TEXT_SYM
3802          { $$= DIAG_MESSAGE_TEXT; }
3803        | MYSQL_ERRNO_SYM
3804          { $$= DIAG_MYSQL_ERRNO; }
3805        ;
3806
3807resignal_stmt:
3808          RESIGNAL_SYM opt_signal_value opt_set_signal_information
3809          {
3810            if (unlikely(Lex->add_resignal_statement(thd, $2)))
3811              MYSQL_YYABORT;
3812          }
3813        ;
3814
3815get_diagnostics:
3816          GET_SYM which_area DIAGNOSTICS_SYM diagnostics_information
3817          {
3818            Diagnostics_information *info= $4;
3819
3820            info->set_which_da($2);
3821
3822            Lex->sql_command= SQLCOM_GET_DIAGNOSTICS;
3823            Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_get_diagnostics(info);
3824
3825            if (unlikely(Lex->m_sql_cmd == NULL))
3826              MYSQL_YYABORT;
3827          }
3828        ;
3829
3830which_area:
3831        /* If <which area> is not specified, then CURRENT is implicit. */
3832          { $$= Diagnostics_information::CURRENT_AREA; }
3833        | CURRENT_SYM
3834          { $$= Diagnostics_information::CURRENT_AREA; }
3835        ;
3836
3837diagnostics_information:
3838          statement_information
3839          {
3840            $$= new (thd->mem_root) Statement_information($1);
3841            if (unlikely($$ == NULL))
3842              MYSQL_YYABORT;
3843          }
3844        | CONDITION_SYM condition_number condition_information
3845          {
3846            $$= new (thd->mem_root) Condition_information($2, $3);
3847            if (unlikely($$ == NULL))
3848              MYSQL_YYABORT;
3849          }
3850        ;
3851
3852statement_information:
3853          statement_information_item
3854          {
3855            $$= new (thd->mem_root) List<Statement_information_item>;
3856            if (unlikely($$ == NULL) ||
3857                unlikely($$->push_back($1, thd->mem_root)))
3858              MYSQL_YYABORT;
3859          }
3860        | statement_information ',' statement_information_item
3861          {
3862            if (unlikely($1->push_back($3, thd->mem_root)))
3863              MYSQL_YYABORT;
3864            $$= $1;
3865          }
3866        ;
3867
3868statement_information_item:
3869          simple_target_specification '=' statement_information_item_name
3870          {
3871            $$= new (thd->mem_root) Statement_information_item($3, $1);
3872            if (unlikely($$ == NULL))
3873              MYSQL_YYABORT;
3874          }
3875        ;
3876
3877simple_target_specification:
3878          ident_cli
3879          {
3880            if (unlikely(!($$= thd->lex->create_item_for_sp_var(&$1, NULL))))
3881              MYSQL_YYABORT;
3882          }
3883        | '@' ident_or_text
3884          {
3885            $$= new (thd->mem_root) Item_func_get_user_var(thd, &$2);
3886            if (unlikely($$ == NULL))
3887              MYSQL_YYABORT;
3888          }
3889        ;
3890
3891statement_information_item_name:
3892          NUMBER_MARIADB_SYM
3893          { $$= Statement_information_item::NUMBER; }
3894        | NUMBER_ORACLE_SYM
3895          { $$= Statement_information_item::NUMBER; }
3896        | ROW_COUNT_SYM
3897          { $$= Statement_information_item::ROW_COUNT; }
3898        ;
3899
3900/*
3901   Only a limited subset of <expr> are allowed in GET DIAGNOSTICS
3902   <condition number>, same subset as for SIGNAL/RESIGNAL.
3903*/
3904condition_number:
3905          signal_allowed_expr
3906          { $$= $1; }
3907        ;
3908
3909condition_information:
3910          condition_information_item
3911          {
3912            $$= new (thd->mem_root) List<Condition_information_item>;
3913            if (unlikely($$ == NULL) ||
3914                unlikely($$->push_back($1, thd->mem_root)))
3915              MYSQL_YYABORT;
3916          }
3917        | condition_information ',' condition_information_item
3918          {
3919            if (unlikely($1->push_back($3, thd->mem_root)))
3920              MYSQL_YYABORT;
3921            $$= $1;
3922          }
3923        ;
3924
3925condition_information_item:
3926          simple_target_specification '=' condition_information_item_name
3927          {
3928            $$= new (thd->mem_root) Condition_information_item($3, $1);
3929            if (unlikely($$ == NULL))
3930              MYSQL_YYABORT;
3931          }
3932        ;
3933
3934condition_information_item_name:
3935          CLASS_ORIGIN_SYM
3936          { $$= Condition_information_item::CLASS_ORIGIN; }
3937        | SUBCLASS_ORIGIN_SYM
3938          { $$= Condition_information_item::SUBCLASS_ORIGIN; }
3939        | CONSTRAINT_CATALOG_SYM
3940          { $$= Condition_information_item::CONSTRAINT_CATALOG; }
3941        | CONSTRAINT_SCHEMA_SYM
3942          { $$= Condition_information_item::CONSTRAINT_SCHEMA; }
3943        | CONSTRAINT_NAME_SYM
3944          { $$= Condition_information_item::CONSTRAINT_NAME; }
3945        | CATALOG_NAME_SYM
3946          { $$= Condition_information_item::CATALOG_NAME; }
3947        | SCHEMA_NAME_SYM
3948          { $$= Condition_information_item::SCHEMA_NAME; }
3949        | TABLE_NAME_SYM
3950          { $$= Condition_information_item::TABLE_NAME; }
3951        | COLUMN_NAME_SYM
3952          { $$= Condition_information_item::COLUMN_NAME; }
3953        | CURSOR_NAME_SYM
3954          { $$= Condition_information_item::CURSOR_NAME; }
3955        | MESSAGE_TEXT_SYM
3956          { $$= Condition_information_item::MESSAGE_TEXT; }
3957        | MYSQL_ERRNO_SYM
3958          { $$= Condition_information_item::MYSQL_ERRNO; }
3959        | RETURNED_SQLSTATE_SYM
3960          { $$= Condition_information_item::RETURNED_SQLSTATE; }
3961        ;
3962
3963sp_decl_ident:
3964          IDENT_sys
3965        | keyword_sp_decl
3966          {
3967            if (unlikely($$.copy_ident_cli(thd, &$1)))
3968              MYSQL_YYABORT;
3969          }
3970        ;
3971
3972sp_decl_idents:
3973          sp_decl_ident
3974          {
3975            /* NOTE: field definition is filled in sp_decl section. */
3976
3977            LEX *lex= Lex;
3978            sp_pcontext *spc= lex->spcont;
3979
3980            if (unlikely(spc->find_variable(&$1, TRUE)))
3981              my_yyabort_error((ER_SP_DUP_VAR, MYF(0), $1.str));
3982            spc->add_variable(thd, &$1);
3983            $$= 1;
3984          }
3985        | sp_decl_idents ',' ident
3986          {
3987            /* NOTE: field definition is filled in sp_decl section. */
3988
3989            LEX *lex= Lex;
3990            sp_pcontext *spc= lex->spcont;
3991
3992            if (unlikely(spc->find_variable(&$3, TRUE)))
3993              my_yyabort_error((ER_SP_DUP_VAR, MYF(0), $3.str));
3994            spc->add_variable(thd, &$3);
3995            $$= $1 + 1;
3996          }
3997        ;
3998
3999sp_opt_default:
4000          /* Empty */ { $$ = NULL; }
4001        | DEFAULT expr { $$ = $2; }
4002        | SET_VAR expr { $$ = $2; }
4003        ;
4004
4005sp_proc_stmt:
4006          sp_labeled_block
4007        | sp_unlabeled_block
4008        | sp_labeled_control
4009        | sp_unlabeled_control
4010        | sp_labelable_stmt
4011        | labels_declaration_oracle sp_labelable_stmt {}
4012        ;
4013
4014sp_labelable_stmt:
4015          sp_proc_stmt_statement
4016        | sp_proc_stmt_continue_oracle
4017        | sp_proc_stmt_exit_oracle
4018        | sp_proc_stmt_leave
4019        | sp_proc_stmt_iterate
4020        | sp_proc_stmt_goto_oracle
4021        | sp_proc_stmt_open
4022        | sp_proc_stmt_fetch
4023        | sp_proc_stmt_close
4024        | sp_proc_stmt_return
4025        | sp_proc_stmt_if
4026        | case_stmt_specification
4027        | NULL_SYM { }
4028        ;
4029
4030sp_proc_stmt_compound_ok:
4031          sp_proc_stmt_if
4032        | case_stmt_specification
4033        | sp_unlabeled_block
4034        | sp_unlabeled_control
4035        ;
4036
4037sp_proc_stmt_if:
4038          IF_SYM
4039          {
4040            if (unlikely(Lex->maybe_start_compound_statement(thd)))
4041              MYSQL_YYABORT;
4042            Lex->sphead->new_cont_backpatch(NULL);
4043          }
4044          sp_if END IF_SYM
4045          { Lex->sphead->do_cont_backpatch(); }
4046        ;
4047
4048sp_statement:
4049          statement
4050        | ident_directly_assignable
4051          {
4052            // Direct procedure call (without the CALL keyword)
4053            if (unlikely(Lex->call_statement_start(thd, &$1)))
4054              MYSQL_YYABORT;
4055          }
4056          opt_sp_cparam_list
4057        | ident_directly_assignable '.' ident
4058          {
4059            if (unlikely(Lex->call_statement_start(thd, &$1, &$3)))
4060              MYSQL_YYABORT;
4061          }
4062          opt_sp_cparam_list
4063        ;
4064
4065sp_proc_stmt_statement:
4066          {
4067            LEX *lex= thd->lex;
4068            Lex_input_stream *lip= YYLIP;
4069
4070            lex->sphead->reset_lex(thd);
4071            /*
4072              We should not push main select here, it will be done or not
4073              done by the statement, we just provide only new LEX for the
4074              statement here as if it is start of parsing new statement.
4075            */
4076            lex->sphead->m_tmp_query= lip->get_tok_start();
4077          }
4078          sp_statement
4079          {
4080            if (Lex->sp_proc_stmt_statement_finalize(thd, yychar == YYEMPTY) ||
4081                Lex->sphead->restore_lex(thd))
4082              MYSQL_YYABORT;
4083          }
4084        ;
4085
4086
4087RETURN_ALLMODES_SYM:
4088          RETURN_MARIADB_SYM
4089        | RETURN_ORACLE_SYM
4090        ;
4091
4092sp_proc_stmt_return:
4093          RETURN_ALLMODES_SYM
4094          {
4095            Lex->sphead->reset_lex(thd);
4096            if (Lex->main_select_push(true))
4097              MYSQL_YYABORT;
4098          }
4099          expr
4100          {
4101            LEX *lex= Lex;
4102            sp_head *sp= lex->sphead;
4103            Lex->pop_select(); //main select
4104            if (Lex->check_cte_dependencies_and_resolve_references())
4105              MYSQL_YYABORT;
4106            if (unlikely(sp->m_handler->add_instr_freturn(thd, sp, lex->spcont,
4107                                                          $3, lex)) ||
4108                unlikely(sp->restore_lex(thd)))
4109              MYSQL_YYABORT;
4110          }
4111        | RETURN_ORACLE_SYM
4112          {
4113            LEX *lex= Lex;
4114            sp_head *sp= lex->sphead;
4115            if (unlikely(sp->m_handler->add_instr_preturn(thd, sp,
4116                                                               lex->spcont)))
4117              MYSQL_YYABORT;
4118          }
4119        ;
4120
4121reset_lex_expr:
4122          {
4123            Lex->sphead->reset_lex(thd);
4124            if (Lex->main_select_push(true))
4125              MYSQL_YYABORT;
4126          }
4127          expr
4128          {
4129            $$= $2;
4130            Lex->pop_select(); //main select
4131          }
4132        ;
4133
4134sp_proc_stmt_exit_oracle:
4135          EXIT_ORACLE_SYM
4136          {
4137            if (unlikely(Lex->sp_exit_statement(thd, NULL)))
4138              MYSQL_YYABORT;
4139          }
4140        | EXIT_ORACLE_SYM label_ident
4141          {
4142            if (unlikely(Lex->sp_exit_statement(thd, &$2, NULL)))
4143              MYSQL_YYABORT;
4144          }
4145        | EXIT_ORACLE_SYM WHEN_SYM reset_lex_expr
4146          {
4147            if (Lex->sp_exit_statement(thd, $3) ||
4148                Lex->sphead->restore_lex(thd))
4149              MYSQL_YYABORT;
4150          }
4151        | EXIT_ORACLE_SYM label_ident WHEN_SYM reset_lex_expr
4152          {
4153            if (Lex->sp_exit_statement(thd, &$2, $4) ||
4154                Lex->sphead->restore_lex(thd))
4155              MYSQL_YYABORT;
4156          }
4157        ;
4158
4159sp_proc_stmt_continue_oracle:
4160          CONTINUE_ORACLE_SYM
4161          {
4162            if (unlikely(Lex->sp_continue_statement(thd, NULL)))
4163              MYSQL_YYABORT;
4164          }
4165        | CONTINUE_ORACLE_SYM label_ident
4166          {
4167            if (unlikely(Lex->sp_continue_statement(thd, &$2, NULL)))
4168              MYSQL_YYABORT;
4169          }
4170        | CONTINUE_ORACLE_SYM WHEN_SYM reset_lex_expr
4171          {
4172            if (Lex->sp_continue_statement(thd, $3) ||
4173                Lex->sphead->restore_lex(thd))
4174              MYSQL_YYABORT;
4175          }
4176        | CONTINUE_ORACLE_SYM label_ident WHEN_SYM reset_lex_expr
4177          {
4178            if (Lex->sp_continue_statement(thd, &$2, $4) ||
4179                Lex->sphead->restore_lex(thd))
4180              MYSQL_YYABORT;
4181          }
4182        ;
4183
4184
4185sp_proc_stmt_leave:
4186          LEAVE_SYM label_ident
4187          {
4188            if (unlikely(Lex->sp_leave_statement(thd, &$2)))
4189              MYSQL_YYABORT;
4190          }
4191        ;
4192
4193sp_proc_stmt_iterate:
4194          ITERATE_SYM label_ident
4195          {
4196            if (unlikely(Lex->sp_iterate_statement(thd, &$2)))
4197              MYSQL_YYABORT;
4198          }
4199        ;
4200
4201sp_proc_stmt_goto_oracle:
4202          GOTO_ORACLE_SYM label_ident
4203          {
4204            if (unlikely(Lex->sp_goto_statement(thd, &$2)))
4205              MYSQL_YYABORT;
4206          }
4207        ;
4208
4209
4210remember_lex:
4211          {
4212            $$= thd->lex;
4213          }
4214        ;
4215
4216assignment_source_lex:
4217          {
4218            DBUG_ASSERT(Lex->sphead);
4219            if (unlikely(!($$= new (thd->mem_root)
4220                           sp_assignment_lex(thd, thd->lex))))
4221              MYSQL_YYABORT;
4222          }
4223        ;
4224
4225assignment_source_expr:
4226          assignment_source_lex
4227          {
4228            DBUG_ASSERT(thd->free_list == NULL);
4229            Lex->sphead->reset_lex(thd, $1);
4230            if (Lex->main_select_push(true))
4231              MYSQL_YYABORT;
4232          }
4233          expr
4234          {
4235            DBUG_ASSERT($1 == thd->lex);
4236            $$= $1;
4237            $$->sp_lex_in_use= true;
4238            $$->set_item_and_free_list($3, thd->free_list);
4239            thd->free_list= NULL;
4240            Lex->pop_select(); //main select
4241            if ($$->sphead->restore_lex(thd))
4242              MYSQL_YYABORT;
4243          }
4244        ;
4245
4246for_loop_bound_expr:
4247          assignment_source_lex
4248          {
4249            Lex->sphead->reset_lex(thd, $1);
4250            if (Lex->main_select_push(true))
4251              MYSQL_YYABORT;
4252            Lex->current_select->parsing_place= FOR_LOOP_BOUND;
4253          }
4254          expr
4255          {
4256            DBUG_ASSERT($1 == thd->lex);
4257            $$= $1;
4258            $$->sp_lex_in_use= true;
4259            $$->set_item_and_free_list($3, NULL);
4260            Lex->pop_select(); //main select
4261            if (unlikely($$->sphead->restore_lex(thd)))
4262              MYSQL_YYABORT;
4263            Lex->current_select->parsing_place= NO_MATTER;
4264          }
4265        ;
4266
4267cursor_actual_parameters:
4268          assignment_source_expr
4269          {
4270            if (unlikely(!($$= new (thd->mem_root) List<sp_assignment_lex>)))
4271              MYSQL_YYABORT;
4272            $$->push_back($1, thd->mem_root);
4273          }
4274        | cursor_actual_parameters ',' assignment_source_expr
4275          {
4276            $$= $1;
4277            $$->push_back($3, thd->mem_root);
4278          }
4279        ;
4280
4281opt_parenthesized_cursor_actual_parameters:
4282          /* Empty */                        { $$= NULL; }
4283        | '(' cursor_actual_parameters ')'   { $$= $2; }
4284        ;
4285
4286sp_proc_stmt_open:
4287          OPEN_SYM ident opt_parenthesized_cursor_actual_parameters
4288          {
4289            if (unlikely(Lex->sp_open_cursor(thd, &$2, $3)))
4290              MYSQL_YYABORT;
4291          }
4292        ;
4293
4294sp_proc_stmt_fetch_head:
4295          FETCH_SYM ident INTO
4296          {
4297            if (unlikely(Lex->sp_add_cfetch(thd, &$2)))
4298              MYSQL_YYABORT;
4299          }
4300        | FETCH_SYM FROM ident INTO
4301          {
4302            if (unlikely(Lex->sp_add_cfetch(thd, &$3)))
4303              MYSQL_YYABORT;
4304          }
4305       | FETCH_SYM NEXT_SYM FROM ident INTO
4306          {
4307            if (unlikely(Lex->sp_add_cfetch(thd, &$4)))
4308              MYSQL_YYABORT;
4309          }
4310        ;
4311
4312sp_proc_stmt_fetch:
4313         sp_proc_stmt_fetch_head sp_fetch_list { }
4314       | FETCH_SYM GROUP_SYM NEXT_SYM ROW_SYM
4315         {
4316           if (unlikely(Lex->sp_add_agg_cfetch()))
4317             MYSQL_YYABORT;
4318         }
4319        ;
4320
4321sp_proc_stmt_close:
4322          CLOSE_SYM ident
4323          {
4324            LEX *lex= Lex;
4325            sp_head *sp= lex->sphead;
4326            uint offset;
4327            sp_instr_cclose *i;
4328
4329            if (unlikely(!lex->spcont->find_cursor(&$2, &offset, false)))
4330              my_yyabort_error((ER_SP_CURSOR_MISMATCH, MYF(0), $2.str));
4331            i= new (thd->mem_root)
4332              sp_instr_cclose(sp->instructions(), lex->spcont,  offset);
4333            if (unlikely(i == NULL) ||
4334                unlikely(sp->add_instr(i)))
4335              MYSQL_YYABORT;
4336          }
4337        ;
4338
4339sp_fetch_list:
4340          ident
4341          {
4342            LEX *lex= Lex;
4343            sp_head *sp= lex->sphead;
4344            sp_pcontext *spc= lex->spcont;
4345            sp_variable *spv= likely(spc != NULL)
4346              ? spc->find_variable(&$1, false)
4347              : NULL;
4348            if (unlikely(!spv))
4349              my_yyabort_error((ER_SP_UNDECLARED_VAR, MYF(0), $1.str));
4350
4351            /* An SP local variable */
4352            sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction();
4353            i->add_to_varlist(spv);
4354          }
4355        | sp_fetch_list ',' ident
4356          {
4357            LEX *lex= Lex;
4358            sp_head *sp= lex->sphead;
4359            sp_pcontext *spc= lex->spcont;
4360            sp_variable *spv= likely(spc != NULL)
4361              ? spc->find_variable(&$3, false)
4362              : NULL;
4363            if (unlikely(!spv))
4364              my_yyabort_error((ER_SP_UNDECLARED_VAR, MYF(0), $3.str));
4365
4366            /* An SP local variable */
4367            sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction();
4368            i->add_to_varlist(spv);
4369          }
4370        ;
4371
4372sp_if:
4373          {
4374            Lex->sphead->reset_lex(thd);
4375            if (Lex->main_select_push(true))
4376              MYSQL_YYABORT;
4377          }
4378          expr THEN_SYM
4379          {
4380            LEX *lex= Lex;
4381            sp_head *sp= lex->sphead;
4382            sp_pcontext *ctx= lex->spcont;
4383            uint ip= sp->instructions();
4384            sp_instr_jump_if_not *i= new (thd->mem_root)
4385              sp_instr_jump_if_not(ip, ctx, $2, lex);
4386            if (unlikely(i == NULL) ||
4387                unlikely(sp->push_backpatch(thd, i, ctx->push_label(thd, &empty_clex_str, 0))) ||
4388                unlikely(sp->add_cont_backpatch(i)) ||
4389                unlikely(sp->add_instr(i)))
4390              MYSQL_YYABORT;
4391            Lex->pop_select(); //main select
4392            if (unlikely(sp->restore_lex(thd)))
4393              MYSQL_YYABORT;
4394          }
4395          sp_proc_stmts1_implicit_block
4396          {
4397            sp_head *sp= Lex->sphead;
4398            sp_pcontext *ctx= Lex->spcont;
4399            uint ip= sp->instructions();
4400            sp_instr_jump *i= new (thd->mem_root) sp_instr_jump(ip, ctx);
4401            if (unlikely(i == NULL) ||
4402                unlikely(sp->add_instr(i)))
4403              MYSQL_YYABORT;
4404            sp->backpatch(ctx->pop_label());
4405            sp->push_backpatch(thd, i, ctx->push_label(thd, &empty_clex_str, 0));
4406          }
4407          sp_elseifs
4408          {
4409            LEX *lex= Lex;
4410
4411            lex->sphead->backpatch(lex->spcont->pop_label());
4412          }
4413        ;
4414
4415sp_elseifs:
4416          /* Empty */
4417        | ELSIF_ORACLE_SYM sp_if
4418        | ELSE sp_proc_stmts1_implicit_block
4419        ;
4420
4421case_stmt_specification:
4422          CASE_SYM
4423          {
4424            if (unlikely(Lex->maybe_start_compound_statement(thd)))
4425              MYSQL_YYABORT;
4426
4427            /**
4428              An example of the CASE statement in use is
4429            <pre>
4430            CREATE PROCEDURE proc_19194_simple(i int)
4431            BEGIN
4432              DECLARE str CHAR(10);
4433
4434              CASE i
4435                WHEN 1 THEN SET str="1";
4436                WHEN 2 THEN SET str="2";
4437                WHEN 3 THEN SET str="3";
4438                ELSE SET str="unknown";
4439              END CASE;
4440
4441              SELECT str;
4442            END
4443            </pre>
4444              The actions are used to generate the following code:
4445            <pre>
4446            SHOW PROCEDURE CODE proc_19194_simple;
4447            Pos     Instruction
4448            0       set str@1 NULL
4449            1       set_case_expr (12) 0 i@0
4450            2       jump_if_not 5(12) (case_expr@0 = 1)
4451            3       set str@1 _latin1'1'
4452            4       jump 12
4453            5       jump_if_not 8(12) (case_expr@0 = 2)
4454            6       set str@1 _latin1'2'
4455            7       jump 12
4456            8       jump_if_not 11(12) (case_expr@0 = 3)
4457            9       set str@1 _latin1'3'
4458            10      jump 12
4459            11      set str@1 _latin1'unknown'
4460            12      stmt 0 "SELECT str"
4461            </pre>
4462            */
4463
4464            Lex->sphead->new_cont_backpatch(NULL);
4465
4466            /*
4467              BACKPATCH: Creating target label for the jump to after END CASE
4468              (instruction 12 in the example)
4469            */
4470            Lex->spcont->push_label(thd, &empty_clex_str, Lex->sphead->instructions());
4471          }
4472          case_stmt_body
4473          else_clause_opt
4474          END
4475          CASE_SYM
4476          {
4477            /*
4478              BACKPATCH: Resolving forward jump from
4479              "case_stmt_action_then" to after END CASE
4480              (jump from instruction 4 to 12, 7 to 12 ... in the example)
4481            */
4482            Lex->sphead->backpatch(Lex->spcont->pop_label());
4483
4484            if ($3)
4485              Lex->spcont->pop_case_expr_id();
4486
4487            Lex->sphead->do_cont_backpatch();
4488          }
4489        ;
4490
4491case_stmt_body:
4492          {
4493            Lex->sphead->reset_lex(thd); /* For expr $2 */
4494            if (Lex->main_select_push(true))
4495              MYSQL_YYABORT;
4496          }
4497          expr
4498          {
4499            if (unlikely(Lex->case_stmt_action_expr($2)))
4500              MYSQL_YYABORT;
4501
4502            Lex->pop_select(); //main select
4503            if (Lex->sphead->restore_lex(thd))
4504              MYSQL_YYABORT;
4505          }
4506          simple_when_clause_list
4507          { $$= 1; }
4508        | searched_when_clause_list
4509          { $$= 0; }
4510        ;
4511
4512simple_when_clause_list:
4513          simple_when_clause
4514        | simple_when_clause_list simple_when_clause
4515        ;
4516
4517searched_when_clause_list:
4518          searched_when_clause
4519        | searched_when_clause_list searched_when_clause
4520        ;
4521
4522simple_when_clause:
4523          WHEN_SYM
4524          {
4525            Lex->sphead->reset_lex(thd); /* For expr $3 */
4526            if (Lex->main_select_push(true))
4527              MYSQL_YYABORT;
4528          }
4529          expr
4530          {
4531            /* Simple case: <caseval> = <whenval> */
4532
4533            LEX *lex= Lex;
4534            if (unlikely(lex->case_stmt_action_when($3, true)))
4535              MYSQL_YYABORT;
4536            Lex->pop_select(); //main select
4537            /* For expr $3 */
4538            if (unlikely(lex->sphead->restore_lex(thd)))
4539              MYSQL_YYABORT;
4540          }
4541          THEN_SYM
4542          sp_proc_stmts1_implicit_block
4543          {
4544            if (unlikely(Lex->case_stmt_action_then()))
4545              MYSQL_YYABORT;
4546          }
4547        ;
4548
4549searched_when_clause:
4550          WHEN_SYM
4551          {
4552            Lex->sphead->reset_lex(thd); /* For expr $3 */
4553            if (Lex->main_select_push(true))
4554              MYSQL_YYABORT;
4555          }
4556          expr
4557          {
4558            LEX *lex= Lex;
4559            if (unlikely(lex->case_stmt_action_when($3, false)))
4560              MYSQL_YYABORT;
4561            Lex->pop_select(); //main select
4562            /* For expr $3 */
4563            if (unlikely(lex->sphead->restore_lex(thd)))
4564              MYSQL_YYABORT;
4565          }
4566          THEN_SYM
4567          sp_proc_stmts1_implicit_block
4568          {
4569            if (unlikely(Lex->case_stmt_action_then()))
4570              MYSQL_YYABORT;
4571          }
4572        ;
4573
4574else_clause_opt:
4575          /* empty */
4576          {
4577            LEX *lex= Lex;
4578            sp_head *sp= lex->sphead;
4579            uint ip= sp->instructions();
4580            sp_instr_error *i= new (thd->mem_root)
4581              sp_instr_error(ip, lex->spcont, ER_SP_CASE_NOT_FOUND);
4582            if (unlikely(i == NULL) ||
4583                unlikely(sp->add_instr(i)))
4584              MYSQL_YYABORT;
4585          }
4586        | ELSE sp_proc_stmts1_implicit_block
4587        ;
4588
4589sp_opt_label:
4590          /* Empty  */  { $$= null_clex_str; }
4591        | label_ident   { $$= $1; }
4592        ;
4593
4594sp_block_label:
4595          labels_declaration_oracle
4596          {
4597            if (unlikely(Lex->spcont->block_label_declare(&$1)))
4598              MYSQL_YYABORT;
4599            $$= $1;
4600          }
4601        ;
4602
4603sp_labeled_block:
4604          sp_block_label
4605          BEGIN_ORACLE_SYM
4606          {
4607            Lex->sp_block_init(thd, &$1);
4608            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
4609              MYSQL_YYABORT;
4610          }
4611          sp_block_statements_and_exceptions
4612          END
4613          sp_opt_label
4614          {
4615            if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4), &$6)))
4616              MYSQL_YYABORT;
4617          }
4618        | sp_block_label
4619          DECLARE_ORACLE_SYM
4620          {
4621            Lex->sp_block_init(thd, &$1);
4622          }
4623          opt_sp_decl_body_list
4624          {
4625            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
4626              MYSQL_YYABORT;
4627          }
4628          BEGIN_ORACLE_SYM
4629          sp_block_statements_and_exceptions
4630          END
4631          sp_opt_label
4632          {
4633            $4.hndlrs+= $7.hndlrs;
4634            if (unlikely(Lex->sp_block_finalize(thd, $4, &$9)))
4635              MYSQL_YYABORT;
4636          }
4637        ;
4638
4639opt_not_atomic:
4640          /* Empty */
4641        | not ATOMIC_SYM /* TODO: BEGIN ATOMIC (not -> opt_not) */
4642        ;
4643
4644sp_unlabeled_block:
4645          BEGIN_ORACLE_SYM opt_not_atomic
4646          {
4647            if (unlikely(Lex->maybe_start_compound_statement(thd)))
4648              MYSQL_YYABORT;
4649            Lex->sp_block_init(thd);
4650            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
4651              MYSQL_YYABORT;
4652          }
4653          sp_block_statements_and_exceptions
4654          END
4655          {
4656            if (unlikely(Lex->sp_block_finalize(thd, Lex_spblock($4))))
4657              MYSQL_YYABORT;
4658          }
4659        | DECLARE_ORACLE_SYM
4660          {
4661            if (unlikely(Lex->maybe_start_compound_statement(thd)))
4662              MYSQL_YYABORT;
4663            Lex->sp_block_init(thd);
4664          }
4665          opt_sp_decl_body_list
4666          {
4667            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
4668              MYSQL_YYABORT;
4669          }
4670          BEGIN_ORACLE_SYM
4671          sp_block_statements_and_exceptions
4672          END
4673          {
4674            $3.hndlrs+= $6.hndlrs;
4675            if (unlikely(Lex->sp_block_finalize(thd, $3)))
4676              MYSQL_YYABORT;
4677          }
4678        ;
4679
4680sp_instr_addr:
4681          { $$= Lex->sphead->instructions(); }
4682        ;
4683
4684sp_body:
4685          {
4686            Lex->sp_block_init(thd);
4687          }
4688          opt_sp_decl_body_list
4689          {
4690            if (unlikely(Lex->sp_block_with_exceptions_finalize_declarations(thd)))
4691              MYSQL_YYABORT;
4692          }
4693          BEGIN_ORACLE_SYM
4694          sp_block_statements_and_exceptions
4695          {
4696            $2.hndlrs+= $5.hndlrs;
4697            if (unlikely(Lex->sp_block_finalize(thd, $2)))
4698              MYSQL_YYABORT;
4699          }
4700          END
4701        ;
4702
4703sp_block_statements_and_exceptions:
4704          sp_instr_addr
4705          sp_proc_stmts
4706          {
4707            if (unlikely(Lex->sp_block_with_exceptions_finalize_executable_section(thd, $1)))
4708              MYSQL_YYABORT;
4709          }
4710          opt_exception_clause
4711          {
4712            if (unlikely(Lex->sp_block_with_exceptions_finalize_exceptions(thd, $1, $4)))
4713              MYSQL_YYABORT;
4714            $$.init($4);
4715          }
4716        ;
4717
4718opt_exception_clause:
4719          /* Empty */                             { $$= 0; }
4720        | EXCEPTION_ORACLE_SYM exception_handlers { $$= $2; }
4721        ;
4722
4723exception_handlers:
4724           exception_handler                    { $$= 1; }
4725         | exception_handlers exception_handler { $$= $1 + 1; }
4726        ;
4727
4728exception_handler:
4729          WHEN_SYM
4730          {
4731            if (unlikely(Lex->sp_handler_declaration_init(thd, sp_handler::EXIT)))
4732              MYSQL_YYABORT;
4733          }
4734          sp_hcond_list
4735          THEN_SYM
4736          sp_proc_stmts1_implicit_block
4737          {
4738            if (unlikely(Lex->sp_handler_declaration_finalize(thd, sp_handler::EXIT)))
4739              MYSQL_YYABORT;
4740          }
4741        ;
4742
4743/* This adds one shift/reduce conflict */
4744opt_sp_for_loop_direction:
4745            /* Empty */ { $$= 1; }
4746          | REVERSE_SYM { $$= -1; }
4747        ;
4748
4749sp_for_loop_index_and_bounds:
4750          ident_directly_assignable
4751          {
4752            if (Lex->main_select_push(true))
4753              MYSQL_YYABORT;
4754          }
4755          sp_for_loop_bounds
4756          {
4757            Lex->pop_select(); //main select
4758            if (unlikely(Lex->sp_for_loop_declarations(thd, &$$, &$1, $3)))
4759              MYSQL_YYABORT;
4760          }
4761        ;
4762
4763sp_for_loop_bounds:
4764          IN_SYM opt_sp_for_loop_direction for_loop_bound_expr
4765          DOT_DOT_SYM for_loop_bound_expr
4766          {
4767            $$= Lex_for_loop_bounds_intrange($2, $3, $5);
4768          }
4769        | IN_SYM opt_sp_for_loop_direction for_loop_bound_expr
4770          {
4771            $$.m_direction= $2;
4772            $$.m_index= $3;
4773            $$.m_target_bound= NULL;
4774            $$.m_implicit_cursor= false;
4775          }
4776        | IN_SYM opt_sp_for_loop_direction '(' sp_cursor_stmt ')'
4777          {
4778            if (unlikely(Lex->sp_for_loop_implicit_cursor_statement(thd, &$$,
4779                                                                    $4)))
4780              MYSQL_YYABORT;
4781          }
4782        ;
4783
4784loop_body:
4785          sp_proc_stmts1 END LOOP_SYM
4786          {
4787            LEX *lex= Lex;
4788            uint ip= lex->sphead->instructions();
4789            sp_label *lab= lex->spcont->last_label();  /* Jumping back */
4790            sp_instr_jump *i= new (thd->mem_root)
4791              sp_instr_jump(ip, lex->spcont, lab->ip);
4792            if (unlikely(i == NULL) ||
4793                unlikely(lex->sphead->add_instr(i)))
4794              MYSQL_YYABORT;
4795          }
4796        ;
4797
4798while_body:
4799          expr LOOP_SYM
4800          {
4801            LEX *lex= Lex;
4802            if (unlikely(lex->sp_while_loop_expression(thd, $1)))
4803              MYSQL_YYABORT;
4804            Lex->pop_select(); //main select
4805            if (lex->sphead->restore_lex(thd))
4806              MYSQL_YYABORT;
4807            if (lex->main_select_push(true))
4808               MYSQL_YYABORT;
4809          }
4810          sp_proc_stmts1 END LOOP_SYM
4811          {
4812            if (unlikely(Lex->sp_while_loop_finalize(thd)))
4813              MYSQL_YYABORT;
4814          }
4815        ;
4816
4817repeat_body:
4818          sp_proc_stmts1 UNTIL_SYM
4819          {
4820            Lex->sphead->reset_lex(thd);
4821            if (Lex->main_select_push(true))
4822              MYSQL_YYABORT;
4823          }
4824          expr END REPEAT_SYM
4825          {
4826            LEX *lex= Lex;
4827            uint ip= lex->sphead->instructions();
4828            sp_label *lab= lex->spcont->last_label();  /* Jumping back */
4829            sp_instr_jump_if_not *i= new (thd->mem_root)
4830              sp_instr_jump_if_not(ip, lex->spcont, $4, lab->ip, lex);
4831            if (unlikely(i == NULL) ||
4832                unlikely(lex->sphead->add_instr(i)))
4833              MYSQL_YYABORT;
4834            Lex->pop_select(); //main select
4835            if (lex->sphead->restore_lex(thd))
4836              MYSQL_YYABORT;
4837            /* We can shortcut the cont_backpatch here */
4838            i->m_cont_dest= ip+1;
4839          }
4840        ;
4841
4842pop_sp_loop_label:
4843          sp_opt_label
4844          {
4845            if (unlikely(Lex->sp_pop_loop_label(thd, &$1)))
4846              MYSQL_YYABORT;
4847          }
4848        ;
4849
4850sp_labeled_control:
4851          labels_declaration_oracle LOOP_SYM
4852          {
4853            if (unlikely(Lex->sp_push_loop_label(thd, &$1)))
4854              MYSQL_YYABORT;
4855          }
4856          loop_body pop_sp_loop_label
4857          { }
4858        | labels_declaration_oracle WHILE_SYM
4859          {
4860            if (unlikely(Lex->sp_push_loop_label(thd, &$1)))
4861              MYSQL_YYABORT;
4862            Lex->sphead->reset_lex(thd);
4863            if (Lex->main_select_push(true))
4864              MYSQL_YYABORT;
4865          }
4866          while_body pop_sp_loop_label
4867          { }
4868        | labels_declaration_oracle FOR_SYM
4869          {
4870            // See "The FOR LOOP statement" comments in sql_lex.cc
4871            Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block
4872          }
4873          sp_for_loop_index_and_bounds
4874          {
4875            if (unlikely(Lex->sp_push_loop_label(thd, &$1))) // The inner WHILE block
4876              MYSQL_YYABORT;
4877            if (unlikely(Lex->sp_for_loop_condition_test(thd, $4)))
4878              MYSQL_YYABORT;
4879          }
4880          LOOP_SYM
4881          sp_proc_stmts1
4882          END LOOP_SYM
4883          {
4884            if (unlikely(Lex->sp_for_loop_finalize(thd, $4)))
4885              MYSQL_YYABORT;
4886          }
4887          pop_sp_loop_label                    // The inner WHILE block
4888          {
4889            if (unlikely(Lex->sp_for_loop_outer_block_finalize(thd, $4)))
4890              MYSQL_YYABORT;
4891          }
4892        | labels_declaration_oracle REPEAT_SYM
4893          {
4894            if (unlikely(Lex->sp_push_loop_label(thd, &$1)))
4895              MYSQL_YYABORT;
4896          }
4897          repeat_body pop_sp_loop_label
4898          { }
4899        ;
4900
4901sp_unlabeled_control:
4902          LOOP_SYM
4903          {
4904            if (unlikely(Lex->sp_push_loop_empty_label(thd)))
4905              MYSQL_YYABORT;
4906          }
4907          loop_body
4908          {
4909            Lex->sp_pop_loop_empty_label(thd);
4910          }
4911        | WHILE_SYM
4912          {
4913            if (unlikely(Lex->sp_push_loop_empty_label(thd)))
4914              MYSQL_YYABORT;
4915            Lex->sphead->reset_lex(thd);
4916            if (Lex->main_select_push(true))
4917              MYSQL_YYABORT;
4918          }
4919          while_body
4920          {
4921            Lex->sp_pop_loop_empty_label(thd);
4922          }
4923        | FOR_SYM
4924          {
4925            // See "The FOR LOOP statement" comments in sql_lex.cc
4926            if (unlikely(Lex->maybe_start_compound_statement(thd)))
4927              MYSQL_YYABORT;
4928            Lex->sp_block_init(thd); // The outer DECLARE..BEGIN..END block
4929          }
4930          sp_for_loop_index_and_bounds
4931          {
4932            if (unlikely(Lex->sp_push_loop_empty_label(thd))) // The inner WHILE block
4933              MYSQL_YYABORT;
4934            if (unlikely(Lex->sp_for_loop_condition_test(thd, $3)))
4935              MYSQL_YYABORT;
4936          }
4937          LOOP_SYM
4938          sp_proc_stmts1
4939          END LOOP_SYM
4940          {
4941            if (unlikely(Lex->sp_for_loop_finalize(thd, $3)))
4942              MYSQL_YYABORT;
4943            Lex->sp_pop_loop_empty_label(thd); // The inner WHILE block
4944            if (unlikely(Lex->sp_for_loop_outer_block_finalize(thd, $3)))
4945              MYSQL_YYABORT;
4946          }
4947        | REPEAT_SYM
4948          {
4949            if (unlikely(Lex->sp_push_loop_empty_label(thd)))
4950              MYSQL_YYABORT;
4951          }
4952          repeat_body
4953          {
4954            Lex->sp_pop_loop_empty_label(thd);
4955          }
4956        ;
4957
4958trg_action_time:
4959            BEFORE_SYM
4960            { Lex->trg_chistics.action_time= TRG_ACTION_BEFORE; }
4961          | AFTER_SYM
4962            { Lex->trg_chistics.action_time= TRG_ACTION_AFTER; }
4963          ;
4964
4965trg_event:
4966            INSERT
4967            { Lex->trg_chistics.event= TRG_EVENT_INSERT; }
4968          | UPDATE_SYM
4969            { Lex->trg_chistics.event= TRG_EVENT_UPDATE; }
4970          | DELETE_SYM
4971            { Lex->trg_chistics.event= TRG_EVENT_DELETE; }
4972          ;
4973/*
4974  This part of the parser contains common code for all TABLESPACE
4975  commands.
4976  CREATE TABLESPACE name ...
4977  ALTER TABLESPACE name CHANGE DATAFILE ...
4978  ALTER TABLESPACE name ADD DATAFILE ...
4979  ALTER TABLESPACE name access_mode
4980  CREATE LOGFILE GROUP_SYM name ...
4981  ALTER LOGFILE GROUP_SYM name ADD UNDOFILE ..
4982  ALTER LOGFILE GROUP_SYM name ADD REDOFILE ..
4983  DROP TABLESPACE name
4984  DROP LOGFILE GROUP_SYM name
4985*/
4986change_tablespace_access:
4987          tablespace_name
4988          ts_access_mode
4989        ;
4990
4991change_tablespace_info:
4992          tablespace_name
4993          CHANGE ts_datafile
4994          change_ts_option_list
4995        ;
4996
4997tablespace_info:
4998          tablespace_name
4999          ADD ts_datafile
5000          opt_logfile_group_name
5001          tablespace_option_list
5002        ;
5003
5004opt_logfile_group_name:
5005          /* empty */ {}
5006        | USE_SYM LOGFILE_SYM GROUP_SYM ident
5007          {
5008            LEX *lex= Lex;
5009            lex->alter_tablespace_info->logfile_group_name= $4.str;
5010          }
5011        ;
5012
5013alter_tablespace_info:
5014          tablespace_name
5015          ADD ts_datafile
5016          alter_tablespace_option_list
5017          {
5018            Lex->alter_tablespace_info->ts_alter_tablespace_type= ALTER_TABLESPACE_ADD_FILE;
5019          }
5020        | tablespace_name
5021          DROP ts_datafile
5022          alter_tablespace_option_list
5023          {
5024            Lex->alter_tablespace_info->ts_alter_tablespace_type= ALTER_TABLESPACE_DROP_FILE;
5025          }
5026        ;
5027
5028logfile_group_info:
5029          logfile_group_name
5030          add_log_file
5031          logfile_group_option_list
5032        ;
5033
5034alter_logfile_group_info:
5035          logfile_group_name
5036          add_log_file
5037          alter_logfile_group_option_list
5038        ;
5039
5040add_log_file:
5041          ADD lg_undofile
5042        | ADD lg_redofile
5043        ;
5044
5045change_ts_option_list:
5046          /* empty */ {}
5047          change_ts_options
5048        ;
5049
5050change_ts_options:
5051          change_ts_option
5052        | change_ts_options change_ts_option
5053        | change_ts_options ',' change_ts_option
5054        ;
5055
5056change_ts_option:
5057          opt_ts_initial_size
5058        | opt_ts_autoextend_size
5059        | opt_ts_max_size
5060        ;
5061
5062tablespace_option_list:
5063        tablespace_options
5064        ;
5065
5066tablespace_options:
5067          tablespace_option
5068        | tablespace_options tablespace_option
5069        | tablespace_options ',' tablespace_option
5070        ;
5071
5072tablespace_option:
5073          opt_ts_initial_size
5074        | opt_ts_autoextend_size
5075        | opt_ts_max_size
5076        | opt_ts_extent_size
5077        | opt_ts_nodegroup
5078        | opt_ts_engine
5079        | ts_wait
5080        | opt_ts_comment
5081        ;
5082
5083alter_tablespace_option_list:
5084        alter_tablespace_options
5085        ;
5086
5087alter_tablespace_options:
5088          alter_tablespace_option
5089        | alter_tablespace_options alter_tablespace_option
5090        | alter_tablespace_options ',' alter_tablespace_option
5091        ;
5092
5093alter_tablespace_option:
5094          opt_ts_initial_size
5095        | opt_ts_autoextend_size
5096        | opt_ts_max_size
5097        | opt_ts_engine
5098        | ts_wait
5099        ;
5100
5101logfile_group_option_list:
5102        logfile_group_options
5103        ;
5104
5105logfile_group_options:
5106          logfile_group_option
5107        | logfile_group_options logfile_group_option
5108        | logfile_group_options ',' logfile_group_option
5109        ;
5110
5111logfile_group_option:
5112          opt_ts_initial_size
5113        | opt_ts_undo_buffer_size
5114        | opt_ts_redo_buffer_size
5115        | opt_ts_nodegroup
5116        | opt_ts_engine
5117        | ts_wait
5118        | opt_ts_comment
5119        ;
5120
5121alter_logfile_group_option_list:
5122          alter_logfile_group_options
5123        ;
5124
5125alter_logfile_group_options:
5126          alter_logfile_group_option
5127        | alter_logfile_group_options alter_logfile_group_option
5128        | alter_logfile_group_options ',' alter_logfile_group_option
5129        ;
5130
5131alter_logfile_group_option:
5132          opt_ts_initial_size
5133        | opt_ts_engine
5134        | ts_wait
5135        ;
5136
5137
5138ts_datafile:
5139          DATAFILE_SYM TEXT_STRING_sys
5140          {
5141            LEX *lex= Lex;
5142            lex->alter_tablespace_info->data_file_name= $2.str;
5143          }
5144        ;
5145
5146lg_undofile:
5147          UNDOFILE_SYM TEXT_STRING_sys
5148          {
5149            LEX *lex= Lex;
5150            lex->alter_tablespace_info->undo_file_name= $2.str;
5151          }
5152        ;
5153
5154lg_redofile:
5155          REDOFILE_SYM TEXT_STRING_sys
5156          {
5157            LEX *lex= Lex;
5158            lex->alter_tablespace_info->redo_file_name= $2.str;
5159          }
5160        ;
5161
5162tablespace_name:
5163          ident
5164          {
5165            LEX *lex= Lex;
5166            lex->alter_tablespace_info= (new (thd->mem_root)
5167                                         st_alter_tablespace());
5168            if (unlikely(lex->alter_tablespace_info == NULL))
5169              MYSQL_YYABORT;
5170            lex->alter_tablespace_info->tablespace_name= $1.str;
5171            lex->sql_command= SQLCOM_ALTER_TABLESPACE;
5172          }
5173        ;
5174
5175logfile_group_name:
5176          ident
5177          {
5178            LEX *lex= Lex;
5179            lex->alter_tablespace_info= (new (thd->mem_root)
5180                                         st_alter_tablespace());
5181            if (unlikely(lex->alter_tablespace_info == NULL))
5182              MYSQL_YYABORT;
5183            lex->alter_tablespace_info->logfile_group_name= $1.str;
5184            lex->sql_command= SQLCOM_ALTER_TABLESPACE;
5185          }
5186        ;
5187
5188ts_access_mode:
5189          READ_ONLY_SYM
5190          {
5191            LEX *lex= Lex;
5192            lex->alter_tablespace_info->ts_access_mode= TS_READ_ONLY;
5193          }
5194        | READ_WRITE_SYM
5195          {
5196            LEX *lex= Lex;
5197            lex->alter_tablespace_info->ts_access_mode= TS_READ_WRITE;
5198          }
5199        | NOT_SYM ACCESSIBLE_SYM
5200          {
5201            LEX *lex= Lex;
5202            lex->alter_tablespace_info->ts_access_mode= TS_NOT_ACCESSIBLE;
5203          }
5204        ;
5205
5206opt_ts_initial_size:
5207          INITIAL_SIZE_SYM opt_equal size_number
5208          {
5209            LEX *lex= Lex;
5210            lex->alter_tablespace_info->initial_size= $3;
5211          }
5212        ;
5213
5214opt_ts_autoextend_size:
5215          AUTOEXTEND_SIZE_SYM opt_equal size_number
5216          {
5217            LEX *lex= Lex;
5218            lex->alter_tablespace_info->autoextend_size= $3;
5219          }
5220        ;
5221
5222opt_ts_max_size:
5223          MAX_SIZE_SYM opt_equal size_number
5224          {
5225            LEX *lex= Lex;
5226            lex->alter_tablespace_info->max_size= $3;
5227          }
5228        ;
5229
5230opt_ts_extent_size:
5231          EXTENT_SIZE_SYM opt_equal size_number
5232          {
5233            LEX *lex= Lex;
5234            lex->alter_tablespace_info->extent_size= $3;
5235          }
5236        ;
5237
5238opt_ts_undo_buffer_size:
5239          UNDO_BUFFER_SIZE_SYM opt_equal size_number
5240          {
5241            LEX *lex= Lex;
5242            lex->alter_tablespace_info->undo_buffer_size= $3;
5243          }
5244        ;
5245
5246opt_ts_redo_buffer_size:
5247          REDO_BUFFER_SIZE_SYM opt_equal size_number
5248          {
5249            LEX *lex= Lex;
5250            lex->alter_tablespace_info->redo_buffer_size= $3;
5251          }
5252        ;
5253
5254opt_ts_nodegroup:
5255          NODEGROUP_SYM opt_equal real_ulong_num
5256          {
5257            LEX *lex= Lex;
5258            if (unlikely(lex->alter_tablespace_info->nodegroup_id != UNDEF_NODEGROUP))
5259              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE,MYF(0),"NODEGROUP"));
5260            lex->alter_tablespace_info->nodegroup_id= $3;
5261          }
5262        ;
5263
5264opt_ts_comment:
5265          COMMENT_SYM opt_equal TEXT_STRING_sys
5266          {
5267            LEX *lex= Lex;
5268            if (unlikely(lex->alter_tablespace_info->ts_comment != NULL))
5269              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE,MYF(0),"COMMENT"));
5270            lex->alter_tablespace_info->ts_comment= $3.str;
5271          }
5272        ;
5273
5274opt_ts_engine:
5275          opt_storage ENGINE_SYM opt_equal storage_engines
5276          {
5277            LEX *lex= Lex;
5278            if (unlikely(lex->alter_tablespace_info->storage_engine != NULL))
5279              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0),
5280                                "STORAGE ENGINE"));
5281            lex->alter_tablespace_info->storage_engine= $4;
5282          }
5283        ;
5284
5285opt_ts_wait:
5286          /* empty */
5287        | ts_wait
5288        ;
5289
5290ts_wait:
5291          WAIT_SYM
5292          {
5293            LEX *lex= Lex;
5294            lex->alter_tablespace_info->wait_until_completed= TRUE;
5295          }
5296        | NO_WAIT_SYM
5297          {
5298            LEX *lex= Lex;
5299            if (unlikely(!(lex->alter_tablespace_info->wait_until_completed)))
5300              my_yyabort_error((ER_FILEGROUP_OPTION_ONLY_ONCE,MYF(0),"NO_WAIT"));
5301            lex->alter_tablespace_info->wait_until_completed= FALSE;
5302          }
5303        ;
5304
5305size_number:
5306          real_ulonglong_num { $$= $1;}
5307        | IDENT_sys
5308          {
5309            if ($1.to_size_number(&$$))
5310              MYSQL_YYABORT;
5311          }
5312        ;
5313
5314/*
5315  End tablespace part
5316*/
5317
5318create_body:
5319          create_field_list_parens
5320          { Lex->create_info.option_list= NULL; }
5321          opt_create_table_options opt_create_partitioning opt_create_select {}
5322        | opt_create_table_options opt_create_partitioning opt_create_select {}
5323        | create_like
5324          {
5325
5326            Lex->create_info.add(DDL_options_st::OPT_LIKE);
5327            TABLE_LIST *src_table= Lex->first_select_lex()->
5328              add_table_to_list(thd, $1, NULL, 0, TL_READ, MDL_SHARED_READ);
5329            if (unlikely(! src_table))
5330              MYSQL_YYABORT;
5331            /* CREATE TABLE ... LIKE is not allowed for views. */
5332            src_table->required_type= TABLE_TYPE_NORMAL;
5333          }
5334        ;
5335
5336create_like:
5337          LIKE table_ident                      { $$= $2; }
5338        | LEFT_PAREN_LIKE LIKE table_ident ')'  { $$= $3; }
5339        ;
5340
5341opt_create_select:
5342          /* empty */ {}
5343        | opt_duplicate opt_as create_select_query_expression
5344        opt_versioning_option
5345          {
5346            if (Lex->check_cte_dependencies_and_resolve_references())
5347              MYSQL_YYABORT;
5348          }
5349        ;
5350
5351create_select_query_expression:
5352          query_expression
5353          {
5354            if (Lex->parsed_insert_select($1->first_select()))
5355              MYSQL_YYABORT;
5356          }
5357        | LEFT_PAREN_WITH with_clause query_expression_no_with_clause ')'
5358          {
5359            SELECT_LEX *first_select= $3->first_select();
5360            $3->set_with_clause($2);
5361            $2->attach_to(first_select);
5362            if (Lex->parsed_insert_select(first_select))
5363              MYSQL_YYABORT;
5364          }
5365        ;
5366
5367opt_create_partitioning:
5368          opt_partitioning
5369          {
5370            /*
5371              Remove all tables used in PARTITION clause from the global table
5372              list. Partitioning with subqueries is not allowed anyway.
5373            */
5374            TABLE_LIST *last_non_sel_table= Lex->create_last_non_select_table;
5375            last_non_sel_table->next_global= 0;
5376            Lex->query_tables_last= &last_non_sel_table->next_global;
5377          }
5378        ;
5379
5380/*
5381 This part of the parser is about handling of the partition information.
5382
5383 It's first version was written by Mikael Ronstrm with lots of answers to
5384 questions provided by Antony Curtis.
5385
5386 The partition grammar can be called from three places.
5387 1) CREATE TABLE ... PARTITION ..
5388 2) ALTER TABLE table_name PARTITION ...
5389 3) PARTITION ...
5390
5391 The first place is called when a new table is created from a MySQL client.
5392 The second place is called when a table is altered with the ALTER TABLE
5393 command from a MySQL client.
5394 The third place is called when opening an frm file and finding partition
5395 info in the .frm file. It is necessary to avoid allowing PARTITION to be
5396 an allowed entry point for SQL client queries. This is arranged by setting
5397 some state variables before arriving here.
5398
5399 To be able to handle errors we will only set error code in this code
5400 and handle the error condition in the function calling the parser. This
5401 is necessary to ensure we can also handle errors when calling the parser
5402 from the openfrm function.
5403*/
5404opt_partitioning:
5405          /* empty */ {}
5406        | partitioning
5407        ;
5408
5409partitioning:
5410          PARTITION_SYM have_partitioning
5411          {
5412            LEX *lex= Lex;
5413            lex->part_info= new (thd->mem_root) partition_info();
5414            if (unlikely(!lex->part_info))
5415              MYSQL_YYABORT;
5416            if (lex->sql_command == SQLCOM_ALTER_TABLE)
5417            {
5418              lex->alter_info.partition_flags|= ALTER_PARTITION_INFO;
5419            }
5420          }
5421          partition
5422        ;
5423
5424have_partitioning:
5425          /* empty */
5426          {
5427#ifdef WITH_PARTITION_STORAGE_ENGINE
5428            LEX_CSTRING partition_name={STRING_WITH_LEN("partition")};
5429            if (unlikely(!plugin_is_ready(&partition_name, MYSQL_STORAGE_ENGINE_PLUGIN)))
5430              my_yyabort_error((ER_OPTION_PREVENTS_STATEMENT, MYF(0),
5431                                "--skip-partition"));
5432#else
5433            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), "partitioning",
5434                              "--with-plugin-partition"));
5435#endif
5436          }
5437        ;
5438
5439partition_entry:
5440          PARTITION_SYM
5441          {
5442            if (unlikely(!Lex->part_info))
5443            {
5444              thd->parse_error(ER_PARTITION_ENTRY_ERROR);
5445              MYSQL_YYABORT;
5446            }
5447            DBUG_ASSERT(Lex->part_info->table);
5448            /*
5449              We enter here when opening the frm file to translate
5450              partition info string into part_info data structure.
5451            */
5452            if (Lex->main_select_push())
5453              MYSQL_YYABORT;
5454          }
5455          partition
5456          {
5457            Lex->pop_select(); //main select
5458          }
5459        ;
5460
5461partition:
5462          BY
5463	  { Lex->safe_to_cache_query= 1; }
5464	   part_type_def opt_num_parts opt_sub_part part_defs
5465        ;
5466
5467part_type_def:
5468          opt_linear KEY_SYM opt_key_algo '(' part_field_list ')'
5469          {
5470            partition_info *part_info= Lex->part_info;
5471            part_info->list_of_part_fields= TRUE;
5472            part_info->column_list= FALSE;
5473            part_info->part_type= HASH_PARTITION;
5474          }
5475        | opt_linear HASH_SYM
5476          { Lex->part_info->part_type= HASH_PARTITION; }
5477          part_func {}
5478        | RANGE_SYM part_func
5479          { Lex->part_info->part_type= RANGE_PARTITION; }
5480        | RANGE_SYM part_column_list
5481          { Lex->part_info->part_type= RANGE_PARTITION; }
5482        | LIST_SYM
5483	  {
5484	    Select->parsing_place= IN_PART_FUNC;
5485          }
5486          part_func
5487          {
5488	    Lex->part_info->part_type= LIST_PARTITION;
5489	    Select->parsing_place= NO_MATTER;
5490	  }
5491        | LIST_SYM part_column_list
5492          { Lex->part_info->part_type= LIST_PARTITION; }
5493        | SYSTEM_TIME_SYM
5494          {
5495             if (unlikely(Lex->part_info->vers_init_info(thd)))
5496               MYSQL_YYABORT;
5497          }
5498          opt_versioning_rotation
5499        ;
5500
5501opt_linear:
5502          /* empty */ {}
5503        | LINEAR_SYM
5504          { Lex->part_info->linear_hash_ind= TRUE;}
5505        ;
5506
5507opt_key_algo:
5508          /* empty */
5509          { Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_NONE;}
5510        | ALGORITHM_SYM '=' real_ulong_num
5511          {
5512            switch ($3) {
5513            case 1:
5514              Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_51;
5515              break;
5516            case 2:
5517              Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_55;
5518              break;
5519            default:
5520              thd->parse_error();
5521              MYSQL_YYABORT;
5522            }
5523          }
5524        ;
5525
5526part_field_list:
5527          /* empty */ {}
5528        | part_field_item_list {}
5529        ;
5530
5531part_field_item_list:
5532          part_field_item {}
5533        | part_field_item_list ',' part_field_item {}
5534        ;
5535
5536part_field_item:
5537          ident
5538          {
5539            partition_info *part_info= Lex->part_info;
5540            part_info->num_columns++;
5541            if (unlikely(part_info->part_field_list.push_back($1.str,
5542                         thd->mem_root)))
5543              MYSQL_YYABORT;
5544            if (unlikely(part_info->num_columns > MAX_REF_PARTS))
5545              my_yyabort_error((ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0),
5546                                "list of partition fields"));
5547          }
5548        ;
5549
5550part_column_list:
5551          COLUMNS '(' part_field_list ')'
5552          {
5553            partition_info *part_info= Lex->part_info;
5554            part_info->column_list= TRUE;
5555            part_info->list_of_part_fields= TRUE;
5556          }
5557        ;
5558
5559
5560part_func:
5561          '(' part_func_expr ')'
5562          {
5563            partition_info *part_info= Lex->part_info;
5564            if (unlikely(part_info->set_part_expr(thd, $2, FALSE)))
5565              MYSQL_YYABORT;
5566            part_info->num_columns= 1;
5567            part_info->column_list= FALSE;
5568          }
5569        ;
5570
5571sub_part_func:
5572          '(' part_func_expr ')'
5573          {
5574            if (unlikely(Lex->part_info->set_part_expr(thd, $2, TRUE)))
5575              MYSQL_YYABORT;
5576          }
5577        ;
5578
5579
5580opt_num_parts:
5581          /* empty */ {}
5582        | PARTITIONS_SYM real_ulong_num
5583          {
5584            uint num_parts= $2;
5585            partition_info *part_info= Lex->part_info;
5586            if (unlikely(num_parts == 0))
5587              my_yyabort_error((ER_NO_PARTS_ERROR, MYF(0), "partitions"));
5588
5589            part_info->num_parts= num_parts;
5590            part_info->use_default_num_partitions= FALSE;
5591          }
5592        ;
5593
5594opt_sub_part:
5595          /* empty */ {}
5596        | SUBPARTITION_SYM BY opt_linear HASH_SYM sub_part_func
5597          { Lex->part_info->subpart_type= HASH_PARTITION; }
5598          opt_num_subparts {}
5599        | SUBPARTITION_SYM BY opt_linear KEY_SYM opt_key_algo
5600          '(' sub_part_field_list ')'
5601          {
5602            partition_info *part_info= Lex->part_info;
5603            part_info->subpart_type= HASH_PARTITION;
5604            part_info->list_of_subpart_fields= TRUE;
5605          }
5606          opt_num_subparts {}
5607        ;
5608
5609sub_part_field_list:
5610          sub_part_field_item {}
5611        | sub_part_field_list ',' sub_part_field_item {}
5612        ;
5613
5614sub_part_field_item:
5615          ident
5616          {
5617            partition_info *part_info= Lex->part_info;
5618            if (unlikely(part_info->subpart_field_list.push_back($1.str,
5619                         thd->mem_root)))
5620              MYSQL_YYABORT;
5621
5622            if (unlikely(part_info->subpart_field_list.elements > MAX_REF_PARTS))
5623              my_yyabort_error((ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0),
5624                                "list of subpartition fields"));
5625          }
5626        ;
5627
5628part_func_expr:
5629          bit_expr
5630          {
5631            if (unlikely(!Lex->safe_to_cache_query))
5632            {
5633              thd->parse_error(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR);
5634              MYSQL_YYABORT;
5635            }
5636            $$=$1;
5637          }
5638        ;
5639
5640opt_num_subparts:
5641          /* empty */ {}
5642        | SUBPARTITIONS_SYM real_ulong_num
5643          {
5644            uint num_parts= $2;
5645            LEX *lex= Lex;
5646            if (unlikely(num_parts == 0))
5647              my_yyabort_error((ER_NO_PARTS_ERROR, MYF(0), "subpartitions"));
5648            lex->part_info->num_subparts= num_parts;
5649            lex->part_info->use_default_num_subpartitions= FALSE;
5650          }
5651        ;
5652
5653part_defs:
5654          /* empty */
5655          {
5656            partition_info *part_info= Lex->part_info;
5657            if (unlikely(part_info->part_type == RANGE_PARTITION))
5658              my_yyabort_error((ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0),
5659                                "RANGE"));
5660            if (unlikely(part_info->part_type == LIST_PARTITION))
5661              my_yyabort_error((ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0),
5662                                "LIST"));
5663          }
5664        | '(' part_def_list ')'
5665          {
5666            partition_info *part_info= Lex->part_info;
5667            uint count_curr_parts= part_info->partitions.elements;
5668            if (part_info->num_parts != 0)
5669            {
5670              if (unlikely(part_info->num_parts !=
5671                           count_curr_parts))
5672              {
5673                thd->parse_error(ER_PARTITION_WRONG_NO_PART_ERROR);
5674                MYSQL_YYABORT;
5675              }
5676            }
5677            else if (count_curr_parts > 0)
5678            {
5679              part_info->num_parts= count_curr_parts;
5680            }
5681            part_info->count_curr_subparts= 0;
5682          }
5683        ;
5684
5685part_def_list:
5686          part_definition {}
5687        | part_def_list ',' part_definition {}
5688        ;
5689
5690part_definition:
5691          PARTITION_SYM
5692          {
5693            partition_info *part_info= Lex->part_info;
5694            partition_element *p_elem= new (thd->mem_root) partition_element();
5695
5696            if (unlikely(!p_elem) ||
5697                unlikely(part_info->partitions.push_back(p_elem, thd->mem_root)))
5698              MYSQL_YYABORT;
5699
5700            p_elem->part_state= PART_NORMAL;
5701            p_elem->id= part_info->partitions.elements - 1;
5702            part_info->curr_part_elem= p_elem;
5703            part_info->current_partition= p_elem;
5704            part_info->use_default_partitions= FALSE;
5705            part_info->use_default_num_partitions= FALSE;
5706          }
5707          part_name
5708          opt_part_values
5709          opt_part_options
5710          opt_sub_partition
5711          {}
5712        ;
5713
5714part_name:
5715          ident
5716          {
5717            partition_info *part_info= Lex->part_info;
5718            partition_element *p_elem= part_info->curr_part_elem;
5719            if (unlikely(check_ident_length(&$1)))
5720              MYSQL_YYABORT;
5721            p_elem->partition_name= $1.str;
5722          }
5723        ;
5724
5725opt_part_values:
5726          /* empty */
5727          {
5728            LEX *lex= Lex;
5729            partition_info *part_info= lex->part_info;
5730            if (! lex->is_partition_management())
5731            {
5732              if (unlikely(part_info->error_if_requires_values()))
5733                MYSQL_YYABORT;
5734              if (unlikely(part_info->part_type == VERSIONING_PARTITION))
5735                my_yyabort_error((ER_VERS_WRONG_PARTS, MYF(0),
5736                                  lex->create_last_non_select_table->
5737                                  table_name.str));
5738            }
5739            else
5740              part_info->part_type= HASH_PARTITION;
5741          }
5742        | VALUES_LESS_SYM THAN_SYM
5743          {
5744            LEX *lex= Lex;
5745            partition_info *part_info= lex->part_info;
5746            if (! lex->is_partition_management())
5747            {
5748              if (unlikely(part_info->part_type != RANGE_PARTITION))
5749                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
5750                                  "RANGE", "LESS THAN"));
5751            }
5752            else
5753              part_info->part_type= RANGE_PARTITION;
5754          }
5755          part_func_max {}
5756        | VALUES_IN_SYM
5757          {
5758            LEX *lex= Lex;
5759            partition_info *part_info= lex->part_info;
5760            if (! lex->is_partition_management())
5761            {
5762              if (unlikely(part_info->part_type != LIST_PARTITION))
5763                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
5764                                  "LIST", "IN"));
5765            }
5766            else
5767              part_info->part_type= LIST_PARTITION;
5768          }
5769          part_values_in {}
5770        | CURRENT_SYM
5771          {
5772            if (Lex->part_values_current(thd))
5773              MYSQL_YYABORT;
5774          }
5775        | HISTORY_SYM
5776          {
5777            if (Lex->part_values_history(thd))
5778              MYSQL_YYABORT;
5779          }
5780        | DEFAULT
5781         {
5782            LEX *lex= Lex;
5783            partition_info *part_info= lex->part_info;
5784            if (! lex->is_partition_management())
5785            {
5786              if (unlikely(part_info->part_type != LIST_PARTITION))
5787                my_yyabort_error((ER_PARTITION_WRONG_VALUES_ERROR, MYF(0),
5788                                  "LIST", "DEFAULT"));
5789            }
5790            else
5791              part_info->part_type= LIST_PARTITION;
5792            if (unlikely(part_info->init_column_part(thd)))
5793              MYSQL_YYABORT;
5794            if (unlikely(part_info->add_max_value(thd)))
5795              MYSQL_YYABORT;
5796         }
5797        ;
5798
5799part_func_max:
5800          MAXVALUE_SYM
5801          {
5802            partition_info *part_info= Lex->part_info;
5803
5804            if (unlikely(part_info->num_columns &&
5805                         part_info->num_columns != 1U))
5806            {
5807              part_info->print_debug("Kilroy II", NULL);
5808              thd->parse_error(ER_PARTITION_COLUMN_LIST_ERROR);
5809              MYSQL_YYABORT;
5810            }
5811            else
5812              part_info->num_columns= 1U;
5813            if (unlikely(part_info->init_column_part(thd)))
5814              MYSQL_YYABORT;
5815            if (unlikely(part_info->add_max_value(thd)))
5816              MYSQL_YYABORT;
5817          }
5818        | part_value_item {}
5819        ;
5820
5821part_values_in:
5822          part_value_item
5823          {
5824            LEX *lex= Lex;
5825            partition_info *part_info= lex->part_info;
5826            part_info->print_debug("part_values_in: part_value_item", NULL);
5827
5828            if (part_info->num_columns != 1U)
5829            {
5830              if (unlikely(!lex->is_partition_management() ||
5831                           part_info->num_columns == 0 ||
5832                           part_info->num_columns > MAX_REF_PARTS))
5833              {
5834                part_info->print_debug("Kilroy III", NULL);
5835                thd->parse_error(ER_PARTITION_COLUMN_LIST_ERROR);
5836                MYSQL_YYABORT;
5837              }
5838              /*
5839                Reorganize the current large array into a list of small
5840                arrays with one entry in each array. This can happen
5841                in the first partition of an ALTER TABLE statement where
5842                we ADD or REORGANIZE partitions. Also can only happen
5843                for LIST partitions.
5844              */
5845              if (unlikely(part_info->reorganize_into_single_field_col_val(thd)))
5846                MYSQL_YYABORT;
5847            }
5848          }
5849        | '(' part_value_list ')'
5850          {
5851            partition_info *part_info= Lex->part_info;
5852            if (unlikely(part_info->num_columns < 2U))
5853            {
5854              thd->parse_error(ER_ROW_SINGLE_PARTITION_FIELD_ERROR);
5855              MYSQL_YYABORT;
5856            }
5857          }
5858        ;
5859
5860part_value_list:
5861          part_value_item {}
5862        | part_value_list ',' part_value_item {}
5863        ;
5864
5865part_value_item:
5866          '('
5867          {
5868            partition_info *part_info= Lex->part_info;
5869            part_info->print_debug("( part_value_item", NULL);
5870            /* Initialisation code needed for each list of value expressions */
5871            if (unlikely(!(part_info->part_type == LIST_PARTITION &&
5872                           part_info->num_columns == 1U) &&
5873                           part_info->init_column_part(thd)))
5874              MYSQL_YYABORT;
5875          }
5876          part_value_item_list {}
5877          ')'
5878          {
5879            partition_info *part_info= Lex->part_info;
5880            part_info->print_debug(") part_value_item", NULL);
5881            if (part_info->num_columns == 0)
5882              part_info->num_columns= part_info->curr_list_object;
5883            if (unlikely(part_info->num_columns != part_info->curr_list_object))
5884            {
5885              /*
5886                All value items lists must be of equal length, in some cases
5887                which is covered by the above if-statement we don't know yet
5888                how many columns is in the partition so the assignment above
5889                ensures that we only report errors when we know we have an
5890                error.
5891              */
5892              part_info->print_debug("Kilroy I", NULL);
5893              thd->parse_error(ER_PARTITION_COLUMN_LIST_ERROR);
5894              MYSQL_YYABORT;
5895            }
5896            part_info->curr_list_object= 0;
5897          }
5898        ;
5899
5900part_value_item_list:
5901          part_value_expr_item {}
5902        | part_value_item_list ',' part_value_expr_item {}
5903        ;
5904
5905part_value_expr_item:
5906          MAXVALUE_SYM
5907          {
5908            partition_info *part_info= Lex->part_info;
5909            if (unlikely(part_info->part_type == LIST_PARTITION))
5910            {
5911              thd->parse_error(ER_MAXVALUE_IN_VALUES_IN);
5912              MYSQL_YYABORT;
5913            }
5914            if (unlikely(part_info->add_max_value(thd)))
5915              MYSQL_YYABORT;
5916          }
5917        | bit_expr
5918          {
5919            LEX *lex= Lex;
5920            partition_info *part_info= lex->part_info;
5921            Item *part_expr= $1;
5922
5923            if (unlikely(!lex->safe_to_cache_query))
5924            {
5925              thd->parse_error(ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR);
5926              MYSQL_YYABORT;
5927            }
5928            if (unlikely(part_info->add_column_list_value(thd, part_expr)))
5929              MYSQL_YYABORT;
5930          }
5931        ;
5932
5933
5934opt_sub_partition:
5935          /* empty */
5936          {
5937            partition_info *part_info= Lex->part_info;
5938            if (unlikely(part_info->num_subparts != 0 &&
5939                         !part_info->use_default_subpartitions))
5940            {
5941              /*
5942                We come here when we have defined subpartitions on the first
5943                partition but not on all the subsequent partitions.
5944              */
5945              thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5946              MYSQL_YYABORT;
5947            }
5948          }
5949        | '(' sub_part_list ')'
5950          {
5951            partition_info *part_info= Lex->part_info;
5952            if (part_info->num_subparts != 0)
5953            {
5954              if (unlikely(part_info->num_subparts !=
5955                           part_info->count_curr_subparts))
5956              {
5957                thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5958                MYSQL_YYABORT;
5959              }
5960            }
5961            else if (part_info->count_curr_subparts > 0)
5962            {
5963              if (unlikely(part_info->partitions.elements > 1))
5964              {
5965                thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
5966                MYSQL_YYABORT;
5967              }
5968              part_info->num_subparts= part_info->count_curr_subparts;
5969            }
5970            part_info->count_curr_subparts= 0;
5971          }
5972        ;
5973
5974sub_part_list:
5975          sub_part_definition {}
5976        | sub_part_list ',' sub_part_definition {}
5977        ;
5978
5979sub_part_definition:
5980          SUBPARTITION_SYM
5981          {
5982            partition_info *part_info= Lex->part_info;
5983            partition_element *curr_part= part_info->current_partition;
5984            partition_element *sub_p_elem= new (thd->mem_root)
5985                                           partition_element(curr_part);
5986            if (unlikely(part_info->use_default_subpartitions &&
5987                         part_info->partitions.elements >= 2))
5988            {
5989              /*
5990                create table t1 (a int)
5991                partition by list (a) subpartition by hash (a)
5992                (partition p0 values in (1),
5993                 partition p1 values in (2) subpartition sp11);
5994                causes use to arrive since we are on the second
5995                partition, but still use_default_subpartitions
5996                is set. When we come here we're processing at least
5997                the second partition (the current partition processed
5998                have already been put into the partitions list.
5999              */
6000              thd->parse_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR);
6001              MYSQL_YYABORT;
6002            }
6003            if (unlikely(!sub_p_elem) ||
6004                unlikely(curr_part->subpartitions.push_back(sub_p_elem, thd->mem_root)))
6005              MYSQL_YYABORT;
6006
6007            sub_p_elem->id= curr_part->subpartitions.elements - 1;
6008            part_info->curr_part_elem= sub_p_elem;
6009            part_info->use_default_subpartitions= FALSE;
6010            part_info->use_default_num_subpartitions= FALSE;
6011            part_info->count_curr_subparts++;
6012          }
6013          sub_name opt_part_options {}
6014        ;
6015
6016sub_name:
6017          ident_or_text
6018          {
6019            if (unlikely(check_ident_length(&$1)))
6020              MYSQL_YYABORT;
6021            Lex->part_info->curr_part_elem->partition_name= $1.str;
6022          }
6023        ;
6024
6025opt_part_options:
6026         /* empty */ {}
6027       | opt_part_option_list {}
6028       ;
6029
6030opt_part_option_list:
6031         opt_part_option_list opt_part_option {}
6032       | opt_part_option {}
6033       ;
6034
6035opt_part_option:
6036          TABLESPACE opt_equal ident_or_text
6037          { Lex->part_info->curr_part_elem->tablespace_name= $3.str; }
6038        | opt_storage ENGINE_SYM opt_equal storage_engines
6039          {
6040            partition_info *part_info= Lex->part_info;
6041            part_info->curr_part_elem->engine_type= $4;
6042            part_info->default_engine_type= $4;
6043          }
6044        | CONNECTION_SYM opt_equal TEXT_STRING_sys
6045          {
6046            LEX *lex= Lex;
6047            lex->part_info->curr_part_elem->connect_string.str= $3.str;
6048            lex->part_info->curr_part_elem->connect_string.length= $3.length;
6049          }
6050        | NODEGROUP_SYM opt_equal real_ulong_num
6051          { Lex->part_info->curr_part_elem->nodegroup_id= (uint16) $3; }
6052        | MAX_ROWS opt_equal real_ulonglong_num
6053          { Lex->part_info->curr_part_elem->part_max_rows= (ha_rows) $3; }
6054        | MIN_ROWS opt_equal real_ulonglong_num
6055          { Lex->part_info->curr_part_elem->part_min_rows= (ha_rows) $3; }
6056        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
6057          { Lex->part_info->curr_part_elem->data_file_name= $4.str; }
6058        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
6059          { Lex->part_info->curr_part_elem->index_file_name= $4.str; }
6060        | COMMENT_SYM opt_equal TEXT_STRING_sys
6061          { Lex->part_info->curr_part_elem->part_comment= $3.str; }
6062        ;
6063
6064opt_versioning_rotation:
6065         /* empty */ {}
6066       | INTERVAL_SYM expr interval opt_versioning_interval_start
6067         {
6068           partition_info *part_info= Lex->part_info;
6069           if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4)))
6070             MYSQL_YYABORT;
6071         }
6072       | LIMIT ulonglong_num
6073       {
6074         partition_info *part_info= Lex->part_info;
6075         if (unlikely(part_info->vers_set_limit($2)))
6076         {
6077           my_error(ER_PART_WRONG_VALUE, MYF(0),
6078                    Lex->create_last_non_select_table->table_name.str,
6079                    "LIMIT");
6080           MYSQL_YYABORT;
6081         }
6082       }
6083       ;
6084
6085
6086opt_versioning_interval_start:
6087         /* empty */
6088         {
6089           $$= thd->query_start();
6090         }
6091       | STARTS_SYM ulong_num
6092         {
6093           /* only allowed from mysql_unpack_partition() */
6094           if (unlikely(!Lex->part_info->table))
6095           {
6096             thd->parse_error(ER_SYNTAX_ERROR, $1.pos());
6097             MYSQL_YYABORT;
6098           }
6099           $$= (ulong)$2;
6100         }
6101       ;
6102
6103/*
6104 End of partition parser part
6105*/
6106
6107opt_as:
6108          /* empty */ {}
6109        | AS {}
6110        ;
6111
6112opt_create_database_options:
6113          /* empty */ {}
6114        | create_database_options {}
6115        ;
6116
6117create_database_options:
6118          create_database_option {}
6119        | create_database_options create_database_option {}
6120        ;
6121
6122create_database_option:
6123          default_collation {}
6124        | default_charset {}
6125        ;
6126
6127opt_if_not_exists_table_element:
6128          /* empty */
6129          {
6130            Lex->check_exists= FALSE;
6131          }
6132        | IF_SYM not EXISTS
6133          {
6134            Lex->check_exists= TRUE;
6135          }
6136         ;
6137
6138opt_if_not_exists:
6139          /* empty */
6140          {
6141            $$.init();
6142          }
6143        | IF_SYM not EXISTS
6144          {
6145            $$.set(DDL_options_st::OPT_IF_NOT_EXISTS);
6146          }
6147         ;
6148
6149create_or_replace:
6150          CREATE /* empty */
6151          {
6152            $$.init();
6153          }
6154        | CREATE OR_SYM REPLACE
6155          {
6156            $$.set(DDL_options_st::OPT_OR_REPLACE);
6157          }
6158         ;
6159
6160opt_create_table_options:
6161          /* empty */
6162        | create_table_options
6163        ;
6164
6165create_table_options_space_separated:
6166          create_table_option
6167        | create_table_option create_table_options_space_separated
6168        ;
6169
6170create_table_options:
6171          create_table_option
6172        | create_table_option     create_table_options
6173        | create_table_option ',' create_table_options
6174        ;
6175
6176create_table_option:
6177          ENGINE_SYM opt_equal ident_or_text
6178          {
6179            LEX *lex= Lex;
6180            if (!lex->m_sql_cmd)
6181            {
6182              DBUG_ASSERT(lex->sql_command == SQLCOM_ALTER_TABLE);
6183              if (!(lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_table()))
6184                MYSQL_YYABORT;
6185            }
6186            Storage_engine_name *opt=
6187              lex->m_sql_cmd->option_storage_engine_name();
6188            DBUG_ASSERT(opt); // Expect a proper Sql_cmd
6189            *opt= Storage_engine_name($3);
6190            lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
6191          }
6192        | MAX_ROWS opt_equal ulonglong_num
6193          {
6194            Lex->create_info.max_rows= $3;
6195            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
6196          }
6197        | MIN_ROWS opt_equal ulonglong_num
6198          {
6199            Lex->create_info.min_rows= $3;
6200            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
6201          }
6202        | AVG_ROW_LENGTH opt_equal ulong_num
6203          {
6204            Lex->create_info.avg_row_length=$3;
6205            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
6206          }
6207        | PASSWORD_SYM opt_equal TEXT_STRING_sys
6208          {
6209            Lex->create_info.password=$3.str;
6210            Lex->create_info.used_fields|= HA_CREATE_USED_PASSWORD;
6211          }
6212        | COMMENT_SYM opt_equal TEXT_STRING_sys
6213          {
6214            Lex->create_info.comment=$3;
6215            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
6216          }
6217        | AUTO_INC opt_equal ulonglong_num
6218          {
6219            Lex->create_info.auto_increment_value=$3;
6220            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
6221          }
6222        | PACK_KEYS_SYM opt_equal ulong_num
6223          {
6224            switch($3) {
6225            case 0:
6226                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
6227                break;
6228            case 1:
6229                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
6230                break;
6231            default:
6232                thd->parse_error();
6233                MYSQL_YYABORT;
6234            }
6235            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
6236          }
6237        | PACK_KEYS_SYM opt_equal DEFAULT
6238          {
6239            Lex->create_info.table_options&=
6240              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
6241            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
6242          }
6243        | STATS_AUTO_RECALC_SYM opt_equal ulong_num
6244          {
6245            switch($3) {
6246            case 0:
6247                Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_OFF;
6248                break;
6249            case 1:
6250                Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_ON;
6251                break;
6252            default:
6253                thd->parse_error();
6254                MYSQL_YYABORT;
6255            }
6256            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_AUTO_RECALC;
6257          }
6258        | STATS_AUTO_RECALC_SYM opt_equal DEFAULT
6259          {
6260            Lex->create_info.stats_auto_recalc= HA_STATS_AUTO_RECALC_DEFAULT;
6261            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_AUTO_RECALC;
6262          }
6263        | STATS_PERSISTENT_SYM opt_equal ulong_num
6264          {
6265            switch($3) {
6266            case 0:
6267                Lex->create_info.table_options|= HA_OPTION_NO_STATS_PERSISTENT;
6268                break;
6269            case 1:
6270                Lex->create_info.table_options|= HA_OPTION_STATS_PERSISTENT;
6271                break;
6272            default:
6273                thd->parse_error();
6274                MYSQL_YYABORT;
6275            }
6276            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_PERSISTENT;
6277          }
6278        | STATS_PERSISTENT_SYM opt_equal DEFAULT
6279          {
6280            Lex->create_info.table_options&=
6281              ~(HA_OPTION_STATS_PERSISTENT | HA_OPTION_NO_STATS_PERSISTENT);
6282            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_PERSISTENT;
6283          }
6284        | STATS_SAMPLE_PAGES_SYM opt_equal ulong_num
6285          {
6286            /* From user point of view STATS_SAMPLE_PAGES can be specified as
6287            STATS_SAMPLE_PAGES=N (where 0<N<=65535, it does not make sense to
6288            scan 0 pages) or STATS_SAMPLE_PAGES=default. Internally we record
6289            =default as 0. See create_frm() in sql/table.cc, we use only two
6290            bytes for stats_sample_pages and this is why we do not allow
6291            larger values. 65535 pages, 16kb each means to sample 1GB, which
6292            is impractical. If at some point this needs to be extended, then
6293            we can store the higher bits from stats_sample_pages in .frm too. */
6294            if (unlikely($3 == 0 || $3 > 0xffff))
6295            {
6296              thd->parse_error();
6297              MYSQL_YYABORT;
6298            }
6299            Lex->create_info.stats_sample_pages=$3;
6300            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_SAMPLE_PAGES;
6301          }
6302        | STATS_SAMPLE_PAGES_SYM opt_equal DEFAULT
6303          {
6304            Lex->create_info.stats_sample_pages=0;
6305            Lex->create_info.used_fields|= HA_CREATE_USED_STATS_SAMPLE_PAGES;
6306          }
6307        | CHECKSUM_SYM opt_equal ulong_num
6308          {
6309            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
6310            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
6311          }
6312        | TABLE_CHECKSUM_SYM opt_equal ulong_num
6313          {
6314             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
6315             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
6316          }
6317        | PAGE_CHECKSUM_SYM opt_equal choice
6318          {
6319            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
6320            Lex->create_info.page_checksum= $3;
6321          }
6322        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
6323          {
6324            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
6325            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
6326          }
6327        | ROW_FORMAT_SYM opt_equal row_types
6328          {
6329            Lex->create_info.row_type= $3;
6330            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
6331          }
6332        | UNION_SYM opt_equal
6333          {
6334            Lex->first_select_lex()->table_list.save_and_clear(&Lex->save_list);
6335          }
6336          '(' opt_table_list ')'
6337          {
6338            /*
6339              Move the union list to the merge_list and exclude its tables
6340              from the global list.
6341            */
6342            LEX *lex=Lex;
6343            lex->create_info.merge_list= lex->first_select_lex()->table_list.first;
6344            lex->first_select_lex()->table_list= lex->save_list;
6345            /*
6346              When excluding union list from the global list we assume that
6347              elements of the former immediately follow elements which represent
6348              table being created/altered and parent tables.
6349            */
6350            TABLE_LIST *last_non_sel_table= lex->create_last_non_select_table;
6351            DBUG_ASSERT(last_non_sel_table->next_global ==
6352                        lex->create_info.merge_list);
6353            last_non_sel_table->next_global= 0;
6354            Lex->query_tables_last= &last_non_sel_table->next_global;
6355
6356            lex->create_info.used_fields|= HA_CREATE_USED_UNION;
6357          }
6358        | default_charset
6359        | default_collation
6360        | INSERT_METHOD opt_equal merge_insert_types
6361          {
6362            Lex->create_info.merge_insert_method= $3;
6363            Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;
6364          }
6365        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
6366          {
6367            Lex->create_info.data_file_name= $4.str;
6368            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
6369          }
6370        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
6371          {
6372            Lex->create_info.index_file_name= $4.str;
6373            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
6374          }
6375        | TABLESPACE ident
6376          {Lex->create_info.tablespace= $2.str;}
6377        | STORAGE_SYM DISK_SYM
6378          {Lex->create_info.storage_media= HA_SM_DISK;}
6379        | STORAGE_SYM MEMORY_SYM
6380          {Lex->create_info.storage_media= HA_SM_MEMORY;}
6381        | CONNECTION_SYM opt_equal TEXT_STRING_sys
6382          {
6383            Lex->create_info.connect_string.str= $3.str;
6384            Lex->create_info.connect_string.length= $3.length;
6385            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
6386          }
6387        | KEY_BLOCK_SIZE opt_equal ulong_num
6388          {
6389            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
6390            Lex->create_info.key_block_size= $3;
6391          }
6392        | TRANSACTIONAL_SYM opt_equal choice
6393          {
6394	    Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
6395            Lex->create_info.transactional= $3;
6396          }
6397        | IDENT_sys equal TEXT_STRING_sys
6398          {
6399            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
6400              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
6401            (void) new (thd->mem_root)
6402                   engine_option_value($1, $3, true,
6403                                       &Lex->create_info.option_list,
6404                                       &Lex->option_list_last);
6405          }
6406        | IDENT_sys equal ident
6407          {
6408            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
6409              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
6410            (void) new (thd->mem_root)
6411                   engine_option_value($1, $3, false,
6412                                       &Lex->create_info.option_list,
6413                                       &Lex->option_list_last);
6414          }
6415        | IDENT_sys equal real_ulonglong_num
6416          {
6417            (void) new (thd->mem_root)
6418                   engine_option_value($1, $3, &Lex->create_info.option_list,
6419                                       &Lex->option_list_last, thd->mem_root);
6420          }
6421        | IDENT_sys equal DEFAULT
6422          {
6423            (void) new (thd->mem_root)
6424                   engine_option_value($1, &Lex->create_info.option_list,
6425                                       &Lex->option_list_last);
6426          }
6427        | SEQUENCE_SYM opt_equal choice
6428          {
6429	    Lex->create_info.used_fields|= HA_CREATE_USED_SEQUENCE;
6430            Lex->create_info.sequence= ($3 == HA_CHOICE_YES);
6431	  }
6432        | versioning_option
6433        ;
6434
6435opt_versioning_option:
6436          /* empty */
6437        | versioning_option
6438        ;
6439
6440versioning_option:
6441        WITH_SYSTEM_SYM VERSIONING_SYM
6442          {
6443            if (unlikely(Lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
6444            {
6445              if (DBUG_EVALUATE_IF("sysvers_force", 0, 1))
6446              {
6447                my_error(ER_VERS_NOT_SUPPORTED, MYF(0), "CREATE TEMPORARY TABLE");
6448                MYSQL_YYABORT;
6449              }
6450            }
6451            else
6452            {
6453              Lex->alter_info.flags|= ALTER_ADD_SYSTEM_VERSIONING;
6454              Lex->create_info.options|= HA_VERSIONED_TABLE;
6455            }
6456          }
6457        ;
6458
6459default_charset:
6460          opt_default charset opt_equal charset_name_or_default
6461          {
6462            if (unlikely(Lex->create_info.add_table_option_default_charset($4)))
6463              MYSQL_YYABORT;
6464          }
6465        ;
6466
6467default_collation:
6468          opt_default COLLATE_SYM opt_equal collation_name_or_default
6469          {
6470            HA_CREATE_INFO *cinfo= &Lex->create_info;
6471            if (unlikely((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
6472                         cinfo->default_table_charset && $4 &&
6473                         !($4= merge_charset_and_collation(cinfo->default_table_charset,
6474                                                           $4))))
6475              MYSQL_YYABORT;
6476
6477            Lex->create_info.default_table_charset= $4;
6478            Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
6479          }
6480        ;
6481
6482storage_engines:
6483          ident_or_text
6484          {
6485            if (Storage_engine_name($1).
6486                 resolve_storage_engine_with_error(thd, &$$,
6487                                            thd->lex->create_info.tmp_table()))
6488              MYSQL_YYABORT;
6489          }
6490        ;
6491
6492known_storage_engines:
6493          ident_or_text
6494          {
6495            plugin_ref plugin;
6496            if (likely((plugin= ha_resolve_by_name(thd, &$1, false))))
6497              $$= plugin_hton(plugin);
6498            else
6499              my_yyabort_error((ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str));
6500          }
6501        ;
6502
6503row_types:
6504          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
6505        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
6506        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
6507        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
6508        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
6509        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
6510        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
6511        ;
6512
6513merge_insert_types:
6514         NO_SYM          { $$= MERGE_INSERT_DISABLED; }
6515       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
6516       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; }
6517       ;
6518
6519udf_type:
6520          STRING_SYM {$$ = (int) STRING_RESULT; }
6521        | REAL {$$ = (int) REAL_RESULT; }
6522        | DECIMAL_SYM {$$ = (int) DECIMAL_RESULT; }
6523        | INT_SYM {$$ = (int) INT_RESULT; }
6524        ;
6525
6526
6527create_field_list:
6528        field_list
6529        {
6530          Lex->create_last_non_select_table= Lex->last_table();
6531        }
6532        ;
6533
6534create_field_list_parens:
6535        LEFT_PAREN_ALT field_list ')'
6536        {
6537          Lex->create_last_non_select_table= Lex->last_table();
6538        }
6539        ;
6540
6541field_list:
6542          field_list_item
6543        | field_list ',' field_list_item
6544        ;
6545
6546field_list_item:
6547          column_def { }
6548        | key_def
6549        | constraint_def
6550        | period_for_system_time
6551        | PERIOD_SYM period_for_application_time { }
6552        ;
6553
6554column_def:
6555          field_spec
6556          { $$= $1; }
6557        | field_spec references
6558          { $$= $1; }
6559        ;
6560
6561key_def:
6562          key_or_index opt_if_not_exists opt_ident opt_USING_key_algorithm
6563          {
6564            Lex->option_list= NULL;
6565            if (unlikely(Lex->add_key(Key::MULTIPLE, &$3, $4, $2)))
6566              MYSQL_YYABORT;
6567          }
6568          '(' key_list ')' normal_key_options { }
6569        | key_or_index opt_if_not_exists ident TYPE_SYM btree_or_rtree
6570          {
6571            Lex->option_list= NULL;
6572            if (unlikely(Lex->add_key(Key::MULTIPLE, &$3, $5, $2)))
6573              MYSQL_YYABORT;
6574          }
6575          '(' key_list ')' normal_key_options { }
6576        | fulltext opt_key_or_index opt_if_not_exists opt_ident
6577          {
6578            Lex->option_list= NULL;
6579            if (unlikely(Lex->add_key($1, &$4, HA_KEY_ALG_UNDEF, $3)))
6580              MYSQL_YYABORT;
6581          }
6582          '(' key_list ')' fulltext_key_options { }
6583        | spatial opt_key_or_index opt_if_not_exists opt_ident
6584          {
6585            Lex->option_list= NULL;
6586            if (unlikely(Lex->add_key($1, &$4, HA_KEY_ALG_UNDEF, $3)))
6587              MYSQL_YYABORT;
6588          }
6589          '(' key_list ')' spatial_key_options { }
6590        | opt_constraint constraint_key_type
6591          opt_if_not_exists opt_ident
6592          opt_USING_key_algorithm
6593          {
6594            Lex->option_list= NULL;
6595            if (unlikely(Lex->add_key($2, $4.str ? &$4 : &$1, $5, $3)))
6596              MYSQL_YYABORT;
6597          }
6598          '(' key_list ')' normal_key_options { }
6599        | opt_constraint constraint_key_type opt_if_not_exists ident
6600          TYPE_SYM btree_or_rtree
6601          {
6602            Lex->option_list= NULL;
6603            if (unlikely(Lex->add_key($2, $4.str ? &$4 : &$1, $6, $3)))
6604              MYSQL_YYABORT;
6605          }
6606          '(' key_list ')' normal_key_options { }
6607        | opt_constraint FOREIGN KEY_SYM opt_if_not_exists opt_ident
6608          {
6609            if (unlikely(Lex->check_add_key($4)) ||
6610                unlikely(!(Lex->last_key= (new (thd->mem_root)
6611                                           Key(Key::MULTIPLE,
6612                                           $1.str ? &$1 : &$5,
6613                                           HA_KEY_ALG_UNDEF, true, $4)))))
6614              MYSQL_YYABORT;
6615            Lex->option_list= NULL;
6616          }
6617          '(' key_list ')' references
6618          {
6619            LEX *lex=Lex;
6620            Key *key= (new (thd->mem_root)
6621                       Foreign_key($5.str ? &$5 : &$1,
6622                                   &lex->last_key->columns,
6623                                   &$10->db,
6624                                   &$10->table,
6625                                   &lex->ref_list,
6626                                   lex->fk_delete_opt,
6627                                   lex->fk_update_opt,
6628                                   lex->fk_match_option,
6629                                    $4));
6630            if (unlikely(key == NULL))
6631              MYSQL_YYABORT;
6632            /*
6633              handle_if_exists_options() expectes the two keys in this order:
6634              the Foreign_key, followed by its auto-generated Key.
6635            */
6636            lex->alter_info.key_list.push_back(key, thd->mem_root);
6637            lex->alter_info.key_list.push_back(Lex->last_key, thd->mem_root);
6638            lex->option_list= NULL;
6639
6640            /* Only used for ALTER TABLE. Ignored otherwise. */
6641            lex->alter_info.flags|= ALTER_ADD_FOREIGN_KEY;
6642          }
6643	;
6644
6645constraint_def:
6646         opt_constraint check_constraint
6647         {
6648           Lex->add_constraint($1, $2, FALSE);
6649         }
6650       ;
6651
6652period_for_system_time:
6653          // If FOR_SYM is followed by SYSTEM_TIME_SYM then they are merged to: FOR_SYSTEM_TIME_SYM .
6654          PERIOD_SYM FOR_SYSTEM_TIME_SYM '(' ident ',' ident ')'
6655          {
6656            Vers_parse_info &info= Lex->vers_get_info();
6657            info.set_period($4, $6);
6658          }
6659        ;
6660
6661period_for_application_time:
6662          FOR_SYM ident '(' ident ',' ident ')'
6663          {
6664            if (Lex->add_period($2, $4, $6))
6665              MYSQL_YYABORT;
6666          }
6667        ;
6668
6669opt_check_constraint:
6670          /* empty */      { $$= (Virtual_column_info*) 0; }
6671        | check_constraint { $$= $1;}
6672        ;
6673
6674check_constraint:
6675          CHECK_SYM '(' expr ')'
6676          {
6677            Virtual_column_info *v= add_virtual_expression(thd, $3);
6678            if (unlikely(!v))
6679              MYSQL_YYABORT;
6680            $$= v;
6681          }
6682        ;
6683
6684opt_constraint_no_id:
6685          /* Empty */  {}
6686        | CONSTRAINT   {}
6687        ;
6688
6689opt_constraint:
6690          /* empty */ { $$= null_clex_str; }
6691        | constraint { $$= $1; }
6692        ;
6693
6694constraint:
6695          CONSTRAINT opt_ident { $$=$2; }
6696        ;
6697
6698field_spec:
6699          field_ident
6700          {
6701            LEX *lex=Lex;
6702            Create_field *f= new (thd->mem_root) Create_field();
6703
6704            if (unlikely(check_string_char_length(&$1, 0, NAME_CHAR_LEN,
6705                                                  system_charset_info, 1)))
6706              my_yyabort_error((ER_TOO_LONG_IDENT, MYF(0), $1.str));
6707
6708            if (unlikely(!f))
6709              MYSQL_YYABORT;
6710
6711            lex->init_last_field(f, &$1, NULL);
6712            $<create_field>$= f;
6713            lex->parsing_options.lookup_keywords_after_qualifier= true;
6714          }
6715          field_type_or_serial opt_check_constraint
6716          {
6717            LEX *lex=Lex;
6718            lex->parsing_options.lookup_keywords_after_qualifier= false;
6719            $$= $<create_field>2;
6720
6721            $$->check_constraint= $4;
6722
6723            if (unlikely($$->check(thd)))
6724              MYSQL_YYABORT;
6725
6726            lex->alter_info.create_list.push_back($$, thd->mem_root);
6727
6728            $$->create_if_not_exists= Lex->check_exists;
6729            if ($$->flags & PRI_KEY_FLAG)
6730              lex->add_key_to_list(&$1, Key::PRIMARY, lex->check_exists);
6731            else if ($$->flags & UNIQUE_KEY_FLAG)
6732              lex->add_key_to_list(&$1, Key::UNIQUE, lex->check_exists);
6733          }
6734        ;
6735
6736field_type_or_serial:
6737          qualified_field_type  { Lex->last_field->set_attributes($1, Lex->charset); }
6738          field_def
6739        | SERIAL_SYM
6740          {
6741            Lex->last_field->set_handler(&type_handler_longlong);
6742            Lex->last_field->flags|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG
6743                                     | UNSIGNED_FLAG | UNIQUE_KEY_FLAG;
6744            Lex->alter_info.flags|= ALTER_ADD_INDEX;
6745          }
6746          opt_serial_attribute
6747        ;
6748
6749opt_serial_attribute:
6750          /* empty */ {}
6751        | opt_serial_attribute_list {}
6752        ;
6753
6754opt_serial_attribute_list:
6755          opt_serial_attribute_list serial_attribute {}
6756        | serial_attribute
6757        ;
6758
6759opt_asrow_attribute:
6760          /* empty */ {}
6761        | opt_asrow_attribute_list {}
6762        ;
6763
6764opt_asrow_attribute_list:
6765          opt_asrow_attribute_list asrow_attribute {}
6766        | asrow_attribute
6767        ;
6768
6769field_def:
6770          /* empty */ { }
6771        | attribute_list
6772        | attribute_list compressed_deprecated_column_attribute
6773        | attribute_list compressed_deprecated_column_attribute attribute_list
6774        | opt_generated_always AS virtual_column_func
6775         {
6776           Lex->last_field->vcol_info= $3;
6777           Lex->last_field->flags&= ~NOT_NULL_FLAG; // undo automatic NOT NULL for timestamps
6778         }
6779          vcol_opt_specifier vcol_opt_attribute
6780        | opt_generated_always AS ROW_SYM START_SYM opt_asrow_attribute
6781          {
6782            if (Lex->last_field_generated_always_as_row_start())
6783              MYSQL_YYABORT;
6784          }
6785        | opt_generated_always AS ROW_SYM END opt_asrow_attribute
6786          {
6787            if (Lex->last_field_generated_always_as_row_end())
6788              MYSQL_YYABORT;
6789          }
6790        ;
6791
6792opt_generated_always:
6793          /* empty */ {}
6794        | GENERATED_SYM ALWAYS_SYM {}
6795        ;
6796
6797vcol_opt_specifier:
6798          /* empty */
6799          {
6800            Lex->last_field->vcol_info->set_stored_in_db_flag(FALSE);
6801          }
6802        | VIRTUAL_SYM
6803          {
6804            Lex->last_field->vcol_info->set_stored_in_db_flag(FALSE);
6805          }
6806        | PERSISTENT_SYM
6807          {
6808            Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE);
6809          }
6810        | STORED_SYM
6811          {
6812            Lex->last_field->vcol_info->set_stored_in_db_flag(TRUE);
6813          }
6814        ;
6815
6816vcol_opt_attribute:
6817          /* empty */ {}
6818        | vcol_opt_attribute_list {}
6819        ;
6820
6821vcol_opt_attribute_list:
6822          vcol_opt_attribute_list vcol_attribute {}
6823        | vcol_attribute
6824        ;
6825
6826vcol_attribute:
6827          UNIQUE_SYM
6828          {
6829            LEX *lex=Lex;
6830            lex->last_field->flags|= UNIQUE_KEY_FLAG;
6831            lex->alter_info.flags|= ALTER_ADD_INDEX;
6832          }
6833        | UNIQUE_SYM KEY_SYM
6834          {
6835            LEX *lex=Lex;
6836            lex->last_field->flags|= UNIQUE_KEY_FLAG;
6837            lex->alter_info.flags|= ALTER_ADD_INDEX;
6838          }
6839        | COMMENT_SYM TEXT_STRING_sys { Lex->last_field->comment= $2; }
6840        | INVISIBLE_SYM
6841          {
6842            Lex->last_field->invisible= INVISIBLE_USER;
6843          }
6844        ;
6845
6846parse_vcol_expr:
6847          PARSE_VCOL_EXPR_SYM
6848          {
6849            /*
6850              "PARSE_VCOL_EXPR" can only be used by the SQL server
6851              when reading a '*.frm' file.
6852              Prevent the end user from invoking this command.
6853            */
6854            MYSQL_YYABORT_UNLESS(Lex->parse_vcol_expr);
6855            if (Lex->main_select_push())
6856              MYSQL_YYABORT;
6857          }
6858          expr
6859          {
6860            Virtual_column_info *v= add_virtual_expression(thd, $3);
6861            if (unlikely(!v))
6862              MYSQL_YYABORT;
6863            Lex->last_field->vcol_info= v;
6864            Lex->pop_select(); //main select
6865          }
6866        ;
6867
6868parenthesized_expr:
6869          expr
6870        | expr ',' expr_list
6871          {
6872            $3->push_front($1, thd->mem_root);
6873            $$= new (thd->mem_root) Item_row(thd, *$3);
6874            if (unlikely($$ == NULL))
6875              MYSQL_YYABORT;
6876          }
6877          ;
6878
6879virtual_column_func:
6880          '(' parenthesized_expr ')'
6881          {
6882            Virtual_column_info *v=
6883              add_virtual_expression(thd, $2);
6884            if (unlikely(!v))
6885              MYSQL_YYABORT;
6886            $$= v;
6887          }
6888        | subquery
6889          {
6890            Item *item;
6891            if (!(item= new (thd->mem_root) Item_singlerow_subselect(thd, $1)))
6892              MYSQL_YYABORT;
6893            Virtual_column_info *v= add_virtual_expression(thd, item);
6894            if (unlikely(!v))
6895              MYSQL_YYABORT;
6896            $$= v;
6897          }
6898        ;
6899
6900expr_or_literal: column_default_non_parenthesized_expr | signed_literal ;
6901
6902column_default_expr:
6903          virtual_column_func
6904        | expr_or_literal
6905          {
6906            if (unlikely(!($$= add_virtual_expression(thd, $1))))
6907              MYSQL_YYABORT;
6908          }
6909        ;
6910
6911field_type: field_type_all
6912        {
6913          Lex->map_data_type(Lex_ident_sys(), &($$= $1));
6914          Lex->last_field->set_attributes($$, Lex->charset);
6915        }
6916        ;
6917
6918qualified_field_type:
6919          field_type_all
6920          {
6921            Lex->map_data_type(Lex_ident_sys(), &($$= $1));
6922          }
6923        | sp_decl_ident '.' field_type_all
6924          {
6925            if (Lex->map_data_type($1, &($$= $3)))
6926              MYSQL_YYABORT;
6927          }
6928        ;
6929
6930field_type_all:
6931          field_type_numeric
6932        | field_type_temporal
6933        | field_type_string
6934        | field_type_lob
6935        | field_type_misc
6936        ;
6937
6938
6939sp_param_field_type:
6940          field_type_numeric
6941        | field_type_temporal
6942        | sp_param_field_type_string
6943        | field_type_lob
6944        | field_type_misc
6945        ;
6946
6947
6948field_type_numeric:
6949          int_type opt_field_length field_options { $$.set($1, $2); }
6950        | real_type opt_precision field_options   { $$.set($1, $2); }
6951        | FLOAT_SYM float_options field_options
6952          {
6953            $$.set(&type_handler_float, $2);
6954            if ($2.length() && !$2.dec())
6955            {
6956              int err;
6957              ulonglong tmp_length= my_strtoll10($2.length(), NULL, &err);
6958              if (unlikely(err || tmp_length > PRECISION_FOR_DOUBLE))
6959                my_yyabort_error((ER_WRONG_FIELD_SPEC, MYF(0),
6960                                  Lex->last_field->field_name.str));
6961              if (tmp_length > PRECISION_FOR_FLOAT)
6962                $$.set(&type_handler_double);
6963              else
6964                $$.set(&type_handler_float);
6965            }
6966          }
6967        | BIT_SYM opt_field_length_default_1
6968          {
6969            $$.set(&type_handler_bit, $2);
6970          }
6971        | BOOL_SYM
6972          {
6973            $$.set(&type_handler_tiny, "1");
6974          }
6975        | BOOLEAN_SYM
6976          {
6977            $$.set(&type_handler_tiny, "1");
6978          }
6979        | DECIMAL_SYM float_options field_options
6980          { $$.set(&type_handler_newdecimal, $2);}
6981        | NUMBER_ORACLE_SYM float_options field_options
6982          {
6983            if ($2.length() != 0)
6984              $$.set(&type_handler_newdecimal, $2);
6985            else
6986              $$.set(&type_handler_double);
6987          }
6988        | NUMERIC_SYM float_options field_options
6989          { $$.set(&type_handler_newdecimal, $2);}
6990        | FIXED_SYM float_options field_options
6991          { $$.set(&type_handler_newdecimal, $2);}
6992        ;
6993
6994
6995opt_binary_and_compression:
6996          /* empty */
6997        | binary
6998        | binary compressed_deprecated_data_type_attribute
6999        | compressed opt_binary
7000        ;
7001
7002field_type_string:
7003          char opt_field_length_default_1 opt_binary
7004          {
7005            $$.set(&type_handler_string, $2);
7006          }
7007        | nchar opt_field_length_default_1 opt_bin_mod
7008          {
7009            $$.set(&type_handler_string, $2);
7010            bincmp_collation(national_charset_info, $3);
7011          }
7012        | BINARY opt_field_length_default_1
7013          {
7014            Lex->charset=&my_charset_bin;
7015            $$.set(&type_handler_string, $2);
7016          }
7017        | varchar field_length opt_binary_and_compression
7018          {
7019            $$.set(&type_handler_varchar, $2);
7020          }
7021        | VARCHAR2_ORACLE_SYM field_length opt_binary_and_compression
7022          {
7023            $$.set(&type_handler_varchar, $2);
7024          }
7025        | nvarchar field_length opt_compressed opt_bin_mod
7026          {
7027            $$.set(&type_handler_varchar, $2);
7028            bincmp_collation(national_charset_info, $4);
7029          }
7030        | VARBINARY field_length opt_compressed
7031          {
7032            Lex->charset=&my_charset_bin;
7033            $$.set(&type_handler_varchar, $2);
7034          }
7035        | RAW_ORACLE_SYM field_length opt_compressed
7036          {
7037            Lex->charset= &my_charset_bin;
7038            $$.set(&type_handler_varchar, $2);
7039          }
7040        ;
7041
7042
7043sp_param_field_type_string:
7044          char opt_field_length_default_sp_param_char opt_binary
7045          {
7046            $$.set(&type_handler_varchar, $2);
7047          }
7048        | nchar opt_field_length_default_sp_param_char opt_bin_mod
7049          {
7050            $$.set(&type_handler_varchar, $2);
7051            bincmp_collation(national_charset_info, $3);
7052          }
7053        | BINARY opt_field_length_default_sp_param_char
7054          {
7055            Lex->charset=&my_charset_bin;
7056            $$.set(&type_handler_varchar, $2);
7057          }
7058        | varchar opt_field_length_default_sp_param_varchar opt_binary
7059          {
7060            $$.set(&type_handler_varchar, $2);
7061          }
7062        | VARCHAR2_ORACLE_SYM opt_field_length_default_sp_param_varchar opt_binary
7063          {
7064            $$.set(&type_handler_varchar, $2);
7065          }
7066        | nvarchar opt_field_length_default_sp_param_varchar opt_bin_mod
7067          {
7068            $$.set(&type_handler_varchar, $2);
7069            bincmp_collation(national_charset_info, $3);
7070          }
7071        | VARBINARY opt_field_length_default_sp_param_varchar
7072          {
7073            Lex->charset= &my_charset_bin;
7074            $$.set(&type_handler_varchar, $2);
7075          }
7076        | RAW_ORACLE_SYM opt_field_length_default_sp_param_varchar
7077          {
7078            Lex->charset= &my_charset_bin;
7079            $$.set(&type_handler_varchar, $2);
7080          }
7081        ;
7082
7083
7084field_type_temporal:
7085          YEAR_SYM opt_field_length field_options
7086          {
7087            if ($2)
7088            {
7089              errno= 0;
7090              ulong length= strtoul($2, NULL, 10);
7091              if (errno == 0 && length <= MAX_FIELD_BLOBLENGTH && length != 4)
7092              {
7093                char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1];
7094                my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length);
7095                push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
7096                                    ER_WARN_DEPRECATED_SYNTAX,
7097                                    ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
7098                                    buff, "YEAR(4)");
7099              }
7100            }
7101            $$.set(&type_handler_year, $2);
7102          }
7103        | DATE_SYM { $$.set(&type_handler_newdate); }
7104        | TIME_SYM opt_field_length
7105          {
7106            $$.set(opt_mysql56_temporal_format ?
7107                   static_cast<const Type_handler*>(&type_handler_time2) :
7108                   static_cast<const Type_handler*>(&type_handler_time),
7109                   $2);
7110          }
7111        | TIMESTAMP opt_field_length
7112          {
7113            $$.set(opt_mysql56_temporal_format ?
7114                   static_cast<const Type_handler*>(&type_handler_timestamp2):
7115                   static_cast<const Type_handler*>(&type_handler_timestamp),
7116                   $2);
7117          }
7118        | DATETIME opt_field_length
7119          {
7120            $$.set(thd->type_handler_for_datetime(), $2);
7121          }
7122        ;
7123
7124
7125field_type_lob:
7126          TINYBLOB opt_compressed
7127          {
7128            Lex->charset=&my_charset_bin;
7129            $$.set(&type_handler_tiny_blob);
7130          }
7131        | BLOB_MARIADB_SYM opt_field_length opt_compressed
7132          {
7133            Lex->charset=&my_charset_bin;
7134            $$.set(&type_handler_blob, $2);
7135          }
7136        | BLOB_ORACLE_SYM field_length opt_compressed
7137          {
7138            Lex->charset=&my_charset_bin;
7139            $$.set(&type_handler_blob, $2);
7140          }
7141        | BLOB_ORACLE_SYM opt_compressed
7142          {
7143            Lex->charset=&my_charset_bin;
7144            $$.set(&type_handler_long_blob);
7145          }
7146        | spatial_type float_options srid_option
7147          {
7148#ifdef HAVE_SPATIAL
7149            Lex->charset=&my_charset_bin;
7150            Lex->last_field->geom_type= $1;
7151            $$.set(&type_handler_geometry, $2);
7152#else
7153            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), sym_group_geom.name,
7154                              sym_group_geom.needed_define));
7155#endif
7156          }
7157        | MEDIUMBLOB opt_compressed
7158          {
7159            Lex->charset=&my_charset_bin;
7160            $$.set(&type_handler_medium_blob);
7161          }
7162        | LONGBLOB opt_compressed
7163          {
7164            Lex->charset=&my_charset_bin;
7165            $$.set(&type_handler_long_blob);
7166          }
7167        | LONG_SYM VARBINARY opt_compressed
7168          {
7169            Lex->charset=&my_charset_bin;
7170            $$.set(&type_handler_medium_blob);
7171          }
7172        | LONG_SYM varchar opt_binary_and_compression
7173          { $$.set(&type_handler_medium_blob); }
7174        | TINYTEXT opt_binary_and_compression
7175          { $$.set(&type_handler_tiny_blob); }
7176        | TEXT_SYM opt_field_length opt_binary_and_compression
7177          { $$.set(&type_handler_blob, $2); }
7178        | MEDIUMTEXT opt_binary_and_compression
7179          { $$.set(&type_handler_medium_blob); }
7180        | LONGTEXT opt_binary_and_compression
7181          { $$.set(&type_handler_long_blob); }
7182        | CLOB_ORACLE_SYM opt_binary_and_compression
7183          { $$.set(&type_handler_long_blob); }
7184        | LONG_SYM opt_binary_and_compression
7185          { $$.set(&type_handler_medium_blob); }
7186        | JSON_SYM opt_compressed
7187          {
7188            Lex->charset= &my_charset_utf8mb4_bin;
7189            $$.set(&type_handler_json_longtext);
7190          }
7191        ;
7192
7193field_type_misc:
7194          ENUM '(' string_list ')' opt_binary
7195          { $$.set(&type_handler_enum); }
7196        | SET '(' string_list ')' opt_binary
7197          { $$.set(&type_handler_set); }
7198        ;
7199
7200spatial_type:
7201          GEOMETRY_SYM        { $$= Field::GEOM_GEOMETRY; }
7202        | GEOMETRYCOLLECTION  { $$= Field::GEOM_GEOMETRYCOLLECTION; }
7203        | POINT_SYM           { $$= Field::GEOM_POINT; }
7204        | MULTIPOINT          { $$= Field::GEOM_MULTIPOINT; }
7205        | LINESTRING          { $$= Field::GEOM_LINESTRING; }
7206        | MULTILINESTRING     { $$= Field::GEOM_MULTILINESTRING; }
7207        | POLYGON             { $$= Field::GEOM_POLYGON; }
7208        | MULTIPOLYGON        { $$= Field::GEOM_MULTIPOLYGON; }
7209        ;
7210
7211char:
7212          CHAR_SYM {}
7213        ;
7214
7215nchar:
7216          NCHAR_SYM {}
7217        | NATIONAL_SYM CHAR_SYM {}
7218        ;
7219
7220varchar:
7221          char VARYING {}
7222        | VARCHAR {}
7223        ;
7224
7225nvarchar:
7226          NATIONAL_SYM VARCHAR {}
7227        | NVARCHAR_SYM {}
7228        | NCHAR_SYM VARCHAR {}
7229        | NATIONAL_SYM CHAR_SYM VARYING {}
7230        | NCHAR_SYM VARYING {}
7231        ;
7232
7233int_type:
7234          INT_SYM   { $$= &type_handler_long; }
7235        | TINYINT   { $$= &type_handler_tiny; }
7236        | SMALLINT  { $$= &type_handler_short; }
7237        | MEDIUMINT { $$= &type_handler_int24; }
7238        | BIGINT    { $$= &type_handler_longlong; }
7239        ;
7240
7241real_type:
7242          REAL
7243          {
7244            $$= thd->variables.sql_mode & MODE_REAL_AS_FLOAT ?
7245              static_cast<const Type_handler *>(&type_handler_float) :
7246              static_cast<const Type_handler *>(&type_handler_double);
7247          }
7248        | DOUBLE_SYM           { $$= &type_handler_double; }
7249        | DOUBLE_SYM PRECISION { $$= &type_handler_double; }
7250        ;
7251
7252srid_option:
7253          /* empty */
7254          { Lex->last_field->srid= 0; }
7255        |
7256          REF_SYSTEM_ID_SYM '=' NUM
7257          {
7258            Lex->last_field->srid=atoi($3.str);
7259          }
7260        ;
7261
7262float_options:
7263          /* empty */  { $$.set(0, 0);  }
7264        | field_length { $$.set($1, 0); }
7265        | precision    { $$= $1; }
7266        ;
7267
7268precision:
7269          '(' NUM ',' NUM ')' { $$.set($2.str, $4.str); }
7270        ;
7271
7272field_options:
7273          /* empty */ {}
7274        | SIGNED_SYM {}
7275        | UNSIGNED { Lex->last_field->flags|= UNSIGNED_FLAG;}
7276        | ZEROFILL { Lex->last_field->flags|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
7277        | UNSIGNED ZEROFILL { Lex->last_field->flags|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
7278        | ZEROFILL UNSIGNED { Lex->last_field->flags|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
7279        ;
7280
7281field_length:
7282          '(' LONG_NUM ')'      { $$= $2.str; }
7283        | '(' ULONGLONG_NUM ')' { $$= $2.str; }
7284        | '(' DECIMAL_NUM ')'   { $$= $2.str; }
7285        | '(' NUM ')'           { $$= $2.str; }
7286        ;
7287
7288opt_field_length:
7289          /* empty */  { $$= (char*) 0; /* use default length */ }
7290        | field_length { $$= $1; }
7291        ;
7292
7293opt_field_length_default_1:
7294          /* empty */  { $$= (char*) "1"; }
7295        | field_length { $$= $1; }
7296        ;
7297
7298/*
7299  In sql_mode=ORACLE, real size of VARCHAR and CHAR with no length
7300  in SP parameters is fixed at runtime with the length of real args.
7301  Let's translate VARCHAR to VARCHAR(4000) for return value.
7302
7303  Since Oracle 9, maximum size for VARCHAR in PL/SQL is 32767.
7304
7305  In MariaDB the limit for VARCHAR is 65535 bytes.
7306  We could translate VARCHAR with no length to VARCHAR(65535), but
7307  it would mean that for multi-byte character sets we'd have to translate
7308  VARCHAR to MEDIUMTEXT, to guarantee 65535 characters.
7309
7310  Also we could translate VARCHAR to VARCHAR(16383), where 16383 is
7311  the maximum possible length in characters in case of mbmaxlen=4
7312  (e.g. utf32, utf16, utf8mb4). However, we'll have character sets with
7313  mbmaxlen=5 soon (e.g. gb18030).
7314*/
7315opt_field_length_default_sp_param_varchar:
7316          /* empty */  { $$.set("4000", "4000"); }
7317        | field_length { $$.set($1, NULL); }
7318        ;
7319
7320opt_field_length_default_sp_param_char:
7321          /* empty */  { $$.set("2000", "2000"); }
7322        | field_length { $$.set($1, NULL); }
7323        ;
7324
7325opt_precision:
7326          /* empty */    { $$.set(0, 0); }
7327        | precision      { $$= $1; }
7328        ;
7329
7330
7331attribute_list:
7332          attribute_list attribute {}
7333        | attribute
7334        ;
7335
7336attribute:
7337          NULL_SYM { Lex->last_field->flags&= ~ NOT_NULL_FLAG; }
7338        | DEFAULT column_default_expr { Lex->last_field->default_value= $2; }
7339        | ON UPDATE_SYM NOW_SYM opt_default_time_precision
7340          {
7341            Item *item= new (thd->mem_root) Item_func_now_local(thd, $4);
7342            if (unlikely(item == NULL))
7343              MYSQL_YYABORT;
7344            Lex->last_field->on_update= item;
7345          }
7346        | AUTO_INC { Lex->last_field->flags|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
7347        | SERIAL_SYM DEFAULT VALUE_SYM
7348          {
7349            LEX *lex=Lex;
7350            lex->last_field->flags|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_KEY_FLAG;
7351            lex->alter_info.flags|= ALTER_ADD_INDEX;
7352          }
7353        | COLLATE_SYM collation_name
7354          {
7355            if (unlikely(Lex->charset && !my_charset_same(Lex->charset,$2)))
7356              my_yyabort_error((ER_COLLATION_CHARSET_MISMATCH, MYF(0),
7357                                $2->name,Lex->charset->csname));
7358            Lex->last_field->charset= $2;
7359          }
7360        | serial_attribute
7361        ;
7362
7363opt_compression_method:
7364          /* empty */ { $$= NULL; }
7365        | equal ident { $$= $2.str; }
7366        ;
7367
7368opt_compressed:
7369          /* empty */ {}
7370        | compressed { }
7371        ;
7372
7373compressed:
7374          COMPRESSED_SYM opt_compression_method
7375          {
7376            if (unlikely(Lex->last_field->set_compressed($2)))
7377              MYSQL_YYABORT;
7378          }
7379        ;
7380
7381compressed_deprecated_data_type_attribute:
7382          COMPRESSED_SYM opt_compression_method
7383          {
7384            if (unlikely(Lex->last_field->set_compressed_deprecated(thd, $2)))
7385              MYSQL_YYABORT;
7386          }
7387        ;
7388
7389compressed_deprecated_column_attribute:
7390          COMPRESSED_SYM opt_compression_method
7391          {
7392            if (unlikely(Lex->last_field->
7393                set_compressed_deprecated_column_attribute(thd, $1.pos(), $2)))
7394              MYSQL_YYABORT;
7395          }
7396        ;
7397
7398asrow_attribute:
7399          not NULL_SYM
7400          {
7401            Lex->last_field->flags|= NOT_NULL_FLAG;
7402          }
7403        | opt_primary KEY_SYM
7404          {
7405            LEX *lex=Lex;
7406            lex->last_field->flags|= PRI_KEY_FLAG | NOT_NULL_FLAG;
7407            lex->alter_info.flags|= ALTER_ADD_INDEX;
7408          }
7409        | vcol_attribute
7410        ;
7411
7412serial_attribute:
7413          asrow_attribute
7414        | IDENT_sys equal TEXT_STRING_sys
7415          {
7416            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
7417              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
7418            (void) new (thd->mem_root)
7419                   engine_option_value($1, $3, true,
7420                                       &Lex->last_field->option_list,
7421                                       &Lex->option_list_last);
7422          }
7423        | IDENT_sys equal ident
7424          {
7425            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
7426              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
7427            (void) new (thd->mem_root)
7428                   engine_option_value($1, $3, false,
7429                                       &Lex->last_field->option_list,
7430                                       &Lex->option_list_last);
7431          }
7432        | IDENT_sys equal real_ulonglong_num
7433          {
7434            (void) new (thd->mem_root)
7435                   engine_option_value($1, $3, &Lex->last_field->option_list,
7436                                       &Lex->option_list_last, thd->mem_root);
7437          }
7438        | IDENT_sys equal DEFAULT
7439          {
7440            (void) new (thd->mem_root)
7441                   engine_option_value($1, &Lex->last_field->option_list,
7442                                       &Lex->option_list_last);
7443          }
7444        | with_or_without_system VERSIONING_SYM
7445          {
7446            Lex->last_field->versioning= $1;
7447            Lex->create_info.options|= HA_VERSIONED_TABLE;
7448            if (Lex->alter_info.flags & ALTER_DROP_SYSTEM_VERSIONING)
7449            {
7450              my_yyabort_error((ER_VERS_NOT_VERSIONED, MYF(0),
7451                       Lex->create_last_non_select_table->table_name.str));
7452            }
7453          }
7454        ;
7455
7456with_or_without_system:
7457        WITH_SYSTEM_SYM
7458          {
7459            Lex->alter_info.flags|= ALTER_COLUMN_UNVERSIONED;
7460            Lex->create_info.vers_info.versioned_fields= true;
7461            $$= Column_definition::WITH_VERSIONING;
7462          }
7463        | WITHOUT SYSTEM
7464          {
7465            Lex->alter_info.flags|= ALTER_COLUMN_UNVERSIONED;
7466            Lex->create_info.vers_info.unversioned_fields= true;
7467            $$= Column_definition::WITHOUT_VERSIONING;
7468          }
7469        ;
7470
7471
7472sp_param_type:
7473        sp_param_field_type
7474        {
7475          Lex->map_data_type(Lex_ident_sys(), &($$= $1));
7476          Lex->last_field->set_attributes($$, Lex->charset);
7477        }
7478        ;
7479
7480charset:
7481          CHAR_SYM SET {}
7482        | CHARSET {}
7483        ;
7484
7485charset_name:
7486          ident_or_text
7487          {
7488            if (unlikely(!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0)))))
7489              my_yyabort_error((ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str));
7490          }
7491        | BINARY { $$= &my_charset_bin; }
7492        ;
7493
7494charset_name_or_default:
7495          charset_name { $$=$1;   }
7496        | DEFAULT    { $$=NULL; }
7497        ;
7498
7499opt_load_data_charset:
7500          /* Empty */ { $$= NULL; }
7501        | charset charset_name_or_default { $$= $2; }
7502        ;
7503
7504old_or_new_charset_name:
7505          ident_or_text
7506          {
7507            if (unlikely(!($$=get_charset_by_csname($1.str,
7508                                                    MY_CS_PRIMARY,MYF(0))) &&
7509                         !($$=get_old_charset_by_name($1.str))))
7510              my_yyabort_error((ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str));
7511          }
7512        | BINARY { $$= &my_charset_bin; }
7513        ;
7514
7515old_or_new_charset_name_or_default:
7516          old_or_new_charset_name { $$=$1;   }
7517        | DEFAULT    { $$=NULL; }
7518        ;
7519
7520collation_name:
7521          ident_or_text
7522          {
7523            if (unlikely(!($$= mysqld_collation_get_by_name($1.str))))
7524              MYSQL_YYABORT;
7525          }
7526        ;
7527
7528opt_collate:
7529          /* empty */ { $$=NULL; }
7530        | COLLATE_SYM collation_name_or_default { $$=$2; }
7531        ;
7532
7533collation_name_or_default:
7534          collation_name { $$=$1; }
7535        | DEFAULT    { $$=NULL; }
7536        ;
7537
7538opt_default:
7539          /* empty */ {}
7540        | DEFAULT {}
7541        ;
7542
7543charset_or_alias:
7544          charset charset_name { $$= $2; }
7545        | ASCII_SYM { $$= &my_charset_latin1; }
7546        | UNICODE_SYM
7547          {
7548            if (unlikely(!($$= get_charset_by_csname("ucs2", MY_CS_PRIMARY,MYF(0)))))
7549              my_yyabort_error((ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2"));
7550          }
7551        ;
7552
7553collate: COLLATE_SYM collation_name_or_default
7554         {
7555           Lex->charset= $2;
7556         }
7557       ;
7558
7559opt_binary:
7560          /* empty */             { bincmp_collation(NULL, false); }
7561        | binary {}
7562        ;
7563
7564binary:
7565          BYTE_SYM                { bincmp_collation(&my_charset_bin, false); }
7566        | charset_or_alias opt_bin_mod { bincmp_collation($1, $2); }
7567        | BINARY                  { bincmp_collation(NULL, true); }
7568        | BINARY charset_or_alias { bincmp_collation($2, true); }
7569        | charset_or_alias collate
7570          {
7571            if (!my_charset_same(Lex->charset, $1))
7572              my_yyabort_error((ER_COLLATION_CHARSET_MISMATCH, MYF(0),
7573                                Lex->charset->name, $1->csname));
7574          }
7575        | collate { }
7576        ;
7577
7578opt_bin_mod:
7579          /* empty */   { $$= false; }
7580        | BINARY        { $$= true; }
7581        ;
7582
7583ws_nweights:
7584        '(' real_ulong_num
7585        {
7586          if (unlikely($2 == 0))
7587          {
7588            thd->parse_error();
7589            MYSQL_YYABORT;
7590          }
7591        }
7592        ')'
7593        { $$= $2; }
7594        ;
7595
7596ws_level_flag_desc:
7597        ASC { $$= 0; }
7598        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
7599        ;
7600
7601ws_level_flag_reverse:
7602        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
7603
7604ws_level_flags:
7605        /* empty */ { $$= 0; }
7606        | ws_level_flag_desc { $$= $1; }
7607        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
7608        | ws_level_flag_reverse { $$= $1 ; }
7609        ;
7610
7611ws_level_number:
7612        real_ulong_num
7613        {
7614          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
7615          $$--;
7616        }
7617        ;
7618
7619ws_level_list_item:
7620        ws_level_number ws_level_flags
7621        {
7622          $$= (1 | $2) << $1;
7623        }
7624        ;
7625
7626ws_level_list:
7627        ws_level_list_item { $$= $1; }
7628        | ws_level_list ',' ws_level_list_item { $$|= $3; }
7629        ;
7630
7631ws_level_range:
7632        ws_level_number '-' ws_level_number
7633        {
7634          uint start= $1;
7635          uint end= $3;
7636          for ($$= 0; start <= end; start++)
7637            $$|= (1 << start);
7638        }
7639        ;
7640
7641ws_level_list_or_range:
7642        ws_level_list { $$= $1; }
7643        | ws_level_range { $$= $1; }
7644        ;
7645
7646opt_ws_levels:
7647        /* empty*/ { $$= 0; }
7648        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
7649        ;
7650
7651opt_primary:
7652          /* empty */
7653        | PRIMARY_SYM
7654        ;
7655
7656references:
7657          REFERENCES
7658          table_ident
7659          opt_ref_list
7660          opt_match_clause
7661          opt_on_update_delete
7662          {
7663            $$=$2;
7664          }
7665        ;
7666
7667opt_ref_list:
7668          /* empty */
7669          { Lex->ref_list.empty(); }
7670        | '(' ref_list ')'
7671        ;
7672
7673ref_list:
7674          ref_list ',' ident
7675          {
7676            Key_part_spec *key= new (thd->mem_root) Key_part_spec(&$3, 0);
7677            if (unlikely(key == NULL))
7678              MYSQL_YYABORT;
7679            Lex->ref_list.push_back(key, thd->mem_root);
7680          }
7681        | ident
7682          {
7683            Key_part_spec *key= new (thd->mem_root) Key_part_spec(&$1, 0);
7684            if (unlikely(key == NULL))
7685              MYSQL_YYABORT;
7686            LEX *lex= Lex;
7687            lex->ref_list.empty();
7688            lex->ref_list.push_back(key, thd->mem_root);
7689          }
7690        ;
7691
7692opt_match_clause:
7693          /* empty */
7694          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
7695        | MATCH FULL
7696          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
7697        | MATCH PARTIAL
7698          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
7699        | MATCH SIMPLE_SYM
7700          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
7701        ;
7702
7703opt_on_update_delete:
7704          /* empty */
7705          {
7706            LEX *lex= Lex;
7707            lex->fk_update_opt= FK_OPTION_UNDEF;
7708            lex->fk_delete_opt= FK_OPTION_UNDEF;
7709          }
7710        | ON UPDATE_SYM delete_option
7711          {
7712            LEX *lex= Lex;
7713            lex->fk_update_opt= $3;
7714            lex->fk_delete_opt= FK_OPTION_UNDEF;
7715          }
7716        | ON DELETE_SYM delete_option
7717          {
7718            LEX *lex= Lex;
7719            lex->fk_update_opt= FK_OPTION_UNDEF;
7720            lex->fk_delete_opt= $3;
7721          }
7722        | ON UPDATE_SYM delete_option
7723          ON DELETE_SYM delete_option
7724          {
7725            LEX *lex= Lex;
7726            lex->fk_update_opt= $3;
7727            lex->fk_delete_opt= $6;
7728          }
7729        | ON DELETE_SYM delete_option
7730          ON UPDATE_SYM delete_option
7731          {
7732            LEX *lex= Lex;
7733            lex->fk_update_opt= $6;
7734            lex->fk_delete_opt= $3;
7735          }
7736        ;
7737
7738delete_option:
7739          RESTRICT      { $$= FK_OPTION_RESTRICT; }
7740        | CASCADE       { $$= FK_OPTION_CASCADE; }
7741        | SET NULL_SYM  { $$= FK_OPTION_SET_NULL; }
7742        | NO_SYM ACTION { $$= FK_OPTION_NO_ACTION; }
7743        | SET DEFAULT   { $$= FK_OPTION_SET_DEFAULT; }
7744        ;
7745
7746constraint_key_type:
7747          PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
7748        | UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; }
7749        ;
7750
7751key_or_index:
7752          KEY_SYM {}
7753        | INDEX_SYM {}
7754        ;
7755
7756opt_key_or_index:
7757          /* empty */ {}
7758        | key_or_index
7759        ;
7760
7761keys_or_index:
7762          KEYS {}
7763        | INDEX_SYM {}
7764        | INDEXES {}
7765        ;
7766
7767opt_unique:
7768          /* empty */  { $$= Key::MULTIPLE; }
7769        | UNIQUE_SYM   { $$= Key::UNIQUE; }
7770        ;
7771
7772fulltext:
7773          FULLTEXT_SYM { $$= Key::FULLTEXT;}
7774        ;
7775
7776spatial:
7777          SPATIAL_SYM
7778          {
7779#ifdef HAVE_SPATIAL
7780            $$= Key::SPATIAL;
7781#else
7782            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), sym_group_geom.name,
7783                              sym_group_geom.needed_define));
7784#endif
7785          }
7786        ;
7787
7788normal_key_options:
7789          /* empty */ {}
7790        | normal_key_opts { Lex->last_key->option_list= Lex->option_list; }
7791        ;
7792
7793fulltext_key_options:
7794          /* empty */ {}
7795        | fulltext_key_opts { Lex->last_key->option_list= Lex->option_list; }
7796        ;
7797
7798spatial_key_options:
7799          /* empty */ {}
7800        | spatial_key_opts { Lex->last_key->option_list= Lex->option_list; }
7801        ;
7802
7803normal_key_opts:
7804          normal_key_opt
7805        | normal_key_opts normal_key_opt
7806        ;
7807
7808spatial_key_opts:
7809          spatial_key_opt
7810        | spatial_key_opts spatial_key_opt
7811        ;
7812
7813fulltext_key_opts:
7814          fulltext_key_opt
7815        | fulltext_key_opts fulltext_key_opt
7816        ;
7817
7818opt_USING_key_algorithm:
7819          /* Empty*/              { $$= HA_KEY_ALG_UNDEF; }
7820        | USING    btree_or_rtree { $$= $2; }
7821        ;
7822
7823/* TYPE is a valid identifier, so it's handled differently than USING */
7824opt_key_algorithm_clause:
7825          /* Empty*/              { $$= HA_KEY_ALG_UNDEF; }
7826        | USING    btree_or_rtree { $$= $2; }
7827        | TYPE_SYM btree_or_rtree { $$= $2; }
7828        ;
7829
7830key_using_alg:
7831          USING btree_or_rtree
7832          { Lex->last_key->key_create_info.algorithm= $2; }
7833        | TYPE_SYM btree_or_rtree
7834          { Lex->last_key->key_create_info.algorithm= $2; }
7835        ;
7836
7837all_key_opt:
7838          KEY_BLOCK_SIZE opt_equal ulong_num
7839          {
7840            Lex->last_key->key_create_info.block_size= $3;
7841            Lex->last_key->key_create_info.flags|= HA_USES_BLOCK_SIZE;
7842         }
7843        | COMMENT_SYM TEXT_STRING_sys
7844          { Lex->last_key->key_create_info.comment= $2; }
7845        | IDENT_sys equal TEXT_STRING_sys
7846          {
7847            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
7848              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
7849            (void) new (thd->mem_root)
7850                   engine_option_value($1, $3, true, &Lex->option_list,
7851                                       &Lex->option_list_last);
7852          }
7853        | IDENT_sys equal ident
7854          {
7855            if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
7856              my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
7857            (void) new (thd->mem_root)
7858                   engine_option_value($1, $3, false, &Lex->option_list,
7859                                       &Lex->option_list_last);
7860          }
7861        | IDENT_sys equal real_ulonglong_num
7862          {
7863            (void) new (thd->mem_root)
7864                  engine_option_value($1, $3, &Lex->option_list,
7865                                      &Lex->option_list_last, thd->mem_root);
7866          }
7867        | IDENT_sys equal DEFAULT
7868          {
7869            (void) new (thd->mem_root)
7870                   engine_option_value($1, &Lex->option_list,
7871                                       &Lex->option_list_last);
7872          }
7873        ;
7874
7875normal_key_opt:
7876          all_key_opt
7877        | key_using_alg
7878        ;
7879
7880spatial_key_opt:
7881          all_key_opt
7882        ;
7883
7884fulltext_key_opt:
7885          all_key_opt
7886        | WITH PARSER_SYM IDENT_sys
7887          {
7888            if (likely(plugin_is_ready(&$3, MYSQL_FTPARSER_PLUGIN)))
7889              Lex->last_key->key_create_info.parser_name= $3;
7890            else
7891              my_yyabort_error((ER_FUNCTION_NOT_DEFINED, MYF(0), $3.str));
7892          }
7893        ;
7894
7895btree_or_rtree:
7896          BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
7897        | RTREE_SYM { $$= HA_KEY_ALG_RTREE; }
7898        | HASH_SYM  { $$= HA_KEY_ALG_HASH; }
7899        ;
7900
7901key_list:
7902          key_list ',' key_part order_dir
7903          {
7904            Lex->last_key->columns.push_back($3, thd->mem_root);
7905          }
7906        | key_part order_dir
7907          {
7908            Lex->last_key->columns.push_back($1, thd->mem_root);
7909          }
7910        ;
7911
7912key_part:
7913          ident
7914          {
7915            $$= new (thd->mem_root) Key_part_spec(&$1, 0);
7916            if (unlikely($$ == NULL))
7917              MYSQL_YYABORT;
7918          }
7919        | ident '(' NUM ')'
7920          {
7921            int key_part_len= atoi($3.str);
7922            if (unlikely(!key_part_len))
7923              my_yyabort_error((ER_KEY_PART_0, MYF(0), $1.str));
7924            $$= new (thd->mem_root) Key_part_spec(&$1, (uint) key_part_len);
7925            if (unlikely($$ == NULL))
7926              MYSQL_YYABORT;
7927          }
7928        ;
7929
7930opt_ident:
7931          /* empty */ { $$= null_clex_str; }
7932        | field_ident { $$= $1; }
7933        ;
7934
7935string_list:
7936          text_string
7937          { Lex->last_field->interval_list.push_back($1, thd->mem_root); }
7938        | string_list ',' text_string
7939          { Lex->last_field->interval_list.push_back($3, thd->mem_root); }
7940        ;
7941
7942/*
7943** Alter table
7944*/
7945
7946alter:
7947          ALTER
7948          {
7949            Lex->name= null_clex_str;
7950            Lex->table_type= TABLE_TYPE_UNKNOWN;
7951            Lex->sql_command= SQLCOM_ALTER_TABLE;
7952            Lex->duplicates= DUP_ERROR;
7953            Lex->first_select_lex()->order_list.empty();
7954            Lex->create_info.init();
7955            Lex->create_info.row_type= ROW_TYPE_NOT_USED;
7956            Lex->alter_info.reset();
7957            Lex->no_write_to_binlog= 0;
7958            Lex->create_info.storage_media= HA_SM_DEFAULT;
7959            if (Lex->main_select_push())
7960              MYSQL_YYABORT;
7961            DBUG_ASSERT(!Lex->m_sql_cmd);
7962          }
7963          alter_options TABLE_SYM table_ident opt_lock_wait_timeout
7964          {
7965            if (!Lex->first_select_lex()->
7966                  add_table_to_list(thd, $5, NULL, TL_OPTION_UPDATING,
7967                                    TL_READ_NO_INSERT, MDL_SHARED_UPGRADABLE))
7968              MYSQL_YYABORT;
7969            Lex->first_select_lex()->db=
7970              (Lex->first_select_lex()->table_list.first)->db;
7971            Lex->create_last_non_select_table= Lex->last_table();
7972            Lex->mark_first_table_as_inserting();
7973          }
7974          alter_commands
7975          {
7976            if (likely(!Lex->m_sql_cmd))
7977            {
7978              /* Create a generic ALTER TABLE statment. */
7979              Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_table();
7980              if (unlikely(Lex->m_sql_cmd == NULL))
7981                MYSQL_YYABORT;
7982            }
7983            Lex->pop_select(); //main select
7984          }
7985        | ALTER DATABASE ident_or_empty
7986          {
7987            Lex->create_info.default_table_charset= NULL;
7988            Lex->create_info.used_fields= 0;
7989            if (Lex->main_select_push(true))
7990              MYSQL_YYABORT;
7991          }
7992          create_database_options
7993          {
7994            LEX *lex=Lex;
7995            lex->sql_command=SQLCOM_ALTER_DB;
7996            lex->name= $3;
7997            if (lex->name.str == NULL &&
7998                unlikely(lex->copy_db_to(&lex->name)))
7999              MYSQL_YYABORT;
8000            Lex->pop_select(); //main select
8001          }
8002        | ALTER DATABASE ident UPGRADE_SYM DATA_SYM DIRECTORY_SYM NAME_SYM
8003          {
8004            LEX *lex= Lex;
8005            if (unlikely(lex->sphead))
8006              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "DATABASE"));
8007            lex->sql_command= SQLCOM_ALTER_DB_UPGRADE;
8008            lex->name= $3;
8009          }
8010        | ALTER PROCEDURE_SYM sp_name
8011          {
8012            LEX *lex= Lex;
8013
8014            if (unlikely(lex->sphead))
8015              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE"));
8016            if (Lex->main_select_push())
8017              MYSQL_YYABORT;
8018            lex->sp_chistics.init();
8019          }
8020          sp_a_chistics
8021          {
8022            LEX *lex=Lex;
8023
8024            lex->sql_command= SQLCOM_ALTER_PROCEDURE;
8025            lex->spname= $3;
8026            Lex->pop_select(); //main select
8027            if (Lex->check_main_unit_semantics())
8028              MYSQL_YYABORT;
8029          }
8030        | ALTER FUNCTION_SYM sp_name
8031          {
8032            LEX *lex= Lex;
8033
8034            if (unlikely(lex->sphead))
8035              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"));
8036            if (Lex->main_select_push())
8037              MYSQL_YYABORT;
8038            lex->sp_chistics.init();
8039          }
8040          sp_a_chistics
8041          {
8042            LEX *lex=Lex;
8043
8044            lex->sql_command= SQLCOM_ALTER_FUNCTION;
8045            lex->spname= $3;
8046            Lex->pop_select(); //main select
8047            if (Lex->check_main_unit_semantics())
8048              MYSQL_YYABORT;
8049          }
8050        | ALTER view_algorithm definer_opt opt_view_suid VIEW_SYM table_ident
8051          {
8052            if (Lex->main_select_push())
8053              MYSQL_YYABORT;
8054            if (Lex->add_alter_view(thd, $2, $4, $6))
8055              MYSQL_YYABORT;
8056          }
8057          view_list_opt AS view_select
8058          {
8059            Lex->pop_select(); //main select
8060            if (Lex->check_main_unit_semantics())
8061              MYSQL_YYABORT;
8062          }
8063        | ALTER definer_opt opt_view_suid VIEW_SYM table_ident
8064          /*
8065            We have two separate rules for ALTER VIEW rather that
8066            optional view_algorithm above, to resolve the ambiguity
8067            with the ALTER EVENT below.
8068          */
8069          {
8070            if (Lex->main_select_push())
8071              MYSQL_YYABORT;
8072            if (Lex->add_alter_view(thd, VIEW_ALGORITHM_INHERIT, $3, $5))
8073              MYSQL_YYABORT;
8074          }
8075          view_list_opt AS view_select
8076          {
8077            Lex->pop_select(); //main select
8078            if (Lex->check_main_unit_semantics())
8079              MYSQL_YYABORT;
8080          }
8081        | ALTER definer_opt remember_name EVENT_SYM sp_name
8082          {
8083            if (Lex->main_select_push())
8084              MYSQL_YYABORT;
8085            /*
8086              It is safe to use Lex->spname because
8087              ALTER EVENT xxx RENATE TO yyy DO ALTER EVENT RENAME TO
8088              is not allowed. Lex->spname is used in the case of RENAME TO
8089              If it had to be supported spname had to be added to
8090              Event_parse_data.
8091            */
8092
8093            if (unlikely(!(Lex->event_parse_data= Event_parse_data::new_instance(thd))))
8094              MYSQL_YYABORT;
8095            Lex->event_parse_data->identifier= $5;
8096
8097            Lex->sql_command= SQLCOM_ALTER_EVENT;
8098            Lex->stmt_definition_begin= $3;
8099          }
8100          ev_alter_on_schedule_completion
8101          opt_ev_rename_to
8102          opt_ev_status
8103          opt_ev_comment
8104          opt_ev_sql_stmt
8105          {
8106            if (unlikely(!($7 || $8 || $9 || $10 || $11)))
8107            {
8108              thd->parse_error();
8109              MYSQL_YYABORT;
8110            }
8111            /*
8112              sql_command is set here because some rules in ev_sql_stmt
8113              can overwrite it
8114            */
8115            Lex->sql_command= SQLCOM_ALTER_EVENT;
8116            Lex->stmt_definition_end= (char*)YYLIP->get_cpp_ptr();
8117
8118            Lex->pop_select(); //main select
8119          }
8120        | ALTER TABLESPACE alter_tablespace_info
8121          {
8122            LEX *lex= Lex;
8123            lex->alter_tablespace_info->ts_cmd_type= ALTER_TABLESPACE;
8124          }
8125        | ALTER LOGFILE_SYM GROUP_SYM alter_logfile_group_info
8126          {
8127            LEX *lex= Lex;
8128            lex->alter_tablespace_info->ts_cmd_type= ALTER_LOGFILE_GROUP;
8129          }
8130        | ALTER TABLESPACE change_tablespace_info
8131          {
8132            LEX *lex= Lex;
8133            lex->alter_tablespace_info->ts_cmd_type= CHANGE_FILE_TABLESPACE;
8134          }
8135        | ALTER TABLESPACE change_tablespace_access
8136          {
8137            LEX *lex= Lex;
8138            lex->alter_tablespace_info->ts_cmd_type= ALTER_ACCESS_MODE_TABLESPACE;
8139          }
8140        | ALTER SERVER_SYM ident_or_text
8141          {
8142            LEX *lex= Lex;
8143            lex->sql_command= SQLCOM_ALTER_SERVER;
8144            lex->server_options.reset($3);
8145          } OPTIONS_SYM '(' server_options_list ')' { }
8146          /* ALTER USER foo is allowed for MySQL compatibility. */
8147        | ALTER USER_SYM opt_if_exists clear_privileges grant_list
8148          opt_require_clause opt_resource_options opt_account_locking_and_opt_password_expiration
8149          {
8150            Lex->create_info.set($3);
8151            Lex->sql_command= SQLCOM_ALTER_USER;
8152          }
8153        | ALTER SEQUENCE_SYM opt_if_exists
8154          {
8155            LEX *lex= Lex;
8156            lex->name= null_clex_str;
8157            lex->table_type= TABLE_TYPE_UNKNOWN;
8158            lex->sql_command= SQLCOM_ALTER_SEQUENCE;
8159            lex->create_info.init();
8160            lex->no_write_to_binlog= 0;
8161            DBUG_ASSERT(!lex->m_sql_cmd);
8162            if (Lex->main_select_push())
8163              MYSQL_YYABORT;
8164          }
8165          table_ident
8166          {
8167            LEX *lex= Lex;
8168            if (!(lex->create_info.seq_create_info= new (thd->mem_root)
8169                                                     sequence_definition()) ||
8170                !lex->first_select_lex()->
8171                  add_table_to_list(thd, $5, NULL, TL_OPTION_SEQUENCE,
8172                                    TL_WRITE, MDL_EXCLUSIVE))
8173              MYSQL_YYABORT;
8174          }
8175          sequence_defs
8176          {
8177            /* Create a generic ALTER SEQUENCE statment. */
8178            Lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_sequence($3);
8179            if (unlikely(Lex->m_sql_cmd == NULL))
8180              MYSQL_YYABORT;
8181            Lex->pop_select(); //main select
8182            if (Lex->check_main_unit_semantics())
8183              MYSQL_YYABORT;
8184          }
8185        ;
8186
8187account_locking_option:
8188          LOCK_SYM
8189          {
8190            Lex->account_options.account_locked= ACCOUNTLOCK_LOCKED;
8191          }
8192        | UNLOCK_SYM
8193          {
8194            Lex->account_options.account_locked= ACCOUNTLOCK_UNLOCKED;
8195          }
8196        ;
8197
8198opt_password_expire_option:
8199          /* empty */
8200          {
8201            Lex->account_options.password_expire= PASSWORD_EXPIRE_NOW;
8202          }
8203        | NEVER_SYM
8204          {
8205            Lex->account_options.password_expire= PASSWORD_EXPIRE_NEVER;
8206          }
8207        | DEFAULT
8208          {
8209            Lex->account_options.password_expire= PASSWORD_EXPIRE_DEFAULT;
8210          }
8211        | INTERVAL_SYM NUM DAY_SYM
8212          {
8213            Lex->account_options.password_expire= PASSWORD_EXPIRE_INTERVAL;
8214            if (!(Lex->account_options.num_expiration_days= atoi($2.str)))
8215              my_yyabort_error((ER_WRONG_VALUE, MYF(0), "DAY", $2.str));
8216          }
8217        ;
8218
8219opt_account_locking_and_opt_password_expiration:
8220          /* empty */
8221        | ACCOUNT_SYM account_locking_option
8222        | PASSWORD_SYM EXPIRE_SYM opt_password_expire_option
8223        | ACCOUNT_SYM account_locking_option PASSWORD_SYM EXPIRE_SYM opt_password_expire_option
8224        | PASSWORD_SYM EXPIRE_SYM opt_password_expire_option ACCOUNT_SYM account_locking_option
8225        ;
8226
8227ev_alter_on_schedule_completion:
8228          /* empty */ { $$= 0;}
8229        | ON SCHEDULE_SYM ev_schedule_time { $$= 1; }
8230        | ev_on_completion { $$= 1; }
8231        | ON SCHEDULE_SYM ev_schedule_time ev_on_completion { $$= 1; }
8232        ;
8233
8234opt_ev_rename_to:
8235          /* empty */ { $$= 0;}
8236        | RENAME TO_SYM sp_name
8237          {
8238            /*
8239              Use lex's spname to hold the new name.
8240              The original name is in the Event_parse_data object
8241            */
8242            Lex->spname= $3;
8243            $$= 1;
8244          }
8245        ;
8246
8247opt_ev_sql_stmt:
8248          /* empty*/ { $$= 0;}
8249        | DO_SYM ev_sql_stmt { $$= 1; }
8250        ;
8251
8252ident_or_empty:
8253          /* empty */ { $$= Lex_ident_sys(); }
8254        | ident
8255        ;
8256
8257alter_commands:
8258          /* empty */
8259        | DISCARD TABLESPACE
8260          {
8261            Lex->m_sql_cmd= new (thd->mem_root)
8262              Sql_cmd_discard_import_tablespace(
8263                Sql_cmd_discard_import_tablespace::DISCARD_TABLESPACE);
8264            if (unlikely(Lex->m_sql_cmd == NULL))
8265              MYSQL_YYABORT;
8266          }
8267        | IMPORT TABLESPACE
8268          {
8269            Lex->m_sql_cmd= new (thd->mem_root)
8270              Sql_cmd_discard_import_tablespace(
8271                Sql_cmd_discard_import_tablespace::IMPORT_TABLESPACE);
8272            if (unlikely(Lex->m_sql_cmd == NULL))
8273              MYSQL_YYABORT;
8274          }
8275        | alter_list
8276          opt_partitioning
8277        | alter_list
8278          remove_partitioning
8279        | remove_partitioning
8280        | partitioning
8281/*
8282  This part was added for release 5.1 by Mikael Ronstrm.
8283  From here we insert a number of commands to manage the partitions of a
8284  partitioned table such as adding partitions, dropping partitions,
8285  reorganising partitions in various manners. In future releases the list
8286  will be longer.
8287*/
8288        | add_partition_rule
8289        | DROP PARTITION_SYM opt_if_exists alt_part_name_list
8290          {
8291            Lex->alter_info.partition_flags|= ALTER_PARTITION_DROP;
8292            DBUG_ASSERT(!Lex->if_exists());
8293            Lex->create_info.add($3);
8294          }
8295        | REBUILD_SYM PARTITION_SYM opt_no_write_to_binlog
8296          all_or_alt_part_name_list
8297          {
8298            LEX *lex= Lex;
8299            lex->alter_info.partition_flags|= ALTER_PARTITION_REBUILD;
8300            lex->no_write_to_binlog= $3;
8301          }
8302        | OPTIMIZE PARTITION_SYM opt_no_write_to_binlog
8303          all_or_alt_part_name_list
8304          {
8305            LEX *lex= thd->lex;
8306            lex->no_write_to_binlog= $3;
8307            lex->check_opt.init();
8308            DBUG_ASSERT(!lex->m_sql_cmd);
8309            lex->m_sql_cmd= new (thd->mem_root)
8310                              Sql_cmd_alter_table_optimize_partition();
8311            if (unlikely(lex->m_sql_cmd == NULL))
8312              MYSQL_YYABORT;
8313          }
8314          opt_no_write_to_binlog
8315        | ANALYZE_SYM PARTITION_SYM opt_no_write_to_binlog
8316          all_or_alt_part_name_list
8317          {
8318            LEX *lex= thd->lex;
8319            lex->no_write_to_binlog= $3;
8320            lex->check_opt.init();
8321            DBUG_ASSERT(!lex->m_sql_cmd);
8322            lex->m_sql_cmd= new (thd->mem_root)
8323                              Sql_cmd_alter_table_analyze_partition();
8324            if (unlikely(lex->m_sql_cmd == NULL))
8325               MYSQL_YYABORT;
8326          }
8327        | CHECK_SYM PARTITION_SYM all_or_alt_part_name_list
8328          {
8329            LEX *lex= thd->lex;
8330            lex->check_opt.init();
8331            DBUG_ASSERT(!lex->m_sql_cmd);
8332            lex->m_sql_cmd= new (thd->mem_root)
8333                              Sql_cmd_alter_table_check_partition();
8334            if (unlikely(lex->m_sql_cmd == NULL))
8335              MYSQL_YYABORT;
8336          }
8337          opt_mi_check_type
8338        | REPAIR PARTITION_SYM opt_no_write_to_binlog
8339          all_or_alt_part_name_list
8340          {
8341            LEX *lex= thd->lex;
8342            lex->no_write_to_binlog= $3;
8343            lex->check_opt.init();
8344            DBUG_ASSERT(!lex->m_sql_cmd);
8345            lex->m_sql_cmd= new (thd->mem_root)
8346                              Sql_cmd_alter_table_repair_partition();
8347            if (unlikely(lex->m_sql_cmd == NULL))
8348              MYSQL_YYABORT;
8349          }
8350          opt_mi_repair_type
8351        | COALESCE PARTITION_SYM opt_no_write_to_binlog real_ulong_num
8352          {
8353            LEX *lex= Lex;
8354            lex->alter_info.partition_flags|= ALTER_PARTITION_COALESCE;
8355            lex->no_write_to_binlog= $3;
8356            lex->alter_info.num_parts= $4;
8357          }
8358        | TRUNCATE_SYM PARTITION_SYM all_or_alt_part_name_list
8359          {
8360            LEX *lex= thd->lex;
8361            lex->check_opt.init();
8362            DBUG_ASSERT(!lex->m_sql_cmd);
8363            lex->m_sql_cmd= new (thd->mem_root)
8364                              Sql_cmd_alter_table_truncate_partition();
8365            if (unlikely(lex->m_sql_cmd == NULL))
8366              MYSQL_YYABORT;
8367          }
8368        | reorg_partition_rule
8369        | EXCHANGE_SYM PARTITION_SYM alt_part_name_item
8370          WITH TABLE_SYM table_ident have_partitioning
8371          {
8372            if (Lex->stmt_alter_table_exchange_partition($6))
8373              MYSQL_YYABORT;
8374          }
8375        ;
8376
8377remove_partitioning:
8378          REMOVE_SYM PARTITIONING_SYM
8379          {
8380            Lex->alter_info.partition_flags|= ALTER_PARTITION_REMOVE;
8381          }
8382        ;
8383
8384all_or_alt_part_name_list:
8385          ALL
8386          {
8387            Lex->alter_info.partition_flags|= ALTER_PARTITION_ALL;
8388          }
8389        | alt_part_name_list
8390        ;
8391
8392add_partition_rule:
8393          ADD PARTITION_SYM opt_if_not_exists
8394          opt_no_write_to_binlog
8395          {
8396            LEX *lex= Lex;
8397            lex->part_info= new (thd->mem_root) partition_info();
8398            if (unlikely(!lex->part_info))
8399              MYSQL_YYABORT;
8400
8401            lex->alter_info.partition_flags|= ALTER_PARTITION_ADD;
8402            DBUG_ASSERT(!Lex->create_info.if_not_exists());
8403            lex->create_info.set($3);
8404            lex->no_write_to_binlog= $4;
8405          }
8406          add_part_extra
8407          {}
8408        ;
8409
8410add_part_extra:
8411          /* empty */
8412        | '(' part_def_list ')'
8413          {
8414            LEX *lex= Lex;
8415            lex->part_info->num_parts= lex->part_info->partitions.elements;
8416          }
8417        | PARTITIONS_SYM real_ulong_num
8418          {
8419            Lex->part_info->num_parts= $2;
8420          }
8421        ;
8422
8423reorg_partition_rule:
8424          REORGANIZE_SYM PARTITION_SYM opt_no_write_to_binlog
8425          {
8426            LEX *lex= Lex;
8427            lex->part_info= new (thd->mem_root) partition_info();
8428            if (unlikely(!lex->part_info))
8429              MYSQL_YYABORT;
8430
8431            lex->no_write_to_binlog= $3;
8432          }
8433          reorg_parts_rule
8434        ;
8435
8436reorg_parts_rule:
8437          /* empty */
8438          {
8439            Lex->alter_info.partition_flags|= ALTER_PARTITION_TABLE_REORG;
8440          }
8441        | alt_part_name_list
8442          {
8443            Lex->alter_info.partition_flags|= ALTER_PARTITION_REORGANIZE;
8444          }
8445          INTO '(' part_def_list ')'
8446          {
8447            partition_info *part_info= Lex->part_info;
8448            part_info->num_parts= part_info->partitions.elements;
8449          }
8450        ;
8451
8452alt_part_name_list:
8453          alt_part_name_item {}
8454        | alt_part_name_list ',' alt_part_name_item {}
8455        ;
8456
8457alt_part_name_item:
8458          ident
8459          {
8460            if (unlikely(Lex->alter_info.partition_names.push_back($1.str,
8461                                                                   thd->mem_root)))
8462              MYSQL_YYABORT;
8463          }
8464        ;
8465
8466/*
8467  End of management of partition commands
8468*/
8469
8470alter_list:
8471          alter_list_item
8472        | alter_list ',' alter_list_item
8473        ;
8474
8475add_column:
8476          ADD opt_column opt_if_not_exists_table_element
8477        ;
8478
8479alter_list_item:
8480          add_column column_def opt_place
8481          {
8482            LEX *lex=Lex;
8483            lex->create_last_non_select_table= lex->last_table();
8484            lex->alter_info.flags|= ALTER_PARSER_ADD_COLUMN;
8485            $2->after= $3;
8486          }
8487        | ADD key_def
8488          {
8489            Lex->create_last_non_select_table= Lex->last_table();
8490            Lex->alter_info.flags|= ALTER_ADD_INDEX;
8491          }
8492        | ADD period_for_system_time
8493          {
8494            Lex->alter_info.flags|= ALTER_ADD_PERIOD;
8495          }
8496        | ADD
8497          PERIOD_SYM opt_if_not_exists_table_element period_for_application_time
8498          {
8499            Table_period_info &period= Lex->create_info.period_info;
8500            period.create_if_not_exists= Lex->check_exists;
8501            Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
8502          }
8503        | add_column '(' create_field_list ')'
8504          {
8505            LEX *lex=Lex;
8506            lex->alter_info.flags|= ALTER_PARSER_ADD_COLUMN;
8507            if (!lex->alter_info.key_list.is_empty())
8508              lex->alter_info.flags|= ALTER_ADD_INDEX;
8509          }
8510        | ADD constraint_def
8511          {
8512            Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
8513	  }
8514        | ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint
8515         {
8516           Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
8517           Lex->add_constraint($6, $7, TRUE);
8518         }
8519        | CHANGE opt_column opt_if_exists_table_element field_ident
8520          field_spec opt_place
8521          {
8522            Lex->alter_info.flags|= ALTER_CHANGE_COLUMN | ALTER_RENAME_COLUMN;
8523            Lex->create_last_non_select_table= Lex->last_table();
8524            $5->change= $4;
8525            $5->after= $6;
8526          }
8527        | MODIFY_SYM opt_column opt_if_exists_table_element
8528          field_spec opt_place
8529          {
8530            Lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
8531            Lex->create_last_non_select_table= Lex->last_table();
8532            $4->change= $4->field_name;
8533            $4->after= $5;
8534          }
8535        | DROP opt_column opt_if_exists_table_element field_ident opt_restrict
8536          {
8537            LEX *lex=Lex;
8538            Alter_drop *ad= (new (thd->mem_root)
8539                             Alter_drop(Alter_drop::COLUMN, $4.str, $3));
8540            if (unlikely(ad == NULL))
8541              MYSQL_YYABORT;
8542            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
8543            lex->alter_info.flags|= ALTER_PARSER_DROP_COLUMN;
8544          }
8545	| DROP CONSTRAINT opt_if_exists_table_element field_ident
8546          {
8547            LEX *lex=Lex;
8548            Alter_drop *ad= (new (thd->mem_root)
8549                             Alter_drop(Alter_drop::CHECK_CONSTRAINT,
8550                                        $4.str, $3));
8551            if (unlikely(ad == NULL))
8552              MYSQL_YYABORT;
8553            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
8554            lex->alter_info.flags|= ALTER_DROP_CHECK_CONSTRAINT;
8555          }
8556        | DROP FOREIGN KEY_SYM opt_if_exists_table_element field_ident
8557          {
8558            LEX *lex=Lex;
8559            Alter_drop *ad= (new (thd->mem_root)
8560                             Alter_drop(Alter_drop::FOREIGN_KEY, $5.str, $4));
8561            if (unlikely(ad == NULL))
8562              MYSQL_YYABORT;
8563            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
8564            lex->alter_info.flags|= ALTER_DROP_FOREIGN_KEY;
8565          }
8566        | DROP opt_constraint_no_id PRIMARY_SYM KEY_SYM
8567          {
8568            LEX *lex=Lex;
8569            Alter_drop *ad= (new (thd->mem_root)
8570                             Alter_drop(Alter_drop::KEY, primary_key_name,
8571                                        FALSE));
8572            if (unlikely(ad == NULL))
8573              MYSQL_YYABORT;
8574            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
8575            lex->alter_info.flags|= ALTER_DROP_INDEX;
8576          }
8577        | DROP key_or_index opt_if_exists_table_element field_ident
8578          {
8579            LEX *lex=Lex;
8580            Alter_drop *ad= (new (thd->mem_root)
8581                             Alter_drop(Alter_drop::KEY, $4.str, $3));
8582            if (unlikely(ad == NULL))
8583              MYSQL_YYABORT;
8584            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
8585            lex->alter_info.flags|= ALTER_DROP_INDEX;
8586          }
8587        | DISABLE_SYM KEYS
8588          {
8589            LEX *lex=Lex;
8590            lex->alter_info.keys_onoff= Alter_info::DISABLE;
8591            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
8592          }
8593        | ENABLE_SYM KEYS
8594          {
8595            LEX *lex=Lex;
8596            lex->alter_info.keys_onoff= Alter_info::ENABLE;
8597            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
8598          }
8599        | ALTER opt_column opt_if_exists_table_element field_ident SET DEFAULT column_default_expr
8600          {
8601            if (check_expression($7, &$4, VCOL_DEFAULT))
8602              MYSQL_YYABORT;
8603            if (unlikely(Lex->add_alter_list($4.str, $7, $3)))
8604              MYSQL_YYABORT;
8605          }
8606        | ALTER opt_column opt_if_exists_table_element field_ident DROP DEFAULT
8607          {
8608            if (unlikely(Lex->add_alter_list($4.str, (Virtual_column_info*) 0,
8609                                             $3)))
8610              MYSQL_YYABORT;
8611          }
8612        | RENAME opt_to table_ident
8613          {
8614            LEX *lex=Lex;
8615            lex->first_select_lex()->db= $3->db;
8616            if (lex->first_select_lex()->db.str == NULL &&
8617                lex->copy_db_to(&lex->first_select_lex()->db))
8618              MYSQL_YYABORT;
8619            if (unlikely(check_table_name($3->table.str,$3->table.length,
8620                                          FALSE)) ||
8621                ($3->db.str && unlikely(check_db_name((LEX_STRING*) &$3->db))))
8622              my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $3->table.str));
8623            lex->name= $3->table;
8624            lex->alter_info.flags|= ALTER_RENAME;
8625          }
8626        | CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
8627          {
8628            if (!$4)
8629            {
8630              $4= thd->variables.collation_database;
8631            }
8632            $5= $5 ? $5 : $4;
8633            if (unlikely(!my_charset_same($4,$5)))
8634              my_yyabort_error((ER_COLLATION_CHARSET_MISMATCH, MYF(0),
8635                                $5->name, $4->csname));
8636            if (unlikely(Lex->create_info.add_alter_list_item_convert_to_charset($5)))
8637              MYSQL_YYABORT;
8638            Lex->alter_info.flags|= ALTER_CONVERT_TO;
8639          }
8640        | create_table_options_space_separated
8641          {
8642            LEX *lex=Lex;
8643            lex->alter_info.flags|= ALTER_OPTIONS;
8644          }
8645        | FORCE_SYM
8646          {
8647            Lex->alter_info.flags|= ALTER_RECREATE;
8648          }
8649        | alter_order_clause
8650          {
8651            LEX *lex=Lex;
8652            lex->alter_info.flags|= ALTER_ORDER;
8653          }
8654        | alter_algorithm_option
8655        | alter_lock_option
8656        | ADD SYSTEM VERSIONING_SYM
8657          {
8658            Lex->alter_info.flags|= ALTER_ADD_SYSTEM_VERSIONING;
8659            Lex->create_info.options|= HA_VERSIONED_TABLE;
8660          }
8661        | DROP SYSTEM VERSIONING_SYM
8662          {
8663            Lex->alter_info.flags|= ALTER_DROP_SYSTEM_VERSIONING;
8664            Lex->create_info.options&= ~HA_VERSIONED_TABLE;
8665          }
8666        | DROP PERIOD_SYM FOR_SYSTEM_TIME_SYM
8667          {
8668            Lex->alter_info.flags|= ALTER_DROP_PERIOD;
8669          }
8670        | DROP PERIOD_SYM opt_if_exists_table_element FOR_SYM ident
8671          {
8672            Alter_drop *ad= new Alter_drop(Alter_drop::PERIOD, $5.str, $3);
8673            if (unlikely(ad == NULL))
8674              MYSQL_YYABORT;
8675            Lex->alter_info.drop_list.push_back(ad, thd->mem_root);
8676            Lex->alter_info.flags|= ALTER_DROP_CHECK_CONSTRAINT;
8677          }
8678        ;
8679
8680opt_index_lock_algorithm:
8681          /* empty */
8682        | alter_lock_option
8683        | alter_algorithm_option
8684        | alter_lock_option alter_algorithm_option
8685        | alter_algorithm_option alter_lock_option
8686        ;
8687
8688alter_algorithm_option:
8689          ALGORITHM_SYM opt_equal DEFAULT
8690          {
8691            Lex->alter_info.set_requested_algorithm(
8692              Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT);
8693          }
8694        | ALGORITHM_SYM opt_equal ident
8695          {
8696            if (unlikely(Lex->alter_info.set_requested_algorithm(&$3)))
8697              my_yyabort_error((ER_UNKNOWN_ALTER_ALGORITHM, MYF(0), $3.str));
8698          }
8699        ;
8700
8701alter_lock_option:
8702          LOCK_SYM opt_equal DEFAULT
8703          {
8704            Lex->alter_info.requested_lock=
8705              Alter_info::ALTER_TABLE_LOCK_DEFAULT;
8706          }
8707        | LOCK_SYM opt_equal ident
8708          {
8709            if (unlikely(Lex->alter_info.set_requested_lock(&$3)))
8710              my_yyabort_error((ER_UNKNOWN_ALTER_LOCK, MYF(0), $3.str));
8711          }
8712        ;
8713
8714opt_column:
8715          /* empty */ {}     %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
8716        | COLUMN_SYM {}
8717        ;
8718
8719opt_ignore:
8720          /* empty */ { Lex->ignore= 0;}
8721        | IGNORE_SYM { Lex->ignore= 1;}
8722        ;
8723
8724alter_options:
8725        { Lex->ignore= 0;} alter_options_part2
8726	;
8727
8728alter_options_part2:
8729          /* empty */
8730        | alter_option_list
8731        ;
8732
8733alter_option_list:
8734        alter_option_list alter_option
8735        | alter_option
8736        ;
8737
8738alter_option:
8739	  IGNORE_SYM { Lex->ignore= 1;}
8740        | ONLINE_SYM
8741          {
8742            Lex->alter_info.requested_lock=
8743              Alter_info::ALTER_TABLE_LOCK_NONE;
8744          }
8745        ;
8746
8747opt_restrict:
8748          /* empty */ { Lex->drop_mode= DROP_DEFAULT; }
8749        | RESTRICT    { Lex->drop_mode= DROP_RESTRICT; }
8750        | CASCADE     { Lex->drop_mode= DROP_CASCADE; }
8751        ;
8752
8753opt_place:
8754        /* empty */ { $$= null_clex_str; }
8755        | AFTER_SYM ident
8756          {
8757            $$= $2;
8758            Lex->alter_info.flags |= ALTER_COLUMN_ORDER;
8759          }
8760        | FIRST_SYM
8761          {
8762            $$.str=    first_keyword;
8763	    $$.length= 5; /* Length of "first" */
8764            Lex->alter_info.flags |= ALTER_COLUMN_ORDER;
8765          }
8766        ;
8767
8768opt_to:
8769          /* empty */ {}
8770        | TO_SYM {}
8771        | '=' {}
8772        | AS {}
8773        ;
8774
8775slave:
8776          START_SYM SLAVE optional_connection_name slave_thread_opts
8777          {
8778            LEX *lex=Lex;
8779            lex->sql_command = SQLCOM_SLAVE_START;
8780            lex->type = 0;
8781            /* If you change this code don't forget to update SLAVE START too */
8782          }
8783          slave_until
8784          {}
8785        | START_SYM ALL SLAVES slave_thread_opts
8786          {
8787            LEX *lex=Lex;
8788            lex->sql_command = SQLCOM_SLAVE_ALL_START;
8789            lex->type = 0;
8790            /* If you change this code don't forget to update STOP SLAVE too */
8791          }
8792          {}
8793        | STOP_SYM SLAVE optional_connection_name slave_thread_opts
8794          {
8795            LEX *lex=Lex;
8796            lex->sql_command = SQLCOM_SLAVE_STOP;
8797            lex->type = 0;
8798            /* If you change this code don't forget to update SLAVE STOP too */
8799          }
8800        | STOP_SYM ALL SLAVES slave_thread_opts
8801          {
8802            LEX *lex=Lex;
8803            lex->sql_command = SQLCOM_SLAVE_ALL_STOP;
8804            lex->type = 0;
8805            /* If you change this code don't forget to update SLAVE STOP too */
8806          }
8807        ;
8808
8809start:
8810          START_SYM TRANSACTION_SYM opt_start_transaction_option_list
8811          {
8812            LEX *lex= Lex;
8813            lex->sql_command= SQLCOM_BEGIN;
8814            /* READ ONLY and READ WRITE are mutually exclusive. */
8815            if (unlikely(($3 & MYSQL_START_TRANS_OPT_READ_WRITE) &&
8816                         ($3 & MYSQL_START_TRANS_OPT_READ_ONLY)))
8817            {
8818              thd->parse_error();
8819              MYSQL_YYABORT;
8820            }
8821            lex->start_transaction_opt= $3;
8822          }
8823        ;
8824
8825opt_start_transaction_option_list:
8826          /* empty */
8827          {
8828            $$= 0;
8829          }
8830        | start_transaction_option_list
8831          {
8832            $$= $1;
8833          }
8834        ;
8835
8836start_transaction_option_list:
8837          start_transaction_option
8838          {
8839            $$= $1;
8840          }
8841        | start_transaction_option_list ',' start_transaction_option
8842          {
8843            $$= $1 | $3;
8844          }
8845        ;
8846
8847start_transaction_option:
8848          WITH CONSISTENT_SYM SNAPSHOT_SYM
8849          {
8850            $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
8851          }
8852        | READ_SYM ONLY_SYM
8853          {
8854            $$= MYSQL_START_TRANS_OPT_READ_ONLY;
8855          }
8856        | READ_SYM WRITE_SYM
8857          {
8858            $$= MYSQL_START_TRANS_OPT_READ_WRITE;
8859          }
8860        ;
8861
8862slave_thread_opts:
8863          { Lex->slave_thd_opt= 0; }
8864          slave_thread_opt_list
8865          {}
8866        ;
8867
8868slave_thread_opt_list:
8869          slave_thread_opt
8870        | slave_thread_opt_list ',' slave_thread_opt
8871        ;
8872
8873slave_thread_opt:
8874          /*empty*/ {}
8875        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
8876        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
8877        ;
8878
8879slave_until:
8880          /*empty*/ {}
8881        | UNTIL_SYM slave_until_opts
8882          {
8883            LEX *lex=Lex;
8884            if (unlikely(((lex->mi.log_file_name || lex->mi.pos) &&
8885                         (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
8886                         !((lex->mi.log_file_name && lex->mi.pos) ||
8887                           (lex->mi.relay_log_name && lex->mi.relay_log_pos))))
8888               my_yyabort_error((ER_BAD_SLAVE_UNTIL_COND, MYF(0)));
8889          }
8890        | UNTIL_SYM MASTER_GTID_POS_SYM '=' TEXT_STRING_sys
8891          {
8892            Lex->mi.gtid_pos_str = $4;
8893          }
8894        ;
8895
8896slave_until_opts:
8897          master_file_def
8898        | slave_until_opts ',' master_file_def
8899        ;
8900
8901checksum:
8902          CHECKSUM_SYM table_or_tables
8903          {
8904            LEX *lex=Lex;
8905            lex->sql_command = SQLCOM_CHECKSUM;
8906            /* Will be overridden during execution. */
8907            YYPS->m_lock_type= TL_UNLOCK;
8908          }
8909          table_list opt_checksum_type
8910          {}
8911        ;
8912
8913opt_checksum_type:
8914          /* nothing */ { Lex->check_opt.flags= 0; }
8915        | QUICK         { Lex->check_opt.flags= T_QUICK; }
8916        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
8917        ;
8918
8919repair_table_or_view:
8920          table_or_tables table_list opt_mi_repair_type
8921        | VIEW_SYM
8922          { Lex->table_type= TABLE_TYPE_VIEW; }
8923          table_list opt_view_repair_type
8924        ;
8925
8926repair:
8927          REPAIR opt_no_write_to_binlog
8928          {
8929            LEX *lex=Lex;
8930            lex->sql_command = SQLCOM_REPAIR;
8931            lex->no_write_to_binlog= $2;
8932            lex->check_opt.init();
8933            lex->alter_info.reset();
8934            /* Will be overridden during execution. */
8935            YYPS->m_lock_type= TL_UNLOCK;
8936          }
8937          repair_table_or_view
8938          {
8939            LEX* lex= thd->lex;
8940            DBUG_ASSERT(!lex->m_sql_cmd);
8941            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_repair_table();
8942            if (unlikely(lex->m_sql_cmd == NULL))
8943              MYSQL_YYABORT;
8944          }
8945        ;
8946
8947opt_mi_repair_type:
8948          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
8949        | mi_repair_types {}
8950        ;
8951
8952mi_repair_types:
8953          mi_repair_type {}
8954        | mi_repair_type mi_repair_types {}
8955        ;
8956
8957mi_repair_type:
8958          QUICK        { Lex->check_opt.flags|= T_QUICK; }
8959        | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
8960        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; }
8961        ;
8962
8963opt_view_repair_type:
8964          /* empty */    { }
8965        | FROM MYSQL_SYM { Lex->check_opt.sql_flags|= TT_FROM_MYSQL; }
8966        ;
8967
8968analyze:
8969          ANALYZE_SYM opt_no_write_to_binlog table_or_tables
8970          {
8971            LEX *lex=Lex;
8972            lex->sql_command = SQLCOM_ANALYZE;
8973            lex->no_write_to_binlog= $2;
8974            lex->check_opt.init();
8975            lex->alter_info.reset();
8976            /* Will be overridden during execution. */
8977            YYPS->m_lock_type= TL_UNLOCK;
8978          }
8979          analyze_table_list
8980          {
8981            LEX* lex= thd->lex;
8982            DBUG_ASSERT(!lex->m_sql_cmd);
8983            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_analyze_table();
8984            if (unlikely(lex->m_sql_cmd == NULL))
8985              MYSQL_YYABORT;
8986          }
8987        ;
8988
8989analyze_table_list:
8990          analyze_table_elem_spec
8991        | analyze_table_list ',' analyze_table_elem_spec
8992        ;
8993
8994analyze_table_elem_spec:
8995          table_name opt_persistent_stat_clause
8996        ;
8997
8998opt_persistent_stat_clause:
8999          /* empty */
9000          {}
9001        | PERSISTENT_SYM FOR_SYM persistent_stat_spec
9002          {
9003            thd->lex->with_persistent_for_clause= TRUE;
9004          }
9005        ;
9006
9007persistent_stat_spec:
9008          ALL
9009          {}
9010        | COLUMNS persistent_column_stat_spec INDEXES persistent_index_stat_spec
9011          {}
9012        ;
9013
9014persistent_column_stat_spec:
9015          ALL {}
9016        | '('
9017          {
9018            LEX* lex= thd->lex;
9019            lex->column_list= new (thd->mem_root) List<LEX_STRING>;
9020            if (unlikely(lex->column_list == NULL))
9021              MYSQL_YYABORT;
9022          }
9023          table_column_list
9024          ')'
9025          { }
9026        ;
9027
9028persistent_index_stat_spec:
9029          ALL {}
9030        | '('
9031          {
9032            LEX* lex= thd->lex;
9033            lex->index_list= new (thd->mem_root) List<LEX_STRING>;
9034            if (unlikely(lex->index_list == NULL))
9035              MYSQL_YYABORT;
9036          }
9037          table_index_list
9038          ')'
9039          { }
9040        ;
9041
9042table_column_list:
9043          /* empty */
9044          {}
9045        | ident
9046          {
9047            Lex->column_list->push_back((LEX_STRING*)
9048                thd->memdup(&$1, sizeof(LEX_STRING)), thd->mem_root);
9049          }
9050        | table_column_list ',' ident
9051          {
9052            Lex->column_list->push_back((LEX_STRING*)
9053                thd->memdup(&$3, sizeof(LEX_STRING)), thd->mem_root);
9054          }
9055        ;
9056
9057table_index_list:
9058          /* empty */
9059          {}
9060        | table_index_name
9061        | table_index_list ',' table_index_name
9062        ;
9063
9064table_index_name:
9065          ident
9066          {
9067            Lex->index_list->push_back((LEX_STRING*)
9068                                       thd->memdup(&$1, sizeof(LEX_STRING)),
9069                                       thd->mem_root);
9070          }
9071        |
9072          PRIMARY_SYM
9073          {
9074            LEX_STRING str= {(char*) "PRIMARY", 7};
9075            Lex->index_list->push_back((LEX_STRING*)
9076                                        thd->memdup(&str, sizeof(LEX_STRING)),
9077                                        thd->mem_root);
9078          }
9079        ;
9080
9081binlog_base64_event:
9082          BINLOG_SYM TEXT_STRING_sys
9083          {
9084            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
9085            Lex->comment= $2;
9086            Lex->ident.str=    NULL;
9087            Lex->ident.length= 0;
9088          }
9089          |
9090          BINLOG_SYM '@' ident_or_text ',' '@' ident_or_text
9091          {
9092            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
9093            Lex->comment= $3;
9094            Lex->ident=   $6;
9095          }
9096          ;
9097
9098check_view_or_table:
9099          table_or_tables table_list opt_mi_check_type
9100        | VIEW_SYM
9101          { Lex->table_type= TABLE_TYPE_VIEW; }
9102          table_list opt_view_check_type
9103        ;
9104
9105check:    CHECK_SYM
9106          {
9107            LEX *lex=Lex;
9108
9109            lex->sql_command = SQLCOM_CHECK;
9110            lex->check_opt.init();
9111            lex->alter_info.reset();
9112            /* Will be overridden during execution. */
9113            YYPS->m_lock_type= TL_UNLOCK;
9114          }
9115          check_view_or_table
9116          {
9117            LEX* lex= thd->lex;
9118            if (unlikely(lex->sphead))
9119              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "CHECK"));
9120            DBUG_ASSERT(!lex->m_sql_cmd);
9121            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_check_table();
9122            if (unlikely(lex->m_sql_cmd == NULL))
9123              MYSQL_YYABORT;
9124          }
9125        ;
9126
9127opt_mi_check_type:
9128          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
9129        | mi_check_types {}
9130        ;
9131
9132mi_check_types:
9133          mi_check_type {}
9134        | mi_check_type mi_check_types {}
9135        ;
9136
9137mi_check_type:
9138          QUICK               { Lex->check_opt.flags|= T_QUICK; }
9139        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
9140        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
9141        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
9142        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
9143        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
9144        ;
9145
9146opt_view_check_type:
9147          /* empty */         { }
9148        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
9149        ;
9150
9151optimize:
9152          OPTIMIZE opt_no_write_to_binlog table_or_tables
9153          {
9154            LEX *lex=Lex;
9155            lex->sql_command = SQLCOM_OPTIMIZE;
9156            lex->no_write_to_binlog= $2;
9157            lex->check_opt.init();
9158            lex->alter_info.reset();
9159            /* Will be overridden during execution. */
9160            YYPS->m_lock_type= TL_UNLOCK;
9161          }
9162          table_list opt_lock_wait_timeout
9163          {
9164            LEX* lex= thd->lex;
9165            DBUG_ASSERT(!lex->m_sql_cmd);
9166            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_optimize_table();
9167            if (unlikely(lex->m_sql_cmd == NULL))
9168              MYSQL_YYABORT;
9169          }
9170        ;
9171
9172opt_no_write_to_binlog:
9173          /* empty */ { $$= 0; }
9174        | NO_WRITE_TO_BINLOG { $$= 1; }
9175        | LOCAL_SYM { $$= 1; }
9176        ;
9177
9178rename:
9179          RENAME table_or_tables
9180          {
9181            Lex->sql_command= SQLCOM_RENAME_TABLE;
9182            if (Lex->main_select_push())
9183              MYSQL_YYABORT;
9184          }
9185          table_to_table_list
9186          {
9187            Lex->pop_select(); //main select
9188          }
9189        | RENAME USER_SYM clear_privileges rename_list
9190          {
9191            Lex->sql_command = SQLCOM_RENAME_USER;
9192          }
9193        ;
9194
9195rename_list:
9196          user TO_SYM user
9197          {
9198            if (unlikely(Lex->users_list.push_back($1, thd->mem_root) ||
9199                         Lex->users_list.push_back($3, thd->mem_root)))
9200              MYSQL_YYABORT;
9201          }
9202        | rename_list ',' user TO_SYM user
9203          {
9204            if (unlikely(Lex->users_list.push_back($3, thd->mem_root) ||
9205                         Lex->users_list.push_back($5, thd->mem_root)))
9206              MYSQL_YYABORT;
9207          }
9208        ;
9209
9210table_to_table_list:
9211          table_to_table
9212        | table_to_table_list ',' table_to_table
9213        ;
9214
9215table_to_table:
9216          table_ident opt_lock_wait_timeout TO_SYM table_ident
9217          {
9218            LEX *lex=Lex;
9219            SELECT_LEX *sl= lex->current_select;
9220            if (unlikely(!sl->add_table_to_list(thd, $1,NULL,
9221                                                TL_OPTION_UPDATING,
9222                                                TL_IGNORE, MDL_EXCLUSIVE)) ||
9223                unlikely(!sl->add_table_to_list(thd, $4, NULL,
9224                                                TL_OPTION_UPDATING,
9225                                                TL_IGNORE, MDL_EXCLUSIVE)))
9226              MYSQL_YYABORT;
9227          }
9228        ;
9229
9230keycache:
9231          CACHE_SYM INDEX_SYM
9232          {
9233            Lex->alter_info.reset();
9234          }
9235          keycache_list_or_parts IN_SYM key_cache_name
9236          {
9237            LEX *lex=Lex;
9238            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
9239            lex->ident= $6;
9240          }
9241        ;
9242
9243keycache_list_or_parts:
9244          keycache_list
9245        | assign_to_keycache_parts
9246        ;
9247
9248keycache_list:
9249          assign_to_keycache
9250        | keycache_list ',' assign_to_keycache
9251        ;
9252
9253assign_to_keycache:
9254          table_ident cache_keys_spec
9255          {
9256            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, 0, TL_READ,
9257                                                    MDL_SHARED_READ,
9258                                                    Select->
9259                                                    pop_index_hints())))
9260              MYSQL_YYABORT;
9261          }
9262        ;
9263
9264assign_to_keycache_parts:
9265          table_ident adm_partition cache_keys_spec
9266          {
9267            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, 0, TL_READ,
9268                                                    MDL_SHARED_READ,
9269                                                    Select->
9270                                                    pop_index_hints())))
9271              MYSQL_YYABORT;
9272          }
9273        ;
9274
9275key_cache_name:
9276          ident    { $$= $1; }
9277        | DEFAULT  { $$ = default_key_cache_base; }
9278        ;
9279
9280preload:
9281          LOAD INDEX_SYM INTO CACHE_SYM
9282          {
9283            LEX *lex=Lex;
9284            lex->sql_command=SQLCOM_PRELOAD_KEYS;
9285            lex->alter_info.reset();
9286            if (lex->main_select_push())
9287              MYSQL_YYABORT;
9288          }
9289          preload_list_or_parts
9290          {
9291            Lex->pop_select(); //main select
9292          }
9293        ;
9294
9295preload_list_or_parts:
9296          preload_keys_parts
9297        | preload_list
9298        ;
9299
9300preload_list:
9301          preload_keys
9302        | preload_list ',' preload_keys
9303        ;
9304
9305preload_keys:
9306          table_ident cache_keys_spec opt_ignore_leaves
9307          {
9308            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, $3, TL_READ,
9309                                                    MDL_SHARED_READ,
9310                                                    Select->
9311                                                    pop_index_hints())))
9312              MYSQL_YYABORT;
9313          }
9314        ;
9315
9316preload_keys_parts:
9317          table_ident adm_partition cache_keys_spec opt_ignore_leaves
9318          {
9319            if (unlikely(!Select->add_table_to_list(thd, $1, NULL, $4, TL_READ,
9320                                                    MDL_SHARED_READ,
9321                                                    Select->
9322                                                    pop_index_hints())))
9323              MYSQL_YYABORT;
9324          }
9325        ;
9326
9327adm_partition:
9328          PARTITION_SYM have_partitioning
9329          {
9330            Lex->alter_info.partition_flags|= ALTER_PARTITION_ADMIN;
9331          }
9332          '(' all_or_alt_part_name_list ')'
9333        ;
9334
9335cache_keys_spec:
9336          {
9337            Lex->first_select_lex()->alloc_index_hints(thd);
9338            Lex->first_select_lex()->set_index_hint_type(INDEX_HINT_USE,
9339                                                         INDEX_HINT_MASK_ALL);
9340          }
9341          cache_key_list_or_empty
9342        ;
9343
9344cache_key_list_or_empty:
9345          /* empty */ { }
9346        | key_or_index '(' opt_key_usage_list ')'
9347        ;
9348
9349opt_ignore_leaves:
9350          /* empty */
9351          { $$= 0; }
9352        | IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
9353        ;
9354
9355/*
9356  Select : retrieve data from table
9357*/
9358
9359select:
9360          query_expression_no_with_clause
9361          {
9362            if (Lex->push_select($1->fake_select_lex ?
9363                                 $1->fake_select_lex :
9364                                 $1->first_select()))
9365              MYSQL_YYABORT;
9366          }
9367          opt_procedure_or_into
9368          {
9369            Lex->pop_select();
9370            $1->set_with_clause(NULL);
9371            if (Lex->select_finalize($1, $3))
9372              MYSQL_YYABORT;
9373          }
9374        | with_clause query_expression_no_with_clause
9375          {
9376            if (Lex->push_select($2->fake_select_lex ?
9377                                 $2->fake_select_lex :
9378                                 $2->first_select()))
9379              MYSQL_YYABORT;
9380          }
9381          opt_procedure_or_into
9382          {
9383            Lex->pop_select();
9384            $2->set_with_clause($1);
9385            $1->attach_to($2->first_select());
9386            if (Lex->select_finalize($2, $4))
9387              MYSQL_YYABORT;
9388          }
9389        ;
9390
9391
9392select_into:
9393          select_into_query_specification
9394          {
9395            if (Lex->push_select($1))
9396              MYSQL_YYABORT;
9397          }
9398          opt_order_limit_lock
9399          {
9400            SELECT_LEX_UNIT *unit;
9401            if (!(unit  = Lex->create_unit($1)))
9402              MYSQL_YYABORT;
9403            if ($3)
9404              unit= Lex->add_tail_to_query_expression_body(unit, $3);
9405            if (Lex->select_finalize(unit))
9406              MYSQL_YYABORT;
9407           }
9408        | with_clause
9409          select_into_query_specification
9410          {
9411            if (Lex->push_select($2))
9412              MYSQL_YYABORT;
9413          }
9414          opt_order_limit_lock
9415          {
9416            SELECT_LEX_UNIT *unit;
9417            if (!(unit  = Lex->create_unit($2)))
9418              MYSQL_YYABORT;
9419            if ($4)
9420              unit= Lex->add_tail_to_query_expression_body(unit, $4);
9421            unit->set_with_clause($1);
9422            $1->attach_to($2);
9423            if (Lex->select_finalize(unit))
9424              MYSQL_YYABORT;
9425          }
9426         ;
9427
9428
9429simple_table:
9430          query_specification      { $$= $1; }
9431        | table_value_constructor  { $$= $1; }
9432        ;
9433
9434table_value_constructor:
9435	  VALUES
9436	  {
9437            if (Lex->parsed_TVC_start())
9438              MYSQL_YYABORT;
9439	  }
9440	  values_list
9441	  {
9442            if (!($$= Lex->parsed_TVC_end()))
9443	      MYSQL_YYABORT;
9444	  }
9445	;
9446
9447query_specification_start:
9448          SELECT_SYM
9449          {
9450            SELECT_LEX *sel;
9451            LEX *lex= Lex;
9452            if (!(sel= lex->alloc_select(TRUE)) ||
9453                  lex->push_select(sel))
9454              MYSQL_YYABORT;
9455            sel->init_select();
9456            sel->braces= FALSE;
9457          }
9458          select_options
9459          {
9460            Select->parsing_place= SELECT_LIST;
9461          }
9462          select_item_list
9463          {
9464            Select->parsing_place= NO_MATTER;
9465          }
9466          ;
9467
9468query_specification:
9469          query_specification_start
9470          opt_from_clause
9471          opt_where_clause
9472          opt_group_clause
9473          opt_having_clause
9474          opt_window_clause
9475          {
9476            $$= Lex->pop_select();
9477          }
9478        ;
9479
9480select_into_query_specification:
9481          query_specification_start
9482          into
9483          opt_from_clause
9484          opt_where_clause
9485          opt_group_clause
9486          opt_having_clause
9487          opt_window_clause
9488          {
9489            $$= Lex->pop_select();
9490          }
9491        ;
9492
9493/**
9494
9495  The following grammar for query expressions conformant to
9496  the latest SQL Standard is supported:
9497
9498    <query expression> ::=
9499     [ <with clause> ] <query expression body>
9500       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
9501
9502   <with clause> ::=
9503     WITH [ RECURSIVE ] <with_list
9504
9505   <with list> ::=
9506     <with list element> [ { <comma> <with list element> }... ]
9507
9508   <with list element> ::=
9509     <query name> [ '(' <with column list> ')' ]
9510         AS <table subquery>
9511
9512   <with column list> ::=
9513     <column name list>
9514
9515   <query expression body> ::
9516       <query term>
9517     | <query expression body> UNION [ ALL | DISTINCT ] <query term>
9518     | <query expression body> EXCEPT [ DISTINCT ] <query term>
9519
9520   <query term> ::=
9521       <query primary>
9522     | <query term> INTERSECT [ DISTINCT ] <query primary>
9523
9524   <query primary> ::=
9525       <simple table>
9526     | '(' <query expression body>
9527       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
9528       ')'
9529
9530   <simple table>
9531       <query specification>
9532     | <table value constructor>
9533
9534  <subquery>
9535       '(' <query_expression> ')'
9536
9537*/
9538
9539/*
9540  query_expression produces the same expressions as
9541      <query expression>
9542*/
9543
9544query_expression:
9545          query_expression_no_with_clause
9546          {
9547            $1->set_with_clause(NULL);
9548            $$= $1;
9549          }
9550        | with_clause
9551          query_expression_no_with_clause
9552          {
9553            $2->set_with_clause($1);
9554            $1->attach_to($2->first_select());
9555            $$= $2;
9556          }
9557        ;
9558
9559/*
9560   query_expression_no_with_clause produces the same expressions as
9561       <query expression> without [ <with clause> ]
9562*/
9563
9564query_expression_no_with_clause:
9565          query_expression_body_ext { $$= $1; }
9566        | query_expression_body_ext_parens { $$= $1; }
9567        ;
9568
9569/*
9570  query_expression_body_ext produces the same expressions as
9571      <query expression body>
9572       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
9573    | '('... <query expression body>
9574       [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
9575      ')'...
9576  Note: number of ')' must be equal to the number of '(' in the rule above
9577*/
9578
9579query_expression_body_ext:
9580          query_expression_body
9581          {
9582            if ($1->first_select()->next_select())
9583            {
9584              if (Lex->parsed_multi_operand_query_expression_body($1))
9585                MYSQL_YYABORT;
9586            }
9587          }
9588          opt_query_expression_tail
9589          {
9590            if (!$3)
9591              $$= $1;
9592            else
9593              $$= Lex->add_tail_to_query_expression_body($1, $3);
9594          }
9595        | query_expression_body_ext_parens
9596          {
9597            Lex->push_select(!$1->first_select()->next_select() ?
9598                               $1->first_select() : $1->fake_select_lex);
9599          }
9600          query_expression_tail
9601          {
9602            if (!($$= Lex->add_tail_to_query_expression_body_ext_parens($1, $3)))
9603               MYSQL_YYABORT;
9604          }
9605        ;
9606
9607query_expression_body_ext_parens:
9608          '(' query_expression_body_ext_parens ')'
9609          { $$= $2; }
9610        | '(' query_expression_body_ext ')'
9611          {
9612            SELECT_LEX *sel= $2->first_select()->next_select() ?
9613                               $2->fake_select_lex : $2->first_select();
9614            sel->braces= true;
9615            $$= $2;
9616          }
9617        ;
9618
9619/*
9620  query_expression_body produces the same expressions as
9621      <query expression body>
9622*/
9623
9624query_expression_body:
9625          query_simple
9626          {
9627            Lex->push_select($1);
9628            if (!($$= Lex->create_unit($1)))
9629              MYSQL_YYABORT;
9630          }
9631        | query_expression_body
9632          unit_type_decl
9633          {
9634            if (!$1->first_select()->next_select())
9635            {
9636              Lex->pop_select();
9637            }
9638          }
9639          query_primary
9640          {
9641            if (!($$= Lex->add_primary_to_query_expression_body($1, $4,
9642                                                                $2.unit_type,
9643                                                                $2.distinct,
9644                                                                TRUE)))
9645              MYSQL_YYABORT;
9646          }
9647        | query_expression_body_ext_parens
9648          unit_type_decl
9649          query_primary
9650          {
9651            if (!($$= Lex->add_primary_to_query_expression_body_ext_parens(
9652                                                                $1, $3,
9653                                                                $2.unit_type,
9654                                                                $2.distinct)))
9655              MYSQL_YYABORT;
9656          }
9657        ;
9658
9659/*
9660  query_primary produces the same expressions as
9661      <query primary>
9662*/
9663
9664query_primary:
9665          query_simple
9666          { $$= $1; }
9667        | query_expression_body_ext_parens
9668          { $$= $1->first_select(); }
9669        ;
9670
9671/*
9672  query_simple produces the same expressions as
9673      <simple table>
9674*/
9675
9676query_simple:
9677          simple_table { $$= $1;}
9678        ;
9679
9680subselect:
9681          query_expression
9682          {
9683            if (!($$= Lex->parsed_subselect($1)))
9684              YYABORT;
9685          }
9686        ;
9687
9688/*
9689  subquery produces the same expressions as
9690     <subquery>
9691
9692  Consider the production rule of the SQL Standard
9693     subquery:
9694        '(' query_expression ')'
9695
9696  This rule is equivalent to the rule
9697     subquery:
9698          '(' query_expression_no_with_clause ')'
9699        | '(' with_clause query_expression_no_with_clause ')'
9700  that in its turn is equivalent to
9701     subquery:
9702          '(' query_expression_body_ext ')'
9703        | query_expression_body_ext_parens
9704        | '(' with_clause query_expression_no_with_clause ')'
9705
9706  The latter can be re-written into
9707     subquery:
9708          query_expression_body_ext_parens
9709        | '(' with_clause query_expression_no_with_clause ')'
9710
9711  The last rule allows us to resolve properly the shift/reduce conflict
9712  when subquery is used in expressions such as in the following queries
9713     select (select * from t1 limit 1) + t2.a from t2
9714     select * from t1 where t1.a [not] in (select t2.a from t2)
9715
9716  In the rule below %prec SUBQUERY_AS_EXPR forces the parser to perform a shift
9717  operation rather then a reduce operation when ')' is encountered and can be
9718  considered as the last symbol a query expression.
9719*/
9720
9721subquery:
9722          query_expression_body_ext_parens %prec SUBQUERY_AS_EXPR
9723          {
9724            if (!$1->fake_select_lex)
9725              $1->first_select()->braces= false;
9726            else
9727              $1->fake_select_lex->braces= false;
9728            if (!($$= Lex->parsed_subselect($1)))
9729              YYABORT;
9730          }
9731        | '(' with_clause query_expression_no_with_clause ')'
9732          {
9733            $3->set_with_clause($2);
9734            $2->attach_to($3->first_select());
9735            if (!($$= Lex->parsed_subselect($3)))
9736              YYABORT;
9737          }
9738        ;
9739
9740opt_from_clause:
9741        /* empty */ %prec EMPTY_FROM_CLAUSE
9742        | from_clause
9743        ;
9744
9745from_clause:
9746          FROM table_reference_list
9747        ;
9748
9749table_reference_list:
9750          join_table_list
9751          {
9752            Select->context.table_list=
9753              Select->context.first_name_resolution_table=
9754                Select->table_list.first;
9755          }
9756        | DUAL_SYM
9757          /* oracle compatibility: oracle always requires FROM clause,
9758             and DUAL is system table without fields.
9759             Is "SELECT 1 FROM DUAL" any better than "SELECT 1" ?
9760          Hmmm :) */
9761        ;
9762
9763select_options:
9764          /* empty*/
9765        | select_option_list
9766          {
9767            if (unlikely((Select->options & SELECT_DISTINCT) &&
9768                         (Select->options & SELECT_ALL)))
9769              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT"));
9770          }
9771        ;
9772
9773opt_history_unit:
9774          /* empty*/         %prec PREC_BELOW_IDENTIFIER_OPT_SPECIAL_CASE
9775          {
9776            $$= VERS_UNDEFINED;
9777          }
9778        | TRANSACTION_SYM
9779          {
9780            $$= VERS_TRX_ID;
9781          }
9782        | TIMESTAMP
9783          {
9784            $$= VERS_TIMESTAMP;
9785          }
9786        ;
9787
9788history_point:
9789          TIMESTAMP TEXT_STRING
9790          {
9791            Item *item;
9792            if (!(item= type_handler_datetime2.create_literal_item(thd,
9793                                                      $2.str, $2.length,
9794                                                      YYCSCL, true)))
9795              MYSQL_YYABORT;
9796            $$= Vers_history_point(VERS_TIMESTAMP, item);
9797          }
9798        | function_call_keyword_timestamp
9799          {
9800            $$= Vers_history_point(VERS_TIMESTAMP, $1);
9801          }
9802        | opt_history_unit bit_expr
9803          {
9804            $$= Vers_history_point($1, $2);
9805          }
9806        ;
9807
9808for_portion_of_time_clause:
9809          FOR_SYM PORTION_SYM OF_SYM remember_tok_start ident FROM
9810          bit_expr TO_SYM bit_expr
9811          {
9812            if (unlikely(0 == strcasecmp($5.str, "SYSTEM_TIME")))
9813            {
9814              thd->parse_error(ER_SYNTAX_ERROR, $4);
9815              MYSQL_YYABORT;
9816            }
9817            Lex->period_conditions.init(SYSTEM_TIME_FROM_TO,
9818                                        Vers_history_point(VERS_TIMESTAMP, $7),
9819                                        Vers_history_point(VERS_TIMESTAMP, $9),
9820                                        $5);
9821          }
9822        ;
9823
9824opt_for_portion_of_time_clause:
9825          /* empty */
9826          {
9827            $$= false;
9828          }
9829        | for_portion_of_time_clause
9830            {
9831            $$= true;
9832          }
9833        ;
9834
9835opt_for_system_time_clause:
9836          /* empty */
9837          {
9838            $$= false;
9839          }
9840        | FOR_SYSTEM_TIME_SYM system_time_expr
9841          {
9842            $$= true;
9843          }
9844        ;
9845
9846system_time_expr:
9847          AS OF_SYM history_point
9848          {
9849            Lex->vers_conditions.init(SYSTEM_TIME_AS_OF, $3);
9850          }
9851        | ALL
9852          {
9853            Lex->vers_conditions.init(SYSTEM_TIME_ALL);
9854          }
9855        | FROM history_point TO_SYM history_point
9856          {
9857            Lex->vers_conditions.init(SYSTEM_TIME_FROM_TO, $2, $4);
9858          }
9859        | BETWEEN_SYM history_point AND_SYM history_point
9860          {
9861            Lex->vers_conditions.init(SYSTEM_TIME_BETWEEN, $2, $4);
9862          }
9863        ;
9864
9865select_option_list:
9866          select_option_list select_option
9867        | select_option
9868        ;
9869
9870select_option:
9871          query_expression_option
9872        | SQL_NO_CACHE_SYM
9873          {
9874            /*
9875              Allow this flag once per query.
9876            */
9877            if (Select->options & OPTION_NO_QUERY_CACHE)
9878              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "SQL_NO_CACHE"));
9879            Select->options|= OPTION_NO_QUERY_CACHE;
9880          }
9881        | SQL_CACHE_SYM
9882          {
9883            /*
9884              Allow this flag once per query.
9885            */
9886            if (Select->options & OPTION_TO_QUERY_CACHE)
9887              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "SQL_CACHE"));
9888            Select->options|= OPTION_TO_QUERY_CACHE;
9889          }
9890        ;
9891
9892
9893select_lock_type:
9894          FOR_SYM UPDATE_SYM opt_lock_wait_timeout_new
9895          {
9896            $$= $3;
9897            $$.defined_lock= TRUE;
9898            $$.update_lock= TRUE;
9899          }
9900        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM opt_lock_wait_timeout_new
9901          {
9902            $$= $5;
9903            $$.defined_lock= TRUE;
9904            $$.update_lock= FALSE;
9905          }
9906        ;
9907
9908opt_select_lock_type:
9909        /* empty */
9910        {
9911          $$.empty();
9912        }
9913        | select_lock_type
9914        {
9915          $$= $1;
9916        }
9917        ;
9918
9919opt_lock_wait_timeout_new:
9920        /* empty */
9921        {
9922          $$.empty();
9923        }
9924        | WAIT_SYM ulong_num
9925        {
9926          $$.defined_timeout= TRUE;
9927          $$.timeout= $2;
9928        }
9929        | NOWAIT_SYM
9930        {
9931          $$.defined_timeout= TRUE;
9932          $$.timeout= 0;
9933        }
9934      ;
9935
9936select_item_list:
9937          select_item_list ',' select_item
9938        | select_item
9939        | '*'
9940          {
9941            Item *item= new (thd->mem_root)
9942                          Item_field(thd, &thd->lex->current_select->context,
9943                                     NULL, NULL, &star_clex_str);
9944            if (unlikely(item == NULL))
9945              MYSQL_YYABORT;
9946            if (unlikely(add_item_to_list(thd, item)))
9947              MYSQL_YYABORT;
9948            (thd->lex->current_select->with_wild)++;
9949          }
9950        ;
9951
9952select_item:
9953          remember_name select_sublist_qualified_asterisk remember_end
9954          {
9955            if (unlikely(add_item_to_list(thd, $2)))
9956              MYSQL_YYABORT;
9957          }
9958        | remember_name expr remember_end select_alias
9959          {
9960            DBUG_ASSERT($1 < $3);
9961
9962            if (unlikely(add_item_to_list(thd, $2)))
9963              MYSQL_YYABORT;
9964            if ($4.str)
9965            {
9966              if (unlikely(Lex->sql_command == SQLCOM_CREATE_VIEW &&
9967                          check_column_name($4.str)))
9968                my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), $4.str));
9969              $2->is_autogenerated_name= FALSE;
9970              $2->set_name(thd, $4.str, $4.length, system_charset_info);
9971            }
9972            else if (!$2->name.str || $2->name.str == item_empty_name)
9973            {
9974              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
9975            }
9976          }
9977        ;
9978
9979remember_tok_start:
9980          {
9981            $$= (char*) YYLIP->get_tok_start();
9982          }
9983        ;
9984
9985remember_name:
9986          {
9987            $$= (char*) YYLIP->get_cpp_tok_start();
9988          }
9989        ;
9990
9991remember_end:
9992          {
9993            $$= (char*) YYLIP->get_cpp_tok_end_rtrim();
9994          }
9995        ;
9996
9997remember_end_opt:
9998          {
9999            if (yychar == YYEMPTY)
10000              $$= (char*) YYLIP->get_cpp_ptr_rtrim();
10001            else
10002              $$= (char*) YYLIP->get_cpp_tok_end_rtrim();
10003          }
10004        ;
10005
10006select_alias:
10007          /* empty */ { $$=null_clex_str;}
10008        | AS ident { $$=$2; }
10009        | AS TEXT_STRING_sys { $$=$2; }
10010        | ident { $$=$1; }
10011        | TEXT_STRING_sys { $$=$1; }
10012        ;
10013
10014opt_default_time_precision:
10015          /* empty */             { $$= NOT_FIXED_DEC;  }
10016        | '(' ')'                 { $$= NOT_FIXED_DEC;  }
10017        | '(' real_ulong_num ')'  { $$= $2; }
10018        ;
10019
10020opt_time_precision:
10021          /* empty */             { $$= 0;  }
10022        | '(' ')'                 { $$= 0;  }
10023        | '(' real_ulong_num ')'  { $$= $2; }
10024        ;
10025
10026optional_braces:
10027          /* empty */ {}
10028        | '(' ')' {}
10029        ;
10030
10031/* all possible expressions */
10032expr:
10033          expr or expr %prec OR_SYM
10034          {
10035            /*
10036              Design notes:
10037              Do not use a manually maintained stack like thd->lex->xxx_list,
10038              but use the internal bison stack ($$, $1 and $3) instead.
10039              Using the bison stack is:
10040              - more robust to changes in the grammar,
10041              - guaranteed to be in sync with the parser state,
10042              - better for performances (no memory allocation).
10043            */
10044            Item_cond_or *item1;
10045            Item_cond_or *item3;
10046            if (is_cond_or($1))
10047            {
10048              item1= (Item_cond_or*) $1;
10049              if (is_cond_or($3))
10050              {
10051                item3= (Item_cond_or*) $3;
10052                /*
10053                  (X1 OR X2) OR (Y1 OR Y2) ==> OR (X1, X2, Y1, Y2)
10054                */
10055                item3->add_at_head(item1->argument_list());
10056                $$ = $3;
10057              }
10058              else
10059              {
10060                /*
10061                  (X1 OR X2) OR Y ==> OR (X1, X2, Y)
10062                */
10063                item1->add($3, thd->mem_root);
10064                $$ = $1;
10065              }
10066            }
10067            else if (is_cond_or($3))
10068            {
10069              item3= (Item_cond_or*) $3;
10070              /*
10071                X OR (Y1 OR Y2) ==> OR (X, Y1, Y2)
10072              */
10073              item3->add_at_head($1, thd->mem_root);
10074              $$ = $3;
10075            }
10076            else
10077            {
10078              /* X OR Y */
10079              $$= new (thd->mem_root) Item_cond_or(thd, $1, $3);
10080              if (unlikely($$ == NULL))
10081                MYSQL_YYABORT;
10082            }
10083          }
10084        | expr XOR expr %prec XOR
10085          {
10086            /* XOR is a proprietary extension */
10087            $$= new (thd->mem_root) Item_func_xor(thd, $1, $3);
10088            if (unlikely($$ == NULL))
10089              MYSQL_YYABORT;
10090          }
10091        | expr and expr %prec AND_SYM
10092          {
10093            /* See comments in rule expr: expr or expr */
10094            Item_cond_and *item1;
10095            Item_cond_and *item3;
10096            if (is_cond_and($1))
10097            {
10098              item1= (Item_cond_and*) $1;
10099              if (is_cond_and($3))
10100              {
10101                item3= (Item_cond_and*) $3;
10102                /*
10103                  (X1 AND X2) AND (Y1 AND Y2) ==> AND (X1, X2, Y1, Y2)
10104                */
10105                item3->add_at_head(item1->argument_list());
10106                $$ = $3;
10107              }
10108              else
10109              {
10110                /*
10111                  (X1 AND X2) AND Y ==> AND (X1, X2, Y)
10112                */
10113                item1->add($3, thd->mem_root);
10114                $$ = $1;
10115              }
10116            }
10117            else if (is_cond_and($3))
10118            {
10119              item3= (Item_cond_and*) $3;
10120              /*
10121                X AND (Y1 AND Y2) ==> AND (X, Y1, Y2)
10122              */
10123              item3->add_at_head($1, thd->mem_root);
10124              $$ = $3;
10125            }
10126            else
10127            {
10128              /* X AND Y */
10129              $$= new (thd->mem_root) Item_cond_and(thd, $1, $3);
10130              if (unlikely($$ == NULL))
10131                MYSQL_YYABORT;
10132            }
10133          }
10134        | NOT_SYM expr %prec NOT_SYM
10135          {
10136            $$= negate_expression(thd, $2);
10137            if (unlikely($$ == NULL))
10138              MYSQL_YYABORT;
10139          }
10140        | expr IS TRUE_SYM %prec IS
10141          {
10142            $$= new (thd->mem_root) Item_func_istrue(thd, $1);
10143            if (unlikely($$ == NULL))
10144              MYSQL_YYABORT;
10145          }
10146        | expr IS not TRUE_SYM %prec IS
10147          {
10148            $$= new (thd->mem_root) Item_func_isnottrue(thd, $1);
10149            if (unlikely($$ == NULL))
10150              MYSQL_YYABORT;
10151          }
10152        | expr IS FALSE_SYM %prec IS
10153          {
10154            $$= new (thd->mem_root) Item_func_isfalse(thd, $1);
10155            if (unlikely($$ == NULL))
10156              MYSQL_YYABORT;
10157          }
10158        | expr IS not FALSE_SYM %prec IS
10159          {
10160            $$= new (thd->mem_root) Item_func_isnotfalse(thd, $1);
10161            if (unlikely($$ == NULL))
10162              MYSQL_YYABORT;
10163          }
10164        | expr IS UNKNOWN_SYM %prec IS
10165          {
10166            $$= new (thd->mem_root) Item_func_isnull(thd, $1);
10167            if (unlikely($$ == NULL))
10168              MYSQL_YYABORT;
10169          }
10170        | expr IS not UNKNOWN_SYM %prec IS
10171          {
10172            $$= new (thd->mem_root) Item_func_isnotnull(thd, $1);
10173            if (unlikely($$ == NULL))
10174              MYSQL_YYABORT;
10175          }
10176        | expr IS NULL_SYM %prec PREC_BELOW_NOT
10177          {
10178            $$= new (thd->mem_root) Item_func_isnull(thd, $1);
10179            if (unlikely($$ == NULL))
10180              MYSQL_YYABORT;
10181          }
10182        | expr IS not NULL_SYM %prec IS
10183          {
10184            $$= new (thd->mem_root) Item_func_isnotnull(thd, $1);
10185            if (unlikely($$ == NULL))
10186              MYSQL_YYABORT;
10187          }
10188        | expr EQUAL_SYM predicate %prec EQUAL_SYM
10189          {
10190            $$= new (thd->mem_root) Item_func_equal(thd, $1, $3);
10191            if (unlikely($$ == NULL))
10192              MYSQL_YYABORT;
10193          }
10194        | expr comp_op predicate %prec '='
10195          {
10196            $$= (*$2)(0)->create(thd, $1, $3);
10197            if (unlikely($$ == NULL))
10198              MYSQL_YYABORT;
10199          }
10200        | expr comp_op all_or_any '(' subselect ')' %prec '='
10201          {
10202            $$= all_any_subquery_creator(thd, $1, $2, $3, $5);
10203            if (unlikely($$ == NULL))
10204              MYSQL_YYABORT;
10205          }
10206        | predicate
10207        ;
10208
10209predicate:
10210          predicate IN_SYM subquery
10211          {
10212            $$= new (thd->mem_root) Item_in_subselect(thd, $1, $3);
10213            if (unlikely(!$$))
10214              MYSQL_YYABORT;
10215          }
10216        | predicate not IN_SYM subquery
10217          {
10218            Item *item= new (thd->mem_root) Item_in_subselect(thd, $1, $4);
10219            if (unlikely(!item))
10220              MYSQL_YYABORT;
10221            $$= negate_expression(thd, item);
10222            if (unlikely(!$$))
10223              MYSQL_YYABORT;
10224          }
10225        | predicate IN_SYM '(' expr ')'
10226          {
10227            $$= handle_sql2003_note184_exception(thd, $1, true, $4);
10228            if (unlikely($$ == NULL))
10229              MYSQL_YYABORT;
10230          }
10231        | predicate IN_SYM '(' expr ',' expr_list ')'
10232          {
10233            $6->push_front($4, thd->mem_root);
10234            $6->push_front($1, thd->mem_root);
10235            $$= new (thd->mem_root) Item_func_in(thd, *$6);
10236            if (unlikely($$ == NULL))
10237              MYSQL_YYABORT;
10238          }
10239        | predicate not IN_SYM '(' expr ')'
10240          {
10241            $$= handle_sql2003_note184_exception(thd, $1, false, $5);
10242            if (unlikely($$ == NULL))
10243              MYSQL_YYABORT;
10244          }
10245        | predicate not IN_SYM '(' expr ',' expr_list ')'
10246          {
10247            $7->push_front($5, thd->mem_root);
10248            $7->push_front($1, thd->mem_root);
10249            Item_func_in *item= new (thd->mem_root) Item_func_in(thd, *$7);
10250            if (unlikely(item == NULL))
10251              MYSQL_YYABORT;
10252            $$= item->neg_transformer(thd);
10253          }
10254        | predicate BETWEEN_SYM predicate AND_SYM predicate %prec BETWEEN_SYM
10255          {
10256            $$= new (thd->mem_root) Item_func_between(thd, $1, $3, $5);
10257            if (unlikely($$ == NULL))
10258              MYSQL_YYABORT;
10259          }
10260        | predicate not BETWEEN_SYM predicate AND_SYM predicate %prec BETWEEN_SYM
10261          {
10262            Item_func_between *item;
10263            item= new (thd->mem_root) Item_func_between(thd, $1, $4, $6);
10264            if (unlikely(item == NULL))
10265              MYSQL_YYABORT;
10266            $$= item->neg_transformer(thd);
10267          }
10268        | predicate SOUNDS_SYM LIKE predicate
10269          {
10270            Item *item1= new (thd->mem_root) Item_func_soundex(thd, $1);
10271            Item *item4= new (thd->mem_root) Item_func_soundex(thd, $4);
10272            if (unlikely(item1 == NULL) || unlikely(item4 == NULL))
10273              MYSQL_YYABORT;
10274            $$= new (thd->mem_root) Item_func_eq(thd, item1, item4);
10275            if (unlikely($$ == NULL))
10276              MYSQL_YYABORT;
10277          }
10278        | predicate LIKE predicate
10279          {
10280            $$= new (thd->mem_root) Item_func_like(thd, $1, $3, escape(thd), false);
10281            if (unlikely(!$$))
10282              MYSQL_YYABORT;
10283          }
10284        | predicate LIKE predicate ESCAPE_SYM predicate %prec LIKE
10285          {
10286            Lex->escape_used= true;
10287            $$= new (thd->mem_root) Item_func_like(thd, $1, $3, $5, true);
10288            if (unlikely(!$$))
10289              MYSQL_YYABORT;
10290          }
10291        | predicate not LIKE predicate
10292          {
10293            Item *item= new (thd->mem_root) Item_func_like(thd, $1, $4, escape(thd), false);
10294            if (unlikely(!item))
10295              MYSQL_YYABORT;
10296            $$= item->neg_transformer(thd);
10297          }
10298        | predicate not LIKE predicate ESCAPE_SYM predicate %prec LIKE
10299          {
10300            Lex->escape_used= true;
10301            Item *item= new (thd->mem_root) Item_func_like(thd, $1, $4, $6, true);
10302            if (unlikely(!item))
10303              MYSQL_YYABORT;
10304            $$= item->neg_transformer(thd);
10305          }
10306        | predicate REGEXP predicate
10307          {
10308            $$= new (thd->mem_root) Item_func_regex(thd, $1, $3);
10309            if (unlikely($$ == NULL))
10310              MYSQL_YYABORT;
10311          }
10312        | predicate not REGEXP predicate
10313          {
10314            Item *item= new (thd->mem_root) Item_func_regex(thd, $1, $4);
10315            if (unlikely(item == NULL))
10316              MYSQL_YYABORT;
10317            $$= negate_expression(thd, item);
10318            if (unlikely($$ == NULL))
10319              MYSQL_YYABORT;
10320          }
10321        | bit_expr %prec PREC_BELOW_NOT
10322        ;
10323
10324bit_expr:
10325          bit_expr '|' bit_expr %prec '|'
10326          {
10327            $$= new (thd->mem_root) Item_func_bit_or(thd, $1, $3);
10328            if (unlikely($$ == NULL))
10329              MYSQL_YYABORT;
10330          }
10331        | bit_expr '&' bit_expr %prec '&'
10332          {
10333            $$= new (thd->mem_root) Item_func_bit_and(thd, $1, $3);
10334            if (unlikely($$ == NULL))
10335              MYSQL_YYABORT;
10336          }
10337        | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
10338          {
10339            $$= new (thd->mem_root) Item_func_shift_left(thd, $1, $3);
10340            if (unlikely($$ == NULL))
10341              MYSQL_YYABORT;
10342          }
10343        | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
10344          {
10345            $$= new (thd->mem_root) Item_func_shift_right(thd, $1, $3);
10346            if (unlikely($$ == NULL))
10347              MYSQL_YYABORT;
10348          }
10349        | bit_expr ORACLE_CONCAT_SYM bit_expr
10350          {
10351            $$= new (thd->mem_root) Item_func_concat_operator_oracle(thd,
10352                                                                     $1, $3);
10353            if (unlikely($$ == NULL))
10354              MYSQL_YYABORT;
10355          }
10356        | bit_expr '+' bit_expr %prec '+'
10357          {
10358            $$= new (thd->mem_root) Item_func_plus(thd, $1, $3);
10359            if (unlikely($$ == NULL))
10360              MYSQL_YYABORT;
10361          }
10362        | bit_expr '-' bit_expr %prec '-'
10363          {
10364            $$= new (thd->mem_root) Item_func_minus(thd, $1, $3);
10365            if (unlikely($$ == NULL))
10366              MYSQL_YYABORT;
10367          }
10368        | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
10369          {
10370            $$= new (thd->mem_root) Item_date_add_interval(thd, $1, $4, $5, 0);
10371            if (unlikely($$ == NULL))
10372              MYSQL_YYABORT;
10373          }
10374        | bit_expr '-' INTERVAL_SYM expr interval %prec '-'
10375          {
10376            $$= new (thd->mem_root) Item_date_add_interval(thd, $1, $4, $5, 1);
10377            if (unlikely($$ == NULL))
10378              MYSQL_YYABORT;
10379          }
10380        | INTERVAL_SYM expr interval '+' expr
10381          /* we cannot put interval before - */
10382          {
10383            $$= new (thd->mem_root) Item_date_add_interval(thd, $5, $2, $3, 0);
10384            if (unlikely($$ == NULL))
10385              MYSQL_YYABORT;
10386          }
10387        | '+' INTERVAL_SYM expr interval '+' expr %prec NEG
10388          {
10389            $$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 0);
10390            if (unlikely($$ == NULL))
10391              MYSQL_YYABORT;
10392          }
10393        | '-' INTERVAL_SYM expr interval '+' expr %prec NEG
10394          {
10395            $$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 1);
10396            if (unlikely($$ == NULL))
10397              MYSQL_YYABORT;
10398          }
10399        | bit_expr '*' bit_expr %prec '*'
10400          {
10401            $$= new (thd->mem_root) Item_func_mul(thd, $1, $3);
10402            if (unlikely($$ == NULL))
10403              MYSQL_YYABORT;
10404          }
10405        | bit_expr '/' bit_expr %prec '/'
10406          {
10407            $$= new (thd->mem_root) Item_func_div(thd, $1, $3);
10408            if (unlikely($$ == NULL))
10409              MYSQL_YYABORT;
10410          }
10411        | bit_expr '%' bit_expr %prec '%'
10412          {
10413            $$= new (thd->mem_root) Item_func_mod(thd, $1, $3);
10414            if (unlikely($$ == NULL))
10415              MYSQL_YYABORT;
10416          }
10417        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
10418          {
10419            $$= new (thd->mem_root) Item_func_int_div(thd, $1, $3);
10420            if (unlikely($$ == NULL))
10421              MYSQL_YYABORT;
10422          }
10423        | bit_expr MOD_SYM bit_expr %prec MOD_SYM
10424          {
10425            $$= new (thd->mem_root) Item_func_mod(thd, $1, $3);
10426            if (unlikely($$ == NULL))
10427              MYSQL_YYABORT;
10428          }
10429        | bit_expr '^' bit_expr
10430          {
10431            $$= new (thd->mem_root) Item_func_bit_xor(thd, $1, $3);
10432            if (unlikely($$ == NULL))
10433              MYSQL_YYABORT;
10434          }
10435        | mysql_concatenation_expr %prec '^'
10436        ;
10437
10438or:
10439          OR_SYM
10440       | OR2_SYM
10441       ;
10442
10443and:
10444          AND_SYM
10445       | AND_AND_SYM
10446       ;
10447
10448not:
10449          NOT_SYM
10450        | NOT2_SYM
10451        ;
10452
10453not2:
10454          '!'
10455        | NOT2_SYM
10456        ;
10457
10458comp_op:
10459          '='     { $$ = &comp_eq_creator; }
10460        | GE     { $$ = &comp_ge_creator; }
10461        | '>' { $$ = &comp_gt_creator; }
10462        | LE     { $$ = &comp_le_creator; }
10463        | '<'     { $$ = &comp_lt_creator; }
10464        | NE     { $$ = &comp_ne_creator; }
10465        ;
10466
10467all_or_any:
10468          ALL     { $$ = 1; }
10469        | ANY_SYM { $$ = 0; }
10470        ;
10471
10472opt_dyncol_type:
10473          /* empty */
10474          {
10475            $$.set(DYN_COL_NULL); /* automatic type */
10476            Lex->charset= NULL;
10477	  }
10478        | AS dyncol_type { $$= $2; }
10479        ;
10480
10481dyncol_type:
10482          numeric_dyncol_type             { $$= $1; Lex->charset= NULL; }
10483        | temporal_dyncol_type            { $$= $1; Lex->charset= NULL; }
10484        | string_dyncol_type              { $$= $1; }
10485        ;
10486
10487numeric_dyncol_type:
10488          INT_SYM                         { $$.set(DYN_COL_INT); }
10489        | UNSIGNED INT_SYM                { $$.set(DYN_COL_UINT);  }
10490        | DOUBLE_SYM                      { $$.set(DYN_COL_DOUBLE);  }
10491        | REAL                            { $$.set(DYN_COL_DOUBLE); }
10492        | FLOAT_SYM                       { $$.set(DYN_COL_DOUBLE); }
10493        | DECIMAL_SYM float_options       { $$.set(DYN_COL_DECIMAL, $2); }
10494        ;
10495
10496temporal_dyncol_type:
10497          DATE_SYM                        { $$.set(DYN_COL_DATE); }
10498        | TIME_SYM opt_field_length       { $$.set(DYN_COL_TIME, 0, $2); }
10499        | DATETIME opt_field_length       { $$.set(DYN_COL_DATETIME, 0, $2); }
10500        ;
10501
10502string_dyncol_type:
10503          char
10504          { Lex->charset= thd->variables.collation_connection; }
10505          opt_binary
10506          {
10507            $$.set(DYN_COL_STRING);
10508          }
10509        | nchar
10510          {
10511            $$.set(DYN_COL_STRING);
10512            Lex->charset= national_charset_info;
10513          }
10514        ;
10515
10516dyncall_create_element:
10517   expr ',' expr opt_dyncol_type
10518   {
10519     LEX *lex= Lex;
10520     $$= (DYNCALL_CREATE_DEF *)
10521       alloc_root(thd->mem_root, sizeof(DYNCALL_CREATE_DEF));
10522     if (unlikely($$ == NULL))
10523       MYSQL_YYABORT;
10524     $$->key= $1;
10525     $$->value= $3;
10526     $$->type= (DYNAMIC_COLUMN_TYPE)$4.dyncol_type();
10527     $$->cs= lex->charset;
10528     if ($4.length())
10529       $$->len= strtoul($4.length(), NULL, 10);
10530     else
10531       $$->len= 0;
10532     if ($4.dec())
10533       $$->frac= strtoul($4.dec(), NULL, 10);
10534     else
10535       $$->len= 0;
10536   }
10537   ;
10538
10539dyncall_create_list:
10540     dyncall_create_element
10541       {
10542         $$= new (thd->mem_root) List<DYNCALL_CREATE_DEF>;
10543         if (unlikely($$ == NULL))
10544           MYSQL_YYABORT;
10545         $$->push_back($1, thd->mem_root);
10546       }
10547   | dyncall_create_list ',' dyncall_create_element
10548       {
10549         $1->push_back($3, thd->mem_root);
10550         $$= $1;
10551       }
10552   ;
10553
10554
10555plsql_cursor_attr:
10556          ISOPEN_SYM    { $$= PLSQL_CURSOR_ATTR_ISOPEN; }
10557        | FOUND_SYM     { $$= PLSQL_CURSOR_ATTR_FOUND; }
10558        | NOTFOUND_SYM  { $$= PLSQL_CURSOR_ATTR_NOTFOUND; }
10559        | ROWCOUNT_SYM  { $$= PLSQL_CURSOR_ATTR_ROWCOUNT; }
10560        ;
10561
10562explicit_cursor_attr:
10563          ident PERCENT_ORACLE_SYM plsql_cursor_attr
10564          {
10565            if (unlikely(!($$= Lex->make_item_plsql_cursor_attr(thd, &$1, $3))))
10566              MYSQL_YYABORT;
10567          }
10568        ;
10569
10570
10571trim_operands:
10572          expr                     { $$.set(TRIM_BOTH, $1);         }
10573        | LEADING  expr FROM expr  { $$.set(TRIM_LEADING, $2, $4);  }
10574        | TRAILING expr FROM expr  { $$.set(TRIM_TRAILING, $2, $4); }
10575        | BOTH     expr FROM expr  { $$.set(TRIM_BOTH, $2, $4);     }
10576        | LEADING       FROM expr  { $$.set(TRIM_LEADING, $3);      }
10577        | TRAILING      FROM expr  { $$.set(TRIM_TRAILING, $3);     }
10578        | BOTH          FROM expr  { $$.set(TRIM_BOTH, $3);         }
10579        | expr          FROM expr  { $$.set(TRIM_BOTH, $1, $3);     }
10580        ;
10581
10582/*
10583  Expressions that the parser allows in a column DEFAULT clause
10584  without parentheses. These expressions cannot end with a COLLATE clause.
10585
10586  If we allowed any "expr" in DEFAULT clause, there would be a confusion
10587  in queries like this:
10588    CREATE TABLE t1 (a TEXT DEFAULT 'a' COLLATE latin1_bin);
10589  It would be not clear what COLLATE stands for:
10590  - the collation of the column `a`, or
10591  - the collation of the string literal 'a'
10592
10593  This restriction allows to parse the above query unambiguiusly:
10594  COLLATE belongs to the column rather than the literal.
10595  If one needs COLLATE to belong to the literal, parentheses must be used:
10596    CREATE TABLE t1 (a TEXT DEFAULT ('a' COLLATE latin1_bin));
10597  Note: the COLLATE clause is rather meaningless here, but the query
10598  is syntactically correct.
10599
10600  Note, some of the expressions are not actually allowed in DEFAULT,
10601  e.g. sum_expr, window_func_expr, ROW(...), VALUES().
10602  We could move them to simple_expr, but that would make
10603  these two queries return a different error messages:
10604    CREATE TABLE t1 (a INT DEFAULT AVG(1));
10605    CREATE TABLE t1 (a INT DEFAULT (AVG(1)));
10606  The first query would return "syntax error".
10607  Currenly both return:
10608   Function or expression 'avg(' is not allowed for 'DEFAULT' ...
10609*/
10610column_default_non_parenthesized_expr:
10611          simple_ident
10612        | function_call_keyword
10613        | function_call_nonkeyword
10614        | function_call_generic
10615        | function_call_conflict
10616        | literal
10617        | param_marker { $$= $1; }
10618        | variable
10619        | sum_expr
10620          {
10621            if (!Lex->select_stack_top)
10622            {
10623              my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0));
10624              MYSQL_YYABORT;
10625            }
10626          }
10627        | window_func_expr
10628          {
10629            if (!Lex->select_stack_top)
10630            {
10631               my_error(ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION, MYF(0));
10632               MYSQL_YYABORT;
10633            }
10634          }
10635        | inverse_distribution_function
10636        | ROW_SYM '(' expr ',' expr_list ')'
10637          {
10638            $5->push_front($3, thd->mem_root);
10639            $$= new (thd->mem_root) Item_row(thd, *$5);
10640            if (unlikely($$ == NULL))
10641              MYSQL_YYABORT;
10642          }
10643        | EXISTS '(' subselect ')'
10644          {
10645            $$= new (thd->mem_root) Item_exists_subselect(thd, $3);
10646            if (unlikely($$ == NULL))
10647              MYSQL_YYABORT;
10648          }
10649        | '{' ident expr '}'
10650          {
10651            if (unlikely(!($$= $3->make_odbc_literal(thd, &$2))))
10652              MYSQL_YYABORT;
10653          }
10654        | MATCH ident_list_arg AGAINST '(' bit_expr fulltext_options ')'
10655          {
10656            $2->push_front($5, thd->mem_root);
10657            Item_func_match *i1= new (thd->mem_root) Item_func_match(thd, *$2,
10658                                                                     $6);
10659            if (unlikely(i1 == NULL))
10660              MYSQL_YYABORT;
10661            Select->add_ftfunc_to_list(thd, i1);
10662            $$= i1;
10663          }
10664        | CAST_SYM '(' expr AS cast_type ')'
10665          {
10666            if (unlikely(!($$= $5.create_typecast_item(thd, $3, Lex->charset))))
10667              MYSQL_YYABORT;
10668          }
10669        | CASE_SYM when_list_opt_else END
10670          {
10671            if (unlikely(!($$= new(thd->mem_root) Item_func_case_searched(thd, *$2))))
10672              MYSQL_YYABORT;
10673          }
10674        | CASE_SYM expr when_list_opt_else END
10675          {
10676            $3->push_front($2, thd->mem_root);
10677            if (unlikely(!($$= new (thd->mem_root) Item_func_case_simple(thd, *$3))))
10678              MYSQL_YYABORT;
10679          }
10680        | CONVERT_SYM '(' expr ',' cast_type ')'
10681          {
10682            if (unlikely(!($$= $5.create_typecast_item(thd, $3, Lex->charset))))
10683              MYSQL_YYABORT;
10684          }
10685        | CONVERT_SYM '(' expr USING charset_name ')'
10686          {
10687            $$= new (thd->mem_root) Item_func_conv_charset(thd, $3, $5);
10688            if (unlikely($$ == NULL))
10689              MYSQL_YYABORT;
10690          }
10691        | DEFAULT '(' simple_ident ')'
10692          {
10693            Item_splocal *il= $3->get_item_splocal();
10694            if (unlikely(il))
10695              my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), il->my_name()->str));
10696            $$= new (thd->mem_root) Item_default_value(thd, Lex->current_context(),
10697                                                         $3, 0);
10698            if (unlikely($$ == NULL))
10699              MYSQL_YYABORT;
10700            Lex->default_used= TRUE;
10701          }
10702        | VALUE_SYM '(' simple_ident_nospvar ')'
10703          {
10704            $$= new (thd->mem_root) Item_insert_value(thd, Lex->current_context(),
10705                                                        $3);
10706            if (unlikely($$ == NULL))
10707              MYSQL_YYABORT;
10708          }
10709        | NEXT_SYM VALUE_SYM FOR_SYM table_ident
10710          {
10711            if (unlikely(!($$= Lex->create_item_func_nextval(thd, $4))))
10712              MYSQL_YYABORT;
10713          }
10714        | NEXTVAL_SYM '(' table_ident ')'
10715          {
10716            if (unlikely(!($$= Lex->create_item_func_nextval(thd, $3))))
10717              MYSQL_YYABORT;
10718          }
10719        | PREVIOUS_SYM VALUE_SYM FOR_SYM table_ident
10720          {
10721            if (unlikely(!($$= Lex->create_item_func_lastval(thd, $4))))
10722              MYSQL_YYABORT;
10723          }
10724        | LASTVAL_SYM '(' table_ident ')'
10725          {
10726            if (unlikely(!($$= Lex->create_item_func_lastval(thd, $3))))
10727              MYSQL_YYABORT;
10728          }
10729        | SETVAL_SYM '(' table_ident ',' longlong_num ')'
10730          {
10731            if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0, 1))))
10732              MYSQL_YYABORT;
10733          }
10734        | SETVAL_SYM '(' table_ident ',' longlong_num ',' bool ')'
10735          {
10736            if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, 0, $7))))
10737              MYSQL_YYABORT;
10738          }
10739        | SETVAL_SYM '(' table_ident ',' longlong_num ',' bool ',' ulonglong_num ')'
10740          {
10741            if (unlikely(!($$= Lex->create_item_func_setval(thd, $3, $5, $9, $7))))
10742              MYSQL_YYABORT;
10743          }
10744        ;
10745
10746primary_expr:
10747          column_default_non_parenthesized_expr
10748        | explicit_cursor_attr
10749        | '(' parenthesized_expr ')' { $$= $2; }
10750        | subquery
10751          {
10752            if (!($$= Lex->create_item_query_expression(thd, $1->master_unit())))
10753              MYSQL_YYABORT;
10754          }
10755        ;
10756
10757string_factor_expr:
10758          primary_expr
10759        | string_factor_expr COLLATE_SYM collation_name
10760          {
10761            if (unlikely(!($$= new (thd->mem_root) Item_func_set_collation(thd, $1, $3))))
10762              MYSQL_YYABORT;
10763          }
10764        ;
10765
10766simple_expr:
10767          string_factor_expr %prec NEG
10768        | BINARY simple_expr
10769          {
10770            Type_cast_attributes at(&my_charset_bin);
10771            if (unlikely(!($$= type_handler_long_blob.create_typecast_item(thd, $2, at))))
10772              MYSQL_YYABORT;
10773          }
10774        | '+' simple_expr %prec NEG
10775          {
10776            $$= $2;
10777          }
10778        | '-' simple_expr %prec NEG
10779          {
10780            $$= $2->neg(thd);
10781            if (unlikely($$ == NULL))
10782              MYSQL_YYABORT;
10783          }
10784        | '~' simple_expr %prec NEG
10785          {
10786            $$= new (thd->mem_root) Item_func_bit_neg(thd, $2);
10787            if (unlikely($$ == NULL))
10788              MYSQL_YYABORT;
10789          }
10790        | not2 simple_expr %prec NEG
10791          {
10792            $$= negate_expression(thd, $2);
10793            if (unlikely($$ == NULL))
10794              MYSQL_YYABORT;
10795          }
10796        ;
10797
10798mysql_concatenation_expr:
10799          simple_expr
10800        | mysql_concatenation_expr MYSQL_CONCAT_SYM simple_expr
10801          {
10802            $$= new (thd->mem_root) Item_func_concat(thd, $1, $3);
10803            if (unlikely($$ == NULL))
10804              MYSQL_YYABORT;
10805          }
10806        ;
10807
10808function_call_keyword_timestamp:
10809          TIMESTAMP '(' expr ')'
10810          {
10811            $$= new (thd->mem_root) Item_datetime_typecast(thd, $3,
10812                                      AUTO_SEC_PART_DIGITS);
10813            if (unlikely($$ == NULL))
10814              MYSQL_YYABORT;
10815          }
10816        | TIMESTAMP '(' expr ',' expr ')'
10817          {
10818            $$= new (thd->mem_root) Item_func_timestamp(thd, $3, $5);
10819            if (unlikely($$ == NULL))
10820              MYSQL_YYABORT;
10821          }
10822        ;
10823/*
10824  Function call syntax using official SQL 2003 keywords.
10825  Because the function name is an official token,
10826  a dedicated grammar rule is needed in the parser.
10827  There is no potential for conflicts
10828*/
10829function_call_keyword:
10830          CHAR_SYM '(' expr_list ')'
10831          {
10832            $$= new (thd->mem_root) Item_func_char(thd, *$3);
10833            if (unlikely($$ == NULL))
10834              MYSQL_YYABORT;
10835          }
10836        | CHAR_SYM '(' expr_list USING charset_name ')'
10837          {
10838            $$= new (thd->mem_root) Item_func_char(thd, *$3, $5);
10839            if (unlikely($$ == NULL))
10840              MYSQL_YYABORT;
10841          }
10842        | CURRENT_USER optional_braces
10843          {
10844            $$= new (thd->mem_root) Item_func_current_user(thd,
10845                                      Lex->current_context());
10846            if (unlikely($$ == NULL))
10847              MYSQL_YYABORT;
10848            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10849            Lex->safe_to_cache_query= 0;
10850          }
10851        | CURRENT_ROLE optional_braces
10852          {
10853            $$= new (thd->mem_root) Item_func_current_role(thd,
10854                                      Lex->current_context());
10855            if (unlikely($$ == NULL))
10856              MYSQL_YYABORT;
10857            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10858            Lex->safe_to_cache_query= 0;
10859          }
10860        | DATE_SYM '(' expr ')'
10861          {
10862            $$= new (thd->mem_root) Item_date_typecast(thd, $3);
10863            if (unlikely($$ == NULL))
10864              MYSQL_YYABORT;
10865          }
10866        | DAY_SYM '(' expr ')'
10867          {
10868            $$= new (thd->mem_root) Item_func_dayofmonth(thd, $3);
10869            if (unlikely($$ == NULL))
10870              MYSQL_YYABORT;
10871          }
10872        | HOUR_SYM '(' expr ')'
10873          {
10874            $$= new (thd->mem_root) Item_func_hour(thd, $3);
10875            if (unlikely($$ == NULL))
10876              MYSQL_YYABORT;
10877          }
10878        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
10879          {
10880            $$= new (thd->mem_root) Item_func_insert(thd, $3, $5, $7, $9);
10881            if (unlikely($$ == NULL))
10882              MYSQL_YYABORT;
10883          }
10884        | INTERVAL_SYM '(' expr ',' expr ')'
10885          {
10886            List<Item> *list= new (thd->mem_root) List<Item>;
10887            if (unlikely(list == NULL))
10888              MYSQL_YYABORT;
10889            if (unlikely(list->push_front($5, thd->mem_root)) ||
10890                unlikely(list->push_front($3, thd->mem_root)))
10891              MYSQL_YYABORT;
10892            Item_row *item= new (thd->mem_root) Item_row(thd, *list);
10893            if (unlikely(item == NULL))
10894              MYSQL_YYABORT;
10895            $$= new (thd->mem_root) Item_func_interval(thd, item);
10896            if (unlikely($$ == NULL))
10897              MYSQL_YYABORT;
10898          }
10899        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')'
10900          {
10901            $7->push_front($5, thd->mem_root);
10902            $7->push_front($3, thd->mem_root);
10903            Item_row *item= new (thd->mem_root) Item_row(thd, *$7);
10904            if (unlikely(item == NULL))
10905              MYSQL_YYABORT;
10906            $$= new (thd->mem_root) Item_func_interval(thd, item);
10907            if (unlikely($$ == NULL))
10908              MYSQL_YYABORT;
10909          }
10910        | LEFT '(' expr ',' expr ')'
10911          {
10912            $$= new (thd->mem_root) Item_func_left(thd, $3, $5);
10913            if (unlikely($$ == NULL))
10914              MYSQL_YYABORT;
10915          }
10916        | MINUTE_SYM '(' expr ')'
10917          {
10918            $$= new (thd->mem_root) Item_func_minute(thd, $3);
10919            if (unlikely($$ == NULL))
10920              MYSQL_YYABORT;
10921          }
10922        | MONTH_SYM '(' expr ')'
10923          {
10924            $$= new (thd->mem_root) Item_func_month(thd, $3);
10925            if (unlikely($$ == NULL))
10926              MYSQL_YYABORT;
10927          }
10928        | RIGHT '(' expr ',' expr ')'
10929          {
10930            $$= new (thd->mem_root) Item_func_right(thd, $3, $5);
10931            if (unlikely($$ == NULL))
10932              MYSQL_YYABORT;
10933          }
10934        | SECOND_SYM '(' expr ')'
10935          {
10936            $$= new (thd->mem_root) Item_func_second(thd, $3);
10937            if (unlikely($$ == NULL))
10938              MYSQL_YYABORT;
10939          }
10940        | SQL_SYM PERCENT_ORACLE_SYM ROWCOUNT_SYM
10941          {
10942            $$= new (thd->mem_root) Item_func_oracle_sql_rowcount(thd);
10943            if (unlikely($$ == NULL))
10944              MYSQL_YYABORT;
10945            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10946            Lex->safe_to_cache_query= 0;
10947          }
10948        | TIME_SYM '(' expr ')'
10949          {
10950            $$= new (thd->mem_root) Item_time_typecast(thd, $3,
10951                                      AUTO_SEC_PART_DIGITS);
10952            if (unlikely($$ == NULL))
10953              MYSQL_YYABORT;
10954          }
10955        | function_call_keyword_timestamp
10956          {
10957            $$= $1;
10958          }
10959        | TRIM '(' trim_operands ')'
10960          {
10961            if (unlikely(!($$= $3.make_item_func_trim(thd))))
10962              MYSQL_YYABORT;
10963          }
10964        | USER_SYM '(' ')'
10965          {
10966            $$= new (thd->mem_root) Item_func_user(thd);
10967            if (unlikely($$ == NULL))
10968              MYSQL_YYABORT;
10969            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
10970            Lex->safe_to_cache_query=0;
10971          }
10972        | YEAR_SYM '(' expr ')'
10973          {
10974            $$= new (thd->mem_root) Item_func_year(thd, $3);
10975            if (unlikely($$ == NULL))
10976              MYSQL_YYABORT;
10977          }
10978        ;
10979
10980/*
10981  Function calls using non reserved keywords, with special syntaxic forms.
10982  Dedicated grammar rules are needed because of the syntax,
10983  but also have the potential to cause incompatibilities with other
10984  parts of the language.
10985  MAINTAINER:
10986  The only reasons a function should be added here are:
10987  - for compatibility reasons with another SQL syntax (CURDATE),
10988  - for typing reasons (GET_FORMAT)
10989  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
10990  discouraged.
10991*/
10992function_call_nonkeyword:
10993          ADDDATE_SYM '(' expr ',' expr ')'
10994          {
10995            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $5,
10996                                                             INTERVAL_DAY, 0);
10997            if (unlikely($$ == NULL))
10998              MYSQL_YYABORT;
10999          }
11000        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
11001          {
11002            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 0);
11003            if (unlikely($$ == NULL))
11004              MYSQL_YYABORT;
11005          }
11006        | CURDATE optional_braces
11007          {
11008            $$= new (thd->mem_root) Item_func_curdate_local(thd);
11009            if (unlikely($$ == NULL))
11010              MYSQL_YYABORT;
11011            Lex->safe_to_cache_query=0;
11012          }
11013        | CURTIME opt_time_precision
11014          {
11015            $$= new (thd->mem_root) Item_func_curtime_local(thd, $2);
11016            if (unlikely($$ == NULL))
11017              MYSQL_YYABORT;
11018            Lex->safe_to_cache_query=0;
11019          }
11020        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
11021          {
11022            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 0);
11023            if (unlikely($$ == NULL))
11024              MYSQL_YYABORT;
11025          }
11026        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
11027          {
11028            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 1);
11029            if (unlikely($$ == NULL))
11030              MYSQL_YYABORT;
11031          }
11032        | DATE_FORMAT_SYM '(' expr ',' expr ')'
11033          {
11034            $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5);
11035            if (unlikely($$ == NULL))
11036              MYSQL_YYABORT;
11037          }
11038        | DATE_FORMAT_SYM '(' expr ',' expr ',' expr ')'
11039          {
11040            $$= new (thd->mem_root) Item_func_date_format(thd, $3, $5, $7);
11041            if (unlikely($$ == NULL))
11042              MYSQL_YYABORT;
11043          }
11044        | DECODE_MARIADB_SYM '(' expr ',' expr ')'
11045          {
11046            $$= new (thd->mem_root) Item_func_decode(thd, $3, $5);
11047            if (unlikely($$ == NULL))
11048              MYSQL_YYABORT;
11049          }
11050        | DECODE_ORACLE_SYM '(' expr ',' decode_when_list_oracle ')'
11051          {
11052            $5->push_front($3, thd->mem_root);
11053            if (unlikely(!($$= new (thd->mem_root) Item_func_decode_oracle(thd, *$5))))
11054              MYSQL_YYABORT;
11055          }
11056        | EXTRACT_SYM '(' interval FROM expr ')'
11057          {
11058            $$=new (thd->mem_root) Item_extract(thd, $3, $5);
11059            if (unlikely($$ == NULL))
11060              MYSQL_YYABORT;
11061          }
11062        | GET_FORMAT '(' date_time_type  ',' expr ')'
11063          {
11064            $$= new (thd->mem_root) Item_func_get_format(thd, $3, $5);
11065            if (unlikely($$ == NULL))
11066              MYSQL_YYABORT;
11067          }
11068        | NOW_SYM opt_time_precision
11069          {
11070            $$= new (thd->mem_root) Item_func_now_local(thd, $2);
11071            if (unlikely($$ == NULL))
11072              MYSQL_YYABORT;
11073            Lex->safe_to_cache_query=0;
11074          }
11075        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
11076          {
11077            $$= new (thd->mem_root) Item_func_locate(thd, $5, $3);
11078            if (unlikely($$ == NULL))
11079              MYSQL_YYABORT;
11080          }
11081        | SUBDATE_SYM '(' expr ',' expr ')'
11082          {
11083            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $5,
11084                                                             INTERVAL_DAY, 1);
11085            if (unlikely($$ == NULL))
11086              MYSQL_YYABORT;
11087          }
11088        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
11089          {
11090            $$= new (thd->mem_root) Item_date_add_interval(thd, $3, $6, $7, 1);
11091            if (unlikely($$ == NULL))
11092              MYSQL_YYABORT;
11093          }
11094        | SUBSTRING '(' expr ',' expr ',' expr ')'
11095          {
11096            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5, $7))))
11097              MYSQL_YYABORT;
11098          }
11099        | SUBSTRING '(' expr ',' expr ')'
11100          {
11101            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5))))
11102              MYSQL_YYABORT;
11103          }
11104        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
11105          {
11106            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5, $7))))
11107              MYSQL_YYABORT;
11108          }
11109        | SUBSTRING '(' expr FROM expr ')'
11110          {
11111            if (unlikely(!($$= Lex->make_item_func_substr(thd, $3, $5))))
11112              MYSQL_YYABORT;
11113          }
11114        | SYSDATE opt_time_precision
11115          {
11116            /*
11117              Unlike other time-related functions, SYSDATE() is
11118              replication-unsafe because it is not affected by the
11119              TIMESTAMP variable.  It is unsafe even if
11120              sysdate_is_now=1, because the slave may have
11121              sysdate_is_now=0.
11122            */
11123            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
11124            if (global_system_variables.sysdate_is_now == 0)
11125              $$= new (thd->mem_root) Item_func_sysdate_local(thd, $2);
11126            else
11127              $$= new (thd->mem_root) Item_func_now_local(thd, $2);
11128            if (unlikely($$ == NULL))
11129              MYSQL_YYABORT;
11130            Lex->safe_to_cache_query=0;
11131          }
11132        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
11133          {
11134            $$= new (thd->mem_root) Item_date_add_interval(thd, $7, $5, $3, 0);
11135            if (unlikely($$ == NULL))
11136              MYSQL_YYABORT;
11137          }
11138        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
11139          {
11140            $$= new (thd->mem_root) Item_func_timestamp_diff(thd, $5, $7, $3);
11141            if (unlikely($$ == NULL))
11142              MYSQL_YYABORT;
11143          }
11144        | TRIM_ORACLE '(' trim_operands ')'
11145          {
11146            if (unlikely(!($$= $3.make_item_func_trim_oracle(thd))))
11147              MYSQL_YYABORT;
11148          }
11149        | UTC_DATE_SYM optional_braces
11150          {
11151            $$= new (thd->mem_root) Item_func_curdate_utc(thd);
11152            if (unlikely($$ == NULL))
11153              MYSQL_YYABORT;
11154            Lex->safe_to_cache_query=0;
11155          }
11156        | UTC_TIME_SYM opt_time_precision
11157          {
11158            $$= new (thd->mem_root) Item_func_curtime_utc(thd, $2);
11159            if (unlikely($$ == NULL))
11160              MYSQL_YYABORT;
11161            Lex->safe_to_cache_query=0;
11162          }
11163        | UTC_TIMESTAMP_SYM opt_time_precision
11164          {
11165            $$= new (thd->mem_root) Item_func_now_utc(thd, $2);
11166            if (unlikely($$ == NULL))
11167              MYSQL_YYABORT;
11168            Lex->safe_to_cache_query=0;
11169          }
11170        |
11171          COLUMN_ADD_SYM '(' expr ',' dyncall_create_list ')'
11172          {
11173            $$= create_func_dyncol_add(thd, $3, *$5);
11174            if (unlikely($$ == NULL))
11175              MYSQL_YYABORT;
11176          }
11177        |
11178          COLUMN_DELETE_SYM '(' expr ',' expr_list ')'
11179          {
11180            $$= create_func_dyncol_delete(thd, $3, *$5);
11181            if (unlikely($$ == NULL))
11182              MYSQL_YYABORT;
11183          }
11184        |
11185          COLUMN_CHECK_SYM '(' expr ')'
11186          {
11187            $$= new (thd->mem_root) Item_func_dyncol_check(thd, $3);
11188            if (unlikely($$ == NULL))
11189              MYSQL_YYABORT;
11190          }
11191        |
11192          COLUMN_CREATE_SYM '(' dyncall_create_list ')'
11193          {
11194            $$= create_func_dyncol_create(thd, *$3);
11195            if (unlikely($$ == NULL))
11196              MYSQL_YYABORT;
11197          }
11198        |
11199          COLUMN_GET_SYM '(' expr ',' expr AS cast_type ')'
11200          {
11201            LEX *lex= Lex;
11202            $$= create_func_dyncol_get(thd, $3, $5, $7.type_handler(),
11203                                        $7.length(), $7.dec(),
11204                                        lex->charset);
11205            if (unlikely($$ == NULL))
11206              MYSQL_YYABORT;
11207          }
11208        ;
11209
11210/*
11211  Functions calls using a non reserved keyword, and using a regular syntax.
11212  Because the non reserved keyword is used in another part of the grammar,
11213  a dedicated rule is needed here.
11214*/
11215function_call_conflict:
11216          ASCII_SYM '(' expr ')'
11217          {
11218            $$= new (thd->mem_root) Item_func_ascii(thd, $3);
11219            if (unlikely($$ == NULL))
11220              MYSQL_YYABORT;
11221          }
11222        | CHARSET '(' expr ')'
11223          {
11224            $$= new (thd->mem_root) Item_func_charset(thd, $3);
11225            if (unlikely($$ == NULL))
11226              MYSQL_YYABORT;
11227          }
11228        | COALESCE '(' expr_list ')'
11229          {
11230            $$= new (thd->mem_root) Item_func_coalesce(thd, *$3);
11231            if (unlikely($$ == NULL))
11232              MYSQL_YYABORT;
11233          }
11234        | COLLATION_SYM '(' expr ')'
11235          {
11236            $$= new (thd->mem_root) Item_func_collation(thd, $3);
11237            if (unlikely($$ == NULL))
11238              MYSQL_YYABORT;
11239          }
11240        | DATABASE '(' ')'
11241          {
11242            $$= new (thd->mem_root) Item_func_database(thd);
11243            if (unlikely($$ == NULL))
11244              MYSQL_YYABORT;
11245            Lex->safe_to_cache_query=0;
11246          }
11247        | IF_SYM '(' expr ',' expr ',' expr ')'
11248          {
11249            $$= new (thd->mem_root) Item_func_if(thd, $3, $5, $7);
11250            if (unlikely($$ == NULL))
11251              MYSQL_YYABORT;
11252          }
11253        | FORMAT_SYM '(' expr ',' expr ')'
11254          {
11255            $$= new (thd->mem_root) Item_func_format(thd, $3, $5);
11256            if (unlikely($$ == NULL))
11257              MYSQL_YYABORT;
11258          }
11259        | FORMAT_SYM '(' expr ',' expr ',' expr ')'
11260          {
11261            $$= new (thd->mem_root) Item_func_format(thd, $3, $5, $7);
11262            if (unlikely($$ == NULL))
11263              MYSQL_YYABORT;
11264          }
11265          /* LAST_VALUE here conflicts with the definition for window functions.
11266             We have these 2 separate rules to remove the shift/reduce conflict.
11267          */
11268        | LAST_VALUE '(' expr ')'
11269          {
11270            List<Item> *list= new (thd->mem_root) List<Item>;
11271            if (unlikely(list == NULL))
11272              MYSQL_YYABORT;
11273            list->push_back($3, thd->mem_root);
11274
11275            $$= new (thd->mem_root) Item_func_last_value(thd, *list);
11276            if (unlikely($$ == NULL))
11277              MYSQL_YYABORT;
11278          }
11279        | LAST_VALUE '(' expr_list ',' expr ')'
11280          {
11281            $3->push_back($5, thd->mem_root);
11282            $$= new (thd->mem_root) Item_func_last_value(thd, *$3);
11283            if (unlikely($$ == NULL))
11284              MYSQL_YYABORT;
11285          }
11286        | MICROSECOND_SYM '(' expr ')'
11287          {
11288            $$= new (thd->mem_root) Item_func_microsecond(thd, $3);
11289            if (unlikely($$ == NULL))
11290              MYSQL_YYABORT;
11291          }
11292        | MOD_SYM '(' expr ',' expr ')'
11293          {
11294            $$= new (thd->mem_root) Item_func_mod(thd, $3, $5);
11295            if (unlikely($$ == NULL))
11296              MYSQL_YYABORT;
11297          }
11298        | OLD_PASSWORD_SYM '(' expr ')'
11299          {
11300            $$=  new (thd->mem_root)
11301              Item_func_password(thd, $3, Item_func_password::OLD);
11302            if (unlikely($$ == NULL))
11303              MYSQL_YYABORT;
11304          }
11305        | PASSWORD_SYM '(' expr ')'
11306          {
11307            Item* i1;
11308            i1= new (thd->mem_root) Item_func_password(thd, $3);
11309            if (unlikely(i1 == NULL))
11310              MYSQL_YYABORT;
11311            $$= i1;
11312          }
11313        | QUARTER_SYM '(' expr ')'
11314          {
11315            $$= new (thd->mem_root) Item_func_quarter(thd, $3);
11316            if (unlikely($$ == NULL))
11317              MYSQL_YYABORT;
11318          }
11319        | REPEAT_SYM '(' expr ',' expr ')'
11320          {
11321            $$= new (thd->mem_root) Item_func_repeat(thd, $3, $5);
11322            if (unlikely($$ == NULL))
11323              MYSQL_YYABORT;
11324          }
11325        | REPLACE '(' expr ',' expr ',' expr ')'
11326          {
11327            if (unlikely(!($$= Lex->make_item_func_replace(thd, $3, $5, $7))))
11328              MYSQL_YYABORT;
11329          }
11330        | REVERSE_SYM '(' expr ')'
11331          {
11332            $$= new (thd->mem_root) Item_func_reverse(thd, $3);
11333            if (unlikely($$ == NULL))
11334              MYSQL_YYABORT;
11335          }
11336        | ROW_COUNT_SYM '(' ')'
11337          {
11338            $$= new (thd->mem_root) Item_func_row_count(thd);
11339            if (unlikely($$ == NULL))
11340              MYSQL_YYABORT;
11341            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
11342            Lex->safe_to_cache_query= 0;
11343          }
11344        | TRUNCATE_SYM '(' expr ',' expr ')'
11345          {
11346            $$= new (thd->mem_root) Item_func_round(thd, $3, $5, 1);
11347            if (unlikely($$ == NULL))
11348              MYSQL_YYABORT;
11349          }
11350        | WEEK_SYM '(' expr ')'
11351          {
11352            $$= new (thd->mem_root) Item_func_week(thd, $3);
11353            if (unlikely($$ == NULL))
11354              MYSQL_YYABORT;
11355          }
11356        | WEEK_SYM '(' expr ',' expr ')'
11357          {
11358            $$= new (thd->mem_root) Item_func_week(thd, $3, $5);
11359            if (unlikely($$ == NULL))
11360              MYSQL_YYABORT;
11361          }
11362        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
11363          {
11364            $$= new (thd->mem_root) Item_func_weight_string(thd, $3, 0, 0, $4);
11365            if (unlikely($$ == NULL))
11366              MYSQL_YYABORT;
11367          }
11368        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
11369          {
11370            $$= new (thd->mem_root)
11371                Item_func_weight_string(thd, $3, 0, $6,
11372                                        $7 | MY_STRXFRM_PAD_WITH_SPACE);
11373            if (unlikely($$ == NULL))
11374              MYSQL_YYABORT;
11375          }
11376        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
11377          {
11378            Item *item= new (thd->mem_root) Item_char_typecast(thd, $3, $6,
11379                                                               &my_charset_bin);
11380            if (unlikely(item == NULL))
11381              MYSQL_YYABORT;
11382            $$= new (thd->mem_root)
11383                Item_func_weight_string(thd, item, 0, $6,
11384                                        MY_STRXFRM_PAD_WITH_SPACE);
11385            if (unlikely($$ == NULL))
11386              MYSQL_YYABORT;
11387          }
11388        | WEIGHT_STRING_SYM '(' expr ',' ulong_num ',' ulong_num ',' ulong_num ')'
11389          {
11390            $$= new (thd->mem_root) Item_func_weight_string(thd, $3, $5, $7,
11391                                                            $9);
11392            if (unlikely($$ == NULL))
11393              MYSQL_YYABORT;
11394          }
11395        | geometry_function
11396          {
11397#ifdef HAVE_SPATIAL
11398            $$= $1;
11399            /* $1 may be NULL, GEOM_NEW not tested for out of memory */
11400            if (unlikely($$ == NULL))
11401              MYSQL_YYABORT;
11402#else
11403            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), sym_group_geom.name,
11404                              sym_group_geom.needed_define));
11405#endif
11406          }
11407        ;
11408
11409geometry_function:
11410          CONTAINS_SYM '(' expr ',' expr ')'
11411          {
11412            $$= GEOM_NEW(thd,
11413                         Item_func_spatial_precise_rel(thd, $3, $5,
11414                                                 Item_func::SP_CONTAINS_FUNC));
11415          }
11416        | GEOMETRYCOLLECTION '(' expr_list ')'
11417          {
11418            $$= GEOM_NEW(thd,
11419                         Item_func_spatial_collection(thd, *$3,
11420                           Geometry::wkb_geometrycollection,
11421                           Geometry::wkb_point));
11422          }
11423        | LINESTRING '(' expr_list ')'
11424          {
11425            $$= GEOM_NEW(thd,
11426                         Item_func_spatial_collection(thd, *$3,
11427                           Geometry::wkb_linestring,
11428                           Geometry::wkb_point));
11429          }
11430        | MULTILINESTRING '(' expr_list ')'
11431          {
11432            $$= GEOM_NEW(thd,
11433                         Item_func_spatial_collection(thd, *$3,
11434                           Geometry::wkb_multilinestring,
11435                           Geometry::wkb_linestring));
11436          }
11437        | MULTIPOINT '(' expr_list ')'
11438          {
11439            $$= GEOM_NEW(thd,
11440                         Item_func_spatial_collection(thd, *$3,
11441                           Geometry::wkb_multipoint,
11442                           Geometry::wkb_point));
11443          }
11444        | MULTIPOLYGON '(' expr_list ')'
11445          {
11446            $$= GEOM_NEW(thd,
11447                         Item_func_spatial_collection(thd, *$3,
11448                           Geometry::wkb_multipolygon,
11449                           Geometry::wkb_polygon));
11450          }
11451        | POINT_SYM '(' expr ',' expr ')'
11452          {
11453            $$= GEOM_NEW(thd, Item_func_point(thd, $3, $5));
11454          }
11455        | POLYGON '(' expr_list ')'
11456          {
11457            $$= GEOM_NEW(thd,
11458                         Item_func_spatial_collection(thd, *$3,
11459                           Geometry::wkb_polygon,
11460                           Geometry::wkb_linestring));
11461          }
11462        | WITHIN '(' expr ',' expr ')'
11463          {
11464            $$= GEOM_NEW(thd, Item_func_spatial_precise_rel(thd, $3, $5,
11465                                                    Item_func::SP_WITHIN_FUNC));
11466          }
11467        ;
11468
11469/*
11470  Regular function calls.
11471  The function name is *not* a token, and therefore is guaranteed to not
11472  introduce side effects to the language in general.
11473  MAINTAINER:
11474  All the new functions implemented for new features should fit into
11475  this category. The place to implement the function itself is
11476  in sql/item_create.cc
11477*/
11478function_call_generic:
11479          IDENT_sys '('
11480          {
11481#ifdef HAVE_DLOPEN
11482            udf_func *udf= 0;
11483            LEX *lex= Lex;
11484            if (using_udf_functions &&
11485                (udf= find_udf($1.str, $1.length)) &&
11486                udf->type == UDFTYPE_AGGREGATE)
11487            {
11488              if (unlikely(lex->current_select->inc_in_sum_expr()))
11489              {
11490                thd->parse_error();
11491                MYSQL_YYABORT;
11492              }
11493            }
11494            /* Temporary placing the result of find_udf in $3 */
11495            $<udf>$= udf;
11496#endif
11497          }
11498          opt_udf_expr_list ')'
11499          {
11500            Create_func *builder;
11501            Item *item= NULL;
11502
11503            if (unlikely(check_routine_name(&$1)))
11504              MYSQL_YYABORT;
11505
11506            /*
11507              Implementation note:
11508              names are resolved with the following order:
11509              - MySQL native functions,
11510              - User Defined Functions,
11511              - Stored Functions (assuming the current <use> database)
11512
11513              This will be revised with WL#2128 (SQL PATH)
11514            */
11515            builder= find_native_function_builder(thd, &$1);
11516            if (builder)
11517            {
11518              item= builder->create_func(thd, &$1, $4);
11519            }
11520            else
11521            {
11522#ifdef HAVE_DLOPEN
11523              /* Retrieving the result of find_udf */
11524              udf_func *udf= $<udf>3;
11525
11526              if (udf)
11527              {
11528                if (udf->type == UDFTYPE_AGGREGATE)
11529                {
11530                  Select->in_sum_expr--;
11531                }
11532
11533                item= Create_udf_func::s_singleton.create(thd, udf, $4);
11534              }
11535              else
11536#endif
11537              {
11538                builder= find_qualified_function_builder(thd);
11539                DBUG_ASSERT(builder);
11540                item= builder->create_func(thd, &$1, $4);
11541              }
11542            }
11543
11544            if (unlikely(! ($$= item)))
11545              MYSQL_YYABORT;
11546          }
11547        | ident_cli '.' ident_cli '(' opt_expr_list ')'
11548          {
11549            if (unlikely(!($$= Lex->make_item_func_call_generic(thd, &$1, &$3, $5))))
11550              MYSQL_YYABORT;
11551          }
11552        ;
11553
11554fulltext_options:
11555          opt_natural_language_mode opt_query_expansion
11556          { $$= $1 | $2; }
11557        | IN_SYM BOOLEAN_SYM MODE_SYM
11558          { $$= FT_BOOL; }
11559        ;
11560
11561opt_natural_language_mode:
11562          /* nothing */                         { $$= FT_NL; }
11563        | IN_SYM NATURAL LANGUAGE_SYM MODE_SYM  { $$= FT_NL; }
11564        ;
11565
11566opt_query_expansion:
11567          /* nothing */                         { $$= 0;         }
11568        | WITH QUERY_SYM EXPANSION_SYM          { $$= FT_EXPAND; }
11569        ;
11570
11571opt_udf_expr_list:
11572        /* empty */     { $$= NULL; }
11573        | udf_expr_list { $$= $1; }
11574        ;
11575
11576udf_expr_list:
11577          udf_expr
11578          {
11579            $$= new (thd->mem_root) List<Item>;
11580            if (unlikely($$ == NULL))
11581              MYSQL_YYABORT;
11582            $$->push_back($1, thd->mem_root);
11583          }
11584        | udf_expr_list ',' udf_expr
11585          {
11586            $1->push_back($3, thd->mem_root);
11587            $$= $1;
11588          }
11589        ;
11590
11591udf_expr:
11592          remember_name expr remember_end select_alias
11593          {
11594            /*
11595             Use Item::name as a storage for the attribute value of user
11596             defined function argument. It is safe to use Item::name
11597             because the syntax will not allow having an explicit name here.
11598             See WL#1017 re. udf attributes.
11599            */
11600            if ($4.str)
11601            {
11602              $2->is_autogenerated_name= FALSE;
11603              $2->set_name(thd, $4.str, $4.length, system_charset_info);
11604            }
11605            /*
11606               A field has to have its proper name in order for name
11607               resolution to work, something we are only guaranteed if we
11608               parse it out. If we hijack the input stream with
11609               remember_name we may get quoted or escaped names.
11610            */
11611            else if ($2->type() != Item::FIELD_ITEM &&
11612                     $2->type() != Item::REF_ITEM /* For HAVING */ )
11613              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
11614            $$= $2;
11615          }
11616        ;
11617
11618sum_expr:
11619          AVG_SYM '(' in_sum_expr ')'
11620          {
11621            $$= new (thd->mem_root) Item_sum_avg(thd, $3, FALSE);
11622            if (unlikely($$ == NULL))
11623              MYSQL_YYABORT;
11624          }
11625        | AVG_SYM '(' DISTINCT in_sum_expr ')'
11626          {
11627            $$= new (thd->mem_root) Item_sum_avg(thd, $4, TRUE);
11628            if (unlikely($$ == NULL))
11629              MYSQL_YYABORT;
11630          }
11631        | BIT_AND  '(' in_sum_expr ')'
11632          {
11633            $$= new (thd->mem_root) Item_sum_and(thd, $3);
11634            if (unlikely($$ == NULL))
11635              MYSQL_YYABORT;
11636          }
11637        | BIT_OR  '(' in_sum_expr ')'
11638          {
11639            $$= new (thd->mem_root) Item_sum_or(thd, $3);
11640            if (unlikely($$ == NULL))
11641              MYSQL_YYABORT;
11642          }
11643        | BIT_XOR  '(' in_sum_expr ')'
11644          {
11645            $$= new (thd->mem_root) Item_sum_xor(thd, $3);
11646            if (unlikely($$ == NULL))
11647              MYSQL_YYABORT;
11648          }
11649        | COUNT_SYM '(' opt_all '*' ')'
11650          {
11651            Item *item= new (thd->mem_root) Item_int(thd, (int32) 0L, 1);
11652            if (unlikely(item == NULL))
11653              MYSQL_YYABORT;
11654            $$= new (thd->mem_root) Item_sum_count(thd, item);
11655            if (unlikely($$ == NULL))
11656              MYSQL_YYABORT;
11657          }
11658        | COUNT_SYM '(' in_sum_expr ')'
11659          {
11660            $$= new (thd->mem_root) Item_sum_count(thd, $3);
11661            if (unlikely($$ == NULL))
11662              MYSQL_YYABORT;
11663          }
11664        | COUNT_SYM '(' DISTINCT
11665          { Select->in_sum_expr++; }
11666          expr_list
11667          { Select->in_sum_expr--; }
11668          ')'
11669          {
11670            $$= new (thd->mem_root) Item_sum_count(thd, *$5);
11671            if (unlikely($$ == NULL))
11672              MYSQL_YYABORT;
11673          }
11674        | MIN_SYM '(' in_sum_expr ')'
11675          {
11676            $$= new (thd->mem_root) Item_sum_min(thd, $3);
11677            if (unlikely($$ == NULL))
11678              MYSQL_YYABORT;
11679          }
11680        /*
11681          According to ANSI SQL, DISTINCT is allowed and has
11682          no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
11683          is processed like an ordinary MIN | MAX()
11684        */
11685        | MIN_SYM '(' DISTINCT in_sum_expr ')'
11686          {
11687            $$= new (thd->mem_root) Item_sum_min(thd, $4);
11688            if (unlikely($$ == NULL))
11689              MYSQL_YYABORT;
11690          }
11691        | MAX_SYM '(' in_sum_expr ')'
11692          {
11693            $$= new (thd->mem_root) Item_sum_max(thd, $3);
11694            if (unlikely($$ == NULL))
11695              MYSQL_YYABORT;
11696          }
11697        | MAX_SYM '(' DISTINCT in_sum_expr ')'
11698          {
11699            $$= new (thd->mem_root) Item_sum_max(thd, $4);
11700            if (unlikely($$ == NULL))
11701              MYSQL_YYABORT;
11702          }
11703        | STD_SYM '(' in_sum_expr ')'
11704          {
11705            $$= new (thd->mem_root) Item_sum_std(thd, $3, 0);
11706            if (unlikely($$ == NULL))
11707              MYSQL_YYABORT;
11708          }
11709        | VARIANCE_SYM '(' in_sum_expr ')'
11710          {
11711            $$= new (thd->mem_root) Item_sum_variance(thd, $3, 0);
11712            if (unlikely($$ == NULL))
11713              MYSQL_YYABORT;
11714          }
11715        | STDDEV_SAMP_SYM '(' in_sum_expr ')'
11716          {
11717            $$= new (thd->mem_root) Item_sum_std(thd, $3, 1);
11718            if (unlikely($$ == NULL))
11719              MYSQL_YYABORT;
11720          }
11721        | VAR_SAMP_SYM '(' in_sum_expr ')'
11722          {
11723            $$= new (thd->mem_root) Item_sum_variance(thd, $3, 1);
11724            if (unlikely($$ == NULL))
11725              MYSQL_YYABORT;
11726          }
11727        | SUM_SYM '(' in_sum_expr ')'
11728          {
11729            $$= new (thd->mem_root) Item_sum_sum(thd, $3, FALSE);
11730            if (unlikely($$ == NULL))
11731              MYSQL_YYABORT;
11732          }
11733        | SUM_SYM '(' DISTINCT in_sum_expr ')'
11734          {
11735            $$= new (thd->mem_root) Item_sum_sum(thd, $4, TRUE);
11736            if (unlikely($$ == NULL))
11737              MYSQL_YYABORT;
11738          }
11739        | GROUP_CONCAT_SYM '(' opt_distinct
11740          { Select->in_sum_expr++; }
11741          expr_list opt_gorder_clause
11742          opt_gconcat_separator opt_glimit_clause
11743          ')'
11744          {
11745            SELECT_LEX *sel= Select;
11746            sel->in_sum_expr--;
11747            $$= new (thd->mem_root)
11748                  Item_func_group_concat(thd, Lex->current_context(),
11749                                        $3, $5,
11750                                        sel->gorder_list, $7, $8,
11751                                        sel->select_limit,
11752                                        sel->offset_limit);
11753            if (unlikely($$ == NULL))
11754              MYSQL_YYABORT;
11755            sel->select_limit= NULL;
11756            sel->offset_limit= NULL;
11757            sel->explicit_limit= 0;
11758            $5->empty();
11759            sel->gorder_list.empty();
11760          }
11761        ;
11762
11763window_func_expr:
11764          window_func OVER_SYM window_name
11765          {
11766            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1, $3);
11767            if (unlikely($$ == NULL))
11768              MYSQL_YYABORT;
11769            if (unlikely(Select->add_window_func((Item_window_func *) $$)))
11770              MYSQL_YYABORT;
11771          }
11772        |
11773          window_func OVER_SYM window_spec
11774          {
11775            LEX *lex= Lex;
11776            if (unlikely(Select->add_window_spec(thd, lex->win_ref,
11777                                                 Select->group_list,
11778                                                 Select->order_list,
11779                                                 lex->win_frame)))
11780              MYSQL_YYABORT;
11781            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1,
11782                                                      thd->lex->win_spec);
11783            if (unlikely($$ == NULL))
11784              MYSQL_YYABORT;
11785            if (unlikely(Select->add_window_func((Item_window_func *) $$)))
11786              MYSQL_YYABORT;
11787          }
11788        ;
11789
11790window_func:
11791          simple_window_func
11792        |
11793          sum_expr
11794        |
11795          function_call_generic
11796          {
11797            Item* item = (Item*)$1;
11798            /* Only UDF aggregate here possible */
11799            if ((item == NULL) ||
11800                (item->type() != Item::SUM_FUNC_ITEM)
11801                || (((Item_sum *)item)->sum_func() != Item_sum::UDF_SUM_FUNC))
11802            {
11803              thd->parse_error();
11804              MYSQL_YYABORT;
11805            }
11806          }
11807        ;
11808
11809simple_window_func:
11810          ROW_NUMBER_SYM '(' ')'
11811          {
11812            $$= new (thd->mem_root) Item_sum_row_number(thd);
11813            if (unlikely($$ == NULL))
11814              MYSQL_YYABORT;
11815          }
11816        |
11817          RANK_SYM '(' ')'
11818          {
11819            $$= new (thd->mem_root) Item_sum_rank(thd);
11820            if (unlikely($$ == NULL))
11821              MYSQL_YYABORT;
11822          }
11823        |
11824          DENSE_RANK_SYM '(' ')'
11825          {
11826            $$= new (thd->mem_root) Item_sum_dense_rank(thd);
11827            if (unlikely($$ == NULL))
11828              MYSQL_YYABORT;
11829          }
11830        |
11831          PERCENT_RANK_SYM '(' ')'
11832          {
11833            $$= new (thd->mem_root) Item_sum_percent_rank(thd);
11834            if (unlikely($$ == NULL))
11835              MYSQL_YYABORT;
11836          }
11837        |
11838          CUME_DIST_SYM '(' ')'
11839          {
11840            $$= new (thd->mem_root) Item_sum_cume_dist(thd);
11841            if (unlikely($$ == NULL))
11842              MYSQL_YYABORT;
11843          }
11844        |
11845          NTILE_SYM '(' expr ')'
11846          {
11847            $$= new (thd->mem_root) Item_sum_ntile(thd, $3);
11848            if (unlikely($$ == NULL))
11849              MYSQL_YYABORT;
11850          }
11851        |
11852          FIRST_VALUE_SYM '(' expr ')'
11853          {
11854            $$= new (thd->mem_root) Item_sum_first_value(thd, $3);
11855            if (unlikely($$ == NULL))
11856              MYSQL_YYABORT;
11857          }
11858        |
11859          LAST_VALUE '(' expr ')'
11860          {
11861            $$= new (thd->mem_root) Item_sum_last_value(thd, $3);
11862            if (unlikely($$ == NULL))
11863              MYSQL_YYABORT;
11864          }
11865        |
11866          NTH_VALUE_SYM '(' expr ',' expr ')'
11867          {
11868            $$= new (thd->mem_root) Item_sum_nth_value(thd, $3, $5);
11869            if (unlikely($$ == NULL))
11870              MYSQL_YYABORT;
11871          }
11872        |
11873          LEAD_SYM '(' expr ')'
11874          {
11875            /* No second argument defaults to 1. */
11876            Item* item_offset= new (thd->mem_root) Item_uint(thd, 1);
11877            if (unlikely(item_offset == NULL))
11878              MYSQL_YYABORT;
11879            $$= new (thd->mem_root) Item_sum_lead(thd, $3, item_offset);
11880            if (unlikely($$ == NULL))
11881              MYSQL_YYABORT;
11882          }
11883        |
11884          LEAD_SYM '(' expr ',' expr ')'
11885          {
11886            $$= new (thd->mem_root) Item_sum_lead(thd, $3, $5);
11887            if (unlikely($$ == NULL))
11888              MYSQL_YYABORT;
11889          }
11890        |
11891          LAG_SYM '(' expr ')'
11892          {
11893            /* No second argument defaults to 1. */
11894            Item* item_offset= new (thd->mem_root) Item_uint(thd, 1);
11895            if (unlikely(item_offset == NULL))
11896              MYSQL_YYABORT;
11897            $$= new (thd->mem_root) Item_sum_lag(thd, $3, item_offset);
11898            if (unlikely($$ == NULL))
11899              MYSQL_YYABORT;
11900          }
11901        |
11902          LAG_SYM '(' expr ',' expr ')'
11903          {
11904            $$= new (thd->mem_root) Item_sum_lag(thd, $3, $5);
11905            if (unlikely($$ == NULL))
11906              MYSQL_YYABORT;
11907          }
11908        ;
11909
11910
11911
11912inverse_distribution_function:
11913          percentile_function OVER_SYM
11914          '(' opt_window_partition_clause ')'
11915          {
11916            LEX *lex= Lex;
11917            if (unlikely(Select->add_window_spec(thd, lex->win_ref,
11918                                                 Select->group_list,
11919                                                 Select->order_list,
11920                                                 NULL)))
11921              MYSQL_YYABORT;
11922            $$= new (thd->mem_root) Item_window_func(thd, (Item_sum *) $1,
11923                                                     thd->lex->win_spec);
11924            if (unlikely($$ == NULL))
11925              MYSQL_YYABORT;
11926            if (unlikely(Select->add_window_func((Item_window_func *) $$)))
11927              MYSQL_YYABORT;
11928          }
11929        ;
11930
11931percentile_function:
11932          inverse_distribution_function_def  WITHIN GROUP_SYM '('
11933           { Select->prepare_add_window_spec(thd); }
11934           order_by_single_element_list ')'
11935           {
11936             $$= $1;
11937           }
11938        | MEDIAN_SYM '(' expr ')'
11939          {
11940            Item *args= new (thd->mem_root) Item_decimal(thd, "0.5", 3,
11941                                                   thd->charset());
11942            if (unlikely(args == NULL) || unlikely(thd->is_error()))
11943              MYSQL_YYABORT;
11944            Select->prepare_add_window_spec(thd);
11945            if (unlikely(add_order_to_list(thd, $3,FALSE)))
11946              MYSQL_YYABORT;
11947
11948            $$= new (thd->mem_root) Item_sum_percentile_cont(thd, args);
11949            if (unlikely($$ == NULL))
11950              MYSQL_YYABORT;
11951          }
11952        ;
11953
11954inverse_distribution_function_def:
11955          PERCENTILE_CONT_SYM '(' expr ')'
11956          {
11957            $$= new (thd->mem_root) Item_sum_percentile_cont(thd, $3);
11958            if (unlikely($$ == NULL))
11959              MYSQL_YYABORT;
11960          }
11961        |  PERCENTILE_DISC_SYM '(' expr ')'
11962          {
11963            $$= new (thd->mem_root) Item_sum_percentile_disc(thd, $3);
11964            if (unlikely($$ == NULL))
11965              MYSQL_YYABORT;
11966          }
11967        ;
11968
11969order_by_single_element_list:
11970          ORDER_SYM BY order_ident order_dir
11971          {
11972            if (unlikely(add_order_to_list(thd, $3,(bool) $4)))
11973              MYSQL_YYABORT;
11974          }
11975        ;
11976
11977
11978window_name:
11979          ident
11980          {
11981            $$= (LEX_CSTRING *) thd->memdup(&$1, sizeof(LEX_CSTRING));
11982            if (unlikely($$ == NULL))
11983              MYSQL_YYABORT;
11984          }
11985        ;
11986
11987variable:
11988          '@'
11989          {
11990            if (unlikely(! Lex->parsing_options.allows_variable))
11991              my_yyabort_error((ER_VIEW_SELECT_VARIABLE, MYF(0)));
11992          }
11993          variable_aux
11994          {
11995            $$= $3;
11996          }
11997        ;
11998
11999variable_aux:
12000          ident_or_text SET_VAR expr
12001          {
12002            Item_func_set_user_var *item;
12003            $$= item= new (thd->mem_root) Item_func_set_user_var(thd, &$1, $3);
12004            if (unlikely($$ == NULL))
12005              MYSQL_YYABORT;
12006            LEX *lex= Lex;
12007            lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
12008            lex->set_var_list.push_back(item, thd->mem_root);
12009          }
12010        | ident_or_text
12011          {
12012            $$= new (thd->mem_root) Item_func_get_user_var(thd, &$1);
12013            if (unlikely($$ == NULL))
12014              MYSQL_YYABORT;
12015            LEX *lex= Lex;
12016            lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
12017          }
12018        | '@' opt_var_ident_type ident_sysvar_name
12019          {
12020            if (unlikely(!($$= Lex->make_item_sysvar(thd, $2, &$3))))
12021              MYSQL_YYABORT;
12022          }
12023        | '@' opt_var_ident_type ident_sysvar_name '.' ident
12024          {
12025            if (unlikely(!($$= Lex->make_item_sysvar(thd, $2, &$3, &$5))))
12026              MYSQL_YYABORT;
12027          }
12028        ;
12029
12030opt_distinct:
12031          /* empty */ { $$ = 0; }
12032        | DISTINCT    { $$ = 1; }
12033        ;
12034
12035opt_gconcat_separator:
12036          /* empty */
12037          {
12038            $$= new (thd->mem_root) String(",", 1, &my_charset_latin1);
12039            if (unlikely($$ == NULL))
12040              MYSQL_YYABORT;
12041          }
12042        | SEPARATOR_SYM text_string { $$ = $2; }
12043        ;
12044
12045opt_gorder_clause:
12046          /* empty */
12047        | ORDER_SYM BY gorder_list
12048        ;
12049
12050gorder_list:
12051          gorder_list ',' order_ident order_dir
12052          {
12053            if (unlikely(add_gorder_to_list(thd, $3,(bool) $4)))
12054              MYSQL_YYABORT;
12055           }
12056        | order_ident order_dir
12057          {
12058            if (unlikely(add_gorder_to_list(thd, $1,(bool) $2)))
12059              MYSQL_YYABORT;
12060           }
12061        ;
12062
12063opt_glimit_clause:
12064          /* empty */ { $$ = 0; }
12065        | glimit_clause { $$ = 1; }
12066        ;
12067
12068glimit_clause_init:
12069          LIMIT{}
12070        ;
12071
12072glimit_clause:
12073          glimit_clause_init glimit_options
12074          {
12075            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
12076          }
12077        ;
12078
12079glimit_options:
12080          limit_option
12081          {
12082            SELECT_LEX *sel= Select;
12083            sel->select_limit= $1;
12084            sel->offset_limit= 0;
12085            sel->explicit_limit= 1;
12086          }
12087        | limit_option ',' limit_option
12088          {
12089            SELECT_LEX *sel= Select;
12090            sel->select_limit= $3;
12091            sel->offset_limit= $1;
12092            sel->explicit_limit= 1;
12093          }
12094        | limit_option OFFSET_SYM limit_option
12095          {
12096            SELECT_LEX *sel= Select;
12097            sel->select_limit= $1;
12098            sel->offset_limit= $3;
12099            sel->explicit_limit= 1;
12100          }
12101        ;
12102
12103
12104
12105in_sum_expr:
12106          opt_all
12107          {
12108            LEX *lex= Lex;
12109            if (unlikely(lex->current_select->inc_in_sum_expr()))
12110            {
12111              thd->parse_error();
12112              MYSQL_YYABORT;
12113            }
12114          }
12115          expr
12116          {
12117            Select->in_sum_expr--;
12118            $$= $3;
12119          }
12120        ;
12121
12122cast_type:
12123          BINARY opt_field_length
12124          { $$.set(&type_handler_long_blob, $2); Lex->charset= &my_charset_bin; }
12125        | CHAR_SYM opt_field_length
12126          { Lex->charset= thd->variables.collation_connection; }
12127          opt_binary
12128          { $$.set(&type_handler_long_blob, $2); }
12129        | VARCHAR field_length
12130          { Lex->charset= thd->variables.collation_connection; }
12131          opt_binary
12132          { $$.set(&type_handler_long_blob, $2); }
12133        | VARCHAR2_ORACLE_SYM field_length
12134          { Lex->charset= thd->variables.collation_connection; }
12135          opt_binary
12136          { $$.set(&type_handler_long_blob, $2); }
12137        | NCHAR_SYM opt_field_length
12138          {
12139            Lex->charset= national_charset_info;
12140            $$.set(&type_handler_long_blob, $2, 0);
12141          }
12142        | cast_type_numeric  { $$= $1; Lex->charset= NULL; }
12143        | cast_type_temporal { $$= $1; Lex->charset= NULL; }
12144        ;
12145
12146cast_type_numeric:
12147          INT_SYM                        { $$.set(&type_handler_longlong); }
12148        | SIGNED_SYM                     { $$.set(&type_handler_longlong); }
12149        | SIGNED_SYM INT_SYM             { $$.set(&type_handler_longlong); }
12150        | UNSIGNED                       { $$.set(&type_handler_ulonglong); }
12151        | UNSIGNED INT_SYM               { $$.set(&type_handler_ulonglong); }
12152        | DECIMAL_SYM float_options      { $$.set(&type_handler_newdecimal, $2); }
12153        | FLOAT_SYM                      { $$.set(&type_handler_float); }
12154        | DOUBLE_SYM opt_precision       { $$.set(&type_handler_double, $2);  }
12155        ;
12156
12157cast_type_temporal:
12158          DATE_SYM                       { $$.set(&type_handler_newdate); }
12159        | TIME_SYM opt_field_length      { $$.set(&type_handler_time2, 0, $2); }
12160        | DATETIME opt_field_length      { $$.set(&type_handler_datetime2, 0, $2); }
12161        | INTERVAL_SYM DAY_SECOND_SYM field_length
12162          {
12163            $$.set(&type_handler_interval_DDhhmmssff, 0, $3);
12164          }
12165        ;
12166
12167opt_expr_list:
12168          /* empty */ { $$= NULL; }
12169        | expr_list { $$= $1;}
12170        ;
12171
12172expr_list:
12173          expr
12174          {
12175            if (unlikely(!($$= List<Item>::make(thd->mem_root, $1))))
12176              MYSQL_YYABORT;
12177          }
12178        | expr_list ',' expr
12179          {
12180            $1->push_back($3, thd->mem_root);
12181            $$= $1;
12182          }
12183        ;
12184
12185ident_list_arg:
12186          ident_list          { $$= $1; }
12187        | '(' ident_list ')'  { $$= $2; }
12188        ;
12189
12190ident_list:
12191          simple_ident
12192          {
12193            $$= new (thd->mem_root) List<Item>;
12194            if (unlikely($$ == NULL) ||
12195                unlikely($$->push_back($1, thd->mem_root)))
12196              MYSQL_YYABORT;
12197          }
12198        | ident_list ',' simple_ident
12199          {
12200            $1->push_back($3, thd->mem_root);
12201            $$= $1;
12202          }
12203        ;
12204
12205when_list:
12206          WHEN_SYM expr THEN_SYM expr
12207          {
12208            $$= new (thd->mem_root) List<Item>;
12209            if (unlikely($$ == NULL))
12210              MYSQL_YYABORT;
12211            if (unlikely($$->push_back($2, thd->mem_root) ||
12212                         $$->push_back($4, thd->mem_root)))
12213              MYSQL_YYABORT;
12214          }
12215        | when_list WHEN_SYM expr THEN_SYM expr
12216          {
12217            if (unlikely($1->push_back($3, thd->mem_root) ||
12218                         $1->push_back($5, thd->mem_root)))
12219              MYSQL_YYABORT;
12220            $$= $1;
12221          }
12222        ;
12223
12224when_list_opt_else:
12225          when_list
12226        | when_list ELSE expr
12227          {
12228            if (unlikely($1->push_back($3, thd->mem_root)))
12229              MYSQL_YYABORT;
12230            $$= $1;
12231          }
12232        ;
12233
12234decode_when_list_oracle:
12235          expr ',' expr
12236          {
12237            $$= new (thd->mem_root) List<Item>;
12238            if (unlikely($$ == NULL) ||
12239                unlikely($$->push_back($1, thd->mem_root)) ||
12240                unlikely($$->push_back($3, thd->mem_root)))
12241              MYSQL_YYABORT;
12242
12243          }
12244        | decode_when_list_oracle ',' expr
12245          {
12246            $$= $1;
12247            if (unlikely($$->push_back($3, thd->mem_root)))
12248              MYSQL_YYABORT;
12249          }
12250        ;
12251
12252
12253/* Equivalent to <table reference> in the SQL:2003 standard. */
12254/* Warning - may return NULL in case of incomplete SELECT */
12255table_ref:
12256          table_factor     { $$= $1; }
12257        | join_table
12258          {
12259            LEX *lex= Lex;
12260            if (unlikely(!($$= lex->current_select->nest_last_join(thd))))
12261            {
12262              thd->parse_error();
12263              MYSQL_YYABORT;
12264            }
12265          }
12266        ;
12267
12268join_table_list:
12269          derived_table_list { MYSQL_YYABORT_UNLESS($$=$1); }
12270        ;
12271
12272/*
12273  The ODBC escape syntax for Outer Join is: '{' OJ join_table '}'
12274  The parser does not define OJ as a token, any ident is accepted
12275  instead in $2 (ident). Also, all productions from table_ref can
12276  be escaped, not only join_table. Both syntax extensions are safe
12277  and are ignored.
12278*/
12279esc_table_ref:
12280          table_ref { $$=$1; }
12281        | '{' ident table_ref '}' { $$=$3; }
12282        ;
12283
12284/* Equivalent to <table reference list> in the SQL:2003 standard. */
12285/* Warning - may return NULL in case of incomplete SELECT */
12286derived_table_list:
12287          esc_table_ref
12288          {
12289            $$=$1;
12290            Select->add_joined_table($1);
12291          }
12292        | derived_table_list ',' esc_table_ref
12293          {
12294            MYSQL_YYABORT_UNLESS($1 && ($$=$3));
12295            Select->add_joined_table($3);
12296          }
12297        ;
12298
12299/*
12300  Notice that JOIN can be a left-associative operator in one context and
12301  a right-associative operator in another context (see the comment for
12302  st_select_lex::add_cross_joined_table).
12303*/
12304join_table:
12305          /* INNER JOIN variants */
12306          table_ref normal_join table_ref %prec CONDITIONLESS_JOIN
12307          {
12308            MYSQL_YYABORT_UNLESS($1 && ($$=$3));
12309            if (unlikely(Select->add_cross_joined_table($1, $3, $2)))
12310              MYSQL_YYABORT;
12311          }
12312        | table_ref normal_join table_ref
12313          ON
12314          {
12315            MYSQL_YYABORT_UNLESS($1 && $3);
12316            Select->add_joined_table($1);
12317            Select->add_joined_table($3);
12318            /* Change the current name resolution context to a local context. */
12319            if (unlikely(push_new_name_resolution_context(thd, $1, $3)))
12320              MYSQL_YYABORT;
12321            Select->parsing_place= IN_ON;
12322          }
12323          expr
12324          {
12325            $3->straight=$2;
12326            add_join_on(thd, $3, $6);
12327            $3->on_context= Lex->pop_context();
12328            Select->parsing_place= NO_MATTER;
12329          }
12330        | table_ref normal_join table_ref
12331          USING
12332          {
12333            MYSQL_YYABORT_UNLESS($1 && $3);
12334            Select->add_joined_table($1);
12335            Select->add_joined_table($3);
12336          }
12337          '(' using_list ')'
12338          {
12339	    $3->straight=$2;
12340            add_join_natural($1,$3,$7,Select);
12341	    $$=$3;
12342          }
12343        | table_ref NATURAL inner_join table_factor
12344          {
12345            MYSQL_YYABORT_UNLESS($1 && ($$=$4));
12346            Select->add_joined_table($1);
12347            Select->add_joined_table($4);
12348	    $4->straight=$3;
12349            add_join_natural($1,$4,NULL,Select);
12350          }
12351
12352          /* LEFT JOIN variants */
12353        | table_ref LEFT opt_outer JOIN_SYM table_ref
12354          ON
12355          {
12356            MYSQL_YYABORT_UNLESS($1 && $5);
12357            Select->add_joined_table($1);
12358            Select->add_joined_table($5);
12359            /* Change the current name resolution context to a local context. */
12360            if (unlikely(push_new_name_resolution_context(thd, $1, $5)))
12361              MYSQL_YYABORT;
12362            Select->parsing_place= IN_ON;
12363          }
12364          expr
12365          {
12366            add_join_on(thd, $5, $8);
12367            $5->on_context= Lex->pop_context();
12368            $5->outer_join|=JOIN_TYPE_LEFT;
12369            $$=$5;
12370            Select->parsing_place= NO_MATTER;
12371          }
12372        | table_ref LEFT opt_outer JOIN_SYM table_factor
12373          {
12374            MYSQL_YYABORT_UNLESS($1 && $5);
12375            Select->add_joined_table($1);
12376            Select->add_joined_table($5);
12377          }
12378          USING '(' using_list ')'
12379          {
12380            add_join_natural($1,$5,$9,Select);
12381            $5->outer_join|=JOIN_TYPE_LEFT;
12382            $$=$5;
12383          }
12384        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
12385          {
12386            MYSQL_YYABORT_UNLESS($1 && $6);
12387            Select->add_joined_table($1);
12388            Select->add_joined_table($6);
12389            add_join_natural($1,$6,NULL,Select);
12390            $6->outer_join|=JOIN_TYPE_LEFT;
12391            $$=$6;
12392          }
12393
12394          /* RIGHT JOIN variants */
12395        | table_ref RIGHT opt_outer JOIN_SYM table_ref
12396          ON
12397          {
12398            MYSQL_YYABORT_UNLESS($1 && $5);
12399            Select->add_joined_table($1);
12400            Select->add_joined_table($5);
12401            /* Change the current name resolution context to a local context. */
12402            if (unlikely(push_new_name_resolution_context(thd, $1, $5)))
12403              MYSQL_YYABORT;
12404            Select->parsing_place= IN_ON;
12405          }
12406          expr
12407          {
12408            LEX *lex= Lex;
12409            if (unlikely(!($$= lex->current_select->convert_right_join())))
12410              MYSQL_YYABORT;
12411            add_join_on(thd, $$, $8);
12412            $1->on_context= Lex->pop_context();
12413            Select->parsing_place= NO_MATTER;
12414          }
12415        | table_ref RIGHT opt_outer JOIN_SYM table_factor
12416          {
12417            MYSQL_YYABORT_UNLESS($1 && $5);
12418            Select->add_joined_table($1);
12419            Select->add_joined_table($5);
12420          }
12421          USING '(' using_list ')'
12422          {
12423            LEX *lex= Lex;
12424            if (unlikely(!($$= lex->current_select->convert_right_join())))
12425              MYSQL_YYABORT;
12426            add_join_natural($$,$5,$9,Select);
12427          }
12428        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
12429          {
12430            MYSQL_YYABORT_UNLESS($1 && $6);
12431            Select->add_joined_table($1);
12432            Select->add_joined_table($6);
12433            add_join_natural($6,$1,NULL,Select);
12434            LEX *lex= Lex;
12435            if (unlikely(!($$= lex->current_select->convert_right_join())))
12436              MYSQL_YYABORT;
12437          }
12438        ;
12439
12440
12441inner_join: /* $$ set if using STRAIGHT_JOIN, false otherwise */
12442          JOIN_SYM           { $$ = 0; }
12443        | INNER_SYM JOIN_SYM { $$ = 0; }
12444        | STRAIGHT_JOIN      { $$ = 1; }
12445        ;
12446
12447normal_join:
12448          inner_join         { $$ = $1; }
12449        | CROSS JOIN_SYM     { $$ = 0; }
12450        ;
12451
12452/*
12453  table PARTITION (list of partitions), reusing using_list instead of creating
12454  a new rule for partition_list.
12455*/
12456opt_use_partition:
12457          /* empty */ { $$= 0;}
12458        | use_partition
12459        ;
12460
12461use_partition:
12462          PARTITION_SYM '(' using_list ')' have_partitioning
12463          {
12464            $$= $3;
12465            Select->parsing_place= Select->save_parsing_place;
12466            Select->save_parsing_place= NO_MATTER;
12467          }
12468        ;
12469
12470table_factor:
12471          table_primary_ident_opt_parens { $$= $1; }
12472        | table_primary_derived_opt_parens { $$= $1; }
12473        | join_table_parens
12474          {
12475            $1->nested_join->nest_type= 0;
12476            $$= $1;
12477          }
12478        | table_reference_list_parens { $$= $1; }
12479        ;
12480
12481table_primary_ident_opt_parens:
12482          table_primary_ident { $$= $1; }
12483        | '(' table_primary_ident_opt_parens ')' { $$= $2; }
12484        ;
12485
12486table_primary_derived_opt_parens:
12487          table_primary_derived { $$= $1; }
12488        | '(' table_primary_derived_opt_parens ')' { $$= $2; }
12489        ;
12490
12491table_reference_list_parens:
12492          '(' table_reference_list_parens ')' { $$= $2; }
12493        | '(' nested_table_reference_list ')'
12494          {
12495            if (!($$= Select->end_nested_join(thd)))
12496              MYSQL_YYABORT;
12497          }
12498        ;
12499
12500nested_table_reference_list:
12501          table_ref ',' table_ref
12502          {
12503            if (Select->init_nested_join(thd))
12504              MYSQL_YYABORT;
12505            Select->add_joined_table($1);
12506            Select->add_joined_table($3);
12507            $$= $1->embedding;
12508          }
12509        | nested_table_reference_list ',' table_ref
12510          {
12511            Select->add_joined_table($3);
12512            $$= $1;
12513          }
12514        ;
12515
12516join_table_parens:
12517          '(' join_table_parens ')' { $$= $2; }
12518        | '(' join_table ')'
12519          {
12520            LEX *lex= Lex;
12521            if (!($$= lex->current_select->nest_last_join(thd)))
12522            {
12523              thd->parse_error();
12524              MYSQL_YYABORT;
12525            }
12526          }
12527        ;
12528
12529
12530table_primary_ident:
12531          table_ident opt_use_partition opt_for_system_time_clause
12532          opt_table_alias_clause opt_key_definition
12533          {
12534            SELECT_LEX *sel= Select;
12535            sel->table_join_options= 0;
12536            if (!($$= Select->add_table_to_list(thd, $1, $4,
12537                                                Select->get_table_join_options(),
12538                                                YYPS->m_lock_type,
12539                                                YYPS->m_mdl_type,
12540                                                Select->pop_index_hints(),
12541                                                $2)))
12542              MYSQL_YYABORT;
12543            if ($3)
12544              $$->vers_conditions= Lex->vers_conditions;
12545          }
12546        ;
12547
12548table_primary_derived:
12549          subquery
12550          opt_for_system_time_clause table_alias_clause
12551          {
12552            if (!($$= Lex->parsed_derived_table($1->master_unit(), $2, $3)))
12553              MYSQL_YYABORT;
12554          }
12555        ;
12556        ;
12557
12558opt_outer:
12559          /* empty */ {}
12560        | OUTER {}
12561        ;
12562
12563index_hint_clause:
12564          /* empty */
12565          {
12566            $$= thd->variables.old_mode ?  INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL;
12567          }
12568        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
12569        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
12570        | FOR_SYM GROUP_SYM BY  { $$= INDEX_HINT_MASK_GROUP; }
12571        ;
12572
12573index_hint_type:
12574          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
12575        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
12576        ;
12577
12578index_hint_definition:
12579          index_hint_type key_or_index index_hint_clause
12580          {
12581            Select->set_index_hint_type($1, $3);
12582          }
12583          '(' key_usage_list ')'
12584        | USE_SYM key_or_index index_hint_clause
12585          {
12586            Select->set_index_hint_type(INDEX_HINT_USE, $3);
12587          }
12588          '(' opt_key_usage_list ')'
12589       ;
12590
12591index_hints_list:
12592          index_hint_definition
12593        | index_hints_list index_hint_definition
12594        ;
12595
12596opt_index_hints_list:
12597          /* empty */
12598        | { Select->alloc_index_hints(thd); } index_hints_list
12599        ;
12600
12601opt_key_definition:
12602          {  Select->clear_index_hints(); }
12603          opt_index_hints_list
12604        ;
12605
12606opt_key_usage_list:
12607          /* empty */ { Select->add_index_hint(thd, NULL, 0); }
12608        | key_usage_list {}
12609        ;
12610
12611key_usage_element:
12612          ident
12613          { Select->add_index_hint(thd, $1.str, $1.length); }
12614        | PRIMARY_SYM
12615          { Select->add_index_hint(thd, "PRIMARY", 7); }
12616        ;
12617
12618key_usage_list:
12619          key_usage_element
12620        | key_usage_list ',' key_usage_element
12621        ;
12622
12623using_list:
12624          ident
12625          {
12626            if (unlikely(!($$= new (thd->mem_root) List<String>)))
12627              MYSQL_YYABORT;
12628            String *s= new (thd->mem_root) String((const char *) $1.str,
12629                                                    $1.length,
12630                                                    system_charset_info);
12631            if (unlikely(unlikely(s == NULL)))
12632              MYSQL_YYABORT;
12633            $$->push_back(s, thd->mem_root);
12634          }
12635        | using_list ',' ident
12636          {
12637            String *s= new (thd->mem_root) String((const char *) $3.str,
12638                                                    $3.length,
12639                                                    system_charset_info);
12640            if (unlikely(unlikely(s == NULL)))
12641              MYSQL_YYABORT;
12642            if (unlikely($1->push_back(s, thd->mem_root)))
12643              MYSQL_YYABORT;
12644            $$= $1;
12645          }
12646        ;
12647
12648interval:
12649          interval_time_stamp    {}
12650        | DAY_HOUR_SYM           { $$=INTERVAL_DAY_HOUR; }
12651        | DAY_MICROSECOND_SYM    { $$=INTERVAL_DAY_MICROSECOND; }
12652        | DAY_MINUTE_SYM         { $$=INTERVAL_DAY_MINUTE; }
12653        | DAY_SECOND_SYM         { $$=INTERVAL_DAY_SECOND; }
12654        | HOUR_MICROSECOND_SYM   { $$=INTERVAL_HOUR_MICROSECOND; }
12655        | HOUR_MINUTE_SYM        { $$=INTERVAL_HOUR_MINUTE; }
12656        | HOUR_SECOND_SYM        { $$=INTERVAL_HOUR_SECOND; }
12657        | MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
12658        | MINUTE_SECOND_SYM      { $$=INTERVAL_MINUTE_SECOND; }
12659        | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
12660        | YEAR_MONTH_SYM         { $$=INTERVAL_YEAR_MONTH; }
12661        ;
12662
12663interval_time_stamp:
12664          DAY_SYM         { $$=INTERVAL_DAY; }
12665        | WEEK_SYM        { $$=INTERVAL_WEEK; }
12666        | HOUR_SYM        { $$=INTERVAL_HOUR; }
12667        | MINUTE_SYM      { $$=INTERVAL_MINUTE; }
12668        | MONTH_SYM       { $$=INTERVAL_MONTH; }
12669        | QUARTER_SYM     { $$=INTERVAL_QUARTER; }
12670        | SECOND_SYM      { $$=INTERVAL_SECOND; }
12671        | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
12672        | YEAR_SYM        { $$=INTERVAL_YEAR; }
12673        ;
12674
12675date_time_type:
12676          DATE_SYM  {$$=MYSQL_TIMESTAMP_DATE;}
12677        | TIME_SYM  {$$=MYSQL_TIMESTAMP_TIME;}
12678        | DATETIME  {$$=MYSQL_TIMESTAMP_DATETIME;}
12679        | TIMESTAMP {$$=MYSQL_TIMESTAMP_DATETIME;}
12680        ;
12681
12682table_alias:
12683          /* empty */
12684        | AS
12685        | '='
12686        ;
12687
12688opt_table_alias_clause:
12689          /* empty */ { $$=0; }
12690        | table_alias_clause { $$= $1; }
12691        ;
12692
12693table_alias_clause:
12694          table_alias ident_table_alias
12695          {
12696            $$= (LEX_CSTRING*) thd->memdup(&$2,sizeof(LEX_STRING));
12697            if (unlikely($$ == NULL))
12698              MYSQL_YYABORT;
12699          }
12700        ;
12701
12702opt_all:
12703          /* empty */
12704        | ALL
12705        ;
12706
12707opt_where_clause:
12708          /* empty */  { Select->where= 0; }
12709        | WHERE
12710          {
12711            Select->parsing_place= IN_WHERE;
12712          }
12713          expr
12714          {
12715            SELECT_LEX *select= Select;
12716            select->where= normalize_cond(thd, $3);
12717            select->parsing_place= NO_MATTER;
12718            if ($3)
12719              $3->top_level_item();
12720          }
12721        ;
12722
12723opt_having_clause:
12724          /* empty */
12725        | HAVING
12726          {
12727            Select->parsing_place= IN_HAVING;
12728          }
12729          expr
12730          {
12731            SELECT_LEX *sel= Select;
12732            sel->having= normalize_cond(thd, $3);
12733            sel->parsing_place= NO_MATTER;
12734            if ($3)
12735              $3->top_level_item();
12736          }
12737        ;
12738
12739/*
12740   group by statement in select
12741*/
12742
12743opt_group_clause:
12744          /* empty */
12745        | GROUP_SYM BY group_list olap_opt
12746        ;
12747
12748group_list:
12749          group_list ',' order_ident order_dir
12750          {
12751             if (unlikely(add_group_to_list(thd, $3,(bool) $4)))
12752               MYSQL_YYABORT;
12753           }
12754        | order_ident order_dir
12755          {
12756            if (unlikely(add_group_to_list(thd, $1,(bool) $2)))
12757              MYSQL_YYABORT;
12758           }
12759        ;
12760
12761olap_opt:
12762          /* empty */ {}
12763        | WITH_CUBE_SYM
12764          {
12765            /*
12766              'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
12767              and cause LALR(2) conflicts.
12768              This syntax is not standard.
12769              MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
12770              SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
12771            */
12772            LEX *lex=Lex;
12773            if (unlikely(lex->current_select->get_linkage() == GLOBAL_OPTIONS_TYPE))
12774              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "WITH CUBE",
12775                                "global union parameters"));
12776            lex->current_select->olap= CUBE_TYPE;
12777
12778            my_yyabort_error((ER_NOT_SUPPORTED_YET, MYF(0), "CUBE"));
12779          }
12780        | WITH_ROLLUP_SYM
12781          {
12782            /*
12783              'WITH ROLLUP' is needed for backward compatibility,
12784              and cause LALR(2) conflicts.
12785              This syntax is not standard.
12786              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
12787              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
12788            */
12789            LEX *lex= Lex;
12790            if (unlikely(lex->current_select->get_linkage() == GLOBAL_OPTIONS_TYPE))
12791              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
12792                                "global union parameters"));
12793            lex->current_select->olap= ROLLUP_TYPE;
12794          }
12795        ;
12796
12797/*
12798  optional window clause in select
12799*/
12800
12801opt_window_clause:
12802          /* empty */
12803          {}
12804        | WINDOW_SYM
12805          window_def_list
12806          {}
12807        ;
12808
12809window_def_list:
12810          window_def_list ',' window_def
12811        | window_def
12812        ;
12813
12814window_def:
12815          window_name AS window_spec
12816          {
12817            LEX *lex= Lex;
12818            if (unlikely(Select->add_window_def(thd, $1, lex->win_ref,
12819                                                Select->group_list,
12820                                                Select->order_list,
12821                                                lex->win_frame)))
12822              MYSQL_YYABORT;
12823          }
12824        ;
12825
12826window_spec:
12827          '('
12828          { Select->prepare_add_window_spec(thd); }
12829          opt_window_ref opt_window_partition_clause
12830          opt_window_order_clause opt_window_frame_clause
12831          ')'
12832          { }
12833        ;
12834
12835opt_window_ref:
12836          /* empty */ {}
12837        | ident
12838          {
12839            thd->lex->win_ref= (LEX_CSTRING *) thd->memdup(&$1, sizeof(LEX_CSTRING));
12840            if (unlikely(thd->lex->win_ref == NULL))
12841              MYSQL_YYABORT;
12842          }
12843        ;
12844
12845opt_window_partition_clause:
12846          /* empty */ { }
12847        | PARTITION_SYM BY group_list
12848        ;
12849
12850opt_window_order_clause:
12851          /* empty */ { }
12852        | ORDER_SYM BY order_list { Select->order_list= *($3); }
12853        ;
12854
12855opt_window_frame_clause:
12856          /* empty */ {}
12857        | window_frame_units window_frame_extent opt_window_frame_exclusion
12858          {
12859            LEX *lex= Lex;
12860            lex->win_frame=
12861              new (thd->mem_root) Window_frame($1,
12862                                               lex->frame_top_bound,
12863                                               lex->frame_bottom_bound,
12864                                               $3);
12865            if (unlikely(lex->win_frame == NULL))
12866              MYSQL_YYABORT;
12867          }
12868        ;
12869
12870window_frame_units:
12871          ROWS_SYM { $$= Window_frame::UNITS_ROWS; }
12872        | RANGE_SYM { $$= Window_frame::UNITS_RANGE; }
12873        ;
12874
12875window_frame_extent:
12876          window_frame_start
12877          {
12878            LEX *lex= Lex;
12879            lex->frame_top_bound= $1;
12880            lex->frame_bottom_bound=
12881              new (thd->mem_root)
12882                Window_frame_bound(Window_frame_bound::CURRENT, NULL);
12883            if (unlikely(lex->frame_bottom_bound == NULL))
12884              MYSQL_YYABORT;
12885          }
12886        | BETWEEN_SYM window_frame_bound AND_SYM window_frame_bound
12887          {
12888            LEX *lex= Lex;
12889            lex->frame_top_bound= $2;
12890            lex->frame_bottom_bound= $4;
12891          }
12892        ;
12893
12894window_frame_start:
12895          UNBOUNDED_SYM PRECEDING_SYM
12896          {
12897            $$= new (thd->mem_root)
12898                  Window_frame_bound(Window_frame_bound::PRECEDING, NULL);
12899            if (unlikely($$ == NULL))
12900              MYSQL_YYABORT;
12901          }
12902        | CURRENT_SYM ROW_SYM
12903          {
12904            $$= new (thd->mem_root)
12905                  Window_frame_bound(Window_frame_bound::CURRENT, NULL);
12906            if (unlikely($$ == NULL))
12907              MYSQL_YYABORT;
12908          }
12909        | literal PRECEDING_SYM
12910          {
12911            $$= new (thd->mem_root)
12912                  Window_frame_bound(Window_frame_bound::PRECEDING, $1);
12913            if (unlikely($$ == NULL))
12914              MYSQL_YYABORT;
12915          }
12916        ;
12917
12918window_frame_bound:
12919          window_frame_start { $$= $1; }
12920        | UNBOUNDED_SYM FOLLOWING_SYM
12921          {
12922            $$= new (thd->mem_root)
12923                  Window_frame_bound(Window_frame_bound::FOLLOWING, NULL);
12924            if (unlikely($$ == NULL))
12925              MYSQL_YYABORT;
12926          }
12927        | literal FOLLOWING_SYM
12928          {
12929            $$= new (thd->mem_root)
12930                  Window_frame_bound(Window_frame_bound::FOLLOWING, $1);
12931            if (unlikely($$ == NULL))
12932              MYSQL_YYABORT;
12933          }
12934        ;
12935
12936opt_window_frame_exclusion:
12937          /* empty */ { $$= Window_frame::EXCL_NONE; }
12938        | EXCLUDE_SYM CURRENT_SYM ROW_SYM
12939          { $$= Window_frame::EXCL_CURRENT_ROW; }
12940        | EXCLUDE_SYM GROUP_SYM
12941          { $$= Window_frame::EXCL_GROUP; }
12942        | EXCLUDE_SYM TIES_SYM
12943          { $$= Window_frame::EXCL_TIES; }
12944        | EXCLUDE_SYM NO_SYM OTHERS_MARIADB_SYM
12945          { $$= Window_frame::EXCL_NONE; }
12946        | EXCLUDE_SYM NO_SYM OTHERS_ORACLE_SYM
12947          { $$= Window_frame::EXCL_NONE; }
12948        ;
12949
12950/*
12951  Order by statement in ALTER TABLE
12952*/
12953
12954alter_order_clause:
12955          ORDER_SYM BY alter_order_list
12956        ;
12957
12958alter_order_list:
12959          alter_order_list ',' alter_order_item
12960        | alter_order_item
12961        ;
12962
12963alter_order_item:
12964          simple_ident_nospvar order_dir
12965          {
12966            bool ascending= ($2 == 1) ? true : false;
12967            if (unlikely(add_order_to_list(thd, $1, ascending)))
12968              MYSQL_YYABORT;
12969          }
12970        ;
12971
12972/*
12973   Order by statement in select
12974*/
12975
12976opt_order_clause:
12977          /* empty */
12978          { $$= NULL; }
12979        | order_clause
12980          { $$= $1; }
12981        ;
12982
12983order_clause:
12984          ORDER_SYM BY
12985          {
12986            thd->where= "ORDER clause";
12987          }
12988          order_list
12989          {
12990            $$= $4;
12991          }
12992         ;
12993
12994order_list:
12995          order_list ',' order_ident order_dir
12996          {
12997            $$= $1;
12998            if (add_to_list(thd, *$$, $3,(bool) $4))
12999              MYSQL_YYABORT;
13000          }
13001        | order_ident order_dir
13002          {
13003            $$= new (thd->mem_root) SQL_I_List<ORDER>();
13004            if (add_to_list(thd, *$$, $1, (bool) $2))
13005              MYSQL_YYABORT;
13006          }
13007        ;
13008
13009order_dir:
13010          /* empty */ { $$ =  1; }
13011        | ASC  { $$ =1; }
13012        | DESC { $$ =0; }
13013        ;
13014
13015opt_limit_clause:
13016          /* empty */
13017          { $$.empty(); }
13018        | limit_clause
13019          { $$= $1; }
13020        ;
13021
13022limit_clause:
13023          LIMIT limit_options
13024          {
13025            $$= $2;
13026            if (!$$.select_limit->basic_const_item() ||
13027                $$.select_limit->val_int() > 0)
13028              Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
13029          }
13030        | LIMIT limit_options
13031          ROWS_SYM EXAMINED_SYM limit_rows_option
13032          {
13033            $$= $2;
13034            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
13035          }
13036        | LIMIT ROWS_SYM EXAMINED_SYM limit_rows_option
13037          {
13038            $$.select_limit= 0;
13039            $$.offset_limit= 0;
13040            $$.explicit_limit= 1;
13041            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
13042          }
13043        ;
13044
13045opt_global_limit_clause:
13046          opt_limit_clause
13047          {
13048            Select->explicit_limit= $1.explicit_limit;
13049            Select->select_limit= $1.select_limit;
13050            Select->offset_limit= $1.offset_limit;
13051          }
13052        ;
13053
13054limit_options:
13055          limit_option
13056          {
13057            $$.select_limit= $1;
13058            $$.offset_limit= 0;
13059            $$.explicit_limit= 1;
13060          }
13061        | limit_option ',' limit_option
13062          {
13063            $$.select_limit= $3;
13064            $$.offset_limit= $1;
13065            $$.explicit_limit= 1;
13066          }
13067        | limit_option OFFSET_SYM limit_option
13068          {
13069            $$.select_limit= $1;
13070            $$.offset_limit= $3;
13071            $$.explicit_limit= 1;
13072          }
13073        ;
13074
13075limit_option:
13076          ident_cli
13077          {
13078            if (unlikely(!($$= Lex->create_item_limit(thd, &$1))))
13079              MYSQL_YYABORT;
13080          }
13081        | ident_cli '.' ident_cli
13082          {
13083            if (unlikely(!($$= Lex->create_item_limit(thd, &$1, &$3))))
13084              MYSQL_YYABORT;
13085          }
13086        | param_marker
13087          {
13088            $1->limit_clause_param= TRUE;
13089          }
13090        | ULONGLONG_NUM
13091          {
13092            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
13093            if (unlikely($$ == NULL))
13094              MYSQL_YYABORT;
13095          }
13096        | LONG_NUM
13097          {
13098            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
13099            if (unlikely($$ == NULL))
13100              MYSQL_YYABORT;
13101          }
13102        | NUM
13103          {
13104            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
13105            if (unlikely($$ == NULL))
13106              MYSQL_YYABORT;
13107          }
13108        ;
13109
13110limit_rows_option:
13111          limit_option
13112          {
13113            LEX *lex=Lex;
13114            lex->limit_rows_examined= $1;
13115          }
13116        ;
13117
13118delete_limit_clause:
13119          /* empty */
13120          {
13121            LEX *lex=Lex;
13122            lex->current_select->select_limit= 0;
13123          }
13124        | LIMIT limit_option
13125          {
13126            SELECT_LEX *sel= Select;
13127            sel->select_limit= $2;
13128            Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT);
13129            sel->explicit_limit= 1;
13130          }
13131       | LIMIT ROWS_SYM EXAMINED_SYM { thd->parse_error(); MYSQL_YYABORT; }
13132       | LIMIT limit_option ROWS_SYM EXAMINED_SYM { thd->parse_error(); MYSQL_YYABORT; }
13133        ;
13134
13135order_limit_lock:
13136          order_or_limit
13137          {
13138            $$= $1;
13139            $$->lock.empty();
13140          }
13141        | order_or_limit select_lock_type
13142          {
13143            $$= $1;
13144            $$->lock= $2;
13145          }
13146        | select_lock_type
13147          {
13148            $$= new(thd->mem_root) Lex_order_limit_lock;
13149            if (!$$)
13150              YYABORT;
13151            $$->order_list= NULL;
13152            $$->limit.empty();
13153            $$->lock= $1;
13154          }
13155        ;
13156opt_order_limit_lock:
13157          /* empty */
13158          {
13159            Lex->pop_select();
13160            $$= NULL;
13161          }
13162        | order_limit_lock { $$= $1; }
13163        ;
13164
13165query_expression_tail:
13166          order_limit_lock
13167        ;
13168
13169opt_query_expression_tail:
13170          opt_order_limit_lock
13171        ;
13172
13173opt_procedure_or_into:
13174          /* empty */
13175          {
13176            $$.empty();
13177          }
13178        | procedure_clause opt_select_lock_type
13179          {
13180            $$= $2;
13181          }
13182        | into opt_select_lock_type
13183          {
13184            push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
13185                                ER_WARN_DEPRECATED_SYNTAX,
13186                                ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
13187                                "<select expression> INTO <destination>;",
13188                                "'SELECT <select list> INTO <destination>"
13189                                " FROM...'");
13190            $$= $2;
13191          }
13192        ;
13193
13194
13195order_or_limit:
13196          order_clause opt_limit_clause
13197          {
13198            $$= new(thd->mem_root) Lex_order_limit_lock;
13199            if (!$$)
13200              YYABORT;
13201            $$->order_list= $1;
13202            $$->limit= $2;
13203          }
13204        | limit_clause
13205          {
13206            Lex_order_limit_lock *op= $$= new(thd->mem_root) Lex_order_limit_lock;
13207            if (!$$)
13208              YYABORT;
13209            op->order_list= NULL;
13210            op->limit= $1;
13211            $$->order_list= NULL;
13212            $$->limit= $1;
13213          }
13214        ;
13215
13216
13217opt_plus:
13218          /* empty */
13219        | '+'
13220        ;
13221
13222int_num:
13223          opt_plus NUM           { int error; $$= (int) my_strtoll10($2.str, (char**) 0, &error); }
13224        | '-' NUM       { int error; $$= -(int) my_strtoll10($2.str, (char**) 0, &error); }
13225        ;
13226
13227ulong_num:
13228          opt_plus NUM           { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
13229        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
13230        | opt_plus LONG_NUM      { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
13231        | opt_plus ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
13232        | opt_plus DECIMAL_NUM   { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
13233        | opt_plus FLOAT_NUM     { int error; $$= (ulong) my_strtoll10($2.str, (char**) 0, &error); }
13234        ;
13235
13236real_ulong_num:
13237          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
13238        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
13239        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
13240        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
13241        | dec_num_error { MYSQL_YYABORT; }
13242        ;
13243
13244longlong_num:
13245          opt_plus NUM           { int error; $$= (longlong) my_strtoll10($2.str, (char**) 0, &error); }
13246        | LONG_NUM      { int error; $$= (longlong) my_strtoll10($1.str, (char**) 0, &error); }
13247        | '-' NUM         { int error; $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error); }
13248        | '-' LONG_NUM  { int error; $$= -(longlong) my_strtoll10($2.str, (char**) 0, &error); }
13249        ;
13250
13251ulonglong_num:
13252          opt_plus NUM           { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
13253        | opt_plus ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
13254        | opt_plus LONG_NUM      { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
13255        | opt_plus DECIMAL_NUM   { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
13256        | opt_plus FLOAT_NUM     { int error; $$= (ulonglong) my_strtoll10($2.str, (char**) 0, &error); }
13257        ;
13258
13259real_ulonglong_num:
13260          NUM           { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
13261        | ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
13262        | HEX_NUM       { $$= strtoull($1.str, (char**) 0, 16); }
13263        | LONG_NUM      { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
13264        | dec_num_error { MYSQL_YYABORT; }
13265        ;
13266
13267dec_num_error:
13268          dec_num
13269          { thd->parse_error(ER_ONLY_INTEGERS_ALLOWED); }
13270        ;
13271
13272dec_num:
13273          DECIMAL_NUM
13274        | FLOAT_NUM
13275        ;
13276
13277choice:
13278	ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
13279	| DEFAULT { $$= HA_CHOICE_UNDEF; }
13280	;
13281
13282bool:
13283        ulong_num   { $$= $1 != 0; }
13284        | TRUE_SYM  { $$= 1; }
13285        | FALSE_SYM { $$= 0; }
13286        ;
13287
13288procedure_clause:
13289          PROCEDURE_SYM ident /* Procedure name */
13290          {
13291            LEX *lex=Lex;
13292
13293            lex->proc_list.elements=0;
13294            lex->proc_list.first=0;
13295            lex->proc_list.next= &lex->proc_list.first;
13296            Item_field *item= new (thd->mem_root)
13297                                Item_field(thd, &lex->current_select->context,
13298                                           NULL, NULL, &$2);
13299            if (unlikely(item == NULL))
13300              MYSQL_YYABORT;
13301            if (unlikely(add_proc_to_list(thd, item)))
13302              MYSQL_YYABORT;
13303            Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
13304
13305            /*
13306              PROCEDURE CLAUSE cannot handle subquery as one of its parameter,
13307              so disallow any subqueries further.
13308              Alow subqueries back once the parameters are reduced.
13309            */
13310            Lex->clause_that_disallows_subselect= "PROCEDURE";
13311            Select->options|= OPTION_PROCEDURE_CLAUSE;
13312          }
13313          '(' procedure_list ')'
13314          {
13315            /* Subqueries are allowed from now.*/
13316            Lex->clause_that_disallows_subselect= NULL;
13317          }
13318        ;
13319
13320procedure_list:
13321          /* empty */ {}
13322        | procedure_list2 {}
13323        ;
13324
13325procedure_list2:
13326          procedure_list2 ',' procedure_item
13327        | procedure_item
13328        ;
13329
13330procedure_item:
13331          remember_name expr remember_end
13332          {
13333            if (unlikely(add_proc_to_list(thd, $2)))
13334              MYSQL_YYABORT;
13335            if (!$2->name.str || $2->name.str == item_empty_name)
13336              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
13337          }
13338        ;
13339
13340select_var_list_init:
13341          {
13342            LEX *lex=Lex;
13343            if (!lex->describe &&
13344                unlikely((!(lex->result= new (thd->mem_root)
13345                            select_dumpvar(thd)))))
13346              MYSQL_YYABORT;
13347          }
13348          select_var_list
13349          {}
13350        ;
13351
13352select_var_list:
13353          select_var_list ',' select_var_ident
13354        | select_var_ident {}
13355        ;
13356
13357select_var_ident: select_outvar
13358          {
13359            if (Lex->result)
13360            {
13361              if (unlikely($1 == NULL))
13362                MYSQL_YYABORT;
13363              ((select_dumpvar *)Lex->result)->var_list.push_back($1, thd->mem_root);
13364            }
13365            else
13366            {
13367              /*
13368                The parser won't create select_result instance only
13369                if it's an EXPLAIN.
13370              */
13371              DBUG_ASSERT(Lex->describe);
13372            }
13373          }
13374        ;
13375
13376select_outvar:
13377          '@' ident_or_text
13378          {
13379            $$ = Lex->result ? new (thd->mem_root) my_var_user(&$2) : NULL;
13380          }
13381        | ident_or_text
13382          {
13383            if (unlikely(!($$= Lex->create_outvar(thd, &$1)) && Lex->result))
13384              MYSQL_YYABORT;
13385          }
13386        | ident '.' ident
13387          {
13388            if (unlikely(!($$= Lex->create_outvar(thd, &$1, &$3)) && Lex->result))
13389              MYSQL_YYABORT;
13390          }
13391        ;
13392
13393into:
13394          INTO into_destination
13395          {}
13396        ;
13397
13398into_destination:
13399          OUTFILE TEXT_STRING_filesystem
13400          {
13401            LEX *lex= Lex;
13402            lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
13403            if (unlikely(!(lex->exchange=
13404                         new (thd->mem_root) sql_exchange($2.str, 0))) ||
13405                unlikely(!(lex->result=
13406                         new (thd->mem_root)
13407                         select_export(thd, lex->exchange))))
13408              MYSQL_YYABORT;
13409          }
13410          opt_load_data_charset
13411          { Lex->exchange->cs= $4; }
13412          opt_field_term opt_line_term
13413        | DUMPFILE TEXT_STRING_filesystem
13414          {
13415            LEX *lex=Lex;
13416            if (!lex->describe)
13417            {
13418              lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
13419              if (unlikely(!(lex->exchange=
13420                             new (thd->mem_root) sql_exchange($2.str,1))))
13421                MYSQL_YYABORT;
13422              if (unlikely(!(lex->result=
13423                           new (thd->mem_root)
13424                           select_dump(thd, lex->exchange))))
13425                MYSQL_YYABORT;
13426            }
13427          }
13428        | select_var_list_init
13429          {
13430            Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
13431          }
13432        ;
13433
13434/*
13435  DO statement
13436*/
13437
13438do:
13439          DO_SYM
13440          {
13441            LEX *lex=Lex;
13442            lex->sql_command = SQLCOM_DO;
13443            if (lex->main_select_push(true))
13444              MYSQL_YYABORT;
13445            mysql_init_select(lex);
13446          }
13447          expr_list
13448          {
13449            Lex->insert_list= $3;
13450            Lex->pop_select(); //main select
13451            if (Lex->check_cte_dependencies_and_resolve_references())
13452              MYSQL_YYABORT;
13453          }
13454        ;
13455
13456/*
13457  Drop : delete tables or index or user
13458*/
13459
13460drop:
13461          DROP opt_temporary table_or_tables opt_if_exists
13462          {
13463            LEX *lex=Lex;
13464            lex->set_command(SQLCOM_DROP_TABLE, $2, $4);
13465            YYPS->m_lock_type= TL_UNLOCK;
13466            YYPS->m_mdl_type= MDL_EXCLUSIVE;
13467          }
13468          table_list opt_lock_wait_timeout opt_restrict
13469          {}
13470        | DROP INDEX_SYM
13471          {
13472            if (Lex->main_select_push())
13473              MYSQL_YYABORT;
13474          }
13475          opt_if_exists_table_element ident ON table_ident opt_lock_wait_timeout
13476          {
13477            LEX *lex=Lex;
13478            Alter_drop *ad= (new (thd->mem_root)
13479                             Alter_drop(Alter_drop::KEY, $5.str, $4));
13480            if (unlikely(ad == NULL))
13481              MYSQL_YYABORT;
13482            lex->sql_command= SQLCOM_DROP_INDEX;
13483            lex->alter_info.reset();
13484            lex->alter_info.flags= ALTER_DROP_INDEX;
13485            lex->alter_info.drop_list.push_back(ad, thd->mem_root);
13486            if (unlikely(!lex->current_select->
13487                         add_table_to_list(thd, $7, NULL, TL_OPTION_UPDATING,
13488                                           TL_READ_NO_INSERT,
13489                                           MDL_SHARED_UPGRADABLE)))
13490              MYSQL_YYABORT;
13491            Lex->pop_select(); //main select
13492          }
13493        | DROP DATABASE opt_if_exists ident
13494          {
13495            LEX *lex=Lex;
13496            lex->set_command(SQLCOM_DROP_DB, $3);
13497            lex->name= $4;
13498          }
13499        | DROP PACKAGE_ORACLE_SYM opt_if_exists sp_name
13500          {
13501            LEX *lex= Lex;
13502            lex->set_command(SQLCOM_DROP_PACKAGE, $3);
13503            if (unlikely(lex->sphead))
13504              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE"));
13505            lex->spname= $4;
13506          }
13507        | DROP PACKAGE_ORACLE_SYM BODY_ORACLE_SYM opt_if_exists sp_name
13508          {
13509            LEX *lex= Lex;
13510            lex->set_command(SQLCOM_DROP_PACKAGE_BODY, $4);
13511            if (unlikely(lex->sphead))
13512              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE BODY"));
13513            lex->spname= $5;
13514          }
13515        | DROP FUNCTION_SYM opt_if_exists ident '.' ident
13516          {
13517            LEX *lex= thd->lex;
13518            sp_name *spname;
13519            if (unlikely($4.str && check_db_name((LEX_STRING*) &$4)))
13520              my_yyabort_error((ER_WRONG_DB_NAME, MYF(0), $4.str));
13521            if (unlikely(lex->sphead))
13522              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"));
13523            lex->set_command(SQLCOM_DROP_FUNCTION, $3);
13524            spname= new (thd->mem_root) sp_name(&$4, &$6, true);
13525            if (unlikely(spname == NULL))
13526              MYSQL_YYABORT;
13527            lex->spname= spname;
13528          }
13529        | DROP FUNCTION_SYM opt_if_exists ident
13530          {
13531            LEX *lex= thd->lex;
13532            LEX_CSTRING db= {0, 0};
13533            sp_name *spname;
13534            if (unlikely(lex->sphead))
13535              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"));
13536            if (thd->db.str && unlikely(lex->copy_db_to(&db)))
13537              MYSQL_YYABORT;
13538            lex->set_command(SQLCOM_DROP_FUNCTION, $3);
13539            spname= new (thd->mem_root) sp_name(&db, &$4, false);
13540            if (unlikely(spname == NULL))
13541              MYSQL_YYABORT;
13542            lex->spname= spname;
13543          }
13544        | DROP PROCEDURE_SYM opt_if_exists sp_name
13545          {
13546            LEX *lex=Lex;
13547            if (unlikely(lex->sphead))
13548              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE"));
13549            lex->set_command(SQLCOM_DROP_PROCEDURE, $3);
13550            lex->spname= $4;
13551          }
13552        | DROP USER_SYM opt_if_exists clear_privileges user_list
13553          {
13554            Lex->set_command(SQLCOM_DROP_USER, $3);
13555          }
13556        | DROP ROLE_SYM opt_if_exists clear_privileges role_list
13557          {
13558            Lex->set_command(SQLCOM_DROP_ROLE, $3);
13559          }
13560        | DROP VIEW_SYM opt_if_exists
13561          {
13562            LEX *lex= Lex;
13563            lex->set_command(SQLCOM_DROP_VIEW, $3);
13564            YYPS->m_lock_type= TL_UNLOCK;
13565            YYPS->m_mdl_type= MDL_EXCLUSIVE;
13566          }
13567          table_list opt_restrict
13568          {}
13569        | DROP EVENT_SYM opt_if_exists sp_name
13570          {
13571            Lex->spname= $4;
13572            Lex->set_command(SQLCOM_DROP_EVENT, $3);
13573          }
13574        | DROP TRIGGER_SYM opt_if_exists sp_name
13575          {
13576            LEX *lex= Lex;
13577            lex->set_command(SQLCOM_DROP_TRIGGER, $3);
13578            lex->spname= $4;
13579          }
13580        | DROP TABLESPACE tablespace_name opt_ts_engine opt_ts_wait
13581          {
13582            LEX *lex= Lex;
13583            lex->alter_tablespace_info->ts_cmd_type= DROP_TABLESPACE;
13584          }
13585        | DROP LOGFILE_SYM GROUP_SYM logfile_group_name opt_ts_engine opt_ts_wait
13586          {
13587            LEX *lex= Lex;
13588            lex->alter_tablespace_info->ts_cmd_type= DROP_LOGFILE_GROUP;
13589          }
13590        | DROP SERVER_SYM opt_if_exists ident_or_text
13591          {
13592            Lex->set_command(SQLCOM_DROP_SERVER, $3);
13593            Lex->server_options.reset($4);
13594          }
13595        | DROP opt_temporary SEQUENCE_SYM opt_if_exists
13596
13597          {
13598            LEX *lex= Lex;
13599            lex->set_command(SQLCOM_DROP_SEQUENCE, $2, $4);
13600            lex->table_type= TABLE_TYPE_SEQUENCE;
13601            YYPS->m_lock_type= TL_UNLOCK;
13602            YYPS->m_mdl_type= MDL_EXCLUSIVE;
13603          }
13604          table_list
13605          {}
13606        ;
13607
13608table_list:
13609          table_name
13610        | table_list ',' table_name
13611        ;
13612
13613table_name:
13614          table_ident
13615          {
13616            if (!thd->lex->current_select_or_default()->
13617                                           add_table_to_list(thd, $1, NULL,
13618                                           TL_OPTION_UPDATING,
13619                                           YYPS->m_lock_type,
13620                                           YYPS->m_mdl_type))
13621              MYSQL_YYABORT;
13622          }
13623        ;
13624
13625table_name_with_opt_use_partition:
13626          table_ident opt_use_partition
13627          {
13628            if (unlikely(!Select->add_table_to_list(thd, $1, NULL,
13629                                                    TL_OPTION_UPDATING,
13630                                                    YYPS->m_lock_type,
13631                                                    YYPS->m_mdl_type,
13632                                                    NULL,
13633                                                    $2)))
13634              MYSQL_YYABORT;
13635          }
13636        ;
13637
13638table_alias_ref_list:
13639          table_alias_ref
13640        | table_alias_ref_list ',' table_alias_ref
13641        ;
13642
13643table_alias_ref:
13644          table_ident_opt_wild
13645          {
13646            if (unlikely(!Select->
13647                         add_table_to_list(thd, $1, NULL,
13648                                           (TL_OPTION_UPDATING |
13649                                            TL_OPTION_ALIAS),
13650                                           YYPS->m_lock_type,
13651                                           YYPS->m_mdl_type)))
13652              MYSQL_YYABORT;
13653          }
13654        ;
13655
13656opt_if_exists_table_element:
13657          /* empty */
13658        {
13659          Lex->check_exists= FALSE;
13660          $$= 0;
13661        }
13662        | IF_SYM EXISTS
13663        {
13664          Lex->check_exists= TRUE;
13665          $$= 1;
13666        }
13667        ;
13668
13669opt_if_exists:
13670          /* empty */
13671        {
13672          $$.set(DDL_options_st::OPT_NONE);
13673        }
13674        | IF_SYM EXISTS
13675        {
13676          $$.set(DDL_options_st::OPT_IF_EXISTS);
13677        }
13678        ;
13679
13680opt_temporary:
13681          /* empty */ { $$= 0; }
13682        | TEMPORARY { $$= HA_LEX_CREATE_TMP_TABLE; }
13683        ;
13684/*
13685** Insert : add new data to table
13686*/
13687
13688insert:
13689          INSERT
13690          {
13691            LEX *lex= Lex;
13692            lex->sql_command= SQLCOM_INSERT;
13693            lex->duplicates= DUP_ERROR;
13694            if (Lex->main_select_push())
13695              MYSQL_YYABORT;
13696            mysql_init_select(lex);
13697            lex->current_select->parsing_place= BEFORE_OPT_LIST;
13698          }
13699          insert_lock_option
13700          opt_ignore insert2
13701          {
13702            Select->set_lock_for_tables($3, true);
13703            Lex->current_select= Lex->first_select_lex();
13704          }
13705          insert_field_spec opt_insert_update
13706          {
13707            Lex->pop_select(); //main select
13708            if (Lex->check_main_unit_semantics())
13709              MYSQL_YYABORT;
13710            Lex->mark_first_table_as_inserting();
13711          }
13712        ;
13713
13714replace:
13715          REPLACE
13716          {
13717            LEX *lex=Lex;
13718            lex->sql_command = SQLCOM_REPLACE;
13719            lex->duplicates= DUP_REPLACE;
13720            if (Lex->main_select_push())
13721              MYSQL_YYABORT;
13722            mysql_init_select(lex);
13723            lex->current_select->parsing_place= BEFORE_OPT_LIST;
13724          }
13725          replace_lock_option insert2
13726          {
13727            Select->set_lock_for_tables($3, true);
13728            Lex->current_select= Lex->first_select_lex();
13729          }
13730          insert_field_spec
13731          {
13732            Lex->pop_select(); //main select
13733            if (Lex->check_main_unit_semantics())
13734              MYSQL_YYABORT;
13735            Lex->mark_first_table_as_inserting();
13736          }
13737        ;
13738
13739insert_lock_option:
13740          /* empty */
13741          {
13742            /*
13743              If it is SP we do not allow insert optimisation when result of
13744              insert visible only after the table unlocking but everyone can
13745              read table.
13746            */
13747            $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT);
13748          }
13749        | LOW_PRIORITY  { $$= TL_WRITE_LOW_PRIORITY; }
13750        | DELAYED_SYM
13751        {
13752         // QQ: why was +1?
13753          Lex->keyword_delayed_begin_offset= (uint)($1.pos() - thd->query());
13754          Lex->keyword_delayed_end_offset= (uint)($1.end() - thd->query());
13755          $$= TL_WRITE_DELAYED;
13756        }
13757        | HIGH_PRIORITY { $$= TL_WRITE; }
13758        ;
13759
13760replace_lock_option:
13761          opt_low_priority { $$= $1; }
13762        | DELAYED_SYM
13763        {
13764          Lex->keyword_delayed_begin_offset= (uint)($1.pos() - thd->query());
13765          Lex->keyword_delayed_end_offset= (uint)($1.end() - thd->query());
13766          $$= TL_WRITE_DELAYED;
13767        }
13768        ;
13769
13770insert2:
13771          INTO insert_table {}
13772        | insert_table {}
13773        ;
13774
13775insert_table:
13776          {
13777            Select->save_parsing_place= Select->parsing_place;
13778          }
13779          table_name_with_opt_use_partition
13780          {
13781            LEX *lex=Lex;
13782            //lex->field_list.empty();
13783            lex->many_values.empty();
13784            lex->insert_list=0;
13785          }
13786        ;
13787
13788insert_field_spec:
13789          insert_values {}
13790        | insert_field_list insert_values {}
13791        | SET
13792          {
13793            LEX *lex=Lex;
13794            if (unlikely(!(lex->insert_list= new (thd->mem_root) List_item)) ||
13795                unlikely(lex->many_values.push_back(lex->insert_list,
13796                         thd->mem_root)))
13797              MYSQL_YYABORT;
13798            lex->current_select->parsing_place= NO_MATTER;
13799          }
13800          ident_eq_list
13801        ;
13802
13803insert_field_list:
13804          LEFT_PAREN_ALT opt_fields ')'
13805          {
13806            Lex->current_select->parsing_place= AFTER_LIST;
13807          }
13808        ;
13809
13810opt_fields:
13811          /* empty */
13812        | fields
13813        ;
13814
13815fields:
13816          fields ',' insert_ident
13817          { Lex->field_list.push_back($3, thd->mem_root); }
13818        | insert_ident { Lex->field_list.push_back($1, thd->mem_root); }
13819        ;
13820
13821
13822
13823insert_values:
13824         create_select_query_expression {}
13825        ;
13826
13827values_list:
13828          values_list ','  no_braces
13829        | no_braces_with_names
13830        ;
13831
13832ident_eq_list:
13833          ident_eq_list ',' ident_eq_value
13834        | ident_eq_value
13835        ;
13836
13837ident_eq_value:
13838          simple_ident_nospvar equal expr_or_ignore_or_default
13839          {
13840            LEX *lex=Lex;
13841            if (unlikely(lex->field_list.push_back($1, thd->mem_root)) ||
13842                unlikely(lex->insert_list->push_back($3, thd->mem_root)))
13843              MYSQL_YYABORT;
13844          }
13845        ;
13846
13847equal:
13848          '=' {}
13849        | SET_VAR {}
13850        ;
13851
13852opt_equal:
13853          /* empty */ {}
13854        | equal {}
13855        ;
13856
13857opt_with:
13858          opt_equal {}
13859        | WITH {}
13860        ;
13861
13862opt_by:
13863          opt_equal {}
13864        | BY {}
13865        ;
13866
13867no_braces:
13868          '('
13869          {
13870            if (unlikely(!(Lex->insert_list= new (thd->mem_root) List_item)))
13871              MYSQL_YYABORT;
13872          }
13873          opt_values ')'
13874          {
13875            LEX *lex=Lex;
13876            if (unlikely(lex->many_values.push_back(lex->insert_list,
13877                                                    thd->mem_root)))
13878              MYSQL_YYABORT;
13879          }
13880        ;
13881
13882no_braces_with_names:
13883          '('
13884          {
13885            if (unlikely(!(Lex->insert_list= new (thd->mem_root) List_item)))
13886              MYSQL_YYABORT;
13887          }
13888          opt_values_with_names ')'
13889          {
13890            LEX *lex=Lex;
13891            if (unlikely(lex->many_values.push_back(lex->insert_list,
13892                                                    thd->mem_root)))
13893              MYSQL_YYABORT;
13894          }
13895        ;
13896
13897opt_values:
13898          /* empty */ {}
13899        | values
13900        ;
13901
13902opt_values_with_names:
13903          /* empty */ {}
13904        | values_with_names
13905        ;
13906
13907values:
13908          values ','  expr_or_ignore_or_default
13909          {
13910            if (unlikely(Lex->insert_list->push_back($3, thd->mem_root)))
13911              MYSQL_YYABORT;
13912          }
13913        | expr_or_ignore_or_default
13914          {
13915            if (unlikely(Lex->insert_list->push_back($1, thd->mem_root)))
13916              MYSQL_YYABORT;
13917          }
13918        ;
13919
13920values_with_names:
13921          values_with_names ','  remember_name expr_or_ignore_or_default remember_end
13922          {
13923            if (unlikely(Lex->insert_list->push_back($4, thd->mem_root)))
13924               MYSQL_YYABORT;
13925            // give some name in case of using in table value constuctor (TVC)
13926            if (!$4->name.str || $4->name.str == item_empty_name)
13927              $4->set_name(thd, $3, (uint) ($5 - $3), thd->charset());
13928           }
13929        | remember_name expr_or_ignore_or_default remember_end
13930          {
13931            if (unlikely(Lex->insert_list->push_back($2, thd->mem_root)))
13932               MYSQL_YYABORT;
13933            // give some name in case of using in table value constuctor (TVC)
13934            if (!$2->name.str || $2->name.str == item_empty_name)
13935              $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset());
13936          }
13937        ;
13938
13939expr_or_ignore:
13940          expr { $$= $1;}
13941        | IGNORE_SYM
13942          {
13943            $$= new (thd->mem_root) Item_ignore_specification(thd);
13944            if (unlikely($$ == NULL))
13945              MYSQL_YYABORT;
13946          }
13947        ;
13948
13949expr_or_ignore_or_default:
13950          expr_or_ignore { $$= $1;}
13951        | DEFAULT
13952          {
13953            $$= new (thd->mem_root) Item_default_specification(thd);
13954            if (unlikely($$ == NULL))
13955              MYSQL_YYABORT;
13956          }
13957        ;
13958
13959opt_insert_update:
13960          /* empty */
13961        | ON DUPLICATE_SYM { Lex->duplicates= DUP_UPDATE; }
13962          KEY_SYM UPDATE_SYM
13963          {
13964	    Select->parsing_place= IN_UPDATE_ON_DUP_KEY;
13965          }
13966          insert_update_list
13967          {
13968	    Select->parsing_place= NO_MATTER;
13969          }
13970        ;
13971
13972update_table_list:
13973          table_ident opt_use_partition for_portion_of_time_clause
13974          opt_table_alias_clause opt_key_definition
13975          {
13976            SELECT_LEX *sel= Select;
13977            sel->table_join_options= 0;
13978            if (!($$= Select->add_table_to_list(thd, $1, $4,
13979                                                Select->get_table_join_options(),
13980                                                YYPS->m_lock_type,
13981                                                YYPS->m_mdl_type,
13982                                                Select->pop_index_hints(),
13983                                                $2)))
13984              MYSQL_YYABORT;
13985            $$->period_conditions= Lex->period_conditions;
13986          }
13987        | join_table_list { $$= $1; }
13988        ;
13989
13990/* Update rows in a table */
13991
13992update:
13993          UPDATE_SYM
13994          {
13995            LEX *lex= Lex;
13996            if (Lex->main_select_push())
13997              MYSQL_YYABORT;
13998            mysql_init_select(lex);
13999            lex->sql_command= SQLCOM_UPDATE;
14000            lex->duplicates= DUP_ERROR;
14001          }
14002          opt_low_priority opt_ignore update_table_list
14003          SET update_list
14004          {
14005            SELECT_LEX *slex= Lex->first_select_lex();
14006            if (slex->table_list.elements > 1)
14007              Lex->sql_command= SQLCOM_UPDATE_MULTI;
14008            else if (slex->get_table_list()->derived)
14009            {
14010              /* it is single table update and it is update of derived table */
14011              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
14012                       slex->get_table_list()->alias.str, "UPDATE");
14013              MYSQL_YYABORT;
14014            }
14015            /*
14016              In case of multi-update setting write lock for all tables may
14017              be too pessimistic. We will decrease lock level if possible in
14018              mysql_multi_update().
14019            */
14020            slex->set_lock_for_tables($3, slex->table_list.elements == 1);
14021          }
14022          opt_where_clause opt_order_clause delete_limit_clause
14023          {
14024            if ($10)
14025              Select->order_list= *($10);
14026            Lex->pop_select(); //main select
14027            if (Lex->check_main_unit_semantics())
14028              MYSQL_YYABORT;
14029          }
14030        ;
14031
14032update_list:
14033          update_list ',' update_elem
14034        | update_elem
14035        ;
14036
14037update_elem:
14038          simple_ident_nospvar equal DEFAULT
14039          {
14040            Item *def= new (thd->mem_root) Item_default_value(thd,
14041                                             Lex->current_context(), $1, 1);
14042            if (!def || add_item_to_list(thd, $1) || add_value_to_list(thd, def))
14043              MYSQL_YYABORT;
14044          }
14045        | simple_ident_nospvar equal expr_or_ignore
14046          {
14047            if (add_item_to_list(thd, $1) || add_value_to_list(thd, $3))
14048              MYSQL_YYABORT;
14049          }
14050        ;
14051
14052insert_update_list:
14053          insert_update_list ',' insert_update_elem
14054        | insert_update_elem
14055        ;
14056
14057insert_update_elem:
14058          simple_ident_nospvar equal expr_or_ignore_or_default
14059          {
14060          LEX *lex= Lex;
14061          if (unlikely(lex->update_list.push_back($1, thd->mem_root)) ||
14062              unlikely(lex->value_list.push_back($3, thd->mem_root)))
14063              MYSQL_YYABORT;
14064          }
14065        ;
14066
14067opt_low_priority:
14068          /* empty */ { $$= TL_WRITE_DEFAULT; }
14069        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
14070        ;
14071
14072/* Delete rows from a table */
14073
14074delete:
14075          DELETE_SYM
14076          {
14077            LEX *lex= Lex;
14078            lex->sql_command= SQLCOM_DELETE;
14079            YYPS->m_lock_type= TL_WRITE_DEFAULT;
14080            YYPS->m_mdl_type= MDL_SHARED_WRITE;
14081            if (Lex->main_select_push())
14082              MYSQL_YYABORT;
14083            mysql_init_select(lex);
14084            lex->ignore= 0;
14085            lex->first_select_lex()->order_list.empty();
14086          }
14087          delete_part2
14088          {
14089            if (Lex->check_cte_dependencies_and_resolve_references())
14090              MYSQL_YYABORT;
14091          }
14092          ;
14093
14094opt_delete_system_time:
14095            /* empty */
14096          {
14097            Lex->vers_conditions.init(SYSTEM_TIME_ALL);
14098          }
14099          | BEFORE_SYM SYSTEM_TIME_SYM history_point
14100          {
14101            Lex->vers_conditions.init(SYSTEM_TIME_BEFORE, $3);
14102          }
14103          ;
14104
14105delete_part2:
14106          opt_delete_options single_multi {}
14107        | HISTORY_SYM delete_single_table opt_delete_system_time
14108          {
14109            Lex->last_table()->vers_conditions= Lex->vers_conditions;
14110            Lex->pop_select(); //main select
14111          }
14112        ;
14113
14114delete_single_table:
14115          FROM table_ident opt_use_partition
14116          {
14117            if (unlikely(!Select->
14118                         add_table_to_list(thd, $2, NULL, TL_OPTION_UPDATING,
14119                                           YYPS->m_lock_type,
14120                                           YYPS->m_mdl_type,
14121                                           NULL,
14122                                           $3)))
14123              MYSQL_YYABORT;
14124            YYPS->m_lock_type= TL_READ_DEFAULT;
14125            YYPS->m_mdl_type= MDL_SHARED_READ;
14126          }
14127        ;
14128
14129delete_single_table_for_period:
14130          delete_single_table opt_for_portion_of_time_clause
14131          {
14132          if ($2)
14133            Lex->last_table()->period_conditions= Lex->period_conditions;
14134          }
14135        ;
14136
14137single_multi:
14138          delete_single_table_for_period
14139          opt_where_clause
14140          opt_order_clause
14141          delete_limit_clause
14142          opt_select_expressions
14143          {
14144            if ($3)
14145              Select->order_list= *($3);
14146            Lex->pop_select(); //main select
14147          }
14148        | table_wild_list
14149          {
14150            mysql_init_multi_delete(Lex);
14151            YYPS->m_lock_type= TL_READ_DEFAULT;
14152            YYPS->m_mdl_type= MDL_SHARED_READ;
14153          }
14154          FROM join_table_list opt_where_clause
14155          {
14156            if (unlikely(multi_delete_set_locks_and_link_aux_tables(Lex)))
14157              MYSQL_YYABORT;
14158            Lex->pop_select(); //main select
14159            if (Lex->check_main_unit_semantics())
14160              MYSQL_YYABORT;
14161          }
14162        | FROM table_alias_ref_list
14163          {
14164            mysql_init_multi_delete(Lex);
14165            YYPS->m_lock_type= TL_READ_DEFAULT;
14166            YYPS->m_mdl_type= MDL_SHARED_READ;
14167          }
14168          USING join_table_list opt_where_clause
14169          {
14170            if (unlikely(multi_delete_set_locks_and_link_aux_tables(Lex)))
14171              MYSQL_YYABORT;
14172            Lex->pop_select(); //main select
14173            if (Lex->check_main_unit_semantics())
14174              MYSQL_YYABORT;
14175          }
14176        ;
14177
14178opt_select_expressions:
14179          /* empty */
14180        | RETURNING_SYM select_item_list
14181        ;
14182
14183table_wild_list:
14184          table_wild_one
14185        | table_wild_list ',' table_wild_one
14186        ;
14187
14188table_wild_one:
14189          ident opt_wild
14190          {
14191            Table_ident *ti= new (thd->mem_root) Table_ident(&$1);
14192            if (unlikely(ti == NULL))
14193              MYSQL_YYABORT;
14194            if (unlikely(!Select->
14195                         add_table_to_list(thd,
14196                                           ti,
14197                                           NULL,
14198                                           (TL_OPTION_UPDATING |
14199                                            TL_OPTION_ALIAS),
14200                                           YYPS->m_lock_type,
14201                                           YYPS->m_mdl_type)))
14202              MYSQL_YYABORT;
14203          }
14204        | ident '.' ident opt_wild
14205          {
14206            Table_ident *ti= new (thd->mem_root) Table_ident(thd, &$1, &$3, 0);
14207            if (unlikely(ti == NULL))
14208              MYSQL_YYABORT;
14209            if (unlikely(!Select->
14210                         add_table_to_list(thd,
14211                                           ti,
14212                                           NULL,
14213                                           (TL_OPTION_UPDATING |
14214                                            TL_OPTION_ALIAS),
14215                                           YYPS->m_lock_type,
14216                                           YYPS->m_mdl_type)))
14217              MYSQL_YYABORT;
14218          }
14219        ;
14220
14221opt_wild:
14222          /* empty */ {}
14223        | '.' '*' {}
14224        ;
14225
14226opt_delete_options:
14227          /* empty */ {}
14228        | opt_delete_option opt_delete_options {}
14229        ;
14230
14231opt_delete_option:
14232          QUICK        { Select->options|= OPTION_QUICK; }
14233        | LOW_PRIORITY { YYPS->m_lock_type= TL_WRITE_LOW_PRIORITY; }
14234        | IGNORE_SYM   { Lex->ignore= 1; }
14235        ;
14236
14237truncate:
14238          TRUNCATE_SYM
14239          {
14240            LEX* lex= Lex;
14241            lex->sql_command= SQLCOM_TRUNCATE;
14242            lex->alter_info.reset();
14243            lex->first_select_lex()->options= 0;
14244            lex->sql_cache= LEX::SQL_CACHE_UNSPECIFIED;
14245            lex->first_select_lex()->order_list.empty();
14246            YYPS->m_lock_type= TL_WRITE;
14247            YYPS->m_mdl_type= MDL_EXCLUSIVE;
14248          }
14249          opt_table_sym table_name opt_lock_wait_timeout
14250          {
14251            LEX* lex= thd->lex;
14252            DBUG_ASSERT(!lex->m_sql_cmd);
14253            lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_truncate_table();
14254            if (unlikely(lex->m_sql_cmd == NULL))
14255              MYSQL_YYABORT;
14256          }
14257          opt_truncate_table_storage_clause { }
14258        ;
14259
14260opt_truncate_table_storage_clause:
14261          /* Empty */
14262        | DROP STORAGE_SYM
14263        | REUSE_SYM STORAGE_SYM
14264        ;
14265
14266opt_table_sym:
14267          /* empty */
14268        | TABLE_SYM
14269        ;
14270
14271opt_profile_defs:
14272  /* empty */
14273  | profile_defs;
14274
14275profile_defs:
14276  profile_def
14277  | profile_defs ',' profile_def;
14278
14279profile_def:
14280  CPU_SYM
14281    {
14282      Lex->profile_options|= PROFILE_CPU;
14283    }
14284  | MEMORY_SYM
14285    {
14286      Lex->profile_options|= PROFILE_MEMORY;
14287    }
14288  | BLOCK_SYM IO_SYM
14289    {
14290      Lex->profile_options|= PROFILE_BLOCK_IO;
14291    }
14292  | CONTEXT_SYM SWITCHES_SYM
14293    {
14294      Lex->profile_options|= PROFILE_CONTEXT;
14295    }
14296  | PAGE_SYM FAULTS_SYM
14297    {
14298      Lex->profile_options|= PROFILE_PAGE_FAULTS;
14299    }
14300  | IPC_SYM
14301    {
14302      Lex->profile_options|= PROFILE_IPC;
14303    }
14304  | SWAPS_SYM
14305    {
14306      Lex->profile_options|= PROFILE_SWAPS;
14307    }
14308  | SOURCE_SYM
14309    {
14310      Lex->profile_options|= PROFILE_SOURCE;
14311    }
14312  | ALL
14313    {
14314      Lex->profile_options|= PROFILE_ALL;
14315    }
14316  ;
14317
14318opt_profile_args:
14319  /* empty */
14320    {
14321      Lex->profile_query_id= 0;
14322    }
14323  | FOR_SYM QUERY_SYM NUM
14324    {
14325      Lex->profile_query_id= atoi($3.str);
14326    }
14327  ;
14328
14329/* Show things */
14330
14331show:
14332          SHOW
14333          {
14334            LEX *lex=Lex;
14335            lex->wild=0;
14336            lex->ident= null_clex_str;
14337            if (Lex->main_select_push())
14338              MYSQL_YYABORT;
14339            mysql_init_select(lex);
14340            lex->current_select->parsing_place= SELECT_LIST;
14341            lex->create_info.init();
14342          }
14343          show_param
14344          {
14345            Select->parsing_place= NO_MATTER;
14346            Lex->pop_select(); //main select
14347          }
14348        ;
14349
14350show_param:
14351           DATABASES wild_and_where
14352           {
14353             LEX *lex= Lex;
14354             lex->sql_command= SQLCOM_SHOW_DATABASES;
14355             if (unlikely(prepare_schema_table(thd, lex, 0, SCH_SCHEMATA)))
14356               MYSQL_YYABORT;
14357           }
14358         | opt_full TABLES opt_db wild_and_where
14359           {
14360             LEX *lex= Lex;
14361             lex->sql_command= SQLCOM_SHOW_TABLES;
14362             lex->first_select_lex()->db= $3;
14363             if (prepare_schema_table(thd, lex, 0, SCH_TABLE_NAMES))
14364               MYSQL_YYABORT;
14365           }
14366         | opt_full TRIGGERS_SYM opt_db wild_and_where
14367           {
14368             LEX *lex= Lex;
14369             lex->sql_command= SQLCOM_SHOW_TRIGGERS;
14370             lex->first_select_lex()->db= $3;
14371             if (prepare_schema_table(thd, lex, 0, SCH_TRIGGERS))
14372               MYSQL_YYABORT;
14373           }
14374         | EVENTS_SYM opt_db wild_and_where
14375           {
14376             LEX *lex= Lex;
14377             lex->sql_command= SQLCOM_SHOW_EVENTS;
14378             lex->first_select_lex()->db= $2;
14379             if (prepare_schema_table(thd, lex, 0, SCH_EVENTS))
14380               MYSQL_YYABORT;
14381           }
14382         | TABLE_SYM STATUS_SYM opt_db wild_and_where
14383           {
14384             LEX *lex= Lex;
14385             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
14386             lex->first_select_lex()->db= $3;
14387             if (prepare_schema_table(thd, lex, 0, SCH_TABLES))
14388               MYSQL_YYABORT;
14389           }
14390        | OPEN_SYM TABLES opt_db wild_and_where
14391          {
14392            LEX *lex= Lex;
14393            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
14394            lex->first_select_lex()->db= $3;
14395            if (prepare_schema_table(thd, lex, 0, SCH_OPEN_TABLES))
14396              MYSQL_YYABORT;
14397          }
14398        | PLUGINS_SYM
14399          {
14400            LEX *lex= Lex;
14401            lex->sql_command= SQLCOM_SHOW_PLUGINS;
14402            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PLUGINS)))
14403              MYSQL_YYABORT;
14404          }
14405        | PLUGINS_SYM SONAME_SYM TEXT_STRING_sys
14406          {
14407            Lex->ident= $3;
14408            Lex->sql_command= SQLCOM_SHOW_PLUGINS;
14409            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_ALL_PLUGINS)))
14410              MYSQL_YYABORT;
14411          }
14412        | PLUGINS_SYM SONAME_SYM wild_and_where
14413          {
14414            Lex->sql_command= SQLCOM_SHOW_PLUGINS;
14415            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_ALL_PLUGINS)))
14416              MYSQL_YYABORT;
14417          }
14418        | ENGINE_SYM known_storage_engines show_engine_param
14419          { Lex->create_info.db_type= $2; }
14420        | ENGINE_SYM ALL show_engine_param
14421          { Lex->create_info.db_type= NULL; }
14422        | opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
14423          {
14424            LEX *lex= Lex;
14425            lex->sql_command= SQLCOM_SHOW_FIELDS;
14426            if ($5.str)
14427              $4->change_db(&$5);
14428            if (unlikely(prepare_schema_table(thd, lex, $4, SCH_COLUMNS)))
14429              MYSQL_YYABORT;
14430          }
14431        | master_or_binary LOGS_SYM
14432          {
14433            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
14434          }
14435        | SLAVE HOSTS_SYM
14436          {
14437            Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
14438          }
14439        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
14440          {
14441            LEX *lex= Lex;
14442            lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
14443          }
14444          opt_global_limit_clause
14445        | RELAYLOG_SYM optional_connection_name EVENTS_SYM binlog_in binlog_from
14446          {
14447            LEX *lex= Lex;
14448            lex->sql_command= SQLCOM_SHOW_RELAYLOG_EVENTS;
14449          }
14450          opt_global_limit_clause
14451        | keys_or_index from_or_in table_ident opt_db opt_where_clause
14452          {
14453            LEX *lex= Lex;
14454            lex->sql_command= SQLCOM_SHOW_KEYS;
14455            if ($4.str)
14456              $3->change_db(&$4);
14457            if (unlikely(prepare_schema_table(thd, lex, $3, SCH_STATISTICS)))
14458              MYSQL_YYABORT;
14459          }
14460        | opt_storage ENGINES_SYM
14461          {
14462            LEX *lex=Lex;
14463            lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
14464            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_ENGINES)))
14465              MYSQL_YYABORT;
14466          }
14467        | AUTHORS_SYM
14468          {
14469            LEX *lex=Lex;
14470            lex->sql_command= SQLCOM_SHOW_AUTHORS;
14471          }
14472        | CONTRIBUTORS_SYM
14473          {
14474            LEX *lex=Lex;
14475            lex->sql_command= SQLCOM_SHOW_CONTRIBUTORS;
14476          }
14477        | PRIVILEGES
14478          {
14479            LEX *lex=Lex;
14480            lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
14481          }
14482        | COUNT_SYM '(' '*' ')' WARNINGS
14483          {
14484            LEX_CSTRING var= {STRING_WITH_LEN("warning_count")};
14485            (void) create_select_for_variable(thd, &var);
14486          }
14487        | COUNT_SYM '(' '*' ')' ERRORS
14488          {
14489            LEX_CSTRING var= {STRING_WITH_LEN("error_count")};
14490            (void) create_select_for_variable(thd, &var);
14491          }
14492        | WARNINGS opt_global_limit_clause
14493          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
14494        | ERRORS opt_global_limit_clause
14495          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
14496        | PROFILES_SYM
14497          { Lex->sql_command = SQLCOM_SHOW_PROFILES; }
14498        | PROFILE_SYM opt_profile_defs opt_profile_args opt_global_limit_clause
14499          {
14500            LEX *lex= Lex;
14501            lex->sql_command= SQLCOM_SHOW_PROFILE;
14502            if (unlikely(prepare_schema_table(thd, lex, NULL, SCH_PROFILES)))
14503              MYSQL_YYABORT;
14504          }
14505        | opt_var_type STATUS_SYM wild_and_where
14506          {
14507            LEX *lex= Lex;
14508            lex->sql_command= SQLCOM_SHOW_STATUS;
14509            lex->option_type= $1;
14510            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_SESSION_STATUS)))
14511              MYSQL_YYABORT;
14512          }
14513        | opt_full PROCESSLIST_SYM
14514          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
14515        | opt_var_type  VARIABLES wild_and_where
14516          {
14517            LEX *lex= Lex;
14518            lex->sql_command= SQLCOM_SHOW_VARIABLES;
14519            lex->option_type= $1;
14520            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_SESSION_VARIABLES)))
14521              MYSQL_YYABORT;
14522          }
14523        | charset wild_and_where
14524          {
14525            LEX *lex= Lex;
14526            lex->sql_command= SQLCOM_SHOW_CHARSETS;
14527            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_CHARSETS)))
14528              MYSQL_YYABORT;
14529          }
14530        | COLLATION_SYM wild_and_where
14531          {
14532            LEX *lex= Lex;
14533            lex->sql_command= SQLCOM_SHOW_COLLATIONS;
14534            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_COLLATIONS)))
14535              MYSQL_YYABORT;
14536          }
14537        | GRANTS
14538          {
14539            Lex->sql_command= SQLCOM_SHOW_GRANTS;
14540            if (unlikely(!(Lex->grant_user=
14541                          (LEX_USER*)thd->alloc(sizeof(LEX_USER)))))
14542              MYSQL_YYABORT;
14543            Lex->grant_user->user= current_user_and_current_role;
14544          }
14545        | GRANTS FOR_SYM user_or_role clear_privileges
14546          {
14547            LEX *lex=Lex;
14548            lex->sql_command= SQLCOM_SHOW_GRANTS;
14549            lex->grant_user=$3;
14550          }
14551        | CREATE DATABASE opt_if_not_exists ident
14552          {
14553            Lex->set_command(SQLCOM_SHOW_CREATE_DB, $3);
14554            Lex->name= $4;
14555          }
14556        | CREATE TABLE_SYM table_ident
14557          {
14558            LEX *lex= Lex;
14559            lex->sql_command = SQLCOM_SHOW_CREATE;
14560            if (!lex->first_select_lex()->add_table_to_list(thd, $3, NULL,0))
14561              MYSQL_YYABORT;
14562            lex->create_info.storage_media= HA_SM_DEFAULT;
14563          }
14564        | CREATE VIEW_SYM table_ident
14565          {
14566            LEX *lex= Lex;
14567            lex->sql_command = SQLCOM_SHOW_CREATE;
14568            if (!lex->first_select_lex()->add_table_to_list(thd, $3, NULL, 0))
14569              MYSQL_YYABORT;
14570            lex->table_type= TABLE_TYPE_VIEW;
14571          }
14572        | CREATE SEQUENCE_SYM table_ident
14573          {
14574            LEX *lex= Lex;
14575            lex->sql_command = SQLCOM_SHOW_CREATE;
14576            if (!lex->first_select_lex()->add_table_to_list(thd, $3, NULL, 0))
14577              MYSQL_YYABORT;
14578            lex->table_type= TABLE_TYPE_SEQUENCE;
14579          }
14580        | MASTER_SYM STATUS_SYM
14581          {
14582            Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
14583          }
14584        | ALL SLAVES STATUS_SYM
14585          {
14586            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
14587            Lex->verbose= 1;
14588          }
14589        | SLAVE STATUS_SYM
14590          {
14591            LEX *lex= thd->lex;
14592            lex->mi.connection_name= null_clex_str;
14593            lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
14594            lex->verbose= 0;
14595          }
14596        | SLAVE connection_name STATUS_SYM
14597          {
14598            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
14599            Lex->verbose= 0;
14600          }
14601        | CREATE PROCEDURE_SYM sp_name
14602          {
14603            LEX *lex= Lex;
14604
14605            lex->sql_command = SQLCOM_SHOW_CREATE_PROC;
14606            lex->spname= $3;
14607          }
14608        | CREATE FUNCTION_SYM sp_name
14609          {
14610            LEX *lex= Lex;
14611
14612            lex->sql_command = SQLCOM_SHOW_CREATE_FUNC;
14613            lex->spname= $3;
14614          }
14615        | CREATE PACKAGE_ORACLE_SYM sp_name
14616          {
14617            LEX *lex= Lex;
14618            lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE;
14619            lex->spname= $3;
14620          }
14621        | CREATE PACKAGE_ORACLE_SYM BODY_ORACLE_SYM sp_name
14622          {
14623            LEX *lex= Lex;
14624            lex->sql_command = SQLCOM_SHOW_CREATE_PACKAGE_BODY;
14625            lex->spname= $4;
14626          }
14627        | CREATE TRIGGER_SYM sp_name
14628          {
14629            LEX *lex= Lex;
14630            lex->sql_command= SQLCOM_SHOW_CREATE_TRIGGER;
14631            lex->spname= $3;
14632          }
14633        | CREATE USER_SYM
14634          {
14635            Lex->sql_command= SQLCOM_SHOW_CREATE_USER;
14636            if (unlikely(!(Lex->grant_user=
14637                          (LEX_USER*)thd->alloc(sizeof(LEX_USER)))))
14638              MYSQL_YYABORT;
14639            Lex->grant_user->user= current_user;
14640          }
14641        | CREATE USER_SYM user
14642          {
14643             Lex->sql_command= SQLCOM_SHOW_CREATE_USER;
14644             Lex->grant_user= $3;
14645          }
14646        | PROCEDURE_SYM STATUS_SYM wild_and_where
14647          {
14648            LEX *lex= Lex;
14649            lex->sql_command= SQLCOM_SHOW_STATUS_PROC;
14650            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
14651              MYSQL_YYABORT;
14652          }
14653        | FUNCTION_SYM STATUS_SYM wild_and_where
14654          {
14655            LEX *lex= Lex;
14656            lex->sql_command= SQLCOM_SHOW_STATUS_FUNC;
14657            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
14658              MYSQL_YYABORT;
14659          }
14660        | PACKAGE_ORACLE_SYM STATUS_SYM wild_and_where
14661          {
14662            LEX *lex= Lex;
14663            lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE;
14664            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
14665              MYSQL_YYABORT;
14666          }
14667        | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM STATUS_SYM wild_and_where
14668          {
14669            LEX *lex= Lex;
14670            lex->sql_command= SQLCOM_SHOW_STATUS_PACKAGE_BODY;
14671            if (unlikely(prepare_schema_table(thd, lex, 0, SCH_PROCEDURES)))
14672              MYSQL_YYABORT;
14673          }
14674        | PROCEDURE_SYM CODE_SYM sp_name
14675          {
14676            Lex->sql_command= SQLCOM_SHOW_PROC_CODE;
14677            Lex->spname= $3;
14678          }
14679        | FUNCTION_SYM CODE_SYM sp_name
14680          {
14681            Lex->sql_command= SQLCOM_SHOW_FUNC_CODE;
14682            Lex->spname= $3;
14683          }
14684        | PACKAGE_ORACLE_SYM BODY_ORACLE_SYM CODE_SYM sp_name
14685          {
14686            Lex->sql_command= SQLCOM_SHOW_PACKAGE_BODY_CODE;
14687            Lex->spname= $4;
14688          }
14689        | CREATE EVENT_SYM sp_name
14690          {
14691            Lex->spname= $3;
14692            Lex->sql_command = SQLCOM_SHOW_CREATE_EVENT;
14693          }
14694        | describe_command FOR_SYM expr
14695          {
14696            Lex->sql_command= SQLCOM_SHOW_EXPLAIN;
14697            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_EXPLAIN)))
14698              MYSQL_YYABORT;
14699            add_value_to_list(thd, $3);
14700          }
14701        | IDENT_sys remember_tok_start wild_and_where
14702           {
14703             LEX *lex= Lex;
14704             bool in_plugin;
14705             lex->sql_command= SQLCOM_SHOW_GENERIC;
14706             ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1, &in_plugin);
14707             if (unlikely(!table || !table->old_format || !in_plugin))
14708             {
14709               thd->parse_error(ER_SYNTAX_ERROR, $2);
14710               MYSQL_YYABORT;
14711             }
14712             if (unlikely(lex->wild && table->idx_field1 < 0))
14713             {
14714               thd->parse_error(ER_SYNTAX_ERROR, $3);
14715               MYSQL_YYABORT;
14716             }
14717             if (unlikely(make_schema_select(thd, Lex->current_select, table)))
14718               MYSQL_YYABORT;
14719           }
14720        ;
14721
14722show_engine_param:
14723          STATUS_SYM
14724          { Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS; }
14725        | MUTEX_SYM
14726          { Lex->sql_command= SQLCOM_SHOW_ENGINE_MUTEX; }
14727        | LOGS_SYM
14728          { Lex->sql_command= SQLCOM_SHOW_ENGINE_LOGS; }
14729        ;
14730
14731master_or_binary:
14732          MASTER_SYM
14733        | BINARY
14734        ;
14735
14736opt_storage:
14737          /* empty */
14738        | STORAGE_SYM
14739        ;
14740
14741opt_db:
14742          /* empty */      { $$= null_clex_str; }
14743        | from_or_in ident { $$= $2; }
14744        ;
14745
14746opt_full:
14747          /* empty */ { Lex->verbose=0; }
14748        | FULL        { Lex->verbose=1; }
14749        ;
14750
14751from_or_in:
14752          FROM
14753        | IN_SYM
14754        ;
14755
14756binlog_in:
14757          /* empty */            { Lex->mi.log_file_name = 0; }
14758        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
14759        ;
14760
14761binlog_from:
14762          /* empty */        { Lex->mi.pos = 4; /* skip magic number */ }
14763        | FROM ulonglong_num { Lex->mi.pos = $2; }
14764        ;
14765
14766wild_and_where:
14767          /* empty */ { $$= 0; }
14768        | LIKE remember_tok_start TEXT_STRING_sys
14769          {
14770            Lex->wild= new (thd->mem_root) String($3.str, $3.length,
14771                                                    system_charset_info);
14772            if (unlikely(Lex->wild == NULL))
14773              MYSQL_YYABORT;
14774            $$= $2;
14775          }
14776        | WHERE remember_tok_start expr
14777          {
14778            Select->where= normalize_cond(thd, $3);
14779            if ($3)
14780              $3->top_level_item();
14781            $$= $2;
14782          }
14783        ;
14784
14785/* A Oracle compatible synonym for show */
14786describe:
14787          describe_command table_ident
14788          {
14789            LEX *lex= Lex;
14790            if (lex->main_select_push())
14791              MYSQL_YYABORT;
14792            mysql_init_select(lex);
14793            lex->current_select->parsing_place= SELECT_LIST;
14794            lex->sql_command= SQLCOM_SHOW_FIELDS;
14795            lex->first_select_lex()->db= null_clex_str;
14796            lex->verbose= 0;
14797            if (unlikely(prepare_schema_table(thd, lex, $2, SCH_COLUMNS)))
14798              MYSQL_YYABORT;
14799          }
14800          opt_describe_column
14801          {
14802            Select->parsing_place= NO_MATTER;
14803            Lex->pop_select(); //main select
14804          }
14805        | describe_command opt_extended_describe
14806          { Lex->describe|= DESCRIBE_NORMAL; }
14807          explainable_command
14808          {
14809            LEX *lex=Lex;
14810            lex->first_select_lex()->options|= SELECT_DESCRIBE;
14811          }
14812        ;
14813
14814explainable_command:
14815          select
14816        | select_into
14817        | insert
14818        | replace
14819        | update
14820        | delete
14821        ;
14822
14823describe_command:
14824          DESC
14825        | DESCRIBE
14826        ;
14827
14828analyze_stmt_command:
14829          ANALYZE_SYM opt_format_json explainable_command
14830          {
14831            Lex->analyze_stmt= true;
14832          }
14833        ;
14834
14835opt_extended_describe:
14836          EXTENDED_SYM   { Lex->describe|= DESCRIBE_EXTENDED; }
14837        | EXTENDED_SYM ALL
14838          { Lex->describe|= DESCRIBE_EXTENDED | DESCRIBE_EXTENDED2; }
14839        | PARTITIONS_SYM { Lex->describe|= DESCRIBE_PARTITIONS; }
14840        | opt_format_json {}
14841        ;
14842
14843opt_format_json:
14844          /* empty */ {}
14845        | FORMAT_SYM '=' ident_or_text
14846          {
14847            if (lex_string_eq(&$3, STRING_WITH_LEN("JSON")))
14848              Lex->explain_json= true;
14849            else if (lex_string_eq(&$3, STRING_WITH_LEN("TRADITIONAL")))
14850              DBUG_ASSERT(Lex->explain_json==false);
14851            else
14852              my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "EXPLAIN",
14853                               $3.str));
14854          }
14855        ;
14856
14857opt_describe_column:
14858          /* empty */ {}
14859        | text_string { Lex->wild= $1; }
14860        | ident
14861          {
14862            Lex->wild= new (thd->mem_root) String((const char*) $1.str,
14863                                                    $1.length,
14864                                                    system_charset_info);
14865            if (unlikely(Lex->wild == NULL))
14866              MYSQL_YYABORT;
14867          }
14868        ;
14869
14870
14871/* flush things */
14872
14873flush:
14874          FLUSH_SYM opt_no_write_to_binlog
14875          {
14876            LEX *lex=Lex;
14877            lex->sql_command= SQLCOM_FLUSH;
14878            lex->type= 0;
14879            lex->no_write_to_binlog= $2;
14880          }
14881          flush_options {}
14882        ;
14883
14884flush_options:
14885          table_or_tables
14886          {
14887            Lex->type|= REFRESH_TABLES;
14888            /*
14889              Set type of metadata and table locks for
14890              FLUSH TABLES table_list [WITH READ LOCK].
14891            */
14892            YYPS->m_lock_type= TL_READ_NO_INSERT;
14893            YYPS->m_mdl_type= MDL_SHARED_HIGH_PRIO;
14894          }
14895          opt_table_list opt_flush_lock
14896          {}
14897        | flush_options_list
14898          {}
14899        ;
14900
14901opt_flush_lock:
14902          /* empty */ {}
14903        | flush_lock
14904        {
14905          TABLE_LIST *tables= Lex->query_tables;
14906          for (; tables; tables= tables->next_global)
14907          {
14908            tables->mdl_request.set_type(MDL_SHARED_NO_WRITE);
14909            /* Don't try to flush views. */
14910            tables->required_type= TABLE_TYPE_NORMAL;
14911            /* Ignore temporary tables. */
14912            tables->open_type= OT_BASE_ONLY;
14913          }
14914        }
14915        ;
14916
14917flush_lock:
14918          WITH READ_SYM LOCK_SYM optional_flush_tables_arguments
14919          { Lex->type|= REFRESH_READ_LOCK | $4; }
14920        | FOR_SYM
14921          {
14922            if (unlikely(Lex->query_tables == NULL))
14923            {
14924              // Table list can't be empty
14925              thd->parse_error(ER_NO_TABLES_USED);
14926              MYSQL_YYABORT;
14927            }
14928            Lex->type|= REFRESH_FOR_EXPORT;
14929          } EXPORT_SYM {}
14930        ;
14931
14932flush_options_list:
14933          flush_options_list ',' flush_option
14934        | flush_option
14935          {}
14936        ;
14937
14938flush_option:
14939          ERROR_SYM LOGS_SYM
14940          { Lex->type|= REFRESH_ERROR_LOG; }
14941        | ENGINE_SYM LOGS_SYM
14942          { Lex->type|= REFRESH_ENGINE_LOG; }
14943        | GENERAL LOGS_SYM
14944          { Lex->type|= REFRESH_GENERAL_LOG; }
14945        | SLOW LOGS_SYM
14946          { Lex->type|= REFRESH_SLOW_LOG; }
14947        | BINARY LOGS_SYM opt_delete_gtid_domain
14948          { Lex->type|= REFRESH_BINARY_LOG; }
14949        | RELAY LOGS_SYM optional_connection_name
14950          {
14951            LEX *lex= Lex;
14952            if (unlikely(lex->type & REFRESH_RELAY_LOG))
14953              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "FLUSH", "RELAY LOGS"));
14954            lex->type|= REFRESH_RELAY_LOG;
14955            lex->relay_log_connection_name= lex->mi.connection_name;
14956           }
14957        | QUERY_SYM CACHE_SYM
14958          { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
14959        | HOSTS_SYM
14960          { Lex->type|= REFRESH_HOSTS; }
14961        | PRIVILEGES
14962          { Lex->type|= REFRESH_GRANT; }
14963        | LOGS_SYM
14964          {
14965            Lex->type|= REFRESH_LOG;
14966            Lex->relay_log_connection_name= empty_clex_str;
14967          }
14968        | STATUS_SYM
14969          { Lex->type|= REFRESH_STATUS; }
14970        | SLAVE optional_connection_name
14971          {
14972            LEX *lex= Lex;
14973            if (unlikely(lex->type & REFRESH_SLAVE))
14974              my_yyabort_error((ER_WRONG_USAGE, MYF(0), "FLUSH","SLAVE"));
14975            lex->type|= REFRESH_SLAVE;
14976            lex->reset_slave_info.all= false;
14977          }
14978        | MASTER_SYM
14979          { Lex->type|= REFRESH_MASTER; }
14980        | DES_KEY_FILE
14981          { Lex->type|= REFRESH_DES_KEY_FILE; }
14982        | RESOURCES
14983          { Lex->type|= REFRESH_USER_RESOURCES; }
14984        | SSL_SYM
14985          { Lex->type|= REFRESH_SSL;}
14986        | IDENT_sys remember_tok_start
14987           {
14988             Lex->type|= REFRESH_GENERIC;
14989             ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1);
14990             if (unlikely(!table || !table->reset_table))
14991             {
14992               thd->parse_error(ER_SYNTAX_ERROR, $2);
14993               MYSQL_YYABORT;
14994             }
14995             if (unlikely(Lex->view_list.push_back((LEX_CSTRING*)
14996                                                   thd->memdup(&$1, sizeof(LEX_CSTRING)),
14997                                                   thd->mem_root)))
14998               MYSQL_YYABORT;
14999           }
15000        ;
15001
15002opt_table_list:
15003          /* empty */  {}
15004        | table_list {}
15005        ;
15006
15007backup:
15008        BACKUP_SYM backup_statements {}
15009	;
15010
15011backup_statements:
15012	STAGE_SYM ident
15013        {
15014          int type;
15015          if (unlikely(Lex->sphead))
15016            my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "BACKUP STAGE"));
15017          if ((type= find_type($2.str, &backup_stage_names,
15018                               FIND_TYPE_NO_PREFIX)) <= 0)
15019            my_yyabort_error((ER_BACKUP_UNKNOWN_STAGE, MYF(0), $2.str));
15020          Lex->sql_command= SQLCOM_BACKUP;
15021          Lex->backup_stage= (backup_stages) (type-1);
15022          break;
15023        }
15024	| LOCK_SYM
15025          {
15026            if (Lex->main_select_push())
15027              MYSQL_YYABORT;
15028          }
15029          table_ident
15030          {
15031	    if (unlikely(!Select->add_table_to_list(thd, $3, NULL, 0,
15032                                                    TL_READ, MDL_SHARED_HIGH_PRIO)))
15033             MYSQL_YYABORT;
15034            Lex->sql_command= SQLCOM_BACKUP_LOCK;
15035            Lex->pop_select(); //main select
15036          }
15037        | UNLOCK_SYM
15038          {
15039	    /* Table list is empty for unlock */
15040            Lex->sql_command= SQLCOM_BACKUP_LOCK;
15041          }
15042        ;
15043
15044opt_delete_gtid_domain:
15045          /* empty */ {}
15046        | DELETE_DOMAIN_ID_SYM '=' '(' delete_domain_id_list ')'
15047          {}
15048        ;
15049delete_domain_id_list:
15050          /* Empty */
15051        | delete_domain_id
15052        | delete_domain_id_list ',' delete_domain_id
15053        ;
15054
15055delete_domain_id:
15056          ulonglong_num
15057          {
15058            uint32 value= (uint32) $1;
15059            if ($1 > UINT_MAX32)
15060            {
15061              my_printf_error(ER_BINLOG_CANT_DELETE_GTID_DOMAIN,
15062                              "The value of gtid domain being deleted ('%llu') "
15063                              "exceeds its maximum size "
15064                              "of 32 bit unsigned integer", MYF(0), $1);
15065              MYSQL_YYABORT;
15066            }
15067            insert_dynamic(&Lex->delete_gtid_domain, (uchar*) &value);
15068          }
15069        ;
15070
15071optional_flush_tables_arguments:
15072          /* empty */        {$$= 0;}
15073        | AND_SYM DISABLE_SYM CHECKPOINT_SYM {$$= REFRESH_CHECKPOINT; }
15074        ;
15075
15076reset:
15077          RESET_SYM
15078          {
15079            LEX *lex=Lex;
15080            lex->sql_command= SQLCOM_RESET; lex->type=0;
15081          }
15082          reset_options
15083          {}
15084        ;
15085
15086reset_options:
15087          reset_options ',' reset_option
15088        | reset_option
15089        ;
15090
15091reset_option:
15092          SLAVE               { Lex->type|= REFRESH_SLAVE; }
15093          optional_connection_name
15094          slave_reset_options { }
15095        | MASTER_SYM
15096          {
15097             Lex->type|= REFRESH_MASTER;
15098             Lex->next_binlog_file_number= 0;
15099          }
15100          master_reset_options
15101        | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;}
15102        ;
15103
15104slave_reset_options:
15105          /* empty */ { Lex->reset_slave_info.all= false; }
15106        | ALL         { Lex->reset_slave_info.all= true; }
15107        ;
15108
15109master_reset_options:
15110          /* empty */ {}
15111        | TO_SYM ulong_num
15112          {
15113            Lex->next_binlog_file_number = $2;
15114          }
15115        ;
15116
15117purge:
15118          PURGE master_or_binary LOGS_SYM TO_SYM TEXT_STRING_sys
15119          {
15120            Lex->stmt_purge_to($5);
15121          }
15122        | PURGE master_or_binary LOGS_SYM BEFORE_SYM
15123          { Lex->clause_that_disallows_subselect= "PURGE..BEFORE"; }
15124          expr
15125          {
15126            Lex->clause_that_disallows_subselect= NULL;
15127            if (Lex->stmt_purge_before($6))
15128              MYSQL_YYABORT;
15129          }
15130        ;
15131
15132
15133/* kill threads */
15134
15135kill:
15136          KILL_SYM
15137          {
15138            LEX *lex=Lex;
15139            lex->value_list.empty();
15140            lex->users_list.empty();
15141            lex->sql_command= SQLCOM_KILL;
15142            lex->kill_type= KILL_TYPE_ID;
15143          }
15144          kill_type kill_option
15145          {
15146            Lex->kill_signal= (killed_state) ($3 | $4);
15147          }
15148        ;
15149
15150kill_type:
15151        /* Empty */    { $$= (int) KILL_HARD_BIT; }
15152        | HARD_SYM     { $$= (int) KILL_HARD_BIT; }
15153        | SOFT_SYM     { $$= 0; }
15154        ;
15155
15156kill_option:
15157          opt_connection kill_expr { $$= (int) KILL_CONNECTION; }
15158        | QUERY_SYM      kill_expr { $$= (int) KILL_QUERY; }
15159        | QUERY_SYM ID_SYM expr
15160          {
15161            $$= (int) KILL_QUERY;
15162            Lex->kill_type= KILL_TYPE_QUERY;
15163            Lex->value_list.push_front($3, thd->mem_root);
15164          }
15165        ;
15166
15167opt_connection:
15168          /* empty */    { }
15169        | CONNECTION_SYM { }
15170        ;
15171
15172kill_expr:
15173        expr
15174        {
15175          Lex->value_list.push_front($$, thd->mem_root);
15176         }
15177        | USER_SYM user
15178          {
15179            Lex->users_list.push_back($2, thd->mem_root);
15180            Lex->kill_type= KILL_TYPE_USER;
15181          }
15182        ;
15183
15184shutdown:
15185        SHUTDOWN { Lex->sql_command= SQLCOM_SHUTDOWN; }
15186        shutdown_option {}
15187        ;
15188
15189shutdown_option:
15190        /*  Empty */    { Lex->is_shutdown_wait_for_slaves= false; }
15191        | WAIT_SYM FOR_SYM ALL SLAVES
15192        {
15193          Lex->is_shutdown_wait_for_slaves= true;
15194        }
15195        ;
15196/* change database */
15197
15198use:
15199          USE_SYM ident
15200          {
15201            LEX *lex=Lex;
15202            lex->sql_command=SQLCOM_CHANGE_DB;
15203            lex->first_select_lex()->db= $2;
15204          }
15205        ;
15206
15207/* import, export of files */
15208
15209load:
15210          LOAD data_or_xml
15211          {
15212            LEX *lex= thd->lex;
15213
15214            if (unlikely(lex->sphead))
15215            {
15216              my_error(ER_SP_BADSTATEMENT, MYF(0),
15217                       $2 == FILETYPE_CSV ? "LOAD DATA" : "LOAD XML");
15218              MYSQL_YYABORT;
15219            }
15220            if (Lex->main_select_push())
15221              MYSQL_YYABORT;
15222            mysql_init_select(lex);
15223          }
15224          load_data_lock opt_local INFILE TEXT_STRING_filesystem
15225          {
15226            LEX *lex=Lex;
15227            lex->sql_command= SQLCOM_LOAD;
15228            lex->local_file=  $5;
15229            lex->duplicates= DUP_ERROR;
15230            lex->ignore= 0;
15231            if (unlikely(!(lex->exchange= new (thd->mem_root)
15232                         sql_exchange($7.str, 0, $2))))
15233              MYSQL_YYABORT;
15234          }
15235          opt_duplicate INTO TABLE_SYM table_ident opt_use_partition
15236          {
15237            LEX *lex=Lex;
15238            if (unlikely(!Select->add_table_to_list(thd, $12, NULL,
15239                                                   TL_OPTION_UPDATING,
15240                                                   $4, MDL_SHARED_WRITE,
15241                                                   NULL, $13)))
15242              MYSQL_YYABORT;
15243            lex->field_list.empty();
15244            lex->update_list.empty();
15245            lex->value_list.empty();
15246            lex->many_values.empty();
15247          }
15248          opt_load_data_charset
15249          { Lex->exchange->cs= $15; }
15250          opt_xml_rows_identified_by
15251          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
15252          opt_load_data_set_spec
15253          {
15254            Lex->pop_select(); //main select
15255            if (Lex->check_main_unit_semantics())
15256              MYSQL_YYABORT;
15257            Lex->mark_first_table_as_inserting();
15258          }
15259          ;
15260
15261data_or_xml:
15262        DATA_SYM  { $$= FILETYPE_CSV; }
15263        | XML_SYM { $$= FILETYPE_XML; }
15264        ;
15265
15266opt_local:
15267          /* empty */ { $$=0;}
15268        | LOCAL_SYM { $$=1;}
15269        ;
15270
15271load_data_lock:
15272          /* empty */ { $$= TL_WRITE_DEFAULT; }
15273        | CONCURRENT
15274          {
15275            /*
15276              Ignore this option in SP to avoid problem with query cache and
15277              triggers with non default priority locks
15278            */
15279            $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT);
15280          }
15281        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
15282        ;
15283
15284opt_duplicate:
15285          /* empty */ { Lex->duplicates=DUP_ERROR; }
15286        | REPLACE { Lex->duplicates=DUP_REPLACE; }
15287        | IGNORE_SYM { Lex->ignore= 1; }
15288        ;
15289
15290opt_field_term:
15291          /* empty */
15292        | COLUMNS field_term_list
15293        ;
15294
15295field_term_list:
15296          field_term_list field_term
15297        | field_term
15298        ;
15299
15300field_term:
15301          TERMINATED BY text_string
15302          {
15303            DBUG_ASSERT(Lex->exchange != 0);
15304            Lex->exchange->field_term= $3;
15305          }
15306        | OPTIONALLY ENCLOSED BY text_string
15307          {
15308            LEX *lex= Lex;
15309            DBUG_ASSERT(lex->exchange != 0);
15310            lex->exchange->enclosed= $4;
15311            lex->exchange->opt_enclosed= 1;
15312          }
15313        | ENCLOSED BY text_string
15314          {
15315            DBUG_ASSERT(Lex->exchange != 0);
15316            Lex->exchange->enclosed= $3;
15317          }
15318        | ESCAPED BY text_string
15319          {
15320            DBUG_ASSERT(Lex->exchange != 0);
15321            Lex->exchange->escaped= $3;
15322          }
15323        ;
15324
15325opt_line_term:
15326          /* empty */
15327        | LINES line_term_list
15328        ;
15329
15330line_term_list:
15331          line_term_list line_term
15332        | line_term
15333        ;
15334
15335line_term:
15336          TERMINATED BY text_string
15337          {
15338            DBUG_ASSERT(Lex->exchange != 0);
15339            Lex->exchange->line_term= $3;
15340          }
15341        | STARTING BY text_string
15342          {
15343            DBUG_ASSERT(Lex->exchange != 0);
15344            Lex->exchange->line_start= $3;
15345          }
15346        ;
15347
15348opt_xml_rows_identified_by:
15349        /* empty */ { }
15350        | ROWS_SYM IDENTIFIED_SYM BY text_string
15351          { Lex->exchange->line_term = $4; }
15352        ;
15353
15354opt_ignore_lines:
15355          /* empty */
15356        | IGNORE_SYM NUM lines_or_rows
15357          {
15358            DBUG_ASSERT(Lex->exchange != 0);
15359            Lex->exchange->skip_lines= atol($2.str);
15360          }
15361        ;
15362
15363lines_or_rows:
15364          LINES { }
15365        | ROWS_SYM { }
15366        ;
15367
15368opt_field_or_var_spec:
15369          /* empty */ {}
15370        | '(' fields_or_vars ')' {}
15371        | '(' ')' {}
15372        ;
15373
15374fields_or_vars:
15375          fields_or_vars ',' field_or_var
15376          { Lex->field_list.push_back($3, thd->mem_root); }
15377        | field_or_var
15378          { Lex->field_list.push_back($1, thd->mem_root); }
15379        ;
15380
15381field_or_var:
15382          simple_ident_nospvar {$$= $1;}
15383        | '@' ident_or_text
15384          {
15385            $$= new (thd->mem_root) Item_user_var_as_out_param(thd, &$2);
15386            if (unlikely($$ == NULL))
15387              MYSQL_YYABORT;
15388          }
15389        ;
15390
15391opt_load_data_set_spec:
15392          /* empty */ {}
15393        | SET load_data_set_list {}
15394        ;
15395
15396load_data_set_list:
15397          load_data_set_list ',' load_data_set_elem
15398        | load_data_set_elem
15399        ;
15400
15401load_data_set_elem:
15402          simple_ident_nospvar equal remember_name expr_or_ignore_or_default remember_end
15403          {
15404            LEX *lex= Lex;
15405            if (unlikely(lex->update_list.push_back($1, thd->mem_root)) ||
15406                unlikely(lex->value_list.push_back($4, thd->mem_root)))
15407                MYSQL_YYABORT;
15408            $4->set_name_no_truncate(thd, $3, (uint) ($5 - $3), thd->charset());
15409          }
15410        ;
15411
15412/* Common definitions */
15413
15414text_literal:
15415          TEXT_STRING
15416          {
15417            if (unlikely(!($$= thd->make_string_literal($1))))
15418              MYSQL_YYABORT;
15419          }
15420        | NCHAR_STRING
15421          {
15422            if (unlikely(!($$= thd->make_string_literal_nchar($1))))
15423              MYSQL_YYABORT;
15424          }
15425        | UNDERSCORE_CHARSET TEXT_STRING
15426          {
15427            if (unlikely(!($$= thd->make_string_literal_charset($2, $1))))
15428              MYSQL_YYABORT;
15429          }
15430        | text_literal TEXT_STRING_literal
15431          {
15432            if (unlikely(!($$= $1->make_string_literal_concat(thd, &$2))))
15433              MYSQL_YYABORT;
15434          }
15435        ;
15436
15437text_string:
15438          TEXT_STRING_literal
15439          {
15440            $$= new (thd->mem_root) String($1.str,
15441                                             $1.length,
15442                                             thd->variables.collation_connection);
15443            if (unlikely($$ == NULL))
15444              MYSQL_YYABORT;
15445          }
15446          | hex_or_bin_String { $$= $1; }
15447          ;
15448
15449
15450hex_or_bin_String:
15451          HEX_NUM
15452          {
15453            Item *tmp= new (thd->mem_root) Item_hex_hybrid(thd, $1.str,
15454                                                           $1.length);
15455            if (unlikely(tmp == NULL))
15456              MYSQL_YYABORT;
15457            $$= tmp->val_str((String*) 0);
15458          }
15459        | HEX_STRING
15460          {
15461            Item *tmp= new (thd->mem_root) Item_hex_string(thd, $1.str,
15462                                                           $1.length);
15463            if (unlikely(tmp == NULL))
15464              MYSQL_YYABORT;
15465            $$= tmp->val_str((String*) 0);
15466          }
15467        | BIN_NUM
15468          {
15469            Item *tmp= new (thd->mem_root) Item_bin_string(thd, $1.str,
15470                                                           $1.length);
15471            if (unlikely(tmp == NULL))
15472              MYSQL_YYABORT;
15473            /*
15474              it is OK only emulate fix_fields, because we need only
15475              value of constant
15476            */
15477            $$= tmp->val_str((String*) 0);
15478          }
15479        ;
15480
15481param_marker:
15482          PARAM_MARKER
15483          {
15484            if (unlikely(!($$= Lex->add_placeholder(thd, &param_clex_str,
15485                                                    YYLIP->get_tok_start(),
15486                                                    YYLIP->get_tok_start() + 1))))
15487              MYSQL_YYABORT;
15488          }
15489        | COLON_ORACLE_SYM ident_cli
15490          {
15491            if (unlikely(!($$= Lex->add_placeholder(thd, &null_clex_str,
15492                                                    $1.pos(), $2.end()))))
15493              MYSQL_YYABORT;
15494          }
15495        | COLON_ORACLE_SYM NUM
15496          {
15497            if (unlikely(!($$= Lex->add_placeholder(thd, &null_clex_str,
15498                                                    $1.pos(),
15499                                                    YYLIP->get_ptr()))))
15500              MYSQL_YYABORT;
15501          }
15502        ;
15503
15504signed_literal:
15505        '+' NUM_literal { $$ = $2; }
15506        | '-' NUM_literal
15507          {
15508            $2->max_length++;
15509            $$= $2->neg(thd);
15510          }
15511        ;
15512
15513literal:
15514          text_literal { $$ = $1; }
15515        | NUM_literal { $$ = $1; }
15516        | temporal_literal { $$= $1; }
15517        | NULL_SYM
15518          {
15519            /*
15520              For the digest computation, in this context only,
15521              NULL is considered a literal, hence reduced to '?'
15522              REDUCE:
15523                TOK_GENERIC_VALUE := NULL_SYM
15524            */
15525            YYLIP->reduce_digest_token(TOK_GENERIC_VALUE, NULL_SYM);
15526            $$= new (thd->mem_root) Item_null(thd);
15527            if (unlikely($$ == NULL))
15528              MYSQL_YYABORT;
15529            YYLIP->next_state= MY_LEX_OPERATOR_OR_IDENT;
15530          }
15531        | FALSE_SYM
15532          {
15533            $$= new (thd->mem_root) Item_bool(thd, (char*) "FALSE",0);
15534            if (unlikely($$ == NULL))
15535              MYSQL_YYABORT;
15536          }
15537        | TRUE_SYM
15538          {
15539            $$= new (thd->mem_root) Item_bool(thd, (char*) "TRUE",1);
15540            if (unlikely($$ == NULL))
15541              MYSQL_YYABORT;
15542          }
15543        | HEX_NUM
15544          {
15545            $$= new (thd->mem_root) Item_hex_hybrid(thd, $1.str, $1.length);
15546            if (unlikely($$ == NULL))
15547              MYSQL_YYABORT;
15548          }
15549        | HEX_STRING
15550          {
15551            $$= new (thd->mem_root) Item_hex_string(thd, $1.str, $1.length);
15552            if (unlikely($$ == NULL))
15553              MYSQL_YYABORT;
15554          }
15555        | BIN_NUM
15556          {
15557            $$= new (thd->mem_root) Item_bin_string(thd, $1.str, $1.length);
15558            if (unlikely($$ == NULL))
15559              MYSQL_YYABORT;
15560          }
15561        | UNDERSCORE_CHARSET hex_or_bin_String
15562          {
15563            Item_string_with_introducer *item_str;
15564            /*
15565              Pass NULL as name. Name will be set in the "select_item" rule and
15566              will include the introducer and the original hex/bin notation.
15567            */
15568            item_str= new (thd->mem_root)
15569               Item_string_with_introducer(thd, NULL, $2->ptr(), $2->length(),
15570                                           $1);
15571            if (unlikely(!item_str ||
15572                         !item_str->check_well_formed_result(true)))
15573              MYSQL_YYABORT;
15574
15575            $$= item_str;
15576          }
15577        ;
15578
15579NUM_literal:
15580          NUM
15581          {
15582            int error;
15583            $$= new (thd->mem_root)
15584                  Item_int(thd, $1.str,
15585                           (longlong) my_strtoll10($1.str, NULL, &error),
15586                           $1.length);
15587            if (unlikely($$ == NULL))
15588              MYSQL_YYABORT;
15589          }
15590        | LONG_NUM
15591          {
15592            int error;
15593            $$= new (thd->mem_root)
15594                  Item_int(thd, $1.str,
15595                           (longlong) my_strtoll10($1.str, NULL, &error),
15596                           $1.length);
15597            if (unlikely($$ == NULL))
15598              MYSQL_YYABORT;
15599          }
15600        | ULONGLONG_NUM
15601          {
15602            $$= new (thd->mem_root) Item_uint(thd, $1.str, $1.length);
15603            if (unlikely($$ == NULL))
15604              MYSQL_YYABORT;
15605          }
15606        | DECIMAL_NUM
15607          {
15608            $$= new (thd->mem_root) Item_decimal(thd, $1.str, $1.length,
15609                                                   thd->charset());
15610            if (unlikely($$ == NULL) || unlikely(thd->is_error()))
15611              MYSQL_YYABORT;
15612          }
15613        | FLOAT_NUM
15614          {
15615            $$= new (thd->mem_root) Item_float(thd, $1.str, $1.length);
15616            if (unlikely($$ == NULL) || unlikely(thd->is_error()))
15617              MYSQL_YYABORT;
15618          }
15619        ;
15620
15621
15622temporal_literal:
15623        DATE_SYM TEXT_STRING
15624          {
15625            if (unlikely(!($$= type_handler_newdate.create_literal_item(thd,
15626                                                           $2.str, $2.length,
15627                                                           YYCSCL, true))))
15628              MYSQL_YYABORT;
15629          }
15630        | TIME_SYM TEXT_STRING
15631          {
15632            if (unlikely(!($$= type_handler_time2.create_literal_item(thd,
15633                                                         $2.str, $2.length,
15634                                                         YYCSCL, true))))
15635              MYSQL_YYABORT;
15636          }
15637        | TIMESTAMP TEXT_STRING
15638          {
15639            if (unlikely(!($$= type_handler_datetime2.create_literal_item(thd,
15640                                                             $2.str, $2.length,
15641                                                             YYCSCL, true))))
15642              MYSQL_YYABORT;
15643          }
15644        ;
15645
15646with_clause:
15647          WITH opt_recursive
15648          {
15649             LEX *lex= Lex;
15650             With_clause *with_clause=
15651             new With_clause($2, Lex->curr_with_clause);
15652             if (unlikely(with_clause == NULL))
15653               MYSQL_YYABORT;
15654             lex->derived_tables|= DERIVED_WITH;
15655             lex->with_cte_resolution= true;
15656             lex->curr_with_clause= with_clause;
15657             with_clause->add_to_list(Lex->with_clauses_list_last_next);
15658             if (lex->current_select &&
15659                 lex->current_select->parsing_place == BEFORE_OPT_LIST)
15660               lex->current_select->parsing_place= NO_MATTER;
15661          }
15662          with_list
15663          {
15664            $$= Lex->curr_with_clause;
15665            Lex->curr_with_clause= Lex->curr_with_clause->pop();
15666          }
15667        ;
15668
15669
15670opt_recursive:
15671 	  /*empty*/ { $$= 0; }
15672	| RECURSIVE_SYM { $$= 1; }
15673	;
15674
15675
15676with_list:
15677	  with_list_element
15678	| with_list ',' with_list_element
15679	;
15680
15681
15682with_list_element:
15683          with_element_head
15684	  opt_with_column_list
15685          {
15686            $2= new List<LEX_CSTRING> (Lex->with_column_list);
15687            if (unlikely($2 == NULL))
15688              MYSQL_YYABORT;
15689            Lex->with_column_list.empty();
15690          }
15691          AS '(' query_expression ')'
15692 	  {
15693            LEX *lex= thd->lex;
15694            const char *query_start= lex->sphead ? lex->sphead->m_tmp_query
15695                                                 : thd->query();
15696            const char *spec_start= $5.pos() + 1;
15697            With_element *elem= new With_element($1, *$2, $6);
15698	    if (elem == NULL || Lex->curr_with_clause->add_with_element(elem))
15699	      MYSQL_YYABORT;
15700            if (elem->set_unparsed_spec(thd, spec_start, $7.pos(),
15701                                        spec_start - query_start))
15702              MYSQL_YYABORT;
15703            elem->set_tables_end_pos(lex->query_tables_last);
15704	  }
15705	;
15706
15707
15708opt_with_column_list:
15709          /* empty */
15710          { $$= NULL; }
15711        | '(' with_column_list ')'
15712          { $$= NULL; }
15713        ;
15714
15715
15716with_column_list:
15717          ident
15718          {
15719            Lex->with_column_list.push_back((LEX_CSTRING*)
15720                    thd->memdup(&$1, sizeof(LEX_CSTRING)));
15721	  }
15722        | with_column_list ',' ident
15723          {
15724            Lex->with_column_list.push_back((LEX_CSTRING*)
15725                    thd->memdup(&$3, sizeof(LEX_CSTRING)));
15726          }
15727        ;
15728
15729
15730with_element_head:
15731          ident
15732          {
15733            LEX_CSTRING *name=
15734              (LEX_CSTRING *) thd->memdup(&$1, sizeof(LEX_CSTRING));
15735            $$= new (thd->mem_root) With_element_head(name);
15736            if (unlikely(name == NULL || $$ == NULL))
15737              MYSQL_YYABORT;
15738            $$->tables_pos.set_start_pos(Lex->query_tables_last);
15739          }
15740        ;
15741
15742
15743
15744/**********************************************************************
15745** Creating different items.
15746**********************************************************************/
15747
15748insert_ident:
15749          simple_ident_nospvar { $$=$1; }
15750        | table_wild { $$=$1; }
15751        ;
15752
15753table_wild:
15754          ident '.' '*'
15755          {
15756            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1))))
15757              MYSQL_YYABORT;
15758          }
15759        | ident '.' ident '.' '*'
15760          {
15761            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1, &$3))))
15762              MYSQL_YYABORT;
15763          }
15764        ;
15765
15766select_sublist_qualified_asterisk:
15767          ident_cli '.' '*'
15768          {
15769            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1))))
15770              MYSQL_YYABORT;
15771          }
15772        | ident_cli '.' ident_cli '.' '*'
15773          {
15774            if (unlikely(!($$= Lex->create_item_qualified_asterisk(thd, &$1, &$3))))
15775              MYSQL_YYABORT;
15776          }
15777        ;
15778
15779order_ident:
15780          expr { $$=$1; }
15781        ;
15782
15783
15784simple_ident:
15785          ident_cli
15786          {
15787            if (unlikely(!($$= Lex->create_item_ident(thd, &$1))))
15788              MYSQL_YYABORT;
15789          }
15790        | ident_cli '.' ident_cli
15791          {
15792            if (unlikely(!($$= Lex->create_item_ident(thd, &$1, &$3))))
15793              MYSQL_YYABORT;
15794          }
15795        | '.' ident_cli '.' ident_cli
15796          {
15797            Lex_ident_cli empty($2.pos(), 0);
15798            if (unlikely(!($$= Lex->create_item_ident(thd, &empty, &$2, &$4))))
15799              MYSQL_YYABORT;
15800          }
15801        | ident_cli '.' ident_cli '.' ident_cli
15802          {
15803            if (unlikely(!($$= Lex->create_item_ident(thd, &$1, &$3, &$5))))
15804              MYSQL_YYABORT;
15805          }
15806        | COLON_ORACLE_SYM ident_cli '.' ident_cli
15807          {
15808            if (unlikely(!($$= Lex->make_item_colon_ident_ident(thd, &$2, &$4))))
15809              MYSQL_YYABORT;
15810          }
15811        ;
15812
15813simple_ident_nospvar:
15814          ident
15815          {
15816            if (unlikely(!($$= Lex->create_item_ident_nosp(thd, &$1))))
15817              MYSQL_YYABORT;
15818          }
15819        | ident '.' ident
15820          {
15821            if (unlikely(!($$= Lex->create_item_ident_nospvar(thd, &$1, &$3))))
15822              MYSQL_YYABORT;
15823          }
15824        | COLON_ORACLE_SYM ident_cli '.' ident_cli
15825          {
15826            if (unlikely(!($$= Lex->make_item_colon_ident_ident(thd, &$2, &$4))))
15827              MYSQL_YYABORT;
15828          }
15829        | '.' ident '.' ident
15830          {
15831            Lex_ident_sys none;
15832            if (unlikely(!($$= Lex->create_item_ident(thd, &none, &$2, &$4))))
15833              MYSQL_YYABORT;
15834          }
15835        | ident '.' ident '.' ident
15836          {
15837            if (unlikely(!($$= Lex->create_item_ident(thd, &$1, &$3, &$5))))
15838              MYSQL_YYABORT;
15839          }
15840        ;
15841
15842field_ident:
15843          ident { $$=$1;}
15844        | ident '.' ident '.' ident
15845          {
15846            TABLE_LIST *table= Select->table_list.first;
15847            if (unlikely(my_strcasecmp(table_alias_charset, $1.str,
15848                                       table->db.str)))
15849              my_yyabort_error((ER_WRONG_DB_NAME, MYF(0), $1.str));
15850            if (unlikely(my_strcasecmp(table_alias_charset, $3.str,
15851                                       table->table_name.str)))
15852              my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $3.str));
15853            $$=$5;
15854          }
15855        | ident '.' ident
15856          {
15857            TABLE_LIST *table= Select->table_list.first;
15858            if (unlikely(my_strcasecmp(table_alias_charset, $1.str,
15859                         table->alias.str)))
15860              my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $1.str));
15861            $$=$3;
15862          }
15863        | '.' ident { $$=$2;} /* For Delphi */
15864        ;
15865
15866table_ident:
15867          ident
15868          {
15869            $$= new (thd->mem_root) Table_ident(&$1);
15870            if (unlikely($$ == NULL))
15871              MYSQL_YYABORT;
15872          }
15873        | ident '.' ident
15874          {
15875            $$= new (thd->mem_root) Table_ident(thd, &$1, &$3, 0);
15876            if (unlikely($$ == NULL))
15877              MYSQL_YYABORT;
15878          }
15879        | '.' ident
15880          {
15881            /* For Delphi */
15882            $$= new (thd->mem_root) Table_ident(&$2);
15883            if (unlikely($$ == NULL))
15884              MYSQL_YYABORT;
15885          }
15886        ;
15887
15888table_ident_opt_wild:
15889          ident opt_wild
15890          {
15891            $$= new (thd->mem_root) Table_ident(&$1);
15892            if (unlikely($$ == NULL))
15893              MYSQL_YYABORT;
15894          }
15895        | ident '.' ident opt_wild
15896          {
15897            $$= new (thd->mem_root) Table_ident(thd, &$1, &$3, 0);
15898            if (unlikely($$ == NULL))
15899              MYSQL_YYABORT;
15900          }
15901        ;
15902
15903table_ident_nodb:
15904          ident
15905          {
15906            LEX_CSTRING db={(char*) any_db,3};
15907            $$= new (thd->mem_root) Table_ident(thd, &db, &$1, 0);
15908            if (unlikely($$ == NULL))
15909              MYSQL_YYABORT;
15910          }
15911        ;
15912
15913IDENT_cli:
15914          IDENT
15915        | IDENT_QUOTED
15916        ;
15917
15918ident_cli:
15919          IDENT
15920        | IDENT_QUOTED
15921        | keyword_ident { $$= $1; }
15922        ;
15923
15924IDENT_sys:
15925          IDENT_cli
15926          {
15927            if (unlikely(thd->to_ident_sys_alloc(&$$, &$1)))
15928              MYSQL_YYABORT;
15929          }
15930        ;
15931
15932TEXT_STRING_sys:
15933          TEXT_STRING
15934          {
15935            if (thd->make_text_string_sys(&$$, &$1))
15936              MYSQL_YYABORT;
15937          }
15938        ;
15939
15940TEXT_STRING_literal:
15941          TEXT_STRING
15942          {
15943            if (thd->make_text_string_connection(&$$, &$1))
15944              MYSQL_YYABORT;
15945          }
15946        ;
15947
15948TEXT_STRING_filesystem:
15949          TEXT_STRING
15950          {
15951            if (thd->make_text_string_filesystem(&$$, &$1))
15952              MYSQL_YYABORT;
15953          }
15954        ;
15955
15956ident_table_alias:
15957          IDENT_sys
15958        | keyword_table_alias
15959          {
15960            if (unlikely($$.copy_keyword(thd, &$1)))
15961              MYSQL_YYABORT;
15962          }
15963        ;
15964
15965ident_set_usual_case:
15966          IDENT_sys
15967        | keyword_set_usual_case
15968          {
15969            if (unlikely($$.copy_keyword(thd, &$1)))
15970              MYSQL_YYABORT;
15971          }
15972        ;
15973
15974ident_sysvar_name:
15975          IDENT_sys
15976        | keyword_sysvar_name
15977          {
15978            if (unlikely($$.copy_keyword(thd, &$1)))
15979              MYSQL_YYABORT;
15980          }
15981        | TEXT_STRING_sys
15982          {
15983            if (unlikely($$.copy_sys(thd, &$1)))
15984              MYSQL_YYABORT;
15985          }
15986        ;
15987
15988
15989ident:
15990          IDENT_sys
15991        | keyword_ident
15992          {
15993            if (unlikely($$.copy_keyword(thd, &$1)))
15994              MYSQL_YYABORT;
15995          }
15996        ;
15997
15998ident_directly_assignable:
15999          IDENT_sys
16000        | keyword_directly_assignable
16001          {
16002            if (unlikely($$.copy_keyword(thd, &$1)))
16003              MYSQL_YYABORT;
16004          }
16005        ;
16006
16007
16008label_ident:
16009          IDENT_sys
16010        | keyword_label
16011          {
16012            if (unlikely($$.copy_keyword(thd, &$1)))
16013              MYSQL_YYABORT;
16014          }
16015        ;
16016
16017labels_declaration_oracle:
16018          label_declaration_oracle { $$= $1; }
16019        | labels_declaration_oracle label_declaration_oracle { $$= $2; }
16020        ;
16021
16022label_declaration_oracle:
16023          SHIFT_LEFT label_ident SHIFT_RIGHT
16024          {
16025            if (unlikely(Lex->sp_push_goto_label(thd, &$2)))
16026              MYSQL_YYABORT;
16027            $$= $2;
16028          }
16029        ;
16030
16031ident_or_text:
16032          ident           { $$=$1;}
16033        | TEXT_STRING_sys { $$=$1;}
16034        | LEX_HOSTNAME { $$=$1;}
16035        ;
16036
16037user_maybe_role:
16038          ident_or_text
16039          {
16040            if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER)))))
16041              MYSQL_YYABORT;
16042            $$->user = $1;
16043
16044            if (unlikely(check_string_char_length(&$$->user, ER_USERNAME,
16045                                                  username_char_length,
16046                                                  system_charset_info, 0)))
16047              MYSQL_YYABORT;
16048          }
16049        | ident_or_text '@' ident_or_text
16050          {
16051            if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER)))))
16052              MYSQL_YYABORT;
16053            $$->user = $1; $$->host=$3;
16054
16055            if (unlikely(check_string_char_length(&$$->user, ER_USERNAME,
16056                                                  username_char_length,
16057                                                 system_charset_info, 0)) ||
16058                unlikely(check_host_name(&$$->host)))
16059              MYSQL_YYABORT;
16060            if ($$->host.str[0])
16061            {
16062              /*
16063                Convert hostname part of username to lowercase.
16064                It's OK to use in-place lowercase as long as
16065                the character set is utf8.
16066              */
16067              my_casedn_str(system_charset_info, (char*) $$->host.str);
16068            }
16069            else
16070            {
16071              /*
16072                fix historical undocumented convention that empty host is the
16073                same as '%'
16074              */
16075              $$->host= host_not_specified;
16076            }
16077          }
16078        | CURRENT_USER optional_braces
16079          {
16080            if (unlikely(!($$=(LEX_USER*)thd->calloc(sizeof(LEX_USER)))))
16081              MYSQL_YYABORT;
16082            $$->user= current_user;
16083            $$->auth= new (thd->mem_root) USER_AUTH();
16084          }
16085        ;
16086
16087user_or_role: user_maybe_role | current_role;
16088
16089user: user_maybe_role
16090         {
16091           if ($1->user.str != current_user.str && $1->host.str == 0)
16092             $1->host= host_not_specified;
16093           $$= $1;
16094         }
16095         ;
16096
16097/* Keywords which we allow as table aliases. */
16098keyword_table_alias:
16099          keyword_data_type
16100        | keyword_set_special_case
16101        | keyword_sp_block_section
16102        | keyword_sp_head
16103        | keyword_sp_var_and_label
16104        | keyword_sp_var_not_label
16105        | keyword_sysvar_type
16106        | keyword_verb_clause
16107        | FUNCTION_SYM
16108        ;
16109
16110/* Keyword that we allow for identifiers (except SP labels) */
16111keyword_ident:
16112          keyword_data_type
16113        | keyword_set_special_case
16114        | keyword_sp_block_section
16115        | keyword_sp_head
16116        | keyword_sp_var_and_label
16117        | keyword_sp_var_not_label
16118        | keyword_sysvar_type
16119        | keyword_verb_clause
16120        | FUNCTION_SYM
16121        | WINDOW_SYM
16122        ;
16123
16124/*
16125  Keywords that we allow for labels in SPs.
16126  Should not include keywords that start a statement or SP characteristics.
16127*/
16128keyword_label:
16129          keyword_data_type
16130        | keyword_set_special_case
16131        | keyword_sp_var_and_label
16132        | keyword_sysvar_type
16133        | FUNCTION_SYM
16134        | COMPRESSED_SYM
16135        ;
16136
16137keyword_sysvar_name:
16138          keyword_data_type
16139        | keyword_set_special_case
16140        | keyword_sp_block_section
16141        | keyword_sp_head
16142        | keyword_sp_var_and_label
16143        | keyword_sp_var_not_label
16144        | keyword_verb_clause
16145        | FUNCTION_SYM
16146        | WINDOW_SYM
16147        ;
16148
16149keyword_sp_decl:
16150          keyword_sp_head
16151        | keyword_set_special_case
16152        | keyword_sp_var_and_label
16153        | keyword_sp_var_not_label
16154        | keyword_sysvar_type
16155        | keyword_verb_clause
16156        | WINDOW_SYM
16157        ;
16158
16159keyword_set_usual_case:
16160          keyword_data_type
16161        | keyword_sp_block_section
16162        | keyword_sp_head
16163        | keyword_sp_var_and_label
16164        | keyword_sp_var_not_label
16165        | keyword_sysvar_type
16166        | keyword_verb_clause
16167        | FUNCTION_SYM
16168        | WINDOW_SYM
16169        ;
16170
16171keyword_directly_assignable:
16172          keyword_data_type
16173        | keyword_set_special_case
16174        | keyword_sp_var_and_label
16175        | keyword_sp_var_not_label
16176        | keyword_sysvar_type
16177        | FUNCTION_SYM
16178        | WINDOW_SYM
16179        ;
16180
16181/*
16182  Keywords that we allow in Oracle-style direct assignments:
16183    xxx := 10;
16184  but do not allow in labels in the default sql_mode:
16185    label:
16186      stmt1;
16187      stmt2;
16188  TODO: check if some of them can migrate to keyword_sp_var_and_label.
16189*/
16190keyword_sp_var_not_label:
16191          ASCII_SYM
16192        | BACKUP_SYM
16193        | BINLOG_SYM
16194        | BYTE_SYM
16195        | CACHE_SYM
16196        | CHECKSUM_SYM
16197        | CHECKPOINT_SYM
16198        | COLUMN_ADD_SYM
16199        | COLUMN_CHECK_SYM
16200        | COLUMN_CREATE_SYM
16201        | COLUMN_DELETE_SYM
16202        | COLUMN_GET_SYM
16203        | COMMENT_SYM
16204        | COMPRESSED_SYM
16205        | DEALLOCATE_SYM
16206        | EXAMINED_SYM
16207        | EXCLUDE_SYM
16208        | EXECUTE_SYM
16209        | FLUSH_SYM
16210        | FOLLOWING_SYM
16211        | FORMAT_SYM
16212        | GET_SYM
16213        | HELP_SYM
16214        | HOST_SYM
16215        | INSTALL_SYM
16216        | OPTION
16217        | OPTIONS_SYM
16218        | OTHERS_MARIADB_SYM
16219        | OWNER_SYM
16220        | PARSER_SYM
16221        | PERIOD_SYM
16222        | PORT_SYM
16223        | PRECEDING_SYM
16224        | PREPARE_SYM
16225        | REMOVE_SYM
16226        | RESET_SYM
16227        | RESTORE_SYM
16228        | SECURITY_SYM
16229        | SERVER_SYM
16230        | SIGNED_SYM
16231        | SOCKET_SYM
16232        | SLAVE
16233        | SLAVES
16234        | SONAME_SYM
16235        | START_SYM
16236        | STOP_SYM
16237        | STORED_SYM
16238        | TIES_SYM
16239        | UNICODE_SYM
16240        | UNINSTALL_SYM
16241        | UNBOUNDED_SYM
16242        | WITHIN
16243        | WRAPPER_SYM
16244        | XA_SYM
16245        | UPGRADE_SYM
16246        ;
16247
16248/*
16249  Keywords that can start optional clauses in SP or trigger declarations
16250  Allowed as identifiers (e.g. table, column names),
16251  but:
16252  - not allowed as SP label names
16253  - not allowed as variable names in Oracle-style assignments:
16254    xxx := 10;
16255
16256  If we allowed these variables in assignments, there would be conflicts
16257  with SP characteristics, or verb clauses, or compound statements, e.g.:
16258    CREATE PROCEDURE p1 LANGUAGE ...
16259  would be either:
16260    CREATE PROCEDURE p1 LANGUAGE SQL BEGIN END;
16261  or
16262    CREATE PROCEDURE p1 LANGUAGE:=10;
16263
16264  Note, these variables can still be assigned using quoted identifiers:
16265    `do`:= 10;
16266    "do":= 10; (when ANSI_QUOTES)
16267  or using a SET statement:
16268    SET do= 10;
16269
16270  Note, some of these keywords are reserved keywords in Oracle.
16271  In case if heavy grammar conflicts are found in the future,
16272  we'll possibly need to make them reserved for sql_mode=ORACLE.
16273
16274  TODO: Allow these variables as SP lables when sql_mode=ORACLE.
16275  TODO: Allow assigning of "SP characteristics" marked variables
16276        inside compound blocks.
16277  TODO: Allow "follows" and "precedes" as variables in compound blocks:
16278        BEGIN
16279          follows := 10;
16280        END;
16281        as they conflict only with non-block FOR EACH ROW statement:
16282          CREATE TRIGGER .. FOR EACH ROW follows:= 10;
16283          CREATE TRIGGER .. FOR EACH ROW FOLLOWS tr1 a:= 10;
16284*/
16285keyword_sp_head:
16286          CONTAINS_SYM           /* SP characteristic               */
16287        | LANGUAGE_SYM           /* SP characteristic               */
16288        | NO_SYM                 /* SP characteristic               */
16289        | CHARSET                /* SET CHARSET utf8;               */
16290        | FOLLOWS_SYM            /* Conflicts with assignment in FOR EACH */
16291        | PRECEDES_SYM           /* Conflicts with assignment in FOR EACH */
16292        ;
16293
16294/*
16295  Keywords that start a statement.
16296  Generally allowed as identifiers (e.g. table, column names)
16297  - not allowed as SP label names
16298  - not allowed as variable names in Oracle-style assignments:
16299    xxx:=10
16300*/
16301keyword_verb_clause:
16302          CLOSE_SYM             /* Verb clause. Reserved in Oracle */
16303        | COMMIT_SYM            /* Verb clause. Reserved in Oracle */
16304        | DO_SYM                /* Verb clause                     */
16305        | HANDLER_SYM           /* Verb clause                     */
16306        | OPEN_SYM              /* Verb clause. Reserved in Oracle */
16307        | REPAIR                /* Verb clause                     */
16308        | ROLLBACK_SYM          /* Verb clause. Reserved in Oracle */
16309        | SAVEPOINT_SYM         /* Verb clause. Reserved in Oracle */
16310        | SHUTDOWN              /* Verb clause                     */
16311        | TRUNCATE_SYM          /* Verb clause. Reserved in Oracle */
16312        ;
16313
16314keyword_set_special_case:
16315          NAMES_SYM
16316        | ROLE_SYM
16317        | PASSWORD_SYM
16318        ;
16319
16320/*
16321  Keywords that start an SP block section.
16322*/
16323keyword_sp_block_section:
16324          BEGIN_ORACLE_SYM
16325        | EXCEPTION_ORACLE_SYM
16326        | END
16327        ;
16328
16329keyword_sysvar_type:
16330          GLOBAL_SYM
16331        | LOCAL_SYM
16332        | SESSION_SYM
16333        ;
16334
16335
16336/*
16337  These keywords are generally allowed as identifiers,
16338  but not allowed as non-delimited SP variable names in sql_mode=ORACLE.
16339*/
16340keyword_data_type:
16341          BIT_SYM
16342        | BOOLEAN_SYM
16343        | BOOL_SYM
16344        | CLOB_MARIADB_SYM
16345        | CLOB_ORACLE_SYM
16346        | DATE_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
16347        | DATETIME
16348        | ENUM
16349        | FIXED_SYM
16350        | GEOMETRYCOLLECTION
16351        | GEOMETRY_SYM
16352        | JSON_SYM
16353        | LINESTRING
16354        | MEDIUM_SYM
16355        | MULTILINESTRING
16356        | MULTIPOINT
16357        | MULTIPOLYGON
16358        | NATIONAL_SYM
16359        | NCHAR_SYM
16360        | NUMBER_MARIADB_SYM
16361        | NUMBER_ORACLE_SYM
16362        | NVARCHAR_SYM
16363        | POINT_SYM
16364        | POLYGON
16365        | RAW_MARIADB_SYM
16366        | RAW_ORACLE_SYM
16367        | ROW_SYM
16368        | SERIAL_SYM
16369        | TEXT_SYM
16370        | TIMESTAMP          %prec PREC_BELOW_CONTRACTION_TOKEN2
16371        | TIME_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
16372        | VARCHAR2_MARIADB_SYM
16373        | VARCHAR2_ORACLE_SYM
16374        | YEAR_SYM
16375        ;
16376
16377
16378/*
16379  These keywords are fine for both SP variable names and SP labels.
16380*/
16381keyword_sp_var_and_label:
16382          ACTION
16383        | ACCOUNT_SYM
16384        | ADDDATE_SYM
16385        | ADMIN_SYM
16386        | AFTER_SYM
16387        | AGAINST
16388        | AGGREGATE_SYM
16389        | ALGORITHM_SYM
16390        | ALWAYS_SYM
16391        | ANY_SYM
16392        | AT_SYM
16393        | ATOMIC_SYM
16394        | AUTHORS_SYM
16395        | AUTO_INC
16396        | AUTOEXTEND_SIZE_SYM
16397        | AUTO_SYM
16398        | AVG_ROW_LENGTH
16399        | AVG_SYM
16400        | BLOCK_SYM
16401        | BODY_MARIADB_SYM
16402        | BTREE_SYM
16403        | CASCADED
16404        | CATALOG_NAME_SYM
16405        | CHAIN_SYM
16406        | CHANGED
16407        | CIPHER_SYM
16408        | CLIENT_SYM
16409        | CLASS_ORIGIN_SYM
16410        | COALESCE
16411        | CODE_SYM
16412        | COLLATION_SYM
16413        | COLUMN_NAME_SYM
16414        | COLUMNS
16415        | COMMITTED_SYM
16416        | COMPACT_SYM
16417        | COMPLETION_SYM
16418        | CONCURRENT
16419        | CONNECTION_SYM
16420        | CONSISTENT_SYM
16421        | CONSTRAINT_CATALOG_SYM
16422        | CONSTRAINT_SCHEMA_SYM
16423        | CONSTRAINT_NAME_SYM
16424        | CONTEXT_SYM
16425        | CONTRIBUTORS_SYM
16426        | CURRENT_POS_SYM
16427        | CPU_SYM
16428        | CUBE_SYM
16429        /*
16430          Although a reserved keyword in SQL:2003 (and :2008),
16431          not reserved in MySQL per WL#2111 specification.
16432        */
16433        | CURRENT_SYM
16434        | CURSOR_NAME_SYM
16435        | CYCLE_SYM
16436        | DATA_SYM
16437        | DATAFILE_SYM
16438        | DATE_FORMAT_SYM
16439        | DAY_SYM
16440        | DECODE_MARIADB_SYM
16441        | DECODE_ORACLE_SYM
16442        | DEFINER_SYM
16443        | DELAY_KEY_WRITE_SYM
16444        | DES_KEY_FILE
16445        | DIAGNOSTICS_SYM
16446        | DIRECTORY_SYM
16447        | DISABLE_SYM
16448        | DISCARD
16449        | DISK_SYM
16450        | DUMPFILE
16451        | DUPLICATE_SYM
16452        | DYNAMIC_SYM
16453        | ELSEIF_ORACLE_SYM
16454        | ELSIF_MARIADB_SYM
16455        | ENDS_SYM
16456        | ENGINE_SYM
16457        | ENGINES_SYM
16458        | ERROR_SYM
16459        | ERRORS
16460        | ESCAPE_SYM
16461        | EVENT_SYM
16462        | EVENTS_SYM
16463        | EVERY_SYM
16464        | EXCEPTION_MARIADB_SYM
16465        | EXCHANGE_SYM
16466        | EXPANSION_SYM
16467        | EXPIRE_SYM
16468        | EXPORT_SYM
16469        | EXTENDED_SYM
16470        | EXTENT_SIZE_SYM
16471        | FAULTS_SYM
16472        | FAST_SYM
16473        | FOUND_SYM
16474        | ENABLE_SYM
16475        | FULL
16476        | FILE_SYM
16477        | FIRST_SYM
16478        | GENERAL
16479        | GENERATED_SYM
16480        | GET_FORMAT
16481        | GRANTS
16482        | GOTO_MARIADB_SYM
16483        | HASH_SYM
16484        | HARD_SYM
16485        | HISTORY_SYM
16486        | HOSTS_SYM
16487        | HOUR_SYM
16488        | ID_SYM
16489        | IDENTIFIED_SYM
16490        | IGNORE_SERVER_IDS_SYM
16491        | INCREMENT_SYM
16492        | IMMEDIATE_SYM
16493        | INVOKER_SYM
16494        | IMPORT
16495        | INDEXES
16496        | INITIAL_SIZE_SYM
16497        | IO_SYM
16498        | IPC_SYM
16499        | ISOLATION
16500        | ISOPEN_SYM
16501        | ISSUER_SYM
16502        | INSERT_METHOD
16503        | INVISIBLE_SYM
16504        | KEY_BLOCK_SIZE
16505        | LAST_VALUE
16506        | LAST_SYM
16507        | LASTVAL_SYM
16508        | LEAVES
16509        | LESS_SYM
16510        | LEVEL_SYM
16511        | LIST_SYM
16512        | LOCKS_SYM
16513        | LOGFILE_SYM
16514        | LOGS_SYM
16515        | MAX_ROWS
16516        | MASTER_SYM
16517        | MASTER_HEARTBEAT_PERIOD_SYM
16518        | MASTER_GTID_POS_SYM
16519        | MASTER_HOST_SYM
16520        | MASTER_PORT_SYM
16521        | MASTER_LOG_FILE_SYM
16522        | MASTER_LOG_POS_SYM
16523        | MASTER_USER_SYM
16524        | MASTER_USE_GTID_SYM
16525        | MASTER_PASSWORD_SYM
16526        | MASTER_SERVER_ID_SYM
16527        | MASTER_CONNECT_RETRY_SYM
16528        | MASTER_DELAY_SYM
16529        | MASTER_SSL_SYM
16530        | MASTER_SSL_CA_SYM
16531        | MASTER_SSL_CAPATH_SYM
16532        | MASTER_SSL_CERT_SYM
16533        | MASTER_SSL_CIPHER_SYM
16534        | MASTER_SSL_CRL_SYM
16535        | MASTER_SSL_CRLPATH_SYM
16536        | MASTER_SSL_KEY_SYM
16537        | MAX_CONNECTIONS_PER_HOUR
16538        | MAX_QUERIES_PER_HOUR
16539        | MAX_SIZE_SYM
16540        | MAX_STATEMENT_TIME_SYM
16541        | MAX_UPDATES_PER_HOUR
16542        | MAX_USER_CONNECTIONS_SYM
16543        | MEMORY_SYM
16544        | MERGE_SYM
16545        | MESSAGE_TEXT_SYM
16546        | MICROSECOND_SYM
16547        | MIGRATE_SYM
16548        | MINUTE_SYM
16549        | MINVALUE_SYM
16550        | MIN_ROWS
16551        | MODIFY_SYM
16552        | MODE_SYM
16553        | MONTH_SYM
16554        | MUTEX_SYM
16555        | MYSQL_SYM
16556        | MYSQL_ERRNO_SYM
16557        | NAME_SYM
16558        | NEXT_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
16559        | NEXTVAL_SYM
16560        | NEVER_SYM
16561        | NEW_SYM
16562        | NOCACHE_SYM
16563        | NOCYCLE_SYM
16564        | NOMINVALUE_SYM
16565        | NOMAXVALUE_SYM
16566        | NO_WAIT_SYM
16567        | NOWAIT_SYM
16568        | NODEGROUP_SYM
16569        | NONE_SYM
16570        | NOTFOUND_SYM
16571        | OF_SYM
16572        | OFFSET_SYM
16573        | OLD_PASSWORD_SYM
16574        | ONE_SYM
16575        | ONLINE_SYM
16576        | ONLY_SYM
16577        | PACKAGE_MARIADB_SYM
16578        | PACK_KEYS_SYM
16579        | PAGE_SYM
16580        | PARTIAL
16581        | PARTITIONING_SYM
16582        | PARTITIONS_SYM
16583        | PERSISTENT_SYM
16584        | PHASE_SYM
16585        | PLUGIN_SYM
16586        | PLUGINS_SYM
16587        | PRESERVE_SYM
16588        | PREV_SYM
16589        | PREVIOUS_SYM       %prec PREC_BELOW_CONTRACTION_TOKEN2
16590        | PRIVILEGES
16591        | PROCESS
16592        | PROCESSLIST_SYM
16593        | PROFILE_SYM
16594        | PROFILES_SYM
16595        | PROXY_SYM
16596        | QUARTER_SYM
16597        | QUERY_SYM
16598        | QUICK
16599        | RAISE_MARIADB_SYM
16600        | READ_ONLY_SYM
16601        | REBUILD_SYM
16602        | RECOVER_SYM
16603        | REDO_BUFFER_SIZE_SYM
16604        | REDOFILE_SYM
16605        | REDUNDANT_SYM
16606        | RELAY
16607        | RELAYLOG_SYM
16608        | RELAY_LOG_FILE_SYM
16609        | RELAY_LOG_POS_SYM
16610        | RELAY_THREAD
16611        | RELOAD
16612        | REORGANIZE_SYM
16613        | REPEATABLE_SYM
16614        | REPLICATION
16615        | RESOURCES
16616        | RESTART_SYM
16617        | RESUME_SYM
16618        | RETURNED_SQLSTATE_SYM
16619        | RETURNS_SYM
16620        | REUSE_SYM
16621        | REVERSE_SYM
16622        | ROLLUP_SYM
16623        | ROUTINE_SYM
16624        | ROWCOUNT_SYM
16625        | ROWTYPE_MARIADB_SYM
16626        | ROW_COUNT_SYM
16627        | ROW_FORMAT_SYM
16628        | RTREE_SYM
16629        | SCHEDULE_SYM
16630        | SCHEMA_NAME_SYM
16631        | SECOND_SYM
16632        | SEQUENCE_SYM
16633        | SERIALIZABLE_SYM
16634        | SETVAL_SYM
16635        | SIMPLE_SYM
16636        | SHARE_SYM
16637        | SLAVE_POS_SYM
16638        | SLOW
16639        | SNAPSHOT_SYM
16640        | SOFT_SYM
16641        | SOUNDS_SYM
16642        | SOURCE_SYM
16643        | SQL_CACHE_SYM
16644        | SQL_BUFFER_RESULT
16645        | SQL_NO_CACHE_SYM
16646        | SQL_THREAD
16647        | STAGE_SYM
16648        | STARTS_SYM
16649        | STATEMENT_SYM
16650        | STATUS_SYM
16651        | STORAGE_SYM
16652        | STRING_SYM
16653        | SUBCLASS_ORIGIN_SYM
16654        | SUBDATE_SYM
16655        | SUBJECT_SYM
16656        | SUBPARTITION_SYM
16657        | SUBPARTITIONS_SYM
16658        | SUPER_SYM
16659        | SUSPEND_SYM
16660        | SWAPS_SYM
16661        | SWITCHES_SYM
16662        | SYSTEM
16663        | SYSTEM_TIME_SYM
16664        | TABLE_NAME_SYM
16665        | TABLES
16666        | TABLE_CHECKSUM_SYM
16667        | TABLESPACE
16668        | TEMPORARY
16669        | TEMPTABLE_SYM
16670        | THAN_SYM
16671        | TRANSACTION_SYM    %prec PREC_BELOW_CONTRACTION_TOKEN2
16672        | TRANSACTIONAL_SYM
16673        | TRIGGERS_SYM
16674        | TRIM_ORACLE
16675        | TIMESTAMP_ADD
16676        | TIMESTAMP_DIFF
16677        | TYPES_SYM
16678        | TYPE_SYM
16679        | UDF_RETURNS_SYM
16680        | UNCOMMITTED_SYM
16681        | UNDEFINED_SYM
16682        | UNDO_BUFFER_SIZE_SYM
16683        | UNDOFILE_SYM
16684        | UNKNOWN_SYM
16685        | UNTIL_SYM
16686        | USER_SYM           %prec PREC_BELOW_CONTRACTION_TOKEN2
16687        | USE_FRM
16688        | VARIABLES
16689        | VERSIONING_SYM
16690        | VIEW_SYM
16691        | VIRTUAL_SYM
16692        | VALUE_SYM
16693        | WARNINGS
16694        | WAIT_SYM
16695        | WEEK_SYM
16696        | WEIGHT_STRING_SYM
16697        | WITHOUT
16698        | WORK_SYM
16699        | X509_SYM
16700        | XML_SYM
16701        | VIA_SYM
16702        ;
16703
16704/*
16705  SQLCOM_SET_OPTION statement.
16706
16707  Note that to avoid shift/reduce conflicts, we have separate rules for the
16708  first option listed in the statement.
16709*/
16710
16711set:
16712          SET
16713          {
16714            LEX *lex=Lex;
16715            if (lex->main_select_push(true))
16716              MYSQL_YYABORT;
16717            lex->set_stmt_init();
16718            lex->var_list.empty();
16719            if (sp_create_assignment_lex(thd, yychar == YYEMPTY))
16720              MYSQL_YYABORT;
16721          }
16722          start_option_value_list
16723          {
16724            Lex->pop_select(); //main select
16725            if (Lex->check_main_unit_semantics())
16726              MYSQL_YYABORT;
16727          }
16728        | SET STATEMENT_SYM
16729          {
16730            if (Lex->main_select_push())
16731              MYSQL_YYABORT;
16732            Lex->set_stmt_init();
16733          }
16734          set_stmt_option_value_following_option_type_list
16735          {
16736            LEX *lex= Lex;
16737            if (unlikely(lex->table_or_sp_used()))
16738              my_yyabort_error((ER_SUBQUERIES_NOT_SUPPORTED, MYF(0), "SET STATEMENT"));
16739            lex->stmt_var_list= lex->var_list;
16740            lex->var_list.empty();
16741            Lex->pop_select(); //main select
16742            if (Lex->check_main_unit_semantics())
16743              MYSQL_YYABORT;
16744          }
16745          FOR_SYM verb_clause
16746	  {}
16747        ;
16748
16749set_assign:
16750          ident_directly_assignable SET_VAR
16751          {
16752            LEX *lex=Lex;
16753            lex->set_stmt_init();
16754            lex->var_list.empty();
16755            if(sp_create_assignment_lex(thd, yychar == YYEMPTY))
16756              MYSQL_YYABORT;
16757          }
16758          set_expr_or_default
16759          {
16760            if (unlikely(Lex->set_variable(&$1, $4)) ||
16761                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16762              MYSQL_YYABORT;
16763          }
16764        | ident_directly_assignable '.' ident SET_VAR
16765          {
16766            LEX *lex=Lex;
16767            lex->set_stmt_init();
16768            lex->var_list.empty();
16769            if (sp_create_assignment_lex(thd, yychar == YYEMPTY))
16770              MYSQL_YYABORT;
16771          }
16772          set_expr_or_default
16773          {
16774            LEX *lex= Lex;
16775            DBUG_ASSERT(lex->var_list.is_empty());
16776            if (unlikely(lex->set_variable(&$1, &$3, $6)) ||
16777                unlikely(lex->sphead->restore_lex(thd)))
16778              MYSQL_YYABORT;
16779          }
16780        | COLON_ORACLE_SYM ident '.' ident SET_VAR
16781          {
16782            LEX *lex= Lex;
16783            if (unlikely(!lex->is_trigger_new_or_old_reference(&$2)))
16784            {
16785              thd->parse_error(ER_SYNTAX_ERROR, $1.pos());
16786              MYSQL_YYABORT;
16787            }
16788            lex->set_stmt_init();
16789            lex->var_list.empty();
16790            if (sp_create_assignment_lex(thd, yychar == YYEMPTY))
16791              MYSQL_YYABORT;
16792          }
16793          set_expr_or_default
16794          {
16795            LEX_CSTRING tmp= { $2.str, $2.length };
16796            if (unlikely(Lex->set_trigger_field(&tmp, &$4, $7)) ||
16797                unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16798              MYSQL_YYABORT;
16799          }
16800        ;
16801
16802set_stmt_option_value_following_option_type_list:
16803       /*
16804         Only system variables can be used here. If this condition is changed
16805         please check careful code under lex->option_type == OPT_STATEMENT
16806         condition on wrong type casts.
16807       */
16808          option_value_following_option_type
16809        | set_stmt_option_value_following_option_type_list ',' option_value_following_option_type
16810        ;
16811
16812/* Start of option value list */
16813start_option_value_list:
16814          option_value_no_option_type
16815          {
16816            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16817              MYSQL_YYABORT;
16818          }
16819          option_value_list_continued
16820        | TRANSACTION_SYM
16821          {
16822            Lex->option_type= OPT_DEFAULT;
16823          }
16824          transaction_characteristics
16825          {
16826            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16827              MYSQL_YYABORT;
16828          }
16829        | option_type
16830          {
16831            Lex->option_type= $1;
16832          }
16833          start_option_value_list_following_option_type
16834        ;
16835
16836
16837/* Start of option value list, option_type was given */
16838start_option_value_list_following_option_type:
16839          option_value_following_option_type
16840          {
16841            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16842              MYSQL_YYABORT;
16843          }
16844          option_value_list_continued
16845        | TRANSACTION_SYM transaction_characteristics
16846          {
16847            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16848              MYSQL_YYABORT;
16849          }
16850        ;
16851
16852/* Remainder of the option value list after first option value. */
16853option_value_list_continued:
16854          /* empty */
16855        | ',' option_value_list
16856        ;
16857
16858/* Repeating list of option values after first option value. */
16859option_value_list:
16860          {
16861            if (sp_create_assignment_lex(thd, yychar == YYEMPTY))
16862              MYSQL_YYABORT;
16863          }
16864          option_value
16865          {
16866            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16867              MYSQL_YYABORT;
16868          }
16869        | option_value_list ','
16870          {
16871            if (sp_create_assignment_lex(thd, yychar == YYEMPTY))
16872              MYSQL_YYABORT;
16873          }
16874          option_value
16875          {
16876            if (unlikely(sp_create_assignment_instr(thd, yychar == YYEMPTY)))
16877              MYSQL_YYABORT;
16878          }
16879        ;
16880
16881/* Wrapper around option values following the first option value in the stmt. */
16882option_value:
16883          option_type
16884          {
16885            Lex->option_type= $1;
16886          }
16887          option_value_following_option_type
16888        | option_value_no_option_type
16889        ;
16890
16891option_type:
16892          GLOBAL_SYM  { $$=OPT_GLOBAL; }
16893        | LOCAL_SYM   { $$=OPT_SESSION; }
16894        | SESSION_SYM { $$=OPT_SESSION; }
16895        ;
16896
16897opt_var_type:
16898          /* empty */ { $$=OPT_SESSION; }
16899        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
16900        | LOCAL_SYM   { $$=OPT_SESSION; }
16901        | SESSION_SYM { $$=OPT_SESSION; }
16902        ;
16903
16904opt_var_ident_type:
16905          /* empty */     { $$=OPT_DEFAULT; }
16906        | GLOBAL_SYM '.'  { $$=OPT_GLOBAL; }
16907        | LOCAL_SYM '.'   { $$=OPT_SESSION; }
16908        | SESSION_SYM '.' { $$=OPT_SESSION; }
16909        ;
16910
16911/* Option values with preceding option_type. */
16912option_value_following_option_type:
16913          ident equal set_expr_or_default
16914          {
16915            if (unlikely(Lex->set_system_variable(Lex->option_type, &$1, $3)))
16916              MYSQL_YYABORT;
16917          }
16918        | ident '.' ident equal set_expr_or_default
16919          {
16920            if (unlikely(Lex->set_system_variable(thd, Lex->option_type, &$1, &$3, $5)))
16921              MYSQL_YYABORT;
16922          }
16923        | DEFAULT '.' ident equal set_expr_or_default
16924          {
16925            if (unlikely(Lex->set_default_system_variable(Lex->option_type, &$3, $5)))
16926              MYSQL_YYABORT;
16927          }
16928        ;
16929
16930/* Option values without preceding option_type. */
16931option_value_no_option_type:
16932          ident_set_usual_case equal set_expr_or_default
16933          {
16934            if (unlikely(Lex->set_variable(&$1, $3)))
16935              MYSQL_YYABORT;
16936          }
16937        | ident '.' ident equal set_expr_or_default
16938          {
16939            if (unlikely(Lex->set_variable(&$1, &$3, $5)))
16940              MYSQL_YYABORT;
16941          }
16942        | DEFAULT '.' ident equal set_expr_or_default
16943          {
16944            if (unlikely(Lex->set_default_system_variable(Lex->option_type, &$3, $5)))
16945              MYSQL_YYABORT;
16946          }
16947        | '@' ident_or_text equal expr
16948          {
16949            if (unlikely(Lex->set_user_variable(thd, &$2, $4)))
16950              MYSQL_YYABORT;
16951          }
16952        | '@' '@' opt_var_ident_type ident_sysvar_name equal set_expr_or_default
16953          {
16954            if (unlikely(Lex->set_system_variable($3, &$4, $6)))
16955              MYSQL_YYABORT;
16956          }
16957        | '@' '@' opt_var_ident_type ident_sysvar_name '.' ident equal set_expr_or_default
16958          {
16959            if (unlikely(Lex->set_system_variable(thd, $3, &$4, &$6, $8)))
16960              MYSQL_YYABORT;
16961          }
16962        | '@' '@' opt_var_ident_type DEFAULT '.' ident equal set_expr_or_default
16963          {
16964            if (unlikely(Lex->set_default_system_variable($3, &$6, $8)))
16965              MYSQL_YYABORT;
16966          }
16967        | charset old_or_new_charset_name_or_default
16968          {
16969            LEX *lex= thd->lex;
16970            CHARSET_INFO *cs2;
16971            cs2= $2 ? $2: global_system_variables.character_set_client;
16972            set_var_collation_client *var;
16973            var= (new (thd->mem_root)
16974                  set_var_collation_client(cs2,
16975                                           thd->variables.collation_database,
16976                                            cs2));
16977            if (unlikely(var == NULL))
16978              MYSQL_YYABORT;
16979            lex->var_list.push_back(var, thd->mem_root);
16980          }
16981        | NAMES_SYM equal expr
16982          {
16983            LEX *lex= Lex;
16984            sp_pcontext *spc= lex->spcont;
16985            LEX_CSTRING names= { STRING_WITH_LEN("names") };
16986            if (unlikely(spc && spc->find_variable(&names, false)))
16987              my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str);
16988            else
16989              thd->parse_error();
16990            MYSQL_YYABORT;
16991          }
16992        | NAMES_SYM charset_name_or_default opt_collate
16993          {
16994            LEX *lex= Lex;
16995            CHARSET_INFO *cs2;
16996            CHARSET_INFO *cs3;
16997            cs2= $2 ? $2 : global_system_variables.character_set_client;
16998            cs3= $3 ? $3 : cs2;
16999            if (unlikely(!my_charset_same(cs2, cs3)))
17000            {
17001              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
17002                       cs3->name, cs2->csname);
17003              MYSQL_YYABORT;
17004            }
17005            set_var_collation_client *var;
17006            var= new (thd->mem_root) set_var_collation_client(cs3, cs3, cs3);
17007            if (unlikely(var == NULL) ||
17008                unlikely(lex->var_list.push_back(var, thd->mem_root)))
17009              MYSQL_YYABORT;
17010          }
17011        | DEFAULT ROLE_SYM grant_role
17012          {
17013            LEX *lex = Lex;
17014            LEX_USER *user;
17015            if (unlikely(!(user=(LEX_USER *) thd->calloc(sizeof(LEX_USER)))))
17016              MYSQL_YYABORT;
17017            user->user= current_user;
17018            set_var_default_role *var= (new (thd->mem_root)
17019                                        set_var_default_role(user,
17020                                                             $3->user));
17021            if (unlikely(var == NULL) ||
17022                unlikely(lex->var_list.push_back(var, thd->mem_root)))
17023              MYSQL_YYABORT;
17024
17025            thd->lex->autocommit= TRUE;
17026            if (lex->sphead)
17027              lex->sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;
17028          }
17029        | DEFAULT ROLE_SYM grant_role FOR_SYM user
17030          {
17031            LEX *lex = Lex;
17032            set_var_default_role *var= (new (thd->mem_root)
17033                                        set_var_default_role($5, $3->user));
17034            if (unlikely(var == NULL) ||
17035                unlikely(lex->var_list.push_back(var, thd->mem_root)))
17036              MYSQL_YYABORT;
17037            thd->lex->autocommit= TRUE;
17038            if (lex->sphead)
17039              lex->sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;
17040          }
17041        | ROLE_SYM ident_or_text
17042          {
17043            LEX *lex = Lex;
17044            set_var_role *var= new (thd->mem_root) set_var_role($2);
17045            if (unlikely(var == NULL) ||
17046                unlikely(lex->var_list.push_back(var, thd->mem_root)))
17047              MYSQL_YYABORT;
17048          }
17049        | ROLE_SYM equal set_expr_or_default
17050          {
17051            if (unlikely(Lex->set_variable(&$1, $3)))
17052              MYSQL_YYABORT;
17053          }
17054        | PASSWORD_SYM opt_for_user text_or_password
17055          {
17056            LEX *lex = Lex;
17057            set_var_password *var= (new (thd->mem_root)
17058                                    set_var_password(lex->definer));
17059            if (unlikely(var == NULL) ||
17060                unlikely(lex->var_list.push_back(var, thd->mem_root)))
17061              MYSQL_YYABORT;
17062            lex->autocommit= TRUE;
17063            if (lex->sphead)
17064              lex->sphead->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;
17065          }
17066        ;
17067
17068
17069transaction_characteristics:
17070          transaction_access_mode
17071        | isolation_level
17072        | transaction_access_mode ',' isolation_level
17073        | isolation_level ',' transaction_access_mode
17074        ;
17075
17076transaction_access_mode:
17077          transaction_access_mode_types
17078          {
17079            LEX *lex=Lex;
17080            Item *item= new (thd->mem_root) Item_int(thd, (int32) $1);
17081            if (unlikely(item == NULL))
17082              MYSQL_YYABORT;
17083            set_var *var= (new (thd->mem_root)
17084                           set_var(thd, lex->option_type,
17085                                   find_sys_var(thd, "tx_read_only"),
17086                                   &null_clex_str,
17087                                   item));
17088            if (unlikely(var == NULL))
17089              MYSQL_YYABORT;
17090            if (unlikely(lex->var_list.push_back(var, thd->mem_root)))
17091              MYSQL_YYABORT;
17092          }
17093        ;
17094
17095isolation_level:
17096          ISOLATION LEVEL_SYM isolation_types
17097          {
17098            LEX *lex=Lex;
17099            Item *item= new (thd->mem_root) Item_int(thd, (int32) $3);
17100            if (unlikely(item == NULL))
17101              MYSQL_YYABORT;
17102            set_var *var= (new (thd->mem_root)
17103                           set_var(thd, lex->option_type,
17104                                   find_sys_var(thd, "tx_isolation"),
17105                                   &null_clex_str,
17106                                   item));
17107            if (unlikely(var == NULL) ||
17108                unlikely(lex->var_list.push_back(var, thd->mem_root)))
17109              MYSQL_YYABORT;
17110          }
17111        ;
17112
17113transaction_access_mode_types:
17114          READ_SYM ONLY_SYM { $$= true; }
17115        | READ_SYM WRITE_SYM { $$= false; }
17116        ;
17117
17118isolation_types:
17119          READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
17120        | READ_SYM COMMITTED_SYM   { $$= ISO_READ_COMMITTED; }
17121        | REPEATABLE_SYM READ_SYM  { $$= ISO_REPEATABLE_READ; }
17122        | SERIALIZABLE_SYM         { $$= ISO_SERIALIZABLE; }
17123        ;
17124
17125opt_for_user:
17126        equal
17127          {
17128            LEX *lex= thd->lex;
17129            sp_pcontext *spc= lex->spcont;
17130            LEX_CSTRING pw= { STRING_WITH_LEN("password") };
17131
17132            if (unlikely(spc && spc->find_variable(&pw, false)))
17133              my_yyabort_error((ER_SP_BAD_VAR_SHADOW, MYF(0), pw.str));
17134            if (unlikely(!(lex->definer= (LEX_USER*)
17135                           thd->calloc(sizeof(LEX_USER)))))
17136              MYSQL_YYABORT;
17137            lex->definer->user= current_user;
17138            lex->definer->auth= new (thd->mem_root) USER_AUTH();
17139          }
17140        | FOR_SYM user equal { Lex->definer= $2; }
17141        ;
17142
17143text_or_password:
17144          TEXT_STRING
17145          {
17146            Lex->definer->auth= new (thd->mem_root) USER_AUTH();
17147            Lex->definer->auth->auth_str= $1;
17148          }
17149        | PASSWORD_SYM '(' TEXT_STRING ')'
17150          {
17151            Lex->definer->auth= new (thd->mem_root) USER_AUTH();
17152            Lex->definer->auth->pwtext= $3;
17153          }
17154        | OLD_PASSWORD_SYM '(' TEXT_STRING ')'
17155          {
17156            Lex->definer->auth= new (thd->mem_root) USER_AUTH();
17157            Lex->definer->auth->pwtext= $3;
17158            Lex->definer->auth->auth_str.str= Item_func_password::alloc(thd,
17159                                   $3.str, $3.length, Item_func_password::OLD);
17160            Lex->definer->auth->auth_str.length=  SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
17161          }
17162        ;
17163
17164set_expr_or_default:
17165          expr { $$=$1; }
17166        | DEFAULT { $$=0; }
17167        | ON
17168          {
17169            $$=new (thd->mem_root) Item_string_sys(thd, "ON",  2);
17170            if (unlikely($$ == NULL))
17171              MYSQL_YYABORT;
17172          }
17173        | ALL
17174          {
17175            $$=new (thd->mem_root) Item_string_sys(thd, "ALL", 3);
17176            if (unlikely($$ == NULL))
17177              MYSQL_YYABORT;
17178          }
17179        | BINARY
17180          {
17181            $$=new (thd->mem_root) Item_string_sys(thd, "binary", 6);
17182            if (unlikely($$ == NULL))
17183              MYSQL_YYABORT;
17184          }
17185        ;
17186
17187/* Lock function */
17188
17189lock:
17190          LOCK_SYM table_or_tables
17191          {
17192            LEX *lex= Lex;
17193
17194            if (unlikely(lex->sphead))
17195              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "LOCK"));
17196            lex->sql_command= SQLCOM_LOCK_TABLES;
17197          }
17198          table_lock_list opt_lock_wait_timeout
17199          {}
17200        ;
17201
17202opt_lock_wait_timeout:
17203        /* empty */
17204        {}
17205        | WAIT_SYM ulong_num
17206        {
17207          if (unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("lock_wait_timeout"), $2)) ||
17208              unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("innodb_lock_wait_timeout"), $2)))
17209            MYSQL_YYABORT;
17210        }
17211        | NOWAIT_SYM
17212        {
17213          if (unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("lock_wait_timeout"), 0)) ||
17214              unlikely(set_statement_var_if_exists(thd, STRING_WITH_LEN("innodb_lock_wait_timeout"), 0)))
17215            MYSQL_YYABORT;
17216        }
17217      ;
17218
17219table_or_tables:
17220          TABLE_SYM        { }
17221        | TABLES           { }
17222        ;
17223
17224table_lock_list:
17225          table_lock
17226        | table_lock_list ',' table_lock
17227        ;
17228
17229table_lock:
17230          table_ident opt_table_alias_clause lock_option
17231          {
17232            thr_lock_type lock_type= (thr_lock_type) $3;
17233            bool lock_for_write= (lock_type >= TL_WRITE_ALLOW_WRITE);
17234            ulong table_options= lock_for_write ? TL_OPTION_UPDATING : 0;
17235            enum_mdl_type mdl_type= !lock_for_write
17236                                    ? MDL_SHARED_READ
17237                                    : lock_type == TL_WRITE_CONCURRENT_INSERT
17238                                      ? MDL_SHARED_WRITE
17239                                      : MDL_SHARED_NO_READ_WRITE;
17240
17241            if (unlikely(!Lex->current_select_or_default()->
17242                         add_table_to_list(thd, $1, $2, table_options,
17243                                           lock_type, mdl_type)))
17244              MYSQL_YYABORT;
17245          }
17246        ;
17247
17248lock_option:
17249          READ_SYM               { $$= TL_READ_NO_INSERT; }
17250        | WRITE_SYM              { $$= TL_WRITE_DEFAULT; }
17251        | WRITE_SYM CONCURRENT
17252          {
17253            $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT);
17254          }
17255
17256        | LOW_PRIORITY WRITE_SYM { $$= TL_WRITE_LOW_PRIORITY; }
17257        | READ_SYM LOCAL_SYM     { $$= TL_READ; }
17258        ;
17259
17260unlock:
17261          UNLOCK_SYM
17262          {
17263            LEX *lex= Lex;
17264
17265            if (unlikely(lex->sphead))
17266              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "UNLOCK"));
17267            lex->sql_command= SQLCOM_UNLOCK_TABLES;
17268          }
17269          table_or_tables
17270          {}
17271        ;
17272
17273/*
17274** Handler: direct access to ISAM functions
17275*/
17276
17277handler:
17278          HANDLER_SYM
17279          {
17280            if (Lex->main_select_push())
17281              MYSQL_YYABORT;
17282          }
17283          handler_tail
17284          {
17285            Lex->pop_select(); //main select
17286          }
17287        ;
17288
17289handler_tail:
17290          table_ident OPEN_SYM opt_table_alias_clause
17291          {
17292            LEX *lex= Lex;
17293            if (unlikely(lex->sphead))
17294              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER"));
17295            lex->sql_command = SQLCOM_HA_OPEN;
17296            if (!lex->current_select->add_table_to_list(thd, $1, $3, 0))
17297              MYSQL_YYABORT;
17298          }
17299        | table_ident_nodb CLOSE_SYM
17300          {
17301            LEX *lex= Lex;
17302            if (unlikely(lex->sphead))
17303              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER"));
17304            lex->sql_command = SQLCOM_HA_CLOSE;
17305            if (!lex->current_select->add_table_to_list(thd, $1, 0, 0))
17306              MYSQL_YYABORT;
17307          }
17308        | table_ident_nodb READ_SYM
17309          {
17310            LEX *lex=Lex;
17311            if (unlikely(lex->sphead))
17312              my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER"));
17313            lex->clause_that_disallows_subselect= "HANDLER..READ";
17314            lex->sql_command = SQLCOM_HA_READ;
17315            lex->ha_rkey_mode= HA_READ_KEY_EXACT; /* Avoid purify warnings */
17316            Item *one= new (thd->mem_root) Item_int(thd, (int32) 1);
17317            if (unlikely(one == NULL))
17318              MYSQL_YYABORT;
17319            lex->current_select->select_limit= one;
17320            lex->current_select->offset_limit= 0;
17321            lex->limit_rows_examined= 0;
17322            if (!lex->current_select->add_table_to_list(thd, $1, 0, 0))
17323              MYSQL_YYABORT;
17324          }
17325          handler_read_or_scan opt_where_clause opt_global_limit_clause
17326          {
17327            LEX *lex=Lex;
17328            lex->clause_that_disallows_subselect= NULL;
17329            if (!lex->current_select->explicit_limit)
17330            {
17331              Item *one= new (thd->mem_root) Item_int(thd, (int32) 1);
17332              if (one == NULL)
17333                MYSQL_YYABORT;
17334              lex->current_select->select_limit= one;
17335              lex->current_select->offset_limit= 0;
17336              lex->limit_rows_examined= 0;
17337            }
17338            /* Stored functions are not supported for HANDLER READ. */
17339            if (lex->uses_stored_routines())
17340            {
17341              my_error(ER_NOT_SUPPORTED_YET, MYF(0),
17342                       "stored functions in HANDLER ... READ");
17343              MYSQL_YYABORT;
17344            }
17345          }
17346        ;
17347
17348handler_read_or_scan:
17349          handler_scan_function       { Lex->ident= null_clex_str; }
17350        | ident handler_rkey_function { Lex->ident= $1; }
17351        ;
17352
17353handler_scan_function:
17354          FIRST_SYM { Lex->ha_read_mode = RFIRST; }
17355        | NEXT_SYM  { Lex->ha_read_mode = RNEXT;  }
17356        ;
17357
17358handler_rkey_function:
17359          FIRST_SYM { Lex->ha_read_mode = RFIRST; }
17360        | NEXT_SYM  { Lex->ha_read_mode = RNEXT;  }
17361        | PREV_SYM  { Lex->ha_read_mode = RPREV;  }
17362        | LAST_SYM  { Lex->ha_read_mode = RLAST;  }
17363        | handler_rkey_mode
17364          {
17365            LEX *lex=Lex;
17366            lex->ha_read_mode = RKEY;
17367            lex->ha_rkey_mode=$1;
17368            if (unlikely(!(lex->insert_list= new (thd->mem_root) List_item)))
17369              MYSQL_YYABORT;
17370          }
17371          '(' values ')'
17372          {}
17373        ;
17374
17375handler_rkey_mode:
17376          '='     { $$=HA_READ_KEY_EXACT;   }
17377        | GE     { $$=HA_READ_KEY_OR_NEXT; }
17378        | LE     { $$=HA_READ_KEY_OR_PREV; }
17379        | '>' { $$=HA_READ_AFTER_KEY;   }
17380        | '<'     { $$=HA_READ_BEFORE_KEY;  }
17381        ;
17382
17383/* GRANT / REVOKE */
17384
17385revoke:
17386          REVOKE clear_privileges revoke_command
17387          {}
17388        ;
17389
17390revoke_command:
17391          grant_privileges ON opt_table grant_ident FROM user_and_role_list
17392          {
17393            LEX *lex= Lex;
17394            lex->sql_command= SQLCOM_REVOKE;
17395            lex->type= 0;
17396          }
17397        | grant_privileges ON FUNCTION_SYM grant_ident FROM user_and_role_list
17398          {
17399            if (unlikely(Lex->add_grant_command(thd, SQLCOM_REVOKE,
17400                                                TYPE_ENUM_FUNCTION)))
17401              MYSQL_YYABORT;
17402          }
17403        | grant_privileges ON PROCEDURE_SYM grant_ident FROM user_and_role_list
17404          {
17405            if (unlikely(Lex->add_grant_command(thd, SQLCOM_REVOKE,
17406                         TYPE_ENUM_PROCEDURE)))
17407              MYSQL_YYABORT;
17408          }
17409        | grant_privileges ON PACKAGE_ORACLE_SYM grant_ident
17410          FROM user_and_role_list
17411          {
17412            if (unlikely(Lex->add_grant_command(thd, SQLCOM_REVOKE,
17413                                                TYPE_ENUM_PACKAGE)))
17414              MYSQL_YYABORT;
17415          }
17416        | grant_privileges ON PACKAGE_ORACLE_SYM BODY_ORACLE_SYM grant_ident
17417          FROM user_and_role_list
17418          {
17419            if (unlikely(Lex->add_grant_command(thd, SQLCOM_REVOKE,
17420                                                TYPE_ENUM_PACKAGE_BODY)))
17421              MYSQL_YYABORT;
17422          }
17423        | ALL opt_privileges ',' GRANT OPTION FROM user_and_role_list
17424          {
17425            Lex->sql_command = SQLCOM_REVOKE_ALL;
17426          }
17427        | PROXY_SYM ON user FROM user_list
17428          {
17429            LEX *lex= Lex;
17430            lex->users_list.push_front ($3);
17431            lex->sql_command= SQLCOM_REVOKE;
17432            lex->type= TYPE_ENUM_PROXY;
17433          }
17434        | admin_option_for_role FROM user_and_role_list
17435          {
17436            Lex->sql_command= SQLCOM_REVOKE_ROLE;
17437            if (unlikely(Lex->users_list.push_front($1, thd->mem_root)))
17438              MYSQL_YYABORT;
17439          }
17440        ;
17441
17442admin_option_for_role:
17443        ADMIN_SYM OPTION FOR_SYM grant_role
17444        { Lex->with_admin_option= true; $$= $4; }
17445      | grant_role
17446        { Lex->with_admin_option= false; $$= $1; }
17447      ;
17448
17449grant:
17450          GRANT clear_privileges grant_command
17451          {}
17452        ;
17453
17454grant_command:
17455          grant_privileges ON opt_table grant_ident TO_SYM grant_list
17456          opt_require_clause opt_grant_options
17457          {
17458            LEX *lex= Lex;
17459            lex->sql_command= SQLCOM_GRANT;
17460            lex->type= 0;
17461          }
17462        | grant_privileges ON FUNCTION_SYM grant_ident TO_SYM grant_list
17463          opt_require_clause opt_grant_options
17464          {
17465            if (unlikely(Lex->add_grant_command(thd, SQLCOM_GRANT,
17466                                                TYPE_ENUM_FUNCTION)))
17467              MYSQL_YYABORT;
17468          }
17469        | grant_privileges ON PROCEDURE_SYM grant_ident TO_SYM grant_list
17470          opt_require_clause opt_grant_options
17471          {
17472            if (unlikely(Lex->add_grant_command(thd, SQLCOM_GRANT,
17473                                                TYPE_ENUM_PROCEDURE)))
17474              MYSQL_YYABORT;
17475          }
17476        | grant_privileges ON PACKAGE_ORACLE_SYM grant_ident TO_SYM grant_list
17477          opt_require_clause opt_grant_options
17478          {
17479            if (unlikely(Lex->add_grant_command(thd, SQLCOM_GRANT,
17480                                                TYPE_ENUM_PACKAGE)))
17481              MYSQL_YYABORT;
17482          }
17483        | grant_privileges ON PACKAGE_ORACLE_SYM BODY_ORACLE_SYM grant_ident TO_SYM grant_list
17484          opt_require_clause opt_grant_options
17485          {
17486            if (unlikely(Lex->add_grant_command(thd, SQLCOM_GRANT,
17487                                                TYPE_ENUM_PACKAGE_BODY)))
17488              MYSQL_YYABORT;
17489          }
17490        | PROXY_SYM ON user TO_SYM grant_list opt_grant_option
17491          {
17492            LEX *lex= Lex;
17493            lex->users_list.push_front ($3);
17494            lex->sql_command= SQLCOM_GRANT;
17495            lex->type= TYPE_ENUM_PROXY;
17496          }
17497        | grant_role TO_SYM grant_list opt_with_admin_option
17498          {
17499            LEX *lex= Lex;
17500            lex->sql_command= SQLCOM_GRANT_ROLE;
17501            /* The first role is the one that is granted */
17502            if (unlikely(Lex->users_list.push_front($1, thd->mem_root)))
17503              MYSQL_YYABORT;
17504          }
17505
17506        ;
17507
17508opt_with_admin:
17509          /* nothing */               { Lex->definer = 0; }
17510        | WITH ADMIN_SYM user_or_role { Lex->definer = $3; }
17511        ;
17512
17513opt_with_admin_option:
17514          /* nothing */               { Lex->with_admin_option= false; }
17515        | WITH ADMIN_SYM OPTION       { Lex->with_admin_option= true; }
17516        ;
17517
17518role_list:
17519          grant_role
17520          {
17521            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17522              MYSQL_YYABORT;
17523          }
17524        | role_list ',' grant_role
17525          {
17526            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17527              MYSQL_YYABORT;
17528          }
17529        ;
17530
17531current_role:
17532          CURRENT_ROLE optional_braces
17533          {
17534            if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER)))))
17535              MYSQL_YYABORT;
17536            $$->user= current_role;
17537            $$->auth= NULL;
17538          }
17539          ;
17540
17541grant_role:
17542          ident_or_text
17543          {
17544            CHARSET_INFO *cs= system_charset_info;
17545            /* trim end spaces (as they'll be lost in mysql.user anyway) */
17546            $1.length= cs->cset->lengthsp(cs, $1.str, $1.length);
17547            ((char*) $1.str)[$1.length] = '\0';
17548            if (unlikely($1.length == 0))
17549              my_yyabort_error((ER_INVALID_ROLE, MYF(0), ""));
17550            if (unlikely(!($$=(LEX_USER*) thd->alloc(sizeof(LEX_USER)))))
17551              MYSQL_YYABORT;
17552            $$->user= $1;
17553            $$->host= empty_clex_str;
17554            $$->auth= NULL;
17555
17556            if (unlikely(check_string_char_length(&$$->user, ER_USERNAME,
17557                                                  username_char_length,
17558                                                  cs, 0)))
17559              MYSQL_YYABORT;
17560          }
17561        | current_role
17562        ;
17563
17564opt_table:
17565          /* Empty */
17566        | TABLE_SYM
17567        ;
17568
17569grant_privileges:
17570          object_privilege_list {}
17571        | ALL opt_privileges
17572          {
17573            Lex->all_privileges= 1;
17574            Lex->grant= GLOBAL_ACLS;
17575          }
17576        ;
17577
17578opt_privileges:
17579          /* empty */
17580        | PRIVILEGES
17581        ;
17582
17583object_privilege_list:
17584          object_privilege
17585        | object_privilege_list ',' object_privilege
17586        ;
17587
17588object_privilege:
17589          SELECT_SYM
17590          { Lex->which_columns = SELECT_ACL;}
17591          opt_column_list {}
17592        | INSERT
17593          { Lex->which_columns = INSERT_ACL;}
17594          opt_column_list {}
17595        | UPDATE_SYM
17596          { Lex->which_columns = UPDATE_ACL; }
17597          opt_column_list {}
17598        | REFERENCES
17599          { Lex->which_columns = REFERENCES_ACL;}
17600          opt_column_list {}
17601        | DELETE_SYM              { Lex->grant |= DELETE_ACL;}
17602        | USAGE                   {}
17603        | INDEX_SYM               { Lex->grant |= INDEX_ACL;}
17604        | ALTER                   { Lex->grant |= ALTER_ACL;}
17605        | CREATE                  { Lex->grant |= CREATE_ACL;}
17606        | DROP                    { Lex->grant |= DROP_ACL;}
17607        | EXECUTE_SYM             { Lex->grant |= EXECUTE_ACL;}
17608        | RELOAD                  { Lex->grant |= RELOAD_ACL;}
17609        | SHUTDOWN                { Lex->grant |= SHUTDOWN_ACL;}
17610        | PROCESS                 { Lex->grant |= PROCESS_ACL;}
17611        | FILE_SYM                { Lex->grant |= FILE_ACL;}
17612        | GRANT OPTION            { Lex->grant |= GRANT_ACL;}
17613        | SHOW DATABASES          { Lex->grant |= SHOW_DB_ACL;}
17614        | SUPER_SYM               { Lex->grant |= SUPER_ACL;}
17615        | CREATE TEMPORARY TABLES { Lex->grant |= CREATE_TMP_ACL;}
17616        | LOCK_SYM TABLES         { Lex->grant |= LOCK_TABLES_ACL; }
17617        | REPLICATION SLAVE       { Lex->grant |= REPL_SLAVE_ACL; }
17618        | REPLICATION CLIENT_SYM  { Lex->grant |= REPL_CLIENT_ACL; }
17619        | CREATE VIEW_SYM         { Lex->grant |= CREATE_VIEW_ACL; }
17620        | SHOW VIEW_SYM           { Lex->grant |= SHOW_VIEW_ACL; }
17621        | CREATE ROUTINE_SYM      { Lex->grant |= CREATE_PROC_ACL; }
17622        | ALTER ROUTINE_SYM       { Lex->grant |= ALTER_PROC_ACL; }
17623        | CREATE USER_SYM         { Lex->grant |= CREATE_USER_ACL; }
17624        | EVENT_SYM               { Lex->grant |= EVENT_ACL;}
17625        | TRIGGER_SYM             { Lex->grant |= TRIGGER_ACL; }
17626        | CREATE TABLESPACE       { Lex->grant |= CREATE_TABLESPACE_ACL; }
17627        | DELETE_SYM HISTORY_SYM  { Lex->grant |= DELETE_HISTORY_ACL; }
17628        ;
17629
17630opt_and:
17631          /* empty */ {}
17632        | AND_SYM {}
17633        ;
17634
17635require_list:
17636          require_list_element opt_and require_list
17637        | require_list_element
17638        ;
17639
17640require_list_element:
17641          SUBJECT_SYM TEXT_STRING
17642          {
17643            LEX *lex=Lex;
17644            if (lex->account_options.x509_subject.str)
17645              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "SUBJECT"));
17646            lex->account_options.x509_subject= $2;
17647          }
17648        | ISSUER_SYM TEXT_STRING
17649          {
17650            LEX *lex=Lex;
17651            if (lex->account_options.x509_issuer.str)
17652              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "ISSUER"));
17653            lex->account_options.x509_issuer= $2;
17654          }
17655        | CIPHER_SYM TEXT_STRING
17656          {
17657            LEX *lex=Lex;
17658            if (lex->account_options.ssl_cipher.str)
17659              my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "CIPHER"));
17660            lex->account_options.ssl_cipher= $2;
17661          }
17662        ;
17663
17664grant_ident:
17665          '*'
17666          {
17667            LEX *lex= Lex;
17668            if (unlikely(lex->copy_db_to(&lex->first_select_lex()->db)))
17669              MYSQL_YYABORT;
17670            if (lex->grant == GLOBAL_ACLS)
17671              lex->grant = DB_ACLS & ~GRANT_ACL;
17672            else if (unlikely(lex->columns.elements))
17673              my_yyabort_error((ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)));
17674          }
17675        | ident '.' '*'
17676          {
17677            LEX *lex= Lex;
17678            lex->first_select_lex()->db= $1;
17679            if (lex->grant == GLOBAL_ACLS)
17680              lex->grant = DB_ACLS & ~GRANT_ACL;
17681            else if (unlikely(lex->columns.elements))
17682              my_yyabort_error((ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)));
17683          }
17684        | '*' '.' '*'
17685          {
17686            LEX *lex= Lex;
17687            lex->first_select_lex()->db= null_clex_str;
17688            if (lex->grant == GLOBAL_ACLS)
17689              lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
17690            else if (unlikely(lex->columns.elements))
17691              my_yyabort_error((ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)));
17692          }
17693        | table_ident
17694          {
17695            LEX *lex=Lex;
17696            if (unlikely(!lex->first_select_lex()->
17697                         add_table_to_list(thd, $1,NULL,
17698                                           TL_OPTION_UPDATING)))
17699              MYSQL_YYABORT;
17700            if (lex->grant == GLOBAL_ACLS)
17701              lex->grant =  TABLE_ACLS & ~GRANT_ACL;
17702          }
17703        ;
17704
17705user_list:
17706          user
17707          {
17708            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17709              MYSQL_YYABORT;
17710          }
17711        | user_list ',' user
17712          {
17713            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17714              MYSQL_YYABORT;
17715          }
17716        ;
17717
17718grant_list:
17719          grant_user
17720          {
17721            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17722              MYSQL_YYABORT;
17723          }
17724        | grant_list ',' grant_user
17725          {
17726            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17727              MYSQL_YYABORT;
17728          }
17729        ;
17730
17731user_and_role_list:
17732          user_or_role
17733          {
17734            if (unlikely(Lex->users_list.push_back($1, thd->mem_root)))
17735              MYSQL_YYABORT;
17736          }
17737        | user_and_role_list ',' user_or_role
17738          {
17739            if (unlikely(Lex->users_list.push_back($3, thd->mem_root)))
17740              MYSQL_YYABORT;
17741          }
17742        ;
17743
17744via_or_with: VIA_SYM | WITH ;
17745using_or_as: USING | AS ;
17746
17747grant_user:
17748          user IDENTIFIED_SYM BY TEXT_STRING
17749          {
17750            $$= $1;
17751            $1->auth= new (thd->mem_root) USER_AUTH();
17752            $1->auth->pwtext= $4;
17753          }
17754        | user IDENTIFIED_SYM BY PASSWORD_SYM TEXT_STRING
17755          {
17756            $$= $1;
17757            $1->auth= new (thd->mem_root) USER_AUTH();
17758            $1->auth->auth_str= $5;
17759          }
17760        | user IDENTIFIED_SYM via_or_with auth_expression
17761          {
17762            $$= $1;
17763            $1->auth= $4;
17764          }
17765        | user_or_role
17766          {
17767            $$= $1;
17768          }
17769        ;
17770
17771auth_expression:
17772          auth_token OR_SYM auth_expression
17773          {
17774            $$= $1;
17775            DBUG_ASSERT($$->next == NULL);
17776            $$->next= $3;
17777          }
17778        | auth_token
17779          {
17780            $$= $1;
17781          }
17782        ;
17783
17784auth_token:
17785          ident_or_text opt_auth_str
17786        {
17787          $$= $2;
17788          $$->plugin= $1;
17789        }
17790        ;
17791
17792opt_auth_str:
17793        /* empty */
17794        {
17795          if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH))))
17796            MYSQL_YYABORT;
17797        }
17798      | using_or_as TEXT_STRING_sys
17799        {
17800          if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH))))
17801            MYSQL_YYABORT;
17802          $$->auth_str= $2;
17803        }
17804      | using_or_as PASSWORD_SYM '(' TEXT_STRING ')'
17805        {
17806          if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH))))
17807            MYSQL_YYABORT;
17808          $$->pwtext= $4;
17809        }
17810        ;
17811
17812opt_column_list:
17813          /* empty */
17814          {
17815            LEX *lex=Lex;
17816            lex->grant |= lex->which_columns;
17817          }
17818        | '(' column_list ')' { }
17819        ;
17820
17821column_list:
17822          column_list ',' column_list_id
17823        | column_list_id
17824        ;
17825
17826column_list_id:
17827          ident
17828          {
17829            String *new_str= new (thd->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
17830            if (unlikely(new_str == NULL))
17831              MYSQL_YYABORT;
17832            List_iterator <LEX_COLUMN> iter(Lex->columns);
17833            class LEX_COLUMN *point;
17834            LEX *lex=Lex;
17835            while ((point=iter++))
17836            {
17837              if (!my_strcasecmp(system_charset_info,
17838                                 point->column.c_ptr(), new_str->c_ptr()))
17839                break;
17840            }
17841            lex->grant_tot_col|= lex->which_columns;
17842            if (point)
17843              point->rights |= lex->which_columns;
17844            else
17845            {
17846              LEX_COLUMN *col= (new (thd->mem_root)
17847                                LEX_COLUMN(*new_str,lex->which_columns));
17848              if (unlikely(col == NULL))
17849                MYSQL_YYABORT;
17850              lex->columns.push_back(col, thd->mem_root);
17851            }
17852          }
17853        ;
17854
17855opt_require_clause:
17856          /* empty */
17857        | REQUIRE_SYM require_list
17858          {
17859            Lex->account_options.ssl_type= SSL_TYPE_SPECIFIED;
17860          }
17861        | REQUIRE_SYM SSL_SYM
17862          {
17863            Lex->account_options.ssl_type= SSL_TYPE_ANY;
17864          }
17865        | REQUIRE_SYM X509_SYM
17866          {
17867            Lex->account_options.ssl_type= SSL_TYPE_X509;
17868          }
17869        | REQUIRE_SYM NONE_SYM
17870          {
17871            Lex->account_options.ssl_type= SSL_TYPE_NONE;
17872          }
17873        ;
17874
17875resource_option:
17876        MAX_QUERIES_PER_HOUR ulong_num
17877          {
17878            Lex->account_options.questions=$2;
17879            Lex->account_options.specified_limits|= USER_RESOURCES::QUERIES_PER_HOUR;
17880          }
17881        | MAX_UPDATES_PER_HOUR ulong_num
17882          {
17883            Lex->account_options.updates=$2;
17884            Lex->account_options.specified_limits|= USER_RESOURCES::UPDATES_PER_HOUR;
17885          }
17886        | MAX_CONNECTIONS_PER_HOUR ulong_num
17887          {
17888            Lex->account_options.conn_per_hour= $2;
17889            Lex->account_options.specified_limits|= USER_RESOURCES::CONNECTIONS_PER_HOUR;
17890          }
17891        | MAX_USER_CONNECTIONS_SYM int_num
17892          {
17893            Lex->account_options.user_conn= $2;
17894            Lex->account_options.specified_limits|= USER_RESOURCES::USER_CONNECTIONS;
17895          }
17896        | MAX_STATEMENT_TIME_SYM NUM_literal
17897          {
17898            Lex->account_options.max_statement_time= $2->val_real();
17899            Lex->account_options.specified_limits|= USER_RESOURCES::MAX_STATEMENT_TIME;
17900          }
17901        ;
17902
17903resource_option_list:
17904	  resource_option_list resource_option {}
17905	| resource_option {}
17906        ;
17907
17908opt_resource_options:
17909	  /* empty */ {}
17910	| WITH resource_option_list
17911        ;
17912
17913
17914opt_grant_options:
17915          /* empty */ {}
17916        | WITH grant_option_list {}
17917        ;
17918
17919opt_grant_option:
17920          /* empty */ {}
17921        | WITH GRANT OPTION { Lex->grant |= GRANT_ACL;}
17922        ;
17923
17924grant_option_list:
17925          grant_option_list grant_option {}
17926        | grant_option {}
17927        ;
17928
17929grant_option:
17930          GRANT OPTION { Lex->grant |= GRANT_ACL;}
17931	| resource_option {}
17932        ;
17933
17934begin_stmt_mariadb:
17935          BEGIN_MARIADB_SYM
17936          {
17937            LEX *lex=Lex;
17938            lex->sql_command = SQLCOM_BEGIN;
17939            lex->start_transaction_opt= 0;
17940          }
17941          opt_work {}
17942          ;
17943
17944compound_statement:
17945          sp_proc_stmt_compound_ok
17946          {
17947            Lex->sql_command= SQLCOM_COMPOUND;
17948            if (Lex->sp_body_finalize_procedure(thd))
17949              MYSQL_YYABORT;
17950          }
17951        ;
17952
17953opt_not:
17954        /* nothing */  { $$= 0; }
17955        | not          { $$= 1; }
17956        ;
17957
17958opt_work:
17959          /* empty */ {}
17960        | WORK_SYM  {}
17961        ;
17962
17963opt_chain:
17964          /* empty */
17965          { $$= TVL_UNKNOWN; }
17966        | AND_SYM NO_SYM CHAIN_SYM { $$= TVL_NO; }
17967        | AND_SYM CHAIN_SYM        { $$= TVL_YES; }
17968        ;
17969
17970opt_release:
17971          /* empty */
17972          { $$= TVL_UNKNOWN; }
17973        | RELEASE_SYM        { $$= TVL_YES; }
17974        | NO_SYM RELEASE_SYM { $$= TVL_NO; }
17975        ;
17976
17977commit:
17978          COMMIT_SYM opt_work opt_chain opt_release
17979          {
17980            LEX *lex=Lex;
17981            lex->sql_command= SQLCOM_COMMIT;
17982            /* Don't allow AND CHAIN RELEASE. */
17983            MYSQL_YYABORT_UNLESS($3 != TVL_YES || $4 != TVL_YES);
17984            lex->tx_chain= $3;
17985            lex->tx_release= $4;
17986          }
17987        ;
17988
17989rollback:
17990          ROLLBACK_SYM opt_work opt_chain opt_release
17991          {
17992            LEX *lex=Lex;
17993            lex->sql_command= SQLCOM_ROLLBACK;
17994            /* Don't allow AND CHAIN RELEASE. */
17995            MYSQL_YYABORT_UNLESS($3 != TVL_YES || $4 != TVL_YES);
17996            lex->tx_chain= $3;
17997            lex->tx_release= $4;
17998          }
17999        | ROLLBACK_SYM opt_work TO_SYM SAVEPOINT_SYM ident
18000          {
18001            LEX *lex=Lex;
18002            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
18003            lex->ident= $5;
18004          }
18005        | ROLLBACK_SYM opt_work TO_SYM ident
18006          {
18007            LEX *lex=Lex;
18008            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
18009            lex->ident= $4;
18010          }
18011        ;
18012
18013savepoint:
18014          SAVEPOINT_SYM ident
18015          {
18016            LEX *lex=Lex;
18017            lex->sql_command= SQLCOM_SAVEPOINT;
18018            lex->ident= $2;
18019          }
18020        ;
18021
18022release:
18023          RELEASE_SYM SAVEPOINT_SYM ident
18024          {
18025            LEX *lex=Lex;
18026            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
18027            lex->ident= $3;
18028          }
18029        ;
18030
18031/*
18032   UNIONS : glue selects together
18033*/
18034
18035unit_type_decl:
18036          UNION_SYM union_option
18037          { $$.unit_type= UNION_TYPE; $$.distinct= $2; }
18038        | INTERSECT_SYM
18039          { $$.unit_type= INTERSECT_TYPE; $$.distinct= 1; }
18040        | EXCEPT_SYM
18041          { $$.unit_type= EXCEPT_TYPE; $$.distinct= 1; }
18042        ;
18043
18044/*
18045  Start a UNION, for non-top level query expressions.
18046*/
18047union_option:
18048          /* empty */ { $$=1; }
18049        | DISTINCT  { $$=1; }
18050        | ALL       { $$=0; }
18051        ;
18052
18053query_expression_option:
18054          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
18055        | HIGH_PRIORITY
18056          {
18057            YYPS->m_lock_type= TL_READ_HIGH_PRIORITY;
18058            YYPS->m_mdl_type= MDL_SHARED_READ;
18059            Select->options|= SELECT_HIGH_PRIORITY;
18060          }
18061        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
18062        | UNIQUE_SYM       { Select->options|= SELECT_DISTINCT; }
18063        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
18064        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
18065        | SQL_BUFFER_RESULT { Select->options|= OPTION_BUFFER_RESULT; }
18066        | SQL_CALC_FOUND_ROWS { Select->options|= OPTION_FOUND_ROWS; }
18067        | ALL { Select->options|= SELECT_ALL; }
18068        ;
18069
18070/**************************************************************************
18071
18072 DEFINER clause support.
18073
18074**************************************************************************/
18075
18076definer_opt:
18077          no_definer
18078        | definer
18079        ;
18080
18081no_definer:
18082          /* empty */
18083          {
18084            /*
18085              We have to distinguish missing DEFINER-clause from case when
18086              CURRENT_USER specified as definer explicitly in order to properly
18087              handle CREATE TRIGGER statements which come to replication thread
18088              from older master servers (i.e. to create non-suid trigger in this
18089              case).
18090            */
18091            thd->lex->definer= 0;
18092          }
18093        ;
18094
18095definer:
18096          DEFINER_SYM '=' user_or_role
18097          {
18098            Lex->definer= $3;
18099            Lex->account_options.reset();
18100          }
18101        ;
18102
18103/**************************************************************************
18104
18105 CREATE VIEW statement parts.
18106
18107**************************************************************************/
18108
18109view_algorithm:
18110          ALGORITHM_SYM '=' UNDEFINED_SYM { $$= DTYPE_ALGORITHM_UNDEFINED; }
18111        | ALGORITHM_SYM '=' MERGE_SYM     { $$= VIEW_ALGORITHM_MERGE; }
18112        | ALGORITHM_SYM '=' TEMPTABLE_SYM { $$= VIEW_ALGORITHM_TMPTABLE; }
18113        ;
18114
18115opt_view_suid:
18116          /* empty */                      { $$= VIEW_SUID_DEFAULT; }
18117        | view_suid                        { $$= $1; }
18118        ;
18119
18120view_suid:
18121          SQL_SYM SECURITY_SYM DEFINER_SYM { $$= VIEW_SUID_DEFINER; }
18122        | SQL_SYM SECURITY_SYM INVOKER_SYM { $$= VIEW_SUID_INVOKER; }
18123        ;
18124
18125view_list_opt:
18126          /* empty */
18127          {}
18128        | '(' view_list ')' { }
18129        ;
18130
18131view_list:
18132          ident
18133          {
18134            Lex->view_list.push_back((LEX_CSTRING*)
18135                                     thd->memdup(&$1, sizeof(LEX_CSTRING)),
18136                                     thd->mem_root);
18137          }
18138        | view_list ',' ident
18139          {
18140            Lex->view_list.push_back((LEX_CSTRING*)
18141                                     thd->memdup(&$3, sizeof(LEX_CSTRING)),
18142                                     thd->mem_root);
18143          }
18144        ;
18145
18146view_select:
18147          {
18148            LEX *lex= Lex;
18149            lex->parsing_options.allows_variable= FALSE;
18150            lex->create_view->select.str= (char *) YYLIP->get_cpp_ptr();
18151          }
18152          query_expression
18153          view_check_option
18154          {
18155            if (Lex->parsed_create_view($2, $3))
18156              MYSQL_YYABORT;
18157          }
18158        ;
18159
18160view_check_option:
18161          /* empty */                     { $$= VIEW_CHECK_NONE; }
18162        | WITH CHECK_SYM OPTION           { $$= VIEW_CHECK_CASCADED; }
18163        | WITH CASCADED CHECK_SYM OPTION  { $$= VIEW_CHECK_CASCADED; }
18164        | WITH LOCAL_SYM CHECK_SYM OPTION { $$= VIEW_CHECK_LOCAL; }
18165        ;
18166
18167/**************************************************************************
18168
18169 CREATE TRIGGER statement parts.
18170
18171**************************************************************************/
18172
18173trigger_action_order:
18174            FOLLOWS_SYM
18175            { $$= TRG_ORDER_FOLLOWS; }
18176          | PRECEDES_SYM
18177            { $$= TRG_ORDER_PRECEDES; }
18178          ;
18179
18180trigger_follows_precedes_clause:
18181            /* empty */
18182            {
18183              $$.ordering_clause= TRG_ORDER_NONE;
18184              $$.anchor_trigger_name.str= NULL;
18185              $$.anchor_trigger_name.length= 0;
18186            }
18187          |
18188            trigger_action_order ident_or_text
18189            {
18190              $$.ordering_clause= $1;
18191              $$.anchor_trigger_name= $2;
18192            }
18193          ;
18194
18195trigger_tail:
18196          remember_name
18197          opt_if_not_exists
18198          {
18199            if (unlikely(Lex->add_create_options_with_check($2)))
18200              MYSQL_YYABORT;
18201          }
18202          sp_name
18203          trg_action_time
18204          trg_event
18205          ON
18206          remember_name /* $8 */
18207          { /* $9 */
18208            Lex->raw_trg_on_table_name_begin= YYLIP->get_tok_start();
18209          }
18210          table_ident /* $10 */
18211          FOR_SYM
18212          remember_name /* $12 */
18213          { /* $13 */
18214            Lex->raw_trg_on_table_name_end= YYLIP->get_tok_start();
18215          }
18216          EACH_SYM
18217          ROW_SYM
18218          {
18219            Lex->trg_chistics.ordering_clause_begin= YYLIP->get_cpp_ptr();
18220          }
18221          trigger_follows_precedes_clause /* $17 */
18222          { /* $18 */
18223            LEX *lex= thd->lex;
18224            Lex_input_stream *lip= YYLIP;
18225
18226            if (unlikely(lex->sphead))
18227              my_yyabort_error((ER_SP_NO_RECURSIVE_CREATE, MYF(0), "TRIGGER"));
18228
18229            lex->stmt_definition_begin= $1;
18230            lex->ident.str= $8;
18231            lex->ident.length= $12 - $8;
18232            lex->spname= $4;
18233            (*static_cast<st_trg_execution_order*>(&lex->trg_chistics))= ($17);
18234            lex->trg_chistics.ordering_clause_end= lip->get_cpp_ptr();
18235
18236            if (unlikely(!lex->make_sp_head(thd, $4, &sp_handler_trigger,
18237                                            DEFAULT_AGGREGATE)))
18238              MYSQL_YYABORT;
18239
18240            lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
18241          }
18242          sp_proc_stmt /* $19 */
18243          { /* $20 */
18244            LEX *lex= Lex;
18245
18246            lex->sql_command= SQLCOM_CREATE_TRIGGER;
18247            if (lex->sp_body_finalize_trigger(thd))
18248              MYSQL_YYABORT;
18249
18250            /*
18251              We have to do it after parsing trigger body, because some of
18252              sp_proc_stmt alternatives are not saving/restoring LEX, so
18253              lex->query_tables can be wiped out.
18254            */
18255            if (!lex->first_select_lex()->
18256                  add_table_to_list(thd, $10, (LEX_CSTRING*) 0,
18257                                    TL_OPTION_UPDATING, TL_READ_NO_INSERT,
18258                                    MDL_SHARED_NO_WRITE))
18259              MYSQL_YYABORT;
18260          }
18261        ;
18262
18263/**************************************************************************
18264
18265 CREATE FUNCTION | PROCEDURE statements parts.
18266
18267**************************************************************************/
18268
18269sf_return_type:
18270          {
18271            LEX *lex= Lex;
18272            lex->init_last_field(&lex->sphead->m_return_field_def,
18273                                 &empty_clex_str,
18274                                 thd->variables.collation_database);
18275          }
18276          sp_param_type
18277          {
18278            if (unlikely(Lex->sphead->fill_field_definition(thd,
18279                                                            Lex->last_field)))
18280              MYSQL_YYABORT;
18281          }
18282        ;
18283
18284sf_c_chistics_and_body_standalone:
18285          sp_c_chistics
18286          {
18287            LEX *lex= thd->lex;
18288            lex->sphead->set_c_chistics(lex->sp_chistics);
18289            lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
18290          }
18291          sp_tail_is
18292          sp_body
18293          {
18294            if (unlikely(Lex->sp_body_finalize_function(thd)))
18295              MYSQL_YYABORT;
18296          }
18297        ;
18298
18299sp_tail_standalone:
18300          sp_name
18301          {
18302            if (unlikely(!Lex->make_sp_head_no_recursive(thd, $1,
18303                                                         &sp_handler_procedure,
18304                                                         DEFAULT_AGGREGATE)))
18305              MYSQL_YYABORT;
18306          }
18307          opt_sp_parenthesized_pdparam_list
18308          sp_c_chistics
18309          {
18310            Lex->sphead->set_c_chistics(Lex->sp_chistics);
18311            Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
18312          }
18313          sp_tail_is
18314          sp_body
18315          opt_sp_name
18316          {
18317            if (unlikely(Lex->sp_body_finalize_procedure_standalone(thd, $8)))
18318              MYSQL_YYABORT;
18319          }
18320        ;
18321
18322
18323opt_package_routine_end_name:
18324          /* Empty */ { $$= null_clex_str; }
18325        | ident       { $$= $1; }
18326        ;
18327
18328sp_tail_is:
18329          IS
18330        | AS
18331        ;
18332
18333/*************************************************************************/
18334
18335xa:
18336          XA_SYM begin_or_start xid opt_join_or_resume
18337          {
18338            Lex->sql_command = SQLCOM_XA_START;
18339          }
18340        | XA_SYM END xid opt_suspend
18341          {
18342            Lex->sql_command = SQLCOM_XA_END;
18343          }
18344        | XA_SYM PREPARE_SYM xid
18345          {
18346            Lex->sql_command = SQLCOM_XA_PREPARE;
18347          }
18348        | XA_SYM COMMIT_SYM xid opt_one_phase
18349          {
18350            Lex->sql_command = SQLCOM_XA_COMMIT;
18351          }
18352        | XA_SYM ROLLBACK_SYM xid
18353          {
18354            Lex->sql_command = SQLCOM_XA_ROLLBACK;
18355          }
18356        | XA_SYM RECOVER_SYM opt_format_xid
18357          {
18358            Lex->sql_command = SQLCOM_XA_RECOVER;
18359            Lex->verbose= $3;
18360          }
18361        ;
18362
18363opt_format_xid:
18364         /* empty */ { $$= false; }
18365        | FORMAT_SYM '=' ident_or_text
18366          {
18367            if (lex_string_eq(&$3, STRING_WITH_LEN("SQL")))
18368              $$= true;
18369            else if (lex_string_eq(&$3, STRING_WITH_LEN("RAW")))
18370              $$= false;
18371            else
18372            {
18373              my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0),
18374                               "XA RECOVER", $3.str));
18375              $$= false;
18376            }
18377          }
18378        ;
18379
18380xid:
18381          text_string
18382          {
18383            MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE);
18384            if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID)))))
18385              MYSQL_YYABORT;
18386            Lex->xid->set(1L, $1->ptr(), $1->length(), 0, 0);
18387          }
18388          | text_string ',' text_string
18389          {
18390            MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
18391            if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID)))))
18392              MYSQL_YYABORT;
18393            Lex->xid->set(1L, $1->ptr(), $1->length(), $3->ptr(), $3->length());
18394          }
18395          | text_string ',' text_string ',' ulong_num
18396          {
18397            MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
18398            if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID)))))
18399              MYSQL_YYABORT;
18400            Lex->xid->set($5, $1->ptr(), $1->length(), $3->ptr(), $3->length());
18401          }
18402        ;
18403
18404begin_or_start:
18405          BEGIN_MARIADB_SYM {}
18406        | BEGIN_ORACLE_SYM {}
18407        | START_SYM {}
18408        ;
18409
18410opt_join_or_resume:
18411          /* nothing */ { Lex->xa_opt=XA_NONE;        }
18412        | JOIN_SYM      { Lex->xa_opt=XA_JOIN;        }
18413        | RESUME_SYM    { Lex->xa_opt=XA_RESUME;      }
18414        ;
18415
18416opt_one_phase:
18417          /* nothing */     { Lex->xa_opt=XA_NONE;        }
18418        | ONE_SYM PHASE_SYM { Lex->xa_opt=XA_ONE_PHASE;   }
18419        ;
18420
18421opt_suspend:
18422          /* nothing */
18423          { Lex->xa_opt=XA_NONE;        }
18424        | SUSPEND_SYM
18425          { Lex->xa_opt=XA_SUSPEND;     }
18426          opt_migrate
18427        ;
18428
18429opt_migrate:
18430          /* nothing */       {}
18431        | FOR_SYM MIGRATE_SYM { Lex->xa_opt=XA_FOR_MIGRATE; }
18432        ;
18433
18434install:
18435          INSTALL_SYM PLUGIN_SYM opt_if_not_exists ident SONAME_SYM TEXT_STRING_sys
18436          {
18437            if (Lex->stmt_install_plugin($3, $4, $6))
18438              MYSQL_YYABORT;
18439          }
18440        | INSTALL_SYM SONAME_SYM TEXT_STRING_sys
18441          {
18442            Lex->stmt_install_plugin($3);
18443          }
18444        ;
18445
18446uninstall:
18447          UNINSTALL_SYM PLUGIN_SYM opt_if_exists ident
18448          {
18449            if (Lex->stmt_uninstall_plugin_by_name($3, $4))
18450              MYSQL_YYABORT;
18451          }
18452        | UNINSTALL_SYM SONAME_SYM opt_if_exists TEXT_STRING_sys
18453          {
18454            if (Lex->stmt_uninstall_plugin_by_soname($3, $4))
18455              MYSQL_YYABORT;
18456          }
18457        ;
18458
18459/* Avoid compiler warning from sql_yacc.cc where yyerrlab1 is not used */
18460keep_gcc_happy:
18461          IMPOSSIBLE_ACTION
18462          {
18463            YYERROR;
18464          }
18465        ;
18466
18467/**
18468  @} (end of group Parser)
18469*/
18470