~drizzle-trunk/drizzle/development

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