~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_yacc.yy

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/* sql_yacc.yy */
 
17
 
 
18
/**
 
19
  @defgroup Parser Parser
 
20
  @{
 
21
*/
 
22
 
 
23
%{
 
24
/* thd is passed as an argument to yyparse(), and subsequently to yylex().
 
25
** The type will be void*, so it must be  cast to (THD*) when used.
 
26
** Use the YYTHD macro for this.
 
27
*/
 
28
#define YYPARSE_PARAM yythd
 
29
#define YYLEX_PARAM yythd
 
30
#define YYTHD ((THD *)yythd)
 
31
 
 
32
#define MYSQL_YACC
 
33
#define YYINITDEPTH 100
 
34
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
 
35
#define Lex (YYTHD->lex)
 
36
#define Select Lex->current_select
 
37
#include "mysql_priv.h"
 
38
#include "slave.h"
 
39
#include "lex_symbol.h"
 
40
#include "item_create.h"
 
41
#include <myisam.h>
 
42
 
 
43
int yylex(void *yylval, void *yythd);
 
44
 
 
45
#define yyoverflow(A,B,C,D,E,F)               \
 
46
  {                                           \
 
47
    ulong val= *(F);                          \
 
48
    if (my_yyoverflow((B), (D), &val))        \
 
49
    {                                         \
 
50
      yyerror((char*) (A));                   \
 
51
      return 2;                               \
 
52
    }                                         \
 
53
    else                                      \
 
54
    {                                         \
 
55
      *(F)= (YYSIZE_T)val;                    \
 
56
    }                                         \
 
57
  }
 
58
 
 
59
#define MYSQL_YYABORT                         \
 
60
  do                                          \
 
61
  {                                           \
 
62
    LEX::cleanup_lex_after_parse_error(YYTHD);\
 
63
    YYABORT;                                  \
 
64
  } while (0)
 
65
 
 
66
#define MYSQL_YYABORT_UNLESS(A)         \
 
67
  if (!(A))                             \
 
68
  {                                     \
 
69
    my_parse_error(ER(ER_SYNTAX_ERROR));\
 
70
    MYSQL_YYABORT;                      \
 
71
  }
 
72
 
 
73
/*
 
74
  Work around for broken code generated by bison 1.875.
 
75
 
 
76
  The code generated by bison 1.875a and later, bison 2.1 and bison 2.2 is ok.
 
77
  With bison 1.875 however, the generated code contains:
 
78
<pre>
 
79
  yyerrlab1:
 
80
  #if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
 
81
    __attribute__ ((__unused__))
 
82
  #endif
 
83
</pre>
 
84
  This usage of __attribute__ is illegal, so we remove it.
 
85
  See the following references for details:
 
86
  http://lists.gnu.org/archive/html/bug-bison/2004-02/msg00014.html
 
87
  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14273
 
88
*/
 
89
 
 
90
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
 
91
#undef __attribute__
 
92
#define __attribute__(X)
 
93
#endif
 
94
 
 
95
 
 
96
#ifndef DBUG_OFF
 
97
#define YYDEBUG 1
 
98
#else
 
99
#define YYDEBUG 0
 
100
#endif
 
101
 
 
102
/**
 
103
  @brief Push an error message into MySQL error stack with line
 
104
  and position information.
 
105
 
 
106
  This function provides semantic action implementers with a way
 
107
  to push the famous "You have a syntax error near..." error
 
108
  message into the error stack, which is normally produced only if
 
109
  a parse error is discovered internally by the Bison generated
 
110
  parser.
 
111
*/
 
112
 
 
113
void my_parse_error(const char *s)
 
114
{
 
115
  THD *thd= current_thd;
 
116
  Lex_input_stream *lip= thd->m_lip;
 
117
 
 
118
  const char *yytext= lip->get_tok_start();
 
119
  /* Push an error into the error stack */
 
120
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
 
121
                  (yytext ? yytext : ""),
 
122
                  lip->yylineno);
 
123
}
 
124
 
 
125
/**
 
126
  @brief Bison callback to report a syntax/OOM error
 
127
 
 
128
  This function is invoked by the bison-generated parser
 
129
  when a syntax error, a parse error or an out-of-memory
 
130
  condition occurs. This function is not invoked when the
 
131
  parser is requested to abort by semantic action code
 
132
  by means of YYABORT or YYACCEPT macros. This is why these
 
133
  macros should not be used (use MYSQL_YYABORT/MYSQL_YYACCEPT
 
134
  instead).
 
135
 
 
136
  The parser will abort immediately after invoking this callback.
 
137
 
 
138
  This function is not for use in semantic actions and is internal to
 
139
  the parser, as it performs some pre-return cleanup. 
 
140
  In semantic actions, please use my_parse_error or my_error to
 
141
  push an error into the error stack and MYSQL_YYABORT
 
142
  to abort from the parser.
 
143
*/
 
144
 
 
145
void MYSQLerror(const char *s)
 
146
{
 
147
  THD *thd= current_thd;
 
148
 
 
149
  /*
 
150
    Restore the original LEX if it was replaced when parsing
 
151
    a stored procedure. We must ensure that a parsing error
 
152
    does not leave any side effects in the THD.
 
153
  */
 
154
  LEX::cleanup_lex_after_parse_error(thd);
 
155
 
 
156
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
 
157
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
 
158
    s= ER(ER_SYNTAX_ERROR);
 
159
  my_parse_error(s);
 
160
}
 
161
 
 
162
 
 
163
#ifndef DBUG_OFF
 
164
void turn_parser_debug_on()
 
165
{
 
166
  /*
 
167
     MYSQLdebug is in sql/sql_yacc.cc, in bison generated code.
 
168
     Turning this option on is **VERY** verbose, and should be
 
169
     used when investigating a syntax error problem only.
 
170
 
 
171
     The syntax to run with bison traces is as follows :
 
172
     - Starting a server manually :
 
173
       mysqld --debug="d,parser_debug" ...
 
174
     - Running a test :
 
175
       mysql-test-run.pl --mysqld="--debug=d,parser_debug" ...
 
176
 
 
177
     The result will be in the process stderr (var/log/master.err)
 
178
   */
 
179
 
 
180
  extern int yydebug;
 
181
  yydebug= 1;
 
182
}
 
183
#endif
 
184
 
 
185
/**
 
186
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
 
187
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
 
188
  This function returns the proper item for the SQL expression
 
189
  <code>left [NOT] IN ( expr )</code>
 
190
  @param thd the current thread
 
191
  @param left the in predicand
 
192
  @param equal true for IN predicates, false for NOT IN predicates
 
193
  @param expr first and only expression of the in value list
 
194
  @return an expression representing the IN predicate.
 
195
*/
 
196
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
 
197
                                       Item *expr)
 
198
{
 
199
  /*
 
200
    Relevant references for this issue:
 
201
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
 
202
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
 
203
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
 
204
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
 
205
    - SQL:2003 Feature F561, "Full value expressions".
 
206
 
 
207
    The exception in SQL:2003 Note 184 means:
 
208
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
 
209
    should be re-interpreted as an Item_in_subselect, which corresponds
 
210
    to a <table subquery> when used inside an <in predicate>.
 
211
 
 
212
    Our reading of Note 184 is reccursive, so that all:
 
213
    - IN (( <subquery> ))
 
214
    - IN ((( <subquery> )))
 
215
    - IN '('^N <subquery> ')'^N
 
216
    - etc
 
217
    should be interpreted as a <table subquery>, no matter how deep in the
 
218
    expression the <subquery> is.
 
219
  */
 
220
 
 
221
  Item *result;
 
222
 
 
223
  DBUG_ENTER("handle_sql2003_note184_exception");
 
224
 
 
225
  if (expr->type() == Item::SUBSELECT_ITEM)
 
226
  {
 
227
    Item_subselect *expr2 = (Item_subselect*) expr;
 
228
 
 
229
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
 
230
    {
 
231
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
232
      st_select_lex *subselect;
 
233
 
 
234
      /*
 
235
        Implement the mandated change, by altering the semantic tree:
 
236
          left IN Item_singlerow_subselect(subselect)
 
237
        is modified to
 
238
          left IN (subselect)
 
239
        which is represented as
 
240
          Item_in_subselect(left, subselect)
 
241
      */
 
242
      subselect= expr3->invalidate_and_restore_select_lex();
 
243
      result= new (thd->mem_root) Item_in_subselect(left, subselect);
 
244
 
 
245
      if (! equal)
 
246
        result = negate_expression(thd, result);
 
247
 
 
248
      DBUG_RETURN(result);
 
249
    }
 
250
  }
 
251
 
 
252
  if (equal)
 
253
    result= new (thd->mem_root) Item_func_eq(left, expr);
 
254
  else
 
255
    result= new (thd->mem_root) Item_func_ne(left, expr);
 
256
 
 
257
  DBUG_RETURN(result);
 
258
}
 
259
 
 
260
/**
 
261
   @brief Creates a new SELECT_LEX for a UNION branch.
 
262
 
 
263
   Sets up and initializes a SELECT_LEX structure for a query once the parser
 
264
   discovers a UNION token. The current SELECT_LEX is pushed on the stack and
 
265
   the new SELECT_LEX becomes the current one..=
 
266
 
 
267
   @lex The parser state.
 
268
 
 
269
   @is_union_distinct True if the union preceding the new select statement
 
270
   uses UNION DISTINCT.
 
271
 
 
272
   @return <code>false</code> if successful, <code>true</code> if an error was
 
273
   reported. In the latter case parsing should stop.
 
274
 */
 
275
bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
276
{
 
277
  if (lex->result)
 
278
  {
 
279
    /* Only the last SELECT can have  INTO...... */
 
280
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
 
281
    return TRUE;
 
282
  }
 
283
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
284
  {
 
285
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
286
    return TRUE;
 
287
  }
 
288
  /* This counter shouldn't be incremented for UNION parts */
 
289
  lex->nest_level--;
 
290
  if (mysql_new_select(lex, 0))
 
291
    return TRUE;
 
292
  mysql_init_select(lex);
 
293
  lex->current_select->linkage=UNION_TYPE;
 
294
  if (is_union_distinct) /* UNION DISTINCT - remember position */
 
295
    lex->current_select->master_unit()->union_distinct=
 
296
      lex->current_select;
 
297
  return FALSE;
 
298
}
 
299
 
 
300
/**
 
301
   @brief Initializes a SELECT_LEX for a query within parentheses (aka
 
302
   braces).
 
303
 
 
304
   @return false if successful, true if an error was reported. In the latter
 
305
   case parsing should stop.
 
306
 */
 
307
bool setup_select_in_parentheses(LEX *lex) 
 
308
{
 
309
  SELECT_LEX * sel= lex->current_select;
 
310
  if (sel->set_braces(1))
 
311
  {
 
312
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
313
    return TRUE;
 
314
  }
 
315
  if (sel->linkage == UNION_TYPE &&
 
316
      !sel->master_unit()->first_select()->braces &&
 
317
      sel->master_unit()->first_select()->linkage ==
 
318
      UNION_TYPE)
 
319
  {
 
320
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
321
    return TRUE;
 
322
  }
 
323
  if (sel->linkage == UNION_TYPE &&
 
324
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
325
      sel->master_unit()->fake_select_lex)
 
326
  {
 
327
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
 
328
    return TRUE;
 
329
  }
 
330
  /* select in braces, can't contain global parameters */
 
331
  if (sel->master_unit()->fake_select_lex)
 
332
    sel->master_unit()->global_parameters=
 
333
      sel->master_unit()->fake_select_lex;
 
334
  return FALSE;
 
335
}
 
336
 
 
337
%}
 
338
%union {
 
339
  int  num;
 
340
  ulong ulong_num;
 
341
  ulonglong ulonglong_number;
 
342
  longlong longlong_number;
 
343
  LEX_STRING lex_str;
 
344
  LEX_STRING *lex_str_ptr;
 
345
  LEX_SYMBOL symbol;
 
346
  Table_ident *table;
 
347
  char *simple_string;
 
348
  Item *item;
 
349
  Item_num *item_num;
 
350
  List<Item> *item_list;
 
351
  List<String> *string_list;
 
352
  String *string;
 
353
  Key_part_spec *key_part;
 
354
  TABLE_LIST *table_list;
 
355
  udf_func *udf;
 
356
  LEX_USER *lex_user;
 
357
  struct sys_var_with_base variable;
 
358
  enum enum_var_type var_type;
 
359
  Key::Keytype key_type;
 
360
  enum ha_key_alg key_alg;
 
361
  handlerton *db_type;
 
362
  enum row_type row_type;
 
363
  enum column_format_type column_format_type;
 
364
  enum ha_rkey_function ha_rkey_mode;
 
365
  enum enum_tx_isolation tx_isolation;
 
366
  enum Cast_target cast_type;
 
367
  enum ha_choice choice;
 
368
  CHARSET_INFO *charset;
 
369
  thr_lock_type lock_type;
 
370
  struct st_table_lock_info table_lock_info;
 
371
  interval_type interval, interval_time_st;
 
372
  timestamp_type date_time_type;
 
373
  st_select_lex *select_lex;
 
374
  chooser_compare_func_creator boolfunc2creator;
 
375
  struct sp_cond_type *spcondtype;
 
376
  struct { int vars, conds, hndlrs, curs; } spblock;
 
377
  struct st_lex *lex;
 
378
  struct p_elem_val *p_elem_value;
 
379
  enum index_hint_type index_hint;
 
380
  enum enum_filetype filetype;
 
381
  enum ha_build_method build_method;
 
382
  enum Foreign_key::fk_option m_fk_option;
 
383
}
 
384
 
 
385
%{
 
386
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 
387
%}
 
388
 
 
389
%pure_parser                                    /* We have threads */
 
390
/*
 
391
  Currently there are 100 shift/reduce conflicts.
 
392
  We should not introduce new conflicts any more.
 
393
*/
 
394
%expect 100
 
395
 
 
396
/*
 
397
   Comments for TOKENS.
 
398
   For each token, please include in the same line a comment that contains
 
399
   the following tags:
 
400
   SQL-2003-R : Reserved keyword as per SQL-2003
 
401
   SQL-2003-N : Non Reserved keyword as per SQL-2003
 
402
   SQL-1999-R : Reserved keyword as per SQL-1999
 
403
   SQL-1999-N : Non Reserved keyword as per SQL-1999
 
404
   MYSQL      : MySQL extention (unspecified)
 
405
   MYSQL-FUNC : MySQL extention, function
 
406
   INTERNAL   : Not a real token, lex optimization
 
407
   OPERATOR   : SQL operator
 
408
   FUTURE-USE : Reserved for futur use
 
409
 
 
410
   This makes the code grep-able, and helps maintenance.
 
411
*/
 
412
 
 
413
%token  ABORT_SYM                     /* INTERNAL (used in lex) */
 
414
%token  ACCESSIBLE_SYM
 
415
%token  ACTION                        /* SQL-2003-N */
 
416
%token  ADD                           /* SQL-2003-R */
 
417
%token  ADDDATE_SYM                   /* MYSQL-FUNC */
 
418
%token  AFTER_SYM                     /* SQL-2003-N */
 
419
%token  AGGREGATE_SYM
 
420
%token  ALGORITHM_SYM
 
421
%token  ALL                           /* SQL-2003-R */
 
422
%token  ALTER                         /* SQL-2003-R */
 
423
%token  ANALYZE_SYM
 
424
%token  AND_AND_SYM                   /* OPERATOR */
 
425
%token  AND_SYM                       /* SQL-2003-R */
 
426
%token  ANY_SYM                       /* SQL-2003-R */
 
427
%token  AS                            /* SQL-2003-R */
 
428
%token  ASC                           /* SQL-2003-N */
 
429
%token  ASCII_SYM                     /* MYSQL-FUNC */
 
430
%token  ASENSITIVE_SYM                /* FUTURE-USE */
 
431
%token  AT_SYM                        /* SQL-2003-R */
 
432
%token  AUTHORS_SYM
 
433
%token  AUTOEXTEND_SIZE_SYM
 
434
%token  AUTO_INC
 
435
%token  AVG_ROW_LENGTH
 
436
%token  AVG_SYM                       /* SQL-2003-N */
 
437
%token  BEFORE_SYM                    /* SQL-2003-N */
 
438
%token  BEGIN_SYM                     /* SQL-2003-R */
 
439
%token  BETWEEN_SYM                   /* SQL-2003-R */
 
440
%token  BIGINT                        /* SQL-2003-R */
 
441
%token  BINARY                        /* SQL-2003-R */
 
442
%token  BINLOG_SYM
 
443
%token  BIN_NUM
 
444
%token  BIT_AND                       /* MYSQL-FUNC */
 
445
%token  BIT_OR                        /* MYSQL-FUNC */
 
446
%token  BIT_SYM                       /* MYSQL-FUNC */
 
447
%token  BIT_XOR                       /* MYSQL-FUNC */
 
448
%token  BLOB_SYM                      /* SQL-2003-R */
 
449
%token  BLOCK_SYM
 
450
%token  BOOLEAN_SYM                   /* SQL-2003-R */
 
451
%token  BOOL_SYM
 
452
%token  BOTH                          /* SQL-2003-R */
 
453
%token  BTREE_SYM
 
454
%token  BY                            /* SQL-2003-R */
 
455
%token  BYTE_SYM
 
456
%token  CACHE_SYM
 
457
%token  CALL_SYM                      /* SQL-2003-R */
 
458
%token  CASCADE                       /* SQL-2003-N */
 
459
%token  CASCADED                      /* SQL-2003-R */
 
460
%token  CASE_SYM                      /* SQL-2003-R */
 
461
%token  CAST_SYM                      /* SQL-2003-R */
 
462
%token  CHAIN_SYM                     /* SQL-2003-N */
 
463
%token  CHANGE
 
464
%token  CHANGED
 
465
%token  CHARSET
 
466
%token  CHAR_SYM                      /* SQL-2003-R */
 
467
%token  CHECKSUM_SYM
 
468
%token  CHECK_SYM                     /* SQL-2003-R */
 
469
%token  CIPHER_SYM
 
470
%token  CLIENT_SYM
 
471
%token  CLOSE_SYM                     /* SQL-2003-R */
 
472
%token  COALESCE                      /* SQL-2003-N */
 
473
%token  CODE_SYM
 
474
%token  COLLATE_SYM                   /* SQL-2003-R */
 
475
%token  COLLATION_SYM                 /* SQL-2003-N */
 
476
%token  COLUMNS
 
477
%token  COLUMN_SYM                    /* SQL-2003-R */
 
478
%token  COMMENT_SYM
 
479
%token  COMMITTED_SYM                 /* SQL-2003-N */
 
480
%token  COMMIT_SYM                    /* SQL-2003-R */
 
481
%token  COMPACT_SYM
 
482
%token  COMPLETION_SYM
 
483
%token  COMPRESSED_SYM
 
484
%token  CONCURRENT
 
485
%token  CONDITION_SYM                 /* SQL-2003-N */
 
486
%token  CONNECTION_SYM
 
487
%token  CONSISTENT_SYM
 
488
%token  CONSTRAINT                    /* SQL-2003-R */
 
489
%token  CONTAINS_SYM                  /* SQL-2003-N */
 
490
%token  CONTEXT_SYM
 
491
%token  CONTINUE_SYM                  /* SQL-2003-R */
 
492
%token  CONTRIBUTORS_SYM
 
493
%token  CONVERT_SYM                   /* SQL-2003-N */
 
494
%token  COUNT_SYM                     /* SQL-2003-N */
 
495
%token  CPU_SYM
 
496
%token  CREATE                        /* SQL-2003-R */
 
497
%token  CROSS                         /* SQL-2003-R */
 
498
%token  CUBE_SYM                      /* SQL-2003-R */
 
499
%token  CURDATE                       /* MYSQL-FUNC */
 
500
%token  CURRENT_USER                  /* SQL-2003-R */
 
501
%token  CURSOR_SYM                    /* SQL-2003-R */
 
502
%token  CURTIME                       /* MYSQL-FUNC */
 
503
%token  DATABASE
 
504
%token  DATABASES
 
505
%token  DATAFILE_SYM
 
506
%token  DATA_SYM                      /* SQL-2003-N */
 
507
%token  DATETIME
 
508
%token  DATE_ADD_INTERVAL             /* MYSQL-FUNC */
 
509
%token  DATE_SUB_INTERVAL             /* MYSQL-FUNC */
 
510
%token  DATE_SYM                      /* SQL-2003-R */
 
511
%token  DAY_HOUR_SYM
 
512
%token  DAY_MICROSECOND_SYM
 
513
%token  DAY_MINUTE_SYM
 
514
%token  DAY_SECOND_SYM
 
515
%token  DAY_SYM                       /* SQL-2003-R */
 
516
%token  DEALLOCATE_SYM                /* SQL-2003-R */
 
517
%token  DECIMAL_NUM
 
518
%token  DECIMAL_SYM                   /* SQL-2003-R */
 
519
%token  DECLARE_SYM                   /* SQL-2003-R */
 
520
%token  DEFAULT                       /* SQL-2003-R */
 
521
%token  DEFINER_SYM
 
522
%token  DELAYED_SYM
 
523
%token  DELAY_KEY_WRITE_SYM
 
524
%token  DELETE_SYM                    /* SQL-2003-R */
 
525
%token  DESC                          /* SQL-2003-N */
 
526
%token  DESCRIBE                      /* SQL-2003-R */
 
527
%token  DES_KEY_FILE
 
528
%token  DETERMINISTIC_SYM             /* SQL-2003-R */
 
529
%token  DIRECTORY_SYM
 
530
%token  DISABLE_SYM
 
531
%token  DISCARD
 
532
%token  DISK_SYM
 
533
%token  DISTINCT                      /* SQL-2003-R */
 
534
%token  DIV_SYM
 
535
%token  DOUBLE_SYM                    /* SQL-2003-R */
 
536
%token  DROP                          /* SQL-2003-R */
 
537
%token  DUMPFILE
 
538
%token  DUPLICATE_SYM
 
539
%token  DYNAMIC_SYM                   /* SQL-2003-R */
 
540
%token  EACH_SYM                      /* SQL-2003-R */
 
541
%token  ELSE                          /* SQL-2003-R */
 
542
%token  ELSEIF_SYM
 
543
%token  ENABLE_SYM
 
544
%token  ENCLOSED
 
545
%token  END                           /* SQL-2003-R */
 
546
%token  ENDS_SYM
 
547
%token  END_OF_INPUT                  /* INTERNAL */
 
548
%token  ENGINES_SYM
 
549
%token  ENGINE_SYM
 
550
%token  ENUM
 
551
%token  EQ                            /* OPERATOR */
 
552
%token  EQUAL_SYM                     /* OPERATOR */
 
553
%token  ERRORS
 
554
%token  ESCAPED
 
555
%token  ESCAPE_SYM                    /* SQL-2003-R */
 
556
%token  EVENTS_SYM
 
557
%token  EVERY_SYM                     /* SQL-2003-N */
 
558
%token  EXCLUSIVE_SYM
 
559
%token  EXISTS                        /* SQL-2003-R */
 
560
%token  EXIT_SYM
 
561
%token  EXTENDED_SYM
 
562
%token  EXTENT_SIZE_SYM
 
563
%token  EXTRACT_SYM                   /* SQL-2003-N */
 
564
%token  FALSE_SYM                     /* SQL-2003-R */
 
565
%token  FAST_SYM
 
566
%token  FAULTS_SYM
 
567
%token  FETCH_SYM                     /* SQL-2003-R */
 
568
%token  COLUMN_FORMAT_SYM
 
569
%token  FILE_SYM
 
570
%token  FIRST_SYM                     /* SQL-2003-N */
 
571
%token  FIXED_SYM
 
572
%token  FLOAT_NUM
 
573
%token  FLOAT_SYM                     /* SQL-2003-R */
 
574
%token  FLUSH_SYM
 
575
%token  FORCE_SYM
 
576
%token  FOREIGN                       /* SQL-2003-R */
 
577
%token  FOR_SYM                       /* SQL-2003-R */
 
578
%token  FOUND_SYM                     /* SQL-2003-R */
 
579
%token  FRAC_SECOND_SYM
 
580
%token  FROM
 
581
%token  FULL                          /* SQL-2003-R */
 
582
%token  FUNCTION_SYM                  /* SQL-2003-R */
 
583
%token  GE
 
584
%token  GET_FORMAT                    /* MYSQL-FUNC */
 
585
%token  GLOBAL_SYM                    /* SQL-2003-R */
 
586
%token  GROUP_SYM                     /* SQL-2003-R */
 
587
%token  GROUP_CONCAT_SYM
 
588
%token  GT_SYM                        /* OPERATOR */
 
589
%token  HANDLER_SYM
 
590
%token  HASH_SYM
 
591
%token  HAVING                        /* SQL-2003-R */
 
592
%token  HEX_NUM
 
593
%token  HIGH_PRIORITY
 
594
%token  HOST_SYM
 
595
%token  HOSTS_SYM
 
596
%token  HOUR_MICROSECOND_SYM
 
597
%token  HOUR_MINUTE_SYM
 
598
%token  HOUR_SECOND_SYM
 
599
%token  HOUR_SYM                      /* SQL-2003-R */
 
600
%token  IDENT
 
601
%token  IDENTIFIED_SYM
 
602
%token  IDENT_QUOTED
 
603
%token  IF
 
604
%token  IGNORE_SYM
 
605
%token  IMPORT
 
606
%token  INDEXES
 
607
%token  INDEX_SYM
 
608
%token  INFILE
 
609
%token  INITIAL_SIZE_SYM
 
610
%token  INNER_SYM                     /* SQL-2003-R */
 
611
%token  INOUT_SYM                     /* SQL-2003-R */
 
612
%token  INSENSITIVE_SYM               /* SQL-2003-R */
 
613
%token  INSERT                        /* SQL-2003-R */
 
614
%token  INSERT_METHOD
 
615
%token  INSTALL_SYM
 
616
%token  INTERVAL_SYM                  /* SQL-2003-R */
 
617
%token  INTO                          /* SQL-2003-R */
 
618
%token  INT_SYM                       /* SQL-2003-R */
 
619
%token  IN_SYM                        /* SQL-2003-R */
 
620
%token  IO_SYM
 
621
%token  IPC_SYM
 
622
%token  IS                            /* SQL-2003-R */
 
623
%token  ISOLATION                     /* SQL-2003-R */
 
624
%token  ISSUER_SYM
 
625
%token  ITERATE_SYM
 
626
%token  JOIN_SYM                      /* SQL-2003-R */
 
627
%token  KEYS
 
628
%token  KEY_BLOCK_SIZE
 
629
%token  KEY_SYM                       /* SQL-2003-N */
 
630
%token  KILL_SYM
 
631
%token  LAST_SYM                      /* SQL-2003-N */
 
632
%token  LE                            /* OPERATOR */
 
633
%token  LEADING                       /* SQL-2003-R */
 
634
%token  LEAVES
 
635
%token  LEFT                          /* SQL-2003-R */
 
636
%token  LEVEL_SYM
 
637
%token  LEX_HOSTNAME
 
638
%token  LIKE                          /* SQL-2003-R */
 
639
%token  LIMIT
 
640
%token  LINEAR_SYM
 
641
%token  LINES
 
642
%token  LINESTRING
 
643
%token  LIST_SYM
 
644
%token  LOAD
 
645
%token  LOCAL_SYM                     /* SQL-2003-R */
 
646
%token  LOCATOR_SYM                   /* SQL-2003-N */
 
647
%token  LOCKS_SYM
 
648
%token  LOCK_SYM
 
649
%token  LOGFILE_SYM
 
650
%token  LOGS_SYM
 
651
%token  LONGBLOB
 
652
%token  LONGTEXT
 
653
%token  LONG_NUM
 
654
%token  LONG_SYM
 
655
%token  LOOP_SYM
 
656
%token  LOW_PRIORITY
 
657
%token  LT                            /* OPERATOR */
 
658
%token  MASTER_CONNECT_RETRY_SYM
 
659
%token  MASTER_HOST_SYM
 
660
%token  MASTER_LOG_FILE_SYM
 
661
%token  MASTER_LOG_POS_SYM
 
662
%token  MASTER_PASSWORD_SYM
 
663
%token  MASTER_PORT_SYM
 
664
%token  MASTER_SERVER_ID_SYM
 
665
%token  MASTER_SYM
 
666
%token  MASTER_USER_SYM
 
667
%token  MASTER_HEARTBEAT_PERIOD_SYM
 
668
%token  MATCH                         /* SQL-2003-R */
 
669
%token  MAX_CONNECTIONS_PER_HOUR
 
670
%token  MAX_QUERIES_PER_HOUR
 
671
%token  MAX_ROWS
 
672
%token  MAX_SIZE_SYM
 
673
%token  MAX_SYM                       /* SQL-2003-N */
 
674
%token  MAX_UPDATES_PER_HOUR
 
675
%token  MAX_USER_CONNECTIONS_SYM
 
676
%token  MAX_VALUE_SYM                 /* SQL-2003-N */
 
677
%token  MEDIUMBLOB
 
678
%token  MEDIUMINT
 
679
%token  MEDIUMTEXT
 
680
%token  MEDIUM_SYM
 
681
%token  MEMORY_SYM
 
682
%token  MERGE_SYM                     /* SQL-2003-R */
 
683
%token  MICROSECOND_SYM               /* MYSQL-FUNC */
 
684
%token  MIGRATE_SYM
 
685
%token  MINUTE_MICROSECOND_SYM
 
686
%token  MINUTE_SECOND_SYM
 
687
%token  MINUTE_SYM                    /* SQL-2003-R */
 
688
%token  MIN_ROWS
 
689
%token  MIN_SYM                       /* SQL-2003-N */
 
690
%token  MODE_SYM
 
691
%token  MODIFIES_SYM                  /* SQL-2003-R */
 
692
%token  MODIFY_SYM
 
693
%token  MOD_SYM                       /* SQL-2003-N */
 
694
%token  MONTH_SYM                     /* SQL-2003-R */
 
695
%token  MUTEX_SYM
 
696
%token  NAMES_SYM                     /* SQL-2003-N */
 
697
%token  NAME_SYM                      /* SQL-2003-N */
 
698
%token  NATIONAL_SYM                  /* SQL-2003-R */
 
699
%token  NATURAL                       /* SQL-2003-R */
 
700
%token  NCHAR_STRING
 
701
%token  NCHAR_SYM                     /* SQL-2003-R */
 
702
%token  NE                            /* OPERATOR */
 
703
%token  NEG
 
704
%token  NEW_SYM                       /* SQL-2003-R */
 
705
%token  NEXT_SYM                      /* SQL-2003-N */
 
706
%token  NODEGROUP_SYM
 
707
%token  NONE_SYM                      /* SQL-2003-R */
 
708
%token  NOT_SYM                       /* SQL-2003-R */
 
709
%token  NOW_SYM
 
710
%token  NOWAIT_SYM
 
711
%token  NO_SYM                        /* SQL-2003-R */
 
712
%token  NO_WAIT_SYM
 
713
%token  NO_WRITE_TO_BINLOG
 
714
%token  NULL_SYM                      /* SQL-2003-R */
 
715
%token  NUM
 
716
%token  NUMERIC_SYM                   /* SQL-2003-R */
 
717
%token  NVARCHAR_SYM
 
718
%token  OFFLINE_SYM
 
719
%token  OFFSET_SYM
 
720
%token  OLD_PASSWORD
 
721
%token  ON                            /* SQL-2003-R */
 
722
%token  ONE_SHOT_SYM
 
723
%token  ONE_SYM
 
724
%token  ONLINE_SYM
 
725
%token  OPEN_SYM                      /* SQL-2003-R */
 
726
%token  OPTIMIZE
 
727
%token  OPTIONS_SYM
 
728
%token  OPTION                        /* SQL-2003-N */
 
729
%token  OPTIONALLY
 
730
%token  ORDER_SYM                     /* SQL-2003-R */
 
731
%token  OR_SYM                        /* SQL-2003-R */
 
732
%token  OUTER
 
733
%token  OUTFILE
 
734
%token  OUT_SYM                       /* SQL-2003-R */
 
735
%token  PACK_KEYS_SYM
 
736
%token  PAGE_SYM
 
737
%token  PAGE_CHECKSUM_SYM
 
738
%token  PARAM_MARKER
 
739
%token  PARTIAL                       /* SQL-2003-N */
 
740
%token  PASSWORD
 
741
%token  PHASE_SYM
 
742
%token  PLUGINS_SYM
 
743
%token  PLUGIN_SYM
 
744
%token  POINT_SYM
 
745
%token  POLYGON
 
746
%token  PORT_SYM
 
747
%token  POSITION_SYM                  /* SQL-2003-N */
 
748
%token  PRECISION                     /* SQL-2003-R */
 
749
%token  PREV_SYM
 
750
%token  PRIMARY_SYM                   /* SQL-2003-R */
 
751
%token  PROCESS
 
752
%token  PROCESSLIST_SYM
 
753
%token  PROFILE_SYM
 
754
%token  PROFILES_SYM
 
755
%token  PURGE
 
756
%token  QUARTER_SYM
 
757
%token  QUERY_SYM
 
758
%token  QUICK
 
759
%token  RANGE_SYM                     /* SQL-2003-R */
 
760
%token  READS_SYM                     /* SQL-2003-R */
 
761
%token  READ_ONLY_SYM
 
762
%token  READ_SYM                      /* SQL-2003-N */
 
763
%token  READ_WRITE_SYM
 
764
%token  REAL                          /* SQL-2003-R */
 
765
%token  REBUILD_SYM
 
766
%token  RECOVER_SYM
 
767
%token  REDOFILE_SYM
 
768
%token  REDO_BUFFER_SIZE_SYM
 
769
%token  REDUNDANT_SYM
 
770
%token  REFERENCES                    /* SQL-2003-R */
 
771
%token  RELAY_LOG_FILE_SYM
 
772
%token  RELAY_LOG_POS_SYM
 
773
%token  RELAY_THREAD
 
774
%token  RELEASE_SYM                   /* SQL-2003-R */
 
775
%token  RELOAD
 
776
%token  REMOVE_SYM
 
777
%token  RENAME
 
778
%token  REORGANIZE_SYM
 
779
%token  REPAIR
 
780
%token  REPEATABLE_SYM                /* SQL-2003-N */
 
781
%token  REPEAT_SYM                    /* MYSQL-FUNC */
 
782
%token  REPLACE                       /* MYSQL-FUNC */
 
783
%token  REPLICATION
 
784
%token  REQUIRE_SYM
 
785
%token  RESET_SYM
 
786
%token  RESOURCES
 
787
%token  RESTRICT
 
788
%token  RESUME_SYM
 
789
%token  RETURNS_SYM                   /* SQL-2003-R */
 
790
%token  RETURN_SYM                    /* SQL-2003-R */
 
791
%token  REVERSE_SYM
 
792
%token  REVOKE                        /* SQL-2003-R */
 
793
%token  RIGHT                         /* SQL-2003-R */
 
794
%token  ROLLBACK_SYM                  /* SQL-2003-R */
 
795
%token  ROLLUP_SYM                    /* SQL-2003-R */
 
796
%token  ROUTINE_SYM                   /* SQL-2003-N */
 
797
%token  ROWS_SYM                      /* SQL-2003-R */
 
798
%token  ROW_FORMAT_SYM
 
799
%token  ROW_SYM                       /* SQL-2003-R */
 
800
%token  SAVEPOINT_SYM                 /* SQL-2003-R */
 
801
%token  SECOND_MICROSECOND_SYM
 
802
%token  SECOND_SYM                    /* SQL-2003-R */
 
803
%token  SECURITY_SYM                  /* SQL-2003-N */
 
804
%token  SELECT_SYM                    /* SQL-2003-R */
 
805
%token  SENSITIVE_SYM                 /* FUTURE-USE */
 
806
%token  SEPARATOR_SYM
 
807
%token  SERIALIZABLE_SYM              /* SQL-2003-N */
 
808
%token  SERIAL_SYM
 
809
%token  SESSION_SYM                   /* SQL-2003-N */
 
810
%token  SERVER_SYM
 
811
%token  SERVER_OPTIONS
 
812
%token  SET                           /* SQL-2003-R */
 
813
%token  SET_VAR
 
814
%token  SHARE_SYM
 
815
%token  SHIFT_LEFT                    /* OPERATOR */
 
816
%token  SHIFT_RIGHT                   /* OPERATOR */
 
817
%token  SHOW
 
818
%token  SHUTDOWN
 
819
%token  SIGNED_SYM
 
820
%token  SIMPLE_SYM                    /* SQL-2003-N */
 
821
%token  SLAVE
 
822
%token  SMALLINT                      /* SQL-2003-R */
 
823
%token  SNAPSHOT_SYM
 
824
%token  SOCKET_SYM
 
825
%token  SONAME_SYM
 
826
%token  SOURCE_SYM
 
827
%token  SPECIFIC_SYM                  /* SQL-2003-R */
 
828
%token  SQLEXCEPTION_SYM              /* SQL-2003-R */
 
829
%token  SQLSTATE_SYM                  /* SQL-2003-R */
 
830
%token  SQLWARNING_SYM                /* SQL-2003-R */
 
831
%token  SQL_BIG_RESULT
 
832
%token  SQL_BUFFER_RESULT
 
833
%token  SQL_CALC_FOUND_ROWS
 
834
%token  SQL_SMALL_RESULT
 
835
%token  SQL_SYM                       /* SQL-2003-R */
 
836
%token  SQL_THREAD
 
837
%token  STARTING
 
838
%token  STARTS_SYM
 
839
%token  START_SYM                     /* SQL-2003-R */
 
840
%token  STATUS_SYM
 
841
%token  STDDEV_SAMP_SYM               /* SQL-2003-N */
 
842
%token  STD_SYM
 
843
%token  STOP_SYM
 
844
%token  STORAGE_SYM
 
845
%token  STRAIGHT_JOIN
 
846
%token  STRING_SYM
 
847
%token  SUBDATE_SYM
 
848
%token  SUBJECT_SYM
 
849
%token  SUBSTRING                     /* SQL-2003-N */
 
850
%token  SUM_SYM                       /* SQL-2003-N */
 
851
%token  SUPER_SYM
 
852
%token  SUSPEND_SYM
 
853
%token  SWAPS_SYM
 
854
%token  SWITCHES_SYM
 
855
%token  SYSDATE
 
856
%token  TABLES
 
857
%token  TABLESPACE
 
858
%token  TABLE_REF_PRIORITY
 
859
%token  TABLE_SYM                     /* SQL-2003-R */
 
860
%token  TABLE_CHECKSUM_SYM
 
861
%token  TEMPORARY                     /* SQL-2003-N */
 
862
%token  TEMPTABLE_SYM
 
863
%token  TERMINATED
 
864
%token  TEXT_STRING
 
865
%token  TEXT_SYM
 
866
%token  THAN_SYM
 
867
%token  THEN_SYM                      /* SQL-2003-R */
 
868
%token  TIMESTAMP                     /* SQL-2003-R */
 
869
%token  TIMESTAMP_ADD
 
870
%token  TIMESTAMP_DIFF
 
871
%token  TIME_SYM                      /* SQL-2003-R */
 
872
%token  TINYBLOB
 
873
%token  TINYINT
 
874
%token  TINYTEXT
 
875
%token  TO_SYM                        /* SQL-2003-R */
 
876
%token  TRAILING                      /* SQL-2003-R */
 
877
%token  TRANSACTION_SYM
 
878
%token  TRANSACTIONAL_SYM
 
879
%token  TRIM                          /* SQL-2003-N */
 
880
%token  TRUE_SYM                      /* SQL-2003-R */
 
881
%token  TRUNCATE_SYM
 
882
%token  TYPES_SYM
 
883
%token  TYPE_SYM                      /* SQL-2003-N */
 
884
%token  UDF_RETURNS_SYM
 
885
%token  ULONGLONG_NUM
 
886
%token  UNCOMMITTED_SYM               /* SQL-2003-N */
 
887
%token  UNDEFINED_SYM
 
888
%token  UNDERSCORE_CHARSET
 
889
%token  UNDOFILE_SYM
 
890
%token  UNDO_BUFFER_SIZE_SYM
 
891
%token  UNDO_SYM                      /* FUTURE-USE */
 
892
%token  UNICODE_SYM
 
893
%token  UNINSTALL_SYM
 
894
%token  UNION_SYM                     /* SQL-2003-R */
 
895
%token  UNIQUE_SYM
 
896
%token  UNKNOWN_SYM                   /* SQL-2003-R */
 
897
%token  UNLOCK_SYM
 
898
%token  UNSIGNED
 
899
%token  UNTIL_SYM
 
900
%token  UPDATE_SYM                    /* SQL-2003-R */
 
901
%token  UPGRADE_SYM
 
902
%token  USAGE                         /* SQL-2003-N */
 
903
%token  USER                          /* SQL-2003-R */
 
904
%token  USE_FRM
 
905
%token  USE_SYM
 
906
%token  USING                         /* SQL-2003-R */
 
907
%token  UTC_DATE_SYM
 
908
%token  UTC_TIMESTAMP_SYM
 
909
%token  UTC_TIME_SYM
 
910
%token  VALUES                        /* SQL-2003-R */
 
911
%token  VALUE_SYM                     /* SQL-2003-R */
 
912
%token  VARBINARY
 
913
%token  VARCHAR                       /* SQL-2003-R */
 
914
%token  VARIABLES
 
915
%token  VARIANCE_SYM
 
916
%token  VARYING                       /* SQL-2003-R */
 
917
%token  VAR_SAMP_SYM
 
918
%token  WAIT_SYM
 
919
%token  WARNINGS
 
920
%token  WEEK_SYM
 
921
%token  WEIGHT_STRING_SYM
 
922
%token  WHEN_SYM                      /* SQL-2003-R */
 
923
%token  WHERE                         /* SQL-2003-R */
 
924
%token  WITH                          /* SQL-2003-R */
 
925
%token  WITH_CUBE_SYM                 /* INTERNAL */
 
926
%token  WITH_ROLLUP_SYM               /* INTERNAL */
 
927
%token  WORK_SYM                      /* SQL-2003-N */
 
928
%token  WRAPPER_SYM
 
929
%token  WRITE_SYM                     /* SQL-2003-N */
 
930
%token  XML_SYM
 
931
%token  XOR
 
932
%token  YEAR_MONTH_SYM
 
933
%token  YEAR_SYM                      /* SQL-2003-R */
 
934
%token  ZEROFILL
 
935
 
 
936
%left   JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
 
937
/* A dummy token to force the priority of table_ref production in a join. */
 
938
%left   TABLE_REF_PRIORITY
 
939
%left   SET_VAR
 
940
%left   OR_SYM
 
941
%left   XOR
 
942
%left   AND_SYM AND_AND_SYM
 
943
%left   BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
 
944
%left   EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
 
945
%left   '|'
 
946
%left   '&'
 
947
%left   SHIFT_LEFT SHIFT_RIGHT
 
948
%left   '-' '+'
 
949
%left   '*' '/' '%' DIV_SYM MOD_SYM
 
950
%left   '^'
 
951
%left   NEG '~'
 
952
%right  NOT_SYM
 
953
%right  BINARY COLLATE_SYM
 
954
%left  INTERVAL_SYM
 
955
 
 
956
%type <lex_str>
 
957
        IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
 
958
        LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
 
959
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
 
960
        NCHAR_STRING opt_component key_cache_name
 
961
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
962
        opt_constraint constraint opt_ident
 
963
 
 
964
%type <lex_str_ptr>
 
965
        opt_table_alias
 
966
 
 
967
%type <table>
 
968
        table_ident references
 
969
 
 
970
%type <simple_string>
 
971
        remember_name remember_end opt_db
 
972
 
 
973
%type <string>
 
974
        text_string opt_gconcat_separator
 
975
 
 
976
%type <num>
 
977
        type int_type real_type order_dir
 
978
        if_exists opt_local opt_table_options table_options
 
979
        table_option opt_if_not_exists opt_no_write_to_binlog
 
980
        opt_temporary all_or_any opt_distinct
 
981
        opt_ignore_leaves union_option
 
982
        start_transaction_opts opt_chain opt_release
 
983
        union_opt select_derived_init option_type2
 
984
        opt_transactional_lock_timeout
 
985
        /* opt_lock_timeout_value */
 
986
 
 
987
%type <m_fk_option>
 
988
        delete_option
 
989
 
 
990
%type <ulong_num>
 
991
        ulong_num real_ulong_num
 
992
        ws_nweights
 
993
        ws_level_flag_desc ws_level_flag_reverse ws_level_flags
 
994
        opt_ws_levels ws_level_list ws_level_list_item ws_level_number
 
995
        ws_level_range ws_level_list_or_range  
 
996
 
 
997
%type <ulonglong_number>
 
998
        ulonglong_num
 
999
 
 
1000
%type <choice> choice
 
1001
 
 
1002
%type <lock_type>
 
1003
        replace_lock_option opt_low_priority insert_lock_option load_data_lock
 
1004
        transactional_lock_mode
 
1005
 
 
1006
%type <table_lock_info>
 
1007
        table_lock_info
 
1008
 
 
1009
%type <item>
 
1010
        literal text_literal insert_ident order_ident
 
1011
        simple_ident expr opt_expr opt_else sum_expr in_sum_expr
 
1012
        variable variable_aux bool_pri
 
1013
        predicate bit_expr
 
1014
        table_wild simple_expr udf_expr
 
1015
        expr_or_default set_expr_or_default
 
1016
        param_marker 
 
1017
        signed_literal now_or_signed_literal opt_escape
 
1018
        simple_ident_nospvar simple_ident_q
 
1019
        field_or_var limit_option
 
1020
        function_call_keyword
 
1021
        function_call_nonkeyword
 
1022
        function_call_generic
 
1023
        function_call_conflict
 
1024
 
 
1025
%type <item_num>
 
1026
        NUM_literal
 
1027
 
 
1028
%type <item_list>
 
1029
        expr_list opt_udf_expr_list udf_expr_list when_list
 
1030
 
 
1031
%type <var_type>
 
1032
        option_type opt_var_type opt_var_ident_type
 
1033
 
 
1034
%type <key_type>
 
1035
        key_type opt_unique constraint_key_type
 
1036
 
 
1037
%type <key_alg>
 
1038
        btree_or_rtree
 
1039
 
 
1040
%type <string_list>
 
1041
        using_list
 
1042
 
 
1043
%type <key_part>
 
1044
        key_part
 
1045
 
 
1046
%type <table_list>
 
1047
        join_table_list  join_table
 
1048
        table_factor table_ref esc_table_ref
 
1049
        select_derived derived_table_list
 
1050
        select_derived_union
 
1051
 
 
1052
%type <date_time_type> date_time_type;
 
1053
%type <interval> interval
 
1054
 
 
1055
%type <interval_time_st> interval_time_st
 
1056
 
 
1057
%type <interval_time_st> interval_time_stamp
 
1058
 
 
1059
%type <db_type> storage_engines known_storage_engines
 
1060
 
 
1061
%type <row_type> row_types
 
1062
 
 
1063
%type <column_format_type> column_format_types
 
1064
 
 
1065
%type <tx_isolation> isolation_types
 
1066
 
 
1067
%type <cast_type> cast_type
 
1068
 
 
1069
%type <symbol> keyword keyword_sp
 
1070
 
 
1071
%type <charset>
 
1072
        opt_collate
 
1073
        charset_name
 
1074
        charset_name_or_default
 
1075
        old_or_new_charset_name
 
1076
        old_or_new_charset_name_or_default
 
1077
        collation_name
 
1078
        collation_name_or_default
 
1079
        opt_load_data_charset
 
1080
        UNDERSCORE_CHARSET
 
1081
 
 
1082
%type <variable> internal_variable_name
 
1083
 
 
1084
%type <select_lex> subselect
 
1085
        get_select_lex query_specification 
 
1086
        query_expression_body
 
1087
 
 
1088
%type <boolfunc2creator> comp_op
 
1089
 
 
1090
%type <build_method> build_method
 
1091
 
 
1092
%type <NONE>
 
1093
        query verb_clause create change select drop insert replace insert2
 
1094
        insert_values update delete truncate rename
 
1095
        show describe load alter optimize keycache preload flush
 
1096
        reset purge begin commit rollback savepoint release
 
1097
        slave master_def master_defs master_file_def slave_until_opts
 
1098
        repair analyze check start checksum
 
1099
        field_list field_list_item field_spec kill column_def key_def
 
1100
        keycache_list assign_to_keycache preload_list preload_keys
 
1101
        select_item_list select_item values_list no_braces
 
1102
        opt_limit_clause delete_limit_clause fields opt_values values
 
1103
        opt_precision opt_ignore opt_column opt_restrict
 
1104
        set lock unlock string_list field_options field_option
 
1105
        field_opt_list opt_binary table_lock_list table_lock
 
1106
        ref_list opt_match_clause opt_on_update_delete use
 
1107
        opt_delete_options opt_delete_option varchar nchar nvarchar
 
1108
        opt_outer table_list table_name table_alias_ref_list table_alias_ref
 
1109
        opt_option opt_place
 
1110
        opt_attribute opt_attribute_list attribute
 
1111
        flush_options flush_option
 
1112
        equal optional_braces
 
1113
        opt_mi_check_type opt_to mi_check_types normal_join
 
1114
        table_to_table_list table_to_table opt_table_list opt_as
 
1115
        single_multi table_wild_list table_wild_one opt_wild
 
1116
        union_clause union_list
 
1117
        precision subselect_start charset
 
1118
        subselect_end select_var_list select_var_list_init opt_len
 
1119
        opt_extended_describe
 
1120
        statement
 
1121
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
 
1122
        binlog_base64_event
 
1123
        init_key_options key_options key_opts key_opt key_using_alg
 
1124
END_OF_INPUT
 
1125
 
 
1126
%type <index_hint> index_hint_type
 
1127
%type <num> index_hint_clause
 
1128
%type <filetype> data_or_xml
 
1129
 
 
1130
%type <NONE>
 
1131
        '-' '+' '*' '/' '%' '(' ')'
 
1132
        ',' '!' '{' '}' '&' '|' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
 
1133
        THEN_SYM WHEN_SYM DIV_SYM MOD_SYM AND_AND_SYM DELETE_SYM
 
1134
%%
 
1135
 
 
1136
/*
 
1137
  Indentation of grammar rules:
 
1138
 
 
1139
rule: <-- starts at col 1
 
1140
          rule1a rule1b rule1c <-- starts at col 11
 
1141
          { <-- starts at col 11
 
1142
            code <-- starts at col 13, indentation is 2 spaces
 
1143
          }
 
1144
        | rule2a rule2b
 
1145
          {
 
1146
            code
 
1147
          }
 
1148
        ; <-- on a line by itself, starts at col 9
 
1149
 
 
1150
  Also, please do not use any <TAB>, but spaces.
 
1151
  Having a uniform indentation in this file helps
 
1152
  code reviews, patches, merges, and make maintenance easier.
 
1153
  Tip: grep [[:cntrl:]] sql_yacc.yy
 
1154
  Thanks.
 
1155
*/
 
1156
 
 
1157
query:
 
1158
          END_OF_INPUT
 
1159
          {
 
1160
            THD *thd= YYTHD;
 
1161
            if (!thd->bootstrap &&
 
1162
              (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
 
1163
            {
 
1164
              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
 
1165
              MYSQL_YYABORT;
 
1166
            }
 
1167
            else
 
1168
            {
 
1169
              thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
 
1170
            }
 
1171
          }
 
1172
        | verb_clause END_OF_INPUT {}
 
1173
        ;
 
1174
 
 
1175
verb_clause:
 
1176
          statement
 
1177
        | begin
 
1178
        ;
 
1179
 
 
1180
/* Verb clauses, except begin */
 
1181
statement:
 
1182
          alter
 
1183
        | analyze
 
1184
        | binlog_base64_event
 
1185
        | change
 
1186
        | check
 
1187
        | checksum
 
1188
        | commit
 
1189
        | create
 
1190
        | delete
 
1191
        | describe
 
1192
        | drop
 
1193
        | flush
 
1194
        | insert
 
1195
        | kill
 
1196
        | load
 
1197
        | lock
 
1198
        | optimize
 
1199
        | keycache
 
1200
        | preload
 
1201
        | purge
 
1202
        | release
 
1203
        | rename
 
1204
        | repair
 
1205
        | replace
 
1206
        | reset
 
1207
        | rollback
 
1208
        | savepoint
 
1209
        | select
 
1210
        | set
 
1211
        | show
 
1212
        | slave
 
1213
        | start
 
1214
        | truncate
 
1215
        | unlock
 
1216
        | update
 
1217
        | use
 
1218
        ;
 
1219
 
 
1220
 
 
1221
/* change master */
 
1222
 
 
1223
change:
 
1224
          CHANGE MASTER_SYM TO_SYM
 
1225
          {
 
1226
            LEX *lex = Lex;
 
1227
            lex->sql_command = SQLCOM_CHANGE_MASTER;
 
1228
            bzero((char*) &lex->mi, sizeof(lex->mi));
 
1229
          }
 
1230
          master_defs
 
1231
          {}
 
1232
        ;
 
1233
 
 
1234
master_defs:
 
1235
          master_def
 
1236
        | master_defs ',' master_def
 
1237
        ;
 
1238
 
 
1239
master_def:
 
1240
          MASTER_HOST_SYM EQ TEXT_STRING_sys
 
1241
          {
 
1242
            Lex->mi.host = $3.str;
 
1243
          }
 
1244
        | MASTER_USER_SYM EQ TEXT_STRING_sys
 
1245
          {
 
1246
            Lex->mi.user = $3.str;
 
1247
          }
 
1248
        | MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
 
1249
          {
 
1250
            Lex->mi.password = $3.str;
 
1251
          }
 
1252
        | MASTER_PORT_SYM EQ ulong_num
 
1253
          {
 
1254
            Lex->mi.port = $3;
 
1255
          }
 
1256
        | MASTER_CONNECT_RETRY_SYM EQ ulong_num
 
1257
          {
 
1258
            Lex->mi.connect_retry = $3;
 
1259
          }
 
1260
        | MASTER_HEARTBEAT_PERIOD_SYM EQ NUM_literal
 
1261
          {
 
1262
            Lex->mi.heartbeat_period= (float) $3->val_real();
 
1263
            if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD ||
 
1264
                Lex->mi.heartbeat_period < 0.0)
 
1265
            {
 
1266
              char buf[sizeof(SLAVE_MAX_HEARTBEAT_PERIOD*4)];
 
1267
              my_sprintf(buf, (buf, "%d seconds", SLAVE_MAX_HEARTBEAT_PERIOD));
 
1268
              my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
 
1269
                       MYF(0),
 
1270
                       " is negative or exceeds the maximum ",
 
1271
                       buf); 
 
1272
              MYSQL_YYABORT;
 
1273
            }
 
1274
            if (Lex->mi.heartbeat_period > slave_net_timeout)
 
1275
            {
 
1276
              push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1277
                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
 
1278
                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
 
1279
                                  " exceeds the value of `slave_net_timeout' sec.",
 
1280
                                  " A sensible value for the period should be"
 
1281
                                  " less than the timeout.");
 
1282
            }
 
1283
            if (Lex->mi.heartbeat_period < 0.001)
 
1284
            {
 
1285
              if (Lex->mi.heartbeat_period != 0.0)
 
1286
              {
 
1287
                push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1288
                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
 
1289
                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
 
1290
                                    " is less than 1 msec.",
 
1291
                                    " The period is reset to zero which means"
 
1292
                                    " no heartbeats will be sending");
 
1293
                Lex->mi.heartbeat_period= 0.0;
 
1294
              }
 
1295
              Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_DISABLE;
 
1296
            }
 
1297
            Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_ENABLE;
 
1298
          }
 
1299
        |
 
1300
        master_file_def
 
1301
        ;
 
1302
 
 
1303
master_file_def:
 
1304
          MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
 
1305
          {
 
1306
            Lex->mi.log_file_name = $3.str;
 
1307
          }
 
1308
        | MASTER_LOG_POS_SYM EQ ulonglong_num
 
1309
          {
 
1310
            Lex->mi.pos = $3;
 
1311
            /* 
 
1312
               If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
 
1313
               instead of causing subsequent errors. 
 
1314
               We need to do it in this file, because only there we know that 
 
1315
               MASTER_LOG_POS has been explicitely specified. On the contrary
 
1316
               in change_master() (sql_repl.cc) we cannot distinguish between 0
 
1317
               (MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
 
1318
               whereas we want to distinguish (specified 0 means "read the binlog
 
1319
               from 0" (4 in fact), unspecified means "don't change the position
 
1320
               (keep the preceding value)").
 
1321
            */
 
1322
            Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
 
1323
          }
 
1324
        | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
 
1325
          {
 
1326
            Lex->mi.relay_log_name = $3.str;
 
1327
          }
 
1328
        | RELAY_LOG_POS_SYM EQ ulong_num
 
1329
          {
 
1330
            Lex->mi.relay_log_pos = $3;
 
1331
            /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
 
1332
            Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
 
1333
          }
 
1334
        ;
 
1335
 
 
1336
/* create a table */
 
1337
 
 
1338
create:
 
1339
          CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
 
1340
          {
 
1341
            THD *thd= YYTHD;
 
1342
            LEX *lex= thd->lex;
 
1343
            lex->sql_command= SQLCOM_CREATE_TABLE;
 
1344
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
1345
                                                   TL_OPTION_UPDATING,
 
1346
                                                   TL_WRITE))
 
1347
              MYSQL_YYABORT;
 
1348
            lex->alter_info.reset();
 
1349
            lex->col_list.empty();
 
1350
            lex->change=NullS;
 
1351
            bzero((char*) &lex->create_info,sizeof(lex->create_info));
 
1352
            lex->create_info.options=$2 | $4;
 
1353
            lex->create_info.db_type= ha_default_handlerton(thd);
 
1354
            lex->create_info.default_table_charset= NULL;
 
1355
            lex->name.str= 0;
 
1356
            lex->name.length= 0;
 
1357
          }
 
1358
          create2
 
1359
          {
 
1360
            LEX *lex= YYTHD->lex;
 
1361
            lex->current_select= &lex->select_lex; 
 
1362
            if (!lex->create_info.db_type)
 
1363
            {
 
1364
              lex->create_info.db_type= ha_default_handlerton(YYTHD);
 
1365
              push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
 
1366
                                  ER_WARN_USING_OTHER_HANDLER,
 
1367
                                  ER(ER_WARN_USING_OTHER_HANDLER),
 
1368
                                  ha_resolve_storage_engine_name(lex->create_info.db_type),
 
1369
                                  $5->table.str);
 
1370
            }
 
1371
          }
 
1372
        | CREATE build_method opt_unique INDEX_SYM ident key_alg 
 
1373
          ON table_ident
 
1374
          {
 
1375
            LEX *lex=Lex;
 
1376
            lex->sql_command= SQLCOM_CREATE_INDEX;
 
1377
            if (!lex->current_select->add_table_to_list(lex->thd, $8,
 
1378
                                                        NULL,
 
1379
                                                        TL_OPTION_UPDATING))
 
1380
              MYSQL_YYABORT;
 
1381
            lex->alter_info.reset();
 
1382
            lex->alter_info.flags= ALTER_ADD_INDEX;
 
1383
            lex->alter_info.build_method= $2;
 
1384
            lex->col_list.empty();
 
1385
            lex->change=NullS;
 
1386
          }
 
1387
          '(' key_list ')' key_options
 
1388
          {
 
1389
            LEX *lex=Lex;
 
1390
            Key *key;
 
1391
            key= new Key($3, $5, &lex->key_create_info, 0,
 
1392
                         lex->col_list);
 
1393
            lex->alter_info.key_list.push_back(key);
 
1394
            lex->col_list.empty();
 
1395
          }
 
1396
        | CREATE DATABASE opt_if_not_exists ident
 
1397
          {
 
1398
            Lex->create_info.default_table_charset= NULL;
 
1399
            Lex->create_info.used_fields= 0;
 
1400
          }
 
1401
          opt_create_database_options
 
1402
          {
 
1403
            LEX *lex=Lex;
 
1404
            lex->sql_command=SQLCOM_CREATE_DB;
 
1405
            lex->name= $4;
 
1406
            lex->create_info.options=$3;
 
1407
          }
 
1408
        ;
 
1409
 
 
1410
 
 
1411
/*
 
1412
  End tablespace part
 
1413
*/
 
1414
 
 
1415
create2:
 
1416
          '(' create2a {}
 
1417
        | opt_create_table_options
 
1418
          create3 {}
 
1419
        | LIKE table_ident
 
1420
          {
 
1421
            THD *thd= YYTHD;
 
1422
            LEX *lex= thd->lex;
 
1423
 
 
1424
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1425
            if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
 
1426
              MYSQL_YYABORT;
 
1427
          }
 
1428
        | '(' LIKE table_ident ')'
 
1429
          {
 
1430
            THD *thd= YYTHD;
 
1431
            LEX *lex= thd->lex;
 
1432
 
 
1433
            lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
 
1434
            if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
 
1435
              MYSQL_YYABORT;
 
1436
          }
 
1437
        ;
 
1438
 
 
1439
create2a:
 
1440
          field_list ')' opt_create_table_options
 
1441
          create3 {}
 
1442
        |  create_select ')'
 
1443
           { Select->set_braces(1);}
 
1444
           union_opt {}
 
1445
        ;
 
1446
 
 
1447
create3:
 
1448
          /* empty */ {}
 
1449
        | opt_duplicate opt_as create_select
 
1450
          { Select->set_braces(0);}
 
1451
          union_clause {}
 
1452
        | opt_duplicate opt_as '(' create_select ')'
 
1453
          { Select->set_braces(1);}
 
1454
          union_opt {}
 
1455
        ;
 
1456
 
 
1457
create_select:
 
1458
          SELECT_SYM
 
1459
          {
 
1460
            LEX *lex=Lex;
 
1461
            lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
 
1462
            if (lex->sql_command == SQLCOM_INSERT)
 
1463
              lex->sql_command= SQLCOM_INSERT_SELECT;
 
1464
            else if (lex->sql_command == SQLCOM_REPLACE)
 
1465
              lex->sql_command= SQLCOM_REPLACE_SELECT;
 
1466
            /*
 
1467
              The following work only with the local list, the global list
 
1468
              is created correctly in this case
 
1469
            */
 
1470
            lex->current_select->table_list.save_and_clear(&lex->save_list);
 
1471
            mysql_init_select(lex);
 
1472
            lex->current_select->parsing_place= SELECT_LIST;
 
1473
          }
 
1474
          select_options select_item_list
 
1475
          {
 
1476
            Select->parsing_place= NO_MATTER;
 
1477
          }
 
1478
          opt_select_from
 
1479
          {
 
1480
            /*
 
1481
              The following work only with the local list, the global list
 
1482
              is created correctly in this case
 
1483
            */
 
1484
            Lex->current_select->table_list.push_front(&Lex->save_list);
 
1485
          }
 
1486
        ;
 
1487
 
 
1488
opt_as:
 
1489
          /* empty */ {}
 
1490
        | AS {}
 
1491
        ;
 
1492
 
 
1493
opt_create_database_options:
 
1494
          /* empty */ {}
 
1495
        | create_database_options {}
 
1496
        ;
 
1497
 
 
1498
create_database_options:
 
1499
          create_database_option {}
 
1500
        | create_database_options create_database_option {}
 
1501
        ;
 
1502
 
 
1503
create_database_option:
 
1504
          default_collation {}
 
1505
        | default_charset {}
 
1506
        ;
 
1507
 
 
1508
opt_table_options:
 
1509
          /* empty */ { $$= 0; }
 
1510
        | table_options  { $$= $1;}
 
1511
        ;
 
1512
 
 
1513
table_options:
 
1514
          table_option { $$=$1; }
 
1515
        | table_option table_options { $$= $1 | $2; }
 
1516
        ;
 
1517
 
 
1518
table_option:
 
1519
          TEMPORARY { $$=HA_LEX_CREATE_TMP_TABLE; }
 
1520
        ;
 
1521
 
 
1522
opt_if_not_exists:
 
1523
          /* empty */ { $$= 0; }
 
1524
        | IF not EXISTS { $$=HA_LEX_CREATE_IF_NOT_EXISTS; }
 
1525
        ;
 
1526
 
 
1527
opt_create_table_options:
 
1528
          /* empty */
 
1529
        | create_table_options
 
1530
        ;
 
1531
 
 
1532
create_table_options_space_separated:
 
1533
          create_table_option
 
1534
        | create_table_option create_table_options_space_separated
 
1535
        ;
 
1536
 
 
1537
create_table_options:
 
1538
          create_table_option
 
1539
        | create_table_option     create_table_options
 
1540
        | create_table_option ',' create_table_options
 
1541
        ;
 
1542
 
 
1543
create_table_option:
 
1544
          ENGINE_SYM opt_equal storage_engines
 
1545
          {
 
1546
            Lex->create_info.db_type= $3;
 
1547
            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
 
1548
          }
 
1549
        | MAX_ROWS opt_equal ulonglong_num
 
1550
          {
 
1551
            Lex->create_info.max_rows= $3;
 
1552
            Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
 
1553
          }
 
1554
        | MIN_ROWS opt_equal ulonglong_num
 
1555
          {
 
1556
            Lex->create_info.min_rows= $3;
 
1557
            Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
 
1558
          }
 
1559
        | AVG_ROW_LENGTH opt_equal ulong_num
 
1560
          {
 
1561
            Lex->create_info.avg_row_length=$3;
 
1562
            Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
 
1563
          }
 
1564
        | PASSWORD opt_equal TEXT_STRING_sys
 
1565
          {
 
1566
            Lex->create_info.password=$3.str;
 
1567
            Lex->create_info.used_fields|= HA_CREATE_USED_PASSWORD;
 
1568
          }
 
1569
        | COMMENT_SYM opt_equal TEXT_STRING_sys
 
1570
          {
 
1571
            Lex->create_info.comment=$3;
 
1572
            Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
 
1573
          }
 
1574
        | AUTO_INC opt_equal ulonglong_num
 
1575
          {
 
1576
            Lex->create_info.auto_increment_value=$3;
 
1577
            Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
 
1578
          }
 
1579
        | PACK_KEYS_SYM opt_equal ulong_num
 
1580
          {
 
1581
            switch($3) {
 
1582
            case 0:
 
1583
                Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
 
1584
                break;
 
1585
            case 1:
 
1586
                Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
 
1587
                break;
 
1588
            default:
 
1589
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
1590
                MYSQL_YYABORT;
 
1591
            }
 
1592
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
 
1593
          }
 
1594
        | PACK_KEYS_SYM opt_equal DEFAULT
 
1595
          {
 
1596
            Lex->create_info.table_options&=
 
1597
              ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
 
1598
            Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
 
1599
          }
 
1600
        | CHECKSUM_SYM opt_equal ulong_num
 
1601
          {
 
1602
            Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
 
1603
            Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
 
1604
          }
 
1605
        | TABLE_CHECKSUM_SYM opt_equal ulong_num
 
1606
          {
 
1607
             Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
 
1608
             Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
 
1609
          }
 
1610
        | PAGE_CHECKSUM_SYM opt_equal choice
 
1611
          {
 
1612
            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
 
1613
            Lex->create_info.page_checksum= $3;
 
1614
          }
 
1615
        | DELAY_KEY_WRITE_SYM opt_equal ulong_num
 
1616
          {
 
1617
            Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
 
1618
            Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
 
1619
          }
 
1620
        | ROW_FORMAT_SYM opt_equal row_types
 
1621
          {
 
1622
            Lex->create_info.row_type= $3;
 
1623
            Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
 
1624
            Lex->alter_info.flags|= ALTER_ROW_FORMAT;
 
1625
          }
 
1626
        | UNION_SYM opt_equal '(' opt_table_list ')'
 
1627
          {
 
1628
            /* Move the union list to the merge_list */
 
1629
            LEX *lex=Lex;
 
1630
            TABLE_LIST *table_list= lex->select_lex.get_table_list();
 
1631
            lex->create_info.merge_list= lex->select_lex.table_list;
 
1632
            lex->create_info.merge_list.elements--;
 
1633
            lex->create_info.merge_list.first=
 
1634
              (uchar*) (table_list->next_local);
 
1635
            lex->select_lex.table_list.elements=1;
 
1636
            lex->select_lex.table_list.next=
 
1637
              (uchar**) &(table_list->next_local);
 
1638
            table_list->next_local= 0;
 
1639
            lex->create_info.used_fields|= HA_CREATE_USED_UNION;
 
1640
          }
 
1641
        | default_charset
 
1642
        | default_collation
 
1643
        | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
 
1644
          {
 
1645
            Lex->create_info.data_file_name= $4.str;
 
1646
            Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
 
1647
          }
 
1648
        | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
 
1649
          {
 
1650
            Lex->create_info.index_file_name= $4.str;
 
1651
            Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
 
1652
          }
 
1653
        | CONNECTION_SYM opt_equal TEXT_STRING_sys
 
1654
          {
 
1655
            Lex->create_info.connect_string.str= $3.str;
 
1656
            Lex->create_info.connect_string.length= $3.length;
 
1657
            Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
 
1658
          }
 
1659
        | KEY_BLOCK_SIZE opt_equal ulong_num
 
1660
          {
 
1661
            Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
 
1662
            Lex->create_info.key_block_size= $3;
 
1663
          }
 
1664
        | TRANSACTIONAL_SYM opt_equal choice
 
1665
          {
 
1666
            Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
 
1667
            Lex->create_info.transactional= $3;
 
1668
          }
 
1669
        ;
 
1670
 
 
1671
default_charset:
 
1672
          opt_default charset opt_equal charset_name_or_default
 
1673
          {
 
1674
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1675
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1676
                 cinfo->default_table_charset && $4 &&
 
1677
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1678
            {
 
1679
              my_error(ER_CONFLICTING_DECLARATIONS, MYF(0),
 
1680
                       "CHARACTER SET ", cinfo->default_table_charset->csname,
 
1681
                       "CHARACTER SET ", $4->csname);
 
1682
              MYSQL_YYABORT;
 
1683
            }
 
1684
            Lex->create_info.default_table_charset= $4;
 
1685
            Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1686
          }
 
1687
        ;
 
1688
 
 
1689
default_collation:
 
1690
          opt_default COLLATE_SYM opt_equal collation_name_or_default
 
1691
          {
 
1692
            HA_CREATE_INFO *cinfo= &Lex->create_info;
 
1693
            if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
1694
                 cinfo->default_table_charset && $4 &&
 
1695
                 !my_charset_same(cinfo->default_table_charset,$4))
 
1696
              {
 
1697
                my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
1698
                         $4->name, cinfo->default_table_charset->csname);
 
1699
                MYSQL_YYABORT;
 
1700
              }
 
1701
              Lex->create_info.default_table_charset= $4;
 
1702
              Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
1703
          }
 
1704
        ;
 
1705
 
 
1706
storage_engines:
 
1707
          ident_or_text
 
1708
          {
 
1709
            plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
 
1710
 
 
1711
            if (plugin)
 
1712
              $$= plugin_data(plugin, handlerton*);
 
1713
            else
 
1714
            {
 
1715
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1716
              MYSQL_YYABORT;
 
1717
            }
 
1718
          }
 
1719
        ;
 
1720
 
 
1721
known_storage_engines:
 
1722
          ident_or_text
 
1723
          {
 
1724
            plugin_ref plugin;
 
1725
            if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
 
1726
              $$= plugin_data(plugin, handlerton*);
 
1727
            else
 
1728
            {
 
1729
              my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
 
1730
              MYSQL_YYABORT;
 
1731
            }
 
1732
          }
 
1733
        ;
 
1734
 
 
1735
column_format_types:
 
1736
          DEFAULT     { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
 
1737
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
 
1738
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
 
1739
 
 
1740
row_types:
 
1741
          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
 
1742
        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
 
1743
        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
 
1744
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
 
1745
        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
 
1746
        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
 
1747
        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
 
1748
        ;
 
1749
 
 
1750
opt_select_from:
 
1751
          opt_limit_clause {}
 
1752
        | select_from select_lock_type
 
1753
        ;
 
1754
 
 
1755
field_list:
 
1756
          field_list_item
 
1757
        | field_list ',' field_list_item
 
1758
        ;
 
1759
 
 
1760
field_list_item:
 
1761
          column_def
 
1762
        | key_def
 
1763
        ;
 
1764
 
 
1765
column_def:
 
1766
          field_spec opt_check_constraint
 
1767
        | field_spec references
 
1768
          {
 
1769
            Lex->col_list.empty(); /* Alloced by sql_alloc */
 
1770
          }
 
1771
        ;
 
1772
 
 
1773
key_def:
 
1774
          key_type opt_ident key_alg '(' key_list ')' key_options
 
1775
          {
 
1776
            LEX *lex=Lex;
 
1777
            Key *key= new Key($1, $2, &lex->key_create_info, 0,
 
1778
                              lex->col_list);
 
1779
            lex->alter_info.key_list.push_back(key);
 
1780
            lex->col_list.empty(); /* Alloced by sql_alloc */
 
1781
          }
 
1782
        | opt_constraint constraint_key_type opt_ident key_alg
 
1783
          '(' key_list ')' key_options
 
1784
          {
 
1785
            LEX *lex=Lex;
 
1786
            Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
 
1787
                              lex->col_list);
 
1788
            lex->alter_info.key_list.push_back(key);
 
1789
            lex->col_list.empty(); /* Alloced by sql_alloc */
 
1790
          }
 
1791
        | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
 
1792
          {
 
1793
            LEX *lex=Lex;
 
1794
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
 
1795
                                      $8,
 
1796
                                      lex->ref_list,
 
1797
                                      lex->fk_delete_opt,
 
1798
                                      lex->fk_update_opt,
 
1799
                                      lex->fk_match_option);
 
1800
            lex->alter_info.key_list.push_back(key);
 
1801
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
 
1802
                         &default_key_create_info, 1,
 
1803
                         lex->col_list);
 
1804
            lex->alter_info.key_list.push_back(key);
 
1805
            lex->col_list.empty(); /* Alloced by sql_alloc */
 
1806
            /* Only used for ALTER TABLE. Ignored otherwise. */
 
1807
            lex->alter_info.flags|= ALTER_FOREIGN_KEY;
 
1808
          }
 
1809
        | constraint opt_check_constraint
 
1810
          {
 
1811
            Lex->col_list.empty(); /* Alloced by sql_alloc */
 
1812
          }
 
1813
        | opt_constraint check_constraint
 
1814
          {
 
1815
            Lex->col_list.empty(); /* Alloced by sql_alloc */
 
1816
          }
 
1817
        ;
 
1818
 
 
1819
opt_check_constraint:
 
1820
          /* empty */
 
1821
        | check_constraint
 
1822
        ;
 
1823
 
 
1824
check_constraint:
 
1825
          CHECK_SYM expr
 
1826
        ;
 
1827
 
 
1828
opt_constraint:
 
1829
          /* empty */ { $$= null_lex_str; }
 
1830
        | constraint { $$= $1; }
 
1831
        ;
 
1832
 
 
1833
constraint:
 
1834
          CONSTRAINT opt_ident { $$=$2; }
 
1835
        ;
 
1836
 
 
1837
field_spec:
 
1838
          field_ident
 
1839
          {
 
1840
            LEX *lex=Lex;
 
1841
            lex->length=lex->dec=0;
 
1842
            lex->type=0;
 
1843
            lex->default_value= lex->on_update_value= 0;
 
1844
            lex->comment=null_lex_str;
 
1845
            lex->charset=NULL;
 
1846
            lex->storage_type= HA_SM_DEFAULT;
 
1847
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1848
          }
 
1849
          type opt_attribute
 
1850
          {
 
1851
            LEX *lex=Lex;
 
1852
            if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
 
1853
                                  lex->length,lex->dec,lex->type,
 
1854
                                  lex->storage_type, lex->column_format,
 
1855
                                  lex->default_value, lex->on_update_value, 
 
1856
                                  &lex->comment,
 
1857
                                  lex->change,&lex->interval_list,lex->charset))
 
1858
              MYSQL_YYABORT;
 
1859
          }
 
1860
        ;
 
1861
 
 
1862
type:
 
1863
          int_type opt_len field_options { $$=$1; }
 
1864
        | real_type opt_precision field_options { $$=$1; }
 
1865
        | FLOAT_SYM float_options field_options { $$=MYSQL_TYPE_FLOAT; }
 
1866
        | BIT_SYM
 
1867
          {
 
1868
            Lex->length= (char*) "1";
 
1869
            $$=MYSQL_TYPE_BIT;
 
1870
          }
 
1871
        | BIT_SYM '(' NUM ')'
 
1872
          {
 
1873
            Lex->length= $3.str;
 
1874
            $$=MYSQL_TYPE_BIT;
 
1875
          }
 
1876
        | BOOL_SYM
 
1877
          {
 
1878
            Lex->length=(char*) "1";
 
1879
            $$=MYSQL_TYPE_TINY;
 
1880
          }
 
1881
        | BOOLEAN_SYM
 
1882
          {
 
1883
            Lex->length=(char*) "1";
 
1884
            $$=MYSQL_TYPE_TINY;
 
1885
          }
 
1886
        | char '(' NUM ')' opt_binary
 
1887
          {
 
1888
            Lex->length=$3.str;
 
1889
            $$=MYSQL_TYPE_STRING;
 
1890
          }
 
1891
        | char opt_binary
 
1892
          {
 
1893
            Lex->length=(char*) "1";
 
1894
            $$=MYSQL_TYPE_STRING;
 
1895
          }
 
1896
        | nchar '(' NUM ')' opt_bin_mod
 
1897
          {
 
1898
            Lex->length=$3.str;
 
1899
            $$=MYSQL_TYPE_STRING;
 
1900
            Lex->charset=national_charset_info;
 
1901
          }
 
1902
        | nchar opt_bin_mod
 
1903
          {
 
1904
            Lex->length=(char*) "1";
 
1905
            $$=MYSQL_TYPE_STRING;
 
1906
            Lex->charset=national_charset_info;
 
1907
          }
 
1908
        | BINARY '(' NUM ')'
 
1909
          {
 
1910
            Lex->length=$3.str;
 
1911
            Lex->charset=&my_charset_bin;
 
1912
            $$=MYSQL_TYPE_STRING;
 
1913
          }
 
1914
        | BINARY
 
1915
          {
 
1916
            Lex->length= (char*) "1";
 
1917
            Lex->charset=&my_charset_bin;
 
1918
            $$=MYSQL_TYPE_STRING;
 
1919
          }
 
1920
        | varchar '(' NUM ')' opt_binary
 
1921
          {
 
1922
            Lex->length=$3.str;
 
1923
            $$= MYSQL_TYPE_VARCHAR;
 
1924
          }
 
1925
        | nvarchar '(' NUM ')' opt_bin_mod
 
1926
          {
 
1927
            Lex->length=$3.str;
 
1928
            $$= MYSQL_TYPE_VARCHAR;
 
1929
            Lex->charset=national_charset_info;
 
1930
          }
 
1931
        | VARBINARY '(' NUM ')'
 
1932
          {
 
1933
            Lex->length=$3.str;
 
1934
            Lex->charset=&my_charset_bin;
 
1935
            $$= MYSQL_TYPE_VARCHAR;
 
1936
          }
 
1937
        | YEAR_SYM opt_len field_options
 
1938
          { $$=MYSQL_TYPE_YEAR; }
 
1939
        | DATE_SYM
 
1940
          { $$=MYSQL_TYPE_DATE; }
 
1941
        | TIME_SYM
 
1942
          { $$=MYSQL_TYPE_TIME; }
 
1943
        | TIMESTAMP
 
1944
          {
 
1945
            /* Unlike other types TIMESTAMP fields are NOT NULL by default */
 
1946
            Lex->type|= NOT_NULL_FLAG;
 
1947
            $$=MYSQL_TYPE_TIMESTAMP;
 
1948
          }
 
1949
        | DATETIME
 
1950
          { $$=MYSQL_TYPE_DATETIME; }
 
1951
        | TINYBLOB
 
1952
          {
 
1953
            Lex->charset=&my_charset_bin;
 
1954
            $$=MYSQL_TYPE_TINY_BLOB;
 
1955
          }
 
1956
        | BLOB_SYM opt_len
 
1957
          {
 
1958
            Lex->charset=&my_charset_bin;
 
1959
            $$=MYSQL_TYPE_BLOB;
 
1960
          }
 
1961
        | MEDIUMBLOB
 
1962
          {
 
1963
            Lex->charset=&my_charset_bin;
 
1964
            $$=MYSQL_TYPE_MEDIUM_BLOB;
 
1965
          }
 
1966
        | LONGBLOB
 
1967
          {
 
1968
            Lex->charset=&my_charset_bin;
 
1969
            $$=MYSQL_TYPE_LONG_BLOB;
 
1970
          }
 
1971
        | LONG_SYM VARBINARY
 
1972
          {
 
1973
            Lex->charset=&my_charset_bin;
 
1974
            $$=MYSQL_TYPE_MEDIUM_BLOB;
 
1975
          }
 
1976
        | LONG_SYM varchar opt_binary
 
1977
          { $$=MYSQL_TYPE_MEDIUM_BLOB; }
 
1978
        | TINYTEXT opt_binary
 
1979
          { $$=MYSQL_TYPE_TINY_BLOB; }
 
1980
        | TEXT_SYM opt_len opt_binary
 
1981
          { $$=MYSQL_TYPE_BLOB; }
 
1982
        | MEDIUMTEXT opt_binary
 
1983
          { $$=MYSQL_TYPE_MEDIUM_BLOB; }
 
1984
        | LONGTEXT opt_binary
 
1985
          { $$=MYSQL_TYPE_LONG_BLOB; }
 
1986
        | DECIMAL_SYM float_options field_options
 
1987
          { $$=MYSQL_TYPE_NEWDECIMAL;}
 
1988
        | NUMERIC_SYM float_options field_options
 
1989
          { $$=MYSQL_TYPE_NEWDECIMAL;}
 
1990
        | FIXED_SYM float_options field_options
 
1991
          { $$=MYSQL_TYPE_NEWDECIMAL;}
 
1992
        | ENUM
 
1993
          {Lex->interval_list.empty();}
 
1994
          '(' string_list ')' opt_binary
 
1995
          { $$=MYSQL_TYPE_ENUM; }
 
1996
        | SET
 
1997
          { Lex->interval_list.empty();}
 
1998
          '(' string_list ')' opt_binary
 
1999
          { $$=MYSQL_TYPE_SET; }
 
2000
        | LONG_SYM opt_binary
 
2001
          { $$=MYSQL_TYPE_MEDIUM_BLOB; }
 
2002
        | SERIAL_SYM
 
2003
          {
 
2004
            $$=MYSQL_TYPE_LONGLONG;
 
2005
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
 
2006
              UNIQUE_FLAG);
 
2007
          }
 
2008
        ;
 
2009
 
 
2010
char:
 
2011
          CHAR_SYM {}
 
2012
        ;
 
2013
 
 
2014
nchar:
 
2015
          NCHAR_SYM {}
 
2016
        | NATIONAL_SYM CHAR_SYM {}
 
2017
        ;
 
2018
 
 
2019
varchar:
 
2020
          char VARYING {}
 
2021
        | VARCHAR {}
 
2022
        ;
 
2023
 
 
2024
nvarchar:
 
2025
          NATIONAL_SYM VARCHAR {}
 
2026
        | NVARCHAR_SYM {}
 
2027
        | NCHAR_SYM VARCHAR {}
 
2028
        | NATIONAL_SYM CHAR_SYM VARYING {}
 
2029
        | NCHAR_SYM VARYING {}
 
2030
        ;
 
2031
 
 
2032
int_type:
 
2033
          INT_SYM   { $$=MYSQL_TYPE_LONG; }
 
2034
        | TINYINT   { $$=MYSQL_TYPE_TINY; }
 
2035
        | SMALLINT  { $$=MYSQL_TYPE_SHORT; }
 
2036
        | MEDIUMINT { $$=MYSQL_TYPE_INT24; }
 
2037
        | BIGINT    { $$=MYSQL_TYPE_LONGLONG; }
 
2038
        ;
 
2039
 
 
2040
real_type:
 
2041
          REAL
 
2042
          {
 
2043
            $$= MYSQL_TYPE_DOUBLE;
 
2044
          }
 
2045
        | DOUBLE_SYM
 
2046
          { $$=MYSQL_TYPE_DOUBLE; }
 
2047
        | DOUBLE_SYM PRECISION
 
2048
          { $$=MYSQL_TYPE_DOUBLE; }
 
2049
        ;
 
2050
 
 
2051
float_options:
 
2052
          /* empty */
 
2053
          { Lex->dec=Lex->length= (char*)0; }
 
2054
        | '(' NUM ')'
 
2055
          { Lex->length=$2.str; Lex->dec= (char*)0; }
 
2056
        | precision
 
2057
          {}
 
2058
        ;
 
2059
 
 
2060
precision:
 
2061
          '(' NUM ',' NUM ')'
 
2062
          {
 
2063
            LEX *lex=Lex;
 
2064
            lex->length=$2.str;
 
2065
            lex->dec=$4.str;
 
2066
          }
 
2067
        ;
 
2068
 
 
2069
field_options:
 
2070
          /* empty */ {}
 
2071
        | field_opt_list {}
 
2072
        ;
 
2073
 
 
2074
field_opt_list:
 
2075
          field_opt_list field_option {}
 
2076
        | field_option {}
 
2077
        ;
 
2078
 
 
2079
field_option:
 
2080
          SIGNED_SYM {}
 
2081
        | UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
 
2082
        | ZEROFILL { Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
 
2083
        ;
 
2084
 
 
2085
opt_len:
 
2086
          /* empty */ { Lex->length=(char*) 0; /* use default length */ }
 
2087
        | '(' NUM ')' { Lex->length= $2.str; }
 
2088
        ;
 
2089
 
 
2090
opt_precision:
 
2091
          /* empty */ {}
 
2092
        | precision {}
 
2093
        ;
 
2094
 
 
2095
opt_attribute:
 
2096
          /* empty */ {}
 
2097
        | opt_attribute_list {}
 
2098
        ;
 
2099
 
 
2100
opt_attribute_list:
 
2101
          opt_attribute_list attribute {}
 
2102
        | attribute
 
2103
        ;
 
2104
 
 
2105
attribute:
 
2106
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
 
2107
        | STORAGE_SYM DEFAULT
 
2108
          {
 
2109
            Lex->storage_type= HA_SM_DEFAULT;
 
2110
            Lex->alter_info.flags|= ALTER_COLUMN_STORAGE;
 
2111
          }
 
2112
        | STORAGE_SYM DISK_SYM
 
2113
          {
 
2114
            Lex->storage_type= HA_SM_DISK;
 
2115
            Lex->alter_info.flags|= ALTER_COLUMN_STORAGE;
 
2116
          }
 
2117
        | STORAGE_SYM MEMORY_SYM
 
2118
          {
 
2119
            Lex->storage_type= HA_SM_MEMORY;
 
2120
            Lex->alter_info.flags|= ALTER_COLUMN_STORAGE;
 
2121
          }
 
2122
        | COLUMN_FORMAT_SYM column_format_types
 
2123
          {
 
2124
            Lex->column_format= $2;
 
2125
            Lex->alter_info.flags|= ALTER_COLUMN_FORMAT;
 
2126
          }
 
2127
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
 
2128
        | DEFAULT now_or_signed_literal 
 
2129
          { 
 
2130
            Lex->default_value=$2; 
 
2131
            Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2132
          }
 
2133
        | ON UPDATE_SYM NOW_SYM optional_braces 
 
2134
          { Lex->on_update_value= new Item_func_now_local(); }
 
2135
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
 
2136
        | SERIAL_SYM DEFAULT VALUE_SYM
 
2137
          { 
 
2138
            LEX *lex=Lex;
 
2139
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
2140
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2141
          }
 
2142
        | opt_primary KEY_SYM
 
2143
          {
 
2144
            LEX *lex=Lex;
 
2145
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
2146
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2147
          }
 
2148
        | UNIQUE_SYM
 
2149
          {
 
2150
            LEX *lex=Lex;
 
2151
            lex->type|= UNIQUE_FLAG; 
 
2152
            lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2153
          }
 
2154
        | UNIQUE_SYM KEY_SYM
 
2155
          {
 
2156
            LEX *lex=Lex;
 
2157
            lex->type|= UNIQUE_KEY_FLAG; 
 
2158
            lex->alter_info.flags|= ALTER_ADD_INDEX; 
 
2159
          }
 
2160
        | COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
 
2161
        | COLLATE_SYM collation_name
 
2162
          {
 
2163
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
 
2164
            {
 
2165
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
2166
                       $2->name,Lex->charset->csname);
 
2167
              MYSQL_YYABORT;
 
2168
            }
 
2169
            else
 
2170
            {
 
2171
              Lex->charset=$2;
 
2172
            }
 
2173
          }
 
2174
        ;
 
2175
 
 
2176
now_or_signed_literal:
 
2177
          NOW_SYM optional_braces
 
2178
          { $$= new Item_func_now_local(); }
 
2179
        | signed_literal
 
2180
          { $$=$1; }
 
2181
        ;
 
2182
 
 
2183
charset:
 
2184
          CHAR_SYM SET {}
 
2185
        | CHARSET {}
 
2186
        ;
 
2187
 
 
2188
charset_name:
 
2189
          ident_or_text
 
2190
          {
 
2191
            if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
 
2192
            {
 
2193
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
 
2194
              MYSQL_YYABORT;
 
2195
            }
 
2196
          }
 
2197
        | BINARY { $$= &my_charset_bin; }
 
2198
        ;
 
2199
 
 
2200
charset_name_or_default:
 
2201
          charset_name { $$=$1;   }
 
2202
        | DEFAULT    { $$=NULL; }
 
2203
        ;
 
2204
 
 
2205
opt_load_data_charset:
 
2206
          /* Empty */ { $$= NULL; }
 
2207
        | charset charset_name_or_default { $$= $2; }
 
2208
        ;
 
2209
 
 
2210
old_or_new_charset_name:
 
2211
          ident_or_text
 
2212
          {
 
2213
            if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
 
2214
                !($$=get_old_charset_by_name($1.str)))
 
2215
            {
 
2216
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
 
2217
              MYSQL_YYABORT;
 
2218
            }
 
2219
          }
 
2220
        | BINARY { $$= &my_charset_bin; }
 
2221
        ;
 
2222
 
 
2223
old_or_new_charset_name_or_default:
 
2224
          old_or_new_charset_name { $$=$1;   }
 
2225
        | DEFAULT    { $$=NULL; }
 
2226
        ;
 
2227
 
 
2228
collation_name:
 
2229
          ident_or_text
 
2230
          {
 
2231
            if (!($$=get_charset_by_name($1.str,MYF(0))))
 
2232
            {
 
2233
              my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
 
2234
              MYSQL_YYABORT;
 
2235
            }
 
2236
          }
 
2237
        ;
 
2238
 
 
2239
opt_collate:
 
2240
          /* empty */ { $$=NULL; }
 
2241
        | COLLATE_SYM collation_name_or_default { $$=$2; }
 
2242
        ;
 
2243
 
 
2244
collation_name_or_default:
 
2245
          collation_name { $$=$1; }
 
2246
        | DEFAULT    { $$=NULL; }
 
2247
        ;
 
2248
 
 
2249
opt_default:
 
2250
          /* empty */ {}
 
2251
        | DEFAULT {}
 
2252
        ;
 
2253
 
 
2254
opt_binary:
 
2255
          /* empty */ { Lex->charset=NULL; }
 
2256
        | ASCII_SYM opt_bin_mod { Lex->charset=&my_charset_latin1; }
 
2257
        | BYTE_SYM { Lex->charset=&my_charset_bin; }
 
2258
        | UNICODE_SYM opt_bin_mod
 
2259
          {
 
2260
            if (!(Lex->charset=get_charset_by_csname("ucs2",
 
2261
                                                     MY_CS_PRIMARY,MYF(0))))
 
2262
            {
 
2263
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
 
2264
              MYSQL_YYABORT;
 
2265
            }
 
2266
          }
 
2267
        | charset charset_name opt_bin_mod { Lex->charset=$2; }
 
2268
        | BINARY opt_bin_charset { Lex->type|= BINCMP_FLAG; }
 
2269
        ;
 
2270
 
 
2271
opt_bin_mod:
 
2272
          /* empty */ { }
 
2273
        | BINARY { Lex->type|= BINCMP_FLAG; }
 
2274
        ;
 
2275
 
 
2276
opt_bin_charset:
 
2277
          /* empty */ { Lex->charset= NULL; }
 
2278
        | ASCII_SYM { Lex->charset=&my_charset_latin1; }
 
2279
        | UNICODE_SYM
 
2280
          {
 
2281
            if (!(Lex->charset=get_charset_by_csname("ucs2",
 
2282
                                                     MY_CS_PRIMARY,MYF(0))))
 
2283
            {
 
2284
              my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
 
2285
              MYSQL_YYABORT;
 
2286
            }
 
2287
          }
 
2288
        | charset charset_name { Lex->charset=$2; }
 
2289
        ;
 
2290
 
 
2291
ws_nweights:
 
2292
        '(' real_ulong_num
 
2293
        {
 
2294
          if ($2 == 0)
 
2295
          {
 
2296
            my_parse_error(ER(ER_SYNTAX_ERROR));
 
2297
            MYSQL_YYABORT;
 
2298
          }
 
2299
        }
 
2300
        ')'
 
2301
        { $$= $2; }
 
2302
        ;
 
2303
 
 
2304
ws_level_flag_desc:
 
2305
        ASC { $$= 0; }
 
2306
        | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
 
2307
        ;
 
2308
 
 
2309
ws_level_flag_reverse:
 
2310
        REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
 
2311
 
 
2312
ws_level_flags:
 
2313
        /* empty */ { $$= 0; }
 
2314
        | ws_level_flag_desc { $$= $1; }
 
2315
        | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
 
2316
        | ws_level_flag_reverse { $$= $1 ; }
 
2317
        ;
 
2318
 
 
2319
ws_level_number:
 
2320
        real_ulong_num
 
2321
        {
 
2322
          $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
 
2323
          $$--;
 
2324
        }
 
2325
        ;
 
2326
 
 
2327
ws_level_list_item:
 
2328
        ws_level_number ws_level_flags
 
2329
        {
 
2330
          $$= (1 | $2) << $1;
 
2331
        }
 
2332
        ;
 
2333
 
 
2334
ws_level_list:
 
2335
        ws_level_list_item { $$= $1; }
 
2336
        | ws_level_list ',' ws_level_list_item { $$|= $3; }
 
2337
        ;
 
2338
 
 
2339
ws_level_range:
 
2340
        ws_level_number '-' ws_level_number
 
2341
        {
 
2342
          uint start= $1;
 
2343
          uint end= $3;
 
2344
          for ($$= 0; start <= end; start++)
 
2345
            $$|= (1 << start);
 
2346
        }
 
2347
        ;
 
2348
 
 
2349
ws_level_list_or_range:
 
2350
        ws_level_list { $$= $1; }
 
2351
        | ws_level_range { $$= $1; }
 
2352
        ;
 
2353
 
 
2354
opt_ws_levels:
 
2355
        /* empty*/ { $$= 0; }
 
2356
        | LEVEL_SYM ws_level_list_or_range { $$= $2; }
 
2357
        ;
 
2358
 
 
2359
opt_primary:
 
2360
          /* empty */
 
2361
        | PRIMARY_SYM
 
2362
        ;
 
2363
 
 
2364
references:
 
2365
          REFERENCES
 
2366
          table_ident
 
2367
          opt_ref_list
 
2368
          opt_match_clause
 
2369
          opt_on_update_delete
 
2370
          {
 
2371
            $$=$2;
 
2372
          }
 
2373
        ;
 
2374
 
 
2375
opt_ref_list:
 
2376
          /* empty */
 
2377
          { Lex->ref_list.empty(); }
 
2378
        | '(' ref_list ')'
 
2379
        ;
 
2380
 
 
2381
ref_list:
 
2382
          ref_list ',' ident
 
2383
          { Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
 
2384
        | ident
 
2385
          {
 
2386
            LEX *lex= Lex;
 
2387
            lex->ref_list.empty();
 
2388
            lex->ref_list.push_back(new Key_part_spec($1, 0));
 
2389
          }
 
2390
        ;
 
2391
 
 
2392
opt_match_clause:
 
2393
          /* empty */
 
2394
          { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
 
2395
        | MATCH FULL
 
2396
          { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
 
2397
        | MATCH PARTIAL
 
2398
          { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
 
2399
        | MATCH SIMPLE_SYM
 
2400
          { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
 
2401
        ;
 
2402
 
 
2403
opt_on_update_delete:
 
2404
          /* empty */
 
2405
          {
 
2406
            LEX *lex= Lex;
 
2407
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
2408
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
2409
          }
 
2410
        | ON UPDATE_SYM delete_option
 
2411
          {
 
2412
            LEX *lex= Lex;
 
2413
            lex->fk_update_opt= $3;
 
2414
            lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
2415
          }
 
2416
        | ON DELETE_SYM delete_option
 
2417
          {
 
2418
            LEX *lex= Lex;
 
2419
            lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
2420
            lex->fk_delete_opt= $3;
 
2421
          }
 
2422
        | ON UPDATE_SYM delete_option
 
2423
          ON DELETE_SYM delete_option
 
2424
          {
 
2425
            LEX *lex= Lex;
 
2426
            lex->fk_update_opt= $3;
 
2427
            lex->fk_delete_opt= $6;
 
2428
          }
 
2429
        | ON DELETE_SYM delete_option
 
2430
          ON UPDATE_SYM delete_option
 
2431
          {
 
2432
            LEX *lex= Lex;
 
2433
            lex->fk_update_opt= $6;
 
2434
            lex->fk_delete_opt= $3;
 
2435
          }
 
2436
        ;
 
2437
 
 
2438
delete_option:
 
2439
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
 
2440
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
 
2441
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
 
2442
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
 
2443
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
 
2444
        ;
 
2445
 
 
2446
key_type:
 
2447
          key_or_index { $$= Key::MULTIPLE; }
 
2448
        ;
 
2449
 
 
2450
constraint_key_type:
 
2451
          PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
 
2452
        | UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; }
 
2453
        ;
 
2454
 
 
2455
key_or_index:
 
2456
          KEY_SYM {}
 
2457
        | INDEX_SYM {}
 
2458
        ;
 
2459
 
 
2460
opt_key_or_index:
 
2461
          /* empty */ {}
 
2462
        | key_or_index
 
2463
        ;
 
2464
 
 
2465
keys_or_index:
 
2466
          KEYS {}
 
2467
        | INDEX_SYM {}
 
2468
        | INDEXES {}
 
2469
        ;
 
2470
 
 
2471
opt_unique:
 
2472
          /* empty */  { $$= Key::MULTIPLE; }
 
2473
        | UNIQUE_SYM   { $$= Key::UNIQUE; }
 
2474
        ;
 
2475
 
 
2476
init_key_options:
 
2477
          {
 
2478
            Lex->key_create_info= default_key_create_info;
 
2479
          }
 
2480
        ;
 
2481
 
 
2482
/*
 
2483
  For now, key_alg initializies lex->key_create_info.
 
2484
  In the future, when all key options are after key definition,
 
2485
  we can remove key_alg and move init_key_options to key_options
 
2486
*/
 
2487
 
 
2488
key_alg:
 
2489
          init_key_options
 
2490
        | init_key_options key_using_alg
 
2491
        ;
 
2492
 
 
2493
key_options:
 
2494
          /* empty */ {}
 
2495
        | key_opts
 
2496
        ;
 
2497
 
 
2498
key_opts:
 
2499
          key_opt
 
2500
        | key_opts key_opt
 
2501
        ;
 
2502
 
 
2503
key_using_alg:
 
2504
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
 
2505
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
 
2506
        ;
 
2507
 
 
2508
key_opt:
 
2509
          key_using_alg
 
2510
        | KEY_BLOCK_SIZE opt_equal ulong_num
 
2511
          { Lex->key_create_info.block_size= $3; }
 
2512
        | COMMENT_SYM TEXT_STRING_sys
 
2513
          { Lex->key_create_info.comment= $2; }
 
2514
        ;
 
2515
 
 
2516
btree_or_rtree:
 
2517
          BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
 
2518
        | HASH_SYM  { $$= HA_KEY_ALG_HASH; }
 
2519
        ;
 
2520
 
 
2521
key_list:
 
2522
          key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
 
2523
        | key_part order_dir { Lex->col_list.push_back($1); }
 
2524
        ;
 
2525
 
 
2526
key_part:
 
2527
          ident { $$=new Key_part_spec($1, 0); }
 
2528
        | ident '(' NUM ')'
 
2529
          {
 
2530
            int key_part_len= atoi($3.str);
 
2531
            if (!key_part_len)
 
2532
            {
 
2533
              my_error(ER_KEY_PART_0, MYF(0), $1.str);
 
2534
            }
 
2535
            $$=new Key_part_spec($1, (uint) key_part_len);
 
2536
          }
 
2537
        ;
 
2538
 
 
2539
opt_ident:
 
2540
          /* empty */ { $$= null_lex_str; }
 
2541
        | field_ident { $$= $1; }
 
2542
        ;
 
2543
 
 
2544
opt_component:
 
2545
          /* empty */    { $$= null_lex_str; }
 
2546
        | '.' ident      { $$= $2; }
 
2547
        ;
 
2548
 
 
2549
string_list:
 
2550
          text_string { Lex->interval_list.push_back($1); }
 
2551
        | string_list ',' text_string { Lex->interval_list.push_back($3); };
 
2552
 
 
2553
/*
 
2554
** Alter table
 
2555
*/
 
2556
 
 
2557
alter:
 
2558
          ALTER build_method opt_ignore TABLE_SYM table_ident
 
2559
          {
 
2560
            THD *thd= YYTHD;
 
2561
            LEX *lex= thd->lex;
 
2562
            lex->name.str= 0;
 
2563
            lex->name.length= 0;
 
2564
            lex->sql_command= SQLCOM_ALTER_TABLE;
 
2565
            lex->duplicates= DUP_ERROR; 
 
2566
            if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
 
2567
                                                   TL_OPTION_UPDATING))
 
2568
              MYSQL_YYABORT;
 
2569
            lex->alter_info.reset();
 
2570
            lex->col_list.empty();
 
2571
            lex->select_lex.init_order();
 
2572
            lex->select_lex.db=
 
2573
              ((TABLE_LIST*) lex->select_lex.table_list.first)->db;
 
2574
            bzero((char*) &lex->create_info,sizeof(lex->create_info));
 
2575
            lex->create_info.db_type= 0;
 
2576
            lex->create_info.default_table_charset= NULL;
 
2577
            lex->create_info.row_type= ROW_TYPE_NOT_USED;
 
2578
            lex->alter_info.reset();
 
2579
            lex->no_write_to_binlog= 0;
 
2580
            lex->create_info.default_storage_media= HA_SM_DEFAULT;
 
2581
            lex->alter_info.build_method= $2;
 
2582
          }
 
2583
          alter_commands
 
2584
          {}
 
2585
        | ALTER DATABASE ident_or_empty
 
2586
          {
 
2587
            Lex->create_info.default_table_charset= NULL;
 
2588
            Lex->create_info.used_fields= 0;
 
2589
          }
 
2590
          create_database_options
 
2591
          {
 
2592
            LEX *lex=Lex;
 
2593
            lex->sql_command=SQLCOM_ALTER_DB;
 
2594
            lex->name= $3;
 
2595
            if (lex->name.str == NULL &&
 
2596
                lex->copy_db_to(&lex->name.str, &lex->name.length))
 
2597
              MYSQL_YYABORT;
 
2598
          }
 
2599
        | ALTER DATABASE ident UPGRADE_SYM DATA_SYM DIRECTORY_SYM NAME_SYM
 
2600
          {
 
2601
            LEX *lex= Lex;
 
2602
            lex->sql_command= SQLCOM_ALTER_DB_UPGRADE;
 
2603
            lex->name= $3;
 
2604
          }
 
2605
        ;
 
2606
 
 
2607
ident_or_empty:
 
2608
          /* empty */ { $$.str= 0; $$.length= 0; }
 
2609
        | ident { $$= $1; }
 
2610
        ;
 
2611
 
 
2612
alter_commands:
 
2613
          /* empty */
 
2614
        | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
 
2615
        | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
 
2616
        | alter_list
 
2617
        ;
 
2618
 
 
2619
build_method:
 
2620
        /* empty */
 
2621
          {
 
2622
            $$= HA_BUILD_DEFAULT;
 
2623
          }
 
2624
        | ONLINE_SYM
 
2625
          {
 
2626
            $$= HA_BUILD_ONLINE;
 
2627
          }
 
2628
        | OFFLINE_SYM
 
2629
          {
 
2630
            $$= HA_BUILD_OFFLINE;
 
2631
          }
 
2632
        ;
 
2633
 
 
2634
alter_list:
 
2635
          alter_list_item
 
2636
        | alter_list ',' alter_list_item
 
2637
        ;
 
2638
 
 
2639
add_column:
 
2640
          ADD opt_column
 
2641
          {
 
2642
            LEX *lex=Lex;
 
2643
            lex->change=0;
 
2644
            lex->alter_info.flags|= ALTER_ADD_COLUMN;
 
2645
          }
 
2646
        ;
 
2647
 
 
2648
alter_list_item:
 
2649
          add_column column_def opt_place { }
 
2650
        | ADD key_def
 
2651
          {
 
2652
            Lex->alter_info.flags|= ALTER_ADD_INDEX;
 
2653
          }
 
2654
        | add_column '(' field_list ')'
 
2655
          {
 
2656
            Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX;
 
2657
          }
 
2658
        | CHANGE opt_column field_ident
 
2659
          {
 
2660
            LEX *lex=Lex;
 
2661
            lex->change= $3.str;
 
2662
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2663
          }
 
2664
          field_spec opt_place
 
2665
        | MODIFY_SYM opt_column field_ident
 
2666
          {
 
2667
            LEX *lex=Lex;
 
2668
            lex->length=lex->dec=0; lex->type=0;
 
2669
            lex->default_value= lex->on_update_value= 0;
 
2670
            lex->comment=null_lex_str;
 
2671
            lex->charset= NULL;
 
2672
            lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
 
2673
            lex->storage_type= HA_SM_DEFAULT;
 
2674
            lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
2675
          }
 
2676
          type opt_attribute
 
2677
          {
 
2678
            LEX *lex=Lex;
 
2679
            if (add_field_to_list(lex->thd,&$3,
 
2680
                                  (enum enum_field_types) $5,
 
2681
                                  lex->length,lex->dec,lex->type,
 
2682
                                  lex->storage_type, lex->column_format,
 
2683
                                  lex->default_value, lex->on_update_value,
 
2684
                                  &lex->comment,
 
2685
                                  $3.str, &lex->interval_list, lex->charset))
 
2686
              MYSQL_YYABORT;
 
2687
          }
 
2688
          opt_place
 
2689
        | DROP opt_column field_ident opt_restrict
 
2690
          {
 
2691
            LEX *lex=Lex;
 
2692
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
 
2693
                                                               $3.str));
 
2694
            lex->alter_info.flags|= ALTER_DROP_COLUMN;
 
2695
          }
 
2696
        | DROP FOREIGN KEY_SYM opt_ident
 
2697
          {
 
2698
            Lex->alter_info.flags|= ALTER_DROP_INDEX | ALTER_FOREIGN_KEY;
 
2699
          }
 
2700
        | DROP PRIMARY_SYM KEY_SYM
 
2701
          {
 
2702
            LEX *lex=Lex;
 
2703
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
2704
                                                               primary_key_name));
 
2705
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2706
          }
 
2707
        | DROP key_or_index field_ident
 
2708
          {
 
2709
            LEX *lex=Lex;
 
2710
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
2711
                                                               $3.str));
 
2712
            lex->alter_info.flags|= ALTER_DROP_INDEX;
 
2713
          }
 
2714
        | DISABLE_SYM KEYS
 
2715
          {
 
2716
            LEX *lex=Lex;
 
2717
            lex->alter_info.keys_onoff= DISABLE;
 
2718
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2719
          }
 
2720
        | ENABLE_SYM KEYS
 
2721
          {
 
2722
            LEX *lex=Lex;
 
2723
            lex->alter_info.keys_onoff= ENABLE;
 
2724
            lex->alter_info.flags|= ALTER_KEYS_ONOFF;
 
2725
          }
 
2726
        | ALTER opt_column field_ident SET DEFAULT signed_literal
 
2727
          {
 
2728
            LEX *lex=Lex;
 
2729
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
 
2730
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2731
          }
 
2732
        | ALTER opt_column field_ident DROP DEFAULT
 
2733
          {
 
2734
            LEX *lex=Lex;
 
2735
            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
 
2736
                                                                  (Item*) 0));
 
2737
            lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
 
2738
          }
 
2739
        | RENAME opt_to table_ident
 
2740
          {
 
2741
            LEX *lex=Lex;
 
2742
            size_t dummy;
 
2743
            lex->select_lex.db=$3->db.str;
 
2744
            if (lex->select_lex.db == NULL &&
 
2745
                lex->copy_db_to(&lex->select_lex.db, &dummy))
 
2746
            {
 
2747
              MYSQL_YYABORT;
 
2748
            }
 
2749
            if (check_table_name($3->table.str,$3->table.length) || ($3->db.str && check_db_name(&$3->db)))
 
2750
            {
 
2751
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
 
2752
              MYSQL_YYABORT;
 
2753
            }
 
2754
            lex->name= $3->table;
 
2755
            lex->alter_info.flags|= ALTER_RENAME;
 
2756
          }
 
2757
        | CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
 
2758
          {
 
2759
            if (!$4)
 
2760
            {
 
2761
              THD *thd= YYTHD;
 
2762
              $4= thd->variables.collation_database;
 
2763
            }
 
2764
            $5= $5 ? $5 : $4;
 
2765
            if (!my_charset_same($4,$5))
 
2766
            {
 
2767
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
2768
                       $5->name, $4->csname);
 
2769
              MYSQL_YYABORT;
 
2770
            }
 
2771
            LEX *lex= Lex;
 
2772
            lex->create_info.table_charset=
 
2773
            lex->create_info.default_table_charset= $5;
 
2774
            lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
 
2775
              HA_CREATE_USED_DEFAULT_CHARSET);
 
2776
            lex->alter_info.flags|= ALTER_CONVERT;
 
2777
          }
 
2778
        | create_table_options_space_separated
 
2779
          {
 
2780
            LEX *lex=Lex;
 
2781
            lex->alter_info.flags|= ALTER_OPTIONS;
 
2782
          }
 
2783
        | FORCE_SYM
 
2784
          {
 
2785
            Lex->alter_info.flags|= ALTER_FORCE;
 
2786
          }
 
2787
        | alter_order_clause
 
2788
          {
 
2789
            LEX *lex=Lex;
 
2790
            lex->alter_info.flags|= ALTER_ORDER;
 
2791
          }
 
2792
        ;
 
2793
 
 
2794
opt_column:
 
2795
          /* empty */ {}
 
2796
        | COLUMN_SYM {}
 
2797
        ;
 
2798
 
 
2799
opt_ignore:
 
2800
          /* empty */ { Lex->ignore= 0;}
 
2801
        | IGNORE_SYM { Lex->ignore= 1;}
 
2802
        ;
 
2803
 
 
2804
opt_restrict:
 
2805
          /* empty */ { Lex->drop_mode= DROP_DEFAULT; }
 
2806
        | RESTRICT    { Lex->drop_mode= DROP_RESTRICT; }
 
2807
        | CASCADE     { Lex->drop_mode= DROP_CASCADE; }
 
2808
        ;
 
2809
 
 
2810
opt_place:
 
2811
          /* empty */ {}
 
2812
        | AFTER_SYM ident
 
2813
          {
 
2814
            store_position_for_column($2.str);
 
2815
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2816
          }
 
2817
        | FIRST_SYM
 
2818
          {
 
2819
            store_position_for_column(first_keyword);
 
2820
            Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
 
2821
          }
 
2822
        ;
 
2823
 
 
2824
opt_to:
 
2825
          /* empty */ {}
 
2826
        | TO_SYM {}
 
2827
        | EQ {}
 
2828
        | AS {}
 
2829
        ;
 
2830
 
 
2831
/*
 
2832
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
 
2833
*/
 
2834
 
 
2835
slave:
 
2836
          START_SYM SLAVE slave_thread_opts
 
2837
          {
 
2838
            LEX *lex=Lex;
 
2839
            lex->sql_command = SQLCOM_SLAVE_START;
 
2840
            lex->type = 0;
 
2841
            /* We'll use mi structure for UNTIL options */
 
2842
            bzero((char*) &lex->mi, sizeof(lex->mi));
 
2843
            /* If you change this code don't forget to update SLAVE START too */
 
2844
          }
 
2845
          slave_until
 
2846
          {}
 
2847
        | STOP_SYM SLAVE slave_thread_opts
 
2848
          {
 
2849
            LEX *lex=Lex;
 
2850
            lex->sql_command = SQLCOM_SLAVE_STOP;
 
2851
            lex->type = 0;
 
2852
            /* If you change this code don't forget to update SLAVE STOP too */
 
2853
          }
 
2854
        | SLAVE START_SYM slave_thread_opts
 
2855
          {
 
2856
            LEX *lex=Lex;
 
2857
            lex->sql_command = SQLCOM_SLAVE_START;
 
2858
            lex->type = 0;
 
2859
            /* We'll use mi structure for UNTIL options */
 
2860
            bzero((char*) &lex->mi, sizeof(lex->mi));
 
2861
          }
 
2862
          slave_until
 
2863
          {}
 
2864
        | SLAVE STOP_SYM slave_thread_opts
 
2865
          {
 
2866
            LEX *lex=Lex;
 
2867
            lex->sql_command = SQLCOM_SLAVE_STOP;
 
2868
            lex->type = 0;
 
2869
          }
 
2870
        ;
 
2871
 
 
2872
start:
 
2873
          START_SYM TRANSACTION_SYM start_transaction_opts
 
2874
          {
 
2875
            LEX *lex= Lex;
 
2876
            lex->sql_command= SQLCOM_BEGIN;
 
2877
            lex->start_transaction_opt= $3;
 
2878
          }
 
2879
        ;
 
2880
 
 
2881
start_transaction_opts:
 
2882
          /*empty*/ { $$ = 0; }
 
2883
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
 
2884
          {
 
2885
            $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
 
2886
          }
 
2887
        ;
 
2888
 
 
2889
slave_thread_opts:
 
2890
          { Lex->slave_thd_opt= 0; }
 
2891
          slave_thread_opt_list
 
2892
          {}
 
2893
        ;
 
2894
 
 
2895
slave_thread_opt_list:
 
2896
          slave_thread_opt
 
2897
        | slave_thread_opt_list ',' slave_thread_opt
 
2898
        ;
 
2899
 
 
2900
slave_thread_opt:
 
2901
          /*empty*/ {}
 
2902
        | SQL_THREAD   { Lex->slave_thd_opt|=SLAVE_SQL; }
 
2903
        | RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
 
2904
        ;
 
2905
 
 
2906
slave_until:
 
2907
          /*empty*/ {}
 
2908
        | UNTIL_SYM slave_until_opts
 
2909
          {
 
2910
            LEX *lex=Lex;
 
2911
            if (((lex->mi.log_file_name || lex->mi.pos) && (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
 
2912
                !((lex->mi.log_file_name && lex->mi.pos) ||
 
2913
                  (lex->mi.relay_log_name && lex->mi.relay_log_pos)))
 
2914
            {
 
2915
               my_message(ER_BAD_SLAVE_UNTIL_COND,
 
2916
                          ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0));
 
2917
               MYSQL_YYABORT;
 
2918
            }
 
2919
          }
 
2920
        ;
 
2921
 
 
2922
slave_until_opts:
 
2923
          master_file_def
 
2924
        | slave_until_opts ',' master_file_def
 
2925
        ;
 
2926
 
 
2927
checksum:
 
2928
          CHECKSUM_SYM table_or_tables
 
2929
          {
 
2930
            LEX *lex=Lex;
 
2931
            lex->sql_command = SQLCOM_CHECKSUM;
 
2932
          }
 
2933
          table_list opt_checksum_type
 
2934
          {}
 
2935
        ;
 
2936
 
 
2937
opt_checksum_type:
 
2938
          /* nothing */ { Lex->check_opt.flags= 0; }
 
2939
        | QUICK         { Lex->check_opt.flags= T_QUICK; }
 
2940
        | EXTENDED_SYM  { Lex->check_opt.flags= T_EXTEND; }
 
2941
        ;
 
2942
 
 
2943
repair:
 
2944
          REPAIR opt_no_write_to_binlog table_or_tables
 
2945
          {
 
2946
            LEX *lex=Lex;
 
2947
            lex->sql_command = SQLCOM_REPAIR;
 
2948
            lex->no_write_to_binlog= $2;
 
2949
            lex->check_opt.init();
 
2950
          }
 
2951
          table_list opt_mi_repair_type
 
2952
          {}
 
2953
        ;
 
2954
 
 
2955
opt_mi_repair_type:
 
2956
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
2957
        | mi_repair_types {}
 
2958
        ;
 
2959
 
 
2960
mi_repair_types:
 
2961
          mi_repair_type {}
 
2962
        | mi_repair_type mi_repair_types {}
 
2963
        ;
 
2964
 
 
2965
mi_repair_type:
 
2966
          QUICK        { Lex->check_opt.flags|= T_QUICK; }
 
2967
        | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
 
2968
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; }
 
2969
        ;
 
2970
 
 
2971
analyze:
 
2972
          ANALYZE_SYM opt_no_write_to_binlog table_or_tables
 
2973
          {
 
2974
            LEX *lex=Lex;
 
2975
            lex->sql_command = SQLCOM_ANALYZE;
 
2976
            lex->no_write_to_binlog= $2;
 
2977
            lex->check_opt.init();
 
2978
          }
 
2979
          table_list
 
2980
          {}
 
2981
        ;
 
2982
 
 
2983
binlog_base64_event:
 
2984
          BINLOG_SYM TEXT_STRING_sys
 
2985
          {
 
2986
            Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
 
2987
            Lex->comment= $2;
 
2988
          }
 
2989
        ;
 
2990
 
 
2991
check:
 
2992
          CHECK_SYM table_or_tables
 
2993
          {
 
2994
            LEX *lex=Lex;
 
2995
 
 
2996
            lex->sql_command = SQLCOM_CHECK;
 
2997
            lex->check_opt.init();
 
2998
          }
 
2999
          table_list opt_mi_check_type
 
3000
          {}
 
3001
        ;
 
3002
 
 
3003
opt_mi_check_type:
 
3004
          /* empty */ { Lex->check_opt.flags = T_MEDIUM; }
 
3005
        | mi_check_types {}
 
3006
        ;
 
3007
 
 
3008
mi_check_types:
 
3009
          mi_check_type {}
 
3010
        | mi_check_type mi_check_types {}
 
3011
        ;
 
3012
 
 
3013
mi_check_type:
 
3014
          QUICK               { Lex->check_opt.flags|= T_QUICK; }
 
3015
        | FAST_SYM            { Lex->check_opt.flags|= T_FAST; }
 
3016
        | MEDIUM_SYM          { Lex->check_opt.flags|= T_MEDIUM; }
 
3017
        | EXTENDED_SYM        { Lex->check_opt.flags|= T_EXTEND; }
 
3018
        | CHANGED             { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
 
3019
        | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
 
3020
        ;
 
3021
 
 
3022
optimize:
 
3023
          OPTIMIZE opt_no_write_to_binlog table_or_tables
 
3024
          {
 
3025
            LEX *lex=Lex;
 
3026
            lex->sql_command = SQLCOM_OPTIMIZE;
 
3027
            lex->no_write_to_binlog= $2;
 
3028
            lex->check_opt.init();
 
3029
          }
 
3030
          table_list
 
3031
          {}
 
3032
        ;
 
3033
 
 
3034
opt_no_write_to_binlog:
 
3035
          /* empty */ { $$= 0; }
 
3036
        | NO_WRITE_TO_BINLOG { $$= 1; }
 
3037
        | LOCAL_SYM { $$= 1; }
 
3038
        ;
 
3039
 
 
3040
rename:
 
3041
          RENAME table_or_tables
 
3042
          {
 
3043
            Lex->sql_command= SQLCOM_RENAME_TABLE;
 
3044
          }
 
3045
          table_to_table_list
 
3046
          {}
 
3047
        ;
 
3048
 
 
3049
table_to_table_list:
 
3050
          table_to_table
 
3051
        | table_to_table_list ',' table_to_table
 
3052
        ;
 
3053
 
 
3054
table_to_table:
 
3055
          table_ident TO_SYM table_ident
 
3056
          {
 
3057
            LEX *lex=Lex;
 
3058
            SELECT_LEX *sl= lex->current_select;
 
3059
            if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
 
3060
                                       TL_IGNORE) ||
 
3061
                !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
 
3062
                                       TL_IGNORE))
 
3063
              MYSQL_YYABORT;
 
3064
          }
 
3065
        ;
 
3066
 
 
3067
keycache:
 
3068
          CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
 
3069
          {
 
3070
            LEX *lex=Lex;
 
3071
            lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
 
3072
            lex->ident= $5;
 
3073
          }
 
3074
        ;
 
3075
 
 
3076
keycache_list:
 
3077
          assign_to_keycache
 
3078
        | keycache_list ',' assign_to_keycache
 
3079
        ;
 
3080
 
 
3081
assign_to_keycache:
 
3082
          table_ident cache_keys_spec
 
3083
          {
 
3084
            if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ, 
 
3085
                                           Select->pop_index_hints()))
 
3086
              MYSQL_YYABORT;
 
3087
          }
 
3088
        ;
 
3089
 
 
3090
key_cache_name:
 
3091
          ident    { $$= $1; }
 
3092
        | DEFAULT  { $$ = default_key_cache_base; }
 
3093
        ;
 
3094
 
 
3095
preload:
 
3096
          LOAD INDEX_SYM INTO CACHE_SYM
 
3097
          {
 
3098
            LEX *lex=Lex;
 
3099
            lex->sql_command=SQLCOM_PRELOAD_KEYS;
 
3100
          }
 
3101
          preload_list
 
3102
          {}
 
3103
        ;
 
3104
 
 
3105
preload_list:
 
3106
          preload_keys
 
3107
        | preload_list ',' preload_keys
 
3108
        ;
 
3109
 
 
3110
preload_keys:
 
3111
          table_ident cache_keys_spec opt_ignore_leaves
 
3112
          {
 
3113
            if (!Select->add_table_to_list(YYTHD, $1, NULL, $3, TL_READ,
 
3114
                                           Select->pop_index_hints()))
 
3115
              MYSQL_YYABORT;
 
3116
          }
 
3117
        ;
 
3118
 
 
3119
cache_keys_spec:
 
3120
          {
 
3121
            Lex->select_lex.alloc_index_hints(YYTHD);
 
3122
            Select->set_index_hint_type(INDEX_HINT_USE, 
 
3123
                                        global_system_variables.old_mode ? 
 
3124
                                        INDEX_HINT_MASK_JOIN : 
 
3125
                                        INDEX_HINT_MASK_ALL);
 
3126
          }
 
3127
          cache_key_list_or_empty
 
3128
        ;
 
3129
 
 
3130
cache_key_list_or_empty:
 
3131
          /* empty */ { }
 
3132
        | key_or_index '(' opt_key_usage_list ')'
 
3133
        ;
 
3134
 
 
3135
opt_ignore_leaves:
 
3136
          /* empty */
 
3137
          { $$= 0; }
 
3138
        | IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
 
3139
        ;
 
3140
 
 
3141
/*
 
3142
  Select : retrieve data from table
 
3143
*/
 
3144
 
 
3145
 
 
3146
select:
 
3147
          select_init
 
3148
          {
 
3149
            LEX *lex= Lex;
 
3150
            lex->sql_command= SQLCOM_SELECT;
 
3151
          }
 
3152
        ;
 
3153
 
 
3154
/* Need select_init2 for subselects. */
 
3155
select_init:
 
3156
          SELECT_SYM select_init2
 
3157
        | '(' select_paren ')' union_opt
 
3158
        ;
 
3159
 
 
3160
select_paren:
 
3161
          SELECT_SYM select_part2
 
3162
          {
 
3163
            if (setup_select_in_parentheses(Lex))
 
3164
              MYSQL_YYABORT;
 
3165
          }
 
3166
        | '(' select_paren ')'
 
3167
        ;
 
3168
 
 
3169
/* The equivalent of select_paren for nested queries. */
 
3170
select_paren_derived:
 
3171
          SELECT_SYM select_part2_derived
 
3172
          {
 
3173
            if (setup_select_in_parentheses(Lex))
 
3174
              MYSQL_YYABORT;
 
3175
          }
 
3176
        | '(' select_paren_derived ')'
 
3177
        ;
 
3178
 
 
3179
select_init2:
 
3180
          select_part2
 
3181
          {
 
3182
            LEX *lex= Lex;
 
3183
            SELECT_LEX * sel= lex->current_select;
 
3184
            if (lex->current_select->set_braces(0))
 
3185
            {
 
3186
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3187
              MYSQL_YYABORT;
 
3188
            }
 
3189
            if (sel->linkage == UNION_TYPE &&
 
3190
                sel->master_unit()->first_select()->braces)
 
3191
            {
 
3192
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3193
              MYSQL_YYABORT;
 
3194
            }
 
3195
          }
 
3196
          union_clause
 
3197
        ;
 
3198
 
 
3199
select_part2:
 
3200
          {
 
3201
            LEX *lex= Lex;
 
3202
            SELECT_LEX *sel= lex->current_select;
 
3203
            if (sel->linkage != UNION_TYPE)
 
3204
              mysql_init_select(lex);
 
3205
            lex->current_select->parsing_place= SELECT_LIST;
 
3206
          }
 
3207
          select_options select_item_list
 
3208
          {
 
3209
            Select->parsing_place= NO_MATTER;
 
3210
          }
 
3211
          select_into select_lock_type
 
3212
        ;
 
3213
 
 
3214
select_into:
 
3215
          opt_order_clause opt_limit_clause {}
 
3216
        | into
 
3217
        | select_from
 
3218
        | into select_from
 
3219
        | select_from into
 
3220
        ;
 
3221
 
 
3222
select_from:
 
3223
          FROM join_table_list where_clause group_clause having_clause
 
3224
          opt_order_clause opt_limit_clause
 
3225
          {
 
3226
            Select->context.table_list=
 
3227
              Select->context.first_name_resolution_table= 
 
3228
                (TABLE_LIST *) Select->table_list.first;
 
3229
          }
 
3230
        ;
 
3231
 
 
3232
select_options:
 
3233
          /* empty*/
 
3234
        | select_option_list
 
3235
          {
 
3236
            if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
 
3237
            {
 
3238
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
 
3239
              MYSQL_YYABORT;
 
3240
            }
 
3241
          }
 
3242
        ;
 
3243
 
 
3244
select_option_list:
 
3245
          select_option_list select_option
 
3246
        | select_option
 
3247
        ;
 
3248
 
 
3249
select_option:
 
3250
          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
 
3251
        | HIGH_PRIORITY
 
3252
          {
 
3253
            if (check_simple_select())
 
3254
              MYSQL_YYABORT;
 
3255
            Lex->lock_option= TL_READ_HIGH_PRIORITY;
 
3256
          }
 
3257
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
 
3258
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
 
3259
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
 
3260
        | SQL_BUFFER_RESULT
 
3261
          {
 
3262
            if (check_simple_select())
 
3263
              MYSQL_YYABORT;
 
3264
            Select->options|= OPTION_BUFFER_RESULT;
 
3265
          }
 
3266
        | SQL_CALC_FOUND_ROWS
 
3267
          {
 
3268
            if (check_simple_select())
 
3269
              MYSQL_YYABORT;
 
3270
            Select->options|= OPTION_FOUND_ROWS;
 
3271
          }
 
3272
        | ALL { Select->options|= SELECT_ALL; }
 
3273
        ;
 
3274
 
 
3275
select_lock_type:
 
3276
          /* empty */
 
3277
        | FOR_SYM UPDATE_SYM
 
3278
          {
 
3279
            LEX *lex=Lex;
 
3280
            lex->current_select->set_lock_for_tables(TL_WRITE);
 
3281
          }
 
3282
        | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
 
3283
          {
 
3284
            LEX *lex=Lex;
 
3285
            lex->current_select->
 
3286
              set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
 
3287
          }
 
3288
        ;
 
3289
 
 
3290
select_item_list:
 
3291
          select_item_list ',' select_item
 
3292
        | select_item
 
3293
        | '*'
 
3294
          {
 
3295
            THD *thd= YYTHD;
 
3296
            if (add_item_to_list(thd,
 
3297
                                 new Item_field(&thd->lex->current_select->
 
3298
                                                context,
 
3299
                                                NULL, NULL, "*")))
 
3300
              MYSQL_YYABORT;
 
3301
            (thd->lex->current_select->with_wild)++;
 
3302
          }
 
3303
        ;
 
3304
 
 
3305
select_item:
 
3306
          remember_name table_wild remember_end
 
3307
          {
 
3308
            THD *thd= YYTHD;
 
3309
 
 
3310
            if (add_item_to_list(thd, $2))
 
3311
              MYSQL_YYABORT;
 
3312
          }
 
3313
        | remember_name expr remember_end select_alias
 
3314
          {
 
3315
            THD *thd= YYTHD;
 
3316
            DBUG_ASSERT($1 < $3);
 
3317
 
 
3318
            if (add_item_to_list(thd, $2))
 
3319
              MYSQL_YYABORT;
 
3320
            if ($4.str)
 
3321
            {
 
3322
              $2->is_autogenerated_name= FALSE;
 
3323
              $2->set_name($4.str, $4.length, system_charset_info);
 
3324
            }
 
3325
            else if (!$2->name)
 
3326
            {
 
3327
              $2->set_name($1, (uint) ($3 - $1), thd->charset());
 
3328
            }
 
3329
          }
 
3330
        ;
 
3331
 
 
3332
remember_name:
 
3333
          {
 
3334
            THD *thd= YYTHD;
 
3335
            Lex_input_stream *lip= thd->m_lip;
 
3336
            $$= (char*) lip->get_cpp_tok_start();
 
3337
          }
 
3338
        ;
 
3339
 
 
3340
remember_end:
 
3341
          {
 
3342
            THD *thd= YYTHD;
 
3343
            Lex_input_stream *lip= thd->m_lip;
 
3344
            $$= (char*) lip->get_cpp_tok_end();
 
3345
          }
 
3346
        ;
 
3347
 
 
3348
select_alias:
 
3349
          /* empty */ { $$=null_lex_str;}
 
3350
        | AS ident { $$=$2; }
 
3351
        | AS TEXT_STRING_sys { $$=$2; }
 
3352
        | ident { $$=$1; }
 
3353
        | TEXT_STRING_sys { $$=$1; }
 
3354
        ;
 
3355
 
 
3356
optional_braces:
 
3357
          /* empty */ {}
 
3358
        | '(' ')' {}
 
3359
        ;
 
3360
 
 
3361
/* all possible expressions */
 
3362
expr:
 
3363
          expr or expr %prec OR_SYM
 
3364
          {
 
3365
            /*
 
3366
              Design notes:
 
3367
              Do not use a manually maintained stack like thd->lex->xxx_list,
 
3368
              but use the internal bison stack ($$, $1 and $3) instead.
 
3369
              Using the bison stack is:
 
3370
              - more robust to changes in the grammar,
 
3371
              - guaranteed to be in sync with the parser state,
 
3372
              - better for performances (no memory allocation).
 
3373
            */
 
3374
            Item_cond_or *item1;
 
3375
            Item_cond_or *item3;
 
3376
            if (is_cond_or($1))
 
3377
            {
 
3378
              item1= (Item_cond_or*) $1;
 
3379
              if (is_cond_or($3))
 
3380
              {
 
3381
                item3= (Item_cond_or*) $3;
 
3382
                /*
 
3383
                  (X1 OR X2) OR (Y1 OR Y2) ==> OR (X1, X2, Y1, Y2)
 
3384
                */
 
3385
                item3->add_at_head(item1->argument_list());
 
3386
                $$ = $3;
 
3387
              }
 
3388
              else
 
3389
              {
 
3390
                /*
 
3391
                  (X1 OR X2) OR Y ==> OR (X1, X2, Y)
 
3392
                */
 
3393
                item1->add($3);
 
3394
                $$ = $1;
 
3395
              }
 
3396
            }
 
3397
            else if (is_cond_or($3))
 
3398
            {
 
3399
              item3= (Item_cond_or*) $3;
 
3400
              /*
 
3401
                X OR (Y1 OR Y2) ==> OR (X, Y1, Y2)
 
3402
              */
 
3403
              item3->add_at_head($1);
 
3404
              $$ = $3;
 
3405
            }
 
3406
            else
 
3407
            {
 
3408
              /* X OR Y */
 
3409
              $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
 
3410
            }
 
3411
          }
 
3412
        | expr XOR expr %prec XOR
 
3413
          {
 
3414
            /* XOR is a proprietary extension */
 
3415
            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
 
3416
          }
 
3417
        | expr and expr %prec AND_SYM
 
3418
          {
 
3419
            /* See comments in rule expr: expr or expr */
 
3420
            Item_cond_and *item1;
 
3421
            Item_cond_and *item3;
 
3422
            if (is_cond_and($1))
 
3423
            {
 
3424
              item1= (Item_cond_and*) $1;
 
3425
              if (is_cond_and($3))
 
3426
              {
 
3427
                item3= (Item_cond_and*) $3;
 
3428
                /*
 
3429
                  (X1 AND X2) AND (Y1 AND Y2) ==> AND (X1, X2, Y1, Y2)
 
3430
                */
 
3431
                item3->add_at_head(item1->argument_list());
 
3432
                $$ = $3;
 
3433
              }
 
3434
              else
 
3435
              {
 
3436
                /*
 
3437
                  (X1 AND X2) AND Y ==> AND (X1, X2, Y)
 
3438
                */
 
3439
                item1->add($3);
 
3440
                $$ = $1;
 
3441
              }
 
3442
            }
 
3443
            else if (is_cond_and($3))
 
3444
            {
 
3445
              item3= (Item_cond_and*) $3;
 
3446
              /*
 
3447
                X AND (Y1 AND Y2) ==> AND (X, Y1, Y2)
 
3448
              */
 
3449
              item3->add_at_head($1);
 
3450
              $$ = $3;
 
3451
            }
 
3452
            else
 
3453
            {
 
3454
              /* X AND Y */
 
3455
              $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
 
3456
            }
 
3457
          }
 
3458
        | NOT_SYM expr %prec NOT_SYM
 
3459
          { $$= negate_expression(YYTHD, $2); }
 
3460
        | bool_pri IS TRUE_SYM %prec IS
 
3461
          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
 
3462
        | bool_pri IS not TRUE_SYM %prec IS
 
3463
          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
 
3464
        | bool_pri IS FALSE_SYM %prec IS
 
3465
          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
 
3466
        | bool_pri IS not FALSE_SYM %prec IS
 
3467
          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
 
3468
        | bool_pri IS UNKNOWN_SYM %prec IS
 
3469
          { $$= new Item_func_isnull($1); }
 
3470
        | bool_pri IS not UNKNOWN_SYM %prec IS
 
3471
          { $$= new Item_func_isnotnull($1); }
 
3472
        | bool_pri
 
3473
        ;
 
3474
 
 
3475
bool_pri:
 
3476
          bool_pri IS NULL_SYM %prec IS
 
3477
          { $$= new Item_func_isnull($1); }
 
3478
        | bool_pri IS not NULL_SYM %prec IS
 
3479
          { $$= new Item_func_isnotnull($1); }
 
3480
        | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
 
3481
          { $$= new Item_func_equal($1,$3); }
 
3482
        | bool_pri comp_op predicate %prec EQ
 
3483
          { $$= (*$2)(0)->create($1,$3); }
 
3484
        | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
 
3485
          { $$= all_any_subquery_creator($1, $2, $3, $5); }
 
3486
        | predicate
 
3487
        ;
 
3488
 
 
3489
predicate:
 
3490
          bit_expr IN_SYM '(' subselect ')'
 
3491
          {
 
3492
            $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
 
3493
          }
 
3494
        | bit_expr not IN_SYM '(' subselect ')'
 
3495
          {
 
3496
            THD *thd= YYTHD;
 
3497
            Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
 
3498
            $$= negate_expression(thd, item);
 
3499
          }
 
3500
        | bit_expr IN_SYM '(' expr ')'
 
3501
          {
 
3502
            $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
 
3503
          }
 
3504
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
 
3505
          { 
 
3506
            $6->push_front($4);
 
3507
            $6->push_front($1);
 
3508
            $$= new (YYTHD->mem_root) Item_func_in(*$6);
 
3509
          }
 
3510
        | bit_expr not IN_SYM '(' expr ')'
 
3511
          {
 
3512
            $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
 
3513
          }
 
3514
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
 
3515
          {
 
3516
            $7->push_front($5);
 
3517
            $7->push_front($1);
 
3518
            Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
 
3519
            item->negate();
 
3520
            $$= item;
 
3521
          }
 
3522
        | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
 
3523
          { $$= new Item_func_between($1,$3,$5); }
 
3524
        | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
 
3525
          {
 
3526
            Item_func_between *item= new Item_func_between($1,$4,$6);
 
3527
            item->negate();
 
3528
            $$= item;
 
3529
          }
 
3530
        | bit_expr LIKE simple_expr opt_escape
 
3531
          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
 
3532
        | bit_expr not LIKE simple_expr opt_escape
 
3533
          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
 
3534
        | bit_expr
 
3535
        ;
 
3536
 
 
3537
bit_expr:
 
3538
          bit_expr '|' bit_expr %prec '|'
 
3539
          { $$= new Item_func_bit_or($1,$3); }
 
3540
        | bit_expr '&' bit_expr %prec '&'
 
3541
          { $$= new Item_func_bit_and($1,$3); }
 
3542
        | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
 
3543
          { $$= new Item_func_shift_left($1,$3); }
 
3544
        | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
 
3545
          { $$= new Item_func_shift_right($1,$3); }
 
3546
        | bit_expr '+' bit_expr %prec '+'
 
3547
          { $$= new Item_func_plus($1,$3); }
 
3548
        | bit_expr '-' bit_expr %prec '-'
 
3549
          { $$= new Item_func_minus($1,$3); }
 
3550
        | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
 
3551
          { $$= new Item_date_add_interval($1,$4,$5,0); }
 
3552
        | bit_expr '-' INTERVAL_SYM expr interval %prec '-'
 
3553
          { $$= new Item_date_add_interval($1,$4,$5,1); }
 
3554
        | bit_expr '*' bit_expr %prec '*'
 
3555
          { $$= new Item_func_mul($1,$3); }
 
3556
        | bit_expr '/' bit_expr %prec '/'
 
3557
          { $$= new Item_func_div($1,$3); }
 
3558
        | bit_expr '%' bit_expr %prec '%'
 
3559
          { $$= new Item_func_mod($1,$3); }
 
3560
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
 
3561
          { $$= new Item_func_int_div($1,$3); }
 
3562
        | bit_expr MOD_SYM bit_expr %prec MOD_SYM
 
3563
          { $$= new Item_func_mod($1,$3); }
 
3564
        | bit_expr '^' bit_expr
 
3565
          { $$= new Item_func_bit_xor($1,$3); }
 
3566
        | simple_expr
 
3567
        ;
 
3568
 
 
3569
or:
 
3570
          OR_SYM
 
3571
       ;
 
3572
 
 
3573
and:
 
3574
          AND_SYM
 
3575
       | AND_AND_SYM
 
3576
       ;
 
3577
 
 
3578
not:
 
3579
          NOT_SYM
 
3580
        ;
 
3581
 
 
3582
comp_op:
 
3583
          EQ     { $$ = &comp_eq_creator; }
 
3584
        | GE     { $$ = &comp_ge_creator; }
 
3585
        | GT_SYM { $$ = &comp_gt_creator; }
 
3586
        | LE     { $$ = &comp_le_creator; }
 
3587
        | LT     { $$ = &comp_lt_creator; }
 
3588
        | NE     { $$ = &comp_ne_creator; }
 
3589
        ;
 
3590
 
 
3591
all_or_any:
 
3592
          ALL     { $$ = 1; }
 
3593
        | ANY_SYM { $$ = 0; }
 
3594
        ;
 
3595
 
 
3596
simple_expr:
 
3597
          simple_ident
 
3598
        | function_call_keyword
 
3599
        | function_call_nonkeyword
 
3600
        | function_call_generic
 
3601
        | function_call_conflict
 
3602
        | simple_expr COLLATE_SYM ident_or_text %prec NEG
 
3603
          {
 
3604
            THD *thd= YYTHD;
 
3605
            Item *i1= new (thd->mem_root) Item_string($3.str,
 
3606
                                                      $3.length,
 
3607
                                                      thd->charset());
 
3608
            $$= new (thd->mem_root) Item_func_set_collation($1, i1);
 
3609
          }
 
3610
        | literal
 
3611
        | param_marker
 
3612
        | variable
 
3613
        | sum_expr
 
3614
        | '+' simple_expr %prec NEG { $$= $2; }
 
3615
        | '-' simple_expr %prec NEG
 
3616
          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
 
3617
        | '~' simple_expr %prec NEG
 
3618
          { $$= new (YYTHD->mem_root) Item_func_bit_neg($2); }
 
3619
        | '(' subselect ')'
 
3620
          { 
 
3621
            $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
 
3622
          }
 
3623
        | '(' expr ')' { $$= $2; }
 
3624
        | '(' expr ',' expr_list ')'
 
3625
          {
 
3626
            $4->push_front($2);
 
3627
            $$= new (YYTHD->mem_root) Item_row(*$4);
 
3628
          }
 
3629
        | ROW_SYM '(' expr ',' expr_list ')'
 
3630
          {
 
3631
            $5->push_front($3);
 
3632
            $$= new (YYTHD->mem_root) Item_row(*$5);
 
3633
          }
 
3634
        | EXISTS '(' subselect ')'
 
3635
          {
 
3636
            $$= new (YYTHD->mem_root) Item_exists_subselect($3);
 
3637
          }
 
3638
        | '{' ident expr '}' { $$= $3; }
 
3639
        | BINARY simple_expr %prec NEG
 
3640
          {
 
3641
            $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
 
3642
                                 &my_charset_bin);
 
3643
          }
 
3644
        | CAST_SYM '(' expr AS cast_type ')'
 
3645
          {
 
3646
            LEX *lex= Lex;
 
3647
            $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
 
3648
                                 lex->charset);
 
3649
            if (!$$)
 
3650
              MYSQL_YYABORT;
 
3651
          }
 
3652
        | CASE_SYM opt_expr when_list opt_else END
 
3653
          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
 
3654
        | CONVERT_SYM '(' expr ',' cast_type ')'
 
3655
          {
 
3656
            $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
 
3657
                                 Lex->charset);
 
3658
            if (!$$)
 
3659
              MYSQL_YYABORT;
 
3660
          }
 
3661
        | CONVERT_SYM '(' expr USING charset_name ')'
 
3662
          { $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5); }
 
3663
        | DEFAULT '(' simple_ident ')'
 
3664
          {
 
3665
            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
 
3666
                                                         $3);
 
3667
          }
 
3668
        | VALUES '(' simple_ident_nospvar ')'
 
3669
          {
 
3670
            $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
 
3671
                                                        $3);
 
3672
          }
 
3673
        | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
 
3674
          /* we cannot put interval before - */
 
3675
          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
 
3676
        ;
 
3677
 
 
3678
/*
 
3679
  Function call syntax using official SQL 2003 keywords.
 
3680
  Because the function name is an official token,
 
3681
  a dedicated grammar rule is needed in the parser.
 
3682
  There is no potential for conflicts
 
3683
*/
 
3684
function_call_keyword:
 
3685
          CHAR_SYM '(' expr_list ')'
 
3686
          { $$= new (YYTHD->mem_root) Item_func_char(*$3); }
 
3687
        | CHAR_SYM '(' expr_list USING charset_name ')'
 
3688
          { $$= new (YYTHD->mem_root) Item_func_char(*$3, $5); }
 
3689
        | CURRENT_USER optional_braces
 
3690
          {
 
3691
            $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
 
3692
            Lex->set_stmt_unsafe();
 
3693
          }
 
3694
        | DATE_SYM '(' expr ')'
 
3695
          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
 
3696
        | DAY_SYM '(' expr ')'
 
3697
          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
 
3698
        | HOUR_SYM '(' expr ')'
 
3699
          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
 
3700
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
 
3701
          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3702
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
 
3703
          {
 
3704
            THD *thd= YYTHD;
 
3705
            List<Item> *list= new (thd->mem_root) List<Item>;
 
3706
            list->push_front($5);
 
3707
            list->push_front($3);
 
3708
            Item_row *item= new (thd->mem_root) Item_row(*list);
 
3709
            $$= new (thd->mem_root) Item_func_interval(item);
 
3710
          }
 
3711
        | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
 
3712
          {
 
3713
            THD *thd= YYTHD;
 
3714
            $7->push_front($5);
 
3715
            $7->push_front($3);
 
3716
            Item_row *item= new (thd->mem_root) Item_row(*$7);
 
3717
            $$= new (thd->mem_root) Item_func_interval(item);
 
3718
          }
 
3719
        | LEFT '(' expr ',' expr ')'
 
3720
          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
 
3721
        | MINUTE_SYM '(' expr ')'
 
3722
          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
 
3723
        | MONTH_SYM '(' expr ')'
 
3724
          { $$= new (YYTHD->mem_root) Item_func_month($3); }
 
3725
        | RIGHT '(' expr ',' expr ')'
 
3726
          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
 
3727
        | SECOND_SYM '(' expr ')'
 
3728
          { $$= new (YYTHD->mem_root) Item_func_second($3); }
 
3729
        | TIME_SYM '(' expr ')'
 
3730
          { $$= new (YYTHD->mem_root) Item_time_typecast($3); }
 
3731
        | TIMESTAMP '(' expr ')'
 
3732
          { $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
 
3733
        | TIMESTAMP '(' expr ',' expr ')'
 
3734
          { $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
 
3735
        | TRIM '(' expr ')'
 
3736
          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
 
3737
        | TRIM '(' LEADING expr FROM expr ')'
 
3738
          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
 
3739
        | TRIM '(' TRAILING expr FROM expr ')'
 
3740
          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
 
3741
        | TRIM '(' BOTH expr FROM expr ')'
 
3742
          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
 
3743
        | TRIM '(' LEADING FROM expr ')'
 
3744
          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
 
3745
        | TRIM '(' TRAILING FROM expr ')'
 
3746
          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
 
3747
        | TRIM '(' BOTH FROM expr ')'
 
3748
          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
 
3749
        | TRIM '(' expr FROM expr ')'
 
3750
          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
 
3751
        | USER '(' ')'
 
3752
          {
 
3753
            $$= new (YYTHD->mem_root) Item_func_user();
 
3754
            Lex->set_stmt_unsafe();
 
3755
          }
 
3756
        | YEAR_SYM '(' expr ')'
 
3757
          { $$= new (YYTHD->mem_root) Item_func_year($3); }
 
3758
        ;
 
3759
 
 
3760
/*
 
3761
  Function calls using non reserved keywords, with special syntaxic forms.
 
3762
  Dedicated grammar rules are needed because of the syntax,
 
3763
  but also have the potential to cause incompatibilities with other
 
3764
  parts of the language.
 
3765
  MAINTAINER:
 
3766
  The only reasons a function should be added here are:
 
3767
  - for compatibility reasons with another SQL syntax (CURDATE),
 
3768
  - for typing reasons (GET_FORMAT)
 
3769
  Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
 
3770
  discouraged.
 
3771
*/
 
3772
function_call_nonkeyword:
 
3773
          ADDDATE_SYM '(' expr ',' expr ')'
 
3774
          {
 
3775
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3776
                                                             INTERVAL_DAY, 0);
 
3777
          }
 
3778
        | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
 
3779
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
 
3780
        | CURDATE optional_braces
 
3781
          {
 
3782
            $$= new (YYTHD->mem_root) Item_func_curdate_local();
 
3783
          }
 
3784
        | CURTIME optional_braces
 
3785
          {
 
3786
            $$= new (YYTHD->mem_root) Item_func_curtime_local();
 
3787
          }
 
3788
        | CURTIME '(' expr ')'
 
3789
          {
 
3790
            $$= new (YYTHD->mem_root) Item_func_curtime_local($3);
 
3791
          }
 
3792
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
 
3793
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
 
3794
        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
 
3795
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
 
3796
        | EXTRACT_SYM '(' interval FROM expr ')'
 
3797
          { $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
 
3798
        | GET_FORMAT '(' date_time_type  ',' expr ')'
 
3799
          { $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
 
3800
        | NOW_SYM optional_braces
 
3801
          {
 
3802
            $$= new (YYTHD->mem_root) Item_func_now_local();
 
3803
          }
 
3804
        | NOW_SYM '(' expr ')'
 
3805
          {
 
3806
            $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3807
          }
 
3808
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
 
3809
          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
 
3810
        | SUBDATE_SYM '(' expr ',' expr ')'
 
3811
          {
 
3812
            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
 
3813
                                                             INTERVAL_DAY, 1);
 
3814
          }
 
3815
        | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
 
3816
          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
 
3817
        | SUBSTRING '(' expr ',' expr ',' expr ')'
 
3818
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3819
        | SUBSTRING '(' expr ',' expr ')'
 
3820
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3821
        | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
 
3822
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
 
3823
        | SUBSTRING '(' expr FROM expr ')'
 
3824
          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
 
3825
        | SYSDATE optional_braces
 
3826
          {
 
3827
            if (global_system_variables.sysdate_is_now == 0)
 
3828
              $$= new (YYTHD->mem_root) Item_func_sysdate_local();
 
3829
            else
 
3830
              $$= new (YYTHD->mem_root) Item_func_now_local();
 
3831
          }
 
3832
        | SYSDATE '(' expr ')'
 
3833
          {
 
3834
            if (global_system_variables.sysdate_is_now == 0)
 
3835
              $$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
 
3836
            else
 
3837
              $$= new (YYTHD->mem_root) Item_func_now_local($3);
 
3838
          }
 
3839
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
 
3840
          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
 
3841
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
 
3842
          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
 
3843
        | UTC_DATE_SYM optional_braces
 
3844
          {
 
3845
            $$= new (YYTHD->mem_root) Item_func_curdate_utc();
 
3846
          }
 
3847
        | UTC_TIME_SYM optional_braces
 
3848
          {
 
3849
            $$= new (YYTHD->mem_root) Item_func_curtime_utc();
 
3850
          }
 
3851
        | UTC_TIMESTAMP_SYM optional_braces
 
3852
          {
 
3853
            $$= new (YYTHD->mem_root) Item_func_now_utc();
 
3854
          }
 
3855
        ;
 
3856
 
 
3857
/*
 
3858
  Functions calls using a non reserved keyword, and using a regular syntax.
 
3859
  Because the non reserved keyword is used in another part of the grammar,
 
3860
  a dedicated rule is needed here.
 
3861
*/
 
3862
function_call_conflict:
 
3863
          ASCII_SYM '(' expr ')'
 
3864
          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
 
3865
        | CHARSET '(' expr ')'
 
3866
          { $$= new (YYTHD->mem_root) Item_func_charset($3); }
 
3867
        | COALESCE '(' expr_list ')'
 
3868
          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
 
3869
        | COLLATION_SYM '(' expr ')'
 
3870
          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
 
3871
        | DATABASE '(' ')'
 
3872
          {
 
3873
            $$= new (YYTHD->mem_root) Item_func_database();
 
3874
          }
 
3875
        | IF '(' expr ',' expr ',' expr ')'
 
3876
          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
 
3877
        | MICROSECOND_SYM '(' expr ')'
 
3878
          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
 
3879
        | MOD_SYM '(' expr ',' expr ')'
 
3880
          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
 
3881
        | OLD_PASSWORD '(' expr ')'
 
3882
          { $$=  new (YYTHD->mem_root) Item_func_old_password($3); }
 
3883
        | PASSWORD '(' expr ')'
 
3884
          {
 
3885
            THD *thd= YYTHD;
 
3886
            Item* i1;
 
3887
            if (thd->variables.old_passwords)
 
3888
              i1= new (thd->mem_root) Item_func_old_password($3);
 
3889
            else
 
3890
              i1= new (thd->mem_root) Item_func_password($3);
 
3891
            $$= i1;
 
3892
          }
 
3893
        | QUARTER_SYM '(' expr ')'
 
3894
          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
 
3895
        | REPEAT_SYM '(' expr ',' expr ')'
 
3896
          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
 
3897
        | REPLACE '(' expr ',' expr ',' expr ')'
 
3898
          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
 
3899
        | REVERSE_SYM '(' expr ')'
 
3900
          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
 
3901
        | TRUNCATE_SYM '(' expr ',' expr ')'
 
3902
          { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
 
3903
        | WEEK_SYM '(' expr ')'
 
3904
          {
 
3905
            THD *thd= YYTHD;
 
3906
            Item *i1= new (thd->mem_root) Item_int((char*) "0",
 
3907
                                           thd->variables.default_week_format,
 
3908
                                                   1);
 
3909
 
 
3910
            $$= new (thd->mem_root) Item_func_week($3, i1);
 
3911
          }
 
3912
        | WEEK_SYM '(' expr ',' expr ')'
 
3913
          { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
 
3914
        | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
 
3915
          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
 
3916
        | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
 
3917
          {
 
3918
            $$= new (YYTHD->mem_root)
 
3919
                Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
 
3920
          }
 
3921
        | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
 
3922
          {
 
3923
            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
 
3924
            $$= new (YYTHD->mem_root)
 
3925
                Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
 
3926
          }
 
3927
        ;
 
3928
 
 
3929
/*
 
3930
  Regular function calls.
 
3931
  The function name is *not* a token, and therefore is guaranteed to not
 
3932
  introduce side effects to the language in general.
 
3933
  MAINTAINER:
 
3934
  All the new functions implemented for new features should fit into
 
3935
  this category. The place to implement the function itself is
 
3936
  in sql/item_create.cc
 
3937
*/
 
3938
function_call_generic:
 
3939
          IDENT_sys '('
 
3940
          {
 
3941
#ifdef HAVE_DLOPEN
 
3942
            udf_func *udf= 0;
 
3943
            LEX *lex= Lex;
 
3944
            if (using_udf_functions &&
 
3945
                (udf= find_udf($1.str, $1.length)) &&
 
3946
                udf->type == UDFTYPE_AGGREGATE)
 
3947
            {
 
3948
              if (lex->current_select->inc_in_sum_expr())
 
3949
              {
 
3950
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
3951
                MYSQL_YYABORT;
 
3952
              }
 
3953
            }
 
3954
            /* Temporary placing the result of find_udf in $3 */
 
3955
            $<udf>$= udf;
 
3956
#endif
 
3957
          }
 
3958
          opt_udf_expr_list ')'
 
3959
          {
 
3960
            THD *thd= YYTHD;
 
3961
            Create_func *builder;
 
3962
            Item *item= NULL;
 
3963
 
 
3964
            /*
 
3965
              Implementation note:
 
3966
              names are resolved with the following order:
 
3967
              - MySQL native functions,
 
3968
              - User Defined Functions,
 
3969
              - Stored Functions (assuming the current <use> database)
 
3970
 
 
3971
              This will be revised with WL#2128 (SQL PATH)
 
3972
            */
 
3973
            builder= find_native_function_builder(thd, $1);
 
3974
            if (builder)
 
3975
            {
 
3976
              item= builder->create(thd, $1, $4);
 
3977
            }
 
3978
            else
 
3979
            {
 
3980
#ifdef HAVE_DLOPEN
 
3981
              /* Retrieving the result of find_udf */
 
3982
              udf_func *udf= $<udf>3;
 
3983
 
 
3984
              {
 
3985
                if (udf->type == UDFTYPE_AGGREGATE)
 
3986
                {
 
3987
                  Select->in_sum_expr--;
 
3988
                }
 
3989
 
 
3990
                item= Create_udf_func::s_singleton.create(thd, udf, $4);
 
3991
              }
 
3992
#endif
 
3993
            }
 
3994
 
 
3995
            if (! ($$= item))
 
3996
            {
 
3997
              MYSQL_YYABORT;
 
3998
            }
 
3999
          }
 
4000
        ;
 
4001
 
 
4002
opt_udf_expr_list:
 
4003
        /* empty */     { $$= NULL; }
 
4004
        | udf_expr_list { $$= $1; }
 
4005
        ;
 
4006
 
 
4007
udf_expr_list:
 
4008
          udf_expr
 
4009
          {
 
4010
            $$= new (YYTHD->mem_root) List<Item>;
 
4011
            $$->push_back($1);
 
4012
          }
 
4013
        | udf_expr_list ',' udf_expr
 
4014
          {
 
4015
            $1->push_back($3);
 
4016
            $$= $1;
 
4017
          }
 
4018
        ;
 
4019
 
 
4020
udf_expr:
 
4021
          remember_name expr remember_end select_alias
 
4022
          {
 
4023
            /*
 
4024
             Use Item::name as a storage for the attribute value of user
 
4025
             defined function argument. It is safe to use Item::name
 
4026
             because the syntax will not allow having an explicit name here.
 
4027
             See WL#1017 re. udf attributes.
 
4028
            */
 
4029
            if ($4.str)
 
4030
            {
 
4031
              $2->is_autogenerated_name= FALSE;
 
4032
              $2->set_name($4.str, $4.length, system_charset_info);
 
4033
            }
 
4034
            else
 
4035
              $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
 
4036
            $$= $2;
 
4037
          }
 
4038
        ;
 
4039
 
 
4040
sum_expr:
 
4041
          AVG_SYM '(' in_sum_expr ')'
 
4042
          { $$=new Item_sum_avg($3); }
 
4043
        | AVG_SYM '(' DISTINCT in_sum_expr ')'
 
4044
          { $$=new Item_sum_avg_distinct($4); }
 
4045
        | BIT_AND  '(' in_sum_expr ')'
 
4046
          { $$=new Item_sum_and($3); }
 
4047
        | BIT_OR  '(' in_sum_expr ')'
 
4048
          { $$=new Item_sum_or($3); }
 
4049
        | BIT_XOR  '(' in_sum_expr ')'
 
4050
          { $$=new Item_sum_xor($3); }
 
4051
        | COUNT_SYM '(' opt_all '*' ')'
 
4052
          { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
 
4053
        | COUNT_SYM '(' in_sum_expr ')'
 
4054
          { $$=new Item_sum_count($3); }
 
4055
        | COUNT_SYM '(' DISTINCT
 
4056
          { Select->in_sum_expr++; }
 
4057
          expr_list
 
4058
          { Select->in_sum_expr--; }
 
4059
          ')'
 
4060
          { $$=new Item_sum_count_distinct(* $5); }
 
4061
        | MIN_SYM '(' in_sum_expr ')'
 
4062
          { $$=new Item_sum_min($3); }
 
4063
        /*
 
4064
          According to ANSI SQL, DISTINCT is allowed and has
 
4065
          no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
 
4066
          is processed like an ordinary MIN | MAX()
 
4067
        */
 
4068
        | MIN_SYM '(' DISTINCT in_sum_expr ')'
 
4069
          { $$=new Item_sum_min($4); }
 
4070
        | MAX_SYM '(' in_sum_expr ')'
 
4071
          { $$=new Item_sum_max($3); }
 
4072
        | MAX_SYM '(' DISTINCT in_sum_expr ')'
 
4073
          { $$=new Item_sum_max($4); }
 
4074
        | STD_SYM '(' in_sum_expr ')'
 
4075
          { $$=new Item_sum_std($3, 0); }
 
4076
        | VARIANCE_SYM '(' in_sum_expr ')'
 
4077
          { $$=new Item_sum_variance($3, 0); }
 
4078
        | STDDEV_SAMP_SYM '(' in_sum_expr ')'
 
4079
          { $$=new Item_sum_std($3, 1); }
 
4080
        | VAR_SAMP_SYM '(' in_sum_expr ')'
 
4081
          { $$=new Item_sum_variance($3, 1); }
 
4082
        | SUM_SYM '(' in_sum_expr ')'
 
4083
          { $$=new Item_sum_sum($3); }
 
4084
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
 
4085
          { $$=new Item_sum_sum_distinct($4); }
 
4086
        | GROUP_CONCAT_SYM '(' opt_distinct
 
4087
          { Select->in_sum_expr++; }
 
4088
          expr_list opt_gorder_clause
 
4089
          opt_gconcat_separator
 
4090
          ')'
 
4091
          {
 
4092
            SELECT_LEX *sel= Select;
 
4093
            sel->in_sum_expr--;
 
4094
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
 
4095
                                          sel->gorder_list, $7);
 
4096
            $5->empty();
 
4097
          }
 
4098
        ;
 
4099
 
 
4100
variable:
 
4101
          '@'
 
4102
          {
 
4103
            if (! Lex->parsing_options.allows_variable)
 
4104
            {
 
4105
              my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
 
4106
              MYSQL_YYABORT;
 
4107
            }
 
4108
          }
 
4109
          variable_aux
 
4110
          {
 
4111
            $$= $3;
 
4112
          }
 
4113
        ;
 
4114
 
 
4115
variable_aux:
 
4116
          ident_or_text SET_VAR expr
 
4117
          {
 
4118
            $$= new Item_func_set_user_var($1, $3);
 
4119
          }
 
4120
        | ident_or_text
 
4121
          {
 
4122
            $$= new Item_func_get_user_var($1);
 
4123
          }
 
4124
        | '@' opt_var_ident_type ident_or_text opt_component
 
4125
          {
 
4126
            /* disallow "SELECT @@global.global.variable" */
 
4127
            if ($3.str && $4.str && check_reserved_words(&$3))
 
4128
            {
 
4129
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4130
              MYSQL_YYABORT;
 
4131
            }
 
4132
            if (!($$= get_system_var(YYTHD, $2, $3, $4)))
 
4133
              MYSQL_YYABORT;
 
4134
            if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
 
4135
              Lex->set_stmt_unsafe();
 
4136
          }
 
4137
        ;
 
4138
 
 
4139
opt_distinct:
 
4140
          /* empty */ { $$ = 0; }
 
4141
        | DISTINCT    { $$ = 1; }
 
4142
        ;
 
4143
 
 
4144
opt_gconcat_separator:
 
4145
          /* empty */
 
4146
            {
 
4147
              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
 
4148
            }
 
4149
        | SEPARATOR_SYM text_string { $$ = $2; }
 
4150
        ;
 
4151
 
 
4152
opt_gorder_clause:
 
4153
          /* empty */
 
4154
          {
 
4155
            Select->gorder_list = NULL;
 
4156
          }
 
4157
        | order_clause
 
4158
          {
 
4159
            SELECT_LEX *select= Select;
 
4160
            select->gorder_list=
 
4161
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
 
4162
                                     sizeof(st_sql_list));
 
4163
            select->order_list.empty();
 
4164
          }
 
4165
        ;
 
4166
 
 
4167
in_sum_expr:
 
4168
          opt_all
 
4169
          {
 
4170
            LEX *lex= Lex;
 
4171
            if (lex->current_select->inc_in_sum_expr())
 
4172
            {
 
4173
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4174
              MYSQL_YYABORT;
 
4175
            }
 
4176
          }
 
4177
          expr
 
4178
          {
 
4179
            Select->in_sum_expr--;
 
4180
            $$= $3;
 
4181
          }
 
4182
        ;
 
4183
 
 
4184
cast_type:
 
4185
          BINARY opt_len
 
4186
          { $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
 
4187
        | CHAR_SYM opt_len opt_binary
 
4188
          { $$=ITEM_CAST_CHAR; Lex->dec= 0; }
 
4189
        | NCHAR_SYM opt_len
 
4190
          { $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; Lex->dec=0; }
 
4191
        | SIGNED_SYM
 
4192
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4193
        | SIGNED_SYM INT_SYM
 
4194
          { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4195
        | UNSIGNED
 
4196
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4197
        | UNSIGNED INT_SYM
 
4198
          { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4199
        | DATE_SYM
 
4200
          { $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4201
        | TIME_SYM
 
4202
          { $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4203
        | DATETIME
 
4204
          { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
 
4205
        | DECIMAL_SYM float_options
 
4206
          { $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
 
4207
        ;
 
4208
 
 
4209
expr_list:
 
4210
          expr
 
4211
          {
 
4212
            $$= new (YYTHD->mem_root) List<Item>;
 
4213
            $$->push_back($1);
 
4214
          }
 
4215
        | expr_list ',' expr
 
4216
          {
 
4217
            $1->push_back($3);
 
4218
            $$= $1;
 
4219
          }
 
4220
        ;
 
4221
 
 
4222
opt_expr:
 
4223
          /* empty */    { $$= NULL; }
 
4224
        | expr           { $$= $1; }
 
4225
        ;
 
4226
 
 
4227
opt_else:
 
4228
          /* empty */  { $$= NULL; }
 
4229
        | ELSE expr    { $$= $2; }
 
4230
        ;
 
4231
 
 
4232
when_list:
 
4233
          WHEN_SYM expr THEN_SYM expr
 
4234
          {
 
4235
            $$= new List<Item>;
 
4236
            $$->push_back($2);
 
4237
            $$->push_back($4);
 
4238
          }
 
4239
        | when_list WHEN_SYM expr THEN_SYM expr
 
4240
          {
 
4241
            $1->push_back($3);
 
4242
            $1->push_back($5);
 
4243
            $$= $1;
 
4244
          }
 
4245
        ;
 
4246
 
 
4247
/* Equivalent to <table reference> in the SQL:2003 standard. */
 
4248
/* Warning - may return NULL in case of incomplete SELECT */
 
4249
table_ref:
 
4250
          table_factor { $$=$1; }
 
4251
        | join_table
 
4252
          {
 
4253
            LEX *lex= Lex;
 
4254
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
 
4255
              MYSQL_YYABORT;
 
4256
          }
 
4257
        ;
 
4258
 
 
4259
join_table_list:
 
4260
          derived_table_list { MYSQL_YYABORT_UNLESS($$=$1); }
 
4261
        ;
 
4262
 
 
4263
/*
 
4264
  The ODBC escape syntax for Outer Join is: '{' OJ join_table '}'
 
4265
  The parser does not define OJ as a token, any ident is accepted
 
4266
  instead in $2 (ident). Also, all productions from table_ref can
 
4267
  be escaped, not only join_table. Both syntax extensions are safe
 
4268
  and are ignored.
 
4269
*/
 
4270
esc_table_ref:
 
4271
        table_ref { $$=$1; }
 
4272
      | '{' ident table_ref '}' { $$=$3; }
 
4273
      ;
 
4274
 
 
4275
/* Equivalent to <table reference list> in the SQL:2003 standard. */
 
4276
/* Warning - may return NULL in case of incomplete SELECT */
 
4277
derived_table_list:
 
4278
          esc_table_ref { $$=$1; }
 
4279
        | derived_table_list ',' esc_table_ref
 
4280
          {
 
4281
            MYSQL_YYABORT_UNLESS($1 && ($$=$3));
 
4282
          }
 
4283
        ;
 
4284
 
 
4285
/*
 
4286
  Notice that JOIN is a left-associative operation, and it must be parsed
 
4287
  as such, that is, the parser must process first the left join operand
 
4288
  then the right one. Such order of processing ensures that the parser
 
4289
  produces correct join trees which is essential for semantic analysis
 
4290
  and subsequent optimization phases.
 
4291
*/
 
4292
join_table:
 
4293
          /* INNER JOIN variants */
 
4294
          /*
 
4295
            Use %prec to evaluate production 'table_ref' before 'normal_join'
 
4296
            so that [INNER | CROSS] JOIN is properly nested as other
 
4297
            left-associative joins.
 
4298
          */
 
4299
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
 
4300
          { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); }
 
4301
        | table_ref STRAIGHT_JOIN table_factor
 
4302
          { MYSQL_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
 
4303
        | table_ref normal_join table_ref
 
4304
          ON
 
4305
          {
 
4306
            MYSQL_YYABORT_UNLESS($1 && $3);
 
4307
            /* Change the current name resolution context to a local context. */
 
4308
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
4309
              MYSQL_YYABORT;
 
4310
            Select->parsing_place= IN_ON;
 
4311
          }
 
4312
          expr
 
4313
          {
 
4314
            add_join_on($3,$6);
 
4315
            Lex->pop_context();
 
4316
            Select->parsing_place= NO_MATTER;
 
4317
          }
 
4318
        | table_ref STRAIGHT_JOIN table_factor
 
4319
          ON
 
4320
          {
 
4321
            MYSQL_YYABORT_UNLESS($1 && $3);
 
4322
            /* Change the current name resolution context to a local context. */
 
4323
            if (push_new_name_resolution_context(YYTHD, $1, $3))
 
4324
              MYSQL_YYABORT;
 
4325
            Select->parsing_place= IN_ON;
 
4326
          }
 
4327
          expr
 
4328
          {
 
4329
            $3->straight=1;
 
4330
            add_join_on($3,$6);
 
4331
            Lex->pop_context();
 
4332
            Select->parsing_place= NO_MATTER;
 
4333
          }
 
4334
        | table_ref normal_join table_ref
 
4335
          USING
 
4336
          {
 
4337
            MYSQL_YYABORT_UNLESS($1 && $3);
 
4338
          }
 
4339
          '(' using_list ')'
 
4340
          { add_join_natural($1,$3,$7,Select); $$=$3; }
 
4341
        | table_ref NATURAL JOIN_SYM table_factor
 
4342
          {
 
4343
            MYSQL_YYABORT_UNLESS($1 && ($$=$4));
 
4344
            add_join_natural($1,$4,NULL,Select);
 
4345
          }
 
4346
 
 
4347
          /* LEFT JOIN variants */
 
4348
        | table_ref LEFT opt_outer JOIN_SYM table_ref
 
4349
          ON
 
4350
          {
 
4351
            MYSQL_YYABORT_UNLESS($1 && $5);
 
4352
            /* Change the current name resolution context to a local context. */
 
4353
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
4354
              MYSQL_YYABORT;
 
4355
            Select->parsing_place= IN_ON;
 
4356
          }
 
4357
          expr
 
4358
          {
 
4359
            add_join_on($5,$8);
 
4360
            Lex->pop_context();
 
4361
            $5->outer_join|=JOIN_TYPE_LEFT;
 
4362
            $$=$5;
 
4363
            Select->parsing_place= NO_MATTER;
 
4364
          }
 
4365
        | table_ref LEFT opt_outer JOIN_SYM table_factor
 
4366
          {
 
4367
            MYSQL_YYABORT_UNLESS($1 && $5);
 
4368
          }
 
4369
          USING '(' using_list ')'
 
4370
          { 
 
4371
            add_join_natural($1,$5,$9,Select); 
 
4372
            $5->outer_join|=JOIN_TYPE_LEFT; 
 
4373
            $$=$5; 
 
4374
          }
 
4375
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
 
4376
          {
 
4377
            MYSQL_YYABORT_UNLESS($1 && $6);
 
4378
            add_join_natural($1,$6,NULL,Select);
 
4379
            $6->outer_join|=JOIN_TYPE_LEFT;
 
4380
            $$=$6;
 
4381
          }
 
4382
 
 
4383
          /* RIGHT JOIN variants */
 
4384
        | table_ref RIGHT opt_outer JOIN_SYM table_ref
 
4385
          ON
 
4386
          {
 
4387
            MYSQL_YYABORT_UNLESS($1 && $5);
 
4388
            /* Change the current name resolution context to a local context. */
 
4389
            if (push_new_name_resolution_context(YYTHD, $1, $5))
 
4390
              MYSQL_YYABORT;
 
4391
            Select->parsing_place= IN_ON;
 
4392
          }
 
4393
          expr
 
4394
          {
 
4395
            LEX *lex= Lex;
 
4396
            if (!($$= lex->current_select->convert_right_join()))
 
4397
              MYSQL_YYABORT;
 
4398
            add_join_on($$, $8);
 
4399
            Lex->pop_context();
 
4400
            Select->parsing_place= NO_MATTER;
 
4401
          }
 
4402
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
 
4403
          {
 
4404
            MYSQL_YYABORT_UNLESS($1 && $5);
 
4405
          }
 
4406
          USING '(' using_list ')'
 
4407
          {
 
4408
            LEX *lex= Lex;
 
4409
            if (!($$= lex->current_select->convert_right_join()))
 
4410
              MYSQL_YYABORT;
 
4411
            add_join_natural($$,$5,$9,Select);
 
4412
          }
 
4413
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
 
4414
          {
 
4415
            MYSQL_YYABORT_UNLESS($1 && $6);
 
4416
            add_join_natural($6,$1,NULL,Select);
 
4417
            LEX *lex= Lex;
 
4418
            if (!($$= lex->current_select->convert_right_join()))
 
4419
              MYSQL_YYABORT;
 
4420
          }
 
4421
        ;
 
4422
 
 
4423
normal_join:
 
4424
          JOIN_SYM {}
 
4425
        | INNER_SYM JOIN_SYM {}
 
4426
        | CROSS JOIN_SYM {}
 
4427
        ;
 
4428
 
 
4429
/* 
 
4430
   This is a flattening of the rules <table factor> and <table primary>
 
4431
   in the SQL:2003 standard, since we don't have <sample clause>
 
4432
 
 
4433
   I.e.
 
4434
   <table factor> ::= <table primary> [ <sample clause> ]
 
4435
*/   
 
4436
/* Warning - may return NULL in case of incomplete SELECT */
 
4437
table_factor:
 
4438
          {
 
4439
            SELECT_LEX *sel= Select;
 
4440
            sel->table_join_options= 0;
 
4441
          }
 
4442
          table_ident opt_table_alias opt_key_definition
 
4443
          {
 
4444
            if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
 
4445
                                                Select->get_table_join_options(),
 
4446
                                                Lex->lock_option,
 
4447
                                                Select->pop_index_hints())))
 
4448
              MYSQL_YYABORT;
 
4449
            Select->add_joined_table($$);
 
4450
          }
 
4451
        | select_derived_init get_select_lex select_derived2
 
4452
          {
 
4453
            LEX *lex= Lex;
 
4454
            SELECT_LEX *sel= lex->current_select;
 
4455
            if ($1)
 
4456
            {
 
4457
              if (sel->set_braces(1))
 
4458
              {
 
4459
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
4460
                MYSQL_YYABORT;
 
4461
              }
 
4462
              /* select in braces, can't contain global parameters */
 
4463
              if (sel->master_unit()->fake_select_lex)
 
4464
                sel->master_unit()->global_parameters=
 
4465
                   sel->master_unit()->fake_select_lex;
 
4466
            }
 
4467
            if ($2->init_nested_join(lex->thd))
 
4468
              MYSQL_YYABORT;
 
4469
            $$= 0;
 
4470
            /* incomplete derived tables return NULL, we must be
 
4471
               nested in select_derived rule to be here. */
 
4472
          }
 
4473
          /*
 
4474
            Represents a flattening of the following rules from the SQL:2003
 
4475
            standard. This sub-rule corresponds to the sub-rule
 
4476
            <table primary> ::= ... | <derived table> [ AS ] <correlation name>
 
4477
            
 
4478
            The following rules have been flattened into query_expression_body
 
4479
            (since we have no <with clause>).
 
4480
 
 
4481
            <derived table> ::= <table subquery>
 
4482
            <table subquery> ::= <subquery>
 
4483
            <subquery> ::= <left paren> <query expression> <right paren>
 
4484
            <query expression> ::= [ <with clause> ] <query expression body>
 
4485
 
 
4486
            For the time being we use the non-standard rule
 
4487
            select_derived_union which is a compromise between the standard
 
4488
            and our parser. Possibly this rule could be replaced by our
 
4489
            query_expression_body.
 
4490
          */
 
4491
        | '(' get_select_lex select_derived_union ')' opt_table_alias
 
4492
          {
 
4493
            /* Use $2 instead of Lex->current_select as derived table will
 
4494
               alter value of Lex->current_select. */
 
4495
            if (!($3 || $5) && $2->embedding &&
 
4496
                !$2->embedding->nested_join->join_list.elements)
 
4497
            {
 
4498
              /* we have a derived table ($3 == NULL) but no alias,
 
4499
                 Since we are nested in further parentheses so we
 
4500
                 can pass NULL to the outer level parentheses
 
4501
                 Permits parsing of "((((select ...))) as xyz)" */
 
4502
              $$= 0;
 
4503
            }
 
4504
            else if (!$3)
 
4505
            {
 
4506
              /* Handle case of derived table, alias may be NULL if there
 
4507
                 are no outer parentheses, add_table_to_list() will throw
 
4508
                 error in this case */
 
4509
              LEX *lex=Lex;
 
4510
              SELECT_LEX *sel= lex->current_select;
 
4511
              SELECT_LEX_UNIT *unit= sel->master_unit();
 
4512
              lex->current_select= sel= unit->outer_select();
 
4513
              if (!($$= sel->add_table_to_list(lex->thd,
 
4514
                                               new Table_ident(unit), $5, 0,
 
4515
                                               TL_READ)))
 
4516
 
 
4517
                MYSQL_YYABORT;
 
4518
              sel->add_joined_table($$);
 
4519
              lex->pop_context();
 
4520
            }
 
4521
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
 
4522
            {
 
4523
              /* simple nested joins cannot have aliases or unions */
 
4524
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4525
              MYSQL_YYABORT;
 
4526
            }
 
4527
            else
 
4528
              $$= $3;
 
4529
          }
 
4530
        ;
 
4531
 
 
4532
select_derived_union:
 
4533
          select_derived opt_order_clause opt_limit_clause
 
4534
        | select_derived_union
 
4535
          UNION_SYM
 
4536
          union_option
 
4537
          {
 
4538
            if (add_select_to_union_list(Lex, (bool)$3))
 
4539
              MYSQL_YYABORT;
 
4540
          }
 
4541
          query_specification
 
4542
          {
 
4543
            /*
 
4544
              Remove from the name resolution context stack the context of the
 
4545
              last select in the union.
 
4546
             */
 
4547
            Lex->pop_context();
 
4548
          }
 
4549
          opt_order_clause opt_limit_clause
 
4550
        ;
 
4551
 
 
4552
/* The equivalent of select_init2 for nested queries. */
 
4553
select_init2_derived:
 
4554
          select_part2_derived
 
4555
          {
 
4556
            LEX *lex= Lex;
 
4557
            SELECT_LEX * sel= lex->current_select;
 
4558
            if (lex->current_select->set_braces(0))
 
4559
            {
 
4560
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4561
              MYSQL_YYABORT;
 
4562
            }
 
4563
            if (sel->linkage == UNION_TYPE &&
 
4564
                sel->master_unit()->first_select()->braces)
 
4565
            {
 
4566
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4567
              MYSQL_YYABORT;
 
4568
            }
 
4569
          }
 
4570
        ;
 
4571
 
 
4572
/* The equivalent of select_part2 for nested queries. */
 
4573
select_part2_derived:
 
4574
          {
 
4575
            LEX *lex= Lex;
 
4576
            SELECT_LEX *sel= lex->current_select;
 
4577
            if (sel->linkage != UNION_TYPE)
 
4578
              mysql_init_select(lex);
 
4579
            lex->current_select->parsing_place= SELECT_LIST;
 
4580
          }
 
4581
          select_options select_item_list
 
4582
          {
 
4583
            Select->parsing_place= NO_MATTER;
 
4584
          }
 
4585
          opt_select_from select_lock_type
 
4586
        ;
 
4587
 
 
4588
/* handle contents of parentheses in join expression */
 
4589
select_derived:
 
4590
          get_select_lex
 
4591
          {
 
4592
            LEX *lex= Lex;
 
4593
            if ($1->init_nested_join(lex->thd))
 
4594
              MYSQL_YYABORT;
 
4595
          }
 
4596
          derived_table_list
 
4597
          {
 
4598
            LEX *lex= Lex;
 
4599
            /* for normal joins, $3 != NULL and end_nested_join() != NULL,
 
4600
               for derived tables, both must equal NULL */
 
4601
 
 
4602
            if (!($$= $1->end_nested_join(lex->thd)) && $3)
 
4603
              MYSQL_YYABORT;
 
4604
            if (!$3 && $$)
 
4605
            {
 
4606
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4607
              MYSQL_YYABORT;
 
4608
            }
 
4609
          }
 
4610
        ;
 
4611
 
 
4612
select_derived2:
 
4613
          {
 
4614
            LEX *lex= Lex;
 
4615
            lex->derived_tables|= DERIVED_SUBQUERY;
 
4616
            if (!lex->expr_allows_subselect ||
 
4617
                lex->sql_command == (int)SQLCOM_PURGE)
 
4618
            {
 
4619
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4620
              MYSQL_YYABORT;
 
4621
            }
 
4622
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
 
4623
                mysql_new_select(lex, 1))
 
4624
              MYSQL_YYABORT;
 
4625
            mysql_init_select(lex);
 
4626
            lex->current_select->linkage= DERIVED_TABLE_TYPE;
 
4627
            lex->current_select->parsing_place= SELECT_LIST;
 
4628
          }
 
4629
          select_options select_item_list
 
4630
          {
 
4631
            Select->parsing_place= NO_MATTER;
 
4632
          }
 
4633
          opt_select_from
 
4634
        ;
 
4635
 
 
4636
get_select_lex:
 
4637
          /* Empty */ { $$= Select; }
 
4638
        ;
 
4639
 
 
4640
select_derived_init:
 
4641
          SELECT_SYM
 
4642
          {
 
4643
            LEX *lex= Lex;
 
4644
 
 
4645
            if (! lex->parsing_options.allows_derived)
 
4646
            {
 
4647
              my_error(ER_VIEW_SELECT_DERIVED, MYF(0));
 
4648
              MYSQL_YYABORT;
 
4649
            }
 
4650
 
 
4651
            SELECT_LEX *sel= lex->current_select;
 
4652
            TABLE_LIST *embedding;
 
4653
            if (!sel->embedding || sel->end_nested_join(lex->thd))
 
4654
            {
 
4655
              /* we are not in parentheses */
 
4656
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
4657
              MYSQL_YYABORT;
 
4658
            }
 
4659
            embedding= Select->embedding;
 
4660
            $$= embedding &&
 
4661
                !embedding->nested_join->join_list.elements;
 
4662
            /* return true if we are deeply nested */
 
4663
          }
 
4664
        ;
 
4665
 
 
4666
opt_outer:
 
4667
          /* empty */ {}
 
4668
        | OUTER {}
 
4669
        ;
 
4670
 
 
4671
index_hint_clause:
 
4672
          /* empty */
 
4673
          {
 
4674
            $$= global_system_variables.old_mode ? 
 
4675
                  INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL; 
 
4676
          }
 
4677
        | FOR_SYM JOIN_SYM      { $$= INDEX_HINT_MASK_JOIN;  }
 
4678
        | FOR_SYM ORDER_SYM BY  { $$= INDEX_HINT_MASK_ORDER; }
 
4679
        | FOR_SYM GROUP_SYM BY  { $$= INDEX_HINT_MASK_GROUP; }
 
4680
        ;
 
4681
 
 
4682
index_hint_type:
 
4683
          FORCE_SYM  { $$= INDEX_HINT_FORCE; }
 
4684
        | IGNORE_SYM { $$= INDEX_HINT_IGNORE; } 
 
4685
        ;
 
4686
 
 
4687
index_hint_definition:
 
4688
          index_hint_type key_or_index index_hint_clause
 
4689
          {
 
4690
            Select->set_index_hint_type($1, $3);
 
4691
          }
 
4692
          '(' key_usage_list ')'
 
4693
        | USE_SYM key_or_index index_hint_clause
 
4694
          {
 
4695
            Select->set_index_hint_type(INDEX_HINT_USE, $3);
 
4696
          }
 
4697
          '(' opt_key_usage_list ')'
 
4698
       ;
 
4699
 
 
4700
index_hints_list:
 
4701
          index_hint_definition
 
4702
        | index_hints_list index_hint_definition
 
4703
        ;
 
4704
 
 
4705
opt_index_hints_list:
 
4706
          /* empty */
 
4707
        | { Select->alloc_index_hints(YYTHD); } index_hints_list
 
4708
        ;
 
4709
 
 
4710
opt_key_definition:
 
4711
          {  Select->clear_index_hints(); }
 
4712
          opt_index_hints_list
 
4713
        ;
 
4714
 
 
4715
opt_key_usage_list:
 
4716
          /* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
 
4717
        | key_usage_list {}
 
4718
        ;
 
4719
 
 
4720
key_usage_element:
 
4721
          ident
 
4722
          { Select->add_index_hint(YYTHD, $1.str, $1.length); }
 
4723
        | PRIMARY_SYM
 
4724
          { Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
 
4725
        ;
 
4726
 
 
4727
key_usage_list:
 
4728
          key_usage_element
 
4729
        | key_usage_list ',' key_usage_element
 
4730
        ;
 
4731
 
 
4732
using_list:
 
4733
          ident
 
4734
          {
 
4735
            if (!($$= new List<String>))
 
4736
              MYSQL_YYABORT;
 
4737
            $$->push_back(new (YYTHD->mem_root)
 
4738
                              String((const char *) $1.str, $1.length,
 
4739
                                      system_charset_info));
 
4740
          }
 
4741
        | using_list ',' ident
 
4742
          {
 
4743
            $1->push_back(new (YYTHD->mem_root)
 
4744
                              String((const char *) $3.str, $3.length,
 
4745
                                      system_charset_info));
 
4746
            $$= $1;
 
4747
          }
 
4748
        ;
 
4749
 
 
4750
interval:
 
4751
          interval_time_st {}
 
4752
        | DAY_HOUR_SYM           { $$=INTERVAL_DAY_HOUR; }
 
4753
        | DAY_MICROSECOND_SYM    { $$=INTERVAL_DAY_MICROSECOND; }
 
4754
        | DAY_MINUTE_SYM         { $$=INTERVAL_DAY_MINUTE; }
 
4755
        | DAY_SECOND_SYM         { $$=INTERVAL_DAY_SECOND; }
 
4756
        | HOUR_MICROSECOND_SYM   { $$=INTERVAL_HOUR_MICROSECOND; }
 
4757
        | HOUR_MINUTE_SYM        { $$=INTERVAL_HOUR_MINUTE; }
 
4758
        | HOUR_SECOND_SYM        { $$=INTERVAL_HOUR_SECOND; }
 
4759
        | MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
 
4760
        | MINUTE_SECOND_SYM      { $$=INTERVAL_MINUTE_SECOND; }
 
4761
        | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
 
4762
        | YEAR_MONTH_SYM         { $$=INTERVAL_YEAR_MONTH; }
 
4763
        ;
 
4764
 
 
4765
interval_time_stamp:
 
4766
        interval_time_st        {}
 
4767
        | FRAC_SECOND_SYM       { 
 
4768
                                  $$=INTERVAL_MICROSECOND; 
 
4769
                                  /*
 
4770
                                    FRAC_SECOND was mistakenly implemented with
 
4771
                                    a wrong resolution. According to the ODBC
 
4772
                                    standard it should be nanoseconds, not
 
4773
                                    microseconds. Changing it to nanoseconds
 
4774
                                    in MySQL would mean making TIMESTAMPDIFF
 
4775
                                    and TIMESTAMPADD to return DECIMAL, since
 
4776
                                    the return value would be too big for BIGINT
 
4777
                                    Hence we just deprecate the incorrect
 
4778
                                    implementation without changing its
 
4779
                                    resolution.
 
4780
                                  */
 
4781
                                }
 
4782
        ;
 
4783
 
 
4784
interval_time_st:
 
4785
          DAY_SYM         { $$=INTERVAL_DAY; }
 
4786
        | WEEK_SYM        { $$=INTERVAL_WEEK; }
 
4787
        | HOUR_SYM        { $$=INTERVAL_HOUR; }
 
4788
        | MINUTE_SYM      { $$=INTERVAL_MINUTE; }
 
4789
        | MONTH_SYM       { $$=INTERVAL_MONTH; }
 
4790
        | QUARTER_SYM     { $$=INTERVAL_QUARTER; }
 
4791
        | SECOND_SYM      { $$=INTERVAL_SECOND; }
 
4792
        | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
 
4793
        | YEAR_SYM        { $$=INTERVAL_YEAR; }
 
4794
        ;
 
4795
 
 
4796
date_time_type:
 
4797
          DATE_SYM  {$$=MYSQL_TIMESTAMP_DATE;}
 
4798
        | TIME_SYM  {$$=MYSQL_TIMESTAMP_TIME;}
 
4799
        | DATETIME  {$$=MYSQL_TIMESTAMP_DATETIME;}
 
4800
        | TIMESTAMP {$$=MYSQL_TIMESTAMP_DATETIME;}
 
4801
        ;
 
4802
 
 
4803
table_alias:
 
4804
          /* empty */
 
4805
        | AS
 
4806
        | EQ
 
4807
        ;
 
4808
 
 
4809
opt_table_alias:
 
4810
          /* empty */ { $$=0; }
 
4811
        | table_alias ident
 
4812
          { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
 
4813
        ;
 
4814
 
 
4815
opt_all:
 
4816
          /* empty */
 
4817
        | ALL
 
4818
        ;
 
4819
 
 
4820
where_clause:
 
4821
          /* empty */  { Select->where= 0; }
 
4822
        | WHERE
 
4823
          {
 
4824
            Select->parsing_place= IN_WHERE;
 
4825
          }
 
4826
          expr
 
4827
          {
 
4828
            SELECT_LEX *select= Select;
 
4829
            select->where= $3;
 
4830
            select->parsing_place= NO_MATTER;
 
4831
            if ($3)
 
4832
              $3->top_level_item();
 
4833
          }
 
4834
        ;
 
4835
 
 
4836
having_clause:
 
4837
          /* empty */
 
4838
        | HAVING
 
4839
          {
 
4840
            Select->parsing_place= IN_HAVING;
 
4841
          }
 
4842
          expr
 
4843
          {
 
4844
            SELECT_LEX *sel= Select;
 
4845
            sel->having= $3;
 
4846
            sel->parsing_place= NO_MATTER;
 
4847
            if ($3)
 
4848
              $3->top_level_item();
 
4849
          }
 
4850
        ;
 
4851
 
 
4852
opt_escape:
 
4853
          ESCAPE_SYM simple_expr 
 
4854
          {
 
4855
            Lex->escape_used= TRUE;
 
4856
            $$= $2;
 
4857
          }
 
4858
        | /* empty */
 
4859
          {
 
4860
            Lex->escape_used= FALSE;
 
4861
            $$= new Item_string("\\", 1, &my_charset_latin1);
 
4862
          }
 
4863
        ;
 
4864
 
 
4865
/*
 
4866
   group by statement in select
 
4867
*/
 
4868
 
 
4869
group_clause:
 
4870
          /* empty */
 
4871
        | GROUP_SYM BY group_list olap_opt
 
4872
        ;
 
4873
 
 
4874
group_list:
 
4875
          group_list ',' order_ident order_dir
 
4876
          { if (add_group_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; }
 
4877
        | order_ident order_dir
 
4878
          { if (add_group_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; }
 
4879
        ;
 
4880
 
 
4881
olap_opt:
 
4882
          /* empty */ {}
 
4883
        | WITH_CUBE_SYM
 
4884
          {
 
4885
            /*
 
4886
              'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
 
4887
              and cause LALR(2) conflicts.
 
4888
              This syntax is not standard.
 
4889
              MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
 
4890
              SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
 
4891
            */
 
4892
            LEX *lex=Lex;
 
4893
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4894
            {
 
4895
              my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
 
4896
                       "global union parameters");
 
4897
              MYSQL_YYABORT;
 
4898
            }
 
4899
            lex->current_select->olap= CUBE_TYPE;
 
4900
            my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
 
4901
            MYSQL_YYABORT;
 
4902
          }
 
4903
        | WITH_ROLLUP_SYM
 
4904
          {
 
4905
            /*
 
4906
              'WITH ROLLUP' is needed for backward compatibility,
 
4907
              and cause LALR(2) conflicts.
 
4908
              This syntax is not standard.
 
4909
              MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
 
4910
              SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
 
4911
            */
 
4912
            LEX *lex= Lex;
 
4913
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
 
4914
            {
 
4915
              my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
 
4916
                       "global union parameters");
 
4917
              MYSQL_YYABORT;
 
4918
            }
 
4919
            lex->current_select->olap= ROLLUP_TYPE;
 
4920
          }
 
4921
        ;
 
4922
 
 
4923
/*
 
4924
  Order by statement in ALTER TABLE
 
4925
*/
 
4926
 
 
4927
alter_order_clause:
 
4928
          ORDER_SYM BY alter_order_list
 
4929
        ;
 
4930
 
 
4931
alter_order_list:
 
4932
          alter_order_list ',' alter_order_item
 
4933
        | alter_order_item
 
4934
        ;
 
4935
 
 
4936
alter_order_item:
 
4937
          simple_ident_nospvar order_dir
 
4938
          {
 
4939
            THD *thd= YYTHD;
 
4940
            bool ascending= ($2 == 1) ? true : false;
 
4941
            if (add_order_to_list(thd, $1, ascending))
 
4942
              MYSQL_YYABORT;
 
4943
          }
 
4944
        ;
 
4945
 
 
4946
/*
 
4947
   Order by statement in select
 
4948
*/
 
4949
 
 
4950
opt_order_clause:
 
4951
          /* empty */
 
4952
        | order_clause
 
4953
        ;
 
4954
 
 
4955
order_clause:
 
4956
          ORDER_SYM BY
 
4957
          {
 
4958
            LEX *lex=Lex;
 
4959
            SELECT_LEX *sel= lex->current_select;
 
4960
            SELECT_LEX_UNIT *unit= sel-> master_unit();
 
4961
            if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
 
4962
                sel->olap != UNSPECIFIED_OLAP_TYPE &&
 
4963
                (sel->linkage != UNION_TYPE || sel->braces))
 
4964
            {
 
4965
              my_error(ER_WRONG_USAGE, MYF(0),
 
4966
                       "CUBE/ROLLUP", "ORDER BY");
 
4967
              MYSQL_YYABORT;
 
4968
            }
 
4969
            if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
 
4970
            {
 
4971
              /*
 
4972
                A query of the of the form (SELECT ...) ORDER BY order_list is
 
4973
                executed in the same way as the query
 
4974
                SELECT ... ORDER BY order_list
 
4975
                unless the SELECT construct contains ORDER BY or LIMIT clauses.
 
4976
                Otherwise we create a fake SELECT_LEX if it has not been created
 
4977
                yet.
 
4978
              */
 
4979
              SELECT_LEX *first_sl= unit->first_select();
 
4980
              if (!unit->is_union() &&
 
4981
                  (first_sl->order_list.elements || 
 
4982
                   first_sl->select_limit) &&            
 
4983
                  unit->add_fake_select_lex(lex->thd))
 
4984
                MYSQL_YYABORT;
 
4985
            }
 
4986
          }
 
4987
          order_list
 
4988
        ;
 
4989
 
 
4990
order_list:
 
4991
          order_list ',' order_ident order_dir
 
4992
          { if (add_order_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; }
 
4993
        | order_ident order_dir
 
4994
          { if (add_order_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; }
 
4995
        ;
 
4996
 
 
4997
order_dir:
 
4998
          /* empty */ { $$ =  1; }
 
4999
        | ASC  { $$ =1; }
 
5000
        | DESC { $$ =0; }
 
5001
        ;
 
5002
 
 
5003
opt_limit_clause_init:
 
5004
          /* empty */
 
5005
          {
 
5006
            LEX *lex= Lex;
 
5007
            SELECT_LEX *sel= lex->current_select;
 
5008
            sel->offset_limit= 0;
 
5009
            sel->select_limit= 0;
 
5010
          }
 
5011
        | limit_clause {}
 
5012
        ;
 
5013
 
 
5014
opt_limit_clause:
 
5015
          /* empty */ {}
 
5016
        | limit_clause {}
 
5017
        ;
 
5018
 
 
5019
limit_clause:
 
5020
          LIMIT limit_options {}
 
5021
        ;
 
5022
 
 
5023
limit_options:
 
5024
          limit_option
 
5025
          {
 
5026
            SELECT_LEX *sel= Select;
 
5027
            sel->select_limit= $1;
 
5028
            sel->offset_limit= 0;
 
5029
            sel->explicit_limit= 1;
 
5030
          }
 
5031
        | limit_option ',' limit_option
 
5032
          {
 
5033
            SELECT_LEX *sel= Select;
 
5034
            sel->select_limit= $3;
 
5035
            sel->offset_limit= $1;
 
5036
            sel->explicit_limit= 1;
 
5037
          }
 
5038
        | limit_option OFFSET_SYM limit_option
 
5039
          {
 
5040
            SELECT_LEX *sel= Select;
 
5041
            sel->select_limit= $1;
 
5042
            sel->offset_limit= $3;
 
5043
            sel->explicit_limit= 1;
 
5044
          }
 
5045
        ;
 
5046
 
 
5047
limit_option:
 
5048
        param_marker
 
5049
        {
 
5050
          ((Item_param *) $1)->limit_clause_param= TRUE;
 
5051
        }
 
5052
        | ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
 
5053
        | LONG_NUM      { $$= new Item_uint($1.str, $1.length); }
 
5054
        | NUM           { $$= new Item_uint($1.str, $1.length); }
 
5055
        ;
 
5056
 
 
5057
delete_limit_clause:
 
5058
          /* empty */
 
5059
          {
 
5060
            LEX *lex=Lex;
 
5061
            lex->current_select->select_limit= 0;
 
5062
          }
 
5063
        | LIMIT limit_option
 
5064
          {
 
5065
            SELECT_LEX *sel= Select;
 
5066
            sel->select_limit= $2;
 
5067
            sel->explicit_limit= 1;
 
5068
          }
 
5069
        ;
 
5070
 
 
5071
ulong_num:
 
5072
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5073
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
5074
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5075
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5076
        | DECIMAL_NUM   { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5077
        | FLOAT_NUM     { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5078
        ;
 
5079
 
 
5080
real_ulong_num:
 
5081
          NUM           { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5082
        | HEX_NUM       { $$= (ulong) strtol($1.str, (char**) 0, 16); }
 
5083
        | LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5084
        | ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
 
5085
        | dec_num_error { MYSQL_YYABORT; }
 
5086
        ;
 
5087
 
 
5088
ulonglong_num:
 
5089
          NUM           { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
 
5090
        | ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
 
5091
        | LONG_NUM      { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
 
5092
        | DECIMAL_NUM   { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
 
5093
        | FLOAT_NUM     { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
 
5094
        ;
 
5095
 
 
5096
dec_num_error:
 
5097
          dec_num
 
5098
          { my_parse_error(ER(ER_ONLY_INTEGERS_ALLOWED)); }
 
5099
        ;
 
5100
 
 
5101
dec_num:
 
5102
          DECIMAL_NUM
 
5103
        | FLOAT_NUM
 
5104
        ;
 
5105
 
 
5106
choice:
 
5107
        ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
 
5108
        | DEFAULT { $$= HA_CHOICE_UNDEF; }
 
5109
        ;
 
5110
 
 
5111
select_var_list_init:
 
5112
          {
 
5113
            LEX *lex=Lex;
 
5114
            if (!lex->describe && (!(lex->result= new select_dumpvar())))
 
5115
              MYSQL_YYABORT;
 
5116
          }
 
5117
          select_var_list
 
5118
          {}
 
5119
        ;
 
5120
 
 
5121
select_var_list:
 
5122
          select_var_list ',' select_var_ident
 
5123
        | select_var_ident {}
 
5124
        ;
 
5125
 
 
5126
select_var_ident:  
 
5127
          '@' ident_or_text
 
5128
          {
 
5129
            LEX *lex=Lex;
 
5130
            if (lex->result) 
 
5131
              ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
 
5132
            else
 
5133
              /*
 
5134
                The parser won't create select_result instance only
 
5135
                if it's an EXPLAIN.
 
5136
              */
 
5137
              DBUG_ASSERT(lex->describe);
 
5138
          }
 
5139
        ;
 
5140
 
 
5141
into:
 
5142
          INTO
 
5143
          {
 
5144
            if (! Lex->parsing_options.allows_select_into)
 
5145
            {
 
5146
              my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "INTO");
 
5147
              MYSQL_YYABORT;
 
5148
            }
 
5149
          }
 
5150
          into_destination
 
5151
        ;
 
5152
 
 
5153
into_destination:
 
5154
          OUTFILE TEXT_STRING_filesystem
 
5155
          {
 
5156
            LEX *lex= Lex;
 
5157
            if (!(lex->exchange= new sql_exchange($2.str, 0)) ||
 
5158
                !(lex->result= new select_export(lex->exchange)))
 
5159
              MYSQL_YYABORT;
 
5160
          }
 
5161
          opt_field_term opt_line_term
 
5162
        | DUMPFILE TEXT_STRING_filesystem
 
5163
          {
 
5164
            LEX *lex=Lex;
 
5165
            if (!lex->describe)
 
5166
            {
 
5167
              if (!(lex->exchange= new sql_exchange($2.str,1)))
 
5168
                MYSQL_YYABORT;
 
5169
              if (!(lex->result= new select_dump(lex->exchange)))
 
5170
                MYSQL_YYABORT;
 
5171
            }
 
5172
          }
 
5173
        | select_var_list_init
 
5174
          { }
 
5175
        ;
 
5176
 
 
5177
/*
 
5178
  Drop : delete tables or index or user
 
5179
*/
 
5180
 
 
5181
drop:
 
5182
          DROP opt_temporary table_or_tables if_exists table_list opt_restrict
 
5183
          {
 
5184
            LEX *lex=Lex;
 
5185
            lex->sql_command = SQLCOM_DROP_TABLE;
 
5186
            lex->drop_temporary= $2;
 
5187
            lex->drop_if_exists= $4;
 
5188
          }
 
5189
        | DROP build_method INDEX_SYM ident ON table_ident {}
 
5190
          {
 
5191
            LEX *lex=Lex;
 
5192
            lex->sql_command= SQLCOM_DROP_INDEX;
 
5193
            lex->alter_info.reset();
 
5194
            lex->alter_info.flags= ALTER_DROP_INDEX;
 
5195
            lex->alter_info.build_method= $2;
 
5196
            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
 
5197
                                                               $4.str));
 
5198
            if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
 
5199
                                                        TL_OPTION_UPDATING))
 
5200
              MYSQL_YYABORT;
 
5201
          }
 
5202
        | DROP DATABASE if_exists ident
 
5203
          {
 
5204
            LEX *lex=Lex;
 
5205
            lex->sql_command= SQLCOM_DROP_DB;
 
5206
            lex->drop_if_exists=$3;
 
5207
            lex->name= $4;
 
5208
          }
 
5209
        | DROP FUNCTION_SYM if_exists ident
 
5210
          {
 
5211
            THD *thd= YYTHD;
 
5212
            LEX *lex= thd->lex;
 
5213
            lex->sql_command = SQLCOM_DROP_FUNCTION;
 
5214
            lex->drop_if_exists= $3;
 
5215
            lex->udf.name = $4;
 
5216
          }
 
5217
        ;
 
5218
 
 
5219
table_list:
 
5220
          table_name
 
5221
        | table_list ',' table_name
 
5222
        ;
 
5223
 
 
5224
table_name:
 
5225
          table_ident
 
5226
          {
 
5227
            if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
 
5228
              MYSQL_YYABORT;
 
5229
          }
 
5230
        ;
 
5231
 
 
5232
table_alias_ref_list:
 
5233
          table_alias_ref
 
5234
        | table_alias_ref_list ',' table_alias_ref
 
5235
        ;
 
5236
 
 
5237
table_alias_ref:
 
5238
          table_ident
 
5239
          {
 
5240
            if (!Select->add_table_to_list(YYTHD, $1, NULL,
 
5241
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
5242
                                           Lex->lock_option ))
 
5243
              MYSQL_YYABORT;
 
5244
          }
 
5245
        ;
 
5246
 
 
5247
if_exists:
 
5248
          /* empty */ { $$= 0; }
 
5249
        | IF EXISTS { $$= 1; }
 
5250
        ;
 
5251
 
 
5252
opt_temporary:
 
5253
          /* empty */ { $$= 0; }
 
5254
        | TEMPORARY { $$= 1; }
 
5255
        ;
 
5256
/*
 
5257
** Insert : add new data to table
 
5258
*/
 
5259
 
 
5260
insert:
 
5261
          INSERT
 
5262
          {
 
5263
            LEX *lex= Lex;
 
5264
            lex->sql_command= SQLCOM_INSERT;
 
5265
            lex->duplicates= DUP_ERROR; 
 
5266
            mysql_init_select(lex);
 
5267
            /* for subselects */
 
5268
            lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
 
5269
          }
 
5270
          insert_lock_option
 
5271
          opt_ignore insert2
 
5272
          {
 
5273
            Select->set_lock_for_tables($3);
 
5274
            Lex->current_select= &Lex->select_lex;
 
5275
          }
 
5276
          insert_field_spec opt_insert_update
 
5277
          {}
 
5278
        ;
 
5279
 
 
5280
replace:
 
5281
          REPLACE
 
5282
          {
 
5283
            LEX *lex=Lex;
 
5284
            lex->sql_command = SQLCOM_REPLACE;
 
5285
            lex->duplicates= DUP_REPLACE;
 
5286
            mysql_init_select(lex);
 
5287
          }
 
5288
          replace_lock_option insert2
 
5289
          {
 
5290
            Select->set_lock_for_tables($3);
 
5291
            Lex->current_select= &Lex->select_lex;
 
5292
          }
 
5293
          insert_field_spec
 
5294
          {}
 
5295
        ;
 
5296
 
 
5297
insert_lock_option:
 
5298
          /* empty */
 
5299
          {
 
5300
            $$= TL_WRITE_CONCURRENT_INSERT;
 
5301
          }
 
5302
        | LOW_PRIORITY  { $$= TL_WRITE_LOW_PRIORITY; }
 
5303
        | DELAYED_SYM   { $$= TL_WRITE_LOW_PRIORITY; }
 
5304
        | HIGH_PRIORITY { $$= TL_WRITE; }
 
5305
        ;
 
5306
 
 
5307
replace_lock_option:
 
5308
          opt_low_priority { $$= $1; }
 
5309
        | DELAYED_SYM { $$= TL_WRITE_LOW_PRIORITY; }
 
5310
        ;
 
5311
 
 
5312
insert2:
 
5313
          INTO insert_table {}
 
5314
        | insert_table {}
 
5315
        ;
 
5316
 
 
5317
insert_table:
 
5318
          table_name
 
5319
          {
 
5320
            LEX *lex=Lex;
 
5321
            lex->field_list.empty();
 
5322
            lex->many_values.empty();
 
5323
            lex->insert_list=0;
 
5324
          };
 
5325
 
 
5326
insert_field_spec:
 
5327
          insert_values {}
 
5328
        | '(' ')' insert_values {}
 
5329
        | '(' fields ')' insert_values {}
 
5330
        | SET
 
5331
          {
 
5332
            LEX *lex=Lex;
 
5333
            if (!(lex->insert_list = new List_item) ||
 
5334
                lex->many_values.push_back(lex->insert_list))
 
5335
              MYSQL_YYABORT;
 
5336
          }
 
5337
          ident_eq_list
 
5338
        ;
 
5339
 
 
5340
fields:
 
5341
          fields ',' insert_ident { Lex->field_list.push_back($3); }
 
5342
        | insert_ident { Lex->field_list.push_back($1); }
 
5343
        ;
 
5344
 
 
5345
insert_values:
 
5346
          VALUES values_list {}
 
5347
        | VALUE_SYM values_list {}
 
5348
        | create_select
 
5349
          { Select->set_braces(0);}
 
5350
          union_clause {}
 
5351
        | '(' create_select ')'
 
5352
          { Select->set_braces(1);}
 
5353
          union_opt {}
 
5354
        ;
 
5355
 
 
5356
values_list:
 
5357
          values_list ','  no_braces
 
5358
        | no_braces
 
5359
        ;
 
5360
 
 
5361
ident_eq_list:
 
5362
          ident_eq_list ',' ident_eq_value
 
5363
        | ident_eq_value
 
5364
        ;
 
5365
 
 
5366
ident_eq_value:
 
5367
          simple_ident_nospvar equal expr_or_default
 
5368
          {
 
5369
            LEX *lex=Lex;
 
5370
            if (lex->field_list.push_back($1) ||
 
5371
                lex->insert_list->push_back($3))
 
5372
              MYSQL_YYABORT;
 
5373
          }
 
5374
        ;
 
5375
 
 
5376
equal:
 
5377
          EQ {}
 
5378
        | SET_VAR {}
 
5379
        ;
 
5380
 
 
5381
opt_equal:
 
5382
          /* empty */ {}
 
5383
        | equal {}
 
5384
        ;
 
5385
 
 
5386
no_braces:
 
5387
          '('
 
5388
          {
 
5389
              if (!(Lex->insert_list = new List_item))
 
5390
                MYSQL_YYABORT;
 
5391
          }
 
5392
          opt_values ')'
 
5393
          {
 
5394
            LEX *lex=Lex;
 
5395
            if (lex->many_values.push_back(lex->insert_list))
 
5396
              MYSQL_YYABORT;
 
5397
          }
 
5398
        ;
 
5399
 
 
5400
opt_values:
 
5401
          /* empty */ {}
 
5402
        | values
 
5403
        ;
 
5404
 
 
5405
values:
 
5406
          values ','  expr_or_default
 
5407
          {
 
5408
            if (Lex->insert_list->push_back($3))
 
5409
              MYSQL_YYABORT;
 
5410
          }
 
5411
        | expr_or_default
 
5412
          {
 
5413
            if (Lex->insert_list->push_back($1))
 
5414
              MYSQL_YYABORT;
 
5415
          }
 
5416
        ;
 
5417
 
 
5418
expr_or_default:
 
5419
          expr { $$= $1;}
 
5420
        | DEFAULT {$$= new Item_default_value(Lex->current_context()); }
 
5421
        ;
 
5422
 
 
5423
opt_insert_update:
 
5424
          /* empty */
 
5425
        | ON DUPLICATE_SYM { Lex->duplicates= DUP_UPDATE; }
 
5426
          KEY_SYM UPDATE_SYM insert_update_list
 
5427
        ;
 
5428
 
 
5429
/* Update rows in a table */
 
5430
 
 
5431
update:
 
5432
          UPDATE_SYM
 
5433
          {
 
5434
            LEX *lex= Lex;
 
5435
            mysql_init_select(lex);
 
5436
            lex->sql_command= SQLCOM_UPDATE;
 
5437
            lex->lock_option= TL_UNLOCK; /* Will be set later */
 
5438
            lex->duplicates= DUP_ERROR; 
 
5439
          }
 
5440
          opt_low_priority opt_ignore join_table_list
 
5441
          SET update_list
 
5442
          {
 
5443
            LEX *lex= Lex;
 
5444
            if (lex->select_lex.table_list.elements > 1)
 
5445
              lex->sql_command= SQLCOM_UPDATE_MULTI;
 
5446
            else if (lex->select_lex.get_table_list()->derived)
 
5447
            {
 
5448
              /* it is single table update and it is update of derived table */
 
5449
              my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
 
5450
                       lex->select_lex.get_table_list()->alias, "UPDATE");
 
5451
              MYSQL_YYABORT;
 
5452
            }
 
5453
            /*
 
5454
              In case of multi-update setting write lock for all tables may
 
5455
              be too pessimistic. We will decrease lock level if possible in
 
5456
              mysql_multi_update().
 
5457
            */
 
5458
            Select->set_lock_for_tables($3);
 
5459
          }
 
5460
          where_clause opt_order_clause delete_limit_clause {}
 
5461
        ;
 
5462
 
 
5463
update_list:
 
5464
          update_list ',' update_elem
 
5465
        | update_elem
 
5466
        ;
 
5467
 
 
5468
update_elem:
 
5469
          simple_ident_nospvar equal expr_or_default
 
5470
          {
 
5471
            if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
 
5472
              MYSQL_YYABORT;
 
5473
          }
 
5474
        ;
 
5475
 
 
5476
insert_update_list:
 
5477
          insert_update_list ',' insert_update_elem
 
5478
        | insert_update_elem
 
5479
        ;
 
5480
 
 
5481
insert_update_elem:
 
5482
          simple_ident_nospvar equal expr_or_default
 
5483
          {
 
5484
          LEX *lex= Lex;
 
5485
          if (lex->update_list.push_back($1) || 
 
5486
              lex->value_list.push_back($3))
 
5487
              MYSQL_YYABORT;
 
5488
          }
 
5489
        ;
 
5490
 
 
5491
opt_low_priority:
 
5492
          /* empty */ { $$= TL_WRITE_DEFAULT; }
 
5493
        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
 
5494
        ;
 
5495
 
 
5496
/* Delete rows from a table */
 
5497
 
 
5498
delete:
 
5499
          DELETE_SYM
 
5500
          {
 
5501
            LEX *lex= Lex;
 
5502
            lex->sql_command= SQLCOM_DELETE;
 
5503
            mysql_init_select(lex);
 
5504
            lex->lock_option= TL_WRITE_DEFAULT;
 
5505
            lex->ignore= 0;
 
5506
            lex->select_lex.init_order();
 
5507
          }
 
5508
          opt_delete_options single_multi
 
5509
        ;
 
5510
 
 
5511
single_multi:
 
5512
          FROM table_ident
 
5513
          {
 
5514
            if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
 
5515
                                           Lex->lock_option))
 
5516
              MYSQL_YYABORT;
 
5517
          }
 
5518
          where_clause opt_order_clause
 
5519
          delete_limit_clause {}
 
5520
        | table_wild_list
 
5521
          { mysql_init_multi_delete(Lex); }
 
5522
          FROM join_table_list where_clause
 
5523
          {
 
5524
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
 
5525
              MYSQL_YYABORT;
 
5526
          }
 
5527
        | FROM table_alias_ref_list
 
5528
          { mysql_init_multi_delete(Lex); }
 
5529
          USING join_table_list where_clause
 
5530
          {
 
5531
            if (multi_delete_set_locks_and_link_aux_tables(Lex))
 
5532
              MYSQL_YYABORT;
 
5533
          }
 
5534
        ;
 
5535
 
 
5536
table_wild_list:
 
5537
          table_wild_one
 
5538
        | table_wild_list ',' table_wild_one
 
5539
        ;
 
5540
 
 
5541
table_wild_one:
 
5542
          ident opt_wild
 
5543
          {
 
5544
            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
 
5545
                                           NULL,
 
5546
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
5547
                                           Lex->lock_option))
 
5548
              MYSQL_YYABORT;
 
5549
          }
 
5550
        | ident '.' ident opt_wild
 
5551
          {
 
5552
            if (!Select->add_table_to_list(YYTHD,
 
5553
                                           new Table_ident(YYTHD, $1, $3, 0),
 
5554
                                           NULL,
 
5555
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
5556
                                           Lex->lock_option))
 
5557
              MYSQL_YYABORT;
 
5558
          }
 
5559
        ;
 
5560
 
 
5561
opt_wild:
 
5562
          /* empty */ {}
 
5563
        | '.' '*' {}
 
5564
        ;
 
5565
 
 
5566
opt_delete_options:
 
5567
          /* empty */ {}
 
5568
        | opt_delete_option opt_delete_options {}
 
5569
        ;
 
5570
 
 
5571
opt_delete_option:
 
5572
          QUICK        { Select->options|= OPTION_QUICK; }
 
5573
        | LOW_PRIORITY { Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
 
5574
        | IGNORE_SYM   { Lex->ignore= 1; }
 
5575
        ;
 
5576
 
 
5577
truncate:
 
5578
          TRUNCATE_SYM opt_table_sym table_name
 
5579
          {
 
5580
            LEX* lex= Lex;
 
5581
            lex->sql_command= SQLCOM_TRUNCATE;
 
5582
            lex->select_lex.options= 0;
 
5583
            lex->select_lex.init_order();
 
5584
          }
 
5585
        ;
 
5586
 
 
5587
opt_table_sym:
 
5588
          /* empty */
 
5589
        | TABLE_SYM
 
5590
        ;
 
5591
 
 
5592
/* Show things */
 
5593
 
 
5594
show:
 
5595
          SHOW
 
5596
          {
 
5597
            LEX *lex=Lex;
 
5598
            lex->wild=0;
 
5599
            lex->lock_option= TL_READ;
 
5600
            mysql_init_select(lex);
 
5601
            lex->current_select->parsing_place= SELECT_LIST;
 
5602
            bzero((char*) &lex->create_info,sizeof(lex->create_info));
 
5603
          }
 
5604
          show_param
 
5605
          {}
 
5606
        ;
 
5607
 
 
5608
show_param:
 
5609
           DATABASES wild_and_where
 
5610
           {
 
5611
             LEX *lex= Lex;
 
5612
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
5613
             if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
 
5614
               MYSQL_YYABORT;
 
5615
           }
 
5616
         | opt_full TABLES opt_db wild_and_where
 
5617
           {
 
5618
             LEX *lex= Lex;
 
5619
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
5620
             lex->select_lex.db= $3;
 
5621
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
 
5622
               MYSQL_YYABORT;
 
5623
           }
 
5624
         | TABLE_SYM STATUS_SYM opt_db wild_and_where
 
5625
           {
 
5626
             LEX *lex= Lex;
 
5627
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
5628
             lex->select_lex.db= $3;
 
5629
             if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
 
5630
               MYSQL_YYABORT;
 
5631
           }
 
5632
        | OPEN_SYM TABLES opt_db wild_and_where
 
5633
          {
 
5634
            LEX *lex= Lex;
 
5635
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
5636
            lex->select_lex.db= $3;
 
5637
            if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
 
5638
              MYSQL_YYABORT;
 
5639
          }
 
5640
        | ENGINE_SYM known_storage_engines show_engine_param
 
5641
          { Lex->create_info.db_type= $2; }
 
5642
        | ENGINE_SYM ALL show_engine_param
 
5643
          { Lex->create_info.db_type= NULL; }
 
5644
        | opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
 
5645
          {
 
5646
            LEX *lex= Lex;
 
5647
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
5648
            if ($5)
 
5649
              $4->change_db($5);
 
5650
            if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
 
5651
              MYSQL_YYABORT;
 
5652
          }
 
5653
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE
 
5654
          WITH MASTER_LOG_FILE_SYM EQ
 
5655
          TEXT_STRING_sys /* $8 */
 
5656
          AND_SYM MASTER_LOG_POS_SYM EQ
 
5657
          ulonglong_num /* $12 */
 
5658
          AND_SYM MASTER_SERVER_ID_SYM EQ
 
5659
          ulong_num /* $16 */
 
5660
          {
 
5661
            Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
 
5662
            Lex->mi.log_file_name = $8.str;
 
5663
            Lex->mi.pos = $12;
 
5664
            Lex->mi.server_id = $16;
 
5665
          }
 
5666
        | master_or_binary LOGS_SYM
 
5667
          {
 
5668
            Lex->sql_command = SQLCOM_SHOW_BINLOGS;
 
5669
          }
 
5670
        | SLAVE HOSTS_SYM
 
5671
          {
 
5672
            Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
 
5673
          }
 
5674
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
 
5675
          {
 
5676
            LEX *lex= Lex;
 
5677
            lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
 
5678
          } opt_limit_clause_init
 
5679
        | keys_or_index from_or_in table_ident opt_db where_clause
 
5680
          {
 
5681
            LEX *lex= Lex;
 
5682
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
5683
            if ($4)
 
5684
              $3->change_db($4);
 
5685
            if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
 
5686
              MYSQL_YYABORT;
 
5687
          }
 
5688
        | COUNT_SYM '(' '*' ')' WARNINGS
 
5689
          { (void) create_select_for_variable("warning_count"); }
 
5690
        | COUNT_SYM '(' '*' ')' ERRORS
 
5691
          { (void) create_select_for_variable("error_count"); }
 
5692
        | WARNINGS opt_limit_clause_init
 
5693
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
 
5694
        | ERRORS opt_limit_clause_init
 
5695
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
 
5696
        | opt_var_type STATUS_SYM wild_and_where
 
5697
          {
 
5698
            LEX *lex= Lex;
 
5699
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
5700
            lex->option_type= $1;
 
5701
            if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
 
5702
              MYSQL_YYABORT;
 
5703
          }
 
5704
        | opt_full PROCESSLIST_SYM
 
5705
          { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
 
5706
        | opt_var_type  VARIABLES wild_and_where
 
5707
          {
 
5708
            LEX *lex= Lex;
 
5709
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
5710
            lex->option_type= $1;
 
5711
            if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
 
5712
              MYSQL_YYABORT;
 
5713
          }
 
5714
        | charset wild_and_where
 
5715
          {
 
5716
            LEX *lex= Lex;
 
5717
            lex->sql_command= SQLCOM_SHOW_CHARSETS;
 
5718
            if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
 
5719
              MYSQL_YYABORT;
 
5720
          }
 
5721
        | COLLATION_SYM wild_and_where
 
5722
          {
 
5723
            LEX *lex= Lex;
 
5724
            lex->sql_command= SQLCOM_SHOW_COLLATIONS;
 
5725
            if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
 
5726
              MYSQL_YYABORT;
 
5727
          }
 
5728
        | CREATE DATABASE opt_if_not_exists ident
 
5729
          {
 
5730
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
 
5731
            Lex->create_info.options=$3;
 
5732
            Lex->name= $4;
 
5733
          }
 
5734
        | CREATE TABLE_SYM table_ident
 
5735
          {
 
5736
            LEX *lex= Lex;
 
5737
            lex->sql_command = SQLCOM_SHOW_CREATE;
 
5738
            if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
 
5739
              MYSQL_YYABORT;
 
5740
            lex->create_info.default_storage_media= HA_SM_DEFAULT;
 
5741
          }
 
5742
        | MASTER_SYM STATUS_SYM
 
5743
          {
 
5744
            Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
 
5745
          }
 
5746
        | SLAVE STATUS_SYM
 
5747
          {
 
5748
            Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
 
5749
          }
 
5750
 
 
5751
show_engine_param:
 
5752
          STATUS_SYM
 
5753
          { Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS; }
 
5754
        | MUTEX_SYM
 
5755
          { Lex->sql_command= SQLCOM_SHOW_ENGINE_MUTEX; }
 
5756
        | LOGS_SYM
 
5757
          { Lex->sql_command= SQLCOM_SHOW_ENGINE_LOGS; }
 
5758
        ;
 
5759
 
 
5760
master_or_binary:
 
5761
          MASTER_SYM
 
5762
        | BINARY
 
5763
        ;
 
5764
 
 
5765
opt_db:
 
5766
          /* empty */  { $$= 0; }
 
5767
        | from_or_in ident { $$= $2.str; }
 
5768
        ;
 
5769
 
 
5770
opt_full:
 
5771
          /* empty */ { Lex->verbose=0; }
 
5772
        | FULL        { Lex->verbose=1; }
 
5773
        ;
 
5774
 
 
5775
from_or_in:
 
5776
          FROM
 
5777
        | IN_SYM
 
5778
        ;
 
5779
 
 
5780
binlog_in:
 
5781
          /* empty */            { Lex->mi.log_file_name = 0; }
 
5782
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
 
5783
        ;
 
5784
 
 
5785
binlog_from:
 
5786
          /* empty */        { Lex->mi.pos = 4; /* skip magic number */ }
 
5787
        | FROM ulonglong_num { Lex->mi.pos = $2; }
 
5788
        ;
 
5789
 
 
5790
wild_and_where:
 
5791
          /* empty */
 
5792
        | LIKE TEXT_STRING_sys
 
5793
          {
 
5794
            Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
 
5795
                                                    system_charset_info);
 
5796
          }
 
5797
        | WHERE expr
 
5798
          {
 
5799
            Select->where= $2;
 
5800
            if ($2)
 
5801
              $2->top_level_item();
 
5802
          }
 
5803
        ;
 
5804
 
 
5805
/* A Oracle compatible synonym for show */
 
5806
describe:
 
5807
          describe_command table_ident
 
5808
          {
 
5809
            LEX *lex= Lex;
 
5810
            lex->lock_option= TL_READ;
 
5811
            mysql_init_select(lex);
 
5812
            lex->current_select->parsing_place= SELECT_LIST;
 
5813
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
5814
            lex->select_lex.db= 0;
 
5815
            lex->verbose= 0;
 
5816
            if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
 
5817
              MYSQL_YYABORT;
 
5818
          }
 
5819
          opt_describe_column {}
 
5820
        | describe_command opt_extended_describe
 
5821
          { Lex->describe|= DESCRIBE_NORMAL; }
 
5822
          select
 
5823
          {
 
5824
            LEX *lex=Lex;
 
5825
            lex->select_lex.options|= SELECT_DESCRIBE;
 
5826
          }
 
5827
        ;
 
5828
 
 
5829
describe_command:
 
5830
          DESC
 
5831
        | DESCRIBE
 
5832
        ;
 
5833
 
 
5834
opt_extended_describe:
 
5835
          /* empty */ {}
 
5836
        | EXTENDED_SYM   { Lex->describe|= DESCRIBE_EXTENDED; }
 
5837
        ;
 
5838
 
 
5839
opt_describe_column:
 
5840
          /* empty */ {}
 
5841
        | text_string { Lex->wild= $1; }
 
5842
        | ident
 
5843
          {
 
5844
            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
 
5845
                                                    $1.length,
 
5846
                                                    system_charset_info);
 
5847
          }
 
5848
        ;
 
5849
 
 
5850
 
 
5851
/* flush things */
 
5852
 
 
5853
flush:
 
5854
          FLUSH_SYM opt_no_write_to_binlog
 
5855
          {
 
5856
            LEX *lex=Lex;
 
5857
            lex->sql_command= SQLCOM_FLUSH;
 
5858
            lex->type= 0;
 
5859
            lex->no_write_to_binlog= $2;
 
5860
          }
 
5861
          flush_options
 
5862
          {}
 
5863
        ;
 
5864
 
 
5865
flush_options:
 
5866
          flush_options ',' flush_option
 
5867
        | flush_option
 
5868
        ;
 
5869
 
 
5870
flush_option:
 
5871
          table_or_tables
 
5872
          { Lex->type|= REFRESH_TABLES; }
 
5873
          opt_table_list {}
 
5874
        | TABLES WITH READ_SYM LOCK_SYM
 
5875
          { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
 
5876
        | QUERY_SYM CACHE_SYM
 
5877
          { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
 
5878
        | HOSTS_SYM
 
5879
          { Lex->type|= REFRESH_HOSTS; }
 
5880
        | LOGS_SYM
 
5881
          { Lex->type|= REFRESH_LOG; }
 
5882
        | STATUS_SYM
 
5883
          { Lex->type|= REFRESH_STATUS; }
 
5884
        | SLAVE
 
5885
          { Lex->type|= REFRESH_SLAVE; }
 
5886
        | MASTER_SYM
 
5887
          { Lex->type|= REFRESH_MASTER; }
 
5888
        | DES_KEY_FILE
 
5889
          { Lex->type|= REFRESH_DES_KEY_FILE; }
 
5890
        | RESOURCES
 
5891
          { Lex->type|= REFRESH_USER_RESOURCES; }
 
5892
        ;
 
5893
 
 
5894
opt_table_list:
 
5895
          /* empty */  {}
 
5896
        | table_list {}
 
5897
        ;
 
5898
 
 
5899
reset:
 
5900
          RESET_SYM
 
5901
          {
 
5902
            LEX *lex=Lex;
 
5903
            lex->sql_command= SQLCOM_RESET; lex->type=0;
 
5904
          }
 
5905
          reset_options
 
5906
          {}
 
5907
        ;
 
5908
 
 
5909
reset_options:
 
5910
          reset_options ',' reset_option
 
5911
        | reset_option
 
5912
        ;
 
5913
 
 
5914
reset_option:
 
5915
          SLAVE               { Lex->type|= REFRESH_SLAVE; }
 
5916
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
 
5917
        | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;}
 
5918
        ;
 
5919
 
 
5920
purge:
 
5921
          PURGE
 
5922
          {
 
5923
            LEX *lex=Lex;
 
5924
            lex->type=0;
 
5925
            lex->sql_command = SQLCOM_PURGE;
 
5926
          }
 
5927
          purge_options
 
5928
          {}
 
5929
        ;
 
5930
 
 
5931
purge_options:
 
5932
          master_or_binary LOGS_SYM purge_option
 
5933
        ;
 
5934
 
 
5935
purge_option:
 
5936
          TO_SYM TEXT_STRING_sys
 
5937
          {
 
5938
            Lex->to_log = $2.str;
 
5939
          }
 
5940
        | BEFORE_SYM expr
 
5941
          {
 
5942
            LEX *lex= Lex;
 
5943
            lex->value_list.empty();
 
5944
            lex->value_list.push_front($2);
 
5945
            lex->sql_command= SQLCOM_PURGE_BEFORE;
 
5946
          }
 
5947
        ;
 
5948
 
 
5949
/* kill threads */
 
5950
 
 
5951
kill:
 
5952
          KILL_SYM kill_option expr
 
5953
          {
 
5954
            LEX *lex=Lex;
 
5955
            lex->value_list.empty();
 
5956
            lex->value_list.push_front($3);
 
5957
            lex->sql_command= SQLCOM_KILL;
 
5958
          }
 
5959
        ;
 
5960
 
 
5961
kill_option:
 
5962
          /* empty */ { Lex->type= 0; }
 
5963
        | CONNECTION_SYM { Lex->type= 0; }
 
5964
        | QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; }
 
5965
        ;
 
5966
 
 
5967
/* change database */
 
5968
 
 
5969
use:
 
5970
          USE_SYM ident
 
5971
          {
 
5972
            LEX *lex=Lex;
 
5973
            lex->sql_command=SQLCOM_CHANGE_DB;
 
5974
            lex->select_lex.db= $2.str;
 
5975
          }
 
5976
        ;
 
5977
 
 
5978
/* import, export of files */
 
5979
 
 
5980
load:
 
5981
          LOAD data_or_xml
 
5982
          {
 
5983
            THD *thd= YYTHD;
 
5984
            LEX *lex= thd->lex;
 
5985
            Lex_input_stream *lip= thd->m_lip;
 
5986
 
 
5987
            lex->fname_start= lip->get_ptr();
 
5988
          }
 
5989
          load_data_lock opt_local INFILE TEXT_STRING_filesystem
 
5990
          {
 
5991
            LEX *lex=Lex;
 
5992
            lex->sql_command= SQLCOM_LOAD;
 
5993
            lex->lock_option= $4;
 
5994
            lex->local_file=  $5;
 
5995
            lex->duplicates= DUP_ERROR;
 
5996
            lex->ignore= 0;
 
5997
            if (!(lex->exchange= new sql_exchange($7.str, 0, $2)))
 
5998
              MYSQL_YYABORT;
 
5999
          }
 
6000
          opt_duplicate INTO
 
6001
          {
 
6002
            THD *thd= YYTHD;
 
6003
            LEX *lex= thd->lex;
 
6004
            Lex_input_stream *lip= thd->m_lip;
 
6005
            lex->fname_end= lip->get_ptr();
 
6006
          }
 
6007
          TABLE_SYM table_ident
 
6008
          {
 
6009
            LEX *lex=Lex;
 
6010
            if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
 
6011
                                           lex->lock_option))
 
6012
              MYSQL_YYABORT;
 
6013
            lex->field_list.empty();
 
6014
            lex->update_list.empty();
 
6015
            lex->value_list.empty();
 
6016
          }
 
6017
          opt_load_data_charset
 
6018
          { Lex->exchange->cs= $15; }
 
6019
          opt_xml_rows_identified_by
 
6020
          opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
 
6021
          opt_load_data_set_spec
 
6022
          {}
 
6023
        ;
 
6024
 
 
6025
data_or_xml:
 
6026
        DATA_SYM  { $$= FILETYPE_CSV; }
 
6027
        | XML_SYM { $$= FILETYPE_XML; }
 
6028
        ;
 
6029
 
 
6030
opt_local:
 
6031
          /* empty */ { $$=0;}
 
6032
        | LOCAL_SYM { $$=1;}
 
6033
        ;
 
6034
 
 
6035
load_data_lock:
 
6036
          /* empty */ { $$= TL_WRITE_DEFAULT; }
 
6037
        | CONCURRENT
 
6038
          {
 
6039
              $$= TL_WRITE_CONCURRENT_INSERT;
 
6040
          }
 
6041
        | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
 
6042
        ;
 
6043
 
 
6044
opt_duplicate:
 
6045
          /* empty */ { Lex->duplicates=DUP_ERROR; }
 
6046
        | REPLACE { Lex->duplicates=DUP_REPLACE; }
 
6047
        | IGNORE_SYM { Lex->ignore= 1; }
 
6048
        ;
 
6049
 
 
6050
opt_field_term:
 
6051
          /* empty */
 
6052
        | COLUMNS field_term_list
 
6053
        ;
 
6054
 
 
6055
field_term_list:
 
6056
          field_term_list field_term
 
6057
        | field_term
 
6058
        ;
 
6059
 
 
6060
field_term:
 
6061
          TERMINATED BY text_string 
 
6062
          {
 
6063
            DBUG_ASSERT(Lex->exchange != 0);
 
6064
            Lex->exchange->field_term= $3;
 
6065
          }
 
6066
        | OPTIONALLY ENCLOSED BY text_string
 
6067
          {
 
6068
            LEX *lex= Lex;
 
6069
            DBUG_ASSERT(lex->exchange != 0);
 
6070
            lex->exchange->enclosed= $4;
 
6071
            lex->exchange->opt_enclosed= 1;
 
6072
          }
 
6073
        | ENCLOSED BY text_string
 
6074
          {
 
6075
            DBUG_ASSERT(Lex->exchange != 0);
 
6076
            Lex->exchange->enclosed= $3;
 
6077
          }
 
6078
        | ESCAPED BY text_string
 
6079
          {
 
6080
            DBUG_ASSERT(Lex->exchange != 0);
 
6081
            Lex->exchange->escaped= $3;
 
6082
          }
 
6083
        ;
 
6084
 
 
6085
opt_line_term:
 
6086
          /* empty */
 
6087
        | LINES line_term_list
 
6088
        ;
 
6089
 
 
6090
line_term_list:
 
6091
          line_term_list line_term
 
6092
        | line_term
 
6093
        ;
 
6094
 
 
6095
line_term:
 
6096
          TERMINATED BY text_string
 
6097
          {
 
6098
            DBUG_ASSERT(Lex->exchange != 0);
 
6099
            Lex->exchange->line_term= $3;
 
6100
          }
 
6101
        | STARTING BY text_string
 
6102
          {
 
6103
            DBUG_ASSERT(Lex->exchange != 0);
 
6104
            Lex->exchange->line_start= $3;
 
6105
          }
 
6106
        ;
 
6107
 
 
6108
opt_xml_rows_identified_by:
 
6109
        /* empty */ { }
 
6110
        | ROWS_SYM IDENTIFIED_SYM BY text_string
 
6111
          { Lex->exchange->line_term = $4; };
 
6112
 
 
6113
opt_ignore_lines:
 
6114
          /* empty */
 
6115
        | IGNORE_SYM NUM lines_or_rows
 
6116
          {
 
6117
            DBUG_ASSERT(Lex->exchange != 0);
 
6118
            Lex->exchange->skip_lines= atol($2.str);
 
6119
          }
 
6120
        ;
 
6121
 
 
6122
lines_or_rows:
 
6123
        LINES { }
 
6124
        | ROWS_SYM { }
 
6125
        ;
 
6126
 
 
6127
opt_field_or_var_spec:
 
6128
          /* empty */ {}
 
6129
        | '(' fields_or_vars ')' {}
 
6130
        | '(' ')' {}
 
6131
        ;
 
6132
 
 
6133
fields_or_vars:
 
6134
          fields_or_vars ',' field_or_var
 
6135
          { Lex->field_list.push_back($3); }
 
6136
        | field_or_var
 
6137
          { Lex->field_list.push_back($1); }
 
6138
        ;
 
6139
 
 
6140
field_or_var:
 
6141
          simple_ident_nospvar {$$= $1;}
 
6142
        | '@' ident_or_text
 
6143
          { $$= new Item_user_var_as_out_param($2); }
 
6144
        ;
 
6145
 
 
6146
opt_load_data_set_spec:
 
6147
          /* empty */ {}
 
6148
        | SET insert_update_list {}
 
6149
        ;
 
6150
 
 
6151
/* Common definitions */
 
6152
 
 
6153
text_literal:
 
6154
          TEXT_STRING
 
6155
          {
 
6156
            LEX_STRING tmp;
 
6157
            THD *thd= YYTHD;
 
6158
            CHARSET_INFO *cs_con= thd->variables.collation_connection;
 
6159
            CHARSET_INFO *cs_cli= thd->variables.character_set_client;
 
6160
            uint repertoire= thd->lex->text_string_is_7bit &&
 
6161
                             my_charset_is_ascii_based(cs_cli) ?
 
6162
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
 
6163
            if (thd->charset_is_collation_connection ||
 
6164
                (repertoire == MY_REPERTOIRE_ASCII &&
 
6165
                 my_charset_is_ascii_based(cs_con)))
 
6166
              tmp= $1;
 
6167
            else
 
6168
              thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
 
6169
            $$= new Item_string(tmp.str, tmp.length, cs_con,
 
6170
                                DERIVATION_COERCIBLE, repertoire);
 
6171
          }
 
6172
        | NCHAR_STRING
 
6173
          {
 
6174
            uint repertoire= Lex->text_string_is_7bit ?
 
6175
                             MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
 
6176
            DBUG_ASSERT(my_charset_is_ascii_based(national_charset_info));
 
6177
            $$= new Item_string($1.str, $1.length, national_charset_info,
 
6178
                                DERIVATION_COERCIBLE, repertoire);
 
6179
          }
 
6180
        | UNDERSCORE_CHARSET TEXT_STRING
 
6181
          {
 
6182
            Item_string *str= new Item_string($2.str, $2.length, $1);
 
6183
            str->set_repertoire_from_value();
 
6184
            str->set_cs_specified(TRUE);
 
6185
 
 
6186
            $$= str;
 
6187
          }
 
6188
        | text_literal TEXT_STRING_literal
 
6189
          {
 
6190
            Item_string* item= (Item_string*) $1;
 
6191
            item->append($2.str, $2.length);
 
6192
            if (!(item->collation.repertoire & MY_REPERTOIRE_EXTENDED))
 
6193
            {
 
6194
              /*
 
6195
                 If the string has been pure ASCII so far,
 
6196
                 check the new part.
 
6197
              */
 
6198
              CHARSET_INFO *cs= YYTHD->variables.collation_connection;
 
6199
              item->collation.repertoire|= my_string_repertoire(cs,
 
6200
                                                                $2.str,
 
6201
                                                                $2.length);
 
6202
            }
 
6203
          }
 
6204
        ;
 
6205
 
 
6206
text_string:
 
6207
          TEXT_STRING_literal
 
6208
          {
 
6209
            $$= new (YYTHD->mem_root) String($1.str,
 
6210
                                             $1.length,
 
6211
                                             YYTHD->variables.collation_connection);
 
6212
          }
 
6213
        | HEX_NUM
 
6214
          {
 
6215
            Item *tmp= new Item_hex_string($1.str, $1.length);
 
6216
            /*
 
6217
              it is OK only emulate fix_fields, because we need only
 
6218
              value of constant
 
6219
            */
 
6220
            $$= tmp ?
 
6221
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
 
6222
              (String*) 0;
 
6223
          }
 
6224
        | BIN_NUM
 
6225
          {
 
6226
            Item *tmp= new Item_bin_string($1.str, $1.length);
 
6227
            /*
 
6228
              it is OK only emulate fix_fields, because we need only
 
6229
              value of constant
 
6230
            */
 
6231
            $$= tmp ? tmp->quick_fix_field(), tmp->val_str((String*) 0) :
 
6232
              (String*) 0;
 
6233
          }
 
6234
        ;
 
6235
 
 
6236
param_marker:
 
6237
          PARAM_MARKER
 
6238
          {
 
6239
            THD *thd= YYTHD;
 
6240
            LEX *lex= thd->lex;
 
6241
            Lex_input_stream *lip= thd->m_lip;
 
6242
            Item_param *item;
 
6243
            if (! lex->parsing_options.allows_variable)
 
6244
            {
 
6245
              my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
 
6246
              MYSQL_YYABORT;
 
6247
            }
 
6248
            item= new Item_param((uint) (lip->get_tok_start() - thd->query));
 
6249
            if (!($$= item) || lex->param_list.push_back(item))
 
6250
            {
 
6251
              my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
 
6252
              MYSQL_YYABORT;
 
6253
            }
 
6254
          }
 
6255
        ;
 
6256
 
 
6257
signed_literal:
 
6258
          literal { $$ = $1; }
 
6259
        | '+' NUM_literal { $$ = $2; }
 
6260
        | '-' NUM_literal
 
6261
          {
 
6262
            $2->max_length++;
 
6263
            $$= $2->neg();
 
6264
          }
 
6265
        ;
 
6266
 
 
6267
literal:
 
6268
          text_literal { $$ = $1; }
 
6269
        | NUM_literal { $$ = $1; }
 
6270
        | NULL_SYM
 
6271
          {
 
6272
            $$ = new Item_null();
 
6273
            YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
 
6274
          }
 
6275
        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
 
6276
        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
 
6277
        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
 
6278
        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
 
6279
        | UNDERSCORE_CHARSET HEX_NUM
 
6280
          {
 
6281
            Item *tmp= new Item_hex_string($2.str, $2.length);
 
6282
            /*
 
6283
              it is OK only emulate fix_fieds, because we need only
 
6284
              value of constant
 
6285
            */
 
6286
            String *str= tmp ?
 
6287
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
 
6288
              (String*) 0;
 
6289
 
 
6290
            Item_string *item_str=
 
6291
              new Item_string(NULL, /* name will be set in select_item */
 
6292
                              str ? str->ptr() : "",
 
6293
                              str ? str->length() : 0,
 
6294
                              $1);
 
6295
            if (!item_str ||
 
6296
                !item_str->check_well_formed_result(&item_str->str_value, TRUE))
 
6297
            {
 
6298
              MYSQL_YYABORT;
 
6299
            }
 
6300
 
 
6301
            item_str->set_repertoire_from_value();
 
6302
            item_str->set_cs_specified(TRUE);
 
6303
 
 
6304
            $$= item_str;
 
6305
          }
 
6306
        | UNDERSCORE_CHARSET BIN_NUM
 
6307
          {
 
6308
            Item *tmp= new Item_bin_string($2.str, $2.length);
 
6309
            /*
 
6310
              it is OK only emulate fix_fieds, because we need only
 
6311
              value of constant
 
6312
            */
 
6313
            String *str= tmp ?
 
6314
              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
 
6315
              (String*) 0;
 
6316
 
 
6317
            Item_string *item_str=
 
6318
              new Item_string(NULL, /* name will be set in select_item */
 
6319
                              str ? str->ptr() : "",
 
6320
                              str ? str->length() : 0,
 
6321
                              $1);
 
6322
            if (!item_str ||
 
6323
                !item_str->check_well_formed_result(&item_str->str_value, TRUE))
 
6324
            {
 
6325
              MYSQL_YYABORT;
 
6326
            }
 
6327
 
 
6328
            item_str->set_cs_specified(TRUE);
 
6329
 
 
6330
            $$= item_str;
 
6331
          }
 
6332
        | DATE_SYM text_literal { $$ = $2; }
 
6333
        | TIME_SYM text_literal { $$ = $2; }
 
6334
        | TIMESTAMP text_literal { $$ = $2; }
 
6335
        ;
 
6336
 
 
6337
NUM_literal:
 
6338
          NUM
 
6339
          {
 
6340
            int error;
 
6341
            $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length);
 
6342
          }
 
6343
        | LONG_NUM
 
6344
          {
 
6345
            int error;
 
6346
            $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length);
 
6347
          }
 
6348
        | ULONGLONG_NUM
 
6349
          { $$ = new Item_uint($1.str, $1.length); }
 
6350
        | DECIMAL_NUM
 
6351
          {
 
6352
            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
 
6353
            if (YYTHD->is_error())
 
6354
            {
 
6355
              MYSQL_YYABORT;
 
6356
            }
 
6357
          }
 
6358
        | FLOAT_NUM
 
6359
          {
 
6360
            $$ = new Item_float($1.str, $1.length);
 
6361
            if (YYTHD->is_error())
 
6362
            {
 
6363
              MYSQL_YYABORT;
 
6364
            }
 
6365
          }
 
6366
        ;
 
6367
 
 
6368
/**********************************************************************
 
6369
** Creating different items.
 
6370
**********************************************************************/
 
6371
 
 
6372
insert_ident:
 
6373
          simple_ident_nospvar { $$=$1; }
 
6374
        | table_wild { $$=$1; }
 
6375
        ;
 
6376
 
 
6377
table_wild:
 
6378
          ident '.' '*'
 
6379
          {
 
6380
            SELECT_LEX *sel= Select;
 
6381
            $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
 
6382
            sel->with_wild++;
 
6383
          }
 
6384
        | ident '.' ident '.' '*'
 
6385
          {
 
6386
            SELECT_LEX *sel= Select;
 
6387
            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
 
6388
                                CLIENT_NO_SCHEMA ? NullS : $1.str),
 
6389
                                $3.str,"*");
 
6390
            sel->with_wild++;
 
6391
          }
 
6392
        ;
 
6393
 
 
6394
order_ident:
 
6395
          expr { $$=$1; }
 
6396
        ;
 
6397
 
 
6398
simple_ident:
 
6399
          ident
 
6400
          {
 
6401
            {
 
6402
              SELECT_LEX *sel=Select;
 
6403
              $$= (sel->parsing_place != IN_HAVING ||
 
6404
                  sel->get_in_sum_expr() > 0) ?
 
6405
                  (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
 
6406
                  (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
 
6407
            }
 
6408
          }
 
6409
        | simple_ident_q { $$= $1; }
 
6410
        ;
 
6411
 
 
6412
simple_ident_nospvar:
 
6413
          ident
 
6414
          {
 
6415
            SELECT_LEX *sel=Select;
 
6416
            $$= (sel->parsing_place != IN_HAVING ||
 
6417
                sel->get_in_sum_expr() > 0) ?
 
6418
                (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
 
6419
                (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
 
6420
          }
 
6421
        | simple_ident_q { $$= $1; }
 
6422
        ;
 
6423
 
 
6424
simple_ident_q:
 
6425
          ident '.' ident
 
6426
          {
 
6427
            THD *thd= YYTHD;
 
6428
            LEX *lex= thd->lex;
 
6429
 
 
6430
            {
 
6431
              SELECT_LEX *sel= lex->current_select;
 
6432
              if (sel->no_table_names_allowed)
 
6433
              {
 
6434
                my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6435
                         MYF(0), $1.str, thd->where);
 
6436
              }
 
6437
              $$= (sel->parsing_place != IN_HAVING ||
 
6438
                  sel->get_in_sum_expr() > 0) ?
 
6439
                  (Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
 
6440
                  (Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
 
6441
            }
 
6442
          }
 
6443
        | '.' ident '.' ident
 
6444
          {
 
6445
            THD *thd= YYTHD;
 
6446
            LEX *lex= thd->lex;
 
6447
            SELECT_LEX *sel= lex->current_select;
 
6448
            if (sel->no_table_names_allowed)
 
6449
            {
 
6450
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6451
                       MYF(0), $2.str, thd->where);
 
6452
            }
 
6453
            $$= (sel->parsing_place != IN_HAVING ||
 
6454
                sel->get_in_sum_expr() > 0) ?
 
6455
                (Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
 
6456
                (Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
 
6457
          }
 
6458
        | ident '.' ident '.' ident
 
6459
          {
 
6460
            THD *thd= YYTHD;
 
6461
            LEX *lex= thd->lex;
 
6462
            SELECT_LEX *sel= lex->current_select;
 
6463
            if (sel->no_table_names_allowed)
 
6464
            {
 
6465
              my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
 
6466
                       MYF(0), $3.str, thd->where);
 
6467
            }
 
6468
            $$= (sel->parsing_place != IN_HAVING ||
 
6469
                sel->get_in_sum_expr() > 0) ?
 
6470
                (Item*) new Item_field(Lex->current_context(),
 
6471
                                       (YYTHD->client_capabilities &
 
6472
                                       CLIENT_NO_SCHEMA ? NullS : $1.str),
 
6473
                                       $3.str, $5.str) :
 
6474
                (Item*) new Item_ref(Lex->current_context(),
 
6475
                                     (YYTHD->client_capabilities &
 
6476
                                     CLIENT_NO_SCHEMA ? NullS : $1.str),
 
6477
                                     $3.str, $5.str);
 
6478
          }
 
6479
        ;
 
6480
 
 
6481
field_ident:
 
6482
          ident { $$=$1;}
 
6483
        | ident '.' ident '.' ident
 
6484
          {
 
6485
            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
 
6486
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
6487
            {
 
6488
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
 
6489
              MYSQL_YYABORT;
 
6490
            }
 
6491
            if (my_strcasecmp(table_alias_charset, $3.str,
 
6492
                              table->table_name))
 
6493
            {
 
6494
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
 
6495
              MYSQL_YYABORT;
 
6496
            }
 
6497
            $$=$5;
 
6498
          }
 
6499
        | ident '.' ident
 
6500
          {
 
6501
            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
 
6502
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
 
6503
            {
 
6504
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
 
6505
              MYSQL_YYABORT;
 
6506
            }
 
6507
            $$=$3;
 
6508
          }
 
6509
        | '.' ident { $$=$2;} /* For Delphi */
 
6510
        ;
 
6511
 
 
6512
table_ident:
 
6513
          ident { $$=new Table_ident($1); }
 
6514
        | ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
 
6515
        | '.' ident { $$=new Table_ident($2);} /* For Delphi */
 
6516
        ;
 
6517
 
 
6518
IDENT_sys:
 
6519
          IDENT { $$= $1; }
 
6520
        | IDENT_QUOTED
 
6521
          {
 
6522
            THD *thd= YYTHD;
 
6523
 
 
6524
            if (thd->charset_is_system_charset)
 
6525
            {
 
6526
              CHARSET_INFO *cs= system_charset_info;
 
6527
              int dummy_error;
 
6528
              uint wlen= cs->cset->well_formed_len(cs, $1.str,
 
6529
                                                   $1.str+$1.length,
 
6530
                                                   $1.length, &dummy_error);
 
6531
              if (wlen < $1.length)
 
6532
              {
 
6533
                my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
 
6534
                         cs->csname, $1.str + wlen);
 
6535
                MYSQL_YYABORT;
 
6536
              }
 
6537
              $$= $1;
 
6538
            }
 
6539
            else
 
6540
              thd->convert_string(&$$, system_charset_info,
 
6541
                                  $1.str, $1.length, thd->charset());
 
6542
          }
 
6543
        ;
 
6544
 
 
6545
TEXT_STRING_sys:
 
6546
          TEXT_STRING
 
6547
          {
 
6548
            THD *thd= YYTHD;
 
6549
 
 
6550
            if (thd->charset_is_system_charset)
 
6551
              $$= $1;
 
6552
            else
 
6553
              thd->convert_string(&$$, system_charset_info,
 
6554
                                  $1.str, $1.length, thd->charset());
 
6555
          }
 
6556
        ;
 
6557
 
 
6558
TEXT_STRING_literal:
 
6559
          TEXT_STRING
 
6560
          {
 
6561
            THD *thd= YYTHD;
 
6562
 
 
6563
            if (thd->charset_is_collation_connection)
 
6564
              $$= $1;
 
6565
            else
 
6566
              thd->convert_string(&$$, thd->variables.collation_connection,
 
6567
                                  $1.str, $1.length, thd->charset());
 
6568
          }
 
6569
        ;
 
6570
 
 
6571
TEXT_STRING_filesystem:
 
6572
          TEXT_STRING
 
6573
          {
 
6574
            THD *thd= YYTHD;
 
6575
 
 
6576
            if (thd->charset_is_character_set_filesystem)
 
6577
              $$= $1;
 
6578
            else
 
6579
              thd->convert_string(&$$, thd->variables.character_set_filesystem,
 
6580
                                  $1.str, $1.length, thd->charset());
 
6581
          }
 
6582
        ;
 
6583
 
 
6584
ident:
 
6585
          IDENT_sys    { $$=$1; }
 
6586
        | keyword
 
6587
          {
 
6588
            THD *thd= YYTHD;
 
6589
            $$.str= thd->strmake($1.str, $1.length);
 
6590
            $$.length= $1.length;
 
6591
          }
 
6592
        ;
 
6593
 
 
6594
ident_or_text:
 
6595
          ident           { $$=$1;}
 
6596
        | TEXT_STRING_sys { $$=$1;}
 
6597
        | LEX_HOSTNAME { $$=$1;}
 
6598
        ;
 
6599
 
 
6600
/* Keyword that we allow for identifiers (except SP labels) */
 
6601
keyword:
 
6602
          keyword_sp            {}
 
6603
        | ASCII_SYM             {}
 
6604
        | BEGIN_SYM             {}
 
6605
        | BYTE_SYM              {}
 
6606
        | CACHE_SYM             {}
 
6607
        | CHARSET               {}
 
6608
        | CHECKSUM_SYM          {}
 
6609
        | CLOSE_SYM             {}
 
6610
        | COMMENT_SYM           {}
 
6611
        | COMMIT_SYM            {}
 
6612
        | CONTAINS_SYM          {}
 
6613
        | DEALLOCATE_SYM        {}
 
6614
        | END                   {}
 
6615
        | FLUSH_SYM             {}
 
6616
        | HANDLER_SYM           {}
 
6617
        | HOST_SYM              {}
 
6618
        | INSTALL_SYM           {}
 
6619
        | NO_SYM                {}
 
6620
        | OPEN_SYM              {}
 
6621
        | OPTIONS_SYM           {}
 
6622
        | PORT_SYM              {}
 
6623
        | REMOVE_SYM            {}
 
6624
        | REPAIR                {}
 
6625
        | RESET_SYM             {}
 
6626
        | ROLLBACK_SYM          {}
 
6627
        | SAVEPOINT_SYM         {}
 
6628
        | SECURITY_SYM          {}
 
6629
        | SERVER_SYM            {}
 
6630
        | SIGNED_SYM            {}
 
6631
        | SOCKET_SYM            {}
 
6632
        | SLAVE                 {}
 
6633
        | SONAME_SYM            {}
 
6634
        | START_SYM             {}
 
6635
        | STOP_SYM              {}
 
6636
        | TRUNCATE_SYM          {}
 
6637
        | UNICODE_SYM           {}
 
6638
        | UNINSTALL_SYM         {}
 
6639
        | WRAPPER_SYM           {}
 
6640
        | UPGRADE_SYM           {}
 
6641
        ;
 
6642
 
 
6643
/*
 
6644
 * Keywords that we allow for labels in SPs.
 
6645
 * Anything that's the beginning of a statement or characteristics
 
6646
 * must be in keyword above, otherwise we get (harmful) shift/reduce
 
6647
 * conflicts.
 
6648
 */
 
6649
keyword_sp:
 
6650
          ACTION                   {}
 
6651
        | ADDDATE_SYM              {}
 
6652
        | AFTER_SYM                {}
 
6653
        | AGGREGATE_SYM            {}
 
6654
        | ALGORITHM_SYM            {}
 
6655
        | ANY_SYM                  {}
 
6656
        | AT_SYM                   {}
 
6657
        | AUTHORS_SYM              {}
 
6658
        | AUTO_INC                 {}
 
6659
        | AUTOEXTEND_SIZE_SYM      {}
 
6660
        | AVG_ROW_LENGTH           {}
 
6661
        | AVG_SYM                  {}
 
6662
        | BINLOG_SYM               {}
 
6663
        | BIT_SYM                  {}
 
6664
        | BLOCK_SYM                {}
 
6665
        | BOOL_SYM                 {}
 
6666
        | BOOLEAN_SYM              {}
 
6667
        | BTREE_SYM                {}
 
6668
        | CASCADED                 {}
 
6669
        | CHAIN_SYM                {}
 
6670
        | CHANGED                  {}
 
6671
        | CIPHER_SYM               {}
 
6672
        | CLIENT_SYM               {}
 
6673
        | COALESCE                 {}
 
6674
        | CODE_SYM                 {}
 
6675
        | COLLATION_SYM            {}
 
6676
        | COLUMN_FORMAT_SYM        {}
 
6677
        | COLUMNS                  {}
 
6678
        | COMMITTED_SYM            {}
 
6679
        | COMPACT_SYM              {}
 
6680
        | COMPLETION_SYM           {}
 
6681
        | COMPRESSED_SYM           {}
 
6682
        | CONCURRENT               {}
 
6683
        | CONNECTION_SYM           {}
 
6684
        | CONSISTENT_SYM           {}
 
6685
        | CONTEXT_SYM              {}
 
6686
        | CONTRIBUTORS_SYM         {}
 
6687
        | CPU_SYM                  {}
 
6688
        | CUBE_SYM                 {}
 
6689
        | DATA_SYM                 {}
 
6690
        | DATAFILE_SYM             {}
 
6691
        | DATETIME                 {}
 
6692
        | DATE_SYM                 {}
 
6693
        | DAY_SYM                  {}
 
6694
        | DEFINER_SYM              {}
 
6695
        | DELAY_KEY_WRITE_SYM      {}
 
6696
        | DES_KEY_FILE             {}
 
6697
        | DIRECTORY_SYM            {}
 
6698
        | DISABLE_SYM              {}
 
6699
        | DISCARD                  {}
 
6700
        | DISK_SYM                 {}
 
6701
        | DUMPFILE                 {}
 
6702
        | DUPLICATE_SYM            {}
 
6703
        | DYNAMIC_SYM              {}
 
6704
        | ENDS_SYM                 {}
 
6705
        | ENUM                     {}
 
6706
        | ENGINE_SYM               {}
 
6707
        | ENGINES_SYM              {}
 
6708
        | ERRORS                   {}
 
6709
        | ESCAPE_SYM               {}
 
6710
        | EVENTS_SYM               {}
 
6711
        | EVERY_SYM                {}
 
6712
        | EXCLUSIVE_SYM            {}
 
6713
        | EXTENDED_SYM             {}
 
6714
        | EXTENT_SIZE_SYM          {}
 
6715
        | FAULTS_SYM               {}
 
6716
        | FAST_SYM                 {}
 
6717
        | FOUND_SYM                {}
 
6718
        | ENABLE_SYM               {}
 
6719
        | FULL                     {}
 
6720
        | FILE_SYM                 {}
 
6721
        | FIRST_SYM                {}
 
6722
        | FIXED_SYM                {}
 
6723
        | FRAC_SECOND_SYM          {}
 
6724
        | GET_FORMAT               {}
 
6725
        | GLOBAL_SYM               {}
 
6726
        | HASH_SYM                 {}
 
6727
        | HOSTS_SYM                {}
 
6728
        | HOUR_SYM                 {}
 
6729
        | IDENTIFIED_SYM           {}
 
6730
        | IMPORT                   {}
 
6731
        | INDEXES                  {}
 
6732
        | INITIAL_SIZE_SYM         {}
 
6733
        | IO_SYM                   {}
 
6734
        | IPC_SYM                  {}
 
6735
        | ISOLATION                {}
 
6736
        | ISSUER_SYM               {}
 
6737
        | INSERT_METHOD            {}
 
6738
        | KEY_BLOCK_SIZE           {}
 
6739
        | LAST_SYM                 {}
 
6740
        | LEAVES                   {}
 
6741
        | LEVEL_SYM                {}
 
6742
        | LINESTRING               {}
 
6743
        | LIST_SYM                 {}
 
6744
        | LOCAL_SYM                {}
 
6745
        | LOCKS_SYM                {}
 
6746
        | LOGFILE_SYM              {}
 
6747
        | LOGS_SYM                 {}
 
6748
        | MAX_ROWS                 {}
 
6749
        | MASTER_SYM               {}
 
6750
        | MASTER_HOST_SYM          {}
 
6751
        | MASTER_PORT_SYM          {}
 
6752
        | MASTER_LOG_FILE_SYM      {}
 
6753
        | MASTER_LOG_POS_SYM       {}
 
6754
        | MASTER_USER_SYM          {}
 
6755
        | MASTER_PASSWORD_SYM      {}
 
6756
        | MASTER_SERVER_ID_SYM     {}
 
6757
        | MASTER_CONNECT_RETRY_SYM {}
 
6758
        | MAX_CONNECTIONS_PER_HOUR {}
 
6759
        | MAX_QUERIES_PER_HOUR     {}
 
6760
        | MAX_SIZE_SYM             {}
 
6761
        | MAX_UPDATES_PER_HOUR     {}
 
6762
        | MAX_USER_CONNECTIONS_SYM {}
 
6763
        | MAX_VALUE_SYM            {}
 
6764
        | MEDIUM_SYM               {}
 
6765
        | MEMORY_SYM               {}
 
6766
        | MERGE_SYM                {}
 
6767
        | MICROSECOND_SYM          {}
 
6768
        | MIGRATE_SYM              {}
 
6769
        | MINUTE_SYM               {}
 
6770
        | MIN_ROWS                 {}
 
6771
        | MODIFY_SYM               {}
 
6772
        | MODE_SYM                 {}
 
6773
        | MONTH_SYM                {}
 
6774
        | MUTEX_SYM                {}
 
6775
        | NAME_SYM                 {}
 
6776
        | NAMES_SYM                {}
 
6777
        | NATIONAL_SYM             {}
 
6778
        | NCHAR_SYM                {}
 
6779
        | NEXT_SYM                 {}
 
6780
        | NEW_SYM                  {}
 
6781
        | NO_WAIT_SYM              {}
 
6782
        | NODEGROUP_SYM            {}
 
6783
        | NONE_SYM                 {}
 
6784
        | NOWAIT_SYM               {}
 
6785
        | NVARCHAR_SYM             {}
 
6786
        | OFFLINE_SYM              {}
 
6787
        | OFFSET_SYM               {}
 
6788
        | OLD_PASSWORD             {}
 
6789
        | ONE_SHOT_SYM             {}
 
6790
        | ONE_SYM                  {}
 
6791
        | ONLINE_SYM               {}
 
6792
        | PACK_KEYS_SYM            {}
 
6793
        | PAGE_SYM                 {}
 
6794
        | PAGE_CHECKSUM_SYM        {}
 
6795
        | PARTIAL                  {}
 
6796
        | PASSWORD                 {}
 
6797
        | PHASE_SYM                {}
 
6798
        | PLUGIN_SYM               {}
 
6799
        | PLUGINS_SYM              {}
 
6800
        | POINT_SYM                {}
 
6801
        | PREV_SYM                 {}
 
6802
        | PROCESS                  {}
 
6803
        | PROCESSLIST_SYM          {}
 
6804
        | PROFILE_SYM              {}
 
6805
        | PROFILES_SYM             {}
 
6806
        | QUARTER_SYM              {}
 
6807
        | QUERY_SYM                {}
 
6808
        | QUICK                    {}
 
6809
        | READ_ONLY_SYM            {}
 
6810
        | REBUILD_SYM              {}
 
6811
        | RECOVER_SYM              {}
 
6812
        | REDO_BUFFER_SIZE_SYM     {}
 
6813
        | REDOFILE_SYM             {}
 
6814
        | REDUNDANT_SYM            {}
 
6815
        | RELAY_LOG_FILE_SYM       {}
 
6816
        | RELAY_LOG_POS_SYM        {}
 
6817
        | RELAY_THREAD             {}
 
6818
        | RELOAD                   {}
 
6819
        | REORGANIZE_SYM           {}
 
6820
        | REPEATABLE_SYM           {}
 
6821
        | REPLICATION              {}
 
6822
        | RESOURCES                {}
 
6823
        | RESUME_SYM               {}
 
6824
        | RETURNS_SYM              {}
 
6825
        | REVERSE_SYM              {}
 
6826
        | ROLLUP_SYM               {}
 
6827
        | ROUTINE_SYM              {}
 
6828
        | ROWS_SYM                 {}
 
6829
        | ROW_FORMAT_SYM           {}
 
6830
        | ROW_SYM                  {}
 
6831
        | SECOND_SYM               {}
 
6832
        | SERIAL_SYM               {}
 
6833
        | SERIALIZABLE_SYM         {}
 
6834
        | SESSION_SYM              {}
 
6835
        | SIMPLE_SYM               {}
 
6836
        | SHARE_SYM                {}
 
6837
        | SHUTDOWN                 {}
 
6838
        | SNAPSHOT_SYM             {}
 
6839
        | SOURCE_SYM               {}
 
6840
        | SQL_BUFFER_RESULT        {}
 
6841
        | SQL_THREAD               {}
 
6842
        | STARTS_SYM               {}
 
6843
        | STATUS_SYM               {}
 
6844
        | STORAGE_SYM              {}
 
6845
        | STRING_SYM               {}
 
6846
        | SUBDATE_SYM              {}
 
6847
        | SUBJECT_SYM              {}
 
6848
        | SUPER_SYM                {}
 
6849
        | SUSPEND_SYM              {}
 
6850
        | SWAPS_SYM                {}
 
6851
        | SWITCHES_SYM             {}
 
6852
        | TABLES                   {}
 
6853
        | TABLE_CHECKSUM_SYM       {}
 
6854
        | TABLESPACE               {}
 
6855
        | TEMPORARY                {}
 
6856
        | TEMPTABLE_SYM            {}
 
6857
        | TEXT_SYM                 {}
 
6858
        | THAN_SYM                 {}
 
6859
        | TRANSACTION_SYM          {}
 
6860
        | TRANSACTIONAL_SYM        {}
 
6861
        | TIMESTAMP                {}
 
6862
        | TIMESTAMP_ADD            {}
 
6863
        | TIMESTAMP_DIFF           {}
 
6864
        | TIME_SYM                 {}
 
6865
        | TYPES_SYM                {}
 
6866
        | TYPE_SYM                 {}
 
6867
        | UDF_RETURNS_SYM          {}
 
6868
        | FUNCTION_SYM             {}
 
6869
        | UNCOMMITTED_SYM          {}
 
6870
        | UNDEFINED_SYM            {}
 
6871
        | UNDO_BUFFER_SIZE_SYM     {}
 
6872
        | UNDOFILE_SYM             {}
 
6873
        | UNKNOWN_SYM              {}
 
6874
        | UNTIL_SYM                {}
 
6875
        | USER                     {}
 
6876
        | USE_FRM                  {}
 
6877
        | VARIABLES                {}
 
6878
        | VALUE_SYM                {}
 
6879
        | WARNINGS                 {}
 
6880
        | WAIT_SYM                 {}
 
6881
        | WEEK_SYM                 {}
 
6882
        | WEIGHT_STRING_SYM        {}
 
6883
        | WORK_SYM                 {}
 
6884
        | XML_SYM                  {}
 
6885
        | YEAR_SYM                 {}
 
6886
        ;
 
6887
 
 
6888
/* Option functions */
 
6889
 
 
6890
set:
 
6891
          SET opt_option
 
6892
          {
 
6893
            LEX *lex=Lex;
 
6894
            lex->sql_command= SQLCOM_SET_OPTION;
 
6895
            mysql_init_select(lex);
 
6896
            lex->option_type=OPT_SESSION;
 
6897
            lex->var_list.empty();
 
6898
            lex->one_shot_set= 0;
 
6899
            lex->autocommit= 0;
 
6900
          }
 
6901
          option_value_list
 
6902
          {}
 
6903
        ;
 
6904
 
 
6905
opt_option:
 
6906
          /* empty */ {}
 
6907
        | OPTION {}
 
6908
        ;
 
6909
 
 
6910
option_value_list:
 
6911
          option_type_value
 
6912
        | option_value_list ',' option_type_value
 
6913
        ;
 
6914
 
 
6915
option_type_value:
 
6916
          {
 
6917
          }
 
6918
          ext_option_value
 
6919
          {
 
6920
          }
 
6921
        ;
 
6922
 
 
6923
option_type:
 
6924
          option_type2    {}
 
6925
        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
 
6926
        | LOCAL_SYM   { $$=OPT_SESSION; }
 
6927
        | SESSION_SYM { $$=OPT_SESSION; }
 
6928
        ;
 
6929
 
 
6930
option_type2:
 
6931
          /* empty */ { $$= OPT_DEFAULT; }
 
6932
        | ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
 
6933
        ;
 
6934
 
 
6935
opt_var_type:
 
6936
          /* empty */ { $$=OPT_SESSION; }
 
6937
        | GLOBAL_SYM  { $$=OPT_GLOBAL; }
 
6938
        | LOCAL_SYM   { $$=OPT_SESSION; }
 
6939
        | SESSION_SYM { $$=OPT_SESSION; }
 
6940
        ;
 
6941
 
 
6942
opt_var_ident_type:
 
6943
          /* empty */     { $$=OPT_DEFAULT; }
 
6944
        | GLOBAL_SYM '.'  { $$=OPT_GLOBAL; }
 
6945
        | LOCAL_SYM '.'   { $$=OPT_SESSION; }
 
6946
        | SESSION_SYM '.' { $$=OPT_SESSION; }
 
6947
        ;
 
6948
 
 
6949
ext_option_value:
 
6950
          sys_option_value
 
6951
        | option_type2 option_value
 
6952
        ;
 
6953
 
 
6954
sys_option_value:
 
6955
          option_type internal_variable_name equal set_expr_or_default
 
6956
          {
 
6957
            LEX *lex=Lex;
 
6958
 
 
6959
            if ($2.var)
 
6960
            { /* System variable */
 
6961
              if ($1)
 
6962
                lex->option_type= $1;
 
6963
              lex->var_list.push_back(new set_var(lex->option_type, $2.var,
 
6964
                                      &$2.base_name, $4));
 
6965
            }
 
6966
          }
 
6967
        | option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
 
6968
          {
 
6969
            LEX *lex=Lex;
 
6970
            lex->option_type= $1;
 
6971
            lex->var_list.push_back(new set_var(lex->option_type,
 
6972
                                                find_sys_var(YYTHD, "tx_isolation"),
 
6973
                                                &null_lex_str,
 
6974
                                                new Item_int((int32) $5)));
 
6975
          }
 
6976
        ;
 
6977
 
 
6978
option_value:
 
6979
          '@' ident_or_text equal expr
 
6980
          {
 
6981
            Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
 
6982
          }
 
6983
        | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
 
6984
          {
 
6985
            LEX *lex=Lex;
 
6986
            lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
 
6987
          }
 
6988
        | charset old_or_new_charset_name_or_default
 
6989
          {
 
6990
            THD *thd= YYTHD;
 
6991
            LEX *lex= thd->lex;
 
6992
            $2= $2 ? $2: global_system_variables.character_set_client;
 
6993
            lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
 
6994
          }
 
6995
        | NAMES_SYM charset_name_or_default opt_collate
 
6996
          {
 
6997
            LEX *lex= Lex;
 
6998
            $2= $2 ? $2 : global_system_variables.character_set_client;
 
6999
            $3= $3 ? $3 : $2;
 
7000
            if (!my_charset_same($2,$3))
 
7001
            {
 
7002
              my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
7003
                       $3->name, $2->csname);
 
7004
              MYSQL_YYABORT;
 
7005
            }
 
7006
            lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
 
7007
          }
 
7008
        ;
 
7009
 
 
7010
internal_variable_name:
 
7011
          ident
 
7012
          {
 
7013
            THD *thd= YYTHD;
 
7014
 
 
7015
            /* We have to lookup here since local vars can shadow sysvars */
 
7016
            {
 
7017
              /* Not an SP local variable */
 
7018
              sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
 
7019
              if (!tmp)
 
7020
                MYSQL_YYABORT;
 
7021
              $$.var= tmp;
 
7022
              $$.base_name= null_lex_str;
 
7023
            }
 
7024
          }
 
7025
        | ident '.' ident
 
7026
          {
 
7027
            if (check_reserved_words(&$1))
 
7028
            {
 
7029
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
7030
              MYSQL_YYABORT;
 
7031
            }
 
7032
            {
 
7033
              sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
7034
              if (!tmp)
 
7035
                MYSQL_YYABORT;
 
7036
              if (!tmp->is_struct())
 
7037
                my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 
7038
              $$.var= tmp;
 
7039
              $$.base_name= $1;
 
7040
            }
 
7041
          }
 
7042
        | DEFAULT '.' ident
 
7043
          {
 
7044
            sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
 
7045
            if (!tmp)
 
7046
              MYSQL_YYABORT;
 
7047
            if (!tmp->is_struct())
 
7048
              my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
 
7049
            $$.var= tmp;
 
7050
            $$.base_name.str=    (char*) "default";
 
7051
            $$.base_name.length= 7;
 
7052
          }
 
7053
        ;
 
7054
 
 
7055
isolation_types:
 
7056
          READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
 
7057
        | READ_SYM COMMITTED_SYM   { $$= ISO_READ_COMMITTED; }
 
7058
        | REPEATABLE_SYM READ_SYM  { $$= ISO_REPEATABLE_READ; }
 
7059
        | SERIALIZABLE_SYM         { $$= ISO_SERIALIZABLE; }
 
7060
        ;
 
7061
 
 
7062
set_expr_or_default:
 
7063
          expr { $$=$1; }
 
7064
        | DEFAULT { $$=0; }
 
7065
        | ON     { $$=new Item_string("ON",  2, system_charset_info); }
 
7066
        | ALL    { $$=new Item_string("ALL", 3, system_charset_info); }
 
7067
        | BINARY { $$=new Item_string("binary", 6, system_charset_info); }
 
7068
        ;
 
7069
 
 
7070
/* Lock function */
 
7071
 
 
7072
lock:
 
7073
          LOCK_SYM
 
7074
          {
 
7075
            /*
 
7076
              Transactional locks can be taken only if all requested locks
 
7077
              are transactional. Initialize lex->lock_transactional as
 
7078
              TRUE. Any non-transactional lock request turns this to FALSE.
 
7079
              Table specific variables keep track of the locking method
 
7080
              requested for the table. This is used to warn about a
 
7081
              changed locking method later.
 
7082
            */
 
7083
            Lex->lock_transactional= TRUE;
 
7084
          }
 
7085
          table_or_tables
 
7086
          {
 
7087
            LEX *lex= Lex;
 
7088
            lex->sql_command= SQLCOM_LOCK_TABLES;
 
7089
          }
 
7090
          table_lock_list
 
7091
          {}
 
7092
        ;
 
7093
 
 
7094
table_or_tables:
 
7095
          TABLE_SYM
 
7096
        | TABLES
 
7097
        ;
 
7098
 
 
7099
table_lock_list:
 
7100
          table_lock
 
7101
        | table_lock_list ',' table_lock
 
7102
        ;
 
7103
 
 
7104
table_lock:
 
7105
        table_ident opt_table_alias table_lock_info
 
7106
        {
 
7107
          TABLE_LIST *tlist;
 
7108
          if (!(tlist= Select->add_table_to_list(YYTHD, $1, $2, 0,
 
7109
                                                 $3.lock_type)))
 
7110
            MYSQL_YYABORT; /* purecov: inspected */
 
7111
          tlist->lock_timeout= $3.lock_timeout;
 
7112
          /* Store the requested lock method for later warning. */
 
7113
          tlist->lock_transactional= $3.lock_transactional;
 
7114
          /* Compute the resulting lock method for all tables. */
 
7115
          if (!$3.lock_transactional)
 
7116
            Lex->lock_transactional= FALSE;
 
7117
        }
 
7118
        ;
 
7119
 
 
7120
table_lock_info:
 
7121
        READ_SYM
 
7122
        {
 
7123
          $$.lock_type=          TL_READ_NO_INSERT;
 
7124
          $$.lock_timeout=       -1;
 
7125
          $$.lock_transactional= FALSE;
 
7126
        }
 
7127
        | WRITE_SYM
 
7128
        {
 
7129
          $$.lock_type=          TL_WRITE_DEFAULT;
 
7130
          $$.lock_timeout=       -1;
 
7131
          $$.lock_transactional= FALSE;
 
7132
        }
 
7133
        | LOW_PRIORITY WRITE_SYM
 
7134
        {
 
7135
          $$.lock_type=          TL_WRITE_LOW_PRIORITY;
 
7136
          $$.lock_timeout=       -1;
 
7137
          $$.lock_transactional= FALSE;
 
7138
        }
 
7139
        | READ_SYM LOCAL_SYM
 
7140
        {
 
7141
          $$.lock_type=          TL_READ;
 
7142
          $$.lock_timeout=       -1;
 
7143
          $$.lock_transactional= FALSE;
 
7144
        }
 
7145
        | IN_SYM transactional_lock_mode MODE_SYM opt_transactional_lock_timeout
 
7146
        {
 
7147
          $$.lock_type=          $2;
 
7148
          $$.lock_timeout=       $4;
 
7149
          $$.lock_transactional= TRUE;
 
7150
        }
 
7151
        ;
 
7152
 
 
7153
/* Use thr_lock_type here for easier fallback to non-trans locking. */
 
7154
transactional_lock_mode:
 
7155
        SHARE_SYM       { $$= TL_READ_NO_INSERT; }
 
7156
        | EXCLUSIVE_SYM { $$= TL_WRITE_DEFAULT; }
 
7157
        ;
 
7158
 
 
7159
opt_transactional_lock_timeout:
 
7160
        /* empty */     { $$= -1; }
 
7161
        | NOWAIT_SYM    { $$= 0; }
 
7162
        /* | WAIT_SYM opt_lock_timeout_value { $$= $2; } */
 
7163
        ;
 
7164
 
 
7165
/*
 
7166
  We have a timeout resolution of milliseconds. The WAIT argument is in
 
7167
  seconds with decimal fragments for sub-second resolution. E.g. 22.5, 0.015
 
7168
*/
 
7169
/* opt_lock_timeout_value: */
 
7170
        /* empty { $$= -1; } */
 
7171
        /* | NUM       { $$= (int) (atof($1.str) * 1000.0 + 0.5); } */
 
7172
 
 
7173
unlock:
 
7174
          UNLOCK_SYM
 
7175
          {
 
7176
            LEX *lex= Lex;
 
7177
            lex->sql_command= SQLCOM_UNLOCK_TABLES;
 
7178
          }
 
7179
          table_or_tables
 
7180
          {}
 
7181
        ;
 
7182
 
 
7183
begin:
 
7184
          BEGIN_SYM
 
7185
          {
 
7186
            LEX *lex=Lex;
 
7187
            lex->sql_command = SQLCOM_BEGIN;
 
7188
            lex->start_transaction_opt= 0;
 
7189
          }
 
7190
          opt_work {}
 
7191
        ;
 
7192
 
 
7193
opt_work:
 
7194
          /* empty */ {}
 
7195
        | WORK_SYM  {}
 
7196
        ;
 
7197
 
 
7198
opt_chain:
 
7199
          /* empty */
 
7200
          { $$= (YYTHD->variables.completion_type == 1); }
 
7201
        | AND_SYM NO_SYM CHAIN_SYM { $$=0; }
 
7202
        | AND_SYM CHAIN_SYM        { $$=1; }
 
7203
        ;
 
7204
 
 
7205
opt_release:
 
7206
          /* empty */
 
7207
          { $$= (YYTHD->variables.completion_type == 2); }
 
7208
        | RELEASE_SYM        { $$=1; }
 
7209
        | NO_SYM RELEASE_SYM { $$=0; }
 
7210
;
 
7211
 
 
7212
opt_savepoint:
 
7213
          /* empty */ {}
 
7214
        | SAVEPOINT_SYM {}
 
7215
        ;
 
7216
 
 
7217
commit:
 
7218
          COMMIT_SYM opt_work opt_chain opt_release
 
7219
          {
 
7220
            LEX *lex=Lex;
 
7221
            lex->sql_command= SQLCOM_COMMIT;
 
7222
            lex->tx_chain= $3; 
 
7223
            lex->tx_release= $4;
 
7224
          }
 
7225
        ;
 
7226
 
 
7227
rollback:
 
7228
          ROLLBACK_SYM opt_work opt_chain opt_release
 
7229
          {
 
7230
            LEX *lex=Lex;
 
7231
            lex->sql_command= SQLCOM_ROLLBACK;
 
7232
            lex->tx_chain= $3; 
 
7233
            lex->tx_release= $4;
 
7234
          }
 
7235
        | ROLLBACK_SYM opt_work
 
7236
          TO_SYM opt_savepoint ident
 
7237
          {
 
7238
            LEX *lex=Lex;
 
7239
            lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
 
7240
            lex->ident= $5;
 
7241
          }
 
7242
        ;
 
7243
 
 
7244
savepoint:
 
7245
          SAVEPOINT_SYM ident
 
7246
          {
 
7247
            LEX *lex=Lex;
 
7248
            lex->sql_command= SQLCOM_SAVEPOINT;
 
7249
            lex->ident= $2;
 
7250
          }
 
7251
        ;
 
7252
 
 
7253
release:
 
7254
          RELEASE_SYM SAVEPOINT_SYM ident
 
7255
          {
 
7256
            LEX *lex=Lex;
 
7257
            lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
 
7258
            lex->ident= $3;
 
7259
          }
 
7260
        ;
 
7261
 
 
7262
/*
 
7263
   UNIONS : glue selects together
 
7264
*/
 
7265
 
 
7266
 
 
7267
union_clause:
 
7268
          /* empty */ {}
 
7269
        | union_list
 
7270
        ;
 
7271
 
 
7272
union_list:
 
7273
          UNION_SYM union_option
 
7274
          {
 
7275
            if (add_select_to_union_list(Lex, (bool)$2))
 
7276
              MYSQL_YYABORT;
 
7277
          }
 
7278
          select_init
 
7279
          {
 
7280
            /*
 
7281
              Remove from the name resolution context stack the context of the
 
7282
              last select in the union.
 
7283
            */
 
7284
            Lex->pop_context();
 
7285
          }
 
7286
        ;
 
7287
 
 
7288
union_opt:
 
7289
          /* Empty */ { $$= 0; }
 
7290
        | union_list { $$= 1; }
 
7291
        | union_order_or_limit { $$= 1; }
 
7292
        ;
 
7293
 
 
7294
union_order_or_limit:
 
7295
          {
 
7296
            THD *thd= YYTHD;
 
7297
            LEX *lex= thd->lex;
 
7298
            DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
 
7299
            SELECT_LEX *sel= lex->current_select;
 
7300
            SELECT_LEX_UNIT *unit= sel->master_unit();
 
7301
            SELECT_LEX *fake= unit->fake_select_lex;
 
7302
            if (fake)
 
7303
            {
 
7304
              unit->global_parameters= fake;
 
7305
              fake->no_table_names_allowed= 1;
 
7306
              lex->current_select= fake;
 
7307
            }
 
7308
            thd->where= "global ORDER clause";
 
7309
          }
 
7310
          order_or_limit
 
7311
          {
 
7312
            THD *thd= YYTHD;
 
7313
            thd->lex->current_select->no_table_names_allowed= 0;
 
7314
            thd->where= "";
 
7315
          }
 
7316
        ;
 
7317
 
 
7318
order_or_limit:
 
7319
          order_clause opt_limit_clause_init
 
7320
        | limit_clause
 
7321
        ;
 
7322
 
 
7323
union_option:
 
7324
          /* empty */ { $$=1; }
 
7325
        | DISTINCT  { $$=1; }
 
7326
        | ALL       { $$=0; }
 
7327
        ;
 
7328
 
 
7329
query_specification:
 
7330
          SELECT_SYM select_init2_derived
 
7331
          { 
 
7332
            $$= Lex->current_select->master_unit()->first_select();
 
7333
          }
 
7334
        | '(' select_paren_derived ')'
 
7335
          {
 
7336
            $$= Lex->current_select->master_unit()->first_select();
 
7337
          }
 
7338
        ;
 
7339
 
 
7340
query_expression_body:
 
7341
          query_specification
 
7342
        | query_expression_body
 
7343
          UNION_SYM union_option 
 
7344
          {
 
7345
            if (add_select_to_union_list(Lex, (bool)$3))
 
7346
              MYSQL_YYABORT;
 
7347
          }
 
7348
          query_specification
 
7349
          {
 
7350
            Lex->pop_context();
 
7351
            $$= $1;
 
7352
          }
 
7353
        ;
 
7354
 
 
7355
/* Corresponds to <query expression> in the SQL:2003 standard. */
 
7356
subselect:
 
7357
          subselect_start query_expression_body subselect_end
 
7358
          { 
 
7359
            $$= $2;
 
7360
          }
 
7361
        ;
 
7362
 
 
7363
subselect_start:
 
7364
          {
 
7365
            LEX *lex=Lex;
 
7366
            if (!lex->expr_allows_subselect ||
 
7367
               lex->sql_command == (int)SQLCOM_PURGE)
 
7368
            {
 
7369
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
7370
              MYSQL_YYABORT;
 
7371
            }
 
7372
            /* 
 
7373
              we are making a "derived table" for the parenthesis
 
7374
              as we need to have a lex level to fit the union 
 
7375
              after the parenthesis, e.g. 
 
7376
              (SELECT .. ) UNION ...  becomes 
 
7377
              SELECT * FROM ((SELECT ...) UNION ...)
 
7378
            */
 
7379
            if (mysql_new_select(Lex, 1))
 
7380
              MYSQL_YYABORT;
 
7381
          }
 
7382
        ;
 
7383
 
 
7384
subselect_end:
 
7385
          {
 
7386
            LEX *lex=Lex;
 
7387
            lex->pop_context();
 
7388
            SELECT_LEX *child= lex->current_select;
 
7389
            lex->current_select = lex->current_select->return_after_parsing();
 
7390
            lex->nest_level--;
 
7391
            lex->current_select->n_child_sum_items += child->n_sum_items;
 
7392
            /*
 
7393
              A subselect can add fields to an outer select. Reserve space for
 
7394
              them.
 
7395
            */
 
7396
            lex->current_select->select_n_where_fields+=
 
7397
            child->select_n_where_fields;
 
7398
          }
 
7399
        ;
 
7400
/**
 
7401
  @} (end of group Parser)
 
7402
*/