1
/* Copyright (C) 2000-2003 MySQL AB
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.
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.
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 */
19
@defgroup Parser Parser
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.
28
#define YYPARSE_PARAM yythd
29
#define YYLEX_PARAM yythd
30
#define YYTHD ((THD *)yythd)
33
#define YYINITDEPTH 100
34
#define YYMAXDEPTH 3200 /* Because of 64K stack */
35
#define Lex (YYTHD->lex)
36
#define Select Lex->current_select
37
#include "mysql_priv.h"
39
#include "lex_symbol.h"
40
#include "item_create.h"
43
int yylex(void *yylval, void *yythd);
45
#define yyoverflow(A,B,C,D,E,F) \
48
if (my_yyoverflow((B), (D), &val)) \
50
yyerror((char*) (A)); \
55
*(F)= (YYSIZE_T)val; \
59
#define MYSQL_YYABORT \
62
LEX::cleanup_lex_after_parse_error(YYTHD);\
66
#define MYSQL_YYABORT_UNLESS(A) \
69
my_parse_error(ER(ER_SYNTAX_ERROR));\
74
Work around for broken code generated by bison 1.875.
76
The code generated by bison 1.875a and later, bison 2.1 and bison 2.2 is ok.
77
With bison 1.875 however, the generated code contains:
80
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
81
__attribute__ ((__unused__))
84
This usage of __attribute__ is illegal, so we remove it.
85
See the following references for details:
86
http://lists.gnu.org/archive/html/bug-bison/2004-02/msg00014.html
87
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14273
90
#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__)
92
#define __attribute__(X)
103
@brief Push an error message into MySQL error stack with line
104
and position information.
106
This function provides semantic action implementers with a way
107
to push the famous "You have a syntax error near..." error
108
message into the error stack, which is normally produced only if
109
a parse error is discovered internally by the Bison generated
113
void my_parse_error(const char *s)
115
THD *thd= current_thd;
116
Lex_input_stream *lip= thd->m_lip;
118
const char *yytext= lip->get_tok_start();
119
/* Push an error into the error stack */
120
my_printf_error(ER_PARSE_ERROR, ER(ER_PARSE_ERROR), MYF(0), s,
121
(yytext ? yytext : ""),
126
@brief Bison callback to report a syntax/OOM error
128
This function is invoked by the bison-generated parser
129
when a syntax error, a parse error or an out-of-memory
130
condition occurs. This function is not invoked when the
131
parser is requested to abort by semantic action code
132
by means of YYABORT or YYACCEPT macros. This is why these
133
macros should not be used (use MYSQL_YYABORT/MYSQL_YYACCEPT
136
The parser will abort immediately after invoking this callback.
138
This function is not for use in semantic actions and is internal to
139
the parser, as it performs some pre-return cleanup.
140
In semantic actions, please use my_parse_error or my_error to
141
push an error into the error stack and MYSQL_YYABORT
142
to abort from the parser.
145
void MYSQLerror(const char *s)
147
THD *thd= current_thd;
150
Restore the original LEX if it was replaced when parsing
151
a stored procedure. We must ensure that a parsing error
152
does not leave any side effects in the THD.
154
LEX::cleanup_lex_after_parse_error(thd);
156
/* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
157
if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
158
s= ER(ER_SYNTAX_ERROR);
164
void turn_parser_debug_on()
167
MYSQLdebug is in sql/sql_yacc.cc, in bison generated code.
168
Turning this option on is **VERY** verbose, and should be
169
used when investigating a syntax error problem only.
171
The syntax to run with bison traces is as follows :
172
- Starting a server manually :
173
mysqld --debug="d,parser_debug" ...
175
mysql-test-run.pl --mysqld="--debug=d,parser_debug" ...
177
The result will be in the process stderr (var/log/master.err)
186
Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
187
See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
188
This function returns the proper item for the SQL expression
189
<code>left [NOT] IN ( expr )</code>
190
@param thd the current thread
191
@param left the in predicand
192
@param equal true for IN predicates, false for NOT IN predicates
193
@param expr first and only expression of the in value list
194
@return an expression representing the IN predicate.
196
Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal,
200
Relevant references for this issue:
201
- SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
202
- SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
203
- SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
204
- SQL:2003, Part 2, section 7.15 <subquery>, page 370,
205
- SQL:2003 Feature F561, "Full value expressions".
207
The exception in SQL:2003 Note 184 means:
208
Item_singlerow_subselect, which corresponds to a <scalar subquery>,
209
should be re-interpreted as an Item_in_subselect, which corresponds
210
to a <table subquery> when used inside an <in predicate>.
212
Our reading of Note 184 is reccursive, so that all:
213
- IN (( <subquery> ))
214
- IN ((( <subquery> )))
215
- IN '('^N <subquery> ')'^N
217
should be interpreted as a <table subquery>, no matter how deep in the
218
expression the <subquery> is.
223
DBUG_ENTER("handle_sql2003_note184_exception");
225
if (expr->type() == Item::SUBSELECT_ITEM)
227
Item_subselect *expr2 = (Item_subselect*) expr;
229
if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
231
Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
232
st_select_lex *subselect;
235
Implement the mandated change, by altering the semantic tree:
236
left IN Item_singlerow_subselect(subselect)
239
which is represented as
240
Item_in_subselect(left, subselect)
242
subselect= expr3->invalidate_and_restore_select_lex();
243
result= new (thd->mem_root) Item_in_subselect(left, subselect);
246
result = negate_expression(thd, result);
253
result= new (thd->mem_root) Item_func_eq(left, expr);
255
result= new (thd->mem_root) Item_func_ne(left, expr);
261
@brief Creates a new SELECT_LEX for a UNION branch.
263
Sets up and initializes a SELECT_LEX structure for a query once the parser
264
discovers a UNION token. The current SELECT_LEX is pushed on the stack and
265
the new SELECT_LEX becomes the current one..=
267
@lex The parser state.
269
@is_union_distinct True if the union preceding the new select statement
272
@return <code>false</code> if successful, <code>true</code> if an error was
273
reported. In the latter case parsing should stop.
275
bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
279
/* Only the last SELECT can have INTO...... */
280
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
283
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
285
my_parse_error(ER(ER_SYNTAX_ERROR));
288
/* This counter shouldn't be incremented for UNION parts */
290
if (mysql_new_select(lex, 0))
292
mysql_init_select(lex);
293
lex->current_select->linkage=UNION_TYPE;
294
if (is_union_distinct) /* UNION DISTINCT - remember position */
295
lex->current_select->master_unit()->union_distinct=
301
@brief Initializes a SELECT_LEX for a query within parentheses (aka
304
@return false if successful, true if an error was reported. In the latter
305
case parsing should stop.
307
bool setup_select_in_parentheses(LEX *lex)
309
SELECT_LEX * sel= lex->current_select;
310
if (sel->set_braces(1))
312
my_parse_error(ER(ER_SYNTAX_ERROR));
315
if (sel->linkage == UNION_TYPE &&
316
!sel->master_unit()->first_select()->braces &&
317
sel->master_unit()->first_select()->linkage ==
320
my_parse_error(ER(ER_SYNTAX_ERROR));
323
if (sel->linkage == UNION_TYPE &&
324
sel->olap != UNSPECIFIED_OLAP_TYPE &&
325
sel->master_unit()->fake_select_lex)
327
my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
330
/* select in braces, can't contain global parameters */
331
if (sel->master_unit()->fake_select_lex)
332
sel->master_unit()->global_parameters=
333
sel->master_unit()->fake_select_lex;
341
ulonglong ulonglong_number;
342
longlong longlong_number;
344
LEX_STRING *lex_str_ptr;
350
List<Item> *item_list;
351
List<String> *string_list;
353
Key_part_spec *key_part;
354
TABLE_LIST *table_list;
357
struct sys_var_with_base variable;
358
enum enum_var_type var_type;
359
Key::Keytype key_type;
360
enum ha_key_alg key_alg;
362
enum row_type row_type;
363
enum column_format_type column_format_type;
364
enum ha_rkey_function ha_rkey_mode;
365
enum enum_tx_isolation tx_isolation;
366
enum Cast_target cast_type;
367
enum ha_choice choice;
368
CHARSET_INFO *charset;
369
thr_lock_type lock_type;
370
struct st_table_lock_info table_lock_info;
371
interval_type interval, interval_time_st;
372
timestamp_type date_time_type;
373
st_select_lex *select_lex;
374
chooser_compare_func_creator boolfunc2creator;
375
struct sp_cond_type *spcondtype;
376
struct { int vars, conds, hndlrs, curs; } spblock;
378
struct p_elem_val *p_elem_value;
379
enum index_hint_type index_hint;
380
enum enum_filetype filetype;
381
enum ha_build_method build_method;
382
enum Foreign_key::fk_option m_fk_option;
386
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
389
%pure_parser /* We have threads */
391
Currently there are 100 shift/reduce conflicts.
392
We should not introduce new conflicts any more.
398
For each token, please include in the same line a comment that contains
400
SQL-2003-R : Reserved keyword as per SQL-2003
401
SQL-2003-N : Non Reserved keyword as per SQL-2003
402
SQL-1999-R : Reserved keyword as per SQL-1999
403
SQL-1999-N : Non Reserved keyword as per SQL-1999
404
MYSQL : MySQL extention (unspecified)
405
MYSQL-FUNC : MySQL extention, function
406
INTERNAL : Not a real token, lex optimization
407
OPERATOR : SQL operator
408
FUTURE-USE : Reserved for futur use
410
This makes the code grep-able, and helps maintenance.
413
%token ABORT_SYM /* INTERNAL (used in lex) */
414
%token ACCESSIBLE_SYM
415
%token ACTION /* SQL-2003-N */
416
%token ADD /* SQL-2003-R */
417
%token ADDDATE_SYM /* MYSQL-FUNC */
418
%token AFTER_SYM /* SQL-2003-N */
421
%token ALL /* SQL-2003-R */
422
%token ALTER /* SQL-2003-R */
424
%token AND_AND_SYM /* OPERATOR */
425
%token AND_SYM /* SQL-2003-R */
426
%token ANY_SYM /* SQL-2003-R */
427
%token AS /* SQL-2003-R */
428
%token ASC /* SQL-2003-N */
429
%token ASCII_SYM /* MYSQL-FUNC */
430
%token ASENSITIVE_SYM /* FUTURE-USE */
431
%token AT_SYM /* SQL-2003-R */
433
%token AUTOEXTEND_SIZE_SYM
435
%token AVG_ROW_LENGTH
436
%token AVG_SYM /* SQL-2003-N */
437
%token BEFORE_SYM /* SQL-2003-N */
438
%token BEGIN_SYM /* SQL-2003-R */
439
%token BETWEEN_SYM /* SQL-2003-R */
440
%token BIGINT /* SQL-2003-R */
441
%token BINARY /* SQL-2003-R */
444
%token BIT_AND /* MYSQL-FUNC */
445
%token BIT_OR /* MYSQL-FUNC */
446
%token BIT_SYM /* MYSQL-FUNC */
447
%token BIT_XOR /* MYSQL-FUNC */
448
%token BLOB_SYM /* SQL-2003-R */
450
%token BOOLEAN_SYM /* SQL-2003-R */
452
%token BOTH /* SQL-2003-R */
454
%token BY /* SQL-2003-R */
457
%token CALL_SYM /* SQL-2003-R */
458
%token CASCADE /* SQL-2003-N */
459
%token CASCADED /* SQL-2003-R */
460
%token CASE_SYM /* SQL-2003-R */
461
%token CAST_SYM /* SQL-2003-R */
462
%token CHAIN_SYM /* SQL-2003-N */
466
%token CHAR_SYM /* SQL-2003-R */
468
%token CHECK_SYM /* SQL-2003-R */
471
%token CLOSE_SYM /* SQL-2003-R */
472
%token COALESCE /* SQL-2003-N */
474
%token COLLATE_SYM /* SQL-2003-R */
475
%token COLLATION_SYM /* SQL-2003-N */
477
%token COLUMN_SYM /* SQL-2003-R */
479
%token COMMITTED_SYM /* SQL-2003-N */
480
%token COMMIT_SYM /* SQL-2003-R */
482
%token COMPLETION_SYM
483
%token COMPRESSED_SYM
485
%token CONDITION_SYM /* SQL-2003-N */
486
%token CONNECTION_SYM
487
%token CONSISTENT_SYM
488
%token CONSTRAINT /* SQL-2003-R */
489
%token CONTAINS_SYM /* SQL-2003-N */
491
%token CONTINUE_SYM /* SQL-2003-R */
492
%token CONTRIBUTORS_SYM
493
%token CONVERT_SYM /* SQL-2003-N */
494
%token COUNT_SYM /* SQL-2003-N */
496
%token CREATE /* SQL-2003-R */
497
%token CROSS /* SQL-2003-R */
498
%token CUBE_SYM /* SQL-2003-R */
499
%token CURDATE /* MYSQL-FUNC */
500
%token CURRENT_USER /* SQL-2003-R */
501
%token CURSOR_SYM /* SQL-2003-R */
502
%token CURTIME /* MYSQL-FUNC */
506
%token DATA_SYM /* SQL-2003-N */
508
%token DATE_ADD_INTERVAL /* MYSQL-FUNC */
509
%token DATE_SUB_INTERVAL /* MYSQL-FUNC */
510
%token DATE_SYM /* SQL-2003-R */
512
%token DAY_MICROSECOND_SYM
513
%token DAY_MINUTE_SYM
514
%token DAY_SECOND_SYM
515
%token DAY_SYM /* SQL-2003-R */
516
%token DEALLOCATE_SYM /* SQL-2003-R */
518
%token DECIMAL_SYM /* SQL-2003-R */
519
%token DECLARE_SYM /* SQL-2003-R */
520
%token DEFAULT /* SQL-2003-R */
523
%token DELAY_KEY_WRITE_SYM
524
%token DELETE_SYM /* SQL-2003-R */
525
%token DESC /* SQL-2003-N */
526
%token DESCRIBE /* SQL-2003-R */
528
%token DETERMINISTIC_SYM /* SQL-2003-R */
533
%token DISTINCT /* SQL-2003-R */
535
%token DOUBLE_SYM /* SQL-2003-R */
536
%token DROP /* SQL-2003-R */
539
%token DYNAMIC_SYM /* SQL-2003-R */
540
%token EACH_SYM /* SQL-2003-R */
541
%token ELSE /* SQL-2003-R */
545
%token END /* SQL-2003-R */
547
%token END_OF_INPUT /* INTERNAL */
551
%token EQ /* OPERATOR */
552
%token EQUAL_SYM /* OPERATOR */
555
%token ESCAPE_SYM /* SQL-2003-R */
557
%token EVERY_SYM /* SQL-2003-N */
559
%token EXISTS /* SQL-2003-R */
562
%token EXTENT_SIZE_SYM
563
%token EXTRACT_SYM /* SQL-2003-N */
564
%token FALSE_SYM /* SQL-2003-R */
567
%token FETCH_SYM /* SQL-2003-R */
568
%token COLUMN_FORMAT_SYM
570
%token FIRST_SYM /* SQL-2003-N */
573
%token FLOAT_SYM /* SQL-2003-R */
576
%token FOREIGN /* SQL-2003-R */
577
%token FOR_SYM /* SQL-2003-R */
578
%token FOUND_SYM /* SQL-2003-R */
579
%token FRAC_SECOND_SYM
581
%token FULL /* SQL-2003-R */
582
%token FUNCTION_SYM /* SQL-2003-R */
584
%token GET_FORMAT /* MYSQL-FUNC */
585
%token GLOBAL_SYM /* SQL-2003-R */
586
%token GROUP_SYM /* SQL-2003-R */
587
%token GROUP_CONCAT_SYM
588
%token GT_SYM /* OPERATOR */
591
%token HAVING /* SQL-2003-R */
596
%token HOUR_MICROSECOND_SYM
597
%token HOUR_MINUTE_SYM
598
%token HOUR_SECOND_SYM
599
%token HOUR_SYM /* SQL-2003-R */
601
%token IDENTIFIED_SYM
609
%token INITIAL_SIZE_SYM
610
%token INNER_SYM /* SQL-2003-R */
611
%token INOUT_SYM /* SQL-2003-R */
612
%token INSENSITIVE_SYM /* SQL-2003-R */
613
%token INSERT /* SQL-2003-R */
616
%token INTERVAL_SYM /* SQL-2003-R */
617
%token INTO /* SQL-2003-R */
618
%token INT_SYM /* SQL-2003-R */
619
%token IN_SYM /* SQL-2003-R */
622
%token IS /* SQL-2003-R */
623
%token ISOLATION /* SQL-2003-R */
626
%token JOIN_SYM /* SQL-2003-R */
628
%token KEY_BLOCK_SIZE
629
%token KEY_SYM /* SQL-2003-N */
631
%token LAST_SYM /* SQL-2003-N */
632
%token LE /* OPERATOR */
633
%token LEADING /* SQL-2003-R */
635
%token LEFT /* SQL-2003-R */
638
%token LIKE /* SQL-2003-R */
645
%token LOCAL_SYM /* SQL-2003-R */
646
%token LOCATOR_SYM /* SQL-2003-N */
657
%token LT /* OPERATOR */
658
%token MASTER_CONNECT_RETRY_SYM
659
%token MASTER_HOST_SYM
660
%token MASTER_LOG_FILE_SYM
661
%token MASTER_LOG_POS_SYM
662
%token MASTER_PASSWORD_SYM
663
%token MASTER_PORT_SYM
664
%token MASTER_SERVER_ID_SYM
666
%token MASTER_USER_SYM
667
%token MASTER_HEARTBEAT_PERIOD_SYM
668
%token MATCH /* SQL-2003-R */
669
%token MAX_CONNECTIONS_PER_HOUR
670
%token MAX_QUERIES_PER_HOUR
673
%token MAX_SYM /* SQL-2003-N */
674
%token MAX_UPDATES_PER_HOUR
675
%token MAX_USER_CONNECTIONS_SYM
676
%token MAX_VALUE_SYM /* SQL-2003-N */
682
%token MERGE_SYM /* SQL-2003-R */
683
%token MICROSECOND_SYM /* MYSQL-FUNC */
685
%token MINUTE_MICROSECOND_SYM
686
%token MINUTE_SECOND_SYM
687
%token MINUTE_SYM /* SQL-2003-R */
689
%token MIN_SYM /* SQL-2003-N */
691
%token MODIFIES_SYM /* SQL-2003-R */
693
%token MOD_SYM /* SQL-2003-N */
694
%token MONTH_SYM /* SQL-2003-R */
696
%token NAMES_SYM /* SQL-2003-N */
697
%token NAME_SYM /* SQL-2003-N */
698
%token NATIONAL_SYM /* SQL-2003-R */
699
%token NATURAL /* SQL-2003-R */
701
%token NCHAR_SYM /* SQL-2003-R */
702
%token NE /* OPERATOR */
704
%token NEW_SYM /* SQL-2003-R */
705
%token NEXT_SYM /* SQL-2003-N */
707
%token NONE_SYM /* SQL-2003-R */
708
%token NOT_SYM /* SQL-2003-R */
711
%token NO_SYM /* SQL-2003-R */
713
%token NO_WRITE_TO_BINLOG
714
%token NULL_SYM /* SQL-2003-R */
716
%token NUMERIC_SYM /* SQL-2003-R */
721
%token ON /* SQL-2003-R */
725
%token OPEN_SYM /* SQL-2003-R */
728
%token OPTION /* SQL-2003-N */
730
%token ORDER_SYM /* SQL-2003-R */
731
%token OR_SYM /* SQL-2003-R */
734
%token OUT_SYM /* SQL-2003-R */
737
%token PAGE_CHECKSUM_SYM
739
%token PARTIAL /* SQL-2003-N */
747
%token POSITION_SYM /* SQL-2003-N */
748
%token PRECISION /* SQL-2003-R */
750
%token PRIMARY_SYM /* SQL-2003-R */
752
%token PROCESSLIST_SYM
759
%token RANGE_SYM /* SQL-2003-R */
760
%token READS_SYM /* SQL-2003-R */
762
%token READ_SYM /* SQL-2003-N */
763
%token READ_WRITE_SYM
764
%token REAL /* SQL-2003-R */
768
%token REDO_BUFFER_SIZE_SYM
770
%token REFERENCES /* SQL-2003-R */
771
%token RELAY_LOG_FILE_SYM
772
%token RELAY_LOG_POS_SYM
774
%token RELEASE_SYM /* SQL-2003-R */
778
%token REORGANIZE_SYM
780
%token REPEATABLE_SYM /* SQL-2003-N */
781
%token REPEAT_SYM /* MYSQL-FUNC */
782
%token REPLACE /* MYSQL-FUNC */
789
%token RETURNS_SYM /* SQL-2003-R */
790
%token RETURN_SYM /* SQL-2003-R */
792
%token REVOKE /* SQL-2003-R */
793
%token RIGHT /* SQL-2003-R */
794
%token ROLLBACK_SYM /* SQL-2003-R */
795
%token ROLLUP_SYM /* SQL-2003-R */
796
%token ROUTINE_SYM /* SQL-2003-N */
797
%token ROWS_SYM /* SQL-2003-R */
798
%token ROW_FORMAT_SYM
799
%token ROW_SYM /* SQL-2003-R */
800
%token SAVEPOINT_SYM /* SQL-2003-R */
801
%token SECOND_MICROSECOND_SYM
802
%token SECOND_SYM /* SQL-2003-R */
803
%token SECURITY_SYM /* SQL-2003-N */
804
%token SELECT_SYM /* SQL-2003-R */
805
%token SENSITIVE_SYM /* FUTURE-USE */
807
%token SERIALIZABLE_SYM /* SQL-2003-N */
809
%token SESSION_SYM /* SQL-2003-N */
811
%token SERVER_OPTIONS
812
%token SET /* SQL-2003-R */
815
%token SHIFT_LEFT /* OPERATOR */
816
%token SHIFT_RIGHT /* OPERATOR */
820
%token SIMPLE_SYM /* SQL-2003-N */
822
%token SMALLINT /* SQL-2003-R */
827
%token SPECIFIC_SYM /* SQL-2003-R */
828
%token SQLEXCEPTION_SYM /* SQL-2003-R */
829
%token SQLSTATE_SYM /* SQL-2003-R */
830
%token SQLWARNING_SYM /* SQL-2003-R */
831
%token SQL_BIG_RESULT
832
%token SQL_BUFFER_RESULT
833
%token SQL_CALC_FOUND_ROWS
834
%token SQL_SMALL_RESULT
835
%token SQL_SYM /* SQL-2003-R */
839
%token START_SYM /* SQL-2003-R */
841
%token STDDEV_SAMP_SYM /* SQL-2003-N */
849
%token SUBSTRING /* SQL-2003-N */
850
%token SUM_SYM /* SQL-2003-N */
858
%token TABLE_REF_PRIORITY
859
%token TABLE_SYM /* SQL-2003-R */
860
%token TABLE_CHECKSUM_SYM
861
%token TEMPORARY /* SQL-2003-N */
867
%token THEN_SYM /* SQL-2003-R */
868
%token TIMESTAMP /* SQL-2003-R */
870
%token TIMESTAMP_DIFF
871
%token TIME_SYM /* SQL-2003-R */
875
%token TO_SYM /* SQL-2003-R */
876
%token TRAILING /* SQL-2003-R */
877
%token TRANSACTION_SYM
878
%token TRANSACTIONAL_SYM
879
%token TRIM /* SQL-2003-N */
880
%token TRUE_SYM /* SQL-2003-R */
883
%token TYPE_SYM /* SQL-2003-N */
884
%token UDF_RETURNS_SYM
886
%token UNCOMMITTED_SYM /* SQL-2003-N */
888
%token UNDERSCORE_CHARSET
890
%token UNDO_BUFFER_SIZE_SYM
891
%token UNDO_SYM /* FUTURE-USE */
894
%token UNION_SYM /* SQL-2003-R */
896
%token UNKNOWN_SYM /* SQL-2003-R */
900
%token UPDATE_SYM /* SQL-2003-R */
902
%token USAGE /* SQL-2003-N */
903
%token USER /* SQL-2003-R */
906
%token USING /* SQL-2003-R */
908
%token UTC_TIMESTAMP_SYM
910
%token VALUES /* SQL-2003-R */
911
%token VALUE_SYM /* SQL-2003-R */
913
%token VARCHAR /* SQL-2003-R */
916
%token VARYING /* SQL-2003-R */
921
%token WEIGHT_STRING_SYM
922
%token WHEN_SYM /* SQL-2003-R */
923
%token WHERE /* SQL-2003-R */
924
%token WITH /* SQL-2003-R */
925
%token WITH_CUBE_SYM /* INTERNAL */
926
%token WITH_ROLLUP_SYM /* INTERNAL */
927
%token WORK_SYM /* SQL-2003-N */
929
%token WRITE_SYM /* SQL-2003-N */
932
%token YEAR_MONTH_SYM
933
%token YEAR_SYM /* SQL-2003-R */
936
%left JOIN_SYM INNER_SYM STRAIGHT_JOIN CROSS LEFT RIGHT
937
/* A dummy token to force the priority of table_ref production in a join. */
938
%left TABLE_REF_PRIORITY
942
%left AND_SYM AND_AND_SYM
943
%left BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
944
%left EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE IN_SYM
947
%left SHIFT_LEFT SHIFT_RIGHT
949
%left '*' '/' '%' DIV_SYM MOD_SYM
953
%right BINARY COLLATE_SYM
957
IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
958
LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
959
IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
960
NCHAR_STRING opt_component key_cache_name
961
BIN_NUM TEXT_STRING_filesystem ident_or_empty
962
opt_constraint constraint opt_ident
968
table_ident references
970
%type <simple_string>
971
remember_name remember_end opt_db
974
text_string opt_gconcat_separator
977
type int_type real_type order_dir
978
if_exists opt_local opt_table_options table_options
979
table_option opt_if_not_exists opt_no_write_to_binlog
980
opt_temporary all_or_any opt_distinct
981
opt_ignore_leaves union_option
982
start_transaction_opts opt_chain opt_release
983
union_opt select_derived_init option_type2
984
opt_transactional_lock_timeout
985
/* opt_lock_timeout_value */
991
ulong_num real_ulong_num
993
ws_level_flag_desc ws_level_flag_reverse ws_level_flags
994
opt_ws_levels ws_level_list ws_level_list_item ws_level_number
995
ws_level_range ws_level_list_or_range
997
%type <ulonglong_number>
1000
%type <choice> choice
1003
replace_lock_option opt_low_priority insert_lock_option load_data_lock
1004
transactional_lock_mode
1006
%type <table_lock_info>
1010
literal text_literal insert_ident order_ident
1011
simple_ident expr opt_expr opt_else sum_expr in_sum_expr
1012
variable variable_aux bool_pri
1014
table_wild simple_expr udf_expr
1015
expr_or_default set_expr_or_default
1017
signed_literal now_or_signed_literal opt_escape
1018
simple_ident_nospvar simple_ident_q
1019
field_or_var limit_option
1020
function_call_keyword
1021
function_call_nonkeyword
1022
function_call_generic
1023
function_call_conflict
1029
expr_list opt_udf_expr_list udf_expr_list when_list
1032
option_type opt_var_type opt_var_ident_type
1035
key_type opt_unique constraint_key_type
1047
join_table_list join_table
1048
table_factor table_ref esc_table_ref
1049
select_derived derived_table_list
1050
select_derived_union
1052
%type <date_time_type> date_time_type;
1053
%type <interval> interval
1055
%type <interval_time_st> interval_time_st
1057
%type <interval_time_st> interval_time_stamp
1059
%type <db_type> storage_engines known_storage_engines
1061
%type <row_type> row_types
1063
%type <column_format_type> column_format_types
1065
%type <tx_isolation> isolation_types
1067
%type <cast_type> cast_type
1069
%type <symbol> keyword keyword_sp
1074
charset_name_or_default
1075
old_or_new_charset_name
1076
old_or_new_charset_name_or_default
1078
collation_name_or_default
1079
opt_load_data_charset
1082
%type <variable> internal_variable_name
1084
%type <select_lex> subselect
1085
get_select_lex query_specification
1086
query_expression_body
1088
%type <boolfunc2creator> comp_op
1090
%type <build_method> build_method
1093
query verb_clause create change select drop insert replace insert2
1094
insert_values update delete truncate rename
1095
show describe load alter optimize keycache preload flush
1096
reset purge begin commit rollback savepoint release
1097
slave master_def master_defs master_file_def slave_until_opts
1098
repair analyze check start checksum
1099
field_list field_list_item field_spec kill column_def key_def
1100
keycache_list assign_to_keycache preload_list preload_keys
1101
select_item_list select_item values_list no_braces
1102
opt_limit_clause delete_limit_clause fields opt_values values
1103
opt_precision opt_ignore opt_column opt_restrict
1104
set lock unlock string_list field_options field_option
1105
field_opt_list opt_binary table_lock_list table_lock
1106
ref_list opt_match_clause opt_on_update_delete use
1107
opt_delete_options opt_delete_option varchar nchar nvarchar
1108
opt_outer table_list table_name table_alias_ref_list table_alias_ref
1109
opt_option opt_place
1110
opt_attribute opt_attribute_list attribute
1111
flush_options flush_option
1112
equal optional_braces
1113
opt_mi_check_type opt_to mi_check_types normal_join
1114
table_to_table_list table_to_table opt_table_list opt_as
1115
single_multi table_wild_list table_wild_one opt_wild
1116
union_clause union_list
1117
precision subselect_start charset
1118
subselect_end select_var_list select_var_list_init opt_len
1119
opt_extended_describe
1121
opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
1123
init_key_options key_options key_opts key_opt key_using_alg
1126
%type <index_hint> index_hint_type
1127
%type <num> index_hint_clause
1128
%type <filetype> data_or_xml
1131
'-' '+' '*' '/' '%' '(' ')'
1132
',' '!' '{' '}' '&' '|' AND_SYM OR_SYM BETWEEN_SYM CASE_SYM
1133
THEN_SYM WHEN_SYM DIV_SYM MOD_SYM AND_AND_SYM DELETE_SYM
1137
Indentation of grammar rules:
1139
rule: <-- starts at col 1
1140
rule1a rule1b rule1c <-- starts at col 11
1141
{ <-- starts at col 11
1142
code <-- starts at col 13, indentation is 2 spaces
1148
; <-- on a line by itself, starts at col 9
1150
Also, please do not use any <TAB>, but spaces.
1151
Having a uniform indentation in this file helps
1152
code reviews, patches, merges, and make maintenance easier.
1153
Tip: grep [[:cntrl:]] sql_yacc.yy
1161
if (!thd->bootstrap &&
1162
(!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
1164
my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
1169
thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
1172
| verb_clause END_OF_INPUT {}
1180
/* Verb clauses, except begin */
1184
| binlog_base64_event
1224
CHANGE MASTER_SYM TO_SYM
1227
lex->sql_command = SQLCOM_CHANGE_MASTER;
1228
bzero((char*) &lex->mi, sizeof(lex->mi));
1236
| master_defs ',' master_def
1240
MASTER_HOST_SYM EQ TEXT_STRING_sys
1242
Lex->mi.host = $3.str;
1244
| MASTER_USER_SYM EQ TEXT_STRING_sys
1246
Lex->mi.user = $3.str;
1248
| MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
1250
Lex->mi.password = $3.str;
1252
| MASTER_PORT_SYM EQ ulong_num
1256
| MASTER_CONNECT_RETRY_SYM EQ ulong_num
1258
Lex->mi.connect_retry = $3;
1260
| MASTER_HEARTBEAT_PERIOD_SYM EQ NUM_literal
1262
Lex->mi.heartbeat_period= (float) $3->val_real();
1263
if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD ||
1264
Lex->mi.heartbeat_period < 0.0)
1266
char buf[sizeof(SLAVE_MAX_HEARTBEAT_PERIOD*4)];
1267
my_sprintf(buf, (buf, "%d seconds", SLAVE_MAX_HEARTBEAT_PERIOD));
1268
my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1270
" is negative or exceeds the maximum ",
1274
if (Lex->mi.heartbeat_period > slave_net_timeout)
1276
push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
1277
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1278
ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1279
" exceeds the value of `slave_net_timeout' sec.",
1280
" A sensible value for the period should be"
1281
" less than the timeout.");
1283
if (Lex->mi.heartbeat_period < 0.001)
1285
if (Lex->mi.heartbeat_period != 0.0)
1287
push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
1288
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1289
ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
1290
" is less than 1 msec.",
1291
" The period is reset to zero which means"
1292
" no heartbeats will be sending");
1293
Lex->mi.heartbeat_period= 0.0;
1295
Lex->mi.heartbeat_opt= LEX_MASTER_INFO::LEX_MI_DISABLE;
1297
Lex->mi.heartbeat_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
1304
MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
1306
Lex->mi.log_file_name = $3.str;
1308
| MASTER_LOG_POS_SYM EQ ulonglong_num
1312
If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
1313
instead of causing subsequent errors.
1314
We need to do it in this file, because only there we know that
1315
MASTER_LOG_POS has been explicitely specified. On the contrary
1316
in change_master() (sql_repl.cc) we cannot distinguish between 0
1317
(MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
1318
whereas we want to distinguish (specified 0 means "read the binlog
1319
from 0" (4 in fact), unspecified means "don't change the position
1320
(keep the preceding value)").
1322
Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
1324
| RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
1326
Lex->mi.relay_log_name = $3.str;
1328
| RELAY_LOG_POS_SYM EQ ulong_num
1330
Lex->mi.relay_log_pos = $3;
1331
/* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
1332
Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
1336
/* create a table */
1339
CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1343
lex->sql_command= SQLCOM_CREATE_TABLE;
1344
if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
1348
lex->alter_info.reset();
1349
lex->col_list.empty();
1351
bzero((char*) &lex->create_info,sizeof(lex->create_info));
1352
lex->create_info.options=$2 | $4;
1353
lex->create_info.db_type= ha_default_handlerton(thd);
1354
lex->create_info.default_table_charset= NULL;
1356
lex->name.length= 0;
1360
LEX *lex= YYTHD->lex;
1361
lex->current_select= &lex->select_lex;
1362
if (!lex->create_info.db_type)
1364
lex->create_info.db_type= ha_default_handlerton(YYTHD);
1365
push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
1366
ER_WARN_USING_OTHER_HANDLER,
1367
ER(ER_WARN_USING_OTHER_HANDLER),
1368
ha_resolve_storage_engine_name(lex->create_info.db_type),
1372
| CREATE build_method opt_unique INDEX_SYM ident key_alg
1376
lex->sql_command= SQLCOM_CREATE_INDEX;
1377
if (!lex->current_select->add_table_to_list(lex->thd, $8,
1379
TL_OPTION_UPDATING))
1381
lex->alter_info.reset();
1382
lex->alter_info.flags= ALTER_ADD_INDEX;
1383
lex->alter_info.build_method= $2;
1384
lex->col_list.empty();
1387
'(' key_list ')' key_options
1391
key= new Key($3, $5, &lex->key_create_info, 0,
1393
lex->alter_info.key_list.push_back(key);
1394
lex->col_list.empty();
1396
| CREATE DATABASE opt_if_not_exists ident
1398
Lex->create_info.default_table_charset= NULL;
1399
Lex->create_info.used_fields= 0;
1401
opt_create_database_options
1404
lex->sql_command=SQLCOM_CREATE_DB;
1406
lex->create_info.options=$3;
1417
| opt_create_table_options
1424
lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1425
if (!lex->select_lex.add_table_to_list(thd, $2, NULL, 0, TL_READ))
1428
| '(' LIKE table_ident ')'
1433
lex->create_info.options|= HA_LEX_CREATE_TABLE_LIKE;
1434
if (!lex->select_lex.add_table_to_list(thd, $3, NULL, 0, TL_READ))
1440
field_list ')' opt_create_table_options
1443
{ Select->set_braces(1);}
1449
| opt_duplicate opt_as create_select
1450
{ Select->set_braces(0);}
1452
| opt_duplicate opt_as '(' create_select ')'
1453
{ Select->set_braces(1);}
1461
lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
1462
if (lex->sql_command == SQLCOM_INSERT)
1463
lex->sql_command= SQLCOM_INSERT_SELECT;
1464
else if (lex->sql_command == SQLCOM_REPLACE)
1465
lex->sql_command= SQLCOM_REPLACE_SELECT;
1467
The following work only with the local list, the global list
1468
is created correctly in this case
1470
lex->current_select->table_list.save_and_clear(&lex->save_list);
1471
mysql_init_select(lex);
1472
lex->current_select->parsing_place= SELECT_LIST;
1474
select_options select_item_list
1476
Select->parsing_place= NO_MATTER;
1481
The following work only with the local list, the global list
1482
is created correctly in this case
1484
Lex->current_select->table_list.push_front(&Lex->save_list);
1493
opt_create_database_options:
1495
| create_database_options {}
1498
create_database_options:
1499
create_database_option {}
1500
| create_database_options create_database_option {}
1503
create_database_option:
1504
default_collation {}
1505
| default_charset {}
1509
/* empty */ { $$= 0; }
1510
| table_options { $$= $1;}
1514
table_option { $$=$1; }
1515
| table_option table_options { $$= $1 | $2; }
1519
TEMPORARY { $$=HA_LEX_CREATE_TMP_TABLE; }
1523
/* empty */ { $$= 0; }
1524
| IF not EXISTS { $$=HA_LEX_CREATE_IF_NOT_EXISTS; }
1527
opt_create_table_options:
1529
| create_table_options
1532
create_table_options_space_separated:
1534
| create_table_option create_table_options_space_separated
1537
create_table_options:
1539
| create_table_option create_table_options
1540
| create_table_option ',' create_table_options
1543
create_table_option:
1544
ENGINE_SYM opt_equal storage_engines
1546
Lex->create_info.db_type= $3;
1547
Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
1549
| MAX_ROWS opt_equal ulonglong_num
1551
Lex->create_info.max_rows= $3;
1552
Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;
1554
| MIN_ROWS opt_equal ulonglong_num
1556
Lex->create_info.min_rows= $3;
1557
Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;
1559
| AVG_ROW_LENGTH opt_equal ulong_num
1561
Lex->create_info.avg_row_length=$3;
1562
Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;
1564
| PASSWORD opt_equal TEXT_STRING_sys
1566
Lex->create_info.password=$3.str;
1567
Lex->create_info.used_fields|= HA_CREATE_USED_PASSWORD;
1569
| COMMENT_SYM opt_equal TEXT_STRING_sys
1571
Lex->create_info.comment=$3;
1572
Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT;
1574
| AUTO_INC opt_equal ulonglong_num
1576
Lex->create_info.auto_increment_value=$3;
1577
Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;
1579
| PACK_KEYS_SYM opt_equal ulong_num
1583
Lex->create_info.table_options|= HA_OPTION_NO_PACK_KEYS;
1586
Lex->create_info.table_options|= HA_OPTION_PACK_KEYS;
1589
my_parse_error(ER(ER_SYNTAX_ERROR));
1592
Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
1594
| PACK_KEYS_SYM opt_equal DEFAULT
1596
Lex->create_info.table_options&=
1597
~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
1598
Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;
1600
| CHECKSUM_SYM opt_equal ulong_num
1602
Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
1603
Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
1605
| TABLE_CHECKSUM_SYM opt_equal ulong_num
1607
Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
1608
Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
1610
| PAGE_CHECKSUM_SYM opt_equal choice
1612
Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
1613
Lex->create_info.page_checksum= $3;
1615
| DELAY_KEY_WRITE_SYM opt_equal ulong_num
1617
Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
1618
Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE;
1620
| ROW_FORMAT_SYM opt_equal row_types
1622
Lex->create_info.row_type= $3;
1623
Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1624
Lex->alter_info.flags|= ALTER_ROW_FORMAT;
1626
| UNION_SYM opt_equal '(' opt_table_list ')'
1628
/* Move the union list to the merge_list */
1630
TABLE_LIST *table_list= lex->select_lex.get_table_list();
1631
lex->create_info.merge_list= lex->select_lex.table_list;
1632
lex->create_info.merge_list.elements--;
1633
lex->create_info.merge_list.first=
1634
(uchar*) (table_list->next_local);
1635
lex->select_lex.table_list.elements=1;
1636
lex->select_lex.table_list.next=
1637
(uchar**) &(table_list->next_local);
1638
table_list->next_local= 0;
1639
lex->create_info.used_fields|= HA_CREATE_USED_UNION;
1643
| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1645
Lex->create_info.data_file_name= $4.str;
1646
Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR;
1648
| INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
1650
Lex->create_info.index_file_name= $4.str;
1651
Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR;
1653
| CONNECTION_SYM opt_equal TEXT_STRING_sys
1655
Lex->create_info.connect_string.str= $3.str;
1656
Lex->create_info.connect_string.length= $3.length;
1657
Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION;
1659
| KEY_BLOCK_SIZE opt_equal ulong_num
1661
Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1662
Lex->create_info.key_block_size= $3;
1664
| TRANSACTIONAL_SYM opt_equal choice
1666
Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
1667
Lex->create_info.transactional= $3;
1672
opt_default charset opt_equal charset_name_or_default
1674
HA_CREATE_INFO *cinfo= &Lex->create_info;
1675
if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1676
cinfo->default_table_charset && $4 &&
1677
!my_charset_same(cinfo->default_table_charset,$4))
1679
my_error(ER_CONFLICTING_DECLARATIONS, MYF(0),
1680
"CHARACTER SET ", cinfo->default_table_charset->csname,
1681
"CHARACTER SET ", $4->csname);
1684
Lex->create_info.default_table_charset= $4;
1685
Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1690
opt_default COLLATE_SYM opt_equal collation_name_or_default
1692
HA_CREATE_INFO *cinfo= &Lex->create_info;
1693
if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
1694
cinfo->default_table_charset && $4 &&
1695
!my_charset_same(cinfo->default_table_charset,$4))
1697
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
1698
$4->name, cinfo->default_table_charset->csname);
1701
Lex->create_info.default_table_charset= $4;
1702
Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
1709
plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
1712
$$= plugin_data(plugin, handlerton*);
1715
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1721
known_storage_engines:
1725
if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
1726
$$= plugin_data(plugin, handlerton*);
1729
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
1735
column_format_types:
1736
DEFAULT { $$= COLUMN_FORMAT_TYPE_DEFAULT; }
1737
| FIXED_SYM { $$= COLUMN_FORMAT_TYPE_FIXED; }
1738
| DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
1741
DEFAULT { $$= ROW_TYPE_DEFAULT; }
1742
| FIXED_SYM { $$= ROW_TYPE_FIXED; }
1743
| DYNAMIC_SYM { $$= ROW_TYPE_DYNAMIC; }
1744
| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
1745
| REDUNDANT_SYM { $$= ROW_TYPE_REDUNDANT; }
1746
| COMPACT_SYM { $$= ROW_TYPE_COMPACT; }
1747
| PAGE_SYM { $$= ROW_TYPE_PAGE; }
1752
| select_from select_lock_type
1757
| field_list ',' field_list_item
1766
field_spec opt_check_constraint
1767
| field_spec references
1769
Lex->col_list.empty(); /* Alloced by sql_alloc */
1774
key_type opt_ident key_alg '(' key_list ')' key_options
1777
Key *key= new Key($1, $2, &lex->key_create_info, 0,
1779
lex->alter_info.key_list.push_back(key);
1780
lex->col_list.empty(); /* Alloced by sql_alloc */
1782
| opt_constraint constraint_key_type opt_ident key_alg
1783
'(' key_list ')' key_options
1786
Key *key= new Key($2, $3.str ? $3 : $1, &lex->key_create_info, 0,
1788
lex->alter_info.key_list.push_back(key);
1789
lex->col_list.empty(); /* Alloced by sql_alloc */
1791
| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1794
Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1799
lex->fk_match_option);
1800
lex->alter_info.key_list.push_back(key);
1801
key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1802
&default_key_create_info, 1,
1804
lex->alter_info.key_list.push_back(key);
1805
lex->col_list.empty(); /* Alloced by sql_alloc */
1806
/* Only used for ALTER TABLE. Ignored otherwise. */
1807
lex->alter_info.flags|= ALTER_FOREIGN_KEY;
1809
| constraint opt_check_constraint
1811
Lex->col_list.empty(); /* Alloced by sql_alloc */
1813
| opt_constraint check_constraint
1815
Lex->col_list.empty(); /* Alloced by sql_alloc */
1819
opt_check_constraint:
1829
/* empty */ { $$= null_lex_str; }
1830
| constraint { $$= $1; }
1834
CONSTRAINT opt_ident { $$=$2; }
1841
lex->length=lex->dec=0;
1843
lex->default_value= lex->on_update_value= 0;
1844
lex->comment=null_lex_str;
1846
lex->storage_type= HA_SM_DEFAULT;
1847
lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1852
if (add_field_to_list(lex->thd, &$1, (enum enum_field_types) $3,
1853
lex->length,lex->dec,lex->type,
1854
lex->storage_type, lex->column_format,
1855
lex->default_value, lex->on_update_value,
1857
lex->change,&lex->interval_list,lex->charset))
1863
int_type opt_len field_options { $$=$1; }
1864
| real_type opt_precision field_options { $$=$1; }
1865
| FLOAT_SYM float_options field_options { $$=MYSQL_TYPE_FLOAT; }
1868
Lex->length= (char*) "1";
1871
| BIT_SYM '(' NUM ')'
1873
Lex->length= $3.str;
1878
Lex->length=(char*) "1";
1883
Lex->length=(char*) "1";
1886
| char '(' NUM ')' opt_binary
1889
$$=MYSQL_TYPE_STRING;
1893
Lex->length=(char*) "1";
1894
$$=MYSQL_TYPE_STRING;
1896
| nchar '(' NUM ')' opt_bin_mod
1899
$$=MYSQL_TYPE_STRING;
1900
Lex->charset=national_charset_info;
1904
Lex->length=(char*) "1";
1905
$$=MYSQL_TYPE_STRING;
1906
Lex->charset=national_charset_info;
1908
| BINARY '(' NUM ')'
1911
Lex->charset=&my_charset_bin;
1912
$$=MYSQL_TYPE_STRING;
1916
Lex->length= (char*) "1";
1917
Lex->charset=&my_charset_bin;
1918
$$=MYSQL_TYPE_STRING;
1920
| varchar '(' NUM ')' opt_binary
1923
$$= MYSQL_TYPE_VARCHAR;
1925
| nvarchar '(' NUM ')' opt_bin_mod
1928
$$= MYSQL_TYPE_VARCHAR;
1929
Lex->charset=national_charset_info;
1931
| VARBINARY '(' NUM ')'
1934
Lex->charset=&my_charset_bin;
1935
$$= MYSQL_TYPE_VARCHAR;
1937
| YEAR_SYM opt_len field_options
1938
{ $$=MYSQL_TYPE_YEAR; }
1940
{ $$=MYSQL_TYPE_DATE; }
1942
{ $$=MYSQL_TYPE_TIME; }
1945
/* Unlike other types TIMESTAMP fields are NOT NULL by default */
1946
Lex->type|= NOT_NULL_FLAG;
1947
$$=MYSQL_TYPE_TIMESTAMP;
1950
{ $$=MYSQL_TYPE_DATETIME; }
1953
Lex->charset=&my_charset_bin;
1954
$$=MYSQL_TYPE_TINY_BLOB;
1958
Lex->charset=&my_charset_bin;
1963
Lex->charset=&my_charset_bin;
1964
$$=MYSQL_TYPE_MEDIUM_BLOB;
1968
Lex->charset=&my_charset_bin;
1969
$$=MYSQL_TYPE_LONG_BLOB;
1971
| LONG_SYM VARBINARY
1973
Lex->charset=&my_charset_bin;
1974
$$=MYSQL_TYPE_MEDIUM_BLOB;
1976
| LONG_SYM varchar opt_binary
1977
{ $$=MYSQL_TYPE_MEDIUM_BLOB; }
1978
| TINYTEXT opt_binary
1979
{ $$=MYSQL_TYPE_TINY_BLOB; }
1980
| TEXT_SYM opt_len opt_binary
1981
{ $$=MYSQL_TYPE_BLOB; }
1982
| MEDIUMTEXT opt_binary
1983
{ $$=MYSQL_TYPE_MEDIUM_BLOB; }
1984
| LONGTEXT opt_binary
1985
{ $$=MYSQL_TYPE_LONG_BLOB; }
1986
| DECIMAL_SYM float_options field_options
1987
{ $$=MYSQL_TYPE_NEWDECIMAL;}
1988
| NUMERIC_SYM float_options field_options
1989
{ $$=MYSQL_TYPE_NEWDECIMAL;}
1990
| FIXED_SYM float_options field_options
1991
{ $$=MYSQL_TYPE_NEWDECIMAL;}
1993
{Lex->interval_list.empty();}
1994
'(' string_list ')' opt_binary
1995
{ $$=MYSQL_TYPE_ENUM; }
1997
{ Lex->interval_list.empty();}
1998
'(' string_list ')' opt_binary
1999
{ $$=MYSQL_TYPE_SET; }
2000
| LONG_SYM opt_binary
2001
{ $$=MYSQL_TYPE_MEDIUM_BLOB; }
2004
$$=MYSQL_TYPE_LONGLONG;
2005
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
2016
| NATIONAL_SYM CHAR_SYM {}
2025
NATIONAL_SYM VARCHAR {}
2027
| NCHAR_SYM VARCHAR {}
2028
| NATIONAL_SYM CHAR_SYM VARYING {}
2029
| NCHAR_SYM VARYING {}
2033
INT_SYM { $$=MYSQL_TYPE_LONG; }
2034
| TINYINT { $$=MYSQL_TYPE_TINY; }
2035
| SMALLINT { $$=MYSQL_TYPE_SHORT; }
2036
| MEDIUMINT { $$=MYSQL_TYPE_INT24; }
2037
| BIGINT { $$=MYSQL_TYPE_LONGLONG; }
2043
$$= MYSQL_TYPE_DOUBLE;
2046
{ $$=MYSQL_TYPE_DOUBLE; }
2047
| DOUBLE_SYM PRECISION
2048
{ $$=MYSQL_TYPE_DOUBLE; }
2053
{ Lex->dec=Lex->length= (char*)0; }
2055
{ Lex->length=$2.str; Lex->dec= (char*)0; }
2075
field_opt_list field_option {}
2081
| UNSIGNED { Lex->type|= UNSIGNED_FLAG;}
2082
| ZEROFILL { Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; }
2086
/* empty */ { Lex->length=(char*) 0; /* use default length */ }
2087
| '(' NUM ')' { Lex->length= $2.str; }
2097
| opt_attribute_list {}
2101
opt_attribute_list attribute {}
2106
NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
2107
| STORAGE_SYM DEFAULT
2109
Lex->storage_type= HA_SM_DEFAULT;
2110
Lex->alter_info.flags|= ALTER_COLUMN_STORAGE;
2112
| STORAGE_SYM DISK_SYM
2114
Lex->storage_type= HA_SM_DISK;
2115
Lex->alter_info.flags|= ALTER_COLUMN_STORAGE;
2117
| STORAGE_SYM MEMORY_SYM
2119
Lex->storage_type= HA_SM_MEMORY;
2120
Lex->alter_info.flags|= ALTER_COLUMN_STORAGE;
2122
| COLUMN_FORMAT_SYM column_format_types
2124
Lex->column_format= $2;
2125
Lex->alter_info.flags|= ALTER_COLUMN_FORMAT;
2127
| not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
2128
| DEFAULT now_or_signed_literal
2130
Lex->default_value=$2;
2131
Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
2133
| ON UPDATE_SYM NOW_SYM optional_braces
2134
{ Lex->on_update_value= new Item_func_now_local(); }
2135
| AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
2136
| SERIAL_SYM DEFAULT VALUE_SYM
2139
lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
2140
lex->alter_info.flags|= ALTER_ADD_INDEX;
2142
| opt_primary KEY_SYM
2145
lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
2146
lex->alter_info.flags|= ALTER_ADD_INDEX;
2151
lex->type|= UNIQUE_FLAG;
2152
lex->alter_info.flags|= ALTER_ADD_INDEX;
2154
| UNIQUE_SYM KEY_SYM
2157
lex->type|= UNIQUE_KEY_FLAG;
2158
lex->alter_info.flags|= ALTER_ADD_INDEX;
2160
| COMMENT_SYM TEXT_STRING_sys { Lex->comment= $2; }
2161
| COLLATE_SYM collation_name
2163
if (Lex->charset && !my_charset_same(Lex->charset,$2))
2165
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
2166
$2->name,Lex->charset->csname);
2176
now_or_signed_literal:
2177
NOW_SYM optional_braces
2178
{ $$= new Item_func_now_local(); }
2191
if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
2193
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
2197
| BINARY { $$= &my_charset_bin; }
2200
charset_name_or_default:
2201
charset_name { $$=$1; }
2202
| DEFAULT { $$=NULL; }
2205
opt_load_data_charset:
2206
/* Empty */ { $$= NULL; }
2207
| charset charset_name_or_default { $$= $2; }
2210
old_or_new_charset_name:
2213
if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
2214
!($$=get_old_charset_by_name($1.str)))
2216
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str);
2220
| BINARY { $$= &my_charset_bin; }
2223
old_or_new_charset_name_or_default:
2224
old_or_new_charset_name { $$=$1; }
2225
| DEFAULT { $$=NULL; }
2231
if (!($$=get_charset_by_name($1.str,MYF(0))))
2233
my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str);
2240
/* empty */ { $$=NULL; }
2241
| COLLATE_SYM collation_name_or_default { $$=$2; }
2244
collation_name_or_default:
2245
collation_name { $$=$1; }
2246
| DEFAULT { $$=NULL; }
2255
/* empty */ { Lex->charset=NULL; }
2256
| ASCII_SYM opt_bin_mod { Lex->charset=&my_charset_latin1; }
2257
| BYTE_SYM { Lex->charset=&my_charset_bin; }
2258
| UNICODE_SYM opt_bin_mod
2260
if (!(Lex->charset=get_charset_by_csname("ucs2",
2261
MY_CS_PRIMARY,MYF(0))))
2263
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
2267
| charset charset_name opt_bin_mod { Lex->charset=$2; }
2268
| BINARY opt_bin_charset { Lex->type|= BINCMP_FLAG; }
2273
| BINARY { Lex->type|= BINCMP_FLAG; }
2277
/* empty */ { Lex->charset= NULL; }
2278
| ASCII_SYM { Lex->charset=&my_charset_latin1; }
2281
if (!(Lex->charset=get_charset_by_csname("ucs2",
2282
MY_CS_PRIMARY,MYF(0))))
2284
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2");
2288
| charset charset_name { Lex->charset=$2; }
2296
my_parse_error(ER(ER_SYNTAX_ERROR));
2306
| DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
2309
ws_level_flag_reverse:
2310
REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
2313
/* empty */ { $$= 0; }
2314
| ws_level_flag_desc { $$= $1; }
2315
| ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
2316
| ws_level_flag_reverse { $$= $1 ; }
2322
$$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
2328
ws_level_number ws_level_flags
2335
ws_level_list_item { $$= $1; }
2336
| ws_level_list ',' ws_level_list_item { $$|= $3; }
2340
ws_level_number '-' ws_level_number
2344
for ($$= 0; start <= end; start++)
2349
ws_level_list_or_range:
2350
ws_level_list { $$= $1; }
2351
| ws_level_range { $$= $1; }
2355
/* empty*/ { $$= 0; }
2356
| LEVEL_SYM ws_level_list_or_range { $$= $2; }
2369
opt_on_update_delete
2377
{ Lex->ref_list.empty(); }
2383
{ Lex->ref_list.push_back(new Key_part_spec($3, 0)); }
2387
lex->ref_list.empty();
2388
lex->ref_list.push_back(new Key_part_spec($1, 0));
2394
{ Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
2396
{ Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
2398
{ Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
2400
{ Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
2403
opt_on_update_delete:
2407
lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
2408
lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
2410
| ON UPDATE_SYM delete_option
2413
lex->fk_update_opt= $3;
2414
lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
2416
| ON DELETE_SYM delete_option
2419
lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
2420
lex->fk_delete_opt= $3;
2422
| ON UPDATE_SYM delete_option
2423
ON DELETE_SYM delete_option
2426
lex->fk_update_opt= $3;
2427
lex->fk_delete_opt= $6;
2429
| ON DELETE_SYM delete_option
2430
ON UPDATE_SYM delete_option
2433
lex->fk_update_opt= $6;
2434
lex->fk_delete_opt= $3;
2439
RESTRICT { $$= Foreign_key::FK_OPTION_RESTRICT; }
2440
| CASCADE { $$= Foreign_key::FK_OPTION_CASCADE; }
2441
| SET NULL_SYM { $$= Foreign_key::FK_OPTION_SET_NULL; }
2442
| NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
2443
| SET DEFAULT { $$= Foreign_key::FK_OPTION_DEFAULT; }
2447
key_or_index { $$= Key::MULTIPLE; }
2450
constraint_key_type:
2451
PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
2452
| UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; }
2472
/* empty */ { $$= Key::MULTIPLE; }
2473
| UNIQUE_SYM { $$= Key::UNIQUE; }
2478
Lex->key_create_info= default_key_create_info;
2483
For now, key_alg initializies lex->key_create_info.
2484
In the future, when all key options are after key definition,
2485
we can remove key_alg and move init_key_options to key_options
2490
| init_key_options key_using_alg
2504
USING btree_or_rtree { Lex->key_create_info.algorithm= $2; }
2505
| TYPE_SYM btree_or_rtree { Lex->key_create_info.algorithm= $2; }
2510
| KEY_BLOCK_SIZE opt_equal ulong_num
2511
{ Lex->key_create_info.block_size= $3; }
2512
| COMMENT_SYM TEXT_STRING_sys
2513
{ Lex->key_create_info.comment= $2; }
2517
BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
2518
| HASH_SYM { $$= HA_KEY_ALG_HASH; }
2522
key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
2523
| key_part order_dir { Lex->col_list.push_back($1); }
2527
ident { $$=new Key_part_spec($1, 0); }
2530
int key_part_len= atoi($3.str);
2533
my_error(ER_KEY_PART_0, MYF(0), $1.str);
2535
$$=new Key_part_spec($1, (uint) key_part_len);
2540
/* empty */ { $$= null_lex_str; }
2541
| field_ident { $$= $1; }
2545
/* empty */ { $$= null_lex_str; }
2546
| '.' ident { $$= $2; }
2550
text_string { Lex->interval_list.push_back($1); }
2551
| string_list ',' text_string { Lex->interval_list.push_back($3); };
2558
ALTER build_method opt_ignore TABLE_SYM table_ident
2563
lex->name.length= 0;
2564
lex->sql_command= SQLCOM_ALTER_TABLE;
2565
lex->duplicates= DUP_ERROR;
2566
if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
2567
TL_OPTION_UPDATING))
2569
lex->alter_info.reset();
2570
lex->col_list.empty();
2571
lex->select_lex.init_order();
2573
((TABLE_LIST*) lex->select_lex.table_list.first)->db;
2574
bzero((char*) &lex->create_info,sizeof(lex->create_info));
2575
lex->create_info.db_type= 0;
2576
lex->create_info.default_table_charset= NULL;
2577
lex->create_info.row_type= ROW_TYPE_NOT_USED;
2578
lex->alter_info.reset();
2579
lex->no_write_to_binlog= 0;
2580
lex->create_info.default_storage_media= HA_SM_DEFAULT;
2581
lex->alter_info.build_method= $2;
2585
| ALTER DATABASE ident_or_empty
2587
Lex->create_info.default_table_charset= NULL;
2588
Lex->create_info.used_fields= 0;
2590
create_database_options
2593
lex->sql_command=SQLCOM_ALTER_DB;
2595
if (lex->name.str == NULL &&
2596
lex->copy_db_to(&lex->name.str, &lex->name.length))
2599
| ALTER DATABASE ident UPGRADE_SYM DATA_SYM DIRECTORY_SYM NAME_SYM
2602
lex->sql_command= SQLCOM_ALTER_DB_UPGRADE;
2608
/* empty */ { $$.str= 0; $$.length= 0; }
2614
| DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
2615
| IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
2622
$$= HA_BUILD_DEFAULT;
2626
$$= HA_BUILD_ONLINE;
2630
$$= HA_BUILD_OFFLINE;
2636
| alter_list ',' alter_list_item
2644
lex->alter_info.flags|= ALTER_ADD_COLUMN;
2649
add_column column_def opt_place { }
2652
Lex->alter_info.flags|= ALTER_ADD_INDEX;
2654
| add_column '(' field_list ')'
2656
Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX;
2658
| CHANGE opt_column field_ident
2661
lex->change= $3.str;
2662
lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
2664
field_spec opt_place
2665
| MODIFY_SYM opt_column field_ident
2668
lex->length=lex->dec=0; lex->type=0;
2669
lex->default_value= lex->on_update_value= 0;
2670
lex->comment=null_lex_str;
2672
lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
2673
lex->storage_type= HA_SM_DEFAULT;
2674
lex->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
2679
if (add_field_to_list(lex->thd,&$3,
2680
(enum enum_field_types) $5,
2681
lex->length,lex->dec,lex->type,
2682
lex->storage_type, lex->column_format,
2683
lex->default_value, lex->on_update_value,
2685
$3.str, &lex->interval_list, lex->charset))
2689
| DROP opt_column field_ident opt_restrict
2692
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
2694
lex->alter_info.flags|= ALTER_DROP_COLUMN;
2696
| DROP FOREIGN KEY_SYM opt_ident
2698
Lex->alter_info.flags|= ALTER_DROP_INDEX | ALTER_FOREIGN_KEY;
2700
| DROP PRIMARY_SYM KEY_SYM
2703
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2705
lex->alter_info.flags|= ALTER_DROP_INDEX;
2707
| DROP key_or_index field_ident
2710
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
2712
lex->alter_info.flags|= ALTER_DROP_INDEX;
2717
lex->alter_info.keys_onoff= DISABLE;
2718
lex->alter_info.flags|= ALTER_KEYS_ONOFF;
2723
lex->alter_info.keys_onoff= ENABLE;
2724
lex->alter_info.flags|= ALTER_KEYS_ONOFF;
2726
| ALTER opt_column field_ident SET DEFAULT signed_literal
2729
lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
2730
lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
2732
| ALTER opt_column field_ident DROP DEFAULT
2735
lex->alter_info.alter_list.push_back(new Alter_column($3.str,
2737
lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
2739
| RENAME opt_to table_ident
2743
lex->select_lex.db=$3->db.str;
2744
if (lex->select_lex.db == NULL &&
2745
lex->copy_db_to(&lex->select_lex.db, &dummy))
2749
if (check_table_name($3->table.str,$3->table.length) || ($3->db.str && check_db_name(&$3->db)))
2751
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
2754
lex->name= $3->table;
2755
lex->alter_info.flags|= ALTER_RENAME;
2757
| CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
2762
$4= thd->variables.collation_database;
2765
if (!my_charset_same($4,$5))
2767
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
2768
$5->name, $4->csname);
2772
lex->create_info.table_charset=
2773
lex->create_info.default_table_charset= $5;
2774
lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
2775
HA_CREATE_USED_DEFAULT_CHARSET);
2776
lex->alter_info.flags|= ALTER_CONVERT;
2778
| create_table_options_space_separated
2781
lex->alter_info.flags|= ALTER_OPTIONS;
2785
Lex->alter_info.flags|= ALTER_FORCE;
2787
| alter_order_clause
2790
lex->alter_info.flags|= ALTER_ORDER;
2800
/* empty */ { Lex->ignore= 0;}
2801
| IGNORE_SYM { Lex->ignore= 1;}
2805
/* empty */ { Lex->drop_mode= DROP_DEFAULT; }
2806
| RESTRICT { Lex->drop_mode= DROP_RESTRICT; }
2807
| CASCADE { Lex->drop_mode= DROP_CASCADE; }
2814
store_position_for_column($2.str);
2815
Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
2819
store_position_for_column(first_keyword);
2820
Lex->alter_info.flags|= ALTER_COLUMN_ORDER;
2832
SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
2836
START_SYM SLAVE slave_thread_opts
2839
lex->sql_command = SQLCOM_SLAVE_START;
2841
/* We'll use mi structure for UNTIL options */
2842
bzero((char*) &lex->mi, sizeof(lex->mi));
2843
/* If you change this code don't forget to update SLAVE START too */
2847
| STOP_SYM SLAVE slave_thread_opts
2850
lex->sql_command = SQLCOM_SLAVE_STOP;
2852
/* If you change this code don't forget to update SLAVE STOP too */
2854
| SLAVE START_SYM slave_thread_opts
2857
lex->sql_command = SQLCOM_SLAVE_START;
2859
/* We'll use mi structure for UNTIL options */
2860
bzero((char*) &lex->mi, sizeof(lex->mi));
2864
| SLAVE STOP_SYM slave_thread_opts
2867
lex->sql_command = SQLCOM_SLAVE_STOP;
2873
START_SYM TRANSACTION_SYM start_transaction_opts
2876
lex->sql_command= SQLCOM_BEGIN;
2877
lex->start_transaction_opt= $3;
2881
start_transaction_opts:
2882
/*empty*/ { $$ = 0; }
2883
| WITH CONSISTENT_SYM SNAPSHOT_SYM
2885
$$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
2890
{ Lex->slave_thd_opt= 0; }
2891
slave_thread_opt_list
2895
slave_thread_opt_list:
2897
| slave_thread_opt_list ',' slave_thread_opt
2902
| SQL_THREAD { Lex->slave_thd_opt|=SLAVE_SQL; }
2903
| RELAY_THREAD { Lex->slave_thd_opt|=SLAVE_IO; }
2908
| UNTIL_SYM slave_until_opts
2911
if (((lex->mi.log_file_name || lex->mi.pos) && (lex->mi.relay_log_name || lex->mi.relay_log_pos)) ||
2912
!((lex->mi.log_file_name && lex->mi.pos) ||
2913
(lex->mi.relay_log_name && lex->mi.relay_log_pos)))
2915
my_message(ER_BAD_SLAVE_UNTIL_COND,
2916
ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0));
2924
| slave_until_opts ',' master_file_def
2928
CHECKSUM_SYM table_or_tables
2931
lex->sql_command = SQLCOM_CHECKSUM;
2933
table_list opt_checksum_type
2938
/* nothing */ { Lex->check_opt.flags= 0; }
2939
| QUICK { Lex->check_opt.flags= T_QUICK; }
2940
| EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; }
2944
REPAIR opt_no_write_to_binlog table_or_tables
2947
lex->sql_command = SQLCOM_REPAIR;
2948
lex->no_write_to_binlog= $2;
2949
lex->check_opt.init();
2951
table_list opt_mi_repair_type
2956
/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
2957
| mi_repair_types {}
2962
| mi_repair_type mi_repair_types {}
2966
QUICK { Lex->check_opt.flags|= T_QUICK; }
2967
| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
2968
| USE_FRM { Lex->check_opt.sql_flags|= TT_USEFRM; }
2972
ANALYZE_SYM opt_no_write_to_binlog table_or_tables
2975
lex->sql_command = SQLCOM_ANALYZE;
2976
lex->no_write_to_binlog= $2;
2977
lex->check_opt.init();
2983
binlog_base64_event:
2984
BINLOG_SYM TEXT_STRING_sys
2986
Lex->sql_command = SQLCOM_BINLOG_BASE64_EVENT;
2992
CHECK_SYM table_or_tables
2996
lex->sql_command = SQLCOM_CHECK;
2997
lex->check_opt.init();
2999
table_list opt_mi_check_type
3004
/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
3010
| mi_check_type mi_check_types {}
3014
QUICK { Lex->check_opt.flags|= T_QUICK; }
3015
| FAST_SYM { Lex->check_opt.flags|= T_FAST; }
3016
| MEDIUM_SYM { Lex->check_opt.flags|= T_MEDIUM; }
3017
| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
3018
| CHANGED { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; }
3019
| FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
3023
OPTIMIZE opt_no_write_to_binlog table_or_tables
3026
lex->sql_command = SQLCOM_OPTIMIZE;
3027
lex->no_write_to_binlog= $2;
3028
lex->check_opt.init();
3034
opt_no_write_to_binlog:
3035
/* empty */ { $$= 0; }
3036
| NO_WRITE_TO_BINLOG { $$= 1; }
3037
| LOCAL_SYM { $$= 1; }
3041
RENAME table_or_tables
3043
Lex->sql_command= SQLCOM_RENAME_TABLE;
3049
table_to_table_list:
3051
| table_to_table_list ',' table_to_table
3055
table_ident TO_SYM table_ident
3058
SELECT_LEX *sl= lex->current_select;
3059
if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
3061
!sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
3068
CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
3071
lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
3078
| keycache_list ',' assign_to_keycache
3082
table_ident cache_keys_spec
3084
if (!Select->add_table_to_list(YYTHD, $1, NULL, 0, TL_READ,
3085
Select->pop_index_hints()))
3092
| DEFAULT { $$ = default_key_cache_base; }
3096
LOAD INDEX_SYM INTO CACHE_SYM
3099
lex->sql_command=SQLCOM_PRELOAD_KEYS;
3107
| preload_list ',' preload_keys
3111
table_ident cache_keys_spec opt_ignore_leaves
3113
if (!Select->add_table_to_list(YYTHD, $1, NULL, $3, TL_READ,
3114
Select->pop_index_hints()))
3121
Lex->select_lex.alloc_index_hints(YYTHD);
3122
Select->set_index_hint_type(INDEX_HINT_USE,
3123
global_system_variables.old_mode ?
3124
INDEX_HINT_MASK_JOIN :
3125
INDEX_HINT_MASK_ALL);
3127
cache_key_list_or_empty
3130
cache_key_list_or_empty:
3132
| key_or_index '(' opt_key_usage_list ')'
3138
| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
3142
Select : retrieve data from table
3150
lex->sql_command= SQLCOM_SELECT;
3154
/* Need select_init2 for subselects. */
3156
SELECT_SYM select_init2
3157
| '(' select_paren ')' union_opt
3161
SELECT_SYM select_part2
3163
if (setup_select_in_parentheses(Lex))
3166
| '(' select_paren ')'
3169
/* The equivalent of select_paren for nested queries. */
3170
select_paren_derived:
3171
SELECT_SYM select_part2_derived
3173
if (setup_select_in_parentheses(Lex))
3176
| '(' select_paren_derived ')'
3183
SELECT_LEX * sel= lex->current_select;
3184
if (lex->current_select->set_braces(0))
3186
my_parse_error(ER(ER_SYNTAX_ERROR));
3189
if (sel->linkage == UNION_TYPE &&
3190
sel->master_unit()->first_select()->braces)
3192
my_parse_error(ER(ER_SYNTAX_ERROR));
3202
SELECT_LEX *sel= lex->current_select;
3203
if (sel->linkage != UNION_TYPE)
3204
mysql_init_select(lex);
3205
lex->current_select->parsing_place= SELECT_LIST;
3207
select_options select_item_list
3209
Select->parsing_place= NO_MATTER;
3211
select_into select_lock_type
3215
opt_order_clause opt_limit_clause {}
3223
FROM join_table_list where_clause group_clause having_clause
3224
opt_order_clause opt_limit_clause
3226
Select->context.table_list=
3227
Select->context.first_name_resolution_table=
3228
(TABLE_LIST *) Select->table_list.first;
3234
| select_option_list
3236
if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
3238
my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
3245
select_option_list select_option
3250
STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
3253
if (check_simple_select())
3255
Lex->lock_option= TL_READ_HIGH_PRIORITY;
3257
| DISTINCT { Select->options|= SELECT_DISTINCT; }
3258
| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
3259
| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
3262
if (check_simple_select())
3264
Select->options|= OPTION_BUFFER_RESULT;
3266
| SQL_CALC_FOUND_ROWS
3268
if (check_simple_select())
3270
Select->options|= OPTION_FOUND_ROWS;
3272
| ALL { Select->options|= SELECT_ALL; }
3277
| FOR_SYM UPDATE_SYM
3280
lex->current_select->set_lock_for_tables(TL_WRITE);
3282
| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
3285
lex->current_select->
3286
set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
3291
select_item_list ',' select_item
3296
if (add_item_to_list(thd,
3297
new Item_field(&thd->lex->current_select->
3301
(thd->lex->current_select->with_wild)++;
3306
remember_name table_wild remember_end
3310
if (add_item_to_list(thd, $2))
3313
| remember_name expr remember_end select_alias
3316
DBUG_ASSERT($1 < $3);
3318
if (add_item_to_list(thd, $2))
3322
$2->is_autogenerated_name= FALSE;
3323
$2->set_name($4.str, $4.length, system_charset_info);
3327
$2->set_name($1, (uint) ($3 - $1), thd->charset());
3335
Lex_input_stream *lip= thd->m_lip;
3336
$$= (char*) lip->get_cpp_tok_start();
3343
Lex_input_stream *lip= thd->m_lip;
3344
$$= (char*) lip->get_cpp_tok_end();
3349
/* empty */ { $$=null_lex_str;}
3350
| AS ident { $$=$2; }
3351
| AS TEXT_STRING_sys { $$=$2; }
3353
| TEXT_STRING_sys { $$=$1; }
3361
/* all possible expressions */
3363
expr or expr %prec OR_SYM
3367
Do not use a manually maintained stack like thd->lex->xxx_list,
3368
but use the internal bison stack ($$, $1 and $3) instead.
3369
Using the bison stack is:
3370
- more robust to changes in the grammar,
3371
- guaranteed to be in sync with the parser state,
3372
- better for performances (no memory allocation).
3374
Item_cond_or *item1;
3375
Item_cond_or *item3;
3378
item1= (Item_cond_or*) $1;
3381
item3= (Item_cond_or*) $3;
3383
(X1 OR X2) OR (Y1 OR Y2) ==> OR (X1, X2, Y1, Y2)
3385
item3->add_at_head(item1->argument_list());
3391
(X1 OR X2) OR Y ==> OR (X1, X2, Y)
3397
else if (is_cond_or($3))
3399
item3= (Item_cond_or*) $3;
3401
X OR (Y1 OR Y2) ==> OR (X, Y1, Y2)
3403
item3->add_at_head($1);
3409
$$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
3412
| expr XOR expr %prec XOR
3414
/* XOR is a proprietary extension */
3415
$$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
3417
| expr and expr %prec AND_SYM
3419
/* See comments in rule expr: expr or expr */
3420
Item_cond_and *item1;
3421
Item_cond_and *item3;
3422
if (is_cond_and($1))
3424
item1= (Item_cond_and*) $1;
3425
if (is_cond_and($3))
3427
item3= (Item_cond_and*) $3;
3429
(X1 AND X2) AND (Y1 AND Y2) ==> AND (X1, X2, Y1, Y2)
3431
item3->add_at_head(item1->argument_list());
3437
(X1 AND X2) AND Y ==> AND (X1, X2, Y)
3443
else if (is_cond_and($3))
3445
item3= (Item_cond_and*) $3;
3447
X AND (Y1 AND Y2) ==> AND (X, Y1, Y2)
3449
item3->add_at_head($1);
3455
$$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
3458
| NOT_SYM expr %prec NOT_SYM
3459
{ $$= negate_expression(YYTHD, $2); }
3460
| bool_pri IS TRUE_SYM %prec IS
3461
{ $$= new (YYTHD->mem_root) Item_func_istrue($1); }
3462
| bool_pri IS not TRUE_SYM %prec IS
3463
{ $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
3464
| bool_pri IS FALSE_SYM %prec IS
3465
{ $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
3466
| bool_pri IS not FALSE_SYM %prec IS
3467
{ $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
3468
| bool_pri IS UNKNOWN_SYM %prec IS
3469
{ $$= new Item_func_isnull($1); }
3470
| bool_pri IS not UNKNOWN_SYM %prec IS
3471
{ $$= new Item_func_isnotnull($1); }
3476
bool_pri IS NULL_SYM %prec IS
3477
{ $$= new Item_func_isnull($1); }
3478
| bool_pri IS not NULL_SYM %prec IS
3479
{ $$= new Item_func_isnotnull($1); }
3480
| bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
3481
{ $$= new Item_func_equal($1,$3); }
3482
| bool_pri comp_op predicate %prec EQ
3483
{ $$= (*$2)(0)->create($1,$3); }
3484
| bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
3485
{ $$= all_any_subquery_creator($1, $2, $3, $5); }
3490
bit_expr IN_SYM '(' subselect ')'
3492
$$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
3494
| bit_expr not IN_SYM '(' subselect ')'
3497
Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
3498
$$= negate_expression(thd, item);
3500
| bit_expr IN_SYM '(' expr ')'
3502
$$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
3504
| bit_expr IN_SYM '(' expr ',' expr_list ')'
3508
$$= new (YYTHD->mem_root) Item_func_in(*$6);
3510
| bit_expr not IN_SYM '(' expr ')'
3512
$$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
3514
| bit_expr not IN_SYM '(' expr ',' expr_list ')'
3518
Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
3522
| bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
3523
{ $$= new Item_func_between($1,$3,$5); }
3524
| bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
3526
Item_func_between *item= new Item_func_between($1,$4,$6);
3530
| bit_expr LIKE simple_expr opt_escape
3531
{ $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
3532
| bit_expr not LIKE simple_expr opt_escape
3533
{ $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
3538
bit_expr '|' bit_expr %prec '|'
3539
{ $$= new Item_func_bit_or($1,$3); }
3540
| bit_expr '&' bit_expr %prec '&'
3541
{ $$= new Item_func_bit_and($1,$3); }
3542
| bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
3543
{ $$= new Item_func_shift_left($1,$3); }
3544
| bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
3545
{ $$= new Item_func_shift_right($1,$3); }
3546
| bit_expr '+' bit_expr %prec '+'
3547
{ $$= new Item_func_plus($1,$3); }
3548
| bit_expr '-' bit_expr %prec '-'
3549
{ $$= new Item_func_minus($1,$3); }
3550
| bit_expr '+' INTERVAL_SYM expr interval %prec '+'
3551
{ $$= new Item_date_add_interval($1,$4,$5,0); }
3552
| bit_expr '-' INTERVAL_SYM expr interval %prec '-'
3553
{ $$= new Item_date_add_interval($1,$4,$5,1); }
3554
| bit_expr '*' bit_expr %prec '*'
3555
{ $$= new Item_func_mul($1,$3); }
3556
| bit_expr '/' bit_expr %prec '/'
3557
{ $$= new Item_func_div($1,$3); }
3558
| bit_expr '%' bit_expr %prec '%'
3559
{ $$= new Item_func_mod($1,$3); }
3560
| bit_expr DIV_SYM bit_expr %prec DIV_SYM
3561
{ $$= new Item_func_int_div($1,$3); }
3562
| bit_expr MOD_SYM bit_expr %prec MOD_SYM
3563
{ $$= new Item_func_mod($1,$3); }
3564
| bit_expr '^' bit_expr
3565
{ $$= new Item_func_bit_xor($1,$3); }
3583
EQ { $$ = &comp_eq_creator; }
3584
| GE { $$ = &comp_ge_creator; }
3585
| GT_SYM { $$ = &comp_gt_creator; }
3586
| LE { $$ = &comp_le_creator; }
3587
| LT { $$ = &comp_lt_creator; }
3588
| NE { $$ = &comp_ne_creator; }
3593
| ANY_SYM { $$ = 0; }
3598
| function_call_keyword
3599
| function_call_nonkeyword
3600
| function_call_generic
3601
| function_call_conflict
3602
| simple_expr COLLATE_SYM ident_or_text %prec NEG
3605
Item *i1= new (thd->mem_root) Item_string($3.str,
3608
$$= new (thd->mem_root) Item_func_set_collation($1, i1);
3614
| '+' simple_expr %prec NEG { $$= $2; }
3615
| '-' simple_expr %prec NEG
3616
{ $$= new (YYTHD->mem_root) Item_func_neg($2); }
3617
| '~' simple_expr %prec NEG
3618
{ $$= new (YYTHD->mem_root) Item_func_bit_neg($2); }
3621
$$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
3623
| '(' expr ')' { $$= $2; }
3624
| '(' expr ',' expr_list ')'
3627
$$= new (YYTHD->mem_root) Item_row(*$4);
3629
| ROW_SYM '(' expr ',' expr_list ')'
3632
$$= new (YYTHD->mem_root) Item_row(*$5);
3634
| EXISTS '(' subselect ')'
3636
$$= new (YYTHD->mem_root) Item_exists_subselect($3);
3638
| '{' ident expr '}' { $$= $3; }
3639
| BINARY simple_expr %prec NEG
3641
$$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
3644
| CAST_SYM '(' expr AS cast_type ')'
3647
$$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
3652
| CASE_SYM opt_expr when_list opt_else END
3653
{ $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
3654
| CONVERT_SYM '(' expr ',' cast_type ')'
3656
$$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
3661
| CONVERT_SYM '(' expr USING charset_name ')'
3662
{ $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5); }
3663
| DEFAULT '(' simple_ident ')'
3665
$$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
3668
| VALUES '(' simple_ident_nospvar ')'
3670
$$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
3673
| INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
3674
/* we cannot put interval before - */
3675
{ $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
3679
Function call syntax using official SQL 2003 keywords.
3680
Because the function name is an official token,
3681
a dedicated grammar rule is needed in the parser.
3682
There is no potential for conflicts
3684
function_call_keyword:
3685
CHAR_SYM '(' expr_list ')'
3686
{ $$= new (YYTHD->mem_root) Item_func_char(*$3); }
3687
| CHAR_SYM '(' expr_list USING charset_name ')'
3688
{ $$= new (YYTHD->mem_root) Item_func_char(*$3, $5); }
3689
| CURRENT_USER optional_braces
3691
$$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
3692
Lex->set_stmt_unsafe();
3694
| DATE_SYM '(' expr ')'
3695
{ $$= new (YYTHD->mem_root) Item_date_typecast($3); }
3696
| DAY_SYM '(' expr ')'
3697
{ $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
3698
| HOUR_SYM '(' expr ')'
3699
{ $$= new (YYTHD->mem_root) Item_func_hour($3); }
3700
| INSERT '(' expr ',' expr ',' expr ',' expr ')'
3701
{ $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
3702
| INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3705
List<Item> *list= new (thd->mem_root) List<Item>;
3706
list->push_front($5);
3707
list->push_front($3);
3708
Item_row *item= new (thd->mem_root) Item_row(*list);
3709
$$= new (thd->mem_root) Item_func_interval(item);
3711
| INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
3716
Item_row *item= new (thd->mem_root) Item_row(*$7);
3717
$$= new (thd->mem_root) Item_func_interval(item);
3719
| LEFT '(' expr ',' expr ')'
3720
{ $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
3721
| MINUTE_SYM '(' expr ')'
3722
{ $$= new (YYTHD->mem_root) Item_func_minute($3); }
3723
| MONTH_SYM '(' expr ')'
3724
{ $$= new (YYTHD->mem_root) Item_func_month($3); }
3725
| RIGHT '(' expr ',' expr ')'
3726
{ $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
3727
| SECOND_SYM '(' expr ')'
3728
{ $$= new (YYTHD->mem_root) Item_func_second($3); }
3729
| TIME_SYM '(' expr ')'
3730
{ $$= new (YYTHD->mem_root) Item_time_typecast($3); }
3731
| TIMESTAMP '(' expr ')'
3732
{ $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
3733
| TIMESTAMP '(' expr ',' expr ')'
3734
{ $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
3736
{ $$= new (YYTHD->mem_root) Item_func_trim($3); }
3737
| TRIM '(' LEADING expr FROM expr ')'
3738
{ $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
3739
| TRIM '(' TRAILING expr FROM expr ')'
3740
{ $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
3741
| TRIM '(' BOTH expr FROM expr ')'
3742
{ $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
3743
| TRIM '(' LEADING FROM expr ')'
3744
{ $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
3745
| TRIM '(' TRAILING FROM expr ')'
3746
{ $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
3747
| TRIM '(' BOTH FROM expr ')'
3748
{ $$= new (YYTHD->mem_root) Item_func_trim($5); }
3749
| TRIM '(' expr FROM expr ')'
3750
{ $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
3753
$$= new (YYTHD->mem_root) Item_func_user();
3754
Lex->set_stmt_unsafe();
3756
| YEAR_SYM '(' expr ')'
3757
{ $$= new (YYTHD->mem_root) Item_func_year($3); }
3761
Function calls using non reserved keywords, with special syntaxic forms.
3762
Dedicated grammar rules are needed because of the syntax,
3763
but also have the potential to cause incompatibilities with other
3764
parts of the language.
3766
The only reasons a function should be added here are:
3767
- for compatibility reasons with another SQL syntax (CURDATE),
3768
- for typing reasons (GET_FORMAT)
3769
Any other 'Syntaxic sugar' enhancements should be *STRONGLY*
3772
function_call_nonkeyword:
3773
ADDDATE_SYM '(' expr ',' expr ')'
3775
$$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
3778
| ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3779
{ $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
3780
| CURDATE optional_braces
3782
$$= new (YYTHD->mem_root) Item_func_curdate_local();
3784
| CURTIME optional_braces
3786
$$= new (YYTHD->mem_root) Item_func_curtime_local();
3788
| CURTIME '(' expr ')'
3790
$$= new (YYTHD->mem_root) Item_func_curtime_local($3);
3792
| DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3793
{ $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
3794
| DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3795
{ $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
3796
| EXTRACT_SYM '(' interval FROM expr ')'
3797
{ $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
3798
| GET_FORMAT '(' date_time_type ',' expr ')'
3799
{ $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
3800
| NOW_SYM optional_braces
3802
$$= new (YYTHD->mem_root) Item_func_now_local();
3804
| NOW_SYM '(' expr ')'
3806
$$= new (YYTHD->mem_root) Item_func_now_local($3);
3808
| POSITION_SYM '(' bit_expr IN_SYM expr ')'
3809
{ $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
3810
| SUBDATE_SYM '(' expr ',' expr ')'
3812
$$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
3815
| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
3816
{ $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
3817
| SUBSTRING '(' expr ',' expr ',' expr ')'
3818
{ $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
3819
| SUBSTRING '(' expr ',' expr ')'
3820
{ $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
3821
| SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3822
{ $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
3823
| SUBSTRING '(' expr FROM expr ')'
3824
{ $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
3825
| SYSDATE optional_braces
3827
if (global_system_variables.sysdate_is_now == 0)
3828
$$= new (YYTHD->mem_root) Item_func_sysdate_local();
3830
$$= new (YYTHD->mem_root) Item_func_now_local();
3832
| SYSDATE '(' expr ')'
3834
if (global_system_variables.sysdate_is_now == 0)
3835
$$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
3837
$$= new (YYTHD->mem_root) Item_func_now_local($3);
3839
| TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3840
{ $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
3841
| TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3842
{ $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
3843
| UTC_DATE_SYM optional_braces
3845
$$= new (YYTHD->mem_root) Item_func_curdate_utc();
3847
| UTC_TIME_SYM optional_braces
3849
$$= new (YYTHD->mem_root) Item_func_curtime_utc();
3851
| UTC_TIMESTAMP_SYM optional_braces
3853
$$= new (YYTHD->mem_root) Item_func_now_utc();
3858
Functions calls using a non reserved keyword, and using a regular syntax.
3859
Because the non reserved keyword is used in another part of the grammar,
3860
a dedicated rule is needed here.
3862
function_call_conflict:
3863
ASCII_SYM '(' expr ')'
3864
{ $$= new (YYTHD->mem_root) Item_func_ascii($3); }
3865
| CHARSET '(' expr ')'
3866
{ $$= new (YYTHD->mem_root) Item_func_charset($3); }
3867
| COALESCE '(' expr_list ')'
3868
{ $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
3869
| COLLATION_SYM '(' expr ')'
3870
{ $$= new (YYTHD->mem_root) Item_func_collation($3); }
3873
$$= new (YYTHD->mem_root) Item_func_database();
3875
| IF '(' expr ',' expr ',' expr ')'
3876
{ $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
3877
| MICROSECOND_SYM '(' expr ')'
3878
{ $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
3879
| MOD_SYM '(' expr ',' expr ')'
3880
{ $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
3881
| OLD_PASSWORD '(' expr ')'
3882
{ $$= new (YYTHD->mem_root) Item_func_old_password($3); }
3883
| PASSWORD '(' expr ')'
3887
if (thd->variables.old_passwords)
3888
i1= new (thd->mem_root) Item_func_old_password($3);
3890
i1= new (thd->mem_root) Item_func_password($3);
3893
| QUARTER_SYM '(' expr ')'
3894
{ $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
3895
| REPEAT_SYM '(' expr ',' expr ')'
3896
{ $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
3897
| REPLACE '(' expr ',' expr ',' expr ')'
3898
{ $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
3899
| REVERSE_SYM '(' expr ')'
3900
{ $$= new (YYTHD->mem_root) Item_func_reverse($3); }
3901
| TRUNCATE_SYM '(' expr ',' expr ')'
3902
{ $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
3903
| WEEK_SYM '(' expr ')'
3906
Item *i1= new (thd->mem_root) Item_int((char*) "0",
3907
thd->variables.default_week_format,
3910
$$= new (thd->mem_root) Item_func_week($3, i1);
3912
| WEEK_SYM '(' expr ',' expr ')'
3913
{ $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
3914
| WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
3915
{ $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, $4); }
3916
| WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
3918
$$= new (YYTHD->mem_root)
3919
Item_func_weight_string($3, $6, $7|MY_STRXFRM_PAD_WITH_SPACE);
3921
| WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
3923
$3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
3924
$$= new (YYTHD->mem_root)
3925
Item_func_weight_string($3, $6, MY_STRXFRM_PAD_WITH_SPACE);
3930
Regular function calls.
3931
The function name is *not* a token, and therefore is guaranteed to not
3932
introduce side effects to the language in general.
3934
All the new functions implemented for new features should fit into
3935
this category. The place to implement the function itself is
3936
in sql/item_create.cc
3938
function_call_generic:
3944
if (using_udf_functions &&
3945
(udf= find_udf($1.str, $1.length)) &&
3946
udf->type == UDFTYPE_AGGREGATE)
3948
if (lex->current_select->inc_in_sum_expr())
3950
my_parse_error(ER(ER_SYNTAX_ERROR));
3954
/* Temporary placing the result of find_udf in $3 */
3958
opt_udf_expr_list ')'
3961
Create_func *builder;
3965
Implementation note:
3966
names are resolved with the following order:
3967
- MySQL native functions,
3968
- User Defined Functions,
3969
- Stored Functions (assuming the current <use> database)
3971
This will be revised with WL#2128 (SQL PATH)
3973
builder= find_native_function_builder(thd, $1);
3976
item= builder->create(thd, $1, $4);
3981
/* Retrieving the result of find_udf */
3982
udf_func *udf= $<udf>3;
3985
if (udf->type == UDFTYPE_AGGREGATE)
3987
Select->in_sum_expr--;
3990
item= Create_udf_func::s_singleton.create(thd, udf, $4);
4003
/* empty */ { $$= NULL; }
4004
| udf_expr_list { $$= $1; }
4010
$$= new (YYTHD->mem_root) List<Item>;
4013
| udf_expr_list ',' udf_expr
4021
remember_name expr remember_end select_alias
4024
Use Item::name as a storage for the attribute value of user
4025
defined function argument. It is safe to use Item::name
4026
because the syntax will not allow having an explicit name here.
4027
See WL#1017 re. udf attributes.
4031
$2->is_autogenerated_name= FALSE;
4032
$2->set_name($4.str, $4.length, system_charset_info);
4035
$2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
4041
AVG_SYM '(' in_sum_expr ')'
4042
{ $$=new Item_sum_avg($3); }
4043
| AVG_SYM '(' DISTINCT in_sum_expr ')'
4044
{ $$=new Item_sum_avg_distinct($4); }
4045
| BIT_AND '(' in_sum_expr ')'
4046
{ $$=new Item_sum_and($3); }
4047
| BIT_OR '(' in_sum_expr ')'
4048
{ $$=new Item_sum_or($3); }
4049
| BIT_XOR '(' in_sum_expr ')'
4050
{ $$=new Item_sum_xor($3); }
4051
| COUNT_SYM '(' opt_all '*' ')'
4052
{ $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
4053
| COUNT_SYM '(' in_sum_expr ')'
4054
{ $$=new Item_sum_count($3); }
4055
| COUNT_SYM '(' DISTINCT
4056
{ Select->in_sum_expr++; }
4058
{ Select->in_sum_expr--; }
4060
{ $$=new Item_sum_count_distinct(* $5); }
4061
| MIN_SYM '(' in_sum_expr ')'
4062
{ $$=new Item_sum_min($3); }
4064
According to ANSI SQL, DISTINCT is allowed and has
4065
no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
4066
is processed like an ordinary MIN | MAX()
4068
| MIN_SYM '(' DISTINCT in_sum_expr ')'
4069
{ $$=new Item_sum_min($4); }
4070
| MAX_SYM '(' in_sum_expr ')'
4071
{ $$=new Item_sum_max($3); }
4072
| MAX_SYM '(' DISTINCT in_sum_expr ')'
4073
{ $$=new Item_sum_max($4); }
4074
| STD_SYM '(' in_sum_expr ')'
4075
{ $$=new Item_sum_std($3, 0); }
4076
| VARIANCE_SYM '(' in_sum_expr ')'
4077
{ $$=new Item_sum_variance($3, 0); }
4078
| STDDEV_SAMP_SYM '(' in_sum_expr ')'
4079
{ $$=new Item_sum_std($3, 1); }
4080
| VAR_SAMP_SYM '(' in_sum_expr ')'
4081
{ $$=new Item_sum_variance($3, 1); }
4082
| SUM_SYM '(' in_sum_expr ')'
4083
{ $$=new Item_sum_sum($3); }
4084
| SUM_SYM '(' DISTINCT in_sum_expr ')'
4085
{ $$=new Item_sum_sum_distinct($4); }
4086
| GROUP_CONCAT_SYM '(' opt_distinct
4087
{ Select->in_sum_expr++; }
4088
expr_list opt_gorder_clause
4089
opt_gconcat_separator
4092
SELECT_LEX *sel= Select;
4094
$$=new Item_func_group_concat(Lex->current_context(), $3, $5,
4095
sel->gorder_list, $7);
4103
if (! Lex->parsing_options.allows_variable)
4105
my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
4116
ident_or_text SET_VAR expr
4118
$$= new Item_func_set_user_var($1, $3);
4122
$$= new Item_func_get_user_var($1);
4124
| '@' opt_var_ident_type ident_or_text opt_component
4126
/* disallow "SELECT @@global.global.variable" */
4127
if ($3.str && $4.str && check_reserved_words(&$3))
4129
my_parse_error(ER(ER_SYNTAX_ERROR));
4132
if (!($$= get_system_var(YYTHD, $2, $3, $4)))
4134
if (!((Item_func_get_system_var*) $$)->is_written_to_binlog())
4135
Lex->set_stmt_unsafe();
4140
/* empty */ { $$ = 0; }
4141
| DISTINCT { $$ = 1; }
4144
opt_gconcat_separator:
4147
$$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
4149
| SEPARATOR_SYM text_string { $$ = $2; }
4155
Select->gorder_list = NULL;
4159
SELECT_LEX *select= Select;
4160
select->gorder_list=
4161
(SQL_LIST*) sql_memdup((char*) &select->order_list,
4162
sizeof(st_sql_list));
4163
select->order_list.empty();
4171
if (lex->current_select->inc_in_sum_expr())
4173
my_parse_error(ER(ER_SYNTAX_ERROR));
4179
Select->in_sum_expr--;
4186
{ $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; Lex->dec= 0; }
4187
| CHAR_SYM opt_len opt_binary
4188
{ $$=ITEM_CAST_CHAR; Lex->dec= 0; }
4190
{ $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; Lex->dec=0; }
4192
{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4193
| SIGNED_SYM INT_SYM
4194
{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4196
{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4198
{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4200
{ $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4202
{ $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4204
{ $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->dec=Lex->length= (char*)0; }
4205
| DECIMAL_SYM float_options
4206
{ $$=ITEM_CAST_DECIMAL; Lex->charset= NULL; }
4212
$$= new (YYTHD->mem_root) List<Item>;
4215
| expr_list ',' expr
4223
/* empty */ { $$= NULL; }
4228
/* empty */ { $$= NULL; }
4229
| ELSE expr { $$= $2; }
4233
WHEN_SYM expr THEN_SYM expr
4239
| when_list WHEN_SYM expr THEN_SYM expr
4247
/* Equivalent to <table reference> in the SQL:2003 standard. */
4248
/* Warning - may return NULL in case of incomplete SELECT */
4250
table_factor { $$=$1; }
4254
if (!($$= lex->current_select->nest_last_join(lex->thd)))
4260
derived_table_list { MYSQL_YYABORT_UNLESS($$=$1); }
4264
The ODBC escape syntax for Outer Join is: '{' OJ join_table '}'
4265
The parser does not define OJ as a token, any ident is accepted
4266
instead in $2 (ident). Also, all productions from table_ref can
4267
be escaped, not only join_table. Both syntax extensions are safe
4271
table_ref { $$=$1; }
4272
| '{' ident table_ref '}' { $$=$3; }
4275
/* Equivalent to <table reference list> in the SQL:2003 standard. */
4276
/* Warning - may return NULL in case of incomplete SELECT */
4278
esc_table_ref { $$=$1; }
4279
| derived_table_list ',' esc_table_ref
4281
MYSQL_YYABORT_UNLESS($1 && ($$=$3));
4286
Notice that JOIN is a left-associative operation, and it must be parsed
4287
as such, that is, the parser must process first the left join operand
4288
then the right one. Such order of processing ensures that the parser
4289
produces correct join trees which is essential for semantic analysis
4290
and subsequent optimization phases.
4293
/* INNER JOIN variants */
4295
Use %prec to evaluate production 'table_ref' before 'normal_join'
4296
so that [INNER | CROSS] JOIN is properly nested as other
4297
left-associative joins.
4299
table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
4300
{ MYSQL_YYABORT_UNLESS($1 && ($$=$3)); }
4301
| table_ref STRAIGHT_JOIN table_factor
4302
{ MYSQL_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
4303
| table_ref normal_join table_ref
4306
MYSQL_YYABORT_UNLESS($1 && $3);
4307
/* Change the current name resolution context to a local context. */
4308
if (push_new_name_resolution_context(YYTHD, $1, $3))
4310
Select->parsing_place= IN_ON;
4316
Select->parsing_place= NO_MATTER;
4318
| table_ref STRAIGHT_JOIN table_factor
4321
MYSQL_YYABORT_UNLESS($1 && $3);
4322
/* Change the current name resolution context to a local context. */
4323
if (push_new_name_resolution_context(YYTHD, $1, $3))
4325
Select->parsing_place= IN_ON;
4332
Select->parsing_place= NO_MATTER;
4334
| table_ref normal_join table_ref
4337
MYSQL_YYABORT_UNLESS($1 && $3);
4340
{ add_join_natural($1,$3,$7,Select); $$=$3; }
4341
| table_ref NATURAL JOIN_SYM table_factor
4343
MYSQL_YYABORT_UNLESS($1 && ($$=$4));
4344
add_join_natural($1,$4,NULL,Select);
4347
/* LEFT JOIN variants */
4348
| table_ref LEFT opt_outer JOIN_SYM table_ref
4351
MYSQL_YYABORT_UNLESS($1 && $5);
4352
/* Change the current name resolution context to a local context. */
4353
if (push_new_name_resolution_context(YYTHD, $1, $5))
4355
Select->parsing_place= IN_ON;
4361
$5->outer_join|=JOIN_TYPE_LEFT;
4363
Select->parsing_place= NO_MATTER;
4365
| table_ref LEFT opt_outer JOIN_SYM table_factor
4367
MYSQL_YYABORT_UNLESS($1 && $5);
4369
USING '(' using_list ')'
4371
add_join_natural($1,$5,$9,Select);
4372
$5->outer_join|=JOIN_TYPE_LEFT;
4375
| table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
4377
MYSQL_YYABORT_UNLESS($1 && $6);
4378
add_join_natural($1,$6,NULL,Select);
4379
$6->outer_join|=JOIN_TYPE_LEFT;
4383
/* RIGHT JOIN variants */
4384
| table_ref RIGHT opt_outer JOIN_SYM table_ref
4387
MYSQL_YYABORT_UNLESS($1 && $5);
4388
/* Change the current name resolution context to a local context. */
4389
if (push_new_name_resolution_context(YYTHD, $1, $5))
4391
Select->parsing_place= IN_ON;
4396
if (!($$= lex->current_select->convert_right_join()))
4398
add_join_on($$, $8);
4400
Select->parsing_place= NO_MATTER;
4402
| table_ref RIGHT opt_outer JOIN_SYM table_factor
4404
MYSQL_YYABORT_UNLESS($1 && $5);
4406
USING '(' using_list ')'
4409
if (!($$= lex->current_select->convert_right_join()))
4411
add_join_natural($$,$5,$9,Select);
4413
| table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
4415
MYSQL_YYABORT_UNLESS($1 && $6);
4416
add_join_natural($6,$1,NULL,Select);
4418
if (!($$= lex->current_select->convert_right_join()))
4425
| INNER_SYM JOIN_SYM {}
4430
This is a flattening of the rules <table factor> and <table primary>
4431
in the SQL:2003 standard, since we don't have <sample clause>
4434
<table factor> ::= <table primary> [ <sample clause> ]
4436
/* Warning - may return NULL in case of incomplete SELECT */
4439
SELECT_LEX *sel= Select;
4440
sel->table_join_options= 0;
4442
table_ident opt_table_alias opt_key_definition
4444
if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
4445
Select->get_table_join_options(),
4447
Select->pop_index_hints())))
4449
Select->add_joined_table($$);
4451
| select_derived_init get_select_lex select_derived2
4454
SELECT_LEX *sel= lex->current_select;
4457
if (sel->set_braces(1))
4459
my_parse_error(ER(ER_SYNTAX_ERROR));
4462
/* select in braces, can't contain global parameters */
4463
if (sel->master_unit()->fake_select_lex)
4464
sel->master_unit()->global_parameters=
4465
sel->master_unit()->fake_select_lex;
4467
if ($2->init_nested_join(lex->thd))
4470
/* incomplete derived tables return NULL, we must be
4471
nested in select_derived rule to be here. */
4474
Represents a flattening of the following rules from the SQL:2003
4475
standard. This sub-rule corresponds to the sub-rule
4476
<table primary> ::= ... | <derived table> [ AS ] <correlation name>
4478
The following rules have been flattened into query_expression_body
4479
(since we have no <with clause>).
4481
<derived table> ::= <table subquery>
4482
<table subquery> ::= <subquery>
4483
<subquery> ::= <left paren> <query expression> <right paren>
4484
<query expression> ::= [ <with clause> ] <query expression body>
4486
For the time being we use the non-standard rule
4487
select_derived_union which is a compromise between the standard
4488
and our parser. Possibly this rule could be replaced by our
4489
query_expression_body.
4491
| '(' get_select_lex select_derived_union ')' opt_table_alias
4493
/* Use $2 instead of Lex->current_select as derived table will
4494
alter value of Lex->current_select. */
4495
if (!($3 || $5) && $2->embedding &&
4496
!$2->embedding->nested_join->join_list.elements)
4498
/* we have a derived table ($3 == NULL) but no alias,
4499
Since we are nested in further parentheses so we
4500
can pass NULL to the outer level parentheses
4501
Permits parsing of "((((select ...))) as xyz)" */
4506
/* Handle case of derived table, alias may be NULL if there
4507
are no outer parentheses, add_table_to_list() will throw
4508
error in this case */
4510
SELECT_LEX *sel= lex->current_select;
4511
SELECT_LEX_UNIT *unit= sel->master_unit();
4512
lex->current_select= sel= unit->outer_select();
4513
if (!($$= sel->add_table_to_list(lex->thd,
4514
new Table_ident(unit), $5, 0,
4518
sel->add_joined_table($$);
4521
else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
4523
/* simple nested joins cannot have aliases or unions */
4524
my_parse_error(ER(ER_SYNTAX_ERROR));
4532
select_derived_union:
4533
select_derived opt_order_clause opt_limit_clause
4534
| select_derived_union
4538
if (add_select_to_union_list(Lex, (bool)$3))
4544
Remove from the name resolution context stack the context of the
4545
last select in the union.
4549
opt_order_clause opt_limit_clause
4552
/* The equivalent of select_init2 for nested queries. */
4553
select_init2_derived:
4554
select_part2_derived
4557
SELECT_LEX * sel= lex->current_select;
4558
if (lex->current_select->set_braces(0))
4560
my_parse_error(ER(ER_SYNTAX_ERROR));
4563
if (sel->linkage == UNION_TYPE &&
4564
sel->master_unit()->first_select()->braces)
4566
my_parse_error(ER(ER_SYNTAX_ERROR));
4572
/* The equivalent of select_part2 for nested queries. */
4573
select_part2_derived:
4576
SELECT_LEX *sel= lex->current_select;
4577
if (sel->linkage != UNION_TYPE)
4578
mysql_init_select(lex);
4579
lex->current_select->parsing_place= SELECT_LIST;
4581
select_options select_item_list
4583
Select->parsing_place= NO_MATTER;
4585
opt_select_from select_lock_type
4588
/* handle contents of parentheses in join expression */
4593
if ($1->init_nested_join(lex->thd))
4599
/* for normal joins, $3 != NULL and end_nested_join() != NULL,
4600
for derived tables, both must equal NULL */
4602
if (!($$= $1->end_nested_join(lex->thd)) && $3)
4606
my_parse_error(ER(ER_SYNTAX_ERROR));
4615
lex->derived_tables|= DERIVED_SUBQUERY;
4616
if (!lex->expr_allows_subselect ||
4617
lex->sql_command == (int)SQLCOM_PURGE)
4619
my_parse_error(ER(ER_SYNTAX_ERROR));
4622
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
4623
mysql_new_select(lex, 1))
4625
mysql_init_select(lex);
4626
lex->current_select->linkage= DERIVED_TABLE_TYPE;
4627
lex->current_select->parsing_place= SELECT_LIST;
4629
select_options select_item_list
4631
Select->parsing_place= NO_MATTER;
4637
/* Empty */ { $$= Select; }
4640
select_derived_init:
4645
if (! lex->parsing_options.allows_derived)
4647
my_error(ER_VIEW_SELECT_DERIVED, MYF(0));
4651
SELECT_LEX *sel= lex->current_select;
4652
TABLE_LIST *embedding;
4653
if (!sel->embedding || sel->end_nested_join(lex->thd))
4655
/* we are not in parentheses */
4656
my_parse_error(ER(ER_SYNTAX_ERROR));
4659
embedding= Select->embedding;
4661
!embedding->nested_join->join_list.elements;
4662
/* return true if we are deeply nested */
4674
$$= global_system_variables.old_mode ?
4675
INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL;
4677
| FOR_SYM JOIN_SYM { $$= INDEX_HINT_MASK_JOIN; }
4678
| FOR_SYM ORDER_SYM BY { $$= INDEX_HINT_MASK_ORDER; }
4679
| FOR_SYM GROUP_SYM BY { $$= INDEX_HINT_MASK_GROUP; }
4683
FORCE_SYM { $$= INDEX_HINT_FORCE; }
4684
| IGNORE_SYM { $$= INDEX_HINT_IGNORE; }
4687
index_hint_definition:
4688
index_hint_type key_or_index index_hint_clause
4690
Select->set_index_hint_type($1, $3);
4692
'(' key_usage_list ')'
4693
| USE_SYM key_or_index index_hint_clause
4695
Select->set_index_hint_type(INDEX_HINT_USE, $3);
4697
'(' opt_key_usage_list ')'
4701
index_hint_definition
4702
| index_hints_list index_hint_definition
4705
opt_index_hints_list:
4707
| { Select->alloc_index_hints(YYTHD); } index_hints_list
4711
{ Select->clear_index_hints(); }
4712
opt_index_hints_list
4716
/* empty */ { Select->add_index_hint(YYTHD, NULL, 0); }
4722
{ Select->add_index_hint(YYTHD, $1.str, $1.length); }
4724
{ Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7); }
4729
| key_usage_list ',' key_usage_element
4735
if (!($$= new List<String>))
4737
$$->push_back(new (YYTHD->mem_root)
4738
String((const char *) $1.str, $1.length,
4739
system_charset_info));
4741
| using_list ',' ident
4743
$1->push_back(new (YYTHD->mem_root)
4744
String((const char *) $3.str, $3.length,
4745
system_charset_info));
4752
| DAY_HOUR_SYM { $$=INTERVAL_DAY_HOUR; }
4753
| DAY_MICROSECOND_SYM { $$=INTERVAL_DAY_MICROSECOND; }
4754
| DAY_MINUTE_SYM { $$=INTERVAL_DAY_MINUTE; }
4755
| DAY_SECOND_SYM { $$=INTERVAL_DAY_SECOND; }
4756
| HOUR_MICROSECOND_SYM { $$=INTERVAL_HOUR_MICROSECOND; }
4757
| HOUR_MINUTE_SYM { $$=INTERVAL_HOUR_MINUTE; }
4758
| HOUR_SECOND_SYM { $$=INTERVAL_HOUR_SECOND; }
4759
| MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
4760
| MINUTE_SECOND_SYM { $$=INTERVAL_MINUTE_SECOND; }
4761
| SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
4762
| YEAR_MONTH_SYM { $$=INTERVAL_YEAR_MONTH; }
4765
interval_time_stamp:
4768
$$=INTERVAL_MICROSECOND;
4770
FRAC_SECOND was mistakenly implemented with
4771
a wrong resolution. According to the ODBC
4772
standard it should be nanoseconds, not
4773
microseconds. Changing it to nanoseconds
4774
in MySQL would mean making TIMESTAMPDIFF
4775
and TIMESTAMPADD to return DECIMAL, since
4776
the return value would be too big for BIGINT
4777
Hence we just deprecate the incorrect
4778
implementation without changing its
4785
DAY_SYM { $$=INTERVAL_DAY; }
4786
| WEEK_SYM { $$=INTERVAL_WEEK; }
4787
| HOUR_SYM { $$=INTERVAL_HOUR; }
4788
| MINUTE_SYM { $$=INTERVAL_MINUTE; }
4789
| MONTH_SYM { $$=INTERVAL_MONTH; }
4790
| QUARTER_SYM { $$=INTERVAL_QUARTER; }
4791
| SECOND_SYM { $$=INTERVAL_SECOND; }
4792
| MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
4793
| YEAR_SYM { $$=INTERVAL_YEAR; }
4797
DATE_SYM {$$=MYSQL_TIMESTAMP_DATE;}
4798
| TIME_SYM {$$=MYSQL_TIMESTAMP_TIME;}
4799
| DATETIME {$$=MYSQL_TIMESTAMP_DATETIME;}
4800
| TIMESTAMP {$$=MYSQL_TIMESTAMP_DATETIME;}
4810
/* empty */ { $$=0; }
4812
{ $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
4821
/* empty */ { Select->where= 0; }
4824
Select->parsing_place= IN_WHERE;
4828
SELECT_LEX *select= Select;
4830
select->parsing_place= NO_MATTER;
4832
$3->top_level_item();
4840
Select->parsing_place= IN_HAVING;
4844
SELECT_LEX *sel= Select;
4846
sel->parsing_place= NO_MATTER;
4848
$3->top_level_item();
4853
ESCAPE_SYM simple_expr
4855
Lex->escape_used= TRUE;
4860
Lex->escape_used= FALSE;
4861
$$= new Item_string("\\", 1, &my_charset_latin1);
4866
group by statement in select
4871
| GROUP_SYM BY group_list olap_opt
4875
group_list ',' order_ident order_dir
4876
{ if (add_group_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; }
4877
| order_ident order_dir
4878
{ if (add_group_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; }
4886
'WITH CUBE' is reserved in the MySQL syntax, but not implemented,
4887
and cause LALR(2) conflicts.
4888
This syntax is not standard.
4889
MySQL syntax: GROUP BY col1, col2, col3 WITH CUBE
4890
SQL-2003: GROUP BY ... CUBE(col1, col2, col3)
4893
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4895
my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE",
4896
"global union parameters");
4899
lex->current_select->olap= CUBE_TYPE;
4900
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE");
4906
'WITH ROLLUP' is needed for backward compatibility,
4907
and cause LALR(2) conflicts.
4908
This syntax is not standard.
4909
MySQL syntax: GROUP BY col1, col2, col3 WITH ROLLUP
4910
SQL-2003: GROUP BY ... ROLLUP(col1, col2, col3)
4913
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4915
my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP",
4916
"global union parameters");
4919
lex->current_select->olap= ROLLUP_TYPE;
4924
Order by statement in ALTER TABLE
4928
ORDER_SYM BY alter_order_list
4932
alter_order_list ',' alter_order_item
4937
simple_ident_nospvar order_dir
4940
bool ascending= ($2 == 1) ? true : false;
4941
if (add_order_to_list(thd, $1, ascending))
4947
Order by statement in select
4959
SELECT_LEX *sel= lex->current_select;
4960
SELECT_LEX_UNIT *unit= sel-> master_unit();
4961
if (sel->linkage != GLOBAL_OPTIONS_TYPE &&
4962
sel->olap != UNSPECIFIED_OLAP_TYPE &&
4963
(sel->linkage != UNION_TYPE || sel->braces))
4965
my_error(ER_WRONG_USAGE, MYF(0),
4966
"CUBE/ROLLUP", "ORDER BY");
4969
if (lex->sql_command != SQLCOM_ALTER_TABLE && !unit->fake_select_lex)
4972
A query of the of the form (SELECT ...) ORDER BY order_list is
4973
executed in the same way as the query
4974
SELECT ... ORDER BY order_list
4975
unless the SELECT construct contains ORDER BY or LIMIT clauses.
4976
Otherwise we create a fake SELECT_LEX if it has not been created
4979
SELECT_LEX *first_sl= unit->first_select();
4980
if (!unit->is_union() &&
4981
(first_sl->order_list.elements ||
4982
first_sl->select_limit) &&
4983
unit->add_fake_select_lex(lex->thd))
4991
order_list ',' order_ident order_dir
4992
{ if (add_order_to_list(YYTHD, $3,(bool) $4)) MYSQL_YYABORT; }
4993
| order_ident order_dir
4994
{ if (add_order_to_list(YYTHD, $1,(bool) $2)) MYSQL_YYABORT; }
4998
/* empty */ { $$ = 1; }
5003
opt_limit_clause_init:
5007
SELECT_LEX *sel= lex->current_select;
5008
sel->offset_limit= 0;
5009
sel->select_limit= 0;
5020
LIMIT limit_options {}
5026
SELECT_LEX *sel= Select;
5027
sel->select_limit= $1;
5028
sel->offset_limit= 0;
5029
sel->explicit_limit= 1;
5031
| limit_option ',' limit_option
5033
SELECT_LEX *sel= Select;
5034
sel->select_limit= $3;
5035
sel->offset_limit= $1;
5036
sel->explicit_limit= 1;
5038
| limit_option OFFSET_SYM limit_option
5040
SELECT_LEX *sel= Select;
5041
sel->select_limit= $1;
5042
sel->offset_limit= $3;
5043
sel->explicit_limit= 1;
5050
((Item_param *) $1)->limit_clause_param= TRUE;
5052
| ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
5053
| LONG_NUM { $$= new Item_uint($1.str, $1.length); }
5054
| NUM { $$= new Item_uint($1.str, $1.length); }
5057
delete_limit_clause:
5061
lex->current_select->select_limit= 0;
5063
| LIMIT limit_option
5065
SELECT_LEX *sel= Select;
5066
sel->select_limit= $2;
5067
sel->explicit_limit= 1;
5072
NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5073
| HEX_NUM { $$= (ulong) strtol($1.str, (char**) 0, 16); }
5074
| LONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5075
| ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5076
| DECIMAL_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5077
| FLOAT_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5081
NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5082
| HEX_NUM { $$= (ulong) strtol($1.str, (char**) 0, 16); }
5083
| LONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5084
| ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
5085
| dec_num_error { MYSQL_YYABORT; }
5089
NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
5090
| ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
5091
| LONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
5092
| DECIMAL_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
5093
| FLOAT_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
5098
{ my_parse_error(ER(ER_ONLY_INTEGERS_ALLOWED)); }
5107
ulong_num { $$= $1 != 0 ? HA_CHOICE_YES : HA_CHOICE_NO; }
5108
| DEFAULT { $$= HA_CHOICE_UNDEF; }
5111
select_var_list_init:
5114
if (!lex->describe && (!(lex->result= new select_dumpvar())))
5122
select_var_list ',' select_var_ident
5123
| select_var_ident {}
5131
((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
5134
The parser won't create select_result instance only
5137
DBUG_ASSERT(lex->describe);
5144
if (! Lex->parsing_options.allows_select_into)
5146
my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "INTO");
5154
OUTFILE TEXT_STRING_filesystem
5157
if (!(lex->exchange= new sql_exchange($2.str, 0)) ||
5158
!(lex->result= new select_export(lex->exchange)))
5161
opt_field_term opt_line_term
5162
| DUMPFILE TEXT_STRING_filesystem
5167
if (!(lex->exchange= new sql_exchange($2.str,1)))
5169
if (!(lex->result= new select_dump(lex->exchange)))
5173
| select_var_list_init
5178
Drop : delete tables or index or user
5182
DROP opt_temporary table_or_tables if_exists table_list opt_restrict
5185
lex->sql_command = SQLCOM_DROP_TABLE;
5186
lex->drop_temporary= $2;
5187
lex->drop_if_exists= $4;
5189
| DROP build_method INDEX_SYM ident ON table_ident {}
5192
lex->sql_command= SQLCOM_DROP_INDEX;
5193
lex->alter_info.reset();
5194
lex->alter_info.flags= ALTER_DROP_INDEX;
5195
lex->alter_info.build_method= $2;
5196
lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
5198
if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
5199
TL_OPTION_UPDATING))
5202
| DROP DATABASE if_exists ident
5205
lex->sql_command= SQLCOM_DROP_DB;
5206
lex->drop_if_exists=$3;
5209
| DROP FUNCTION_SYM if_exists ident
5213
lex->sql_command = SQLCOM_DROP_FUNCTION;
5214
lex->drop_if_exists= $3;
5221
| table_list ',' table_name
5227
if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
5232
table_alias_ref_list:
5234
| table_alias_ref_list ',' table_alias_ref
5240
if (!Select->add_table_to_list(YYTHD, $1, NULL,
5241
TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5248
/* empty */ { $$= 0; }
5249
| IF EXISTS { $$= 1; }
5253
/* empty */ { $$= 0; }
5254
| TEMPORARY { $$= 1; }
5257
** Insert : add new data to table
5264
lex->sql_command= SQLCOM_INSERT;
5265
lex->duplicates= DUP_ERROR;
5266
mysql_init_select(lex);
5267
/* for subselects */
5268
lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
5273
Select->set_lock_for_tables($3);
5274
Lex->current_select= &Lex->select_lex;
5276
insert_field_spec opt_insert_update
5284
lex->sql_command = SQLCOM_REPLACE;
5285
lex->duplicates= DUP_REPLACE;
5286
mysql_init_select(lex);
5288
replace_lock_option insert2
5290
Select->set_lock_for_tables($3);
5291
Lex->current_select= &Lex->select_lex;
5300
$$= TL_WRITE_CONCURRENT_INSERT;
5302
| LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
5303
| DELAYED_SYM { $$= TL_WRITE_LOW_PRIORITY; }
5304
| HIGH_PRIORITY { $$= TL_WRITE; }
5307
replace_lock_option:
5308
opt_low_priority { $$= $1; }
5309
| DELAYED_SYM { $$= TL_WRITE_LOW_PRIORITY; }
5313
INTO insert_table {}
5321
lex->field_list.empty();
5322
lex->many_values.empty();
5328
| '(' ')' insert_values {}
5329
| '(' fields ')' insert_values {}
5333
if (!(lex->insert_list = new List_item) ||
5334
lex->many_values.push_back(lex->insert_list))
5341
fields ',' insert_ident { Lex->field_list.push_back($3); }
5342
| insert_ident { Lex->field_list.push_back($1); }
5346
VALUES values_list {}
5347
| VALUE_SYM values_list {}
5349
{ Select->set_braces(0);}
5351
| '(' create_select ')'
5352
{ Select->set_braces(1);}
5357
values_list ',' no_braces
5362
ident_eq_list ',' ident_eq_value
5367
simple_ident_nospvar equal expr_or_default
5370
if (lex->field_list.push_back($1) ||
5371
lex->insert_list->push_back($3))
5389
if (!(Lex->insert_list = new List_item))
5395
if (lex->many_values.push_back(lex->insert_list))
5406
values ',' expr_or_default
5408
if (Lex->insert_list->push_back($3))
5413
if (Lex->insert_list->push_back($1))
5420
| DEFAULT {$$= new Item_default_value(Lex->current_context()); }
5425
| ON DUPLICATE_SYM { Lex->duplicates= DUP_UPDATE; }
5426
KEY_SYM UPDATE_SYM insert_update_list
5429
/* Update rows in a table */
5435
mysql_init_select(lex);
5436
lex->sql_command= SQLCOM_UPDATE;
5437
lex->lock_option= TL_UNLOCK; /* Will be set later */
5438
lex->duplicates= DUP_ERROR;
5440
opt_low_priority opt_ignore join_table_list
5444
if (lex->select_lex.table_list.elements > 1)
5445
lex->sql_command= SQLCOM_UPDATE_MULTI;
5446
else if (lex->select_lex.get_table_list()->derived)
5448
/* it is single table update and it is update of derived table */
5449
my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
5450
lex->select_lex.get_table_list()->alias, "UPDATE");
5454
In case of multi-update setting write lock for all tables may
5455
be too pessimistic. We will decrease lock level if possible in
5456
mysql_multi_update().
5458
Select->set_lock_for_tables($3);
5460
where_clause opt_order_clause delete_limit_clause {}
5464
update_list ',' update_elem
5469
simple_ident_nospvar equal expr_or_default
5471
if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
5477
insert_update_list ',' insert_update_elem
5478
| insert_update_elem
5482
simple_ident_nospvar equal expr_or_default
5485
if (lex->update_list.push_back($1) ||
5486
lex->value_list.push_back($3))
5492
/* empty */ { $$= TL_WRITE_DEFAULT; }
5493
| LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
5496
/* Delete rows from a table */
5502
lex->sql_command= SQLCOM_DELETE;
5503
mysql_init_select(lex);
5504
lex->lock_option= TL_WRITE_DEFAULT;
5506
lex->select_lex.init_order();
5508
opt_delete_options single_multi
5514
if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
5518
where_clause opt_order_clause
5519
delete_limit_clause {}
5521
{ mysql_init_multi_delete(Lex); }
5522
FROM join_table_list where_clause
5524
if (multi_delete_set_locks_and_link_aux_tables(Lex))
5527
| FROM table_alias_ref_list
5528
{ mysql_init_multi_delete(Lex); }
5529
USING join_table_list where_clause
5531
if (multi_delete_set_locks_and_link_aux_tables(Lex))
5538
| table_wild_list ',' table_wild_one
5544
if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
5546
TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5550
| ident '.' ident opt_wild
5552
if (!Select->add_table_to_list(YYTHD,
5553
new Table_ident(YYTHD, $1, $3, 0),
5555
TL_OPTION_UPDATING | TL_OPTION_ALIAS,
5568
| opt_delete_option opt_delete_options {}
5572
QUICK { Select->options|= OPTION_QUICK; }
5573
| LOW_PRIORITY { Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
5574
| IGNORE_SYM { Lex->ignore= 1; }
5578
TRUNCATE_SYM opt_table_sym table_name
5581
lex->sql_command= SQLCOM_TRUNCATE;
5582
lex->select_lex.options= 0;
5583
lex->select_lex.init_order();
5599
lex->lock_option= TL_READ;
5600
mysql_init_select(lex);
5601
lex->current_select->parsing_place= SELECT_LIST;
5602
bzero((char*) &lex->create_info,sizeof(lex->create_info));
5609
DATABASES wild_and_where
5612
lex->sql_command= SQLCOM_SHOW_DATABASES;
5613
if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
5616
| opt_full TABLES opt_db wild_and_where
5619
lex->sql_command= SQLCOM_SHOW_TABLES;
5620
lex->select_lex.db= $3;
5621
if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
5624
| TABLE_SYM STATUS_SYM opt_db wild_and_where
5627
lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
5628
lex->select_lex.db= $3;
5629
if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
5632
| OPEN_SYM TABLES opt_db wild_and_where
5635
lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5636
lex->select_lex.db= $3;
5637
if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
5640
| ENGINE_SYM known_storage_engines show_engine_param
5641
{ Lex->create_info.db_type= $2; }
5642
| ENGINE_SYM ALL show_engine_param
5643
{ Lex->create_info.db_type= NULL; }
5644
| opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
5647
lex->sql_command= SQLCOM_SHOW_FIELDS;
5650
if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
5653
| NEW_SYM MASTER_SYM FOR_SYM SLAVE
5654
WITH MASTER_LOG_FILE_SYM EQ
5655
TEXT_STRING_sys /* $8 */
5656
AND_SYM MASTER_LOG_POS_SYM EQ
5657
ulonglong_num /* $12 */
5658
AND_SYM MASTER_SERVER_ID_SYM EQ
5661
Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
5662
Lex->mi.log_file_name = $8.str;
5664
Lex->mi.server_id = $16;
5666
| master_or_binary LOGS_SYM
5668
Lex->sql_command = SQLCOM_SHOW_BINLOGS;
5672
Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
5674
| BINLOG_SYM EVENTS_SYM binlog_in binlog_from
5677
lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
5678
} opt_limit_clause_init
5679
| keys_or_index from_or_in table_ident opt_db where_clause
5682
lex->sql_command= SQLCOM_SHOW_KEYS;
5685
if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
5688
| COUNT_SYM '(' '*' ')' WARNINGS
5689
{ (void) create_select_for_variable("warning_count"); }
5690
| COUNT_SYM '(' '*' ')' ERRORS
5691
{ (void) create_select_for_variable("error_count"); }
5692
| WARNINGS opt_limit_clause_init
5693
{ Lex->sql_command = SQLCOM_SHOW_WARNS;}
5694
| ERRORS opt_limit_clause_init
5695
{ Lex->sql_command = SQLCOM_SHOW_ERRORS;}
5696
| opt_var_type STATUS_SYM wild_and_where
5699
lex->sql_command= SQLCOM_SHOW_STATUS;
5700
lex->option_type= $1;
5701
if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
5704
| opt_full PROCESSLIST_SYM
5705
{ Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
5706
| opt_var_type VARIABLES wild_and_where
5709
lex->sql_command= SQLCOM_SHOW_VARIABLES;
5710
lex->option_type= $1;
5711
if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
5714
| charset wild_and_where
5717
lex->sql_command= SQLCOM_SHOW_CHARSETS;
5718
if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
5721
| COLLATION_SYM wild_and_where
5724
lex->sql_command= SQLCOM_SHOW_COLLATIONS;
5725
if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
5728
| CREATE DATABASE opt_if_not_exists ident
5730
Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5731
Lex->create_info.options=$3;
5734
| CREATE TABLE_SYM table_ident
5737
lex->sql_command = SQLCOM_SHOW_CREATE;
5738
if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
5740
lex->create_info.default_storage_media= HA_SM_DEFAULT;
5742
| MASTER_SYM STATUS_SYM
5744
Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
5748
Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
5753
{ Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS; }
5755
{ Lex->sql_command= SQLCOM_SHOW_ENGINE_MUTEX; }
5757
{ Lex->sql_command= SQLCOM_SHOW_ENGINE_LOGS; }
5766
/* empty */ { $$= 0; }
5767
| from_or_in ident { $$= $2.str; }
5771
/* empty */ { Lex->verbose=0; }
5772
| FULL { Lex->verbose=1; }
5781
/* empty */ { Lex->mi.log_file_name = 0; }
5782
| IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; }
5786
/* empty */ { Lex->mi.pos = 4; /* skip magic number */ }
5787
| FROM ulonglong_num { Lex->mi.pos = $2; }
5792
| LIKE TEXT_STRING_sys
5794
Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
5795
system_charset_info);
5801
$2->top_level_item();
5805
/* A Oracle compatible synonym for show */
5807
describe_command table_ident
5810
lex->lock_option= TL_READ;
5811
mysql_init_select(lex);
5812
lex->current_select->parsing_place= SELECT_LIST;
5813
lex->sql_command= SQLCOM_SHOW_FIELDS;
5814
lex->select_lex.db= 0;
5816
if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))
5819
opt_describe_column {}
5820
| describe_command opt_extended_describe
5821
{ Lex->describe|= DESCRIBE_NORMAL; }
5825
lex->select_lex.options|= SELECT_DESCRIBE;
5834
opt_extended_describe:
5836
| EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; }
5839
opt_describe_column:
5841
| text_string { Lex->wild= $1; }
5844
Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
5846
system_charset_info);
5854
FLUSH_SYM opt_no_write_to_binlog
5857
lex->sql_command= SQLCOM_FLUSH;
5859
lex->no_write_to_binlog= $2;
5866
flush_options ',' flush_option
5872
{ Lex->type|= REFRESH_TABLES; }
5874
| TABLES WITH READ_SYM LOCK_SYM
5875
{ Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
5876
| QUERY_SYM CACHE_SYM
5877
{ Lex->type|= REFRESH_QUERY_CACHE_FREE; }
5879
{ Lex->type|= REFRESH_HOSTS; }
5881
{ Lex->type|= REFRESH_LOG; }
5883
{ Lex->type|= REFRESH_STATUS; }
5885
{ Lex->type|= REFRESH_SLAVE; }
5887
{ Lex->type|= REFRESH_MASTER; }
5889
{ Lex->type|= REFRESH_DES_KEY_FILE; }
5891
{ Lex->type|= REFRESH_USER_RESOURCES; }
5903
lex->sql_command= SQLCOM_RESET; lex->type=0;
5910
reset_options ',' reset_option
5915
SLAVE { Lex->type|= REFRESH_SLAVE; }
5916
| MASTER_SYM { Lex->type|= REFRESH_MASTER; }
5917
| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;}
5925
lex->sql_command = SQLCOM_PURGE;
5932
master_or_binary LOGS_SYM purge_option
5936
TO_SYM TEXT_STRING_sys
5938
Lex->to_log = $2.str;
5943
lex->value_list.empty();
5944
lex->value_list.push_front($2);
5945
lex->sql_command= SQLCOM_PURGE_BEFORE;
5952
KILL_SYM kill_option expr
5955
lex->value_list.empty();
5956
lex->value_list.push_front($3);
5957
lex->sql_command= SQLCOM_KILL;
5962
/* empty */ { Lex->type= 0; }
5963
| CONNECTION_SYM { Lex->type= 0; }
5964
| QUERY_SYM { Lex->type= ONLY_KILL_QUERY; }
5967
/* change database */
5973
lex->sql_command=SQLCOM_CHANGE_DB;
5974
lex->select_lex.db= $2.str;
5978
/* import, export of files */
5985
Lex_input_stream *lip= thd->m_lip;
5987
lex->fname_start= lip->get_ptr();
5989
load_data_lock opt_local INFILE TEXT_STRING_filesystem
5992
lex->sql_command= SQLCOM_LOAD;
5993
lex->lock_option= $4;
5994
lex->local_file= $5;
5995
lex->duplicates= DUP_ERROR;
5997
if (!(lex->exchange= new sql_exchange($7.str, 0, $2)))
6004
Lex_input_stream *lip= thd->m_lip;
6005
lex->fname_end= lip->get_ptr();
6007
TABLE_SYM table_ident
6010
if (!Select->add_table_to_list(YYTHD, $13, NULL, TL_OPTION_UPDATING,
6013
lex->field_list.empty();
6014
lex->update_list.empty();
6015
lex->value_list.empty();
6017
opt_load_data_charset
6018
{ Lex->exchange->cs= $15; }
6019
opt_xml_rows_identified_by
6020
opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
6021
opt_load_data_set_spec
6026
DATA_SYM { $$= FILETYPE_CSV; }
6027
| XML_SYM { $$= FILETYPE_XML; }
6031
/* empty */ { $$=0;}
6032
| LOCAL_SYM { $$=1;}
6036
/* empty */ { $$= TL_WRITE_DEFAULT; }
6039
$$= TL_WRITE_CONCURRENT_INSERT;
6041
| LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }
6045
/* empty */ { Lex->duplicates=DUP_ERROR; }
6046
| REPLACE { Lex->duplicates=DUP_REPLACE; }
6047
| IGNORE_SYM { Lex->ignore= 1; }
6052
| COLUMNS field_term_list
6056
field_term_list field_term
6061
TERMINATED BY text_string
6063
DBUG_ASSERT(Lex->exchange != 0);
6064
Lex->exchange->field_term= $3;
6066
| OPTIONALLY ENCLOSED BY text_string
6069
DBUG_ASSERT(lex->exchange != 0);
6070
lex->exchange->enclosed= $4;
6071
lex->exchange->opt_enclosed= 1;
6073
| ENCLOSED BY text_string
6075
DBUG_ASSERT(Lex->exchange != 0);
6076
Lex->exchange->enclosed= $3;
6078
| ESCAPED BY text_string
6080
DBUG_ASSERT(Lex->exchange != 0);
6081
Lex->exchange->escaped= $3;
6087
| LINES line_term_list
6091
line_term_list line_term
6096
TERMINATED BY text_string
6098
DBUG_ASSERT(Lex->exchange != 0);
6099
Lex->exchange->line_term= $3;
6101
| STARTING BY text_string
6103
DBUG_ASSERT(Lex->exchange != 0);
6104
Lex->exchange->line_start= $3;
6108
opt_xml_rows_identified_by:
6110
| ROWS_SYM IDENTIFIED_SYM BY text_string
6111
{ Lex->exchange->line_term = $4; };
6115
| IGNORE_SYM NUM lines_or_rows
6117
DBUG_ASSERT(Lex->exchange != 0);
6118
Lex->exchange->skip_lines= atol($2.str);
6127
opt_field_or_var_spec:
6129
| '(' fields_or_vars ')' {}
6134
fields_or_vars ',' field_or_var
6135
{ Lex->field_list.push_back($3); }
6137
{ Lex->field_list.push_back($1); }
6141
simple_ident_nospvar {$$= $1;}
6143
{ $$= new Item_user_var_as_out_param($2); }
6146
opt_load_data_set_spec:
6148
| SET insert_update_list {}
6151
/* Common definitions */
6158
CHARSET_INFO *cs_con= thd->variables.collation_connection;
6159
CHARSET_INFO *cs_cli= thd->variables.character_set_client;
6160
uint repertoire= thd->lex->text_string_is_7bit &&
6161
my_charset_is_ascii_based(cs_cli) ?
6162
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
6163
if (thd->charset_is_collation_connection ||
6164
(repertoire == MY_REPERTOIRE_ASCII &&
6165
my_charset_is_ascii_based(cs_con)))
6168
thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
6169
$$= new Item_string(tmp.str, tmp.length, cs_con,
6170
DERIVATION_COERCIBLE, repertoire);
6174
uint repertoire= Lex->text_string_is_7bit ?
6175
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
6176
DBUG_ASSERT(my_charset_is_ascii_based(national_charset_info));
6177
$$= new Item_string($1.str, $1.length, national_charset_info,
6178
DERIVATION_COERCIBLE, repertoire);
6180
| UNDERSCORE_CHARSET TEXT_STRING
6182
Item_string *str= new Item_string($2.str, $2.length, $1);
6183
str->set_repertoire_from_value();
6184
str->set_cs_specified(TRUE);
6188
| text_literal TEXT_STRING_literal
6190
Item_string* item= (Item_string*) $1;
6191
item->append($2.str, $2.length);
6192
if (!(item->collation.repertoire & MY_REPERTOIRE_EXTENDED))
6195
If the string has been pure ASCII so far,
6198
CHARSET_INFO *cs= YYTHD->variables.collation_connection;
6199
item->collation.repertoire|= my_string_repertoire(cs,
6209
$$= new (YYTHD->mem_root) String($1.str,
6211
YYTHD->variables.collation_connection);
6215
Item *tmp= new Item_hex_string($1.str, $1.length);
6217
it is OK only emulate fix_fields, because we need only
6221
tmp->quick_fix_field(), tmp->val_str((String*) 0) :
6226
Item *tmp= new Item_bin_string($1.str, $1.length);
6228
it is OK only emulate fix_fields, because we need only
6231
$$= tmp ? tmp->quick_fix_field(), tmp->val_str((String*) 0) :
6241
Lex_input_stream *lip= thd->m_lip;
6243
if (! lex->parsing_options.allows_variable)
6245
my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
6248
item= new Item_param((uint) (lip->get_tok_start() - thd->query));
6249
if (!($$= item) || lex->param_list.push_back(item))
6251
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
6258
literal { $$ = $1; }
6259
| '+' NUM_literal { $$ = $2; }
6268
text_literal { $$ = $1; }
6269
| NUM_literal { $$ = $1; }
6272
$$ = new Item_null();
6273
YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
6275
| FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
6276
| TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
6277
| HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
6278
| BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
6279
| UNDERSCORE_CHARSET HEX_NUM
6281
Item *tmp= new Item_hex_string($2.str, $2.length);
6283
it is OK only emulate fix_fieds, because we need only
6287
tmp->quick_fix_field(), tmp->val_str((String*) 0) :
6290
Item_string *item_str=
6291
new Item_string(NULL, /* name will be set in select_item */
6292
str ? str->ptr() : "",
6293
str ? str->length() : 0,
6296
!item_str->check_well_formed_result(&item_str->str_value, TRUE))
6301
item_str->set_repertoire_from_value();
6302
item_str->set_cs_specified(TRUE);
6306
| UNDERSCORE_CHARSET BIN_NUM
6308
Item *tmp= new Item_bin_string($2.str, $2.length);
6310
it is OK only emulate fix_fieds, because we need only
6314
tmp->quick_fix_field(), tmp->val_str((String*) 0) :
6317
Item_string *item_str=
6318
new Item_string(NULL, /* name will be set in select_item */
6319
str ? str->ptr() : "",
6320
str ? str->length() : 0,
6323
!item_str->check_well_formed_result(&item_str->str_value, TRUE))
6328
item_str->set_cs_specified(TRUE);
6332
| DATE_SYM text_literal { $$ = $2; }
6333
| TIME_SYM text_literal { $$ = $2; }
6334
| TIMESTAMP text_literal { $$ = $2; }
6341
$$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length);
6346
$$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length);
6349
{ $$ = new Item_uint($1.str, $1.length); }
6352
$$= new Item_decimal($1.str, $1.length, YYTHD->charset());
6353
if (YYTHD->is_error())
6360
$$ = new Item_float($1.str, $1.length);
6361
if (YYTHD->is_error())
6368
/**********************************************************************
6369
** Creating different items.
6370
**********************************************************************/
6373
simple_ident_nospvar { $$=$1; }
6374
| table_wild { $$=$1; }
6380
SELECT_LEX *sel= Select;
6381
$$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
6384
| ident '.' ident '.' '*'
6386
SELECT_LEX *sel= Select;
6387
$$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
6388
CLIENT_NO_SCHEMA ? NullS : $1.str),
6402
SELECT_LEX *sel=Select;
6403
$$= (sel->parsing_place != IN_HAVING ||
6404
sel->get_in_sum_expr() > 0) ?
6405
(Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
6406
(Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
6409
| simple_ident_q { $$= $1; }
6412
simple_ident_nospvar:
6415
SELECT_LEX *sel=Select;
6416
$$= (sel->parsing_place != IN_HAVING ||
6417
sel->get_in_sum_expr() > 0) ?
6418
(Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
6419
(Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
6421
| simple_ident_q { $$= $1; }
6431
SELECT_LEX *sel= lex->current_select;
6432
if (sel->no_table_names_allowed)
6434
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6435
MYF(0), $1.str, thd->where);
6437
$$= (sel->parsing_place != IN_HAVING ||
6438
sel->get_in_sum_expr() > 0) ?
6439
(Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
6440
(Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
6443
| '.' ident '.' ident
6447
SELECT_LEX *sel= lex->current_select;
6448
if (sel->no_table_names_allowed)
6450
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6451
MYF(0), $2.str, thd->where);
6453
$$= (sel->parsing_place != IN_HAVING ||
6454
sel->get_in_sum_expr() > 0) ?
6455
(Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
6456
(Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
6458
| ident '.' ident '.' ident
6462
SELECT_LEX *sel= lex->current_select;
6463
if (sel->no_table_names_allowed)
6465
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6466
MYF(0), $3.str, thd->where);
6468
$$= (sel->parsing_place != IN_HAVING ||
6469
sel->get_in_sum_expr() > 0) ?
6470
(Item*) new Item_field(Lex->current_context(),
6471
(YYTHD->client_capabilities &
6472
CLIENT_NO_SCHEMA ? NullS : $1.str),
6474
(Item*) new Item_ref(Lex->current_context(),
6475
(YYTHD->client_capabilities &
6476
CLIENT_NO_SCHEMA ? NullS : $1.str),
6483
| ident '.' ident '.' ident
6485
TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
6486
if (my_strcasecmp(table_alias_charset, $1.str, table->db))
6488
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
6491
if (my_strcasecmp(table_alias_charset, $3.str,
6494
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
6501
TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
6502
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
6504
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
6509
| '.' ident { $$=$2;} /* For Delphi */
6513
ident { $$=new Table_ident($1); }
6514
| ident '.' ident { $$=new Table_ident(YYTHD, $1,$3,0);}
6515
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
6524
if (thd->charset_is_system_charset)
6526
CHARSET_INFO *cs= system_charset_info;
6528
uint wlen= cs->cset->well_formed_len(cs, $1.str,
6530
$1.length, &dummy_error);
6531
if (wlen < $1.length)
6533
my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
6534
cs->csname, $1.str + wlen);
6540
thd->convert_string(&$$, system_charset_info,
6541
$1.str, $1.length, thd->charset());
6550
if (thd->charset_is_system_charset)
6553
thd->convert_string(&$$, system_charset_info,
6554
$1.str, $1.length, thd->charset());
6558
TEXT_STRING_literal:
6563
if (thd->charset_is_collation_connection)
6566
thd->convert_string(&$$, thd->variables.collation_connection,
6567
$1.str, $1.length, thd->charset());
6571
TEXT_STRING_filesystem:
6576
if (thd->charset_is_character_set_filesystem)
6579
thd->convert_string(&$$, thd->variables.character_set_filesystem,
6580
$1.str, $1.length, thd->charset());
6585
IDENT_sys { $$=$1; }
6589
$$.str= thd->strmake($1.str, $1.length);
6590
$$.length= $1.length;
6596
| TEXT_STRING_sys { $$=$1;}
6597
| LEX_HOSTNAME { $$=$1;}
6600
/* Keyword that we allow for identifiers (except SP labels) */
6644
* Keywords that we allow for labels in SPs.
6645
* Anything that's the beginning of a statement or characteristics
6646
* must be in keyword above, otherwise we get (harmful) shift/reduce
6659
| AUTOEXTEND_SIZE_SYM {}
6676
| COLUMN_FORMAT_SYM {}
6686
| CONTRIBUTORS_SYM {}
6695
| DELAY_KEY_WRITE_SYM {}
6714
| EXTENT_SIZE_SYM {}
6723
| FRAC_SECOND_SYM {}
6732
| INITIAL_SIZE_SYM {}
6750
| MASTER_HOST_SYM {}
6751
| MASTER_PORT_SYM {}
6752
| MASTER_LOG_FILE_SYM {}
6753
| MASTER_LOG_POS_SYM {}
6754
| MASTER_USER_SYM {}
6755
| MASTER_PASSWORD_SYM {}
6756
| MASTER_SERVER_ID_SYM {}
6757
| MASTER_CONNECT_RETRY_SYM {}
6758
| MAX_CONNECTIONS_PER_HOUR {}
6759
| MAX_QUERIES_PER_HOUR {}
6761
| MAX_UPDATES_PER_HOUR {}
6762
| MAX_USER_CONNECTIONS_SYM {}
6767
| MICROSECOND_SYM {}
6794
| PAGE_CHECKSUM_SYM {}
6803
| PROCESSLIST_SYM {}
6812
| REDO_BUFFER_SIZE_SYM {}
6815
| RELAY_LOG_FILE_SYM {}
6816
| RELAY_LOG_POS_SYM {}
6833
| SERIALIZABLE_SYM {}
6840
| SQL_BUFFER_RESULT {}
6853
| TABLE_CHECKSUM_SYM {}
6859
| TRANSACTION_SYM {}
6860
| TRANSACTIONAL_SYM {}
6867
| UDF_RETURNS_SYM {}
6869
| UNCOMMITTED_SYM {}
6871
| UNDO_BUFFER_SIZE_SYM {}
6882
| WEIGHT_STRING_SYM {}
6888
/* Option functions */
6894
lex->sql_command= SQLCOM_SET_OPTION;
6895
mysql_init_select(lex);
6896
lex->option_type=OPT_SESSION;
6897
lex->var_list.empty();
6898
lex->one_shot_set= 0;
6912
| option_value_list ',' option_type_value
6925
| GLOBAL_SYM { $$=OPT_GLOBAL; }
6926
| LOCAL_SYM { $$=OPT_SESSION; }
6927
| SESSION_SYM { $$=OPT_SESSION; }
6931
/* empty */ { $$= OPT_DEFAULT; }
6932
| ONE_SHOT_SYM { Lex->one_shot_set= 1; $$= OPT_SESSION; }
6936
/* empty */ { $$=OPT_SESSION; }
6937
| GLOBAL_SYM { $$=OPT_GLOBAL; }
6938
| LOCAL_SYM { $$=OPT_SESSION; }
6939
| SESSION_SYM { $$=OPT_SESSION; }
6943
/* empty */ { $$=OPT_DEFAULT; }
6944
| GLOBAL_SYM '.' { $$=OPT_GLOBAL; }
6945
| LOCAL_SYM '.' { $$=OPT_SESSION; }
6946
| SESSION_SYM '.' { $$=OPT_SESSION; }
6951
| option_type2 option_value
6955
option_type internal_variable_name equal set_expr_or_default
6960
{ /* System variable */
6962
lex->option_type= $1;
6963
lex->var_list.push_back(new set_var(lex->option_type, $2.var,
6964
&$2.base_name, $4));
6967
| option_type TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
6970
lex->option_type= $1;
6971
lex->var_list.push_back(new set_var(lex->option_type,
6972
find_sys_var(YYTHD, "tx_isolation"),
6974
new Item_int((int32) $5)));
6979
'@' ident_or_text equal expr
6981
Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
6983
| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6986
lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
6988
| charset old_or_new_charset_name_or_default
6992
$2= $2 ? $2: global_system_variables.character_set_client;
6993
lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
6995
| NAMES_SYM charset_name_or_default opt_collate
6998
$2= $2 ? $2 : global_system_variables.character_set_client;
7000
if (!my_charset_same($2,$3))
7002
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
7003
$3->name, $2->csname);
7006
lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
7010
internal_variable_name:
7015
/* We have to lookup here since local vars can shadow sysvars */
7017
/* Not an SP local variable */
7018
sys_var *tmp=find_sys_var(thd, $1.str, $1.length);
7022
$$.base_name= null_lex_str;
7027
if (check_reserved_words(&$1))
7029
my_parse_error(ER(ER_SYNTAX_ERROR));
7033
sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
7036
if (!tmp->is_struct())
7037
my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
7044
sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
7047
if (!tmp->is_struct())
7048
my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str);
7050
$$.base_name.str= (char*) "default";
7051
$$.base_name.length= 7;
7056
READ_SYM UNCOMMITTED_SYM { $$= ISO_READ_UNCOMMITTED; }
7057
| READ_SYM COMMITTED_SYM { $$= ISO_READ_COMMITTED; }
7058
| REPEATABLE_SYM READ_SYM { $$= ISO_REPEATABLE_READ; }
7059
| SERIALIZABLE_SYM { $$= ISO_SERIALIZABLE; }
7062
set_expr_or_default:
7065
| ON { $$=new Item_string("ON", 2, system_charset_info); }
7066
| ALL { $$=new Item_string("ALL", 3, system_charset_info); }
7067
| BINARY { $$=new Item_string("binary", 6, system_charset_info); }
7076
Transactional locks can be taken only if all requested locks
7077
are transactional. Initialize lex->lock_transactional as
7078
TRUE. Any non-transactional lock request turns this to FALSE.
7079
Table specific variables keep track of the locking method
7080
requested for the table. This is used to warn about a
7081
changed locking method later.
7083
Lex->lock_transactional= TRUE;
7088
lex->sql_command= SQLCOM_LOCK_TABLES;
7101
| table_lock_list ',' table_lock
7105
table_ident opt_table_alias table_lock_info
7108
if (!(tlist= Select->add_table_to_list(YYTHD, $1, $2, 0,
7110
MYSQL_YYABORT; /* purecov: inspected */
7111
tlist->lock_timeout= $3.lock_timeout;
7112
/* Store the requested lock method for later warning. */
7113
tlist->lock_transactional= $3.lock_transactional;
7114
/* Compute the resulting lock method for all tables. */
7115
if (!$3.lock_transactional)
7116
Lex->lock_transactional= FALSE;
7123
$$.lock_type= TL_READ_NO_INSERT;
7124
$$.lock_timeout= -1;
7125
$$.lock_transactional= FALSE;
7129
$$.lock_type= TL_WRITE_DEFAULT;
7130
$$.lock_timeout= -1;
7131
$$.lock_transactional= FALSE;
7133
| LOW_PRIORITY WRITE_SYM
7135
$$.lock_type= TL_WRITE_LOW_PRIORITY;
7136
$$.lock_timeout= -1;
7137
$$.lock_transactional= FALSE;
7139
| READ_SYM LOCAL_SYM
7141
$$.lock_type= TL_READ;
7142
$$.lock_timeout= -1;
7143
$$.lock_transactional= FALSE;
7145
| IN_SYM transactional_lock_mode MODE_SYM opt_transactional_lock_timeout
7148
$$.lock_timeout= $4;
7149
$$.lock_transactional= TRUE;
7153
/* Use thr_lock_type here for easier fallback to non-trans locking. */
7154
transactional_lock_mode:
7155
SHARE_SYM { $$= TL_READ_NO_INSERT; }
7156
| EXCLUSIVE_SYM { $$= TL_WRITE_DEFAULT; }
7159
opt_transactional_lock_timeout:
7160
/* empty */ { $$= -1; }
7161
| NOWAIT_SYM { $$= 0; }
7162
/* | WAIT_SYM opt_lock_timeout_value { $$= $2; } */
7166
We have a timeout resolution of milliseconds. The WAIT argument is in
7167
seconds with decimal fragments for sub-second resolution. E.g. 22.5, 0.015
7169
/* opt_lock_timeout_value: */
7170
/* empty { $$= -1; } */
7171
/* | NUM { $$= (int) (atof($1.str) * 1000.0 + 0.5); } */
7177
lex->sql_command= SQLCOM_UNLOCK_TABLES;
7187
lex->sql_command = SQLCOM_BEGIN;
7188
lex->start_transaction_opt= 0;
7200
{ $$= (YYTHD->variables.completion_type == 1); }
7201
| AND_SYM NO_SYM CHAIN_SYM { $$=0; }
7202
| AND_SYM CHAIN_SYM { $$=1; }
7207
{ $$= (YYTHD->variables.completion_type == 2); }
7208
| RELEASE_SYM { $$=1; }
7209
| NO_SYM RELEASE_SYM { $$=0; }
7218
COMMIT_SYM opt_work opt_chain opt_release
7221
lex->sql_command= SQLCOM_COMMIT;
7223
lex->tx_release= $4;
7228
ROLLBACK_SYM opt_work opt_chain opt_release
7231
lex->sql_command= SQLCOM_ROLLBACK;
7233
lex->tx_release= $4;
7235
| ROLLBACK_SYM opt_work
7236
TO_SYM opt_savepoint ident
7239
lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
7248
lex->sql_command= SQLCOM_SAVEPOINT;
7254
RELEASE_SYM SAVEPOINT_SYM ident
7257
lex->sql_command= SQLCOM_RELEASE_SAVEPOINT;
7263
UNIONS : glue selects together
7273
UNION_SYM union_option
7275
if (add_select_to_union_list(Lex, (bool)$2))
7281
Remove from the name resolution context stack the context of the
7282
last select in the union.
7289
/* Empty */ { $$= 0; }
7290
| union_list { $$= 1; }
7291
| union_order_or_limit { $$= 1; }
7294
union_order_or_limit:
7298
DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
7299
SELECT_LEX *sel= lex->current_select;
7300
SELECT_LEX_UNIT *unit= sel->master_unit();
7301
SELECT_LEX *fake= unit->fake_select_lex;
7304
unit->global_parameters= fake;
7305
fake->no_table_names_allowed= 1;
7306
lex->current_select= fake;
7308
thd->where= "global ORDER clause";
7313
thd->lex->current_select->no_table_names_allowed= 0;
7319
order_clause opt_limit_clause_init
7324
/* empty */ { $$=1; }
7325
| DISTINCT { $$=1; }
7329
query_specification:
7330
SELECT_SYM select_init2_derived
7332
$$= Lex->current_select->master_unit()->first_select();
7334
| '(' select_paren_derived ')'
7336
$$= Lex->current_select->master_unit()->first_select();
7340
query_expression_body:
7342
| query_expression_body
7343
UNION_SYM union_option
7345
if (add_select_to_union_list(Lex, (bool)$3))
7355
/* Corresponds to <query expression> in the SQL:2003 standard. */
7357
subselect_start query_expression_body subselect_end
7366
if (!lex->expr_allows_subselect ||
7367
lex->sql_command == (int)SQLCOM_PURGE)
7369
my_parse_error(ER(ER_SYNTAX_ERROR));
7373
we are making a "derived table" for the parenthesis
7374
as we need to have a lex level to fit the union
7375
after the parenthesis, e.g.
7376
(SELECT .. ) UNION ... becomes
7377
SELECT * FROM ((SELECT ...) UNION ...)
7379
if (mysql_new_select(Lex, 1))
7388
SELECT_LEX *child= lex->current_select;
7389
lex->current_select = lex->current_select->return_after_parsing();
7391
lex->current_select->n_child_sum_items += child->n_sum_items;
7393
A subselect can add fields to an outer select. Reserve space for
7396
lex->current_select->select_n_where_fields+=
7397
child->select_n_where_fields;
7401
@} (end of group Parser)