sql_yacc.yy 136 KB
Newer Older
1
/* Copyright (C) 2000-2003 MySQL AB
2

unknown's avatar
unknown committed
3 4 5 6
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
7

unknown's avatar
unknown committed
8 9 10 11
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
12

unknown's avatar
unknown committed
13 14 15 16
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

unknown's avatar
unknown committed
17
/* sql_yacc.yy */
unknown's avatar
unknown committed
18 19

%{
20 21 22
/* thd is passed as an arg to yyparse(), and subsequently to yylex().
** The type will be void*, so it must be  cast to (THD*) when used.
** Use the YYTHD macro for this.
23 24
*/
#define YYPARSE_PARAM yythd
25
#define YYLEX_PARAM yythd
26 27
#define YYTHD ((THD *)yythd)

unknown's avatar
unknown committed
28 29 30
#define MYSQL_YACC
#define YYINITDEPTH 100
#define YYMAXDEPTH 3200				/* Because of 64K stack */
31
#define Lex (&(YYTHD->lex))
32
#define Select Lex->current_select
unknown's avatar
unknown committed
33
#include "mysql_priv.h"
unknown's avatar
unknown committed
34
#include "slave.h"
unknown's avatar
unknown committed
35 36
#include "sql_acl.h"
#include "lex_symbol.h"
37
#include "item_create.h"
unknown's avatar
unknown committed
38
#include <myisam.h>
39
#include <myisammrg.h>
40

41
int yylex(void *yylval, void *yythd);
unknown's avatar
unknown committed
42

unknown's avatar
unknown committed
43
#define yyoverflow(A,B,C,D,E,F) if (my_yyoverflow((B),(D),(int*) (F))) { yyerror((char*) (A)); return 2; }
unknown's avatar
unknown committed
44

45
inline Item *or_or_concat(THD *thd, Item* A, Item* B)
unknown's avatar
unknown committed
46
{
47
  return (thd->variables.sql_mode & MODE_PIPES_AS_CONCAT ?
unknown's avatar
unknown committed
48 49 50 51 52 53 54
          (Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B));
}

%}
%union {
  int  num;
  ulong ulong_num;
unknown's avatar
unknown committed
55
  ulonglong ulonglong_number;
unknown's avatar
unknown committed
56 57 58 59 60 61 62 63
  LEX_STRING lex_str;
  LEX_STRING *lex_str_ptr;
  LEX_SYMBOL symbol;
  Table_ident *table;
  char *simple_string;
  Item *item;
  List<Item> *item_list;
  List<String> *string_list;
unknown's avatar
unknown committed
64 65 66 67 68
  String *string;
  key_part_spec *key_part;
  TABLE_LIST *table_list;
  udf_func *udf;
  LEX_USER *lex_user;
unknown's avatar
unknown committed
69
  struct sys_var_with_base variable;
unknown's avatar
unknown committed
70
  Key::Keytype key_type;
unknown's avatar
unknown committed
71
  enum ha_key_alg key_alg;
unknown's avatar
unknown committed
72 73
  enum db_type db_type;
  enum row_type row_type;
unknown's avatar
unknown committed
74
  enum ha_rkey_function ha_rkey_mode;
unknown's avatar
unknown committed
75
  enum enum_tx_isolation tx_isolation;
76
  enum Cast_target cast_type;
unknown's avatar
unknown committed
77
  enum Item_udftype udf_type;
78
  CHARSET_INFO *charset;
unknown's avatar
unknown committed
79
  thr_lock_type lock_type;
unknown's avatar
unknown committed
80
  interval_type interval;
81
  timestamp_type date_time_type;
unknown's avatar
unknown committed
82
  st_select_lex *select_lex;
unknown's avatar
unknown committed
83
  chooser_compare_func_creator boolfunc2creator;
unknown's avatar
unknown committed
84 85 86 87 88 89 90 91 92 93
}

%{
bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%}

%pure_parser					/* We have threads */

%token	END_OF_INPUT

94 95 96 97 98 99
%token CLOSE_SYM
%token HANDLER_SYM
%token LAST_SYM
%token NEXT_SYM
%token PREV_SYM

100
%token	DIV_SYM
unknown's avatar
unknown committed
101 102
%token	EQ
%token	EQUAL_SYM
unknown's avatar
unknown committed
103
%token	SOUNDS_SYM
unknown's avatar
unknown committed
104 105 106 107 108 109
%token	GE
%token	GT_SYM
%token	LE
%token	LT
%token	NE
%token	IS
110
%token	MOD_SYM
unknown's avatar
unknown committed
111 112 113 114
%token	SHIFT_LEFT
%token	SHIFT_RIGHT
%token  SET_VAR

unknown's avatar
unknown committed
115
%token	ABORT_SYM
unknown's avatar
unknown committed
116 117
%token	ADD
%token	AFTER_SYM
unknown's avatar
unknown committed
118 119
%token	ALTER
%token	ANALYZE_SYM
unknown's avatar
unknown committed
120
%token	ANY_SYM
unknown's avatar
unknown committed
121 122 123
%token	AVG_SYM
%token	BEGIN_SYM
%token	BINLOG_SYM
unknown's avatar
unknown committed
124
%token	CHANGE
unknown's avatar
unknown committed
125 126 127 128
%token	CLIENT_SYM
%token	COMMENT_SYM
%token	COMMIT_SYM
%token	COUNT_SYM
unknown's avatar
unknown committed
129 130
%token	CREATE
%token	CROSS
131
%token  CUBE_SYM
unknown's avatar
unknown committed
132
%token	DELETE_SYM
133
%token	DUAL_SYM
unknown's avatar
unknown committed
134
%token	DO_SYM
unknown's avatar
unknown committed
135
%token	DROP
unknown's avatar
unknown committed
136 137
%token	EVENTS_SYM
%token	EXECUTE_SYM
138
%token	EXPANSION_SYM
unknown's avatar
unknown committed
139
%token	FLUSH_SYM
140
%token  HELP_SYM
unknown's avatar
unknown committed
141
%token	INSERT
unknown's avatar
unknown committed
142
%token	RELAY_THREAD
unknown's avatar
unknown committed
143 144
%token	KILL_SYM
%token	LOAD
unknown's avatar
unknown committed
145
%token	LOCKS_SYM
unknown's avatar
unknown committed
146 147 148 149
%token	LOCK_SYM
%token	MASTER_SYM
%token	MAX_SYM
%token	MIN_SYM
150
%token	NONE_SYM
unknown's avatar
unknown committed
151 152 153 154 155 156
%token	OPTIMIZE
%token	PURGE
%token	REPAIR
%token	REPLICATION
%token	RESET_SYM
%token	ROLLBACK_SYM
157
%token  ROLLUP_SYM
158
%token	SAVEPOINT_SYM
unknown's avatar
unknown committed
159 160 161 162 163 164
%token	SELECT_SYM
%token	SHOW
%token	SLAVE
%token	SQL_THREAD
%token	START_SYM
%token	STD_SYM
unknown's avatar
unknown committed
165
%token  VARIANCE_SYM
unknown's avatar
unknown committed
166 167
%token	STOP_SYM
%token	SUM_SYM
unknown's avatar
unknown committed
168
%token	ADDDATE_SYM
unknown's avatar
unknown committed
169 170
%token	SUPER_SYM
%token	TRUNCATE_SYM
unknown's avatar
unknown committed
171
%token	UNLOCK_SYM
172
%token	UNTIL_SYM
unknown's avatar
unknown committed
173
%token	UPDATE_SYM
unknown's avatar
unknown committed
174 175 176 177 178 179 180

%token	ACTION
%token	AGGREGATE_SYM
%token	ALL
%token	AND
%token	AS
%token	ASC
181
%token	AUTO_INC
unknown's avatar
unknown committed
182
%token	AVG_ROW_LENGTH
unknown's avatar
unknown committed
183
%token	BACKUP_SYM
unknown's avatar
unknown committed
184 185 186 187
%token	BERKELEY_DB_SYM
%token	BINARY
%token	BIT_SYM
%token	BOOL_SYM
unknown's avatar
unknown committed
188
%token	BOOLEAN_SYM
unknown's avatar
unknown committed
189
%token	BOTH
unknown's avatar
unknown committed
190
%token	BTREE_SYM
unknown's avatar
unknown committed
191
%token	BY
192
%token	BYTE_SYM
unknown's avatar
unknown committed
193
%token	CACHE_SYM
unknown's avatar
unknown committed
194
%token	CASCADE
unknown's avatar
unknown committed
195
%token	CAST_SYM
196
%token	CHARSET
unknown's avatar
unknown committed
197 198
%token	CHECKSUM_SYM
%token	CHECK_SYM
unknown's avatar
unknown committed
199
%token	COMMITTED_SYM
unknown's avatar
unknown committed
200
%token	COLLATE_SYM
unknown's avatar
unknown committed
201
%token	COLLATION_SYM
unknown's avatar
unknown committed
202 203
%token	COLUMNS
%token	COLUMN_SYM
unknown's avatar
unknown committed
204
%token	CONCURRENT
unknown's avatar
unknown committed
205
%token	CONSTRAINT
unknown's avatar
unknown committed
206
%token	CONVERT_SYM
unknown's avatar
unknown committed
207 208 209 210 211 212 213
%token	DATABASES
%token	DATA_SYM
%token	DEFAULT
%token	DELAYED_SYM
%token	DELAY_KEY_WRITE_SYM
%token	DESC
%token	DESCRIBE
unknown's avatar
unknown committed
214
%token	DES_KEY_FILE
215
%token	DISABLE_SYM
unknown's avatar
unknown committed
216
%token	DISCARD
unknown's avatar
unknown committed
217
%token	DISTINCT
unknown's avatar
unknown committed
218
%token  DUPLICATE_SYM
unknown's avatar
unknown committed
219
%token	DYNAMIC_SYM
220
%token	ENABLE_SYM
unknown's avatar
unknown committed
221 222
%token	ENCLOSED
%token	ESCAPED
unknown's avatar
unknown committed
223
%token	DIRECTORY_SYM
unknown's avatar
unknown committed
224 225 226
%token	ESCAPE_SYM
%token	EXISTS
%token	EXTENDED_SYM
227
%token	FALSE_SYM
unknown's avatar
unknown committed
228 229 230 231
%token	FILE_SYM
%token	FIRST_SYM
%token	FIXED_SYM
%token	FLOAT_NUM
232
%token	FORCE_SYM
unknown's avatar
unknown committed
233 234 235
%token	FOREIGN
%token	FROM
%token	FULL
unknown's avatar
unknown committed
236 237
%token	FULLTEXT_SYM
%token	GLOBAL_SYM
unknown's avatar
unknown committed
238 239 240 241 242
%token	GRANT
%token	GRANTS
%token	GREATEST_SYM
%token	GROUP
%token	HAVING
unknown's avatar
unknown committed
243
%token	HASH_SYM
unknown's avatar
unknown committed
244 245 246 247
%token	HEX_NUM
%token	HIGH_PRIORITY
%token	HOSTS_SYM
%token	IDENT
248
%token	IDENT_QUOTED
unknown's avatar
unknown committed
249
%token	IGNORE_SYM
unknown's avatar
unknown committed
250
%token	IMPORT
unknown's avatar
unknown committed
251
%token	INDEX
unknown's avatar
unknown committed
252
%token	INDEXES
unknown's avatar
unknown committed
253 254
%token	INFILE
%token	INNER_SYM
unknown's avatar
unknown committed
255
%token	INNOBASE_SYM
unknown's avatar
unknown committed
256 257
%token	INTO
%token	IN_SYM
unknown's avatar
unknown committed
258
%token	ISOLATION
unknown's avatar
unknown committed
259 260 261 262 263
%token	JOIN_SYM
%token	KEYS
%token	KEY_SYM
%token	LEADING
%token	LEAST_SYM
unknown's avatar
unknown committed
264
%token	LEAVES
unknown's avatar
unknown committed
265
%token	LEVEL_SYM
unknown's avatar
unknown committed
266 267 268 269
%token	LEX_HOSTNAME
%token	LIKE
%token	LINES
%token	LOCAL_SYM
270
%token	LOG_SYM
unknown's avatar
unknown committed
271 272 273 274
%token	LOGS_SYM
%token	LONG_NUM
%token	LONG_SYM
%token	LOW_PRIORITY
unknown's avatar
unknown committed
275 276 277 278 279 280 281 282
%token	MASTER_HOST_SYM
%token	MASTER_USER_SYM
%token	MASTER_LOG_FILE_SYM
%token	MASTER_LOG_POS_SYM
%token	MASTER_PASSWORD_SYM
%token	MASTER_PORT_SYM
%token	MASTER_CONNECT_RETRY_SYM
%token	MASTER_SERVER_ID_SYM
unknown's avatar
unknown committed
283 284 285 286 287 288
%token	MASTER_SSL_SYM
%token	MASTER_SSL_CA_SYM
%token	MASTER_SSL_CAPATH_SYM
%token	MASTER_SSL_CERT_SYM
%token	MASTER_SSL_CIPHER_SYM
%token	MASTER_SSL_KEY_SYM
unknown's avatar
unknown committed
289 290
%token	RELAY_LOG_FILE_SYM
%token	RELAY_LOG_POS_SYM
unknown's avatar
unknown committed
291 292
%token	MATCH
%token	MAX_ROWS
unknown's avatar
unknown committed
293 294 295
%token	MAX_CONNECTIONS_PER_HOUR
%token	MAX_QUERIES_PER_HOUR
%token	MAX_UPDATES_PER_HOUR
296
%token	MEDIUM_SYM
unknown's avatar
unknown committed
297
%token	MIN_ROWS
unknown's avatar
unknown committed
298
%token	NAMES_SYM
unknown's avatar
unknown committed
299 300
%token	NATIONAL_SYM
%token	NATURAL
unknown's avatar
unknown committed
301
%token	NEW_SYM
unknown's avatar
unknown committed
302
%token	NCHAR_SYM
unknown's avatar
unknown committed
303
%token	NCHAR_STRING
unknown's avatar
unknown committed
304
%token  NVARCHAR_SYM
unknown's avatar
unknown committed
305 306 307 308
%token	NOT
%token	NO_SYM
%token	NULL_SYM
%token	NUM
unknown's avatar
unknown committed
309
%token	OFFSET_SYM
unknown's avatar
unknown committed
310
%token	ON
311
%token	OPEN_SYM
unknown's avatar
unknown committed
312 313 314
%token	OPTION
%token	OPTIONALLY
%token	OR
315
%token	OR_OR_CONCAT
unknown's avatar
unknown committed
316 317 318
%token	ORDER_SYM
%token	OUTER
%token	OUTFILE
unknown's avatar
unknown committed
319
%token	DUMPFILE
unknown's avatar
unknown committed
320 321 322 323 324 325
%token	PACK_KEYS_SYM
%token	PARTIAL
%token	PRIMARY_SYM
%token	PRIVILEGES
%token	PROCESS
%token	PROCESSLIST_SYM
unknown's avatar
unknown committed
326
%token	QUERY_SYM
unknown's avatar
unknown committed
327
%token	RAID_0_SYM
328 329
%token	RAID_STRIPED_SYM
%token	RAID_TYPE
unknown's avatar
unknown committed
330 331 332 333 334 335 336 337
%token	RAID_CHUNKS
%token	RAID_CHUNKSIZE
%token	READ_SYM
%token	REAL_NUM
%token	REFERENCES
%token	REGEXP
%token	RELOAD
%token	RENAME
unknown's avatar
unknown committed
338
%token	REPEATABLE_SYM
unknown's avatar
unknown committed
339
%token	REQUIRE_SYM
unknown's avatar
unknown committed
340 341
%token	RESOURCES
%token	RESTORE_SYM
unknown's avatar
unknown committed
342 343 344 345 346
%token	RESTRICT
%token	REVOKE
%token	ROWS_SYM
%token	ROW_FORMAT_SYM
%token	ROW_SYM
unknown's avatar
unknown committed
347
%token	RTREE_SYM
unknown's avatar
unknown committed
348
%token	SET
349
%token  SEPARATOR_SYM
350
%token	SERIAL_SYM
unknown's avatar
unknown committed
351 352
%token	SERIALIZABLE_SYM
%token	SESSION_SYM
353
%token	SIMPLE_SYM
unknown's avatar
unknown committed
354
%token	SHUTDOWN
unknown's avatar
unknown committed
355
%token	SPATIAL_SYM
356
%token  SSL_SYM
unknown's avatar
unknown committed
357 358 359
%token	STARTING
%token	STATUS_SYM
%token	STRAIGHT_JOIN
unknown's avatar
unknown committed
360
%token	SUBJECT_SYM
unknown's avatar
unknown committed
361 362
%token	TABLES
%token	TABLE_SYM
unknown's avatar
unknown committed
363
%token	TABLESPACE
unknown's avatar
unknown committed
364 365 366
%token	TEMPORARY
%token	TERMINATED
%token	TEXT_STRING
367 368 369
%token	TO_SYM
%token	TRAILING
%token	TRANSACTION_SYM
370
%token	TRUE_SYM
371
%token	TYPE_SYM
unknown's avatar
unknown committed
372
%token  TYPES_SYM
unknown's avatar
unknown committed
373 374 375 376
%token	FUNC_ARG0
%token	FUNC_ARG1
%token	FUNC_ARG2
%token	FUNC_ARG3
377 378 379
%token	UDF_RETURNS_SYM
%token	UDF_SONAME_SYM
%token	UDF_SYM
unknown's avatar
unknown committed
380
%token	UNCOMMITTED_SYM
381
%token	UNDERSCORE_CHARSET
unknown's avatar
unknown committed
382
%token	UNICODE_SYM
383 384 385
%token	UNION_SYM
%token	UNIQUE_SYM
%token	USAGE
unknown's avatar
unknown committed
386
%token	USE_FRM
387 388
%token	USE_SYM
%token	USING
389
%token	VALUE_SYM
390
%token	VALUES
unknown's avatar
unknown committed
391 392 393 394
%token	VARIABLES
%token	WHERE
%token	WITH
%token	WRITE_SYM
395
%token  NO_WRITE_TO_BINLOG
unknown's avatar
unknown committed
396
%token	X509_SYM
unknown's avatar
unknown committed
397
%token	XOR
unknown's avatar
unknown committed
398
%token	COMPRESSED_SYM
unknown's avatar
unknown committed
399

unknown's avatar
unknown committed
400 401 402
%token  ERRORS
%token  WARNINGS

unknown's avatar
unknown committed
403
%token	ASCII_SYM
unknown's avatar
unknown committed
404 405 406
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
unknown's avatar
unknown committed
407
%token	CHANGED
unknown's avatar
unknown committed
408 409 410 411 412 413
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
414
%token	FAST_SYM
unknown's avatar
unknown committed
415
%token	FLOAT_SYM
unknown's avatar
unknown committed
416
%token  GEOMETRY_SYM
unknown's avatar
unknown committed
417 418 419 420 421 422 423 424 425
%token	INT_SYM
%token	LIMIT
%token	LONGBLOB
%token	LONGTEXT
%token	MEDIUMBLOB
%token	MEDIUMINT
%token	MEDIUMTEXT
%token	NUMERIC_SYM
%token	PRECISION
unknown's avatar
unknown committed
426
%token	QUICK
unknown's avatar
unknown committed
427
%token	REAL
unknown's avatar
unknown committed
428
%token	SIGNED_SYM
unknown's avatar
unknown committed
429 430 431 432 433 434 435 436
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
unknown's avatar
unknown committed
437
%token	ULONGLONG_NUM
unknown's avatar
unknown committed
438
%token	UNSIGNED
439 440 441
%token	VARBINARY
%token	VARCHAR
%token	VARYING
unknown's avatar
unknown committed
442 443
%token	ZEROFILL

unknown's avatar
unknown committed
444
%token	ADDDATE_SYM
unknown's avatar
unknown committed
445
%token	AGAINST
unknown's avatar
unknown committed
446 447 448 449
%token	ATAN
%token	BETWEEN_SYM
%token	BIT_AND
%token	BIT_OR
450
%token  BIT_XOR
unknown's avatar
unknown committed
451 452
%token	CASE_SYM
%token	CONCAT
unknown's avatar
unknown committed
453
%token	CONCAT_WS
unknown's avatar
unknown committed
454 455 456 457 458 459
%token	CURDATE
%token	CURTIME
%token	DATABASE
%token	DATE_ADD_INTERVAL
%token	DATE_SUB_INTERVAL
%token	DAY_HOUR_SYM
unknown's avatar
unknown committed
460
%token	DAY_MICROSECOND_SYM
unknown's avatar
unknown committed
461 462 463 464
%token	DAY_MINUTE_SYM
%token	DAY_SECOND_SYM
%token	DAY_SYM
%token	DECODE_SYM
unknown's avatar
unknown committed
465 466
%token	DES_ENCRYPT_SYM
%token	DES_DECRYPT_SYM
unknown's avatar
unknown committed
467 468 469 470 471 472 473 474 475 476
%token	ELSE
%token	ELT_FUNC
%token	ENCODE_SYM
%token	ENCRYPT
%token	EXPORT_SET
%token	EXTRACT_SYM
%token	FIELD_FUNC
%token	FORMAT_SYM
%token	FOR_SYM
%token	FROM_UNIXTIME
unknown's avatar
unknown committed
477 478
%token	GEOMCOLLFROMTEXT
%token	GEOMFROMTEXT
unknown's avatar
unknown committed
479
%token	GEOMFROMWKB
unknown's avatar
unknown committed
480
%token  GEOMETRYCOLLECTION
481
%token  GROUP_CONCAT_SYM
unknown's avatar
unknown committed
482
%token	GROUP_UNIQUE_USERS
483
%token  GET_FORMAT
unknown's avatar
unknown committed
484
%token	HOUR_MICROSECOND_SYM
unknown's avatar
unknown committed
485 486 487 488 489
%token	HOUR_MINUTE_SYM
%token	HOUR_SECOND_SYM
%token	HOUR_SYM
%token	IDENTIFIED_SYM
%token	IF
490
%token	INSERT_METHOD
unknown's avatar
unknown committed
491 492 493
%token	INTERVAL_SYM
%token	LAST_INSERT_ID
%token	LEFT
unknown's avatar
unknown committed
494
%token	LINEFROMTEXT
unknown's avatar
unknown committed
495
%token  LINESTRING
unknown's avatar
unknown committed
496 497
%token	LOCATE
%token	MAKE_SET_SYM
498
%token	MASTER_POS_WAIT
unknown's avatar
unknown committed
499 500
%token  MICROSECOND_SYM
%token	MINUTE_MICROSECOND_SYM
unknown's avatar
unknown committed
501 502
%token	MINUTE_SECOND_SYM
%token	MINUTE_SYM
unknown's avatar
unknown committed
503
%token	MODE_SYM
unknown's avatar
unknown committed
504 505
%token	MODIFY_SYM
%token	MONTH_SYM
unknown's avatar
unknown committed
506 507 508
%token	MLINEFROMTEXT
%token	MPOINTFROMTEXT
%token	MPOLYFROMTEXT
unknown's avatar
unknown committed
509 510 511
%token  MULTILINESTRING
%token  MULTIPOINT
%token  MULTIPOLYGON
unknown's avatar
unknown committed
512
%token	NOW_SYM
unknown's avatar
unknown committed
513
%token	OLD_PASSWORD
unknown's avatar
unknown committed
514
%token	PASSWORD
unknown's avatar
unknown committed
515
%token	POINTFROMTEXT
516
%token	POINT_SYM
unknown's avatar
unknown committed
517
%token	POLYFROMTEXT
unknown's avatar
unknown committed
518
%token  POLYGON
unknown's avatar
unknown committed
519 520 521 522 523 524 525
%token	POSITION_SYM
%token	PROCEDURE
%token	RAND
%token	REPLACE
%token	RIGHT
%token	ROUND
%token	SECOND_SYM
unknown's avatar
unknown committed
526
%token	SECOND_MICROSECOND_SYM
unknown's avatar
unknown committed
527
%token	SHARE_SYM
unknown's avatar
unknown committed
528
%token	SUBDATE_SYM
unknown's avatar
unknown committed
529 530 531 532 533 534 535 536 537 538 539 540
%token	SUBSTRING
%token	SUBSTRING_INDEX
%token	TRIM
%token	UDA_CHAR_SUM
%token	UDA_FLOAT_SUM
%token	UDA_INT_SUM
%token	UDF_CHAR_FUNC
%token	UDF_FLOAT_FUNC
%token	UDF_INT_FUNC
%token	UNIQUE_USERS
%token	UNIX_TIMESTAMP
%token	USER
541 542 543
%token	UTC_DATE_SYM
%token	UTC_TIME_SYM
%token	UTC_TIMESTAMP_SYM
unknown's avatar
unknown committed
544 545
%token	WEEK_SYM
%token	WHEN_SYM
unknown's avatar
unknown committed
546
%token	WORK_SYM
unknown's avatar
unknown committed
547 548 549
%token	YEAR_MONTH_SYM
%token	YEAR_SYM
%token	YEARWEEK
unknown's avatar
unknown committed
550 551 552
%token	BENCHMARK_SYM
%token	END
%token	THEN_SYM
unknown's avatar
unknown committed
553

unknown's avatar
unknown committed
554 555 556 557
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
558
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
559
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
560

unknown's avatar
unknown committed
561 562
%token  ISSUER_SYM
%token  SUBJECT_SYM
563
%token  CIPHER_SYM
unknown's avatar
unknown committed
564

565
%token  BEFORE_SYM
unknown's avatar
unknown committed
566 567 568 569 570 571 572 573 574
%left   SET_VAR
%left	OR_OR_CONCAT OR
%left	AND
%left	BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
%left	EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP IN_SYM
%left	'|'
%left	'&'
%left	SHIFT_LEFT SHIFT_RIGHT
%left	'-' '+'
575
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
576
%left	NEG '~'
unknown's avatar
unknown committed
577 578
%left   XOR
%left   '^'
unknown's avatar
unknown committed
579
%right	NOT
unknown's avatar
unknown committed
580
%right	BINARY COLLATE_SYM
581

unknown's avatar
unknown committed
582
%type <lex_str>
583 584
	IDENT IDENT_QUOTED TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
	LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
585
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
586
	NCHAR_STRING opt_component key_cache_name
unknown's avatar
unknown committed
587 588 589 590 591

%type <lex_str_ptr>
	opt_table_alias

%type <table>
592
	table_ident references
unknown's avatar
unknown committed
593 594

%type <simple_string>
595
	remember_name remember_end opt_ident opt_db text_or_password
596
	opt_escape opt_constraint
unknown's avatar
unknown committed
597 598

%type <string>
599
	text_string opt_gconcat_separator
unknown's avatar
unknown committed
600 601

%type <num>
unknown's avatar
unknown committed
602
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
603
	udf_type if_exists opt_local opt_table_options table_options
604 605 606
        table_option opt_if_not_exists opt_no_write_to_binlog opt_var_type
        opt_var_ident_type delete_option opt_temporary all_or_any opt_distinct
        opt_ignore_leaves fulltext_options
unknown's avatar
unknown committed
607 608

%type <ulong_num>
609
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
610

unknown's avatar
unknown committed
611 612
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
613

unknown's avatar
unknown committed
614 615 616
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

unknown's avatar
unknown committed
617
%type <item>
unknown's avatar
unknown committed
618
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
619
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
620
	table_wild no_in_expr expr_expr simple_expr no_and_expr
621
	using_list expr_or_default set_expr_or_default interval_expr
unknown's avatar
unknown committed
622
	param_marker singlerow_subselect singlerow_subselect_init
unknown's avatar
unknown committed
623
	exists_subselect exists_subselect_init
unknown's avatar
unknown committed
624 625

%type <item_list>
unknown's avatar
unknown committed
626
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
627 628

%type <key_type>
629
	key_type opt_unique_or_fulltext constraint_key_type
unknown's avatar
unknown committed
630

unknown's avatar
unknown committed
631 632 633
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
634 635 636 637 638 639 640
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
641
	join_table_list  join_table
unknown's avatar
unknown committed
642 643 644 645 646

%type <udf>
	UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
	UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM

647
%type <date_time_type> date_time_type;
unknown's avatar
unknown committed
648 649 650 651 652 653
%type <interval> interval

%type <db_type> table_types

%type <row_type> row_types

unknown's avatar
unknown committed
654
%type <tx_isolation> isolation_types
unknown's avatar
unknown committed
655

unknown's avatar
unknown committed
656 657
%type <ha_rkey_mode> handler_rkey_mode

658
%type <cast_type> cast_type cast_type_finalize
unknown's avatar
unknown committed
659

unknown's avatar
unknown committed
660 661 662 663 664 665
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

666
%type <charset>
667
	opt_collate
668 669
	charset_name
	charset_name_or_default
unknown's avatar
unknown committed
670 671
	old_or_new_charset_name
	old_or_new_charset_name_or_default
672 673
	collation_name
	collation_name_or_default
674

unknown's avatar
unknown committed
675 676
%type <variable> internal_variable_name

unknown's avatar
unknown committed
677 678
%type <select_lex> in_subselect in_subselect_init

unknown's avatar
unknown committed
679 680
%type <boolfunc2creator> comp_op

unknown's avatar
unknown committed
681
%type <NONE>
unknown's avatar
unknown committed
682
	query verb_clause create change select do drop insert replace insert2
683
	insert_values update delete truncate rename
unknown's avatar
unknown committed
684
	show describe load alter optimize keycache preload flush
685
	reset purge begin commit rollback savepoint
686
	slave master_def master_defs master_file_def slave_until_opts
687
	repair restore backup analyze check start checksum
688
	field_list field_list_item field_spec kill column_def key_def
unknown's avatar
unknown committed
689
	keycache_list assign_to_keycache preload_list preload_keys
unknown's avatar
unknown committed
690
	select_item_list select_item values_list no_braces
691
	opt_limit_clause delete_limit_clause fields opt_values values
unknown's avatar
unknown committed
692
	procedure_list procedure_list2 procedure_item
693
	when_list2 expr_list2  handler
unknown's avatar
unknown committed
694 695
	opt_precision opt_ignore opt_column opt_restrict
	grant revoke set lock unlock string_list field_options field_option
unknown's avatar
unknown committed
696
	field_opt_list opt_binary table_lock_list table_lock
697
	ref_list opt_on_delete opt_on_delete_list opt_on_delete_item use
unknown's avatar
unknown committed
698
	opt_delete_options opt_delete_option varchar nchar nvarchar
unknown's avatar
unknown committed
699
	opt_outer table_list table_name opt_option opt_place
unknown's avatar
unknown committed
700 701
	opt_attribute opt_attribute_list attribute column_list column_list_id
	opt_column_list grant_privileges opt_table user_list grant_option
unknown's avatar
unknown committed
702
	grant_privilege grant_privilege_list
unknown's avatar
unknown committed
703
	flush_options flush_option
unknown's avatar
unknown committed
704 705
	equal optional_braces opt_key_definition key_usage_list2
	opt_mi_check_type opt_to mi_check_types normal_join
706
	table_to_table_list table_to_table opt_table_list opt_as
unknown's avatar
unknown committed
707
	handler_rkey_function handler_read_or_scan
unknown's avatar
unknown committed
708
	single_multi table_wild_list table_wild_one opt_wild
709
	union_clause union_list union_option
710
	precision subselect_start opt_and charset
711
	subselect_end select_var_list select_var_list_init help opt_len
unknown's avatar
unknown committed
712
	opt_extended_describe
713
END_OF_INPUT
unknown's avatar
unknown committed
714 715 716

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
717 718
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
unknown's avatar
unknown committed
719 720 721 722 723
%%


query:
	END_OF_INPUT
unknown's avatar
unknown committed
724
	{
725
	   THD *thd= YYTHD;
726
	   if (!thd->bootstrap &&
unknown's avatar
unknown committed
727
	      (!(thd->lex.select_lex.options & OPTION_FOUND_COMMENT)))
728
	   {
729
	     send_error(thd,ER_EMPTY_QUERY);
730
	     YYABORT;
731
	   }
732 733 734 735
	   else
	   {
	     thd->lex.sql_command = SQLCOM_EMPTY_QUERY;
	   }
unknown's avatar
unknown committed
736
	}
unknown's avatar
unknown committed
737
	| verb_clause END_OF_INPUT {};
unknown's avatar
unknown committed
738 739 740 741

verb_clause:
	  alter
	| analyze
742
	| backup
unknown's avatar
unknown committed
743 744 745
	| begin
	| change
	| check
746
	| checksum
unknown's avatar
unknown committed
747 748 749 750
	| commit
	| create
	| delete
	| describe
unknown's avatar
unknown committed
751
	| do
unknown's avatar
unknown committed
752
	| drop
unknown's avatar
unknown committed
753
	| flush
unknown's avatar
unknown committed
754
	| grant
unknown's avatar
unknown committed
755 756
	| handler
	| help
unknown's avatar
unknown committed
757
	| insert
unknown's avatar
unknown committed
758
	| kill
unknown's avatar
unknown committed
759 760 761
	| load
	| lock
	| optimize
unknown's avatar
unknown committed
762
        | keycache
unknown's avatar
unknown committed
763
	| preload
764
	| purge
765
	| rename
unknown's avatar
unknown committed
766
	| repair
unknown's avatar
unknown committed
767
	| replace
unknown's avatar
unknown committed
768
	| reset
769
	| restore
unknown's avatar
unknown committed
770 771
	| revoke
	| rollback
772
	| savepoint
unknown's avatar
unknown committed
773 774
	| select
	| set
unknown's avatar
unknown committed
775
	| show
unknown's avatar
unknown committed
776
	| slave
unknown's avatar
unknown committed
777
	| start
778
	| truncate
unknown's avatar
unknown committed
779 780
	| unlock
	| update
unknown's avatar
unknown committed
781
	| use
unknown's avatar
unknown committed
782
        ;
783

unknown's avatar
unknown committed
784 785
/* help */

786
help:
787
       HELP_SYM ident_or_text
unknown's avatar
unknown committed
788
       {
789 790 791
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
792
       };
unknown's avatar
unknown committed
793 794 795 796

/* change master */

change:
unknown's avatar
unknown committed
797
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
798 799 800
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
unknown's avatar
unknown committed
801
	  bzero((char*) &lex->mi, sizeof(lex->mi));
802 803 804 805
        }
       master_defs
	{}
       ;
unknown's avatar
unknown committed
806 807 808

master_defs:
       master_def
unknown's avatar
unknown committed
809
       | master_defs ',' master_def;
unknown's avatar
unknown committed
810

unknown's avatar
unknown committed
811
master_def:
unknown's avatar
unknown committed
812
       MASTER_HOST_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
813 814 815 816
       {
	 Lex->mi.host = $3.str;
       }
       |
unknown's avatar
unknown committed
817
       MASTER_USER_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
818 819 820 821
       {
	 Lex->mi.user = $3.str;
       }
       |
unknown's avatar
unknown committed
822
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
823 824 825 826
       {
	 Lex->mi.password = $3.str;
       }
       |
unknown's avatar
unknown committed
827
       MASTER_PORT_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
828 829 830 831
       {
	 Lex->mi.port = $3;
       }
       |
unknown's avatar
unknown committed
832
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
833 834 835
       {
	 Lex->mi.connect_retry = $3;
       }
unknown's avatar
unknown committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
       | MASTER_SSL_SYM EQ ULONG_NUM
         {
           Lex->mi.ssl= $3 ? 
               LEX_MASTER_INFO::SSL_ENABLE : LEX_MASTER_INFO::SSL_DISABLE;
         }
       | MASTER_SSL_CA_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_ca= $3.str;
         }
       | MASTER_SSL_CAPATH_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_capath= $3.str;
         }
       | MASTER_SSL_CERT_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_cert= $3.str;
         }
       | MASTER_SSL_CIPHER_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_cipher= $3.str;
         }
       | MASTER_SSL_KEY_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_key= $3.str;
860
	 }
861
       |
862
         master_file_def
863
       ;
unknown's avatar
unknown committed
864

865 866
master_file_def:
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
867
       {
868
	 Lex->mi.log_file_name = $3.str;
869
       }
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
       | MASTER_LOG_POS_SYM EQ ulonglong_num
         {
           Lex->mi.pos = $3;
           /* 
              If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
              instead of causing subsequent errors. 
              We need to do it in this file, because only there we know that 
              MASTER_LOG_POS has been explicitely specified. On the contrary
              in change_master() (sql_repl.cc) we cannot distinguish between 0
              (MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
              whereas we want to distinguish (specified 0 means "read the binlog
              from 0" (4 in fact), unspecified means "don't change the position
              (keep the preceding value)").
           */
           Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
         }
       | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.relay_log_name = $3.str;
         }
       | RELAY_LOG_POS_SYM EQ ULONG_NUM
         {
           Lex->mi.relay_log_pos = $3;
           /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
           Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
         }
896
       ;
unknown's avatar
unknown committed
897 898 899 900 901 902

/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
903
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
904 905
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
unknown's avatar
unknown committed
906
	  if (!lex->select_lex.add_table_to_list(thd,$5,
907
						 ($2 &
908 909
						  HA_LEX_CREATE_TMP_TABLE ?
						  &tmp_table_alias :
unknown's avatar
unknown committed
910 911
						  (LEX_STRING*) 0),
						 TL_OPTION_UPDATING,
unknown's avatar
unknown committed
912 913 914
						 ((using_update_log)?
						  TL_READ_NO_INSERT:
						  TL_READ)))
unknown's avatar
unknown committed
915 916 917 918 919 920 921
	    YYABORT;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
	  lex->change=NullS;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	  lex->create_info.options=$2 | $4;
unknown's avatar
unknown committed
922
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
923
	  lex->create_info.default_table_charset= thd->variables.collation_database;
unknown's avatar
unknown committed
924
	  lex->name=0;
unknown's avatar
unknown committed
925 926
	}
	create2
unknown's avatar
unknown committed
927
	  { Lex->current_select= &Lex->select_lex; }
unknown's avatar
unknown committed
928
	| CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
unknown's avatar
unknown committed
929
	  {
unknown's avatar
unknown committed
930 931
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
unknown's avatar
unknown committed
932 933
	    if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
934
	      YYABORT;
unknown's avatar
unknown committed
935 936 937 938
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
unknown's avatar
unknown committed
939
	  }
940
	   '(' key_list ')'
unknown's avatar
unknown committed
941
	  {
unknown's avatar
unknown committed
942
	    LEX *lex=Lex;
unknown's avatar
unknown committed
943

944
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
unknown's avatar
unknown committed
945
	    lex->col_list.empty();
unknown's avatar
unknown committed
946 947
	  }
	| CREATE DATABASE opt_if_not_exists ident
948
	  { Lex->create_info.default_table_charset=NULL; }
949
	  opt_create_database_options
unknown's avatar
unknown committed
950
	  {
unknown's avatar
unknown committed
951 952 953 954
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
unknown's avatar
unknown committed
955
	  }
unknown's avatar
unknown committed
956
	| CREATE udf_func_type UDF_SYM IDENT_sys
unknown's avatar
unknown committed
957
	  {
unknown's avatar
unknown committed
958 959
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
960
	    lex->udf.name = $4;
unknown's avatar
unknown committed
961
	    lex->udf.type= $2;
unknown's avatar
unknown committed
962
	  }
unknown's avatar
unknown committed
963
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
964
	  {
unknown's avatar
unknown committed
965 966 967
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
968 969
	  }
          ;
unknown's avatar
unknown committed
970 971

create2:
unknown's avatar
unknown committed
972
 	'(' create2a {}
973
	| opt_create_table_options create3 {}
unknown's avatar
unknown committed
974 975 976 977 978 979
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
980 981 982 983 984 985
	| '(' LIKE table_ident ')'
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$3))
              YYABORT;
    	  }
unknown's avatar
unknown committed
986
        ;
unknown's avatar
unknown committed
987

unknown's avatar
unknown committed
988 989
create2a:
        field_list ')' opt_create_table_options create3 {}
unknown's avatar
unknown committed
990
	|  create_select ')' { Select->set_braces(1);} union_opt {}
991
        ;
unknown's avatar
unknown committed
992 993

create3:
994
	/* empty */ {}
unknown's avatar
unknown committed
995
	| opt_duplicate opt_as     create_select
unknown's avatar
unknown committed
996
          { Select->set_braces(0);} union_clause {}
unknown's avatar
unknown committed
997
	| opt_duplicate opt_as '(' create_select ')'
unknown's avatar
unknown committed
998
          { Select->set_braces(1);} union_opt {}
999 1000
        ;

unknown's avatar
unknown committed
1001
create_select:
1002
          SELECT_SYM
unknown's avatar
unknown committed
1003
          {
unknown's avatar
unknown committed
1004 1005
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
1006 1007 1008 1009
	    if (lex->sql_command == SQLCOM_INSERT)
	      lex->sql_command= SQLCOM_INSERT_SELECT;
	    else if (lex->sql_command == SQLCOM_REPLACE)
	      lex->sql_command= SQLCOM_REPLACE_SELECT;
unknown's avatar
unknown committed
1010
	    lex->current_select->table_list.save_and_clear(&lex->save_list);
unknown's avatar
unknown committed
1011
	    mysql_init_select(lex);
unknown's avatar
unknown committed
1012
	    lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
unknown's avatar
unknown committed
1013
          }
unknown's avatar
unknown committed
1014 1015 1016 1017
          select_options select_item_list
	  {
	    Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
	  }
unknown's avatar
unknown committed
1018
	  opt_select_from
unknown's avatar
unknown committed
1019
	  { Lex->current_select->table_list.push_front(&Lex->save_list); }
unknown's avatar
unknown committed
1020
        ;
unknown's avatar
unknown committed
1021

1022 1023
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
1024
	| AS	    {};
1025

1026 1027 1028 1029 1030 1031 1032 1033 1034
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
1035 1036
	  opt_default COLLATE_SYM collation_name_or_default	
	  { Lex->create_info.default_table_charset=$3; }
1037
	| opt_default charset charset_name_or_default
1038
	  { Lex->create_info.default_table_charset=$3; }
1039
	;
1040

unknown's avatar
unknown committed
1041
opt_table_options:
unknown's avatar
unknown committed
1042
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
1043
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
1044 1045 1046

table_options:
	table_option	{ $$=$1; }
unknown's avatar
unknown committed
1047
	| table_option table_options { $$= $1 | $2; };
unknown's avatar
unknown committed
1048

unknown's avatar
unknown committed
1049
table_option:
unknown's avatar
unknown committed
1050
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
1051 1052

opt_if_not_exists:
unknown's avatar
unknown committed
1053
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
1054
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
1055 1056 1057

opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
1058
	| create_table_options;
unknown's avatar
unknown committed
1059

unknown's avatar
unknown committed
1060 1061 1062 1063
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
1064 1065
create_table_options:
	create_table_option
1066
	| create_table_option     create_table_options
unknown's avatar
unknown committed
1067
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
1068 1069

create_table_option:
1070 1071 1072 1073
	TYPE_SYM opt_equal table_types          { Lex->create_info.db_type= $3; }
	| MAX_ROWS opt_equal ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS opt_equal ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH opt_equal ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
unknown's avatar
unknown committed
1074 1075
	| PASSWORD opt_equal TEXT_STRING_sys	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM opt_equal TEXT_STRING_sys	{ Lex->create_info.comment=$3.str; }
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
	| AUTO_INC opt_equal ulonglong_num	{ Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;}
	| PACK_KEYS_SYM opt_equal ULONG_NUM	{ Lex->create_info.table_options|= $3 ? HA_OPTION_PACK_KEYS : HA_OPTION_NO_PACK_KEYS; Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;}
	| PACK_KEYS_SYM opt_equal DEFAULT	{ Lex->create_info.table_options&= ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS); Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;}
	| CHECKSUM_SYM opt_equal ULONG_NUM	{ Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; }
	| DELAY_KEY_WRITE_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; }
	| ROW_FORMAT_SYM opt_equal row_types	{ Lex->create_info.row_type= $3; }
	| RAID_TYPE opt_equal raid_types	{ Lex->create_info.raid_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKS opt_equal ULONG_NUM	{ Lex->create_info.raid_chunks= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKSIZE opt_equal ULONG_NUM	{ Lex->create_info.raid_chunksize= $3*RAID_BLOCK_SIZE; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| UNION_SYM opt_equal '(' table_list ')'
1086 1087 1088
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
1089 1090
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
1091 1092
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
1093 1094
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
1095
	    table_list->next=0;
1096
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
1097
	  }
1098
	| DEFAULT charset opt_equal charset_name_or_default
1099
	  {
1100 1101 1102 1103 1104 1105
	    Lex->create_info.default_table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
	  }
	| charset opt_equal charset_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
1106 1107
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1108 1109 1110 1111 1112
	| DEFAULT COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
	  }
1113 1114 1115 1116 1117
	| COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1118
	| INSERT_METHOD opt_equal merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
unknown's avatar
unknown committed
1119 1120 1121
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
	  { Lex->create_info.data_file_name= $4.str; }
	| INDEX DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; };
unknown's avatar
unknown committed
1122 1123

table_types:
1124 1125 1126 1127 1128 1129 1130 1131
	ident_or_text
	{
	  $$ = ha_resolve_by_name($1.str,$1.length);
	  if ($$ == DB_TYPE_UNKNOWN) {
	    net_printf(YYTHD, ER_UNKNOWN_TABLE_ENGINE, $1.str);
	    YYABORT;
	  }
	};
unknown's avatar
unknown committed
1132 1133 1134 1135 1136

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
1137
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
1138 1139 1140 1141

raid_types:
	RAID_STRIPED_SYM { $$= RAID_TYPE_0; }
	| RAID_0_SYM	 { $$= RAID_TYPE_0; }
unknown's avatar
unknown committed
1142
	| ULONG_NUM	 { $$=$1;};
unknown's avatar
unknown committed
1143

1144 1145 1146
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
1147
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1148

unknown's avatar
unknown committed
1149
opt_select_from:
1150
	opt_limit_clause {}
unknown's avatar
unknown committed
1151
	| FROM DUAL_SYM {}
unknown's avatar
unknown committed
1152
	| select_from select_lock_type;
unknown's avatar
unknown committed
1153 1154

udf_func_type:
1155
	/* empty */	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
1156
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
1157 1158 1159 1160

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
1161
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
1162 1163 1164

field_list:
	  field_list_item
unknown's avatar
unknown committed
1165
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
1166 1167 1168


field_list_item:
unknown's avatar
unknown committed
1169
	   column_def
1170 1171 1172 1173
         | key_def
         ;

column_def:
1174
	  field_spec check_constraint
unknown's avatar
unknown committed
1175 1176 1177 1178
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1179
	;
1180 1181

key_def:
unknown's avatar
unknown committed
1182
	key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1183
	  {
unknown's avatar
unknown committed
1184
	    LEX *lex=Lex;
1185
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
unknown's avatar
unknown committed
1186
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1187
	  }
1188 1189 1190 1191 1192 1193 1194
	| opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')'
	  {
	    LEX *lex=Lex;
	    const char *key_name= $3 ? $3:$1;
	    lex->key_list.push_back(new Key($2, key_name, $4, lex->col_list));
	    lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
1195
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1196
	  {
1197 1198 1199 1200 1201 1202 1203 1204
	    LEX *lex=Lex;
	    lex->key_list.push_back(new foreign_key($4, lex->col_list,
				    $8,
				    lex->ref_list,
				    lex->fk_delete_opt,
				    lex->fk_update_opt,
				    lex->fk_match_option));
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1205
	  }
1206
	| opt_constraint check_constraint
unknown's avatar
unknown committed
1207 1208
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1209 1210 1211 1212 1213 1214 1215
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
unknown's avatar
unknown committed
1216 1217

opt_constraint:
1218 1219
	/* empty */		{ $$=(char*) 0; }
	| CONSTRAINT opt_ident	{ $$=$2; };
unknown's avatar
unknown committed
1220 1221 1222 1223

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1224 1225
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
unknown's avatar
unknown committed
1226 1227
	   lex->default_value=0;
	   lex->comment=0;
1228
	   lex->charset=NULL;
unknown's avatar
unknown committed
1229 1230 1231
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1232
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1233
	  if (add_field_to_list(lex->thd, $1.str,
unknown's avatar
unknown committed
1234
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1235
				lex->length,lex->dec,lex->type,
1236
				lex->default_value, lex->comment,
unknown's avatar
unknown committed
1237 1238
				lex->change,lex->interval,lex->charset,
				lex->uint_geom_type))
unknown's avatar
unknown committed
1239
	    YYABORT;
unknown's avatar
unknown committed
1240
	};
unknown's avatar
unknown committed
1241 1242

type:
1243
	int_type opt_len field_options	{ $$=$1; }
unknown's avatar
unknown committed
1244 1245 1246 1247 1248 1249
	| real_type opt_precision field_options { $$=$1; }
	| FLOAT_SYM float_options field_options { $$=FIELD_TYPE_FLOAT; }
	| BIT_SYM opt_len		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
	| BOOL_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1250 1251
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1252
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1253 1254 1255
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
unknown's avatar
unknown committed
1256
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1257
					  $$=FIELD_TYPE_STRING;
1258
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1259
	| nchar				{ Lex->length=(char*) "1";
unknown's avatar
unknown committed
1260
					  $$=FIELD_TYPE_STRING;
1261
					  Lex->charset=national_charset_info; }
1262
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1263
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1264 1265 1266
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
unknown's avatar
unknown committed
1267 1268
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
1269
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1270
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1271
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1272
					  $$=FIELD_TYPE_VAR_STRING; }
1273
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
unknown's avatar
unknown committed
1274 1275
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1276 1277
	| TIMESTAMP
	  {
1278
	    if (YYTHD->variables.sql_mode & MODE_MAXDB)
1279 1280
	      $$=FIELD_TYPE_DATETIME;
	    else
1281
	      $$=FIELD_TYPE_TIMESTAMP;
1282
	   }
unknown's avatar
unknown committed
1283 1284 1285
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
unknown's avatar
unknown committed
1286
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1287
					  $$=FIELD_TYPE_TINY_BLOB; }
unknown's avatar
unknown committed
1288
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1289
					  $$=FIELD_TYPE_BLOB; }
unknown's avatar
unknown committed
1290
	| GEOMETRY_SYM			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1291
					  Lex->uint_geom_type= (uint) Field::GEOM_GEOMETRY;
unknown's avatar
unknown committed
1292
					  $$=FIELD_TYPE_GEOMETRY; }
1293
	| GEOMETRYCOLLECTION		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1294
					  Lex->uint_geom_type= (uint) Field::GEOM_GEOMETRYCOLLECTION;
1295
					  $$=FIELD_TYPE_GEOMETRY; }
1296
	| POINT_SYM			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1297
					  Lex->uint_geom_type= (uint) Field::GEOM_POINT;
1298 1299
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOINT			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1300
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTIPOINT;
1301 1302
					  $$=FIELD_TYPE_GEOMETRY; }
	| LINESTRING			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1303
					  Lex->uint_geom_type= (uint) Field::GEOM_LINESTRING;
1304 1305
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTILINESTRING		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1306
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTILINESTRING;
1307 1308
					  $$=FIELD_TYPE_GEOMETRY; }
	| POLYGON			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1309
					  Lex->uint_geom_type= (uint) Field::GEOM_POLYGON;
1310 1311
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOLYGON			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1312
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTIPOLYGON;
1313
					  $$=FIELD_TYPE_GEOMETRY; }
unknown's avatar
unknown committed
1314
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1315
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1316
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1317
					  $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1318
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1319
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1320 1321
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1322
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1323 1324
	| MEDIUMTEXT opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT opt_binary		{ $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1325 1326 1327 1328
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1329 1330
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1331
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1332
	  {
unknown's avatar
unknown committed
1333 1334
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1335 1336
	    $$=FIELD_TYPE_ENUM;
	  }
1337
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1338
	  {
unknown's avatar
unknown committed
1339 1340
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1341
	    $$=FIELD_TYPE_SET;
1342
	  }
1343
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1344 1345 1346 1347 1348 1349
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
1350
	;
unknown's avatar
unknown committed
1351 1352 1353

char:
	CHAR_SYM {}
unknown's avatar
unknown committed
1354 1355 1356 1357 1358 1359
	;

nchar:
	NCHAR_SYM {}
	| NATIONAL_SYM CHAR_SYM {}
	;
unknown's avatar
unknown committed
1360

unknown's avatar
unknown committed
1361 1362 1363
varchar:
	char VARYING {}
	| VARCHAR {}
unknown's avatar
unknown committed
1364 1365 1366 1367
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
unknown's avatar
unknown committed
1368
	| NVARCHAR_SYM {}
unknown's avatar
unknown committed
1369 1370 1371 1372
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
unknown's avatar
unknown committed
1373 1374 1375 1376 1377 1378

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1379
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1380 1381

real_type:
1382
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1383 1384
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1385
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1386 1387 1388 1389 1390


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1391
	| precision		{};
unknown's avatar
unknown committed
1392 1393 1394 1395 1396 1397

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1398
	};
unknown's avatar
unknown committed
1399 1400 1401

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1402
	| field_opt_list	{};
unknown's avatar
unknown committed
1403 1404 1405

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1406
	| field_option {};
unknown's avatar
unknown committed
1407 1408

field_option:
unknown's avatar
unknown committed
1409
	SIGNED_SYM	{}
1410
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1411
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1412 1413

opt_len:
1414 1415
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1416 1417 1418

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1419
	| precision	{};
unknown's avatar
unknown committed
1420 1421 1422

opt_attribute:
	/* empty */ {}
unknown's avatar
unknown committed
1423
	| opt_attribute_list {};
unknown's avatar
unknown committed
1424 1425 1426

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1427
	| attribute;
unknown's avatar
unknown committed
1428 1429 1430 1431 1432 1433

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
	| DEFAULT literal { Lex->default_value=$2; }
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1434
	| SERIAL_SYM DEFAULT VALUE_SYM
unknown's avatar
unknown committed
1435 1436
	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; }
	| opt_primary KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
unknown's avatar
unknown committed
1437
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1438
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
unknown's avatar
unknown committed
1439
	| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
unknown's avatar
unknown committed
1440 1441
	| COLLATE_SYM collation_name
	  {
unknown's avatar
unknown committed
1442
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
unknown's avatar
unknown committed
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $2->name,Lex->charset->csname);
	      YYABORT;
	    }
	    else
	    {
	      Lex->charset=$2;
	    }
	  }
	;
unknown's avatar
unknown committed
1454

1455 1456 1457 1458
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
unknown's avatar
unknown committed
1459

1460
charset_name:
1461
	ident_or_text
1462
	{
unknown's avatar
unknown committed
1463
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
1464
	  {
1465
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1466 1467
	    YYABORT;
	  }
unknown's avatar
unknown committed
1468 1469 1470
	}
	| BINARY { $$= &my_charset_bin; }
	;
1471

1472 1473 1474
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1475

unknown's avatar
unknown committed
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493

old_or_new_charset_name:
	ident_or_text
	{
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
	      !($$=get_old_charset_by_name($1.str)))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	}
	| BINARY { $$= &my_charset_bin; }
	;

old_or_new_charset_name_or_default:
	old_or_new_charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1494
collation_name:
1495
	ident_or_text
1496 1497 1498
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
1499
	    net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str);
1500 1501 1502 1503
	    YYABORT;
	  }
	};

1504 1505
opt_collate:
	/* empty */	{ $$=NULL; }
unknown's avatar
unknown committed
1506
	| COLLATE_SYM collation_name_or_default { $$=$2; }
1507 1508
	;

1509 1510 1511 1512
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1513 1514 1515 1516
opt_default:
	/* empty */	{}
	| DEFAULT	{};

unknown's avatar
unknown committed
1517
opt_binary:
1518
	/* empty */			{ Lex->charset=NULL; }
unknown's avatar
unknown committed
1519 1520 1521
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
	| BINARY			{ Lex->charset=&my_charset_bin; }
unknown's avatar
unknown committed
1522 1523
	| UNICODE_SYM
	{
1524
	  if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
unknown's avatar
unknown committed
1525 1526 1527 1528 1529
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1530
	| charset charset_name	{ Lex->charset=$2; } ;
unknown's avatar
unknown committed
1531

unknown's avatar
unknown committed
1532 1533 1534
opt_primary:
	/* empty */
	| PRIMARY_SYM
1535
	;
unknown's avatar
unknown committed
1536

unknown's avatar
unknown committed
1537
references:
1538 1539
	REFERENCES table_ident
	{
1540
	  LEX *lex=Lex;
1541 1542 1543 1544 1545 1546
	  lex->fk_delete_opt= lex->fk_update_opt= lex->fk_match_option= 0;
	  lex->ref_list.empty();
	}
	opt_ref_list
	{
	  $$=$2;
unknown's avatar
unknown committed
1547
	};
1548

1549
opt_ref_list:
unknown's avatar
unknown committed
1550
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1551
	| '(' ref_list ')' opt_on_delete {};
1552 1553 1554

ref_list:
	ref_list ',' ident	{ Lex->ref_list.push_back(new key_part_spec($3.str)); }
unknown's avatar
unknown committed
1555
	| ident			{ Lex->ref_list.push_back(new key_part_spec($1.str)); };
1556

unknown's avatar
unknown committed
1557 1558 1559

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1560
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1561 1562 1563

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1564
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1565 1566

opt_on_delete_item:
1567 1568 1569 1570
	ON DELETE_SYM delete_option   { Lex->fk_delete_opt= $3; }
	| ON UPDATE_SYM delete_option { Lex->fk_update_opt= $3; }
	| MATCH FULL	{ Lex->fk_match_option= foreign_key::FK_MATCH_FULL; }
	| MATCH PARTIAL { Lex->fk_match_option= foreign_key::FK_MATCH_PARTIAL; }
unknown's avatar
unknown committed
1571
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1572 1573

delete_option:
1574 1575 1576 1577
	RESTRICT	 { $$= (int) foreign_key::FK_OPTION_RESTRICT; }
	| CASCADE	 { $$= (int) foreign_key::FK_OPTION_CASCADE; }
	| SET NULL_SYM   { $$= (int) foreign_key::FK_OPTION_SET_NULL; }
	| NO_SYM ACTION  { $$= (int) foreign_key::FK_OPTION_NO_ACTION; }
unknown's avatar
unknown committed
1578
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1579 1580

key_type:
1581
	key_or_index			    { $$= Key::MULTIPLE; }
1582 1583
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
unknown's avatar
unknown committed
1584
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
1585 1586 1587 1588 1589 1590
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; };

constraint_key_type:
	PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| UNIQUE_SYM	    { $$= Key::UNIQUE; }
	| UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1591 1592 1593

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1594
	| INDEX {};
unknown's avatar
unknown committed
1595

1596 1597 1598 1599 1600
opt_keys_or_index:
	/* empty */ {}
	| keys_or_index
	;

unknown's avatar
unknown committed
1601 1602 1603
keys_or_index:
	KEYS {}
	| INDEX {}
unknown's avatar
unknown committed
1604
	| INDEXES {};
unknown's avatar
unknown committed
1605

1606
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1607 1608
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1609 1610 1611
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT;}
	| SPATIAL_SYM	{ $$= Key::SPATIAL; }
        ;
unknown's avatar
unknown committed
1612 1613

key_alg:
1614
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1615
	| USING opt_btree_or_rtree { $$= $2; }
unknown's avatar
unknown committed
1616
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
unknown's avatar
unknown committed
1617 1618 1619 1620

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
	| RTREE_SYM	{ $$= HA_KEY_ALG_RTREE; }
unknown's avatar
unknown committed
1621
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1622 1623 1624

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1625
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1626 1627 1628

key_part:
	ident			{ $$=new key_part_spec($1.str); }
unknown's avatar
unknown committed
1629
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
unknown's avatar
unknown committed
1630 1631 1632

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
unknown's avatar
unknown committed
1633
	| field_ident	{ $$=$1.str; };
unknown's avatar
unknown committed
1634

1635 1636 1637
opt_component:
	/* empty */	 { $$.str= 0; $$.length= 0; }
	| '.' ident	 { $$=$2; };
1638

unknown's avatar
unknown committed
1639 1640
string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1641
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1642 1643 1644 1645 1646 1647 1648 1649

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1650
	  THD *thd= YYTHD;
1651
	  LEX *lex=&thd->lex;
unknown's avatar
unknown committed
1652 1653
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
unknown's avatar
unknown committed
1654 1655
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1656 1657 1658 1659 1660 1661 1662
	    YYABORT;
	  lex->drop_primary=0;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
	  lex->drop_list.empty();
	  lex->alter_list.empty();
1663
          lex->select_lex.init_order();
1664
	  lex->select_lex.db=lex->name=0;
1665
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
unknown's avatar
unknown committed
1666
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1667
	  lex->create_info.default_table_charset= thd->variables.collation_database;
1668
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1669
          lex->alter_keys_onoff=LEAVE_AS_IS;
unknown's avatar
unknown committed
1670
	  lex->tablespace_op=NO_TABLESPACE_OP;
1671
          lex->simple_alter=1;
unknown's avatar
unknown committed
1672
	}
1673 1674
	alter_list
	{}
1675
	| ALTER DATABASE ident opt_create_database_options
1676 1677 1678 1679
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1680
	  };
1681 1682


unknown's avatar
unknown committed
1683
alter_list:
unknown's avatar
unknown committed
1684 1685
	| DISCARD TABLESPACE { Lex->tablespace_op=DISCARD_TABLESPACE; }
	| IMPORT TABLESPACE { Lex->tablespace_op=IMPORT_TABLESPACE; }
unknown's avatar
unknown committed
1686
        | alter_list_item
unknown's avatar
unknown committed
1687
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1688 1689

add_column:
unknown's avatar
unknown committed
1690
	ADD opt_column { Lex->change=0; };
unknown's avatar
unknown committed
1691 1692

alter_list_item:
1693 1694
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1695
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1696 1697 1698 1699 1700
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1701
          field_spec opt_place
unknown's avatar
unknown committed
1702 1703 1704 1705
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
            lex->length=lex->dec=0; lex->type=0; lex->interval=0;
unknown's avatar
unknown committed
1706 1707
            lex->default_value=0;
	    lex->comment=0;
1708
	    lex->charset= NULL;
unknown's avatar
unknown committed
1709
            lex->simple_alter=0;
unknown's avatar
unknown committed
1710 1711 1712 1713
          }
          type opt_attribute
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
1714
            if (add_field_to_list(lex->thd,$3.str,
unknown's avatar
unknown committed
1715 1716 1717
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
unknown's avatar
unknown committed
1718 1719
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
unknown's avatar
unknown committed
1720 1721 1722
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1723
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
					    $3.str)); lex->simple_alter=0;
	  }
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
	    lex->drop_primary=1; lex->simple_alter=0;
	  }
1734
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1735
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1736 1737 1738 1739 1740 1741
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1742 1743
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
unknown's avatar
unknown committed
1744
	| ALTER opt_column field_ident SET DEFAULT literal
unknown's avatar
unknown committed
1745 1746 1747 1748 1749
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
unknown's avatar
unknown committed
1750
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1751 1752 1753 1754 1755
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1756
	| RENAME opt_to table_ident
1757
	  {
1758
	    LEX *lex=Lex;
1759
	    lex->select_lex.db=$3->db.str;
1760
	    lex->name= $3->table.str;
1761
	  }
unknown's avatar
unknown committed
1762
        | create_table_options_space_separated { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1763
	| order_clause         { Lex->simple_alter=0; };
unknown's avatar
unknown committed
1764 1765 1766

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
1767
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
1768 1769 1770

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
unknown's avatar
unknown committed
1771
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
1772 1773 1774 1775

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
1776
	| CASCADE	{};
unknown's avatar
unknown committed
1777 1778 1779 1780

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
1781
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
1782 1783 1784 1785

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1786
	| EQ		{}
unknown's avatar
unknown committed
1787
	| AS		{};
unknown's avatar
unknown committed
1788

unknown's avatar
unknown committed
1789
/*
1790 1791
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
  To use UNTIL, one must use START SLAVE, not SLAVE START.
unknown's avatar
unknown committed
1792 1793
*/

unknown's avatar
unknown committed
1794
slave:
1795 1796 1797 1798 1799 1800 1801 1802 1803 1804
	  START_SYM SLAVE slave_thread_opts 
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_START;
	    lex->type = 0;
	    /* We'll use mi structure for UNTIL options */
	    bzero((char*) &lex->mi, sizeof(lex->mi));
          }
          slave_until
          {}
unknown's avatar
unknown committed
1805 1806 1807 1808 1809 1810
        | STOP_SYM SLAVE slave_thread_opts
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_STOP;
	    lex->type = 0;
          }
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824
	| SLAVE START_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
         }
	| SLAVE STOP_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_STOP;
	   lex->type = 0;
         }
        ;

unknown's avatar
unknown committed
1825

unknown's avatar
unknown committed
1826 1827 1828 1829 1830
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

unknown's avatar
unknown committed
1831
slave_thread_opts:
1832 1833
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
1834
        {}
unknown's avatar
unknown committed
1835
	;
1836 1837

slave_thread_opt_list:
unknown's avatar
unknown committed
1838
	slave_thread_opt
1839 1840
	| slave_thread_opt_list ',' slave_thread_opt
	;
1841 1842

slave_thread_opt:
1843
	/*empty*/	{}
unknown's avatar
unknown committed
1844
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
unknown's avatar
unknown committed
1845
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
unknown's avatar
unknown committed
1846
	;
1847

1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
slave_until:
	/*empty*/	{}
	| UNTIL_SYM slave_until_opts
          {
            LEX *lex=Lex;
            if ((lex->mi.log_file_name || lex->mi.pos) &&
                (lex->mi.relay_log_name || lex->mi.relay_log_pos) ||
                !((lex->mi.log_file_name && lex->mi.pos) ||
                  (lex->mi.relay_log_name && lex->mi.relay_log_pos)))
            {
               send_error(lex->thd, ER_BAD_SLAVE_UNTIL_COND);
               YYABORT;
            }

          }
	;

slave_until_opts:
       master_file_def
       | slave_until_opts ',' master_file_def ;


unknown's avatar
unknown committed
1870 1871 1872 1873 1874
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
unknown's avatar
unknown committed
1875
	table_list FROM TEXT_STRING_sys
unknown's avatar
unknown committed
1876 1877
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1878
        };
unknown's avatar
unknown committed
1879

unknown's avatar
unknown committed
1880 1881 1882 1883 1884
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
unknown's avatar
unknown committed
1885
	table_list TO_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
1886 1887
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1888
        };
unknown's avatar
unknown committed
1889

1890 1891 1892 1893 1894 1895
checksum:
        CHECKSUM_SYM table_or_tables
	{
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECKSUM;
	}
1896 1897
	table_list opt_checksum_type
        {}
1898 1899
	;

1900 1901 1902 1903 1904 1905
opt_checksum_type:
        /* nothing */  { Lex->check_opt.flags= 0; }
	| QUICK        { Lex->check_opt.flags= T_QUICK; }
	| EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; }
        ;

unknown's avatar
unknown committed
1906
repair:
1907
	REPAIR opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1908
	{
unknown's avatar
unknown committed
1909 1910
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
1911
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1912
	   lex->check_opt.init();
unknown's avatar
unknown committed
1913
	}
1914 1915 1916
	table_list opt_mi_repair_type
	{}
	;
unknown's avatar
unknown committed
1917

unknown's avatar
unknown committed
1918
opt_mi_repair_type:
unknown's avatar
unknown committed
1919
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1920
	| mi_repair_types {};
unknown's avatar
unknown committed
1921

unknown's avatar
unknown committed
1922 1923
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
1924
	| mi_repair_type mi_repair_types {};
1925

unknown's avatar
unknown committed
1926
mi_repair_type:
unknown's avatar
unknown committed
1927
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1928
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1929
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
1930 1931

analyze:
1932
	ANALYZE_SYM opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1933
	{
unknown's avatar
unknown committed
1934 1935
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
1936
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1937
	   lex->check_opt.init();
unknown's avatar
unknown committed
1938
	}
1939 1940 1941
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1942 1943

check:
unknown's avatar
unknown committed
1944
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
1945
	{
unknown's avatar
unknown committed
1946 1947 1948
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1949
	}
1950 1951 1952
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1953

unknown's avatar
unknown committed
1954 1955
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1956
	| mi_check_types {};
unknown's avatar
unknown committed
1957 1958 1959

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
1960
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
1961 1962 1963 1964 1965 1966

mi_check_type:
	QUICK      { Lex->check_opt.flags|= T_QUICK; }
	| FAST_SYM { Lex->check_opt.flags|= T_FAST; }
	| MEDIUM_SYM { Lex->check_opt.flags|= T_MEDIUM; }
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1967
	| CHANGED  { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; };
unknown's avatar
unknown committed
1968

unknown's avatar
unknown committed
1969
optimize:
1970
	OPTIMIZE opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1971
	{
unknown's avatar
unknown committed
1972 1973
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
unknown's avatar
unknown committed
1974
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1975
	   lex->check_opt.init();
unknown's avatar
unknown committed
1976
	}
1977 1978 1979
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1980

1981 1982 1983
opt_no_write_to_binlog:
	/* empty */        { $$= 0; }
	| NO_WRITE_TO_BINLOG  { $$= 1; }
1984
	| LOCAL_SYM  { $$= 1; }
1985 1986
	;

1987 1988 1989 1990 1991
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1992 1993 1994
	table_to_table_list
	{}
	;
1995 1996 1997

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
1998
	| table_to_table_list ',' table_to_table;
1999 2000 2001

table_to_table:
	table_ident TO_SYM table_ident
2002
	{
unknown's avatar
unknown committed
2003
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2004
	  SELECT_LEX *sl= lex->current_select;
unknown's avatar
unknown committed
2005 2006 2007 2008
	  if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
				     TL_IGNORE) ||
	      !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
				     TL_IGNORE))
2009
	    YYABORT;
2010
	};
2011

unknown's avatar
unknown committed
2012
keycache:
2013
        CACHE_SYM INDEX keycache_list IN_SYM key_cache_name
unknown's avatar
unknown committed
2014 2015
        {
          LEX *lex=Lex;
2016 2017
          lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
	  lex->name_and_length= $5;
unknown's avatar
unknown committed
2018 2019 2020 2021 2022 2023 2024 2025
        }
        ;

keycache_list:
        assign_to_keycache
        | keycache_list ',' assign_to_keycache;

assign_to_keycache:
2026
        table_ident cache_keys_spec
unknown's avatar
unknown committed
2027 2028 2029 2030 2031 2032
        {
          LEX *lex=Lex;
          SELECT_LEX *sel= &lex->select_lex;
          if (!sel->add_table_to_list(lex->thd, $1, NULL, 0,
                                      TL_READ,
                                      sel->get_use_index(),
2033
                                      (List<String> *)0))
unknown's avatar
unknown committed
2034 2035 2036 2037
            YYABORT;
        }
        ;

2038 2039 2040
key_cache_name:
	ident	   { $$= $1; }
	| DEFAULT  { $$ = default_key_cache_base; }
2041
	;
2042

unknown's avatar
unknown committed
2043
preload:
unknown's avatar
unknown committed
2044
	LOAD INDEX INTO CACHE_SYM
unknown's avatar
unknown committed
2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057
	{
	  LEX *lex=Lex;
	  lex->sql_command=SQLCOM_PRELOAD_KEYS;
	}
	preload_list
	{}
	;

preload_list:
	preload_keys
	| preload_list ',' preload_keys;

preload_keys:
unknown's avatar
unknown committed
2058
	table_ident cache_keys_spec opt_ignore_leaves
unknown's avatar
unknown committed
2059 2060 2061
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
unknown's avatar
unknown committed
2062 2063
	  if (!sel->add_table_to_list(lex->thd, $1, NULL, $3,
                                      TL_READ,
unknown's avatar
unknown committed
2064 2065 2066 2067 2068 2069
                                      sel->get_use_index(),
                                      (List<String> *)0))
            YYABORT;
	}
	;

2070
cache_keys_spec:
2071
        { Select->interval_list.empty(); }
2072 2073 2074 2075 2076 2077 2078
        cache_key_list_or_empty
        {
          LEX *lex=Lex;
          SELECT_LEX *sel= &lex->select_lex;
          sel->use_index= sel->interval_list;
        }
        ;
unknown's avatar
unknown committed
2079

unknown's avatar
unknown committed
2080
cache_key_list_or_empty:
2081 2082 2083 2084 2085 2086
	/* empty */	{ Lex->select_lex.use_index_ptr= 0; }
	| opt_keys_or_index '(' key_usage_list2 ')'
	  {
            SELECT_LEX *sel= &Lex->select_lex;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2087 2088
	;

unknown's avatar
unknown committed
2089
opt_ignore_leaves:
unknown's avatar
unknown committed
2090 2091 2092 2093 2094
	/* empty */
	{ $$= 0; }
	| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
	;

unknown's avatar
unknown committed
2095
/*
unknown's avatar
unknown committed
2096
  Select : retrieve data from table
unknown's avatar
unknown committed
2097 2098 2099 2100
*/


select:
2101 2102 2103 2104 2105
	select_init
	{
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_SELECT;
	  lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
unknown's avatar
unknown committed
2106 2107
	}
	;
unknown's avatar
unknown committed
2108

2109
/* Need select_init2 for subselects. */
unknown's avatar
unknown committed
2110
select_init:
2111
	SELECT_SYM select_init2
2112
	|
2113 2114
	'(' SELECT_SYM select_part2 ')'
	  {
2115
	    LEX *lex= Lex;
unknown's avatar
unknown committed
2116
            SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2117
	    if (sel->set_braces(1))
2118 2119 2120 2121
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
2122 2123
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
2124 2125 2126 2127
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
2128
            /* select in braces, can't contain global parameters */
unknown's avatar
unknown committed
2129 2130 2131
	    if (sel->master_unit()->fake_select_lex)
              sel->master_unit()->global_parameters=
                 sel->master_unit()->fake_select_lex;
unknown's avatar
unknown committed
2132
          } union_opt;
2133

2134 2135
select_init2:
	select_part2
2136
        {
2137
	  LEX *lex= Lex;
unknown's avatar
unknown committed
2138
          SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2139
          if (lex->current_select->set_braces(0))
2140 2141 2142 2143
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
2144 2145
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
2146 2147 2148 2149
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
2150
	}
2151
	union_clause
2152 2153
	;

2154
select_part2:
unknown's avatar
unknown committed
2155 2156
	{
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2157
	  SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2158
	  if (lex->current_select == &lex->select_lex)
2159
	    lex->lock_option= TL_READ; /* Only for global SELECT */
unknown's avatar
unknown committed
2160 2161
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
unknown's avatar
unknown committed
2162 2163 2164 2165 2166
	  lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
	}
	select_options select_item_list
	{
	  Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
unknown's avatar
unknown committed
2167
	}
unknown's avatar
unknown committed
2168
	select_into select_lock_type;
2169

unknown's avatar
unknown committed
2170
select_into:
2171 2172 2173 2174 2175 2176
	opt_limit_clause {}
	| FROM DUAL_SYM /* oracle compatibility: oracle always requires FROM
                           clause, and DUAL is system table without fields.
                           Is "SELECT 1 FROM DUAL" any better than
                           "SELECT 1" ? Hmmm :) */
        | into
unknown's avatar
unknown committed
2177
	| select_from
2178 2179
	| into select_from
	| select_from into;
unknown's avatar
unknown committed
2180 2181

select_from:
2182
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
unknown's avatar
unknown committed
2183 2184 2185

select_options:
	/* empty*/
unknown's avatar
unknown committed
2186
	| select_option_list;
unknown's avatar
unknown committed
2187 2188 2189

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
2190
	| select_option;
unknown's avatar
unknown committed
2191 2192

select_option:
2193
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
2194 2195 2196 2197 2198 2199
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
2200 2201 2202
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
	| SQL_BUFFER_RESULT
	  {
	    if (check_simple_select())
	      YYABORT;
	    Select->options|= OPTION_BUFFER_RESULT;
	  }
	| SQL_CALC_FOUND_ROWS
	  {
	    if (check_simple_select())
	      YYABORT;
	    Select->options|= OPTION_FOUND_ROWS;
	  }
2215
	| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
2216 2217 2218 2219
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
2220 2221
	| ALL		{}
	;
unknown's avatar
unknown committed
2222

unknown's avatar
unknown committed
2223 2224 2225
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
2226 2227
	  {
	    LEX *lex=Lex;
2228
	    lex->current_select->set_lock_for_tables(TL_WRITE);
2229
	    lex->safe_to_cache_query=0;
2230
	  }
unknown's avatar
unknown committed
2231
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2232 2233
	  {
	    LEX *lex=Lex;
2234 2235
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2236
	    lex->safe_to_cache_query=0;
2237 2238
	  }
	;
unknown's avatar
unknown committed
2239

unknown's avatar
unknown committed
2240 2241 2242 2243 2244
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
2245 2246
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
unknown's avatar
unknown committed
2247
	      YYABORT;
unknown's avatar
unknown committed
2248
	    (thd->lex.current_select->with_wild)++;
unknown's avatar
unknown committed
2249
	  };
unknown's avatar
unknown committed
2250 2251 2252 2253 2254


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
unknown's avatar
unknown committed
2255
	    if (add_item_to_list(YYTHD, $2))
unknown's avatar
unknown committed
2256 2257
	      YYABORT;
	    if ($4.str)
unknown's avatar
unknown committed
2258
	      $2->set_name($4.str,$4.length,system_charset_info);
unknown's avatar
unknown committed
2259
	    else if (!$2->name)
unknown's avatar
unknown committed
2260
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
unknown's avatar
unknown committed
2261
	  };
unknown's avatar
unknown committed
2262 2263

remember_name:
unknown's avatar
unknown committed
2264
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
2265 2266

remember_end:
unknown's avatar
unknown committed
2267
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
2268 2269 2270

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
2271
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
2272 2273

select_alias:
unknown's avatar
unknown committed
2274 2275 2276 2277 2278 2279
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
unknown's avatar
unknown committed
2280 2281 2282

optional_braces:
	/* empty */ {}
unknown's avatar
unknown committed
2283
	| '(' ')' {};
unknown's avatar
unknown committed
2284

unknown's avatar
unknown committed
2285
/* all possible expressions */
unknown's avatar
SCRUM  
unknown committed
2286 2287 2288 2289
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
unknown's avatar
unknown committed
2290

unknown's avatar
unknown committed
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302
comp_op:  EQ		{ $$ = &comp_eq_creator; }
	| GE		{ $$ = &comp_ge_creator; }
	| GT_SYM	{ $$ = &comp_gt_creator; }
	| LE		{ $$ = &comp_le_creator; }
	| LT		{ $$ = &comp_lt_creator; }
	| NE		{ $$ = &comp_ne_creator; }
	;

all_or_any: ALL     { $$ = 1; }
        |   ANY_SYM { $$ = 0; }
        ;

unknown's avatar
unknown committed
2303 2304
/* expressions that begin with 'expr' */
expr_expr:
unknown's avatar
SCRUM  
unknown committed
2305
	 expr IN_SYM '(' expr_list ')'
2306
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
unknown's avatar
unknown committed
2307
	| expr NOT IN_SYM '(' expr_list ')'
2308
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
unknown's avatar
unknown committed
2309
        | expr IN_SYM in_subselect
2310
          { $$= new Item_in_subselect($1, $3); }
unknown's avatar
unknown committed
2311
	| expr NOT IN_SYM in_subselect
2312
          {
2313
            $$= new Item_func_not(new Item_in_subselect($1, $4));
unknown's avatar
unknown committed
2314
          }
unknown's avatar
unknown committed
2315 2316 2317 2318
	| expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2319
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2320
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2321
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2322
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2323 2324 2325 2326 2327 2328 2329 2330 2331
	| expr SOUNDS_SYM LIKE expr
	  {
	    $$= new Item_func_eq(new Item_func_soundex($1),
				 new Item_func_soundex($4));
	  }
	| expr LIKE simple_expr opt_escape
          { $$= new Item_func_like($1,$3,$4); }
	| expr NOT LIKE simple_expr opt_escape
          { $$= new Item_func_not(new Item_func_like($1,$4,$5));}
unknown's avatar
unknown committed
2332
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2333 2334
	| expr NOT REGEXP expr
          { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2335 2336 2337
	| expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
unknown's avatar
unknown committed
2338
	| expr comp_op expr %prec EQ	{ $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2339 2340
	| expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2341
	  $$= all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2342
	}
unknown's avatar
unknown committed
2343 2344 2345 2346 2347 2348
	| expr SHIFT_LEFT expr	{ $$= new Item_func_shift_left($1,$3); }
	| expr SHIFT_RIGHT expr { $$= new Item_func_shift_right($1,$3); }
	| expr '+' expr		{ $$= new Item_func_plus($1,$3); }
	| expr '-' expr		{ $$= new Item_func_minus($1,$3); }
	| expr '*' expr		{ $$= new Item_func_mul($1,$3); }
	| expr '/' expr		{ $$= new Item_func_div($1,$3); }
2349 2350
	| expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
	| expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
unknown's avatar
unknown committed
2351
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2352
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2353 2354
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2355 2356 2357 2358
	| expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
unknown's avatar
unknown committed
2359
	;
unknown's avatar
unknown committed
2360 2361 2362 2363 2364 2365 2366

/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
	no_in_expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| no_in_expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2367
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2368
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2369
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2370
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2371 2372 2373 2374 2375 2376 2377 2378 2379
	| no_in_expr SOUNDS_SYM LIKE expr
	  {
	    $$= new Item_func_eq(new Item_func_soundex($1),
				 new Item_func_soundex($4));
	  }
	| no_in_expr LIKE simple_expr opt_escape
	  { $$= new Item_func_like($1,$3,$4); }
	| no_in_expr NOT LIKE simple_expr opt_escape
	  { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
unknown's avatar
unknown committed
2380
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2381 2382
	| no_in_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2383 2384 2385
	| no_in_expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| no_in_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| no_in_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
unknown's avatar
unknown committed
2386
	| no_in_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2387 2388
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2389
	  all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2390
	}
unknown's avatar
unknown committed
2391 2392 2393 2394 2395 2396
	| no_in_expr SHIFT_LEFT expr  { $$= new Item_func_shift_left($1,$3); }
	| no_in_expr SHIFT_RIGHT expr { $$= new Item_func_shift_right($1,$3); }
	| no_in_expr '+' expr		{ $$= new Item_func_plus($1,$3); }
	| no_in_expr '-' expr		{ $$= new Item_func_minus($1,$3); }
	| no_in_expr '*' expr		{ $$= new Item_func_mul($1,$3); }
	| no_in_expr '/' expr		{ $$= new Item_func_div($1,$3); }
2397
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2398
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2399
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2400 2401
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2402
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2403 2404 2405 2406
	| no_in_expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| no_in_expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
unknown's avatar
unknown committed
2407
	| simple_expr;
unknown's avatar
unknown committed
2408 2409 2410

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
unknown's avatar
unknown committed
2411
	  no_and_expr IN_SYM '(' expr_list ')'
2412
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
unknown's avatar
unknown committed
2413
	| no_and_expr NOT IN_SYM '(' expr_list ')'
2414
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
unknown's avatar
unknown committed
2415
        | no_and_expr IN_SYM in_subselect
2416
          { $$= new Item_in_subselect($1, $3); }
unknown's avatar
unknown committed
2417
	| no_and_expr NOT IN_SYM in_subselect
2418
          {
2419
            $$= new Item_func_not(new Item_in_subselect($1, $4));
unknown's avatar
unknown committed
2420
          }
unknown's avatar
unknown committed
2421 2422 2423 2424
	| no_and_expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| no_and_expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2425
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2426
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2427
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2428 2429 2430 2431 2432 2433 2434 2435 2436
	| no_and_expr SOUNDS_SYM LIKE expr
	  {
	    $$= new Item_func_eq(new Item_func_soundex($1),
				 new Item_func_soundex($4));
	  }
	| no_and_expr LIKE simple_expr opt_escape
	  { $$= new Item_func_like($1,$3,$4); }
	| no_and_expr NOT LIKE simple_expr opt_escape
	  { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
unknown's avatar
unknown committed
2437
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2438 2439
	| no_and_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2440 2441 2442
	| no_and_expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| no_and_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| no_and_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
unknown's avatar
unknown committed
2443
	| no_and_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2444 2445
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2446
	  all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2447
	}
unknown's avatar
unknown committed
2448 2449 2450 2451 2452 2453
	| no_and_expr SHIFT_LEFT expr  { $$= new Item_func_shift_left($1,$3); }
	| no_and_expr SHIFT_RIGHT expr { $$= new Item_func_shift_right($1,$3); }
	| no_and_expr '+' expr		{ $$= new Item_func_plus($1,$3); }
	| no_and_expr '-' expr		{ $$= new Item_func_minus($1,$3); }
	| no_and_expr '*' expr		{ $$= new Item_func_mul($1,$3); }
	| no_and_expr '/' expr		{ $$= new Item_func_div($1,$3); }
2454
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2455
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2456
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2457 2458
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2459
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2460 2461 2462 2463
	| no_and_expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| no_and_expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
unknown's avatar
unknown committed
2464
	| simple_expr;
unknown's avatar
unknown committed
2465

2466
interval_expr:
unknown's avatar
unknown committed
2467
         INTERVAL_SYM expr { $$=$2; }
2468 2469
        ;

unknown's avatar
unknown committed
2470 2471
simple_expr:
	simple_ident
2472
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
unknown's avatar
unknown committed
2473
	  {
unknown's avatar
unknown committed
2474 2475 2476 2477
	    $$= new Item_func_set_collation($1,
					    new Item_string($3.str,
							    $3.length,
					    		    YYTHD->charset()));
2478
	  }
unknown's avatar
unknown committed
2479
	| literal
unknown's avatar
unknown committed
2480
	| param_marker
unknown's avatar
unknown committed
2481
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
2482 2483
	  {
	    $$= new Item_func_set_user_var($2,$4);
2484
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2485
	  }
2486
	| '@' ident_or_text
unknown's avatar
unknown committed
2487 2488
	  {
	    $$= new Item_func_get_user_var($2);
2489
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2490
	  }
2491
	| '@' '@' opt_var_ident_type ident_or_text opt_component
unknown's avatar
unknown committed
2492
	  {
2493
	    if (!($$= get_system_var(YYTHD, (enum_var_type) $3, $4, $5)))
unknown's avatar
unknown committed
2494
	      YYABORT;
unknown's avatar
unknown committed
2495
	  }
unknown's avatar
unknown committed
2496
	| sum_expr
2497 2498
	| '+' expr %prec NEG	{ $$= $2; }
	| '-' expr %prec NEG    { $$= new Item_func_neg($2); }
unknown's avatar
unknown committed
2499 2500 2501 2502
	| '~' expr %prec NEG	{ $$= new Item_func_bit_neg($2); }
	| NOT expr %prec NEG	{ $$= new Item_func_not($2); }
	| '!' expr %prec NEG	{ $$= new Item_func_not($2); }
	| '(' expr ')'		{ $$= $2; }
2503 2504 2505 2506 2507
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
2508
	| ROW_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2509
	  {
2510 2511
	    $5->push_front($3);
	    $$= new Item_row(*$5);
unknown's avatar
unknown committed
2512
	  }
unknown's avatar
unknown committed
2513
	| EXISTS exists_subselect { $$= $2; }
unknown's avatar
unknown committed
2514
	| singlerow_subselect   { $$= $1; }
unknown's avatar
unknown committed
2515
	| '{' ident expr '}'	{ $$= $3; }
2516
        | MATCH ident_list_arg AGAINST '(' expr fulltext_options ')'
2517
          { $2->push_front($5);
2518 2519
            Select->add_ftfunc_to_list((Item_func_match*)
                                        ($$=new Item_func_match(*$2,$6))); }
unknown's avatar
unknown committed
2520
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
unknown's avatar
unknown committed
2521
	| BINARY expr %prec NEG
unknown's avatar
unknown committed
2522
	  {
unknown's avatar
unknown committed
2523 2524
	    $$= new Item_func_set_collation($2,new Item_string(binary_keyword,
					    6, &my_charset_latin1));
unknown's avatar
unknown committed
2525
	  }
2526
	| CAST_SYM '(' expr AS cast_type ')'
2527 2528
	  {
	    $$= create_func_cast($3, $5,
2529
				 Lex->length ? atoi(Lex->length) : -1,
2530
				 Lex->charset);
2531
	  }
unknown's avatar
unknown committed
2532
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
2533
	  { $$= new Item_func_case(* $4, $2, $5 ); }
2534
	| CONVERT_SYM '(' expr ',' cast_type ')'
2535 2536 2537 2538 2539
	  {
	    $$= create_func_cast($3, $5,
				 Lex->length ? atoi(Lex->length) : -1,
				 Lex->charset);
	  }
2540 2541
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
2542
	| CONVERT_SYM '(' expr ',' expr ',' expr ')'
2543
	  { $$= new Item_func_conv_charset3($3,$7,$5); }
unknown's avatar
SCRUM  
unknown committed
2544 2545
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
unknown's avatar
unknown committed
2546 2547
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
unknown's avatar
unknown committed
2548 2549 2550 2551 2552 2553 2554 2555
	| FUNC_ARG0 '(' ')'
	  { $$= ((Item*(*)(void))($1.symbol->create_func))();}
	| FUNC_ARG1 '(' expr ')'
	  { $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);}
	| FUNC_ARG2 '(' expr ',' expr ')'
	  { $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);}
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
	  { $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);}
unknown's avatar
unknown committed
2556 2557 2558 2559
	| ADDDATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);}
	| ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3, $6, $7, 0); }
unknown's avatar
unknown committed
2560 2561 2562 2563 2564 2565
	| ATAN	'(' expr ')'
	  { $$= new Item_func_atan($3); }
	| ATAN	'(' expr ',' expr ')'
	  { $$= new Item_func_atan($3,$5); }
	| CHAR_SYM '(' expr_list ')'
	  { $$= new Item_func_char(*$3); }
unknown's avatar
unknown committed
2566 2567
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
2568 2569
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
unknown's avatar
unknown committed
2570 2571
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
unknown's avatar
unknown committed
2572 2573 2574 2575 2576
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
2577
	  { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2578
	| CURTIME optional_braces
2579
	  { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2580
	| CURTIME '(' expr ')'
2581
	  {
2582
	    $$= new Item_func_curtime_local($3);
2583
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2584
	  }
2585 2586 2587 2588
	| DATE_ADD_INTERVAL '(' expr ',' interval_expr interval ')'
	  { $$= new Item_date_add_interval($3,$5,$6,0); }
	| DATE_SUB_INTERVAL '(' expr ',' interval_expr interval ')'
	  { $$= new Item_date_add_interval($3,$5,$6,1); }
unknown's avatar
unknown committed
2589
	| DATABASE '(' ')'
2590
	  {
unknown's avatar
unknown committed
2591
	    $$= new Item_func_database();
2592
            Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2593
	  }
unknown's avatar
unknown committed
2594
	| DATE_SYM '(' expr ')'
unknown's avatar
unknown committed
2595
	  { $$= new Item_date_typecast($3); }
unknown's avatar
unknown committed
2596 2597
	| DAY_SYM '(' expr ')'
	  { $$= new Item_func_dayofmonth($3); }
unknown's avatar
unknown committed
2598
	| ELT_FUNC '(' expr ',' expr_list ')'
2599
	  { $5->push_front($3); $$= new Item_func_elt(*$5); }
unknown's avatar
unknown committed
2600 2601
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
unknown's avatar
unknown committed
2602 2603 2604
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
2605
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2606
	  }
unknown's avatar
unknown committed
2607
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
2608
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2609
	  { $$= new Item_func_decode($3,$5.str); }
2610
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2611
	 { $$= new Item_func_encode($3,$5.str); }
unknown's avatar
unknown committed
2612
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2613
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
2614
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2615
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
2616
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2617
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
2618
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2619
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
2620 2621 2622 2623 2624 2625
	| EXPORT_SET '(' expr ',' expr ',' expr ')'
		{ $$= new Item_func_export_set($3, $5, $7); }
	| EXPORT_SET '(' expr ',' expr ',' expr ',' expr ')'
		{ $$= new Item_func_export_set($3, $5, $7, $9); }
	| EXPORT_SET '(' expr ',' expr ',' expr ',' expr ',' expr ')'
		{ $$= new Item_func_export_set($3, $5, $7, $9, $11); }
2626 2627
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
2628 2629 2630 2631 2632 2633
	| FORMAT_SYM '(' expr ',' NUM ')'
	  { $$= new Item_func_format($3,atoi($5.str)); }
	| FROM_UNIXTIME '(' expr ')'
	  { $$= new Item_func_from_unixtime($3); }
	| FROM_UNIXTIME '(' expr ',' expr ')'
	  {
unknown's avatar
unknown committed
2634
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2635 2636
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
2637
	  { $5->push_front($3); $$= new Item_func_field(*$5); }
unknown's avatar
unknown committed
2638
	| GEOMFROMTEXT '(' expr ')'
2639
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2640
	| GEOMFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2641 2642 2643 2644 2645
	  { $$= new Item_func_geometry_from_text($3, $5); }
	| GEOMFROMWKB '(' expr ')'
	  { $$= new Item_func_geometry_from_wkb($3); }
	| GEOMFROMWKB '(' expr ',' expr ')'
	  { $$= new Item_func_geometry_from_wkb($3, $5); }
unknown's avatar
unknown committed
2646
	| GEOMETRYCOLLECTION '(' expr_list ')'
2647 2648
	  { $$= new Item_func_spatial_collection(* $3,
                       Geometry::wkbGeometryCollection,
unknown's avatar
unknown committed
2649
                       Geometry::wkbPoint); }
2650
	| GET_FORMAT '(' date_time_type  ',' expr ')'
2651
	  { $$= new Item_func_get_format($3, $5); }
unknown's avatar
unknown committed
2652 2653 2654 2655 2656 2657
	| HOUR_SYM '(' expr ')'
	  { $$= new Item_func_hour($3); }
	| IF '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_if($3,$5,$7); }
	| INSERT '(' expr ',' expr ',' expr ',' expr ')'
	  { $$= new Item_func_insert($3,$5,$7,$9); }
2658
	| interval_expr interval '+' expr
unknown's avatar
unknown committed
2659
	  /* we cannot put interval before - */
2660 2661 2662 2663 2664 2665 2666 2667 2668 2669
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
              send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
unknown's avatar
unknown committed
2670 2671
	| LAST_INSERT_ID '(' ')'
	  {
2672
	    $$= get_system_var(YYTHD, OPT_SESSION, "last_insert_id", 14,
2673
			      "last_insert_id()");
2674
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2675 2676 2677 2678
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
2679
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2680 2681 2682
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
unknown's avatar
unknown committed
2683
	| LINESTRING '(' expr_list ')'
2684
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2685
               Geometry::wkbLineString, Geometry::wkbPoint); }
unknown's avatar
unknown committed
2686 2687 2688 2689
	| LOCATE '(' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3); }
	| LOCATE '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3,$7); }
unknown's avatar
unknown committed
2690
 	| GEOMCOLLFROMTEXT '(' expr ')'
2691
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2692
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2693
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2694
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2695 2696 2697
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
2698
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
2699
	  { $$= new Item_func_log($3); }
2700
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2701
	  { $$= new Item_func_log($3, $5); }
unknown's avatar
unknown committed
2702
 	| LINEFROMTEXT '(' expr ')'
2703
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2704
	| LINEFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2705
	  { $$= new Item_func_geometry_from_text($3, $5); }
2706
	| MASTER_POS_WAIT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2707
	  {
2708
	    $$= new Item_master_pos_wait($3, $5);
unknown's avatar
unknown committed
2709
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2710
		  }
2711
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
unknown's avatar
unknown committed
2712
	  {
2713
	    $$= new Item_master_pos_wait($3, $5, $7);
unknown's avatar
unknown committed
2714
	    Lex->safe_to_cache_query=0;
2715
	  }
unknown's avatar
unknown committed
2716 2717
	| MICROSECOND_SYM '(' expr ')'
	  { $$= new Item_func_microsecond($3); }
unknown's avatar
unknown committed
2718 2719
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
2720 2721
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
2722 2723
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
unknown's avatar
unknown committed
2724
 	| MULTILINESTRING '(' expr_list ')'
2725
 	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2726
                    Geometry::wkbMultiLineString, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2727
 	| MLINEFROMTEXT '(' expr ')'
2728
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2729
	| MLINEFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2730
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2731
	| MPOINTFROMTEXT '(' expr ')'
2732
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2733
	| MPOINTFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2734
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2735
	| MPOLYFROMTEXT '(' expr ')'
2736
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2737
	| MPOLYFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2738
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2739
	| MULTIPOINT '(' expr_list ')'
2740
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2741 2742
                    Geometry::wkbMultiPoint, Geometry::wkbPoint); }
 	| MULTIPOLYGON '(' expr_list ')'
2743
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2744
                       Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
unknown's avatar
unknown committed
2745
	| NOW_SYM optional_braces
2746
	  { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2747
	| NOW_SYM '(' expr ')'
2748
	  { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2749
	| PASSWORD '(' expr ')'
2750
	  {
2751 2752
	    $$= YYTHD->variables.old_passwords ?
              (Item *) new Item_func_old_password($3) :
unknown's avatar
unknown committed
2753 2754 2755 2756
	      (Item *) new Item_func_password($3);
	  }
	| OLD_PASSWORD '(' expr ')'
	  { $$=  new Item_func_old_password($3); }
2757
	| POINT_SYM '(' expr ',' expr ')'
2758
	  { $$= new Item_func_point($3,$5); }
unknown's avatar
unknown committed
2759
 	| POINTFROMTEXT '(' expr ')'
2760
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2761
	| POINTFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2762
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2763
	| POLYFROMTEXT '(' expr ')'
2764
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2765
	| POLYFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2766
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2767
	| POLYGON '(' expr_list ')'
2768
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2769
			Geometry::wkbPolygon, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2770 2771
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
2772
	| RAND '(' expr ')'
2773
	  { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
unknown's avatar
unknown committed
2774
	| RAND '(' ')'
2775
	  { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
unknown's avatar
unknown committed
2776 2777 2778 2779 2780 2781 2782
	| REPLACE '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_replace($3,$5,$7); }
	| RIGHT '(' expr ',' expr ')'
	  { $$= new Item_func_right($3,$5); }
	| ROUND '(' expr ')'
	  { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
	| ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
unknown's avatar
unknown committed
2783 2784 2785 2786
	| SUBDATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);}
	| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3, $6, $7, 1); }
unknown's avatar
unknown committed
2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798
	| SECOND_SYM '(' expr ')'
	  { $$= new Item_func_second($3); }
	| SUBSTRING '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_substr($3,$5,$7); }
	| SUBSTRING '(' expr ',' expr ')'
	  { $$= new Item_func_substr($3,$5); }
	| SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
	  { $$= new Item_func_substr($3,$5,$7); }
	| SUBSTRING '(' expr FROM expr ')'
	  { $$= new Item_func_substr($3,$5); }
	| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_substr_index($3,$5,$7); }
unknown's avatar
unknown committed
2799
	| TIME_SYM '(' expr ')'
unknown's avatar
unknown committed
2800 2801 2802
	  { $$= new Item_time_typecast($3); }
	| TIMESTAMP '(' expr ')'
	  { $$= new Item_datetime_typecast($3); }
unknown's avatar
unknown committed
2803
	| TIMESTAMP '(' expr ',' expr ')'
unknown's avatar
unknown committed
2804
	  { $$= new Item_func_add_time($3, $5, 1, 0); }
unknown's avatar
unknown committed
2805
	| TRIM '(' expr ')'
2806 2807
	  { $$= new Item_func_trim($3); }
	| TRIM '(' LEADING expr FROM expr ')'
unknown's avatar
unknown committed
2808
	  { $$= new Item_func_ltrim($6,$4); }
2809
	| TRIM '(' TRAILING expr FROM expr ')'
unknown's avatar
unknown committed
2810
	  { $$= new Item_func_rtrim($6,$4); }
2811
	| TRIM '(' BOTH expr FROM expr ')'
unknown's avatar
unknown committed
2812
	  { $$= new Item_func_trim($6,$4); }
2813 2814 2815 2816 2817 2818
	| TRIM '(' LEADING FROM expr ')'
	 { $$= new Item_func_ltrim($5); }
	| TRIM '(' TRAILING FROM expr ')'
	  { $$= new Item_func_rtrim($5); }
	| TRIM '(' BOTH FROM expr ')'
	  { $$= new Item_func_trim($5); }
unknown's avatar
unknown committed
2819 2820
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
2821 2822
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
2823 2824
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
	| UDA_CHAR_SUM '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_sum_udf_str($1, *$3);
	    else
	      $$ = new Item_sum_udf_str($1);
	  }
	| UDA_FLOAT_SUM '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_sum_udf_float($1, *$3);
	    else
	      $$ = new Item_sum_udf_float($1);
	  }
	| UDA_INT_SUM '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_sum_udf_int($1, *$3);
	    else
	      $$ = new Item_sum_udf_int($1);
	  }
	| UDF_CHAR_FUNC '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_func_udf_str($1, *$3);
	    else
	      $$ = new Item_func_udf_str($1);
	  }
	| UDF_FLOAT_FUNC '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_func_udf_float($1, *$3);
	    else
	      $$ = new Item_func_udf_float($1);
	  }
	| UDF_INT_FUNC '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_func_udf_int($1, *$3);
	    else
	      $$ = new Item_func_udf_int($1);
	  }
	| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
2868
	  {
unknown's avatar
unknown committed
2869 2870
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
2871
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
2872 2873
	  {
	    $$= new Item_func_unix_timestamp();
2874
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2875
	  }
unknown's avatar
unknown committed
2876 2877 2878
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
2879
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
2880 2881 2882 2883 2884 2885
	| UTC_DATE_SYM optional_braces
	  { $$= new Item_func_curdate_utc(); Lex->safe_to_cache_query=0;}
	| UTC_TIME_SYM optional_braces
	  { $$= new Item_func_curtime_utc(); Lex->safe_to_cache_query=0;}
	| UTC_TIMESTAMP_SYM optional_braces
	  { $$= new Item_func_now_utc(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2886
	| WEEK_SYM '(' expr ')'
unknown's avatar
unknown committed
2887
	  {
2888
            $$= new Item_func_week($3,new Item_int((char*) "0",
unknown's avatar
unknown committed
2889
				   YYTHD->variables.default_week_format,1));
2890
          }
unknown's avatar
unknown committed
2891 2892 2893 2894 2895 2896 2897 2898 2899
	| WEEK_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_week($3,$5); }
	| YEAR_SYM '(' expr ')'
	  { $$= new Item_func_year($3); }
	| YEARWEEK '(' expr ')'
	  { $$= new Item_func_yearweek($3,new Item_int((char*) "0",0,1)); }
	| YEARWEEK '(' expr ',' expr ')'
	  { $$= new Item_func_yearweek($3, $5); }
	| BENCHMARK_SYM '(' ULONG_NUM ',' expr ')'
2900
	  {
unknown's avatar
unknown committed
2901
	    $$=new Item_func_benchmark($3,$5);
2902
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
2903
	  }
unknown's avatar
unknown committed
2904
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
2905
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
2906

2907 2908 2909 2910 2911 2912
fulltext_options:
        /* nothing */                   { $$= FT_NL;  }
        | WITH QUERY_SYM EXPANSION_SYM  { $$= FT_NL | FT_EXPAND; }
        | IN_SYM BOOLEAN_SYM MODE_SYM   { $$= FT_BOOL; }
        ;

unknown's avatar
unknown committed
2913 2914
udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
2915
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
2916 2917 2918 2919 2920 2921 2922 2923

sum_expr:
	AVG_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_avg($3); }
	| BIT_AND  '(' in_sum_expr ')'
	  { $$=new Item_sum_and($3); }
	| BIT_OR  '(' in_sum_expr ')'
	  { $$=new Item_sum_or($3); }
2924 2925
	| BIT_XOR  '(' in_sum_expr ')'
	  { $$=new Item_sum_xor($3); }
unknown's avatar
unknown committed
2926
	| COUNT_SYM '(' opt_all '*' ')'
unknown's avatar
unknown committed
2927 2928 2929
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
2930
	| COUNT_SYM '(' DISTINCT
unknown's avatar
unknown committed
2931
	  { Select->in_sum_expr++; }
2932
	   expr_list
unknown's avatar
unknown committed
2933
	  { Select->in_sum_expr--; }
2934 2935
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
unknown's avatar
unknown committed
2936 2937 2938 2939 2940 2941 2942 2943
	| GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
	  { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
	| MIN_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_min($3); }
	| MAX_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_max($3); }
	| STD_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_std($3); }
unknown's avatar
unknown committed
2944 2945
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
unknown's avatar
unknown committed
2946
	| SUM_SYM '(' in_sum_expr ')'
2947
	  { $$=new Item_sum_sum($3); }
unknown's avatar
unknown committed
2948 2949 2950 2951
	| GROUP_CONCAT_SYM '(' opt_distinct expr_list opt_gorder_clause
	  opt_gconcat_separator ')'
	  {
	    $$=new Item_func_group_concat($3,$4,Lex->gorder_list,$6);
2952 2953 2954 2955 2956 2957 2958 2959
	    $4->empty();
	  };

opt_distinct:
    /* empty */ { $$ = 0; }
    |DISTINCT   { $$ = 1; };

opt_gconcat_separator:
2960
    /* empty */        { $$ = new String(",",1,default_charset_info); }
2961
    |SEPARATOR_SYM text_string  { $$ = $2; };
unknown's avatar
unknown committed
2962

2963 2964

opt_gorder_clause:
2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977
	  /* empty */
	  {
            LEX *lex=Lex;
            lex->gorder_list = NULL;
	  }
	| order_clause
          {
            LEX *lex=Lex;
            lex->gorder_list= 
	      (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,
				     sizeof(st_sql_list));
	    lex->current_select->order_list.empty();
	  };
unknown's avatar
unknown committed
2978

unknown's avatar
unknown committed
2979 2980

in_sum_expr:
unknown's avatar
unknown committed
2981
	opt_all
2982 2983 2984 2985 2986
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
2987
	    YYABORT;
2988 2989
	  }
	}
unknown's avatar
unknown committed
2990 2991
	expr
	{
unknown's avatar
unknown committed
2992
	  Select->in_sum_expr--;
2993
	  $$= $3;
unknown's avatar
unknown committed
2994
	};
unknown's avatar
unknown committed
2995

2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012
cast_type_init:
	{ Lex->charset= NULL; Lex->length= (char*)0; }
	;

cast_type_finalize:
	BINARY			{ $$=ITEM_CAST_BINARY; }
	| CHAR_SYM opt_len opt_binary	{ $$=ITEM_CAST_CHAR; }
	| NCHAR_SYM opt_len	{ $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; }
	| SIGNED_SYM		{ $$=ITEM_CAST_SIGNED_INT; }
	| SIGNED_SYM INT_SYM	{ $$=ITEM_CAST_SIGNED_INT; }
	| UNSIGNED		{ $$=ITEM_CAST_UNSIGNED_INT; }
	| UNSIGNED INT_SYM	{ $$=ITEM_CAST_UNSIGNED_INT; }
	| DATE_SYM		{ $$=ITEM_CAST_DATE; }
	| TIME_SYM		{ $$=ITEM_CAST_TIME; }
	| DATETIME		{ $$=ITEM_CAST_DATETIME; }
	;

unknown's avatar
unknown committed
3013
cast_type:
3014
	cast_type_init cast_type_finalize { $$= $2; }
3015
	;
unknown's avatar
unknown committed
3016

unknown's avatar
unknown committed
3017
expr_list:
3018
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3019
	expr_list2
unknown's avatar
unknown committed
3020
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
3021 3022

expr_list2:
3023
	expr { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
3024
	| expr_list2 ',' expr { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
3025

unknown's avatar
unknown committed
3026 3027
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
3028
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
3029

unknown's avatar
unknown committed
3030
ident_list:
3031
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3032
        ident_list2
unknown's avatar
unknown committed
3033
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
3034 3035

ident_list2:
3036
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
3037
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
3038 3039 3040

opt_expr:
	/* empty */      { $$= NULL; }
3041
	| expr           { $$= $1; };
unknown's avatar
unknown committed
3042 3043 3044

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
3045
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
3046 3047

when_list:
unknown's avatar
unknown committed
3048
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3049
	when_list2
unknown's avatar
unknown committed
3050
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
3051 3052

when_list2:
unknown's avatar
unknown committed
3053
	expr THEN_SYM expr
unknown's avatar
unknown committed
3054
	  {
unknown's avatar
unknown committed
3055
	    SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
3056 3057
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
3058
	}
unknown's avatar
unknown committed
3059
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
3060
	  {
unknown's avatar
unknown committed
3061
	    SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
3062 3063
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
3064
	  };
unknown's avatar
unknown committed
3065 3066 3067 3068

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
unknown's avatar
unknown committed
3069
	| join_table_list ',' join_table_list { $$=$3; }
3070
	| join_table_list normal_join join_table_list { $$=$3; }
3071
	| join_table_list STRAIGHT_JOIN join_table_list
3072
	  { $$=$3 ; $1->next->straight=1; }
unknown's avatar
unknown committed
3073 3074 3075
	| join_table_list normal_join join_table_list ON expr
	  { add_join_on($3,$5); $$=$3; }
	| join_table_list normal_join join_table_list
unknown's avatar
unknown committed
3076
	  USING
unknown's avatar
unknown committed
3077
	  {
unknown's avatar
unknown committed
3078
	    SELECT_LEX *sel= Select;
3079
	    sel->db1=$1->db; sel->table1=$1->alias;
unknown's avatar
unknown committed
3080
	    sel->db2=$3->db; sel->table2=$3->alias;
unknown's avatar
unknown committed
3081
	  }
unknown's avatar
unknown committed
3082 3083 3084
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

3085
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
3086
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
3087
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
3088
	  {
unknown's avatar
unknown committed
3089
	    SELECT_LEX *sel= Select;
3090 3091
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
3092
	  }
unknown's avatar
unknown committed
3093
	  USING '(' using_list ')'
3094
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
3095
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
3096 3097 3098 3099 3100
	  {
	    add_join_natural($1,$1->next);
	    $1->next->outer_join|=JOIN_TYPE_LEFT;
	    $$=$6;
	  }
3101
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
3102
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
3103
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
3104
	  {
unknown's avatar
unknown committed
3105
	    SELECT_LEX *sel= Select;
3106 3107
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
3108
	  }
3109
	  USING '(' using_list ')'
3110
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
3111
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
3112 3113 3114 3115 3116
	  {
	    add_join_natural($1->next,$1);
	    $1->outer_join|=JOIN_TYPE_RIGHT;
	    $$=$6;
	  }
3117
	| join_table_list NATURAL JOIN_SYM join_table_list
3118
	  { add_join_natural($1,$1->next); $$=$4; };
unknown's avatar
unknown committed
3119 3120

normal_join:
unknown's avatar
unknown committed
3121 3122 3123 3124
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
unknown's avatar
unknown committed
3125 3126

join_table:
unknown's avatar
unknown committed
3127
	{
unknown's avatar
unknown committed
3128
	  SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3129
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
unknown's avatar
unknown committed
3130
	  sel->table_join_options= 0;
unknown's avatar
unknown committed
3131
	}
unknown's avatar
unknown committed
3132
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
3133
	{
unknown's avatar
unknown committed
3134
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3135
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
3136
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
unknown's avatar
unknown committed
3137
					   sel->get_table_join_options(),
unknown's avatar
unknown committed
3138
					   lex->lock_option,
3139 3140
					   sel->get_use_index(),
					   sel->get_ignore_index())))
3141
	    YYABORT;
unknown's avatar
unknown committed
3142
	}
unknown's avatar
unknown committed
3143
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
3144
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
3145
        | '(' SELECT_SYM select_derived ')' opt_table_alias
unknown's avatar
unknown committed
3146 3147
	{
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3148 3149
	  if (lex->sql_command == SQLCOM_UPDATE &&
	      &lex->select_lex == lex->current_select->outer_select())
3150 3151 3152 3153 3154
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }

3155 3156 3157
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
unknown's avatar
unknown committed
3158
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
3159
				  TL_READ,(List<String> *)0,
unknown's avatar
unknown committed
3160 3161
	                          (List<String> *)0)))

unknown's avatar
unknown committed
3162
	    YYABORT;
unknown's avatar
unknown committed
3163
	};
unknown's avatar
unknown committed
3164

3165
select_derived:
unknown's avatar
unknown committed
3166
        {
unknown's avatar
unknown committed
3167
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3168
	  lex->derived_tables= 1;
unknown's avatar
unknown committed
3169 3170 3171
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
3172 3173 3174 3175
	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
3176
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
unknown's avatar
unknown committed
3177
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
3178 3179
	    YYABORT;
	  mysql_init_select(lex);
3180
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
unknown's avatar
unknown committed
3181
	}
3182
        select_options select_item_list opt_select_from union_opt
3183
        ;
unknown's avatar
unknown committed
3184 3185 3186

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
3187
	| OUTER		{};
unknown's avatar
unknown committed
3188 3189 3190 3191

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
3192
          {
unknown's avatar
unknown committed
3193
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3194 3195 3196
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
3197 3198
	| FORCE_SYM key_usage_list
          {
unknown's avatar
unknown committed
3199
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3200 3201 3202 3203
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
unknown's avatar
unknown committed
3204
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
3205
	  {
unknown's avatar
unknown committed
3206
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3207 3208
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
3209
	  };
unknown's avatar
unknown committed
3210 3211

key_usage_list:
unknown's avatar
unknown committed
3212
	key_or_index { Select->interval_list.empty(); }
unknown's avatar
unknown committed
3213
        '(' key_list_or_empty ')'
unknown's avatar
unknown committed
3214
        { $$= &Select->interval_list; }
unknown's avatar
unknown committed
3215 3216 3217 3218 3219 3220
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
unknown's avatar
unknown committed
3221 3222 3223

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
3224
        { Select->
3225
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
3226
				    system_charset_info)); }
unknown's avatar
unknown committed
3227
	| ident
unknown's avatar
unknown committed
3228
        { Select->
3229
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
3230
				    system_charset_info)); }
unknown's avatar
unknown committed
3231
	| PRIMARY_SYM
unknown's avatar
unknown committed
3232
        { Select->
3233
	    interval_list.push_back(new String("PRIMARY", 7,
3234
				    system_charset_info)); };
unknown's avatar
unknown committed
3235 3236 3237

using_list:
	ident
unknown's avatar
unknown committed
3238
	  {
unknown's avatar
unknown committed
3239
	    SELECT_LEX *sel= Select;
3240 3241 3242 3243
	    if (!($$= new Item_func_eq(new Item_field(sel->db1, sel->table1,
						      $1.str),
				       new Item_field(sel->db2, sel->table2,
						      $1.str))))
unknown's avatar
unknown committed
3244 3245 3246 3247
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
3248
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3249
	    if (!($$= new Item_cond_and(new Item_func_eq(new Item_field(sel->db1,sel->table1,$3.str), new Item_field(sel->db2,sel->table2,$3.str)), $1)))
unknown's avatar
unknown committed
3250
	      YYABORT;
unknown's avatar
unknown committed
3251
	  };
unknown's avatar
unknown committed
3252 3253 3254

interval:
	 DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
unknown's avatar
unknown committed
3255
	| DAY_MICROSECOND_SYM	{ $$=INTERVAL_DAY_MICROSECOND; }
unknown's avatar
unknown committed
3256 3257 3258
	| DAY_MINUTE_SYM	{ $$=INTERVAL_DAY_MINUTE; }
	| DAY_SECOND_SYM	{ $$=INTERVAL_DAY_SECOND; }
	| DAY_SYM		{ $$=INTERVAL_DAY; }
unknown's avatar
unknown committed
3259
	| HOUR_MICROSECOND_SYM	{ $$=INTERVAL_HOUR_MICROSECOND; }
unknown's avatar
unknown committed
3260 3261 3262
	| HOUR_MINUTE_SYM	{ $$=INTERVAL_HOUR_MINUTE; }
	| HOUR_SECOND_SYM	{ $$=INTERVAL_HOUR_SECOND; }
	| HOUR_SYM		{ $$=INTERVAL_HOUR; }
unknown's avatar
unknown committed
3263 3264
	| MICROSECOND_SYM	{ $$=INTERVAL_MICROSECOND; }
	| MINUTE_MICROSECOND_SYM	{ $$=INTERVAL_MINUTE_MICROSECOND; }
unknown's avatar
unknown committed
3265 3266 3267
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
unknown's avatar
unknown committed
3268
	| SECOND_MICROSECOND_SYM	{ $$=INTERVAL_SECOND_MICROSECOND; }
unknown's avatar
unknown committed
3269 3270
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
	| YEAR_MONTH_SYM	{ $$=INTERVAL_YEAR_MONTH; }
unknown's avatar
unknown committed
3271
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
unknown's avatar
unknown committed
3272

3273 3274 3275 3276
date_time_type:
	DATE_SYM		{$$=TIMESTAMP_DATE;}
	| TIME_SYM		{$$=TIMESTAMP_TIME;}
	| DATETIME		{$$=TIMESTAMP_DATETIME;};
3277

unknown's avatar
unknown committed
3278 3279 3280
table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
3281
	| EQ;
unknown's avatar
unknown committed
3282 3283 3284 3285

opt_table_alias:
	/* empty */		{ $$=0; }
	| table_alias ident
unknown's avatar
unknown committed
3286
	  { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); };
unknown's avatar
unknown committed
3287

unknown's avatar
unknown committed
3288 3289 3290 3291
opt_all:
	/* empty */
	| ALL
	;
unknown's avatar
unknown committed
3292 3293

where_clause:
unknown's avatar
unknown committed
3294
	/* empty */  { Select->where= 0; }
3295 3296
	| WHERE expr
	  {
unknown's avatar
unknown committed
3297
	    Select->where= $2;
3298 3299 3300
	    if ($2)
	      $2->top_level_item();
	  }
unknown's avatar
unknown committed
3301
 	;
unknown's avatar
unknown committed
3302 3303 3304

having_clause:
	/* empty */
unknown's avatar
unknown committed
3305 3306
	| HAVING
	  {
unknown's avatar
unknown committed
3307
	    Select->parsing_place= SELECT_LEX_NODE::IN_HAVING;
unknown's avatar
unknown committed
3308 3309
          }
	  expr
unknown's avatar
unknown committed
3310
	  {
unknown's avatar
unknown committed
3311
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3312 3313
	    sel->having= $3;
	    sel->parsing_place= SELECT_LEX_NODE::NO_MATTER;
unknown's avatar
unknown committed
3314 3315 3316
	    if ($3)
	      $3->top_level_item();
	  }
3317
	;
unknown's avatar
unknown committed
3318 3319

opt_escape:
3320
	ESCAPE_SYM TEXT_STRING_literal	{ $$= $2.str; }
unknown's avatar
unknown committed
3321
	| /* empty */			{ $$= (char*) "\\"; };
unknown's avatar
unknown committed
3322 3323 3324


/*
unknown's avatar
unknown committed
3325
   group by statement in select
unknown's avatar
unknown committed
3326 3327 3328 3329
*/

group_clause:
	/* empty */
3330
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
3331 3332

group_list:
unknown's avatar
unknown committed
3333
	group_list ',' order_ident order_dir
unknown's avatar
unknown committed
3334
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3335
	| order_ident order_dir
unknown's avatar
unknown committed
3336
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3337

3338 3339
olap_opt:
	/* empty */ {}
3340
	| WITH CUBE_SYM
3341
          {
3342
	    LEX *lex=Lex;
3343 3344 3345 3346 3347 3348
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE",
		       "global union parameters");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3349
	    lex->current_select->olap= CUBE_TYPE;
3350
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
3351
	    YYABORT;	/* To be deleted in 5.1 */
3352
	  }
3353
	| WITH ROLLUP_SYM
3354
          {
3355 3356 3357 3358 3359 3360 3361
	    LEX *lex= Lex;
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP",
		       "global union parameters");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3362
	    lex->current_select->olap= ROLLUP_TYPE;
3363
	  }
3364
	;
3365

unknown's avatar
unknown committed
3366
/*
unknown's avatar
unknown committed
3367
   Order by statement in select
unknown's avatar
unknown committed
3368 3369
*/

3370
opt_order_clause:
unknown's avatar
unknown committed
3371
	/* empty */
unknown's avatar
unknown committed
3372
	| order_clause;
3373 3374

order_clause:
3375 3376
	ORDER_SYM BY
        {
unknown's avatar
unknown committed
3377
	  LEX *lex=Lex;
3378
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
3379
	      lex->current_select->olap !=
3380
	      UNSPECIFIED_OLAP_TYPE)
3381
	  {
3382
	    net_printf(lex->thd, ER_WRONG_USAGE,
3383 3384 3385 3386
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
3387
	} order_list;
unknown's avatar
unknown committed
3388 3389 3390

order_list:
	order_list ',' order_ident order_dir
unknown's avatar
unknown committed
3391
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3392
	| order_ident order_dir
unknown's avatar
unknown committed
3393
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3394 3395 3396

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
3397
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
3398
	| DESC { $$ =0; };
unknown's avatar
unknown committed
3399 3400


3401 3402 3403
opt_limit_clause_init:
	/* empty */
	{
unknown's avatar
unknown committed
3404
	  SELECT_LEX *sel= Select;
3405 3406 3407
          sel->offset_limit= 0L;
          sel->select_limit= Lex->thd->variables.select_limit;
	}
3408 3409 3410
	| limit_clause {}
	;

3411 3412 3413 3414 3415
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

3416
limit_clause:
3417
	LIMIT limit_options {}
unknown's avatar
unknown committed
3418
	;
unknown's avatar
unknown committed
3419 3420 3421

limit_options:
	ULONG_NUM
unknown's avatar
unknown committed
3422
	  {
unknown's avatar
unknown committed
3423
            SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3424 3425 3426 3427 3428
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
unknown's avatar
unknown committed
3429
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3430 3431
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
unknown's avatar
unknown committed
3432
	  }
unknown's avatar
unknown committed
3433
	| ULONG_NUM OFFSET_SYM ULONG_NUM
unknown's avatar
unknown committed
3434
	  {
unknown's avatar
unknown committed
3435
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3436 3437 3438 3439
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
unknown's avatar
unknown committed
3440 3441 3442 3443 3444


delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
3445
	  LEX *lex=Lex;
3446
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
3447
	}
unknown's avatar
unknown committed
3448
	| LIMIT ulonglong_num
unknown's avatar
unknown committed
3449
	{ Select->select_limit= (ha_rows) $2; };
unknown's avatar
unknown committed
3450 3451

ULONG_NUM:
unknown's avatar
unknown committed
3452
	NUM	    { $$= strtoul($1.str,NULL,10); }
3453
	| LONG_NUM  { $$= (ulong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3454
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3455
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3456
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
unknown's avatar
unknown committed
3457

unknown's avatar
unknown committed
3458
ulonglong_num:
unknown's avatar
unknown committed
3459
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3460
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
3461
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3462
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3463
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
unknown's avatar
unknown committed
3464 3465 3466 3467 3468 3469

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
3470 3471 3472 3473 3474 3475 3476
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3477 3478 3479
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
unknown's avatar
unknown committed
3480
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
unknown's avatar
unknown committed
3481
	      YYABORT;
3482
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3483
	  }
unknown's avatar
unknown committed
3484
	  '(' procedure_list ')';
unknown's avatar
unknown committed
3485 3486 3487 3488


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
3489
	| procedure_list2 {};
unknown's avatar
unknown committed
3490 3491 3492

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
3493
	| procedure_item;
unknown's avatar
unknown committed
3494 3495 3496 3497

procedure_item:
	  remember_name expr
	  {
unknown's avatar
unknown committed
3498 3499
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
unknown's avatar
unknown committed
3500 3501
	      YYABORT;
	    if (!$2->name)
unknown's avatar
unknown committed
3502
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
3503 3504 3505 3506 3507 3508
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
3509 3510
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3511 3512
	        YYABORT;
	   }
3513
	   select_var_list
3514
	   {}
3515
           ;
unknown's avatar
unknown committed
3516

unknown's avatar
unknown committed
3517
select_var_list:
3518 3519 3520 3521 3522
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
3523
           {
3524
             LEX *lex=Lex;
unknown's avatar
unknown committed
3525
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
3526 3527
	       YYABORT;
	   }
unknown's avatar
unknown committed
3528
           ;
unknown's avatar
unknown committed
3529

3530
into:
unknown's avatar
unknown committed
3531
        INTO OUTFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3532
	{
3533
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3534 3535
	  if (!lex->describe)
	  {
3536
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3537 3538 3539 3540 3541
	    if (!(lex->exchange= new sql_exchange($3.str,0)))
	      YYABORT;
	    if (!(lex->result= new select_export(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3542 3543
	}
	opt_field_term opt_line_term
unknown's avatar
unknown committed
3544
	| INTO DUMPFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3545
	{
3546
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3547 3548
	  if (!lex->describe)
	  {
3549
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3550 3551 3552 3553 3554
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3555
	}
3556
        | INTO select_var_list_init
unknown's avatar
unknown committed
3557
	{
3558
	  Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
3559 3560
	}
        ;
unknown's avatar
unknown committed
3561

unknown's avatar
unknown committed
3562 3563 3564
/*
  DO statement
*/
unknown's avatar
unknown committed
3565

3566
do:	DO_SYM
unknown's avatar
unknown committed
3567 3568 3569 3570 3571 3572
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
3573 3574 3575 3576
	values
	{}
	;

unknown's avatar
unknown committed
3577
/*
3578
  Drop : delete tables or index or user
unknown's avatar
unknown committed
3579 3580 3581
*/

drop:
unknown's avatar
unknown committed
3582
	DROP opt_temporary table_or_tables if_exists table_list opt_restrict
unknown's avatar
unknown committed
3583
	{
unknown's avatar
unknown committed
3584 3585
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3586 3587
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
unknown's avatar
unknown committed
3588 3589 3590
	}
	| DROP INDEX ident ON table_ident {}
	  {
unknown's avatar
unknown committed
3591 3592 3593 3594
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
	     lex->drop_list.empty();
	     lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
unknown's avatar
unknown committed
3595
						     $3.str));
unknown's avatar
unknown committed
3596 3597
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3598 3599 3600 3601
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
3602 3603 3604 3605
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
3606
	 }
unknown's avatar
unknown committed
3607
	| DROP UDF_SYM IDENT_sys
unknown's avatar
unknown committed
3608
	  {
unknown's avatar
unknown committed
3609 3610
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3611
	    lex->udf.name = $3;
3612 3613 3614 3615 3616 3617
	  }
	| DROP USER
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_USER;
	    lex->users_list.empty();
unknown's avatar
unknown committed
3618
	  }
3619 3620 3621
	  user_list
	  {}
	  ;
unknown's avatar
unknown committed
3622 3623 3624


table_list:
3625
	table_name
unknown's avatar
unknown committed
3626
	| table_list ',' table_name;
unknown's avatar
unknown committed
3627

3628
table_name:
unknown's avatar
unknown committed
3629
	table_ident
unknown's avatar
unknown committed
3630 3631 3632 3633 3634
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
unknown's avatar
unknown committed
3635 3636

if_exists:
3637
	/* empty */ { $$= 0; }
3638 3639
	| IF EXISTS { $$= 1; }
	;
unknown's avatar
unknown committed
3640

3641 3642 3643 3644
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
unknown's avatar
unknown committed
3645 3646 3647 3648 3649
/*
** Insert : add new data to table
*/

insert:
3650 3651 3652 3653 3654 3655
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3656
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
3657
	} insert_lock_option
3658
	opt_ignore insert2
unknown's avatar
unknown committed
3659
	{
unknown's avatar
unknown committed
3660
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3661
	  Lex->current_select= &Lex->select_lex;
unknown's avatar
unknown committed
3662
	}
3663
	insert_field_spec opt_insert_update
3664
	{}
unknown's avatar
unknown committed
3665
	;
unknown's avatar
unknown committed
3666 3667

replace:
3668 3669
	REPLACE
	{
3670
	  LEX *lex=Lex;
3671 3672
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
3673
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
3674
	}
unknown's avatar
unknown committed
3675 3676
	replace_lock_option insert2
	{
unknown's avatar
unknown committed
3677
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3678
	  Lex->current_select= &Lex->select_lex;
unknown's avatar
unknown committed
3679 3680
	}
	insert_field_spec
3681
	{}
unknown's avatar
unknown committed
3682
	{}
unknown's avatar
unknown committed
3683
	;
unknown's avatar
unknown committed
3684 3685

insert_lock_option:
unknown's avatar
unknown committed
3686 3687 3688 3689
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3690
	;
unknown's avatar
unknown committed
3691 3692

replace_lock_option:
unknown's avatar
unknown committed
3693 3694
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
3695 3696 3697

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
3698
	| insert_table {};
unknown's avatar
unknown committed
3699 3700

insert_table:
3701
	table_name
unknown's avatar
unknown committed
3702
	{
unknown's avatar
unknown committed
3703 3704 3705 3706
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
3707
	};
unknown's avatar
unknown committed
3708 3709

insert_field_spec:
unknown's avatar
unknown committed
3710 3711 3712
	insert_values {}
	| '(' ')' insert_values {}
	| '(' fields ')' insert_values {}
unknown's avatar
unknown committed
3713 3714
	| SET
	  {
unknown's avatar
unknown committed
3715 3716 3717
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3718 3719
	      YYABORT;
	   }
unknown's avatar
unknown committed
3720
	   ident_eq_list;
unknown's avatar
unknown committed
3721 3722 3723 3724

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
3725
	| '(' ')'	  { };
unknown's avatar
unknown committed
3726 3727 3728

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
3729
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
3730 3731 3732

insert_values:
	VALUES	values_list  {}
unknown's avatar
unknown committed
3733
	| VALUE_SYM values_list  {}
unknown's avatar
unknown committed
3734 3735
	|     create_select     { Select->set_braces(0);} union_clause {}
	| '(' create_select ')' { Select->set_braces(1);} union_opt {}
3736
        ;
unknown's avatar
unknown committed
3737 3738 3739

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
3740
	| no_braces;
unknown's avatar
unknown committed
3741 3742 3743 3744

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
3745
	ident_eq_value;
unknown's avatar
unknown committed
3746 3747

ident_eq_value:
unknown's avatar
unknown committed
3748
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
3749
	 {
unknown's avatar
unknown committed
3750 3751 3752
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
3753
	    YYABORT;
unknown's avatar
unknown committed
3754
	 };
unknown's avatar
unknown committed
3755 3756

equal:	EQ		{}
unknown's avatar
unknown committed
3757 3758 3759 3760 3761 3762 3763
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
3764 3765 3766 3767 3768 3769 3770 3771 3772

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
3773 3774
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3775
	    YYABORT;
unknown's avatar
unknown committed
3776
	 };
unknown's avatar
unknown committed
3777 3778 3779

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
3780
	| values;
unknown's avatar
unknown committed
3781 3782

values:
unknown's avatar
unknown committed
3783
	values ','  expr_or_default
unknown's avatar
unknown committed
3784 3785 3786 3787
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
3788 3789 3790 3791 3792 3793 3794 3795
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3796
	expr	  { $$= $1;}
unknown's avatar
SCRUM  
unknown committed
3797
	| DEFAULT {$$= new Item_default_value(); }
unknown's avatar
unknown committed
3798
	;
unknown's avatar
unknown committed
3799

3800 3801
opt_insert_update:
        /* empty */
unknown's avatar
unknown committed
3802
        | ON DUPLICATE_SYM
3803 3804 3805 3806 3807 3808 3809 3810 3811
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
	      send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
          }
3812
          KEY_SYM UPDATE_SYM update_list
3813 3814
        ;

unknown's avatar
unknown committed
3815 3816 3817
/* Update rows in a table */

update:
3818 3819
	UPDATE_SYM
	{
3820
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3821
	  mysql_init_select(lex);
3822
          lex->sql_command= SQLCOM_UPDATE;
3823
        }
unknown's avatar
unknown committed
3824 3825 3826
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3827
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3828
	  Select->set_lock_for_tables($3);
3829
          if (lex->select_lex.table_list.elements > 1)
unknown's avatar
unknown committed
3830
            lex->sql_command= SQLCOM_UPDATE_MULTI;
unknown's avatar
unknown committed
3831 3832
	}
	;
unknown's avatar
unknown committed
3833 3834

update_list:
unknown's avatar
SCRUM  
unknown committed
3835
	update_list ',' simple_ident equal expr_or_default
unknown's avatar
unknown committed
3836
	{
unknown's avatar
unknown committed
3837
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
unknown's avatar
unknown committed
3838 3839
	    YYABORT;
	}
unknown's avatar
SCRUM  
unknown committed
3840
	| simple_ident equal expr_or_default
unknown's avatar
unknown committed
3841
	  {
unknown's avatar
unknown committed
3842
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
unknown's avatar
unknown committed
3843
	      YYABORT;
unknown's avatar
unknown committed
3844
	  };
unknown's avatar
unknown committed
3845 3846

opt_low_priority:
3847
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3848
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3849 3850 3851 3852

/* Delete rows from a table */

delete:
3853
	DELETE_SYM
3854
	{
3855 3856
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
unknown's avatar
unknown committed
3857
	  lex->lock_option= lex->thd->update_lock_default;
3858
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3859
	}
unknown's avatar
unknown committed
3860 3861
	opt_delete_options single_multi {}
	;
3862 3863

single_multi:
unknown's avatar
unknown committed
3864 3865
 	FROM table_ident
	{
unknown's avatar
unknown committed
3866 3867
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
unknown's avatar
unknown committed
3868 3869 3870
	    YYABORT;
	}
	where_clause opt_order_clause
3871
	delete_limit_clause {}
unknown's avatar
unknown committed
3872
	| table_wild_list
unknown's avatar
unknown committed
3873
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
3874
          FROM join_table_list where_clause
unknown's avatar
unknown committed
3875 3876
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3877 3878 3879
	  USING join_table_list where_clause
	  {}
	;
unknown's avatar
unknown committed
3880 3881 3882

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
3883
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
3884 3885

table_wild_one:
unknown's avatar
unknown committed
3886
	ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3887
	{
unknown's avatar
unknown committed
3888 3889
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
unknown's avatar
unknown committed
3890 3891
	    YYABORT;
        }
unknown's avatar
unknown committed
3892
	| ident '.' ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3893
	  {
unknown's avatar
unknown committed
3894 3895
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
unknown's avatar
unknown committed
3896 3897
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
unknown's avatar
unknown committed
3898
	      YYABORT;
unknown's avatar
unknown committed
3899
	  }
unknown's avatar
unknown committed
3900
	;
unknown's avatar
unknown committed
3901 3902

opt_wild:
3903
	/* empty */	{}
unknown's avatar
unknown committed
3904
	| '.' '*'	{};
unknown's avatar
unknown committed
3905 3906


3907
opt_delete_options:
unknown's avatar
unknown committed
3908
	/* empty */	{}
unknown's avatar
unknown committed
3909
	| opt_delete_option opt_delete_options {};
3910 3911

opt_delete_option:
3912
	QUICK		{ Select->options|= OPTION_QUICK; }
3913 3914
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
	| IGNORE_SYM	{ Lex->duplicates= DUP_IGNORE; };
3915

3916
truncate:
unknown's avatar
unknown committed
3917
	TRUNCATE_SYM opt_table_sym table_name
3918
	{
3919
	  LEX* lex= Lex;
3920
	  lex->sql_command= SQLCOM_TRUNCATE;
3921
	  lex->select_lex.options= 0;
3922
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3923 3924
	}
	;
3925

unknown's avatar
unknown committed
3926 3927
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
3928
	| TABLE_SYM;
3929

unknown's avatar
unknown committed
3930 3931
/* Show things */

3932 3933
show:	SHOW
	{
unknown's avatar
unknown committed
3934 3935 3936 3937
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
unknown's avatar
unknown committed
3938
	show_param
3939 3940
	{}
	;
unknown's avatar
unknown committed
3941 3942 3943 3944 3945

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
3946
	  {
3947
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3948
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3949 3950
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
unknown's avatar
unknown committed
3951
	   }
unknown's avatar
unknown committed
3952
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
3953
	  {
3954
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3955
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3956 3957
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
3958
	  }
3959
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
3960
	  {
3961
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3962
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
3963 3964
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
3965
	  }
unknown's avatar
unknown committed
3966
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
3967 3968
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3969 3970
	    if ($5)
	      $4->change_db($5);
unknown's avatar
unknown committed
3971
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
unknown's avatar
unknown committed
3972 3973
	      YYABORT;
	  }
3974
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
unknown's avatar
unknown committed
3975
	  TEXT_STRING_sys AND MASTER_LOG_POS_SYM EQ ulonglong_num
3976
	  AND MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
3977 3978 3979 3980 3981
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
3982
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
3983
          }
3984
        | master_or_binary LOGS_SYM
unknown's avatar
unknown committed
3985 3986
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
3987 3988 3989 3990 3991
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
3992
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
3993
          {
3994 3995
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
3996
          } opt_limit_clause_init
unknown's avatar
unknown committed
3997 3998 3999 4000 4001
	| keys_or_index FROM table_ident opt_db
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
unknown's avatar
unknown committed
4002
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
unknown's avatar
unknown committed
4003 4004
	      YYABORT;
	  }
unknown's avatar
unknown committed
4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019
	| COLUMN_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
	  }
	| TABLE_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_TABLE_TYPES;
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
4020
        | COUNT_SYM '(' '*' ')' WARNINGS
4021
          { (void) create_select_for_variable("warning_count"); }
4022
        | COUNT_SYM '(' '*' ')' ERRORS
4023
	  { (void) create_select_for_variable("error_count"); }
4024
        | WARNINGS opt_limit_clause_init
unknown's avatar
unknown committed
4025
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4026
        | ERRORS opt_limit_clause_init
4027
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
unknown's avatar
unknown committed
4028 4029
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
4030 4031
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
unknown's avatar
unknown committed
4032 4033
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
4034
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
4035
	  {
4036
	    THD *thd= YYTHD;
4037
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
unknown's avatar
unknown committed
4038
	    thd->lex.option_type= (enum_var_type) $1;
4039
	  }
4040
	| charset wild
4041
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
4042 4043
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
4044 4045
	| BERKELEY_DB_SYM LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
unknown's avatar
unknown committed
4046 4047
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
unknown's avatar
unknown committed
4048
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
4049 4050 4051 4052 4053 4054
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
4055
	| CREATE DATABASE opt_if_not_exists ident
unknown's avatar
unknown committed
4056 4057
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
4058 4059
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
4060
	  }
unknown's avatar
unknown committed
4061 4062 4063
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
unknown's avatar
unknown committed
4064
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
unknown's avatar
unknown committed
4065 4066 4067 4068 4069
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
4070
          }
unknown's avatar
unknown committed
4071 4072 4073
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
4074
          };
unknown's avatar
unknown committed
4075

4076 4077 4078 4079
master_or_binary:
	MASTER_SYM
	| BINARY;

unknown's avatar
unknown committed
4080 4081
opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
4082
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
4083 4084 4085

wild:
	/* empty */
unknown's avatar
unknown committed
4086
	| LIKE text_string { Lex->wild= $2; };
unknown's avatar
unknown committed
4087

unknown's avatar
unknown committed
4088 4089
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
4090
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
4091

unknown's avatar
unknown committed
4092 4093
from_or_in:
	FROM
unknown's avatar
unknown committed
4094
	| IN_SYM;
unknown's avatar
unknown committed
4095

unknown's avatar
unknown committed
4096 4097
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
4098
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
4099 4100 4101

binlog_from:
	/* empty */ { Lex->mi.pos = 4; /* skip magic number */ }
unknown's avatar
unknown committed
4102
        | FROM ulonglong_num { Lex->mi.pos = $2; };
unknown's avatar
unknown committed
4103 4104


unknown's avatar
unknown committed
4105 4106 4107 4108
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
4109 4110 4111 4112
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
4113
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
unknown's avatar
unknown committed
4114 4115
	    YYABORT;
	}
4116
	opt_describe_column {}
unknown's avatar
unknown committed
4117 4118 4119
	| describe_command opt_extended_describe
	  { Lex->describe|= DESCRIBE_NORMAL; }
	  select
4120
          {
unknown's avatar
unknown committed
4121
	    LEX *lex=Lex;
4122
	    lex->select_lex.options|= SELECT_DESCRIBE;
unknown's avatar
unknown committed
4123 4124
	  }
	;
unknown's avatar
unknown committed
4125 4126 4127

describe_command:
	DESC
unknown's avatar
unknown committed
4128
	| DESCRIBE;
unknown's avatar
unknown committed
4129

unknown's avatar
unknown committed
4130 4131 4132 4133 4134
opt_extended_describe:
	/* empty */ {}
	| EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; }
	;

unknown's avatar
unknown committed
4135 4136 4137
opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
4138
	| ident
4139
	  { Lex->wild= new String((const char*) $1.str,$1.length,system_charset_info); };
unknown's avatar
unknown committed
4140 4141 4142 4143 4144


/* flush things */

flush:
4145
	FLUSH_SYM opt_no_write_to_binlog
unknown's avatar
unknown committed
4146 4147 4148
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
unknown's avatar
unknown committed
4149
          lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
4150
	}
4151 4152 4153
	flush_options
	{}
	;
unknown's avatar
unknown committed
4154 4155 4156

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
4157
	| flush_option;
unknown's avatar
unknown committed
4158 4159

flush_option:
4160
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
unknown's avatar
unknown committed
4161
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
4162
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
4163 4164 4165 4166
	| HOSTS_SYM	{ Lex->type|= REFRESH_HOSTS; }
	| PRIVILEGES	{ Lex->type|= REFRESH_GRANT; }
	| LOGS_SYM	{ Lex->type|= REFRESH_LOG; }
	| STATUS_SYM	{ Lex->type|= REFRESH_STATUS; }
unknown's avatar
unknown committed
4167 4168
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
4169 4170
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
4171

unknown's avatar
unknown committed
4172
opt_table_list:
4173 4174
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
4175

unknown's avatar
unknown committed
4176
reset:
unknown's avatar
unknown committed
4177 4178 4179 4180
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
4181 4182 4183 4184
	} reset_options
	{}
	;

unknown's avatar
unknown committed
4185 4186
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
4187
	| reset_option;
unknown's avatar
unknown committed
4188 4189

reset_option:
unknown's avatar
unknown committed
4190 4191
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
4192
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
4193

unknown's avatar
unknown committed
4194
purge:
unknown's avatar
unknown committed
4195 4196 4197 4198
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
4199 4200 4201 4202 4203
	} purge_options
	{}
	;

purge_options:
4204
	master_or_binary LOGS_SYM purge_option
unknown's avatar
unknown committed
4205
	;
4206 4207

purge_option:
unknown's avatar
unknown committed
4208
        TO_SYM TEXT_STRING_sys
4209 4210 4211 4212 4213 4214 4215 4216 4217
        {
	   Lex->sql_command = SQLCOM_PURGE;
	   Lex->to_log = $2.str;
        }
	| BEFORE_SYM expr
	{
	  if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2))
	  {
	    net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE");
unknown's avatar
unknown committed
4218
	    YYABORT;
4219 4220 4221
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
4222
	  Lex->purge_time= (ulong) tmp->val_int();
unknown's avatar
unknown committed
4223
	}
unknown's avatar
unknown committed
4224
	;
unknown's avatar
unknown committed
4225

unknown's avatar
unknown committed
4226 4227 4228
/* kill threads */

kill:
4229
	KILL_SYM expr
unknown's avatar
unknown committed
4230
	{
unknown's avatar
unknown committed
4231
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4232
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
4233
	  {
4234
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
4235 4236 4237 4238
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
4239
	};
unknown's avatar
unknown committed
4240 4241 4242 4243

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
4244 4245
	{
	  LEX *lex=Lex;
4246 4247
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
4248
	};
unknown's avatar
unknown committed
4249 4250 4251

/* import, export of files */

unknown's avatar
unknown committed
4252
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
unknown's avatar
unknown committed
4253
	{
unknown's avatar
unknown committed
4254 4255
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
unknown's avatar
unknown committed
4256 4257
	  lex->lock_option= $3;
	  lex->local_file=  $4;
unknown's avatar
unknown committed
4258
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
4259
	    YYABORT;
unknown's avatar
unknown committed
4260
	  lex->field_list.empty();
unknown's avatar
unknown committed
4261 4262 4263 4264
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
unknown's avatar
unknown committed
4265
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
4266 4267 4268
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
4269
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
4270 4271
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
unknown's avatar
unknown committed
4272
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
4273
	    YYABORT;
unknown's avatar
unknown committed
4274 4275

        }
4276 4277 4278 4279
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
4280
        };
unknown's avatar
unknown committed
4281 4282 4283

opt_local:
	/* empty */	{ $$=0;}
unknown's avatar
unknown committed
4284
	| LOCAL_SYM	{ $$=1;};
unknown's avatar
unknown committed
4285

unknown's avatar
unknown committed
4286
load_data_lock:
4287
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4288 4289
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
4290 4291


unknown's avatar
unknown committed
4292 4293 4294
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
unknown's avatar
unknown committed
4295
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
4296 4297 4298

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
4299
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
4300 4301 4302

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
4303
	| field_term;
unknown's avatar
unknown committed
4304 4305 4306 4307

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
4308 4309 4310 4311 4312
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
unknown's avatar
unknown committed
4313
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
unknown's avatar
unknown committed
4314
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
unknown's avatar
unknown committed
4315 4316 4317

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
4318
	| LINES line_term_list;
unknown's avatar
unknown committed
4319 4320 4321

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
4322
	| line_term;
unknown's avatar
unknown committed
4323 4324 4325

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
unknown's avatar
unknown committed
4326
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
unknown's avatar
unknown committed
4327 4328 4329 4330

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
unknown's avatar
unknown committed
4331
	  { Lex->exchange->skip_lines=atol($2.str); };
unknown's avatar
unknown committed
4332 4333 4334 4335

/* Common definitions */

text_literal:
4336
	TEXT_STRING_literal
unknown's avatar
unknown committed
4337 4338
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4339
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
unknown's avatar
unknown committed
4340
	}
unknown's avatar
unknown committed
4341
	| NCHAR_STRING
4342
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
4343
	| UNDERSCORE_CHARSET TEXT_STRING
4344
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
4345
	| text_literal TEXT_STRING_literal
unknown's avatar
unknown committed
4346 4347
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
unknown's avatar
unknown committed
4348 4349

text_string:
4350
	TEXT_STRING_literal
unknown's avatar
unknown committed
4351
	{ $$=  new String($1.str,$1.length,YYTHD->variables.collation_connection); }
unknown's avatar
unknown committed
4352 4353
	| HEX_NUM
	  {
4354
	    Item *tmp = new Item_varbinary($1.str,$1.length);
unknown's avatar
unknown committed
4355
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
4356 4357 4358
	  }
	;

unknown's avatar
unknown committed
4359
param_marker:
4360
        '?'
unknown's avatar
unknown committed
4361
        {
4362
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4363
          if (YYTHD->command == COM_PREPARE)
4364
          {
4365
            lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query)));
4366
            lex->param_count++;
unknown's avatar
unknown committed
4367
          }
4368
          else
unknown's avatar
unknown committed
4369 4370 4371 4372
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
4373 4374 4375
        }
	;

unknown's avatar
unknown committed
4376 4377
literal:
	text_literal	{ $$ =	$1; }
4378 4379
	| NUM		{ $$ =	new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); }
	| LONG_NUM	{ $$ =	new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); }
unknown's avatar
unknown committed
4380
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
unknown's avatar
unknown committed
4381 4382 4383
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
4384
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
4385
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
4386
	| UNDERSCORE_CHARSET HEX_NUM
4387
	  {
4388 4389
	    Item *tmp= new Item_varbinary($2.str,$2.length);
	    String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0;
unknown's avatar
unknown committed
4390 4391 4392
	    $$= new Item_string(str ? str->ptr() : "",
				str ? str->length() : 0,
				Lex->charset);
4393
	  }
unknown's avatar
unknown committed
4394 4395
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
4396
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
4397 4398 4399 4400 4401 4402 4403

/**********************************************************************
** Createing different items.
**********************************************************************/

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
4404
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
4405 4406

table_wild:
unknown's avatar
unknown committed
4407
	ident '.' '*'
4408 4409
	{
	  $$ = new Item_field(NullS,$1.str,"*");
unknown's avatar
unknown committed
4410
	  Lex->current_select->with_wild++;
4411
	}
unknown's avatar
unknown committed
4412
	| ident '.' ident '.' '*'
4413 4414 4415 4416
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
unknown's avatar
unknown committed
4417
	  Lex->current_select->with_wild++;
4418 4419
	}
	;
unknown's avatar
unknown committed
4420 4421

order_ident:
unknown's avatar
unknown committed
4422
	expr { $$=$1; };
unknown's avatar
unknown committed
4423 4424 4425

simple_ident:
	ident
unknown's avatar
unknown committed
4426
	{
unknown's avatar
unknown committed
4427
	  SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
4428 4429 4430 4431
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
              (Item*) new Item_field(NullS,NullS,$1.str) :
	      (Item*) new Item_ref(NullS,NullS,$1.str);
unknown's avatar
unknown committed
4432
	}
unknown's avatar
unknown committed
4433
	| ident '.' ident
unknown's avatar
unknown committed
4434
	{
unknown's avatar
unknown committed
4435 4436
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
unknown's avatar
unknown committed
4437
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4438 4439
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4440
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4441 4442 4443
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
unknown's avatar
unknown committed
4444 4445 4446 4447
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$1.str,$3.str) :
	      (Item*) new Item_ref(NullS,$1.str,$3.str);
unknown's avatar
unknown committed
4448
	}
unknown's avatar
unknown committed
4449
	| '.' ident '.' ident
unknown's avatar
unknown committed
4450
	{
unknown's avatar
unknown committed
4451 4452
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
unknown's avatar
unknown committed
4453
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4454 4455
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4456
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4457 4458 4459
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
unknown's avatar
unknown committed
4460 4461 4462 4463
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$2.str,$4.str) :
              (Item*) new Item_ref(NullS,$2.str,$4.str);
unknown's avatar
unknown committed
4464
	}
unknown's avatar
unknown committed
4465
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
4466
	{
unknown's avatar
unknown committed
4467 4468
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
unknown's avatar
unknown committed
4469
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4470 4471
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4472
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4473 4474 4475
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
unknown's avatar
unknown committed
4476 4477 4478 4479 4480 4481 4482 4483
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field((YYTHD->client_capabilities &
				      CLIENT_NO_SCHEMA ? NullS : $1.str),
				     $3.str, $5.str) :
	      (Item*) new Item_ref((YYTHD->client_capabilities &
				    CLIENT_NO_SCHEMA ? NullS : $1.str),
                                   $3.str, $5.str);
unknown's avatar
unknown committed
4484
	};
unknown's avatar
unknown committed
4485 4486 4487 4488 4489


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
unknown's avatar
unknown committed
4490
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
4491 4492 4493

table_ident:
	ident			{ $$=new Table_ident($1); }
unknown's avatar
unknown committed
4494
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
unknown's avatar
unknown committed
4495 4496
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
unknown's avatar
unknown committed
4497

unknown's avatar
unknown committed
4498
IDENT_sys:
4499 4500 4501 4502 4503 4504 4505 4506 4507 4508
	IDENT { $$= $1; }
	| IDENT_QUOTED
	  {
	    THD *thd= YYTHD;
	    if (thd->charset_is_system_charset)
	      $$= $1;
	    else
	      thd->convert_string(&$$, system_charset_info,
				  $1.str, $1.length, thd->charset());
	  }
unknown's avatar
unknown committed
4509 4510 4511 4512 4513 4514
	;

TEXT_STRING_sys:
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4515 4516
	  if (thd->charset_is_system_charset)
	    $$= $1;
unknown's avatar
unknown committed
4517
	  else
unknown's avatar
unknown committed
4518 4519
	    thd->convert_string(&$$, system_charset_info,
				$1.str, $1.length, thd->charset());
unknown's avatar
unknown committed
4520 4521 4522
	}
	;

4523
TEXT_STRING_literal:
unknown's avatar
unknown committed
4524 4525 4526
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4527 4528
	  if (thd->charset_is_collation_connection)
	    $$= $1;
unknown's avatar
unknown committed
4529
	  else
unknown's avatar
unknown committed
4530 4531
	    thd->convert_string(&$$, thd->variables.collation_connection,
				$1.str, $1.length, thd->charset());
unknown's avatar
unknown committed
4532 4533 4534 4535
	}
	;


unknown's avatar
unknown committed
4536
ident:
unknown's avatar
unknown committed
4537
	IDENT_sys	    { $$=$1; }
unknown's avatar
unknown committed
4538 4539
	| keyword
	{
unknown's avatar
unknown committed
4540 4541 4542
	  THD *thd= YYTHD;
	  $$.str=    thd->strmake($1.str, $1.length);
	  $$.length= $1.length;
4543 4544
	}
	;
unknown's avatar
unknown committed
4545 4546

ident_or_text:
unknown's avatar
unknown committed
4547 4548 4549
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
unknown's avatar
unknown committed
4550 4551 4552 4553

user:
	ident_or_text
	{
unknown's avatar
unknown committed
4554 4555
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4556
	    YYABORT;
4557 4558 4559 4560
	  $$->user = $1;
	  $$->host.str= (char *) "%";
	  $$->host.length= 1;
	}
unknown's avatar
unknown committed
4561 4562
	| ident_or_text '@' ident_or_text
	  {
unknown's avatar
unknown committed
4563 4564
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4565 4566
	      YYABORT;
	    $$->user = $1; $$->host=$3;
unknown's avatar
unknown committed
4567
	  };
unknown's avatar
unknown committed
4568 4569 4570 4571 4572

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
unknown's avatar
unknown committed
4573
	| ADDDATE_SYM		{}
unknown's avatar
unknown committed
4574
	| AFTER_SYM		{}
4575
	| AGAINST		{}
unknown's avatar
unknown committed
4576
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
4577
	| ANY_SYM		{}
unknown's avatar
unknown committed
4578
	| ASCII_SYM		{}
unknown's avatar
unknown committed
4579
	| AUTO_INC		{}
unknown's avatar
unknown committed
4580 4581
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
4582
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
4583
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
4584
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
4585
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
4586 4587
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
4588
	| BOOLEAN_SYM		{}
4589
	| BYTE_SYM		{}
unknown's avatar
unknown committed
4590
	| BTREE_SYM		{}
unknown's avatar
unknown committed
4591
	| CACHE_SYM		{}
4592
	| CHANGED		{}
4593
	| CHARSET		{}
unknown's avatar
unknown committed
4594
	| CHECKSUM_SYM		{}
4595
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
4596
	| CLIENT_SYM		{}
4597
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
4598
	| COLLATION_SYM		{}
unknown's avatar
unknown committed
4599
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
4600
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
4601
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
4602
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
4603
	| CONCURRENT		{}
4604
	| CUBE_SYM		{}
unknown's avatar
unknown committed
4605 4606 4607 4608 4609
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
4610 4611
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
4612
	| DISCARD		{}
unknown's avatar
unknown committed
4613
	| DO_SYM		{}
4614
	| DUAL_SYM		{}
unknown's avatar
unknown committed
4615 4616
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
unknown's avatar
unknown committed
4617 4618 4619
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
4620
	| ERRORS		{}
unknown's avatar
unknown committed
4621
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
4622
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
4623
	| EXECUTE_SYM		{}
4624
        | EXPANSION_SYM         {}
unknown's avatar
unknown committed
4625
	| EXTENDED_SYM		{}
4626
	| FAST_SYM		{}
unknown's avatar
unknown committed
4627 4628
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
4629
	| FULL			{}
unknown's avatar
unknown committed
4630 4631 4632 4633
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
4634
	| GEOMETRY_SYM		{}
4635
	| GEOMETRYCOLLECTION	{}
4636
	| GET_FORMAT		{}
unknown's avatar
unknown committed
4637
	| GRANTS		{}
unknown's avatar
unknown committed
4638
	| GLOBAL_SYM		{}
4639
	| HANDLER_SYM		{}
unknown's avatar
unknown committed
4640
	| HASH_SYM		{}
4641
	| HELP_SYM		{}
unknown's avatar
unknown committed
4642 4643 4644
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
4645
	| IMPORT		{}
unknown's avatar
unknown committed
4646
	| INDEXES		{}
unknown's avatar
unknown committed
4647
	| ISOLATION		{}
unknown's avatar
unknown committed
4648
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
4649
	| INNOBASE_SYM		{}
4650
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
4651
	| RELAY_THREAD		{}
4652
	| LAST_SYM		{}
unknown's avatar
unknown committed
4653
	| LEAVES                {}
unknown's avatar
unknown committed
4654
	| LEVEL_SYM		{}
4655
	| LINESTRING		{}
unknown's avatar
unknown committed
4656
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
4657
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
4658 4659 4660 4661 4662 4663 4664 4665 4666 4667
	| LOGS_SYM		{}
	| MAX_ROWS		{}
	| MASTER_SYM		{}
	| MASTER_HOST_SYM	{}
	| MASTER_PORT_SYM	{}
	| MASTER_LOG_FILE_SYM	{}
	| MASTER_LOG_POS_SYM	{}
	| MASTER_USER_SYM	{}
	| MASTER_PASSWORD_SYM	{}
	| MASTER_CONNECT_RETRY_SYM	{}
unknown's avatar
unknown committed
4668 4669 4670 4671 4672 4673
	| MASTER_SSL_SYM	{}
	| MASTER_SSL_CA_SYM	{}
	| MASTER_SSL_CAPATH_SYM	{}
	| MASTER_SSL_CERT_SYM	{}
	| MASTER_SSL_CIPHER_SYM	{}
	| MASTER_SSL_KEY_SYM	{}
unknown's avatar
unknown committed
4674 4675 4676
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
4677
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
4678
	| MICROSECOND_SYM	{}
unknown's avatar
unknown committed
4679 4680 4681
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
4682
	| MODE_SYM		{}
unknown's avatar
unknown committed
4683
	| MONTH_SYM		{}
4684 4685 4686
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
unknown's avatar
unknown committed
4687
	| NAMES_SYM		{}
unknown's avatar
unknown committed
4688 4689
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
4690
	| NEXT_SYM		{}
unknown's avatar
unknown committed
4691
	| NEW_SYM		{}
unknown's avatar
unknown committed
4692
	| NO_SYM		{}
4693
	| NONE_SYM		{}
unknown's avatar
unknown committed
4694
	| NVARCHAR_SYM		{}
unknown's avatar
unknown committed
4695
	| OFFSET_SYM		{}
unknown's avatar
unknown committed
4696
	| OLD_PASSWORD		{}
4697
	| OPEN_SYM		{}
unknown's avatar
unknown committed
4698
	| PACK_KEYS_SYM		{}
4699
	| PARTIAL		{}
unknown's avatar
unknown committed
4700
	| PASSWORD		{}
4701
	| POINT_SYM		{}
4702
	| POLYGON		{}
4703
	| PREV_SYM		{}
unknown's avatar
unknown committed
4704 4705
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
4706
	| QUERY_SYM		{}
4707
	| QUICK			{}
unknown's avatar
unknown committed
4708
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
4709 4710
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
4711
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
4712
	| RAID_TYPE		{}
unknown's avatar
unknown committed
4713 4714
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
4715 4716
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
4717
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
4718
	| REPLICATION		{}
unknown's avatar
unknown committed
4719
	| RESET_SYM		{}
4720
	| RESOURCES		{}
unknown's avatar
unknown committed
4721
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
4722
	| ROLLBACK_SYM		{}
4723
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
4724 4725 4726
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
unknown's avatar
unknown committed
4727
	| RTREE_SYM		{}
4728
	| SAVEPOINT_SYM		{}
unknown's avatar
unknown committed
4729
	| SECOND_SYM		{}
4730
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
4731 4732
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
4733
	| SIGNED_SYM		{}
4734
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
4735
	| SHARE_SYM		{}
unknown's avatar
unknown committed
4736
	| SHUTDOWN		{}
unknown's avatar
unknown committed
4737
	| SLAVE			{}
unknown's avatar
unknown committed
4738
	| SOUNDS_SYM		{}
unknown's avatar
unknown committed
4739
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
4740
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
4741
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
4742
	| SQL_THREAD		{}
unknown's avatar
unknown committed
4743 4744 4745 4746
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
unknown's avatar
unknown committed
4747
	| SUBDATE_SYM		{}
unknown's avatar
unknown committed
4748
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
4749
	| SUPER_SYM		{}
unknown's avatar
unknown committed
4750
	| TABLESPACE		{}
unknown's avatar
unknown committed
4751 4752
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
4753
	| TRANSACTION_SYM	{}
4754
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
4755 4756 4757 4758
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
unknown's avatar
unknown committed
4759
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
4760
	| UNICODE_SYM		{}
4761
	| UNTIL_SYM		{}
4762
	| USER			{}
unknown's avatar
unknown committed
4763
	| USE_FRM		{}
unknown's avatar
unknown committed
4764
	| VARIABLES		{}
4765
	| VALUE_SYM		{}
4766
	| WARNINGS		{}
unknown's avatar
unknown committed
4767
	| WORK_SYM		{}
4768
	| X509_SYM		{}
unknown's avatar
unknown committed
4769 4770
	| YEAR_SYM		{}
	;
unknown's avatar
unknown committed
4771 4772 4773 4774 4775 4776

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
4777 4778
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
unknown's avatar
unknown committed
4779 4780
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
unknown's avatar
unknown committed
4781
	}
4782 4783 4784
	option_value_list
	{}
	;
unknown's avatar
unknown committed
4785 4786 4787

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
4788
	| OPTION {};
unknown's avatar
unknown committed
4789 4790

option_value_list:
unknown's avatar
unknown committed
4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802
	option_type option_value
	| option_value_list ',' option_type option_value;

option_type:
	/* empty */	{}
	| GLOBAL_SYM	{ Lex->option_type= OPT_GLOBAL; }
	| LOCAL_SYM	{ Lex->option_type= OPT_SESSION; }
	| SESSION_SYM	{ Lex->option_type= OPT_SESSION; }
	;

opt_var_type:
	/* empty */	{ $$=OPT_SESSION; }
unknown's avatar
unknown committed
4803
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4804 4805 4806 4807 4808 4809
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
4810
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4811 4812 4813
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
4814 4815

option_value:
unknown's avatar
unknown committed
4816
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
4817
	{
unknown's avatar
unknown committed
4818
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
4819
	}
unknown's avatar
unknown committed
4820
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4821
	  {
unknown's avatar
unknown committed
4822
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4823 4824
	    lex->var_list.push_back(new set_var(lex->option_type, $1.var,
						&$1.base_name, $3));
unknown's avatar
unknown committed
4825
	  }
unknown's avatar
unknown committed
4826
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4827 4828
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4829 4830
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4.var,
						&$4.base_name, $6));
unknown's avatar
unknown committed
4831 4832 4833 4834
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4835 4836 4837
	    LEX_STRING tmp;
	    tmp.str=0;
	    tmp.length=0;
unknown's avatar
unknown committed
4838
	    lex->var_list.push_back(new set_var(lex->option_type,
unknown's avatar
unknown committed
4839
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
4840
						&tmp,
unknown's avatar
unknown committed
4841
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
4842
	  }
4843
	| charset old_or_new_charset_name_or_default
unknown's avatar
unknown committed
4844
	{
unknown's avatar
unknown committed
4845
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4846
	  LEX *lex= Lex;
4847
	  $2= $2 ? $2: global_system_variables.character_set_client;
4848
	  lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
unknown's avatar
unknown committed
4849
	}
4850
	| NAMES_SYM charset_name_or_default opt_collate
4851
	{
unknown's avatar
unknown committed
4852
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4853
	  LEX *lex= Lex;
4854
	  $2= $2 ? $2 : global_system_variables.character_set_client;
4855 4856
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
4857
	  {
unknown's avatar
unknown committed
4858 4859
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
4860
	  }
4861
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
4862
	}
unknown's avatar
unknown committed
4863
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
4864
	  {
4865
	    THD *thd=YYTHD;
unknown's avatar
unknown committed
4866
	    LEX_USER *user;
unknown's avatar
unknown committed
4867
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
unknown's avatar
unknown committed
4868 4869 4870 4871 4872 4873
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
	    thd->lex.var_list.push_back(new set_var_password(user, $3));
	  }
	| PASSWORD FOR_SYM user equal text_or_password
unknown's avatar
unknown committed
4874
	  {
unknown's avatar
unknown committed
4875 4876
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
4877
	;
unknown's avatar
unknown committed
4878

unknown's avatar
unknown committed
4879 4880 4881 4882 4883 4884
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
unknown's avatar
unknown committed
4885 4886 4887
	  $$.var= tmp;
	  $$.base_name.str=0;
	  $$.base_name.length=0;
unknown's avatar
unknown committed
4888
	}
4889 4890 4891 4892 4893 4894 4895
	| ident '.' ident
	  {
	    sys_var *tmp=find_sys_var($3.str, $3.length);
	    if (!tmp)
	      YYABORT;
	    if (!tmp->is_struct())
	      net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str);
unknown's avatar
unknown committed
4896 4897
	    $$.var= tmp;
	    $$.base_name= $1;
4898 4899 4900 4901 4902 4903 4904 4905
	  }
	| DEFAULT '.' ident
	  {
	    sys_var *tmp=find_sys_var($3.str, $3.length);
	    if (!tmp)
	      YYABORT;
	    if (!tmp->is_struct())
	      net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str);
unknown's avatar
unknown committed
4906 4907 4908
	    $$.var= tmp;
	    $$.base_name.str=    (char*) "default";
	    $$.base_name.length= 7;
4909
	  }
4910
        ;
unknown's avatar
unknown committed
4911 4912 4913 4914 4915 4916 4917

isolation_types:
	READ_SYM UNCOMMITTED_SYM	{ $$= ISO_READ_UNCOMMITTED; }
	| READ_SYM COMMITTED_SYM	{ $$= ISO_READ_COMMITTED; }
	| REPEATABLE_SYM READ_SYM	{ $$= ISO_REPEATABLE_READ; }
	| SERIALIZABLE_SYM		{ $$= ISO_SERIALIZABLE; }
	;
4918

unknown's avatar
unknown committed
4919 4920 4921 4922
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
4923
	    $$= $3.length ? YYTHD->variables.old_passwords ?
unknown's avatar
unknown committed
4924 4925 4926 4927 4928 4929 4930 4931
	        Item_func_old_password::alloc(YYTHD, $3.str) :
	        Item_func_password::alloc(YYTHD, $3.str) :
	      $3.str;
	  }
	| OLD_PASSWORD '(' TEXT_STRING ')'
	  {
	    $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str) :
	      $3.str;
4932 4933
	  }
          ;
unknown's avatar
unknown committed
4934

unknown's avatar
unknown committed
4935

unknown's avatar
unknown committed
4936
set_expr_or_default:
unknown's avatar
unknown committed
4937 4938
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
4939 4940
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
4941
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
unknown's avatar
unknown committed
4942
	;
unknown's avatar
unknown committed
4943 4944


unknown's avatar
unknown committed
4945 4946 4947 4948 4949 4950 4951
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
4952 4953 4954
	table_lock_list
	{}
	;
unknown's avatar
unknown committed
4955 4956 4957

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
4958
	| TABLES;
unknown's avatar
unknown committed
4959 4960 4961

table_lock_list:
	table_lock
unknown's avatar
unknown committed
4962
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
4963 4964 4965

table_lock:
	table_ident opt_table_alias lock_option
4966
	{
unknown's avatar
unknown committed
4967
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
4968 4969
	   YYABORT;
	}
4970
        ;
unknown's avatar
unknown committed
4971 4972 4973

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
4974
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4975
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
4976 4977
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
4978 4979

unlock:
4980 4981
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
4982 4983


4984
/*
unknown's avatar
unknown committed
4985
** Handler: direct access to ISAM functions
4986 4987 4988 4989 4990
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
4991 4992
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
unknown's avatar
unknown committed
4993
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
4994 4995 4996 4997
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
4998 4999
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
unknown's avatar
unknown committed
5000
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
5001 5002
	    YYABORT;
	}
unknown's avatar
unknown committed
5003
	| HANDLER_SYM table_ident READ_SYM
5004
	{
unknown's avatar
unknown committed
5005 5006 5007
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
5008 5009
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
unknown's avatar
unknown committed
5010
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
5011
	    YYABORT;
unknown's avatar
unknown committed
5012
        }
5013
        handler_read_or_scan where_clause opt_limit_clause {}
5014
        ;
5015

unknown's avatar
unknown committed
5016 5017
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
5018 5019
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
5020 5021 5022

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
5023 5024
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
5025 5026 5027 5028 5029 5030

handler_rkey_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
	| PREV_SYM { Lex->ha_read_mode = RPREV;  }
	| LAST_SYM { Lex->ha_read_mode = RLAST;  }
5031 5032
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
5033 5034
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
5035
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
5036
	  if (!(lex->insert_list = new List_item))
5037
	    YYABORT;
5038 5039
	} '(' values ')' { }
        ;
5040 5041

handler_rkey_mode:
unknown's avatar
unknown committed
5042 5043 5044 5045
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
5046 5047
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
5048

unknown's avatar
unknown committed
5049 5050 5051 5052 5053
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
5054 5055 5056 5057 5058
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
5059
	  lex->select_lex.db=0;
5060 5061
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
5062
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
5063
	}
5064 5065 5066 5067 5068
	revoke_command
	{}
        ;

revoke_command:
5069 5070
	grant_privileges ON opt_table FROM user_list
	{}
5071 5072 5073 5074 5075
	|
	ALL PRIVILEGES ',' GRANT FROM user_list
	{
	  Lex->sql_command = SQLCOM_REVOKE_ALL;
	}
5076
	;
unknown's avatar
unknown committed
5077 5078 5079 5080

grant:
	GRANT
	{
unknown's avatar
unknown committed
5081 5082 5083
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
5084 5085
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
5086
	  lex->select_lex.db= 0;
5087 5088
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
5089
	  bzero((char *)&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
5090 5091
	}
	grant_privileges ON opt_table TO_SYM user_list
5092 5093 5094
	require_clause grant_options
	{}
	;
unknown's avatar
unknown committed
5095 5096 5097

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
5098
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
5099 5100
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
unknown's avatar
unknown committed
5101 5102 5103

grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
5104
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
5105 5106

grant_privilege:
unknown's avatar
unknown committed
5107
	SELECT_SYM	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
5108 5109 5110
	| INSERT	{ Lex->which_columns = INSERT_ACL;} opt_column_list {}
	| UPDATE_SYM	{ Lex->which_columns = UPDATE_ACL; } opt_column_list {}
	| REFERENCES	{ Lex->which_columns = REFERENCES_ACL;} opt_column_list {}
unknown's avatar
unknown committed
5111 5112
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
5113 5114 5115 5116
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
unknown's avatar
unknown committed
5117
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
5118 5119 5120 5121
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
unknown's avatar
unknown committed
5122 5123 5124 5125 5126 5127 5128 5129
	| GRANT OPTION  { Lex->grant |= GRANT_ACL;}
	| SHOW DATABASES { Lex->grant |= SHOW_DB_ACL;}
	| SUPER_SYM	{ Lex->grant |= SUPER_ACL;}
	| CREATE TEMPORARY TABLES { Lex->grant |= CREATE_TMP_ACL;}
	| LOCK_SYM TABLES   { Lex->grant |= LOCK_TABLES_ACL; }
	| REPLICATION SLAVE  { Lex->grant |= REPL_SLAVE_ACL;}
	| REPLICATION CLIENT_SYM { Lex->grant |= REPL_CLIENT_ACL;}
	;
unknown's avatar
unknown committed
5130

unknown's avatar
unknown committed
5131

5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
unknown's avatar
unknown committed
5144 5145 5146 5147
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
5148
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
5149 5150 5151 5152 5153 5154 5155 5156 5157
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
5158
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
5159 5160 5161 5162 5163 5164 5165 5166 5167
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
5168
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
5169 5170 5171 5172 5173
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
5174

unknown's avatar
unknown committed
5175 5176 5177
opt_table:
	'*'
	  {
5178
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5179
	    lex->current_select->db= lex->thd->db;
unknown's avatar
unknown committed
5180
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5181 5182
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5183
	    {
5184
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
5185
	      YYABORT;
unknown's avatar
unknown committed
5186
	    }
unknown's avatar
unknown committed
5187 5188 5189
	  }
	| ident '.' '*'
	  {
5190
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5191
	    lex->current_select->db = $1.str;
unknown's avatar
unknown committed
5192
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5193 5194
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5195
	    {
5196
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
5197 5198 5199 5200 5201
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
5202
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5203
	    lex->current_select->db = NULL;
unknown's avatar
unknown committed
5204 5205
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
5206
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5207
	    {
5208
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
5209 5210 5211 5212 5213
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
5214
	    LEX *lex=Lex;
unknown's avatar
unknown committed
5215
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
unknown's avatar
unknown committed
5216
	      YYABORT;
unknown's avatar
unknown committed
5217
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5218
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
5219 5220
	  }
          ;
unknown's avatar
unknown committed
5221 5222 5223


user_list:
5224 5225 5226 5227 5228 5229 5230
	grant_user  { if (Lex->users_list.push_back($1)) YYABORT;}
	| user_list ',' grant_user
	  {
	    if (Lex->users_list.push_back($3))
	      YYABORT;
	  }
	;
unknown's avatar
unknown committed
5231 5232 5233 5234 5235 5236 5237 5238


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
5239
             if (YYTHD->variables.old_passwords)
5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256
             {
               char *buff= 
                 (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
               if (buff)
                 make_scrambled_password_323(buff, $4.str);
               $1->password.str= buff;
               $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
             }
             else
             {
               char *buff= 
                 (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
               if (buff)
                 make_scrambled_password(buff, $4.str);
               $1->password.str= buff;
               $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH;
             }
unknown's avatar
unknown committed
5257 5258 5259 5260 5261
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
5262 5263
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
5264 5265 5266


opt_column_list:
unknown's avatar
unknown committed
5267 5268 5269 5270 5271
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
5272
	| '(' column_list ')';
unknown's avatar
unknown committed
5273 5274 5275

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
5276
	| column_list_id;
unknown's avatar
unknown committed
5277 5278 5279 5280

column_list_id:
	ident
	{
5281
	  String *new_str = new String((const char*) $1.str,$1.length,system_charset_info);
unknown's avatar
unknown committed
5282 5283
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
5284
	  LEX *lex=Lex;
unknown's avatar
unknown committed
5285 5286
	  while ((point=iter++))
	  {
5287 5288
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
5289 5290
		break;
	  }
unknown's avatar
unknown committed
5291
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
5292
	  if (point)
unknown's avatar
unknown committed
5293
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
5294
	  else
unknown's avatar
unknown committed
5295
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
5296 5297
	}
        ;
unknown's avatar
unknown committed
5298

unknown's avatar
unknown committed
5299 5300

require_clause: /* empty */
5301
        | REQUIRE_SYM require_list
5302 5303 5304
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
5305
        | REQUIRE_SYM SSL_SYM
5306 5307 5308
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
5309
        | REQUIRE_SYM X509_SYM
5310 5311 5312 5313 5314 5315 5316
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
5317
          ;
unknown's avatar
unknown committed
5318

unknown's avatar
unknown committed
5319
grant_options:
unknown's avatar
unknown committed
5320
	/* empty */ {}
unknown's avatar
unknown committed
5321
	| WITH grant_option_list;
unknown's avatar
unknown committed
5322

unknown's avatar
unknown committed
5323 5324
grant_option_list:
	grant_option_list grant_option {}
5325 5326
	| grant_option {}
        ;
unknown's avatar
unknown committed
5327 5328 5329

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
5330
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
5331
        {
5332
	  Lex->mqh.questions=$2;
5333
	  Lex->mqh.bits |= 1;
5334
	}
5335
        | MAX_UPDATES_PER_HOUR ULONG_NUM
5336
        {
5337
	  Lex->mqh.updates=$2;
5338
	  Lex->mqh.bits |= 2;
5339
	}
5340
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
5341
        {
5342
	  Lex->mqh.connections=$2;
5343
	  Lex->mqh.bits |= 4;
5344 5345
	}
        ;
5346

unknown's avatar
unknown committed
5347
begin:
5348 5349
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
unknown's avatar
unknown committed
5350 5351 5352

opt_work:
	/* empty */ {}
5353 5354
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
5355 5356

commit:
unknown's avatar
unknown committed
5357
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
5358 5359

rollback:
unknown's avatar
unknown committed
5360
	ROLLBACK_SYM
5361 5362 5363 5364 5365
	{
	  Lex->sql_command = SQLCOM_ROLLBACK;
	}
	| ROLLBACK_SYM TO_SYM SAVEPOINT_SYM ident
	{
unknown's avatar
unknown committed
5366
	  Lex->sql_command = SQLCOM_ROLLBACK_TO_SAVEPOINT;
5367 5368 5369 5370 5371 5372 5373 5374
	  Lex->savepoint_name = $4.str;
	};
savepoint:
	SAVEPOINT_SYM ident
	{
	  Lex->sql_command = SQLCOM_SAVEPOINT;
	  Lex->savepoint_name = $2.str;
	};
5375 5376

/*
unknown's avatar
unknown committed
5377
   UNIONS : glue selects together
5378 5379 5380
*/


5381
union_clause:
5382
	/* empty */ {}
unknown's avatar
unknown committed
5383 5384
	| union_list
	;
5385 5386

union_list:
unknown's avatar
unknown committed
5387
	UNION_SYM    union_option
5388 5389 5390 5391 5392
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
5393
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
5394
	    YYABORT;
5395
	  }
5396
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
5397
	  {
5398
	    send_error(lex->thd, ER_SYNTAX_ERROR);
5399 5400
	    YYABORT;
	  }
5401
	  if (mysql_new_select(lex, 0))
5402
	    YYABORT;
unknown's avatar
unknown committed
5403
          mysql_init_select(lex);
5404
	  lex->current_select->linkage=UNION_TYPE;
unknown's avatar
unknown committed
5405
	}
5406
	select_init {}
5407
	;
5408 5409

union_opt:
unknown's avatar
unknown committed
5410
	union_list {}
unknown's avatar
unknown committed
5411 5412
	| optional_order_or_limit {}
	;
5413 5414

optional_order_or_limit:
5415
	/* Empty */ {}
5416 5417
	|
	  {
unknown's avatar
unknown committed
5418 5419
	    THD *thd= YYTHD;
	    LEX *lex= &thd->lex;
unknown's avatar
unknown committed
5420
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
unknown's avatar
unknown committed
5421
	    SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
5422
	    SELECT_LEX_UNIT *unit= sel->master_unit();
unknown's avatar
unknown committed
5423
	    SELECT_LEX *fake= unit->fake_select_lex;
unknown's avatar
unknown committed
5424 5425 5426 5427 5428 5429
	    if (fake)
	    {
	      unit->global_parameters= fake;
	      fake->no_table_names_allowed= 1;
	      lex->current_select= fake;
	    }
unknown's avatar
unknown committed
5430
	    thd->where= "global ORDER clause";
5431
	  }
5432
	order_or_limit
unknown's avatar
unknown committed
5433 5434 5435 5436 5437
          {
	    THD *thd= YYTHD;
	    thd->lex.current_select->no_table_names_allowed= 0;
	    thd->where= "";
          }
5438 5439 5440
	;

order_or_limit:
5441 5442
	order_clause opt_limit_clause_init
	| limit_clause
5443
	;
unknown's avatar
unknown committed
5444 5445

union_option:
5446
	/* empty */ {}
unknown's avatar
unknown committed
5447
	| ALL {Select->master_unit()->union_option|= UNION_ALL;};
5448

unknown's avatar
unknown committed
5449 5450
singlerow_subselect:
	subselect_start singlerow_subselect_init
unknown's avatar
unknown committed
5451 5452 5453 5454
	subselect_end
	{
	  $$= $2;
	};
5455

unknown's avatar
unknown committed
5456
singlerow_subselect_init:
5457
	select_init2
unknown's avatar
unknown committed
5458
	{
5459 5460
	  $$= new Item_singlerow_subselect(Lex->current_select->
					   master_unit()->first_select());
unknown's avatar
unknown committed
5461
	};
unknown's avatar
unknown committed
5462 5463

exists_subselect:
unknown's avatar
unknown committed
5464 5465 5466 5467 5468
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
5469 5470

exists_subselect_init:
5471
	select_init2
unknown's avatar
unknown committed
5472
	{
5473 5474
	  $$= new Item_exists_subselect(Lex->current_select->master_unit()->
					first_select());
unknown's avatar
unknown committed
5475
	};
5476

unknown's avatar
unknown committed
5477 5478 5479 5480 5481 5482 5483 5484
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
5485
  select_init2
unknown's avatar
unknown committed
5486
  {
unknown's avatar
unknown committed
5487
    $$= Lex->current_select->master_unit()->first_select();
unknown's avatar
unknown committed
5488 5489
  };

5490
subselect_start:
5491
	'(' SELECT_SYM
unknown's avatar
unknown committed
5492
	{
5493
	  LEX *lex=Lex;
5494
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
5495 5496 5497
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
	  {	
5498 5499 5500
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
unknown's avatar
unknown committed
5501 5502 5503
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
5504 5505

subselect_end:
unknown's avatar
unknown committed
5506 5507 5508
	')'
	{
	  LEX *lex=Lex;
5509
	  lex->current_select = lex->current_select->return_after_parsing();
unknown's avatar
unknown committed
5510
	};
unknown's avatar
unknown committed
5511