sql_yacc.yy 140 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

unknown's avatar
unknown committed
45 46 47 48 49
#define WARN_DEPRECATED(A,B) \
  push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, \
		      ER_WARN_DEPRECATED_SYNTAX, \
		      ER(ER_WARN_DEPRECATED_SYNTAX), (A), (B)); 

50
inline Item *or_or_concat(THD *thd, Item* A, Item* B)
unknown's avatar
unknown committed
51
{
52
  return (thd->variables.sql_mode & MODE_PIPES_AS_CONCAT ?
unknown's avatar
unknown committed
53 54 55 56 57 58 59
          (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
60
  ulonglong ulonglong_number;
unknown's avatar
unknown committed
61 62 63 64 65 66 67 68
  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
69 70 71 72 73
  String *string;
  key_part_spec *key_part;
  TABLE_LIST *table_list;
  udf_func *udf;
  LEX_USER *lex_user;
unknown's avatar
unknown committed
74
  struct sys_var_with_base variable;
unknown's avatar
unknown committed
75
  Key::Keytype key_type;
unknown's avatar
unknown committed
76
  enum ha_key_alg key_alg;
unknown's avatar
unknown committed
77 78
  enum db_type db_type;
  enum row_type row_type;
unknown's avatar
unknown committed
79
  enum ha_rkey_function ha_rkey_mode;
unknown's avatar
unknown committed
80
  enum enum_tx_isolation tx_isolation;
81
  enum Cast_target cast_type;
unknown's avatar
unknown committed
82
  enum Item_udftype udf_type;
83
  CHARSET_INFO *charset;
unknown's avatar
unknown committed
84
  thr_lock_type lock_type;
unknown's avatar
unknown committed
85
  interval_type interval;
86
  timestamp_type date_time_type;
unknown's avatar
unknown committed
87
  st_select_lex *select_lex;
unknown's avatar
unknown committed
88
  chooser_compare_func_creator boolfunc2creator;
unknown's avatar
unknown committed
89 90 91 92 93 94 95 96 97 98
}

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

%pure_parser					/* We have threads */

%token	END_OF_INPUT

99 100 101 102 103 104
%token CLOSE_SYM
%token HANDLER_SYM
%token LAST_SYM
%token NEXT_SYM
%token PREV_SYM

105
%token	DIV_SYM
unknown's avatar
unknown committed
106 107
%token	EQ
%token	EQUAL_SYM
unknown's avatar
unknown committed
108
%token	SOUNDS_SYM
unknown's avatar
unknown committed
109 110 111 112 113 114
%token	GE
%token	GT_SYM
%token	LE
%token	LT
%token	NE
%token	IS
115
%token	MOD_SYM
unknown's avatar
unknown committed
116 117 118 119
%token	SHIFT_LEFT
%token	SHIFT_RIGHT
%token  SET_VAR

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

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

unknown's avatar
unknown committed
406 407 408
%token  ERRORS
%token  WARNINGS

unknown's avatar
unknown committed
409
%token	ASCII_SYM
unknown's avatar
unknown committed
410 411 412
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
unknown's avatar
unknown committed
413
%token	CHANGED
unknown's avatar
unknown committed
414 415 416 417 418 419
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
420
%token	FAST_SYM
unknown's avatar
unknown committed
421
%token	FLOAT_SYM
unknown's avatar
unknown committed
422
%token  GEOMETRY_SYM
unknown's avatar
unknown committed
423 424 425 426 427 428 429 430 431
%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
432
%token	QUICK
unknown's avatar
unknown committed
433
%token	REAL
unknown's avatar
unknown committed
434
%token	SIGNED_SYM
unknown's avatar
unknown committed
435 436 437 438 439 440 441 442
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
unknown's avatar
unknown committed
443
%token	ULONGLONG_NUM
unknown's avatar
unknown committed
444
%token	UNSIGNED
445 446 447
%token	VARBINARY
%token	VARCHAR
%token	VARYING
unknown's avatar
unknown committed
448 449
%token	ZEROFILL

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

unknown's avatar
unknown committed
562 563 564 565
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
566
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
567
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
568

unknown's avatar
unknown committed
569 570
%token  ISSUER_SYM
%token  SUBJECT_SYM
571
%token  CIPHER_SYM
unknown's avatar
unknown committed
572

573
%token  BEFORE_SYM
unknown's avatar
unknown committed
574
%left   SET_VAR
575
%left	OR_OR_CONCAT OR XOR
unknown's avatar
unknown committed
576 577 578 579 580 581 582
%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	'-' '+'
583
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
584
%left   '^'
unknown's avatar
unknown committed
585
%left	NEG '~'
unknown's avatar
unknown committed
586
%right	NOT
unknown's avatar
unknown committed
587
%right	BINARY COLLATE_SYM
588

unknown's avatar
unknown committed
589
%type <lex_str>
590 591
	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
592
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
593
	NCHAR_STRING opt_component key_cache_name
unknown's avatar
unknown committed
594 595 596 597 598

%type <lex_str_ptr>
	opt_table_alias

%type <table>
unknown's avatar
unknown committed
599
	table_ident table_ident_ref references
unknown's avatar
unknown committed
600 601

%type <simple_string>
602
	remember_name remember_end opt_ident opt_db text_or_password
603
	opt_escape opt_constraint
unknown's avatar
unknown committed
604 605

%type <string>
606
	text_string opt_gconcat_separator
unknown's avatar
unknown committed
607 608

%type <num>
unknown's avatar
unknown committed
609
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
610
	udf_type if_exists opt_local opt_table_options table_options
611 612
        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
unknown's avatar
unknown committed
613
        opt_ignore_leaves fulltext_options spatial_type
unknown's avatar
unknown committed
614 615

%type <ulong_num>
616
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
617

unknown's avatar
unknown committed
618 619
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
620

unknown's avatar
unknown committed
621 622 623
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

unknown's avatar
unknown committed
624
%type <item>
unknown's avatar
unknown committed
625
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
626
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
627
	table_wild no_in_expr expr_expr simple_expr no_and_expr
628
	using_list expr_or_default set_expr_or_default interval_expr
unknown's avatar
unknown committed
629
	param_marker singlerow_subselect singlerow_subselect_init
unknown's avatar
unknown committed
630
	exists_subselect exists_subselect_init geometry_function
unknown's avatar
unknown committed
631
	signed_literal NUM_literal
unknown's avatar
unknown committed
632 633

%type <item_list>
unknown's avatar
unknown committed
634
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
635 636

%type <key_type>
637
	key_type opt_unique_or_fulltext constraint_key_type
unknown's avatar
unknown committed
638

unknown's avatar
unknown committed
639 640 641
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
642 643 644 645 646 647 648
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
649
	join_table_list  join_table
unknown's avatar
unknown committed
650 651 652 653 654

%type <udf>
	UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
	UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM

655
%type <date_time_type> date_time_type;
unknown's avatar
unknown committed
656 657
%type <interval> interval

unknown's avatar
unknown committed
658
%type <db_type> storage_engines
unknown's avatar
unknown committed
659 660 661

%type <row_type> row_types

unknown's avatar
unknown committed
662
%type <tx_isolation> isolation_types
unknown's avatar
unknown committed
663

unknown's avatar
unknown committed
664 665
%type <ha_rkey_mode> handler_rkey_mode

666
%type <cast_type> cast_type
unknown's avatar
unknown committed
667

unknown's avatar
unknown committed
668 669 670 671 672 673
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

674
%type <charset>
675
	opt_collate
676 677
	charset_name
	charset_name_or_default
unknown's avatar
unknown committed
678 679
	old_or_new_charset_name
	old_or_new_charset_name_or_default
680 681
	collation_name
	collation_name_or_default
682

unknown's avatar
unknown committed
683 684
%type <variable> internal_variable_name

unknown's avatar
unknown committed
685 686
%type <select_lex> in_subselect in_subselect_init

unknown's avatar
unknown committed
687 688
%type <boolfunc2creator> comp_op

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

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
725 726
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
unknown's avatar
unknown committed
727 728 729 730 731
%%


query:
	END_OF_INPUT
unknown's avatar
unknown committed
732
	{
733
	   THD *thd= YYTHD;
734
	   if (!thd->bootstrap &&
735
	      (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
736
	   {
737
	     send_error(thd,ER_EMPTY_QUERY);
738
	     YYABORT;
739
	   }
740 741
	   else
	   {
742
	     thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
743
	   }
unknown's avatar
unknown committed
744
	}
unknown's avatar
unknown committed
745
	| verb_clause END_OF_INPUT {};
unknown's avatar
unknown committed
746 747 748 749

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

unknown's avatar
unknown committed
792 793
/* help */

794
help:
795
       HELP_SYM ident_or_text
unknown's avatar
unknown committed
796
       {
797 798 799
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
800
       };
unknown's avatar
unknown committed
801 802 803 804

/* change master */

change:
unknown's avatar
unknown committed
805
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
806 807 808
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
unknown's avatar
unknown committed
809
	  bzero((char*) &lex->mi, sizeof(lex->mi));
810 811 812 813
        }
       master_defs
	{}
       ;
unknown's avatar
unknown committed
814 815 816

master_defs:
       master_def
unknown's avatar
unknown committed
817
       | master_defs ',' master_def;
unknown's avatar
unknown committed
818

unknown's avatar
unknown committed
819
master_def:
unknown's avatar
unknown committed
820
       MASTER_HOST_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
821 822 823 824
       {
	 Lex->mi.host = $3.str;
       }
       |
unknown's avatar
unknown committed
825
       MASTER_USER_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
826 827 828 829
       {
	 Lex->mi.user = $3.str;
       }
       |
unknown's avatar
unknown committed
830
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
831 832 833 834
       {
	 Lex->mi.password = $3.str;
       }
       |
unknown's avatar
unknown committed
835
       MASTER_PORT_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
836 837 838 839
       {
	 Lex->mi.port = $3;
       }
       |
unknown's avatar
unknown committed
840
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
841 842 843
       {
	 Lex->mi.connect_retry = $3;
       }
unknown's avatar
unknown committed
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
       | 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;
868
	 }
869
       |
870
         master_file_def
871
       ;
unknown's avatar
unknown committed
872

873 874
master_file_def:
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
875
       {
876
	 Lex->mi.log_file_name = $3.str;
877
       }
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
       | 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);
         }
904
       ;
unknown's avatar
unknown committed
905 906 907 908 909 910

/* create a table */

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

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

create2:
unknown's avatar
unknown committed
980
 	'(' create2a {}
981
	| opt_create_table_options create3 {}
unknown's avatar
unknown committed
982 983 984 985 986 987
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
988 989 990 991 992 993
	| '(' LIKE table_ident ')'
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$3))
              YYABORT;
    	  }
unknown's avatar
unknown committed
994
        ;
unknown's avatar
unknown committed
995

unknown's avatar
unknown committed
996 997
create2a:
        field_list ')' opt_create_table_options create3 {}
unknown's avatar
unknown committed
998
	|  create_select ')' { Select->set_braces(1);} union_opt {}
999
        ;
unknown's avatar
unknown committed
1000 1001

create3:
1002
	/* empty */ {}
unknown's avatar
unknown committed
1003
	| opt_duplicate opt_as     create_select
unknown's avatar
unknown committed
1004
          { Select->set_braces(0);} union_clause {}
unknown's avatar
unknown committed
1005
	| opt_duplicate opt_as '(' create_select ')'
unknown's avatar
unknown committed
1006
          { Select->set_braces(1);} union_opt {}
1007 1008
        ;

unknown's avatar
unknown committed
1009
create_select:
1010
          SELECT_SYM
unknown's avatar
unknown committed
1011
          {
unknown's avatar
unknown committed
1012 1013
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
1014 1015 1016 1017
	    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
1018
	    lex->current_select->table_list.save_and_clear(&lex->save_list);
unknown's avatar
unknown committed
1019
	    mysql_init_select(lex);
unknown's avatar
unknown committed
1020
	    lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
unknown's avatar
unknown committed
1021
          }
unknown's avatar
unknown committed
1022 1023 1024 1025
          select_options select_item_list
	  {
	    Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
	  }
unknown's avatar
unknown committed
1026
	  opt_select_from
unknown's avatar
unknown committed
1027
	  { Lex->current_select->table_list.push_front(&Lex->save_list); }
unknown's avatar
unknown committed
1028
        ;
unknown's avatar
unknown committed
1029

1030 1031
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
1032
	| AS	    {};
1033

1034 1035 1036 1037 1038 1039 1040 1041 1042
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
1043 1044
	  opt_default COLLATE_SYM collation_name_or_default	
	  { Lex->create_info.default_table_charset=$3; }
1045
	| opt_default charset charset_name_or_default
1046
	  { Lex->create_info.default_table_charset=$3; }
1047
	;
1048

unknown's avatar
unknown committed
1049
opt_table_options:
unknown's avatar
unknown committed
1050
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
1051
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
1052 1053 1054

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

unknown's avatar
unknown committed
1057
table_option:
unknown's avatar
unknown committed
1058
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
1059 1060

opt_if_not_exists:
unknown's avatar
unknown committed
1061
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
1062
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
1063 1064 1065

opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
1066
	| create_table_options;
unknown's avatar
unknown committed
1067

unknown's avatar
unknown committed
1068 1069 1070 1071
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
1072 1073
create_table_options:
	create_table_option
1074
	| create_table_option     create_table_options
unknown's avatar
unknown committed
1075
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
1076 1077

create_table_option:
unknown's avatar
unknown committed
1078
	ENGINE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; }
1079
	| TYPE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; WARN_DEPRECATED("TYPE=storage_engine","ENGINE=storage_engine"); }
1080 1081 1082
	| 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
1083 1084
	| 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; }
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
	| 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 ')'
1095 1096 1097
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
1098 1099
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
1100 1101
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
1102 1103
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
1104
	    table_list->next=0;
1105
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
1106
	  }
1107
	| DEFAULT charset opt_equal charset_name_or_default
1108
	  {
1109 1110 1111 1112 1113 1114
	    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;
1115 1116
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1117 1118 1119 1120 1121
	| 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;
	  }
1122 1123 1124 1125 1126
	| COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1127
	| 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
1128 1129 1130
	| 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
1131

unknown's avatar
unknown committed
1132
storage_engines:
1133 1134 1135 1136
	ident_or_text
	{
	  $$ = ha_resolve_by_name($1.str,$1.length);
	  if ($$ == DB_TYPE_UNKNOWN) {
unknown's avatar
unknown committed
1137
	    net_printf(YYTHD, ER_UNKNOWN_STORAGE_ENGINE, $1.str);
1138 1139 1140
	    YYABORT;
	  }
	};
unknown's avatar
unknown committed
1141 1142 1143 1144 1145

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
1146
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
1147 1148 1149 1150

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

1153 1154 1155
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
1156
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1157

unknown's avatar
unknown committed
1158
opt_select_from:
1159
	opt_limit_clause {}
unknown's avatar
unknown committed
1160
	| FROM DUAL_SYM {}
unknown's avatar
unknown committed
1161
	| select_from select_lock_type;
unknown's avatar
unknown committed
1162 1163

udf_func_type:
1164
	/* empty */	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
1165
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
1166 1167 1168 1169

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
1170
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
1171 1172 1173

field_list:
	  field_list_item
unknown's avatar
unknown committed
1174
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
1175 1176 1177


field_list_item:
unknown's avatar
unknown committed
1178
	   column_def
1179 1180 1181 1182
         | key_def
         ;

column_def:
1183
	  field_spec check_constraint
unknown's avatar
unknown committed
1184 1185 1186 1187
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1188
	;
1189 1190

key_def:
unknown's avatar
unknown committed
1191
	key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1192
	  {
unknown's avatar
unknown committed
1193
	    LEX *lex=Lex;
1194
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
unknown's avatar
unknown committed
1195
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1196
	  }
1197 1198 1199 1200 1201 1202 1203
	| 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 */
	  }
1204
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1205
	  {
1206 1207 1208 1209 1210 1211 1212 1213
	    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
1214
	  }
1215
	| opt_constraint check_constraint
unknown's avatar
unknown committed
1216 1217
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1218 1219 1220 1221 1222 1223 1224
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
unknown's avatar
unknown committed
1225 1226

opt_constraint:
1227 1228
	/* empty */		{ $$=(char*) 0; }
	| CONSTRAINT opt_ident	{ $$=$2; };
unknown's avatar
unknown committed
1229 1230 1231 1232

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1233 1234
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
unknown's avatar
unknown committed
1235 1236
	   lex->default_value=0;
	   lex->comment=0;
1237
	   lex->charset=NULL;
unknown's avatar
unknown committed
1238 1239 1240
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1241
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1242
	  if (add_field_to_list(lex->thd, $1.str,
unknown's avatar
unknown committed
1243
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1244
				lex->length,lex->dec,lex->type,
1245
				lex->default_value, lex->comment,
unknown's avatar
unknown committed
1246 1247
				lex->change,lex->interval,lex->charset,
				lex->uint_geom_type))
unknown's avatar
unknown committed
1248
	    YYABORT;
unknown's avatar
unknown committed
1249
	};
unknown's avatar
unknown committed
1250 1251

type:
1252
	int_type opt_len field_options	{ $$=$1; }
unknown's avatar
unknown committed
1253 1254 1255 1256 1257 1258
	| 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; }
1259 1260
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1261
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1262 1263 1264
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
unknown's avatar
unknown committed
1265
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1266
					  $$=FIELD_TYPE_STRING;
1267
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1268
	| nchar				{ Lex->length=(char*) "1";
unknown's avatar
unknown committed
1269
					  $$=FIELD_TYPE_STRING;
1270
					  Lex->charset=national_charset_info; }
1271
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1272
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1273 1274 1275
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
unknown's avatar
unknown committed
1276 1277
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
1278
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1279
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1280
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1281
					  $$=FIELD_TYPE_VAR_STRING; }
1282
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
unknown's avatar
unknown committed
1283 1284
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1285 1286
	| TIMESTAMP
	  {
1287
	    if (YYTHD->variables.sql_mode & MODE_MAXDB)
1288 1289
	      $$=FIELD_TYPE_DATETIME;
	    else
1290
	      $$=FIELD_TYPE_TIMESTAMP;
1291
	   }
unknown's avatar
unknown committed
1292 1293 1294
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
unknown's avatar
unknown committed
1295
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1296
					  $$=FIELD_TYPE_TINY_BLOB; }
unknown's avatar
unknown committed
1297
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1298
					  $$=FIELD_TYPE_BLOB; }
unknown's avatar
unknown committed
1299 1300 1301 1302 1303 1304 1305 1306
	| spatial_type			{ 
#ifdef HAVE_SPATIAL
					  Lex->charset=&my_charset_bin;
					  Lex->uint_geom_type= (uint)$1;
					  $$=FIELD_TYPE_GEOMETRY;
#else
	                                  net_printf(Lex->thd, ER_FEATURE_DISABLED,
			                             ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
1307 1308
			                             sym_group_geom.name,
	                                             sym_group_geom.needed_define);
unknown's avatar
unknown committed
1309 1310 1311
					  YYABORT;
#endif
					}
unknown's avatar
unknown committed
1312
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1313
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1314
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1315
					  $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1316
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1317
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1318 1319
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1320
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1321 1322
	| MEDIUMTEXT opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT opt_binary		{ $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1323 1324 1325 1326
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1327 1328
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1329
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1330
	  {
unknown's avatar
unknown committed
1331 1332
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1333 1334
	    $$=FIELD_TYPE_ENUM;
	  }
1335
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1336
	  {
unknown's avatar
unknown committed
1337 1338
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1339
	    $$=FIELD_TYPE_SET;
1340
	  }
1341
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1342 1343 1344 1345 1346 1347
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
1348
	;
unknown's avatar
unknown committed
1349

unknown's avatar
unknown committed
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
spatial_type:
	GEOMETRY_SYM	      { $$= Field::GEOM_GEOMETRY; }
	| GEOMETRYCOLLECTION  { $$= Field::GEOM_GEOMETRYCOLLECTION; }
	| POINT_SYM           { $$= Field::GEOM_POINT; }
	| MULTIPOINT          { $$= Field::GEOM_MULTIPOINT; }
	| LINESTRING          { $$= Field::GEOM_LINESTRING; }
	| MULTILINESTRING     { $$= Field::GEOM_MULTILINESTRING; }
	| POLYGON             { $$= Field::GEOM_POLYGON; }
	| MULTIPOLYGON        { $$= Field::GEOM_MULTIPOLYGON; }
	;

unknown's avatar
unknown committed
1361 1362
char:
	CHAR_SYM {}
unknown's avatar
unknown committed
1363 1364 1365 1366 1367 1368
	;

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

unknown's avatar
unknown committed
1370 1371 1372
varchar:
	char VARYING {}
	| VARCHAR {}
unknown's avatar
unknown committed
1373 1374 1375 1376
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
unknown's avatar
unknown committed
1377
	| NVARCHAR_SYM {}
unknown's avatar
unknown committed
1378 1379 1380 1381
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
unknown's avatar
unknown committed
1382 1383 1384 1385 1386 1387

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1388
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1389 1390

real_type:
1391
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1392 1393
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1394
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1395 1396 1397 1398 1399


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1400
	| precision		{};
unknown's avatar
unknown committed
1401 1402 1403 1404 1405 1406

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1407
	};
unknown's avatar
unknown committed
1408 1409 1410

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1411
	| field_opt_list	{};
unknown's avatar
unknown committed
1412 1413 1414

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1415
	| field_option {};
unknown's avatar
unknown committed
1416 1417

field_option:
unknown's avatar
unknown committed
1418
	SIGNED_SYM	{}
1419
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1420
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1421 1422

opt_len:
1423 1424
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1425 1426 1427

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1428
	| precision	{};
unknown's avatar
unknown committed
1429 1430 1431

opt_attribute:
	/* empty */ {}
unknown's avatar
unknown committed
1432
	| opt_attribute_list {};
unknown's avatar
unknown committed
1433 1434 1435

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1436
	| attribute;
unknown's avatar
unknown committed
1437 1438 1439 1440

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
unknown's avatar
unknown committed
1441
	| DEFAULT signed_literal { Lex->default_value=$2; }
unknown's avatar
unknown committed
1442
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1443
	| SERIAL_SYM DEFAULT VALUE_SYM
unknown's avatar
unknown committed
1444 1445
	  { 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
1446
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1447
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
unknown's avatar
unknown committed
1448
	| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
unknown's avatar
unknown committed
1449 1450
	| COLLATE_SYM collation_name
	  {
unknown's avatar
unknown committed
1451
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
unknown's avatar
unknown committed
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $2->name,Lex->charset->csname);
	      YYABORT;
	    }
	    else
	    {
	      Lex->charset=$2;
	    }
	  }
	;
unknown's avatar
unknown committed
1463

1464 1465 1466 1467
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
unknown's avatar
unknown committed
1468

1469
charset_name:
1470
	ident_or_text
1471
	{
unknown's avatar
unknown committed
1472
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
1473
	  {
1474
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1475 1476
	    YYABORT;
	  }
unknown's avatar
unknown committed
1477 1478 1479
	}
	| BINARY { $$= &my_charset_bin; }
	;
1480

1481 1482 1483
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1484

unknown's avatar
unknown committed
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502

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; } ;

1503
collation_name:
1504
	ident_or_text
1505 1506 1507
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
1508
	    net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str);
1509 1510 1511 1512
	    YYABORT;
	  }
	};

1513 1514
opt_collate:
	/* empty */	{ $$=NULL; }
unknown's avatar
unknown committed
1515
	| COLLATE_SYM collation_name_or_default { $$=$2; }
1516 1517
	;

1518 1519 1520 1521
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1522 1523 1524 1525
opt_default:
	/* empty */	{}
	| DEFAULT	{};

unknown's avatar
unknown committed
1526
opt_binary:
1527
	/* empty */			{ Lex->charset=NULL; }
unknown's avatar
unknown committed
1528 1529 1530
	| 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
1531 1532
	| UNICODE_SYM
	{
1533
	  if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
unknown's avatar
unknown committed
1534 1535 1536 1537 1538
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1539
	| charset charset_name	{ Lex->charset=$2; } ;
unknown's avatar
unknown committed
1540

unknown's avatar
unknown committed
1541 1542 1543
opt_primary:
	/* empty */
	| PRIMARY_SYM
1544
	;
unknown's avatar
unknown committed
1545

unknown's avatar
unknown committed
1546
references:
1547 1548
	REFERENCES table_ident
	{
1549
	  LEX *lex=Lex;
1550 1551 1552 1553 1554 1555
	  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
1556
	};
1557

1558
opt_ref_list:
unknown's avatar
unknown committed
1559
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1560
	| '(' ref_list ')' opt_on_delete {};
1561 1562 1563

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

unknown's avatar
unknown committed
1566 1567 1568

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1569
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1570 1571 1572

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1573
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1574 1575

opt_on_delete_item:
1576 1577 1578 1579
	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
1580
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1581 1582

delete_option:
1583 1584 1585 1586
	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
1587
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1588 1589

key_type:
1590
	key_or_index			    { $$= Key::MULTIPLE; }
unknown's avatar
SCRUM  
unknown committed
1591 1592
	| FULLTEXT_SYM opt_key_or_index	    { $$= Key::FULLTEXT; }
	| SPATIAL_SYM opt_key_or_index
unknown's avatar
unknown committed
1593 1594 1595 1596 1597 1598
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
	               ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
1599
		       sym_group_geom.name, sym_group_geom.needed_define);
unknown's avatar
unknown committed
1600 1601 1602
	    YYABORT;
#endif
	  };
1603 1604 1605

constraint_key_type:
	PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
unknown's avatar
SCRUM  
unknown committed
1606
	| UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1607 1608 1609

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1610
	| INDEX {};
unknown's avatar
unknown committed
1611

unknown's avatar
SCRUM  
unknown committed
1612 1613 1614 1615 1616
opt_key_or_index:
	/* empty */ {}
	| key_or_index
	;

unknown's avatar
unknown committed
1617 1618 1619
keys_or_index:
	KEYS {}
	| INDEX {}
unknown's avatar
unknown committed
1620
	| INDEXES {};
unknown's avatar
unknown committed
1621

1622
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1623 1624
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1625
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT;}
unknown's avatar
unknown committed
1626 1627 1628 1629 1630 1631 1632
	| SPATIAL_SYM
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
	               ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
1633
	               sym_group_geom.name, sym_group_geom.needed_define);
unknown's avatar
unknown committed
1634 1635 1636
	    YYABORT;
#endif
	  }
unknown's avatar
unknown committed
1637
        ;
unknown's avatar
unknown committed
1638 1639

key_alg:
1640
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1641
	| USING opt_btree_or_rtree { $$= $2; }
unknown's avatar
unknown committed
1642
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
unknown's avatar
unknown committed
1643 1644 1645

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
unknown's avatar
unknown committed
1646 1647 1648 1649
	| RTREE_SYM
	  {
	    $$= HA_KEY_ALG_RTREE;
	  }
unknown's avatar
unknown committed
1650
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1651 1652 1653

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1654
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1655 1656 1657

key_part:
	ident			{ $$=new key_part_spec($1.str); }
unknown's avatar
unknown committed
1658
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
unknown's avatar
unknown committed
1659 1660 1661

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

1664 1665 1666
opt_component:
	/* empty */	 { $$.str= 0; $$.length= 0; }
	| '.' ident	 { $$=$2; };
1667

unknown's avatar
unknown committed
1668 1669
string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1670
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1671 1672 1673 1674 1675 1676 1677 1678

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1679
	  THD *thd= YYTHD;
1680
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
1681 1682
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
unknown's avatar
unknown committed
1683 1684
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1685 1686 1687 1688 1689 1690
	    YYABORT;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
	  lex->drop_list.empty();
	  lex->alter_list.empty();
1691
          lex->select_lex.init_order();
1692
	  lex->select_lex.db=lex->name=0;
1693
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
unknown's avatar
unknown committed
1694
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1695
	  lex->create_info.default_table_charset= thd->variables.collation_database;
1696
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1697
          lex->alter_keys_onoff=LEAVE_AS_IS;
unknown's avatar
unknown committed
1698
	  lex->tablespace_op=NO_TABLESPACE_OP;
1699
          lex->simple_alter=1;
unknown's avatar
unknown committed
1700
	}
1701 1702
	alter_list
	{}
1703
	| ALTER DATABASE ident opt_create_database_options
1704 1705 1706 1707
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1708
	  };
1709 1710


unknown's avatar
unknown committed
1711
alter_list:
unknown's avatar
unknown committed
1712 1713
	| DISCARD TABLESPACE { Lex->tablespace_op=DISCARD_TABLESPACE; }
	| IMPORT TABLESPACE { Lex->tablespace_op=IMPORT_TABLESPACE; }
unknown's avatar
unknown committed
1714
        | alter_list_item
unknown's avatar
unknown committed
1715
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1716 1717

add_column:
unknown's avatar
unknown committed
1718
	ADD opt_column { Lex->change=0; };
unknown's avatar
unknown committed
1719 1720

alter_list_item:
1721 1722
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1723
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1724 1725 1726 1727 1728
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1729
          field_spec opt_place
unknown's avatar
unknown committed
1730 1731 1732 1733
        | 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
1734 1735
            lex->default_value=0;
	    lex->comment=0;
1736
	    lex->charset= NULL;
unknown's avatar
unknown committed
1737
            lex->simple_alter=0;
unknown's avatar
unknown committed
1738 1739 1740 1741
          }
          type opt_attribute
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
1742
            if (add_field_to_list(lex->thd,$3.str,
unknown's avatar
unknown committed
1743 1744 1745
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
unknown's avatar
unknown committed
1746 1747
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
unknown's avatar
unknown committed
1748 1749 1750
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1751
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1752 1753 1754 1755 1756
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
					    $3.str)); lex->simple_alter=0;
	  }
1757
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1758 1759 1760
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
1761 1762 1763
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    primary_key_name));
	    lex->simple_alter=0;
unknown's avatar
unknown committed
1764
	  }
unknown's avatar
unknown committed
1765
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1766 1767 1768 1769 1770 1771
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1772 1773
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
unknown's avatar
unknown committed
1774
	| ALTER opt_column field_ident SET DEFAULT signed_literal
unknown's avatar
unknown committed
1775 1776 1777 1778 1779
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
unknown's avatar
unknown committed
1780
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1781 1782 1783 1784 1785
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1786
	| RENAME opt_to table_ident
1787
	  {
1788
	    LEX *lex=Lex;
1789
	    lex->select_lex.db=$3->db.str;
1790
	    lex->name= $3->table.str;
1791
	  }
unknown's avatar
unknown committed
1792
        | create_table_options_space_separated { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1793
	| order_clause         { Lex->simple_alter=0; };
unknown's avatar
unknown committed
1794 1795 1796

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
1797
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
1798 1799 1800

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
unknown's avatar
unknown committed
1801
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
1802 1803 1804 1805

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
1806
	| CASCADE	{};
unknown's avatar
unknown committed
1807 1808 1809 1810

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
1811
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
1812 1813 1814 1815

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1816
	| EQ		{}
unknown's avatar
unknown committed
1817
	| AS		{};
unknown's avatar
unknown committed
1818

unknown's avatar
unknown committed
1819
/*
1820
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
unknown's avatar
unknown committed
1821 1822
*/

unknown's avatar
unknown committed
1823
slave:
1824 1825 1826 1827 1828 1829 1830
	  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));
unknown's avatar
unknown committed
1831
            /* If you change this code don't forget to update SLAVE START too */
1832 1833 1834
          }
          slave_until
          {}
unknown's avatar
unknown committed
1835 1836 1837 1838 1839
        | STOP_SYM SLAVE slave_thread_opts
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_STOP;
	    lex->type = 0;
unknown's avatar
unknown committed
1840
            /* If you change this code don't forget to update SLAVE STOP too */
unknown's avatar
unknown committed
1841
          }
1842 1843 1844 1845 1846
	| SLAVE START_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
1847 1848 1849 1850 1851
	    /* We'll use mi structure for UNTIL options */
	    bzero((char*) &lex->mi, sizeof(lex->mi));
          }
          slave_until
          {}
1852 1853 1854 1855 1856 1857 1858 1859
	| SLAVE STOP_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_STOP;
	   lex->type = 0;
         }
        ;

unknown's avatar
unknown committed
1860

unknown's avatar
unknown committed
1861 1862 1863 1864 1865
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

unknown's avatar
unknown committed
1866
slave_thread_opts:
1867 1868
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
1869
        {}
unknown's avatar
unknown committed
1870
	;
1871 1872

slave_thread_opt_list:
unknown's avatar
unknown committed
1873
	slave_thread_opt
1874 1875
	| slave_thread_opt_list ',' slave_thread_opt
	;
1876 1877

slave_thread_opt:
1878
	/*empty*/	{}
unknown's avatar
unknown committed
1879
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
unknown's avatar
unknown committed
1880
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
unknown's avatar
unknown committed
1881
	;
1882

1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
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
1905 1906 1907 1908 1909
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
unknown's avatar
unknown committed
1910
	table_list FROM TEXT_STRING_sys
unknown's avatar
unknown committed
1911 1912
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1913
        };
unknown's avatar
unknown committed
1914

unknown's avatar
unknown committed
1915 1916 1917 1918 1919
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
unknown's avatar
unknown committed
1920
	table_list TO_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
1921 1922
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1923
        };
unknown's avatar
unknown committed
1924

1925 1926 1927 1928 1929 1930
checksum:
        CHECKSUM_SYM table_or_tables
	{
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECKSUM;
	}
1931 1932
	table_list opt_checksum_type
        {}
1933 1934
	;

1935 1936 1937 1938 1939 1940
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
1941
repair:
1942
	REPAIR opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1943
	{
unknown's avatar
unknown committed
1944 1945
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
1946
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1947
	   lex->check_opt.init();
unknown's avatar
unknown committed
1948
	}
1949 1950 1951
	table_list opt_mi_repair_type
	{}
	;
unknown's avatar
unknown committed
1952

unknown's avatar
unknown committed
1953
opt_mi_repair_type:
unknown's avatar
unknown committed
1954
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1955
	| mi_repair_types {};
unknown's avatar
unknown committed
1956

unknown's avatar
unknown committed
1957 1958
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
1959
	| mi_repair_type mi_repair_types {};
1960

unknown's avatar
unknown committed
1961
mi_repair_type:
unknown's avatar
unknown committed
1962
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1963
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1964
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
1965 1966

analyze:
1967
	ANALYZE_SYM opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1968
	{
unknown's avatar
unknown committed
1969 1970
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
1971
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1972
	   lex->check_opt.init();
unknown's avatar
unknown committed
1973
	}
1974 1975 1976
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1977 1978

check:
unknown's avatar
unknown committed
1979
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
1980
	{
unknown's avatar
unknown committed
1981 1982 1983
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1984
	}
1985 1986 1987
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1988

unknown's avatar
unknown committed
1989 1990
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1991
	| mi_check_types {};
unknown's avatar
unknown committed
1992 1993 1994

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
1995
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
1996 1997 1998 1999 2000 2001

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
2002
	| CHANGED  { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; };
unknown's avatar
unknown committed
2003

unknown's avatar
unknown committed
2004
optimize:
2005
	OPTIMIZE opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
2006
	{
unknown's avatar
unknown committed
2007 2008
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
unknown's avatar
unknown committed
2009
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
2010
	   lex->check_opt.init();
unknown's avatar
unknown committed
2011
	}
2012 2013 2014
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
2015

2016 2017 2018
opt_no_write_to_binlog:
	/* empty */        { $$= 0; }
	| NO_WRITE_TO_BINLOG  { $$= 1; }
2019
	| LOCAL_SYM  { $$= 1; }
2020 2021
	;

2022 2023 2024 2025 2026
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
2027 2028 2029
	table_to_table_list
	{}
	;
2030 2031 2032

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
2033
	| table_to_table_list ',' table_to_table;
2034 2035 2036

table_to_table:
	table_ident TO_SYM table_ident
2037
	{
unknown's avatar
unknown committed
2038
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2039
	  SELECT_LEX *sl= lex->current_select;
unknown's avatar
unknown committed
2040 2041 2042 2043
	  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))
2044
	    YYABORT;
2045
	};
2046

unknown's avatar
unknown committed
2047
keycache:
2048
        CACHE_SYM INDEX keycache_list IN_SYM key_cache_name
unknown's avatar
unknown committed
2049 2050
        {
          LEX *lex=Lex;
2051 2052
          lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
	  lex->name_and_length= $5;
unknown's avatar
unknown committed
2053 2054 2055 2056 2057 2058 2059 2060
        }
        ;

keycache_list:
        assign_to_keycache
        | keycache_list ',' assign_to_keycache;

assign_to_keycache:
2061
        table_ident cache_keys_spec
unknown's avatar
unknown committed
2062 2063 2064 2065 2066 2067
        {
          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(),
2068
                                      (List<String> *)0))
unknown's avatar
unknown committed
2069 2070 2071 2072
            YYABORT;
        }
        ;

2073 2074 2075
key_cache_name:
	ident	   { $$= $1; }
	| DEFAULT  { $$ = default_key_cache_base; }
2076
	;
2077

unknown's avatar
unknown committed
2078
preload:
unknown's avatar
unknown committed
2079
	LOAD INDEX INTO CACHE_SYM
unknown's avatar
unknown committed
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
	{
	  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
2093
	table_ident cache_keys_spec opt_ignore_leaves
unknown's avatar
unknown committed
2094 2095 2096
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
unknown's avatar
unknown committed
2097 2098
	  if (!sel->add_table_to_list(lex->thd, $1, NULL, $3,
                                      TL_READ,
unknown's avatar
unknown committed
2099 2100 2101 2102 2103 2104
                                      sel->get_use_index(),
                                      (List<String> *)0))
            YYABORT;
	}
	;

2105
cache_keys_spec:
2106
        { Select->interval_list.empty(); }
2107 2108 2109 2110 2111 2112 2113
        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
2114

unknown's avatar
unknown committed
2115
cache_key_list_or_empty:
2116
	/* empty */	{ Lex->select_lex.use_index_ptr= 0; }
2117
	| opt_key_or_index '(' key_usage_list2 ')'
2118 2119 2120 2121
	  {
            SELECT_LEX *sel= &Lex->select_lex;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2122 2123
	;

unknown's avatar
unknown committed
2124
opt_ignore_leaves:
unknown's avatar
unknown committed
2125 2126 2127 2128 2129
	/* empty */
	{ $$= 0; }
	| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
	;

unknown's avatar
unknown committed
2130
/*
unknown's avatar
unknown committed
2131
  Select : retrieve data from table
unknown's avatar
unknown committed
2132 2133 2134 2135
*/


select:
2136 2137 2138 2139 2140
	select_init
	{
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_SELECT;
	  lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
unknown's avatar
unknown committed
2141 2142
	}
	;
unknown's avatar
unknown committed
2143

2144
/* Need select_init2 for subselects. */
unknown's avatar
unknown committed
2145
select_init:
2146
	SELECT_SYM select_init2
2147
	|
2148 2149
	'(' SELECT_SYM select_part2 ')'
	  {
2150
	    LEX *lex= Lex;
unknown's avatar
unknown committed
2151
            SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2152
	    if (sel->set_braces(1))
2153
	    {
2154
	      yyerror(ER(ER_SYNTAX_ERROR));
2155 2156
	      YYABORT;
	    }
2157 2158
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
2159
	  {
2160
	    yyerror(ER(ER_SYNTAX_ERROR));
unknown's avatar
unknown committed
2161 2162
	    YYABORT;
	  }
2163
            /* select in braces, can't contain global parameters */
unknown's avatar
unknown committed
2164 2165 2166
	    if (sel->master_unit()->fake_select_lex)
              sel->master_unit()->global_parameters=
                 sel->master_unit()->fake_select_lex;
unknown's avatar
unknown committed
2167
          } union_opt;
2168

2169 2170
select_init2:
	select_part2
2171
        {
2172
	  LEX *lex= Lex;
unknown's avatar
unknown committed
2173
          SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2174
          if (lex->current_select->set_braces(0))
2175
	  {
2176
	    yyerror(ER(ER_SYNTAX_ERROR));
2177 2178
	    YYABORT;
	  }
2179 2180
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
2181
	  {
2182
	    yyerror(ER(ER_SYNTAX_ERROR));
unknown's avatar
unknown committed
2183 2184
	    YYABORT;
	  }
2185
	}
2186
	union_clause
2187 2188
	;

2189
select_part2:
unknown's avatar
unknown committed
2190
	{
unknown's avatar
unknown committed
2191 2192 2193
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
	  lex->lock_option= TL_READ;
unknown's avatar
unknown committed
2194 2195
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
unknown's avatar
unknown committed
2196 2197 2198 2199 2200
	  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
2201
	}
unknown's avatar
unknown committed
2202
	select_into select_lock_type;
2203

unknown's avatar
unknown committed
2204
select_into:
2205 2206 2207 2208 2209 2210
	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
2211
	| select_from
2212 2213
	| into select_from
	| select_from into;
unknown's avatar
unknown committed
2214 2215

select_from:
2216
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
unknown's avatar
unknown committed
2217 2218 2219

select_options:
	/* empty*/
unknown's avatar
unknown committed
2220
	| select_option_list;
unknown's avatar
unknown committed
2221 2222 2223

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
2224
	| select_option;
unknown's avatar
unknown committed
2225 2226

select_option:
2227
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
2228 2229 2230 2231 2232 2233
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
2234 2235 2236
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248
	| 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;
	  }
2249
	| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
2250 2251 2252 2253
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
2254 2255
	| ALL		{}
	;
unknown's avatar
unknown committed
2256

unknown's avatar
unknown committed
2257 2258 2259
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
2260 2261
	  {
	    LEX *lex=Lex;
2262
	    lex->current_select->set_lock_for_tables(TL_WRITE);
2263
	    lex->safe_to_cache_query=0;
2264
	  }
unknown's avatar
unknown committed
2265
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2266 2267
	  {
	    LEX *lex=Lex;
2268 2269
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2270
	    lex->safe_to_cache_query=0;
2271 2272
	  }
	;
unknown's avatar
unknown committed
2273

unknown's avatar
unknown committed
2274 2275 2276 2277 2278
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
2279 2280
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
unknown's avatar
unknown committed
2281
	      YYABORT;
2282
	    (thd->lex->current_select->with_wild)++;
unknown's avatar
unknown committed
2283
	  };
unknown's avatar
unknown committed
2284 2285 2286 2287 2288


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
unknown's avatar
unknown committed
2289
	    if (add_item_to_list(YYTHD, $2))
unknown's avatar
unknown committed
2290 2291
	      YYABORT;
	    if ($4.str)
unknown's avatar
unknown committed
2292
	      $2->set_name($4.str,$4.length,system_charset_info);
unknown's avatar
unknown committed
2293
	    else if (!$2->name)
unknown's avatar
unknown committed
2294
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
unknown's avatar
unknown committed
2295
	  };
unknown's avatar
unknown committed
2296 2297

remember_name:
unknown's avatar
unknown committed
2298
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
2299 2300

remember_end:
unknown's avatar
unknown committed
2301
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
2302 2303 2304

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
2305
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
2306 2307

select_alias:
unknown's avatar
unknown committed
2308 2309 2310 2311 2312 2313
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
unknown's avatar
unknown committed
2314 2315 2316

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

unknown's avatar
unknown committed
2319
/* all possible expressions */
unknown's avatar
SCRUM  
unknown committed
2320 2321 2322 2323
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
unknown's avatar
unknown committed
2324

unknown's avatar
unknown committed
2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
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
2337 2338
/* expressions that begin with 'expr' */
expr_expr:
unknown's avatar
SCRUM  
unknown committed
2339
	 expr IN_SYM '(' expr_list ')'
2340
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
unknown's avatar
unknown committed
2341
	| expr NOT IN_SYM '(' expr_list ')'
2342
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
unknown's avatar
unknown committed
2343
        | expr IN_SYM in_subselect
2344
          { $$= new Item_in_subselect($1, $3); }
unknown's avatar
unknown committed
2345
	| expr NOT IN_SYM in_subselect
2346
          {
2347
            $$= new Item_func_not(new Item_in_subselect($1, $4));
unknown's avatar
unknown committed
2348
          }
unknown's avatar
unknown committed
2349 2350 2351 2352
	| 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)); }
2353
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2354
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2355
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2356
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2357 2358 2359 2360 2361 2362 2363 2364 2365
	| 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
2366
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2367 2368
	| expr NOT REGEXP expr
          { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2369 2370 2371
	| 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
2372
	| expr comp_op expr %prec EQ	{ $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2373 2374
	| expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2375
	  $$= all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2376
	}
unknown's avatar
unknown committed
2377 2378 2379 2380 2381 2382
	| 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); }
2383 2384
	| 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
2385
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2386
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2387 2388
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2389 2390 2391 2392
	| 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
2393
	;
unknown's avatar
unknown committed
2394 2395 2396 2397 2398 2399 2400

/* 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)); }
2401
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2402
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2403
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2404
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2405 2406 2407 2408 2409 2410 2411 2412 2413
	| 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
2414
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2415 2416
	| no_in_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2417 2418 2419
	| 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
2420
	| no_in_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2421 2422
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2423
	  all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2424
	}
unknown's avatar
unknown committed
2425 2426 2427 2428 2429 2430
	| 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); }
2431
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2432
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2433
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2434 2435
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2436
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2437 2438 2439 2440
	| 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
2441
	| simple_expr;
unknown's avatar
unknown committed
2442 2443 2444

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
unknown's avatar
unknown committed
2445
	  no_and_expr IN_SYM '(' expr_list ')'
2446
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
unknown's avatar
unknown committed
2447
	| no_and_expr NOT IN_SYM '(' expr_list ')'
2448
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
unknown's avatar
unknown committed
2449
        | no_and_expr IN_SYM in_subselect
2450
          { $$= new Item_in_subselect($1, $3); }
unknown's avatar
unknown committed
2451
	| no_and_expr NOT IN_SYM in_subselect
2452
          {
2453
            $$= new Item_func_not(new Item_in_subselect($1, $4));
unknown's avatar
unknown committed
2454
          }
unknown's avatar
unknown committed
2455 2456 2457 2458
	| 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)); }
2459
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2460
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2461
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2462 2463 2464 2465 2466 2467 2468 2469 2470
	| 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
2471
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2472 2473
	| no_and_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2474 2475 2476
	| 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
2477
	| no_and_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2478 2479
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2480
	  all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2481
	}
unknown's avatar
unknown committed
2482 2483 2484 2485 2486 2487
	| 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); }
2488
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2489
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2490
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2491 2492
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2493
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2494 2495 2496 2497
	| 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
2498
	| simple_expr;
unknown's avatar
unknown committed
2499

2500
interval_expr:
unknown's avatar
unknown committed
2501
         INTERVAL_SYM expr { $$=$2; }
2502 2503
        ;

unknown's avatar
unknown committed
2504 2505
simple_expr:
	simple_ident
2506
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
unknown's avatar
unknown committed
2507
	  {
unknown's avatar
unknown committed
2508 2509 2510 2511
	    $$= new Item_func_set_collation($1,
					    new Item_string($3.str,
							    $3.length,
					    		    YYTHD->charset()));
2512
	  }
unknown's avatar
unknown committed
2513
	| literal
unknown's avatar
unknown committed
2514
	| param_marker
unknown's avatar
unknown committed
2515
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
2516 2517
	  {
	    $$= new Item_func_set_user_var($2,$4);
2518
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2519
	  }
2520
	| '@' ident_or_text
unknown's avatar
unknown committed
2521 2522
	  {
	    $$= new Item_func_get_user_var($2);
2523
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2524
	  }
2525
	| '@' '@' opt_var_ident_type ident_or_text opt_component
unknown's avatar
unknown committed
2526
	  {
2527
	    if (!($$= get_system_var(YYTHD, (enum_var_type) $3, $4, $5)))
unknown's avatar
unknown committed
2528
	      YYABORT;
unknown's avatar
unknown committed
2529
	  }
unknown's avatar
unknown committed
2530
	| sum_expr
2531 2532
	| '+' expr %prec NEG	{ $$= $2; }
	| '-' expr %prec NEG    { $$= new Item_func_neg($2); }
unknown's avatar
unknown committed
2533 2534 2535 2536
	| '~' 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; }
2537 2538 2539 2540 2541
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
2542
	| ROW_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2543
	  {
2544 2545
	    $5->push_front($3);
	    $$= new Item_row(*$5);
unknown's avatar
unknown committed
2546
	  }
unknown's avatar
unknown committed
2547
	| EXISTS exists_subselect { $$= $2; }
unknown's avatar
unknown committed
2548
	| singlerow_subselect   { $$= $1; }
unknown's avatar
unknown committed
2549
	| '{' ident expr '}'	{ $$= $3; }
2550
        | MATCH ident_list_arg AGAINST '(' expr fulltext_options ')'
2551
          { $2->push_front($5);
2552 2553
            Select->add_ftfunc_to_list((Item_func_match*)
                                        ($$=new Item_func_match(*$2,$6))); }
unknown's avatar
unknown committed
2554
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
unknown's avatar
unknown committed
2555
	| BINARY expr %prec NEG
unknown's avatar
unknown committed
2556
	  {
unknown's avatar
unknown committed
2557 2558
	    $$= new Item_func_set_collation($2,new Item_string(binary_keyword,
					    6, &my_charset_latin1));
unknown's avatar
unknown committed
2559
	  }
2560
	| CAST_SYM '(' expr AS cast_type ')'
2561 2562
	  {
	    $$= create_func_cast($3, $5,
2563
				 Lex->length ? atoi(Lex->length) : -1,
2564
				 Lex->charset);
2565
	  }
unknown's avatar
unknown committed
2566
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
2567
	  { $$= new Item_func_case(* $4, $2, $5 ); }
2568
	| CONVERT_SYM '(' expr ',' cast_type ')'
2569 2570 2571 2572 2573
	  {
	    $$= create_func_cast($3, $5,
				 Lex->length ? atoi(Lex->length) : -1,
				 Lex->charset);
	  }
2574 2575
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
unknown's avatar
SCRUM  
unknown committed
2576 2577
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
unknown's avatar
unknown committed
2578 2579
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
unknown's avatar
unknown committed
2580
	| FUNC_ARG0 '(' ')'
unknown's avatar
unknown committed
2581 2582 2583 2584 2585
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
2586
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2587 2588 2589 2590 2591
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(void))($1.symbol->create_func))();
	  }
unknown's avatar
unknown committed
2592
	| FUNC_ARG1 '(' expr ')'
unknown's avatar
unknown committed
2593 2594 2595 2596 2597
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
2598
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2599 2600 2601 2602 2603
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
	  }
unknown's avatar
unknown committed
2604
	| FUNC_ARG2 '(' expr ',' expr ')'
unknown's avatar
unknown committed
2605 2606 2607 2608 2609
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
2610
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2611 2612 2613 2614 2615
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
	  }
unknown's avatar
unknown committed
2616
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
unknown's avatar
unknown committed
2617 2618 2619 2620 2621
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
2622
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2623 2624 2625 2626 2627
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
	  }
unknown's avatar
unknown committed
2628 2629 2630 2631
	| 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
2632 2633 2634 2635 2636 2637
	| 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
2638 2639
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
2640 2641
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
unknown's avatar
unknown committed
2642 2643
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
unknown's avatar
unknown committed
2644 2645 2646 2647 2648
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
2649
	  { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2650
	| CURTIME optional_braces
2651
	  { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2652
	| CURTIME '(' expr ')'
2653
	  {
2654
	    $$= new Item_func_curtime_local($3);
2655
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2656
	  }
2657 2658 2659 2660
	| 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
2661
	| DATABASE '(' ')'
2662
	  {
unknown's avatar
unknown committed
2663
	    $$= new Item_func_database();
2664
            Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2665
	  }
unknown's avatar
unknown committed
2666
	| DATE_SYM '(' expr ')'
unknown's avatar
unknown committed
2667
	  { $$= new Item_date_typecast($3); }
unknown's avatar
unknown committed
2668 2669
	| DAY_SYM '(' expr ')'
	  { $$= new Item_func_dayofmonth($3); }
unknown's avatar
unknown committed
2670
	| ELT_FUNC '(' expr ',' expr_list ')'
2671
	  { $5->push_front($3); $$= new Item_func_elt(*$5); }
unknown's avatar
unknown committed
2672 2673
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
unknown's avatar
unknown committed
2674 2675 2676
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
2677
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2678
	  }
unknown's avatar
unknown committed
2679
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
2680
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2681
	  { $$= new Item_func_decode($3,$5.str); }
2682
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2683
	 { $$= new Item_func_encode($3,$5.str); }
unknown's avatar
unknown committed
2684
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2685
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
2686
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2687
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
2688
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2689
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
2690
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2691
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
2692 2693 2694 2695 2696 2697
	| 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); }
2698 2699
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
2700 2701 2702 2703 2704 2705
	| 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
2706
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2707 2708
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
2709
	  { $5->push_front($3); $$= new Item_func_field(*$5); }
unknown's avatar
unknown committed
2710 2711 2712 2713 2714 2715 2716
	| geometry_function
	  {
#ifdef HAVE_SPATIAL
	    $$= $1;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
	               ER(ER_FEATURE_DISABLED),
unknown's avatar
SCRUM  
unknown committed
2717
	               sym_group_geom.name, sym_group_geom.needed_define);
unknown's avatar
unknown committed
2718 2719 2720
	    YYABORT;
#endif
	  }
2721
	| GET_FORMAT '(' date_time_type  ',' expr ')'
2722
	  { $$= new Item_func_get_format($3, $5); }
unknown's avatar
unknown committed
2723 2724 2725 2726 2727 2728
	| 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); }
2729
	| interval_expr interval '+' expr
unknown's avatar
unknown committed
2730
	  /* we cannot put interval before - */
2731 2732 2733 2734 2735
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
2736
              yyerror(ER(ER_SYNTAX_ERROR));
2737 2738 2739 2740
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
unknown's avatar
unknown committed
2741 2742
	| LAST_INSERT_ID '(' ')'
	  {
2743
	    $$= get_system_var(YYTHD, OPT_SESSION, "last_insert_id", 14,
2744
			      "last_insert_id()");
2745
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2746 2747 2748 2749
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
2750
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2751 2752 2753 2754 2755 2756 2757
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
	| 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
2758
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2759 2760 2761
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
2762
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
2763
	  { $$= new Item_func_log($3); }
2764
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2765
	  { $$= new Item_func_log($3, $5); }
2766
	| MASTER_POS_WAIT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2767
	  {
2768
	    $$= new Item_master_pos_wait($3, $5);
unknown's avatar
unknown committed
2769
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2770
		  }
2771
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
unknown's avatar
unknown committed
2772
	  {
2773
	    $$= new Item_master_pos_wait($3, $5, $7);
unknown's avatar
unknown committed
2774
	    Lex->safe_to_cache_query=0;
2775
	  }
unknown's avatar
unknown committed
2776 2777
	| MICROSECOND_SYM '(' expr ')'
	  { $$= new Item_func_microsecond($3); }
unknown's avatar
unknown committed
2778 2779
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
2780 2781
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
2782 2783 2784
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
	| NOW_SYM optional_braces
2785
	  { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2786
	| NOW_SYM '(' expr ')'
2787
	  { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2788
	| PASSWORD '(' expr ')'
2789
	  {
2790 2791
	    $$= YYTHD->variables.old_passwords ?
              (Item *) new Item_func_old_password($3) :
unknown's avatar
unknown committed
2792 2793 2794 2795
	      (Item *) new Item_func_password($3);
	  }
	| OLD_PASSWORD '(' expr ')'
	  { $$=  new Item_func_old_password($3); }
unknown's avatar
unknown committed
2796 2797
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
2798
	| RAND '(' expr ')'
2799
	  { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
unknown's avatar
unknown committed
2800
	| RAND '(' ')'
2801
	  { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
unknown's avatar
unknown committed
2802 2803 2804 2805 2806 2807 2808
	| 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
2809 2810 2811 2812
	| 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
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824
	| 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
2825
	| TIME_SYM '(' expr ')'
unknown's avatar
unknown committed
2826 2827 2828
	  { $$= new Item_time_typecast($3); }
	| TIMESTAMP '(' expr ')'
	  { $$= new Item_datetime_typecast($3); }
unknown's avatar
unknown committed
2829
	| TIMESTAMP '(' expr ',' expr ')'
unknown's avatar
unknown committed
2830
	  { $$= new Item_func_add_time($3, $5, 1, 0); }
unknown's avatar
unknown committed
2831
	| TRIM '(' expr ')'
2832 2833
	  { $$= new Item_func_trim($3); }
	| TRIM '(' LEADING expr FROM expr ')'
unknown's avatar
unknown committed
2834
	  { $$= new Item_func_ltrim($6,$4); }
2835
	| TRIM '(' TRAILING expr FROM expr ')'
unknown's avatar
unknown committed
2836
	  { $$= new Item_func_rtrim($6,$4); }
2837
	| TRIM '(' BOTH expr FROM expr ')'
unknown's avatar
unknown committed
2838
	  { $$= new Item_func_trim($6,$4); }
2839 2840 2841 2842 2843 2844
	| 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
2845 2846
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
2847 2848
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
2849 2850
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893
	| 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 ')'
2894
	  {
unknown's avatar
unknown committed
2895 2896
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
2897
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
2898 2899
	  {
	    $$= new Item_func_unix_timestamp();
2900
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2901
	  }
unknown's avatar
unknown committed
2902 2903 2904
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
2905
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
2906 2907 2908 2909 2910 2911
	| 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
2912
	| WEEK_SYM '(' expr ')'
unknown's avatar
unknown committed
2913
	  {
2914
            $$= new Item_func_week($3,new Item_int((char*) "0",
unknown's avatar
unknown committed
2915
				   YYTHD->variables.default_week_format,1));
2916
          }
unknown's avatar
unknown committed
2917 2918 2919 2920 2921 2922 2923 2924 2925
	| 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 ')'
2926
	  {
unknown's avatar
unknown committed
2927
	    $$=new Item_func_benchmark($3,$5);
2928
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
2929
	  }
unknown's avatar
unknown committed
2930
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
2931
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
2932

unknown's avatar
unknown committed
2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992
geometry_function:
	GEOMFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| GEOMFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| GEOMFROMWKB '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_wkb($3)); }
	| GEOMFROMWKB '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_wkb($3, $5)); }
	| GEOMETRYCOLLECTION '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
                           Geometry::wkbGeometryCollection,
                           Geometry::wkbPoint)); }
	| LINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
                  Geometry::wkbLineString, Geometry::wkbPoint)); }
 	| MULTILINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW( Item_func_spatial_collection(* $3,
                   Geometry::wkbMultiLineString, Geometry::wkbLineString)); }
 	| MLINEFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| MLINEFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| MPOINTFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| MPOINTFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| MPOLYFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| MPOLYFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| MULTIPOINT '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
                  Geometry::wkbMultiPoint, Geometry::wkbPoint)); }
 	| MULTIPOLYGON '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
                  Geometry::wkbMultiPolygon, Geometry::wkbPolygon)); }
	| POINT_SYM '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_point($3,$5)); }
 	| POINTFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| POINTFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| POLYFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| POLYFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| POLYGON '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
	          Geometry::wkbPolygon, Geometry::wkbLineString)); }
 	| GEOMCOLLFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
 	| LINEFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| LINEFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	;

2993 2994 2995 2996 2997 2998
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
2999 3000
udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
3001
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
3002 3003 3004 3005 3006 3007 3008 3009

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); }
3010 3011
	| BIT_XOR  '(' in_sum_expr ')'
	  { $$=new Item_sum_xor($3); }
unknown's avatar
unknown committed
3012
	| COUNT_SYM '(' opt_all '*' ')'
unknown's avatar
unknown committed
3013 3014 3015
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
3016
	| COUNT_SYM '(' DISTINCT
unknown's avatar
unknown committed
3017
	  { Select->in_sum_expr++; }
3018
	   expr_list
unknown's avatar
unknown committed
3019
	  { Select->in_sum_expr--; }
3020 3021
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
unknown's avatar
unknown committed
3022 3023 3024 3025 3026 3027 3028 3029
	| 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
3030 3031
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
unknown's avatar
unknown committed
3032
	| SUM_SYM '(' in_sum_expr ')'
3033
	  { $$=new Item_sum_sum($3); }
unknown's avatar
unknown committed
3034 3035 3036 3037
	| GROUP_CONCAT_SYM '(' opt_distinct expr_list opt_gorder_clause
	  opt_gconcat_separator ')'
	  {
	    $$=new Item_func_group_concat($3,$4,Lex->gorder_list,$6);
3038 3039 3040 3041 3042 3043 3044 3045
	    $4->empty();
	  };

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

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

3049 3050

opt_gorder_clause:
3051 3052 3053 3054 3055 3056 3057 3058
	  /* empty */
	  {
            LEX *lex=Lex;
            lex->gorder_list = NULL;
	  }
	| order_clause
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
3059
            lex->gorder_list=
3060 3061 3062 3063
	      (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
3064

unknown's avatar
unknown committed
3065 3066

in_sum_expr:
unknown's avatar
unknown committed
3067
	opt_all
3068 3069 3070 3071
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
3072
	    yyerror(ER(ER_SYNTAX_ERROR));
3073
	    YYABORT;
3074 3075
	  }
	}
unknown's avatar
unknown committed
3076 3077
	expr
	{
unknown's avatar
unknown committed
3078
	  Select->in_sum_expr--;
3079
	  $$= $3;
unknown's avatar
unknown committed
3080
	};
unknown's avatar
unknown committed
3081

3082
cast_type:
unknown's avatar
unknown committed
3083
	BINARY			{ $$=ITEM_CAST_BINARY; Lex->charset= NULL; Lex->length= (char*)0; }
3084 3085
	| CHAR_SYM opt_len opt_binary	{ $$=ITEM_CAST_CHAR; }
	| NCHAR_SYM opt_len	{ $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; }
unknown's avatar
unknown committed
3086 3087 3088 3089 3090 3091 3092
	| SIGNED_SYM		{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| SIGNED_SYM INT_SYM	{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| UNSIGNED		{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| UNSIGNED INT_SYM	{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| DATE_SYM		{ $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->length= (char*)0; }
	| TIME_SYM		{ $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->length= (char*)0; }
	| DATETIME		{ $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->length= (char*)0; }
3093 3094
	;

unknown's avatar
unknown committed
3095
expr_list:
3096
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3097
	expr_list2
unknown's avatar
unknown committed
3098
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
3099 3100

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

unknown's avatar
unknown committed
3104 3105
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
3106
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
3107

unknown's avatar
unknown committed
3108
ident_list:
3109
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3110
        ident_list2
unknown's avatar
unknown committed
3111
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
3112 3113

ident_list2:
3114
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
3115
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
3116 3117 3118

opt_expr:
	/* empty */      { $$= NULL; }
3119
	| expr           { $$= $1; };
unknown's avatar
unknown committed
3120 3121 3122

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
3123
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
3124 3125

when_list:
unknown's avatar
unknown committed
3126
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3127
	when_list2
unknown's avatar
unknown committed
3128
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
3129 3130

when_list2:
unknown's avatar
unknown committed
3131
	expr THEN_SYM expr
unknown's avatar
unknown committed
3132
	  {
unknown's avatar
unknown committed
3133
	    SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
3134 3135
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
3136
	}
unknown's avatar
unknown committed
3137
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
3138
	  {
unknown's avatar
unknown committed
3139
	    SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
3140 3141
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
3142
	  };
unknown's avatar
unknown committed
3143 3144 3145 3146

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
unknown's avatar
unknown committed
3147
	| join_table_list ',' join_table_list { $$=$3; }
3148
	| join_table_list normal_join join_table_list { $$=$3; }
3149
	| join_table_list STRAIGHT_JOIN join_table_list
3150
	  { $$=$3 ; $1->next->straight=1; }
unknown's avatar
unknown committed
3151 3152 3153
	| 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
3154
	  USING
unknown's avatar
unknown committed
3155
	  {
unknown's avatar
unknown committed
3156
	    SELECT_LEX *sel= Select;
3157
	    sel->db1=$1->db; sel->table1=$1->alias;
unknown's avatar
unknown committed
3158
	    sel->db2=$3->db; sel->table2=$3->alias;
unknown's avatar
unknown committed
3159
	  }
unknown's avatar
unknown committed
3160 3161 3162
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

3163
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
3164
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
3165
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
3166
	  {
unknown's avatar
unknown committed
3167
	    SELECT_LEX *sel= Select;
3168 3169
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
3170
	  }
unknown's avatar
unknown committed
3171
	  USING '(' using_list ')'
3172
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
3173
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
3174 3175 3176 3177 3178
	  {
	    add_join_natural($1,$1->next);
	    $1->next->outer_join|=JOIN_TYPE_LEFT;
	    $$=$6;
	  }
3179
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
3180
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
3181
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
3182
	  {
unknown's avatar
unknown committed
3183
	    SELECT_LEX *sel= Select;
3184 3185
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
3186
	  }
3187
	  USING '(' using_list ')'
3188
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
3189
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
3190 3191 3192 3193 3194
	  {
	    add_join_natural($1->next,$1);
	    $1->outer_join|=JOIN_TYPE_RIGHT;
	    $$=$6;
	  }
3195
	| join_table_list NATURAL JOIN_SYM join_table_list
3196
	  { add_join_natural($1,$1->next); $$=$4; };
unknown's avatar
unknown committed
3197 3198

normal_join:
unknown's avatar
unknown committed
3199 3200 3201 3202
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
unknown's avatar
unknown committed
3203 3204

join_table:
unknown's avatar
unknown committed
3205
	{
unknown's avatar
unknown committed
3206
	  SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3207
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
unknown's avatar
unknown committed
3208
	  sel->table_join_options= 0;
unknown's avatar
unknown committed
3209
	}
unknown's avatar
unknown committed
3210
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
3211
	{
unknown's avatar
unknown committed
3212
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3213
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
3214
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
unknown's avatar
unknown committed
3215
					   sel->get_table_join_options(),
unknown's avatar
unknown committed
3216
					   lex->lock_option,
3217 3218
					   sel->get_use_index(),
					   sel->get_ignore_index())))
3219
	    YYABORT;
unknown's avatar
unknown committed
3220
	}
unknown's avatar
unknown committed
3221
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
3222
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
3223
        | '(' SELECT_SYM select_derived ')' opt_table_alias
unknown's avatar
unknown committed
3224 3225
	{
	  LEX *lex=Lex;
3226 3227 3228
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
unknown's avatar
unknown committed
3229
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
3230
				  TL_READ,(List<String> *)0,
unknown's avatar
unknown committed
3231 3232
	                          (List<String> *)0)))

unknown's avatar
unknown committed
3233
	    YYABORT;
unknown's avatar
unknown committed
3234
	};
unknown's avatar
unknown committed
3235

3236
select_derived:
unknown's avatar
unknown committed
3237
        {
unknown's avatar
unknown committed
3238
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3239
	  lex->derived_tables= 1;
unknown's avatar
unknown committed
3240 3241 3242
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
3243 3244
	  {
	    yyerror(ER(ER_SYNTAX_ERROR));
3245 3246
	    YYABORT;
	  }
3247
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
unknown's avatar
unknown committed
3248
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
3249 3250
	    YYABORT;
	  mysql_init_select(lex);
3251
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
unknown's avatar
unknown committed
3252
	}
3253
        select_options select_item_list opt_select_from union_opt
3254
        ;
unknown's avatar
unknown committed
3255 3256 3257

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
3258
	| OUTER		{};
unknown's avatar
unknown committed
3259 3260 3261 3262

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
3263
          {
unknown's avatar
unknown committed
3264
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3265 3266 3267
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
3268 3269
	| FORCE_SYM key_usage_list
          {
unknown's avatar
unknown committed
3270
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3271 3272 3273 3274
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
unknown's avatar
unknown committed
3275
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
3276
	  {
unknown's avatar
unknown committed
3277
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3278 3279
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
3280
	  };
unknown's avatar
unknown committed
3281 3282

key_usage_list:
unknown's avatar
unknown committed
3283
	key_or_index { Select->interval_list.empty(); }
unknown's avatar
unknown committed
3284
        '(' key_list_or_empty ')'
unknown's avatar
unknown committed
3285
        { $$= &Select->interval_list; }
unknown's avatar
unknown committed
3286 3287 3288 3289 3290 3291
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
unknown's avatar
unknown committed
3292 3293 3294

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
3295
        { Select->
3296
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
3297
				    system_charset_info)); }
unknown's avatar
unknown committed
3298
	| ident
unknown's avatar
unknown committed
3299
        { Select->
3300
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
3301
				    system_charset_info)); }
unknown's avatar
unknown committed
3302
	| PRIMARY_SYM
unknown's avatar
unknown committed
3303
        { Select->
3304
	    interval_list.push_back(new String("PRIMARY", 7,
3305
				    system_charset_info)); };
unknown's avatar
unknown committed
3306 3307 3308

using_list:
	ident
unknown's avatar
unknown committed
3309
	  {
unknown's avatar
unknown committed
3310
	    SELECT_LEX *sel= Select;
3311 3312 3313 3314
	    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
3315 3316 3317 3318
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
3319
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3320
	    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
3321
	      YYABORT;
unknown's avatar
unknown committed
3322
	  };
unknown's avatar
unknown committed
3323 3324 3325

interval:
	 DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
unknown's avatar
unknown committed
3326
	| DAY_MICROSECOND_SYM	{ $$=INTERVAL_DAY_MICROSECOND; }
unknown's avatar
unknown committed
3327 3328 3329
	| DAY_MINUTE_SYM	{ $$=INTERVAL_DAY_MINUTE; }
	| DAY_SECOND_SYM	{ $$=INTERVAL_DAY_SECOND; }
	| DAY_SYM		{ $$=INTERVAL_DAY; }
unknown's avatar
unknown committed
3330
	| HOUR_MICROSECOND_SYM	{ $$=INTERVAL_HOUR_MICROSECOND; }
unknown's avatar
unknown committed
3331 3332 3333
	| HOUR_MINUTE_SYM	{ $$=INTERVAL_HOUR_MINUTE; }
	| HOUR_SECOND_SYM	{ $$=INTERVAL_HOUR_SECOND; }
	| HOUR_SYM		{ $$=INTERVAL_HOUR; }
unknown's avatar
unknown committed
3334 3335
	| MICROSECOND_SYM	{ $$=INTERVAL_MICROSECOND; }
	| MINUTE_MICROSECOND_SYM	{ $$=INTERVAL_MINUTE_MICROSECOND; }
unknown's avatar
unknown committed
3336 3337 3338
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
unknown's avatar
unknown committed
3339
	| SECOND_MICROSECOND_SYM	{ $$=INTERVAL_SECOND_MICROSECOND; }
unknown's avatar
unknown committed
3340 3341
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
	| YEAR_MONTH_SYM	{ $$=INTERVAL_YEAR_MONTH; }
unknown's avatar
unknown committed
3342
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
unknown's avatar
unknown committed
3343

3344 3345 3346 3347
date_time_type:
	DATE_SYM		{$$=TIMESTAMP_DATE;}
	| TIME_SYM		{$$=TIMESTAMP_TIME;}
	| DATETIME		{$$=TIMESTAMP_DATETIME;};
3348

unknown's avatar
unknown committed
3349 3350 3351
table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
3352
	| EQ;
unknown's avatar
unknown committed
3353 3354 3355 3356

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

unknown's avatar
unknown committed
3359 3360 3361 3362
opt_all:
	/* empty */
	| ALL
	;
unknown's avatar
unknown committed
3363 3364

where_clause:
unknown's avatar
unknown committed
3365
	/* empty */  { Select->where= 0; }
3366 3367
	| WHERE expr
	  {
unknown's avatar
unknown committed
3368
	    Select->where= $2;
3369 3370 3371
	    if ($2)
	      $2->top_level_item();
	  }
unknown's avatar
unknown committed
3372
 	;
unknown's avatar
unknown committed
3373 3374 3375

having_clause:
	/* empty */
unknown's avatar
unknown committed
3376 3377
	| HAVING
	  {
unknown's avatar
unknown committed
3378
	    Select->parsing_place= SELECT_LEX_NODE::IN_HAVING;
unknown's avatar
unknown committed
3379 3380
          }
	  expr
unknown's avatar
unknown committed
3381
	  {
unknown's avatar
unknown committed
3382
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3383 3384
	    sel->having= $3;
	    sel->parsing_place= SELECT_LEX_NODE::NO_MATTER;
unknown's avatar
unknown committed
3385 3386 3387
	    if ($3)
	      $3->top_level_item();
	  }
3388
	;
unknown's avatar
unknown committed
3389 3390

opt_escape:
3391
	ESCAPE_SYM TEXT_STRING_literal	{ $$= $2.str; }
unknown's avatar
unknown committed
3392
	| /* empty */			{ $$= (char*) "\\"; };
unknown's avatar
unknown committed
3393 3394 3395


/*
unknown's avatar
unknown committed
3396
   group by statement in select
unknown's avatar
unknown committed
3397 3398 3399 3400
*/

group_clause:
	/* empty */
3401
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
3402 3403

group_list:
unknown's avatar
unknown committed
3404
	group_list ',' order_ident order_dir
unknown's avatar
unknown committed
3405
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3406
	| order_ident order_dir
unknown's avatar
unknown committed
3407
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3408

3409 3410
olap_opt:
	/* empty */ {}
3411
	| WITH CUBE_SYM
3412
          {
3413
	    LEX *lex=Lex;
3414 3415 3416 3417 3418 3419
	    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
3420
	    lex->current_select->olap= CUBE_TYPE;
3421
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
3422
	    YYABORT;	/* To be deleted in 5.1 */
3423
	  }
3424
	| WITH ROLLUP_SYM
3425
          {
3426 3427 3428 3429 3430 3431 3432
	    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
3433
	    lex->current_select->olap= ROLLUP_TYPE;
3434
	  }
3435
	;
3436

unknown's avatar
unknown committed
3437
/*
unknown's avatar
unknown committed
3438
   Order by statement in select
unknown's avatar
unknown committed
3439 3440
*/

3441
opt_order_clause:
unknown's avatar
unknown committed
3442
	/* empty */
unknown's avatar
unknown committed
3443
	| order_clause;
3444 3445

order_clause:
3446 3447
	ORDER_SYM BY
        {
unknown's avatar
unknown committed
3448
	  LEX *lex=Lex;
3449
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
3450
	      lex->current_select->olap !=
3451
	      UNSPECIFIED_OLAP_TYPE)
3452
	  {
3453
	    net_printf(lex->thd, ER_WRONG_USAGE,
3454 3455 3456 3457
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
3458
	} order_list;
unknown's avatar
unknown committed
3459 3460 3461

order_list:
	order_list ',' order_ident order_dir
unknown's avatar
unknown committed
3462
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3463
	| order_ident order_dir
unknown's avatar
unknown committed
3464
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3465 3466 3467

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
3468
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
3469
	| DESC { $$ =0; };
unknown's avatar
unknown committed
3470 3471


3472 3473 3474
opt_limit_clause_init:
	/* empty */
	{
3475 3476
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
3477
          sel->offset_limit= 0L;
3478 3479 3480
          sel->select_limit= (&lex->select_lex == sel) ?
	    Lex->thd->variables.select_limit :	/* primary SELECT */
	    HA_POS_ERROR;			/* subquery */
3481
	}
3482 3483 3484
	| limit_clause {}
	;

3485 3486 3487 3488 3489
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

3490
limit_clause:
3491
	LIMIT limit_options {}
unknown's avatar
unknown committed
3492
	;
unknown's avatar
unknown committed
3493 3494 3495

limit_options:
	ULONG_NUM
unknown's avatar
unknown committed
3496
	  {
unknown's avatar
unknown committed
3497
            SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3498 3499 3500 3501 3502
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
unknown's avatar
unknown committed
3503
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3504 3505
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
unknown's avatar
unknown committed
3506
	  }
unknown's avatar
unknown committed
3507
	| ULONG_NUM OFFSET_SYM ULONG_NUM
unknown's avatar
unknown committed
3508
	  {
unknown's avatar
unknown committed
3509
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3510 3511 3512 3513
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
unknown's avatar
unknown committed
3514 3515 3516 3517 3518


delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
3519
	  LEX *lex=Lex;
3520
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
3521
	}
unknown's avatar
unknown committed
3522
	| LIMIT ulonglong_num
unknown's avatar
unknown committed
3523
	{ Select->select_limit= (ha_rows) $2; };
unknown's avatar
unknown committed
3524 3525

ULONG_NUM:
unknown's avatar
unknown committed
3526
	NUM	    { $$= strtoul($1.str,NULL,10); }
3527
	| LONG_NUM  { $$= (ulong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3528
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3529
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3530
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
unknown's avatar
unknown committed
3531

unknown's avatar
unknown committed
3532
ulonglong_num:
unknown's avatar
unknown committed
3533
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3534
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
3535
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3536
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3537
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
unknown's avatar
unknown committed
3538 3539 3540 3541 3542 3543

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
3544 3545 3546 3547 3548 3549 3550
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3551 3552 3553
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
unknown's avatar
unknown committed
3554
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
unknown's avatar
unknown committed
3555
	      YYABORT;
3556
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3557
	  }
unknown's avatar
unknown committed
3558
	  '(' procedure_list ')';
unknown's avatar
unknown committed
3559 3560 3561 3562


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
3563
	| procedure_list2 {};
unknown's avatar
unknown committed
3564 3565 3566

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
3567
	| procedure_item;
unknown's avatar
unknown committed
3568 3569 3570 3571

procedure_item:
	  remember_name expr
	  {
unknown's avatar
unknown committed
3572 3573
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
unknown's avatar
unknown committed
3574 3575
	      YYABORT;
	    if (!$2->name)
unknown's avatar
unknown committed
3576
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
3577 3578 3579 3580 3581 3582
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
3583 3584
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3585 3586
	        YYABORT;
	   }
3587
	   select_var_list
3588
	   {}
3589
           ;
unknown's avatar
unknown committed
3590

unknown's avatar
unknown committed
3591
select_var_list:
3592 3593 3594 3595 3596
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
3597
           {
3598
             LEX *lex=Lex;
unknown's avatar
unknown committed
3599
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
3600 3601
	       YYABORT;
	   }
unknown's avatar
unknown committed
3602
           ;
unknown's avatar
unknown committed
3603

3604
into:
unknown's avatar
unknown committed
3605
        INTO OUTFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3606
	{
3607
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3608 3609
	  if (!lex->describe)
	  {
3610
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3611 3612 3613 3614 3615
	    if (!(lex->exchange= new sql_exchange($3.str,0)))
	      YYABORT;
	    if (!(lex->result= new select_export(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3616 3617
	}
	opt_field_term opt_line_term
unknown's avatar
unknown committed
3618
	| INTO DUMPFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3619
	{
3620
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3621 3622
	  if (!lex->describe)
	  {
3623
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3624 3625 3626 3627 3628
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3629
	}
3630
        | INTO select_var_list_init
unknown's avatar
unknown committed
3631
	{
3632
	  Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
3633 3634
	}
        ;
unknown's avatar
unknown committed
3635

unknown's avatar
unknown committed
3636 3637 3638
/*
  DO statement
*/
unknown's avatar
unknown committed
3639

3640
do:	DO_SYM
unknown's avatar
unknown committed
3641 3642 3643 3644 3645 3646
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
3647 3648 3649 3650
	values
	{}
	;

unknown's avatar
unknown committed
3651
/*
3652
  Drop : delete tables or index or user
unknown's avatar
unknown committed
3653 3654 3655
*/

drop:
unknown's avatar
unknown committed
3656
	DROP opt_temporary table_or_tables if_exists table_list opt_restrict
unknown's avatar
unknown committed
3657
	{
unknown's avatar
unknown committed
3658 3659
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3660 3661
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
unknown's avatar
unknown committed
3662 3663 3664
	}
	| DROP INDEX ident ON table_ident {}
	  {
unknown's avatar
unknown committed
3665 3666 3667 3668
	     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
3669
						     $3.str));
unknown's avatar
unknown committed
3670 3671
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3672 3673 3674 3675
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
3676 3677 3678 3679
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
3680
	 }
unknown's avatar
unknown committed
3681
	| DROP UDF_SYM IDENT_sys
unknown's avatar
unknown committed
3682
	  {
unknown's avatar
unknown committed
3683 3684
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3685
	    lex->udf.name = $3;
3686 3687 3688 3689 3690 3691
	  }
	| DROP USER
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_USER;
	    lex->users_list.empty();
unknown's avatar
unknown committed
3692
	  }
3693 3694 3695
	  user_list
	  {}
	  ;
unknown's avatar
unknown committed
3696 3697 3698


table_list:
3699
	table_name
unknown's avatar
unknown committed
3700
	| table_list ',' table_name;
unknown's avatar
unknown committed
3701

3702
table_name:
unknown's avatar
unknown committed
3703
	table_ident
unknown's avatar
unknown committed
3704 3705 3706 3707 3708
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
unknown's avatar
unknown committed
3709 3710

if_exists:
3711
	/* empty */ { $$= 0; }
3712 3713
	| IF EXISTS { $$= 1; }
	;
unknown's avatar
unknown committed
3714

3715 3716 3717 3718
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
unknown's avatar
unknown committed
3719 3720 3721 3722 3723
/*
** Insert : add new data to table
*/

insert:
3724 3725 3726 3727 3728 3729
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3730
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
3731
	} insert_lock_option
3732
	opt_ignore insert2
unknown's avatar
unknown committed
3733
	{
unknown's avatar
unknown committed
3734
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3735
	  Lex->current_select= &Lex->select_lex;
unknown's avatar
unknown committed
3736
	}
3737
	insert_field_spec opt_insert_update
3738
	{}
unknown's avatar
unknown committed
3739
	;
unknown's avatar
unknown committed
3740 3741

replace:
3742 3743
	REPLACE
	{
3744
	  LEX *lex=Lex;
3745 3746
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
3747
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
3748
	}
unknown's avatar
unknown committed
3749 3750
	replace_lock_option insert2
	{
unknown's avatar
unknown committed
3751
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3752
	  Lex->current_select= &Lex->select_lex;
unknown's avatar
unknown committed
3753 3754
	}
	insert_field_spec
3755
	{}
unknown's avatar
unknown committed
3756
	{}
unknown's avatar
unknown committed
3757
	;
unknown's avatar
unknown committed
3758 3759

insert_lock_option:
unknown's avatar
unknown committed
3760 3761 3762 3763
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3764
	;
unknown's avatar
unknown committed
3765 3766

replace_lock_option:
unknown's avatar
unknown committed
3767 3768
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
3769 3770 3771

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
3772
	| insert_table {};
unknown's avatar
unknown committed
3773 3774

insert_table:
3775
	table_name
unknown's avatar
unknown committed
3776
	{
unknown's avatar
unknown committed
3777 3778 3779 3780
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
3781
	};
unknown's avatar
unknown committed
3782 3783

insert_field_spec:
unknown's avatar
unknown committed
3784 3785 3786
	insert_values {}
	| '(' ')' insert_values {}
	| '(' fields ')' insert_values {}
unknown's avatar
unknown committed
3787 3788
	| SET
	  {
unknown's avatar
unknown committed
3789 3790 3791
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3792 3793
	      YYABORT;
	   }
unknown's avatar
unknown committed
3794
	   ident_eq_list;
unknown's avatar
unknown committed
3795 3796 3797 3798

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
3799
	| '(' ')'	  { };
unknown's avatar
unknown committed
3800 3801 3802

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
3803
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
3804 3805 3806

insert_values:
	VALUES	values_list  {}
unknown's avatar
unknown committed
3807
	| VALUE_SYM values_list  {}
unknown's avatar
unknown committed
3808 3809
	|     create_select     { Select->set_braces(0);} union_clause {}
	| '(' create_select ')' { Select->set_braces(1);} union_opt {}
3810
        ;
unknown's avatar
unknown committed
3811 3812 3813

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
3814
	| no_braces;
unknown's avatar
unknown committed
3815 3816 3817 3818

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
3819
	ident_eq_value;
unknown's avatar
unknown committed
3820 3821

ident_eq_value:
unknown's avatar
unknown committed
3822
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
3823
	 {
unknown's avatar
unknown committed
3824 3825 3826
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
3827
	    YYABORT;
unknown's avatar
unknown committed
3828
	 };
unknown's avatar
unknown committed
3829 3830

equal:	EQ		{}
unknown's avatar
unknown committed
3831 3832 3833 3834 3835 3836 3837
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
3838 3839 3840 3841 3842 3843 3844 3845 3846

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
3847 3848
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3849
	    YYABORT;
unknown's avatar
unknown committed
3850
	 };
unknown's avatar
unknown committed
3851 3852 3853

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
3854
	| values;
unknown's avatar
unknown committed
3855 3856

values:
unknown's avatar
unknown committed
3857
	values ','  expr_or_default
unknown's avatar
unknown committed
3858 3859 3860 3861
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
3862 3863 3864 3865 3866 3867 3868 3869
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3870
	expr	  { $$= $1;}
unknown's avatar
SCRUM  
unknown committed
3871
	| DEFAULT {$$= new Item_default_value(); }
unknown's avatar
unknown committed
3872
	;
unknown's avatar
unknown committed
3873

3874 3875
opt_insert_update:
        /* empty */
unknown's avatar
unknown committed
3876
        | ON DUPLICATE_SYM
3877 3878 3879 3880 3881
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
3882
	      yyerror(ER(ER_SYNTAX_ERROR));
3883 3884 3885
              YYABORT;
            }
          }
3886
          KEY_SYM UPDATE_SYM update_list
3887 3888
        ;

unknown's avatar
unknown committed
3889 3890 3891
/* Update rows in a table */

update:
3892 3893
	UPDATE_SYM
	{
3894
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3895
	  mysql_init_select(lex);
3896
          lex->sql_command= SQLCOM_UPDATE;
unknown's avatar
unknown committed
3897
	  lex->lock_option= TL_UNLOCK; 	/* Will be set later */
3898
        }
unknown's avatar
unknown committed
3899 3900 3901
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3902
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3903
	  Select->set_lock_for_tables($3);
3904
          if (lex->select_lex.table_list.elements > 1)
unknown's avatar
unknown committed
3905
            lex->sql_command= SQLCOM_UPDATE_MULTI;
3906 3907 3908 3909 3910 3911 3912
	  else if (lex->select_lex.get_table_list()->derived)
	  {
	    /* it is single table update and it is update of derived table */
	    net_printf(lex->thd, ER_NON_UPDATABLE_TABLE,
		       lex->select_lex.get_table_list()->alias, "UPDATE");
	    YYABORT;
	  }
unknown's avatar
unknown committed
3913 3914
	}
	;
unknown's avatar
unknown committed
3915 3916

update_list:
unknown's avatar
SCRUM  
unknown committed
3917
	update_list ',' simple_ident equal expr_or_default
unknown's avatar
unknown committed
3918
	{
unknown's avatar
unknown committed
3919
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
unknown's avatar
unknown committed
3920 3921
	    YYABORT;
	}
unknown's avatar
SCRUM  
unknown committed
3922
	| simple_ident equal expr_or_default
unknown's avatar
unknown committed
3923
	  {
unknown's avatar
unknown committed
3924
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
unknown's avatar
unknown committed
3925
	      YYABORT;
unknown's avatar
unknown committed
3926
	  };
unknown's avatar
unknown committed
3927 3928

opt_low_priority:
3929
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3930
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3931 3932 3933 3934

/* Delete rows from a table */

delete:
3935
	DELETE_SYM
3936
	{
3937 3938
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
unknown's avatar
unknown committed
3939
	  lex->lock_option= lex->thd->update_lock_default;
3940
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3941
	}
unknown's avatar
unknown committed
3942 3943
	opt_delete_options single_multi {}
	;
3944 3945

single_multi:
unknown's avatar
unknown committed
3946 3947
 	FROM table_ident
	{
unknown's avatar
unknown committed
3948 3949
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
unknown's avatar
unknown committed
3950 3951 3952
	    YYABORT;
	}
	where_clause opt_order_clause
3953
	delete_limit_clause {}
unknown's avatar
unknown committed
3954
	| table_wild_list
unknown's avatar
unknown committed
3955
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
3956
          FROM join_table_list where_clause
unknown's avatar
unknown committed
3957 3958
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3959 3960 3961
	  USING join_table_list where_clause
	  {}
	;
unknown's avatar
unknown committed
3962 3963 3964

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
3965
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
3966 3967

table_wild_one:
unknown's avatar
unknown committed
3968
	ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3969
	{
unknown's avatar
unknown committed
3970 3971
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
unknown's avatar
unknown committed
3972 3973
	    YYABORT;
        }
unknown's avatar
unknown committed
3974
	| ident '.' ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3975
	  {
unknown's avatar
unknown committed
3976 3977
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
unknown's avatar
unknown committed
3978 3979
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
unknown's avatar
unknown committed
3980
	      YYABORT;
unknown's avatar
unknown committed
3981
	  }
unknown's avatar
unknown committed
3982
	;
unknown's avatar
unknown committed
3983 3984

opt_wild:
3985
	/* empty */	{}
unknown's avatar
unknown committed
3986
	| '.' '*'	{};
unknown's avatar
unknown committed
3987 3988


3989
opt_delete_options:
unknown's avatar
unknown committed
3990
	/* empty */	{}
unknown's avatar
unknown committed
3991
	| opt_delete_option opt_delete_options {};
3992 3993

opt_delete_option:
3994
	QUICK		{ Select->options|= OPTION_QUICK; }
3995 3996
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
	| IGNORE_SYM	{ Lex->duplicates= DUP_IGNORE; };
3997

3998
truncate:
unknown's avatar
unknown committed
3999
	TRUNCATE_SYM opt_table_sym table_name
4000
	{
4001
	  LEX* lex= Lex;
4002
	  lex->sql_command= SQLCOM_TRUNCATE;
4003
	  lex->select_lex.options= 0;
4004
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
4005 4006
	}
	;
4007

unknown's avatar
unknown committed
4008 4009
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
4010
	| TABLE_SYM;
4011

unknown's avatar
unknown committed
4012 4013
/* Show things */

4014 4015
show:	SHOW
	{
unknown's avatar
unknown committed
4016 4017 4018 4019
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
unknown's avatar
unknown committed
4020
	show_param
4021 4022
	{}
	;
unknown's avatar
unknown committed
4023 4024 4025 4026 4027

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
4028
	  {
4029
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4030
	    lex->sql_command= SQLCOM_SHOW_TABLES;
4031 4032
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
unknown's avatar
unknown committed
4033
	   }
unknown's avatar
unknown committed
4034
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
4035
	  {
4036
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4037
	    lex->sql_command= SQLCOM_SHOW_TABLES;
4038 4039
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
4040
	  }
4041
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
4042
	  {
4043
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4044
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
4045 4046
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
4047
	  }
unknown's avatar
unknown committed
4048
	| ENGINE_SYM storage_engines 
unknown's avatar
unknown committed
4049 4050
	  { Lex->create_info.db_type= $2; }
	  show_engine_param
unknown's avatar
unknown committed
4051
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
4052 4053
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
4054 4055
	    if ($5)
	      $4->change_db($5);
unknown's avatar
unknown committed
4056
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
unknown's avatar
unknown committed
4057 4058
	      YYABORT;
	  }
4059
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
unknown's avatar
unknown committed
4060
	  TEXT_STRING_sys AND MASTER_LOG_POS_SYM EQ ulonglong_num
4061
	  AND MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
4062 4063 4064 4065 4066
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
4067
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
4068
          }
4069
        | master_or_binary LOGS_SYM
unknown's avatar
unknown committed
4070 4071
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
4072 4073 4074 4075 4076
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
4077
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
4078
          {
4079 4080
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
4081
          } opt_limit_clause_init
unknown's avatar
unknown committed
4082 4083 4084 4085 4086
	| 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
4087
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
unknown's avatar
unknown committed
4088 4089
	      YYABORT;
	  }
unknown's avatar
unknown committed
4090 4091 4092 4093 4094 4095 4096 4097
	| COLUMN_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
	  }
	| TABLE_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4098 4099 4100 4101 4102 4103 4104
	    lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
	    WARN_DEPRECATED("SHOW TABLE TYPES", "SHOW [STORAGE] ENGINES");
	  }
	| opt_storage ENGINES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
unknown's avatar
unknown committed
4105 4106 4107 4108 4109 4110
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
4111
        | COUNT_SYM '(' '*' ')' WARNINGS
4112
          { (void) create_select_for_variable("warning_count"); }
4113
        | COUNT_SYM '(' '*' ')' ERRORS
4114
	  { (void) create_select_for_variable("error_count"); }
4115
        | WARNINGS opt_limit_clause_init
unknown's avatar
unknown committed
4116
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4117
        | ERRORS opt_limit_clause_init
4118
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
unknown's avatar
unknown committed
4119 4120
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
4121
        | INNOBASE_SYM STATUS_SYM
unknown's avatar
unknown committed
4122
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS; WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); }
unknown's avatar
unknown committed
4123 4124
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
4125
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
4126
	  {
4127
	    THD *thd= YYTHD;
4128 4129
	    thd->lex->sql_command= SQLCOM_SHOW_VARIABLES;
	    thd->lex->option_type= (enum_var_type) $1;
4130
	  }
4131
	| charset wild
4132
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
4133 4134
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
4135
	| BERKELEY_DB_SYM LOGS_SYM
unknown's avatar
unknown committed
4136
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); }
unknown's avatar
unknown committed
4137
	| LOGS_SYM
unknown's avatar
unknown committed
4138
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); }
unknown's avatar
unknown committed
4139
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
4140 4141 4142 4143 4144 4145
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
4146
	| CREATE DATABASE opt_if_not_exists ident
unknown's avatar
unknown committed
4147 4148
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
4149 4150
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
4151
	  }
unknown's avatar
unknown committed
4152 4153 4154
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
unknown's avatar
unknown committed
4155
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
unknown's avatar
unknown committed
4156 4157 4158 4159 4160
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
4161
          }
unknown's avatar
unknown committed
4162 4163 4164
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
4165
          };
unknown's avatar
unknown committed
4166

unknown's avatar
unknown committed
4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190
show_engine_param:
	STATUS_SYM
	  {
	    switch (Lex->create_info.db_type) {
	    case DB_TYPE_INNODB:
	      Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
	      break;
	    default:
	      net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "STATUS");
	      YYABORT;
	    }
	  }
	| LOGS_SYM
	  {
	    switch (Lex->create_info.db_type) {
	    case DB_TYPE_BERKELEY_DB:
	      Lex->sql_command = SQLCOM_SHOW_LOGS;
	      break;
	    default:
	      net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "LOGS");
	      YYABORT;
	    }
	  };

4191 4192 4193 4194
master_or_binary:
	MASTER_SYM
	| BINARY;

unknown's avatar
unknown committed
4195 4196 4197 4198
opt_storage:
	/* empty */
	| STORAGE_SYM;

unknown's avatar
unknown committed
4199 4200
opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
4201
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
4202 4203 4204

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

unknown's avatar
unknown committed
4207 4208
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
4209
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
4210

unknown's avatar
unknown committed
4211 4212
from_or_in:
	FROM
unknown's avatar
unknown committed
4213
	| IN_SYM;
unknown's avatar
unknown committed
4214

unknown's avatar
unknown committed
4215 4216
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
4217
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
4218 4219 4220

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


unknown's avatar
unknown committed
4224 4225 4226 4227
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
4228 4229 4230 4231
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
4232
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
unknown's avatar
unknown committed
4233 4234
	    YYABORT;
	}
4235
	opt_describe_column {}
unknown's avatar
unknown committed
4236 4237 4238
	| describe_command opt_extended_describe
	  { Lex->describe|= DESCRIBE_NORMAL; }
	  select
4239
          {
unknown's avatar
unknown committed
4240
	    LEX *lex=Lex;
4241
	    lex->select_lex.options|= SELECT_DESCRIBE;
unknown's avatar
unknown committed
4242 4243
	  }
	;
unknown's avatar
unknown committed
4244 4245 4246

describe_command:
	DESC
unknown's avatar
unknown committed
4247
	| DESCRIBE;
unknown's avatar
unknown committed
4248

unknown's avatar
unknown committed
4249 4250 4251 4252 4253
opt_extended_describe:
	/* empty */ {}
	| EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; }
	;

unknown's avatar
unknown committed
4254 4255 4256
opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
4257
	| ident
4258
	  { Lex->wild= new String((const char*) $1.str,$1.length,system_charset_info); };
unknown's avatar
unknown committed
4259 4260 4261 4262 4263


/* flush things */

flush:
4264
	FLUSH_SYM opt_no_write_to_binlog
unknown's avatar
unknown committed
4265 4266 4267
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
unknown's avatar
unknown committed
4268
          lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
4269
	}
4270 4271 4272
	flush_options
	{}
	;
unknown's avatar
unknown committed
4273 4274 4275

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
4276
	| flush_option;
unknown's avatar
unknown committed
4277 4278

flush_option:
4279
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
unknown's avatar
unknown committed
4280
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
4281
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
4282 4283 4284 4285
	| 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
4286 4287
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
4288 4289
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
4290

unknown's avatar
unknown committed
4291
opt_table_list:
4292 4293
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
4294

unknown's avatar
unknown committed
4295
reset:
unknown's avatar
unknown committed
4296 4297 4298 4299
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
4300 4301 4302 4303
	} reset_options
	{}
	;

unknown's avatar
unknown committed
4304 4305
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
4306
	| reset_option;
unknown's avatar
unknown committed
4307 4308

reset_option:
unknown's avatar
unknown committed
4309 4310
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
4311
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
4312

unknown's avatar
unknown committed
4313
purge:
unknown's avatar
unknown committed
4314 4315 4316 4317
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
4318 4319 4320 4321 4322
	} purge_options
	{}
	;

purge_options:
4323
	master_or_binary LOGS_SYM purge_option
unknown's avatar
unknown committed
4324
	;
4325 4326

purge_option:
unknown's avatar
unknown committed
4327
        TO_SYM TEXT_STRING_sys
4328 4329 4330 4331 4332 4333 4334 4335 4336
        {
	   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
4337
	    YYABORT;
4338 4339 4340
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
4341
	  Lex->purge_time= (ulong) tmp->val_int();
unknown's avatar
unknown committed
4342
	}
unknown's avatar
unknown committed
4343
	;
unknown's avatar
unknown committed
4344

unknown's avatar
unknown committed
4345 4346 4347
/* kill threads */

kill:
4348
	KILL_SYM expr
unknown's avatar
unknown committed
4349
	{
unknown's avatar
unknown committed
4350
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4351
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
4352
	  {
4353
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
4354 4355 4356 4357
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
4358
	};
unknown's avatar
unknown committed
4359 4360 4361 4362

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
4363 4364
	{
	  LEX *lex=Lex;
4365 4366
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
4367
	};
unknown's avatar
unknown committed
4368 4369 4370

/* import, export of files */

unknown's avatar
unknown committed
4371
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
unknown's avatar
unknown committed
4372
	{
unknown's avatar
unknown committed
4373 4374
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
unknown's avatar
unknown committed
4375 4376
	  lex->lock_option= $3;
	  lex->local_file=  $4;
unknown's avatar
unknown committed
4377
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
4378
	    YYABORT;
unknown's avatar
unknown committed
4379
	  lex->field_list.empty();
unknown's avatar
unknown committed
4380 4381 4382 4383
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
unknown's avatar
unknown committed
4384
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
4385 4386 4387
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
4388
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
4389 4390
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
unknown's avatar
unknown committed
4391
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
4392
	    YYABORT;
unknown's avatar
unknown committed
4393 4394

        }
4395 4396 4397 4398
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
4399
        };
unknown's avatar
unknown committed
4400 4401 4402

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

unknown's avatar
unknown committed
4405
load_data_lock:
4406
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4407 4408
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
4409 4410


unknown's avatar
unknown committed
4411 4412 4413
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
unknown's avatar
unknown committed
4414
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
4415 4416 4417

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
4418
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
4419 4420 4421

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
4422
	| field_term;
unknown's avatar
unknown committed
4423 4424 4425 4426

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
4427 4428 4429 4430 4431
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
unknown's avatar
unknown committed
4432
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
unknown's avatar
unknown committed
4433
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
unknown's avatar
unknown committed
4434 4435 4436

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
4437
	| LINES line_term_list;
unknown's avatar
unknown committed
4438 4439 4440

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
4441
	| line_term;
unknown's avatar
unknown committed
4442 4443 4444

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
unknown's avatar
unknown committed
4445
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
unknown's avatar
unknown committed
4446 4447 4448 4449

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
unknown's avatar
unknown committed
4450
	  { Lex->exchange->skip_lines=atol($2.str); };
unknown's avatar
unknown committed
4451 4452 4453 4454

/* Common definitions */

text_literal:
4455
	TEXT_STRING_literal
unknown's avatar
unknown committed
4456 4457
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4458
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
unknown's avatar
unknown committed
4459
	}
unknown's avatar
unknown committed
4460
	| NCHAR_STRING
4461
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
4462
	| UNDERSCORE_CHARSET TEXT_STRING
4463
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
4464
	| text_literal TEXT_STRING_literal
unknown's avatar
unknown committed
4465 4466
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
unknown's avatar
unknown committed
4467 4468

text_string:
4469
	TEXT_STRING_literal
unknown's avatar
unknown committed
4470
	{ $$=  new String($1.str,$1.length,YYTHD->variables.collation_connection); }
unknown's avatar
unknown committed
4471 4472
	| HEX_NUM
	  {
4473
	    Item *tmp = new Item_varbinary($1.str,$1.length);
unknown's avatar
unknown committed
4474
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
4475 4476 4477
	  }
	;

unknown's avatar
unknown committed
4478
param_marker:
4479
        '?'
unknown's avatar
unknown committed
4480
        {
4481 4482 4483
          THD *thd=YYTHD;
	  LEX *lex= thd->lex;
          if (thd->command == COM_PREPARE)
4484
          {
4485 4486 4487 4488 4489 4490 4491
            Item_param *item= new Item_param((uint) (lex->tok_start -
                                                     (uchar *) thd->query));
            if (!($$= item) || lex->param_list.push_back(item))
            {
	      send_error(thd, ER_OUT_OF_RESOURCES);
	      YYABORT;
            }
unknown's avatar
unknown committed
4492
          }
4493
          else
unknown's avatar
unknown committed
4494
          {
4495
            yyerror(ER(ER_SYNTAX_ERROR));
unknown's avatar
unknown committed
4496 4497
            YYABORT;
          }
4498 4499 4500
        }
	;

unknown's avatar
unknown committed
4501 4502 4503 4504 4505 4506 4507
signed_literal:
	literal		{ $$ = $1; }
	| '+' NUM_literal { $$ = $2; }
	| '-' NUM_literal { $$ = new Item_func_neg($2); }
	;


unknown's avatar
unknown committed
4508 4509
literal:
	text_literal	{ $$ =	$1; }
unknown's avatar
unknown committed
4510
	| NUM_literal	{ $$ = $1; }
unknown's avatar
unknown committed
4511
	| NULL_SYM	{ $$ =	new Item_null();
4512
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
4513
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
4514
	| UNDERSCORE_CHARSET HEX_NUM
4515
	  {
4516 4517
	    Item *tmp= new Item_varbinary($2.str,$2.length);
	    String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0;
unknown's avatar
unknown committed
4518 4519 4520
	    $$= new Item_string(str ? str->ptr() : "",
				str ? str->length() : 0,
				Lex->charset);
4521
	  }
unknown's avatar
unknown committed
4522 4523
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
4524
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
4525

4526 4527 4528 4529 4530 4531 4532 4533
NUM_literal:
	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); }
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	;
	
unknown's avatar
unknown committed
4534 4535 4536 4537 4538 4539
/**********************************************************************
** Createing different items.
**********************************************************************/

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
4540
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
4541 4542

table_wild:
unknown's avatar
unknown committed
4543
	ident '.' '*'
4544 4545
	{
	  $$ = new Item_field(NullS,$1.str,"*");
unknown's avatar
unknown committed
4546
	  Lex->current_select->with_wild++;
4547
	}
unknown's avatar
unknown committed
4548
	| ident '.' ident '.' '*'
4549 4550 4551 4552
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
unknown's avatar
unknown committed
4553
	  Lex->current_select->with_wild++;
4554 4555
	}
	;
unknown's avatar
unknown committed
4556 4557

order_ident:
unknown's avatar
unknown committed
4558
	expr { $$=$1; };
unknown's avatar
unknown committed
4559 4560 4561

simple_ident:
	ident
unknown's avatar
unknown committed
4562
	{
unknown's avatar
unknown committed
4563
	  SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
4564 4565 4566
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
              (Item*) new Item_field(NullS,NullS,$1.str) :
unknown's avatar
unknown committed
4567
	      (Item*) new Item_ref(0,0, NullS,NullS,$1.str);
unknown's avatar
unknown committed
4568
	}
unknown's avatar
unknown committed
4569
	| ident '.' ident
unknown's avatar
unknown committed
4570
	{
unknown's avatar
unknown committed
4571
	  THD *thd= YYTHD;
4572
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
4573
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4574 4575
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4576
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4577 4578 4579
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
unknown's avatar
unknown committed
4580 4581 4582
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$1.str,$3.str) :
unknown's avatar
unknown committed
4583
	      (Item*) new Item_ref(0,0,NullS,$1.str,$3.str);
unknown's avatar
unknown committed
4584
	}
unknown's avatar
unknown committed
4585
	| '.' ident '.' ident
unknown's avatar
unknown committed
4586
	{
unknown's avatar
unknown committed
4587
	  THD *thd= YYTHD;
4588
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
4589
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4590 4591
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4592
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4593 4594 4595
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
unknown's avatar
unknown committed
4596 4597 4598
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$2.str,$4.str) :
unknown's avatar
unknown committed
4599
              (Item*) new Item_ref(0,0,NullS,$2.str,$4.str);
unknown's avatar
unknown committed
4600
	}
unknown's avatar
unknown committed
4601
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
4602
	{
unknown's avatar
unknown committed
4603
	  THD *thd= YYTHD;
4604
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
4605
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4606 4607
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4608
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4609 4610 4611
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
unknown's avatar
unknown committed
4612 4613 4614 4615 4616
	  $$= (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) :
unknown's avatar
unknown committed
4617 4618
	      (Item*) new Item_ref(0,0,(YYTHD->client_capabilities &
				        CLIENT_NO_SCHEMA ? NullS : $1.str),
unknown's avatar
unknown committed
4619
                                   $3.str, $5.str);
unknown's avatar
unknown committed
4620
	};
unknown's avatar
unknown committed
4621 4622 4623 4624 4625


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
unknown's avatar
unknown committed
4626
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
4627 4628 4629

table_ident:
	ident			{ $$=new Table_ident($1); }
unknown's avatar
unknown committed
4630
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
4631 4632 4633 4634
	| '.' ident		{ $$=new Table_ident($2);} /* For Delphi */
        ;

table_ident_ref:
unknown's avatar
unknown committed
4635 4636
	ident			{ LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); }
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
4637
        ;
unknown's avatar
unknown committed
4638

unknown's avatar
unknown committed
4639
IDENT_sys:
4640 4641 4642 4643 4644 4645 4646 4647 4648 4649
	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
4650 4651 4652 4653 4654 4655
	;

TEXT_STRING_sys:
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4656 4657
	  if (thd->charset_is_system_charset)
	    $$= $1;
unknown's avatar
unknown committed
4658
	  else
unknown's avatar
unknown committed
4659 4660
	    thd->convert_string(&$$, system_charset_info,
				$1.str, $1.length, thd->charset());
unknown's avatar
unknown committed
4661 4662 4663
	}
	;

4664
TEXT_STRING_literal:
unknown's avatar
unknown committed
4665 4666 4667
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4668 4669
	  if (thd->charset_is_collation_connection)
	    $$= $1;
unknown's avatar
unknown committed
4670
	  else
unknown's avatar
unknown committed
4671 4672
	    thd->convert_string(&$$, thd->variables.collation_connection,
				$1.str, $1.length, thd->charset());
unknown's avatar
unknown committed
4673 4674 4675 4676
	}
	;


unknown's avatar
unknown committed
4677
ident:
unknown's avatar
unknown committed
4678
	IDENT_sys	    { $$=$1; }
unknown's avatar
unknown committed
4679 4680
	| keyword
	{
unknown's avatar
unknown committed
4681 4682 4683
	  THD *thd= YYTHD;
	  $$.str=    thd->strmake($1.str, $1.length);
	  $$.length= $1.length;
4684 4685
	}
	;
unknown's avatar
unknown committed
4686 4687

ident_or_text:
unknown's avatar
unknown committed
4688 4689 4690
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
unknown's avatar
unknown committed
4691 4692 4693 4694

user:
	ident_or_text
	{
unknown's avatar
unknown committed
4695 4696
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4697
	    YYABORT;
4698 4699 4700 4701
	  $$->user = $1;
	  $$->host.str= (char *) "%";
	  $$->host.length= 1;
	}
unknown's avatar
unknown committed
4702 4703
	| ident_or_text '@' ident_or_text
	  {
unknown's avatar
unknown committed
4704 4705
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4706 4707
	      YYABORT;
	    $$->user = $1; $$->host=$3;
unknown's avatar
unknown committed
4708
	  };
unknown's avatar
unknown committed
4709 4710 4711 4712 4713

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
unknown's avatar
unknown committed
4714
	| ADDDATE_SYM		{}
unknown's avatar
unknown committed
4715
	| AFTER_SYM		{}
4716
	| AGAINST		{}
unknown's avatar
unknown committed
4717
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
4718
	| ANY_SYM		{}
unknown's avatar
unknown committed
4719
	| ASCII_SYM		{}
unknown's avatar
unknown committed
4720
	| AUTO_INC		{}
unknown's avatar
unknown committed
4721 4722
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
4723
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
4724
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
4725
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
4726
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
4727 4728
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
4729
	| BOOLEAN_SYM		{}
4730
	| BYTE_SYM		{}
unknown's avatar
unknown committed
4731
	| BTREE_SYM		{}
unknown's avatar
unknown committed
4732
	| CACHE_SYM		{}
4733
	| CHANGED		{}
4734
	| CHARSET		{}
unknown's avatar
unknown committed
4735
	| CHECKSUM_SYM		{}
4736
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
4737
	| CLIENT_SYM		{}
4738
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
4739
	| COLLATION_SYM		{}
unknown's avatar
unknown committed
4740
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
4741
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
4742
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
4743
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
4744
	| CONCURRENT		{}
4745
	| CUBE_SYM		{}
unknown's avatar
unknown committed
4746 4747 4748 4749 4750
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
4751 4752
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
4753
	| DISCARD		{}
unknown's avatar
unknown committed
4754
	| DO_SYM		{}
4755
	| DUAL_SYM		{}
unknown's avatar
unknown committed
4756 4757
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
unknown's avatar
unknown committed
4758 4759 4760
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
unknown's avatar
unknown committed
4761
	| ENGINE_SYM		{}
unknown's avatar
unknown committed
4762
	| ENGINES_SYM		{}
4763
	| ERRORS		{}
unknown's avatar
unknown committed
4764
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
4765
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
4766
	| EXECUTE_SYM		{}
4767
        | EXPANSION_SYM         {}
unknown's avatar
unknown committed
4768
	| EXTENDED_SYM		{}
4769
	| FAST_SYM		{}
unknown's avatar
unknown committed
4770 4771
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
4772
	| FULL			{}
unknown's avatar
unknown committed
4773 4774 4775 4776
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
4777
	| GEOMETRY_SYM		{}
4778
	| GEOMETRYCOLLECTION	{}
4779
	| GET_FORMAT		{}
unknown's avatar
unknown committed
4780
	| GRANTS		{}
unknown's avatar
unknown committed
4781
	| GLOBAL_SYM		{}
4782
	| HANDLER_SYM		{}
unknown's avatar
unknown committed
4783
	| HASH_SYM		{}
4784
	| HELP_SYM		{}
unknown's avatar
unknown committed
4785 4786 4787
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
4788
	| IMPORT		{}
unknown's avatar
unknown committed
4789
	| INDEXES		{}
unknown's avatar
unknown committed
4790
	| ISOLATION		{}
unknown's avatar
unknown committed
4791
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
4792
	| INNOBASE_SYM		{}
4793
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
4794
	| RELAY_THREAD		{}
4795
	| LAST_SYM		{}
unknown's avatar
unknown committed
4796
	| LEAVES                {}
unknown's avatar
unknown committed
4797
	| LEVEL_SYM		{}
4798
	| LINESTRING		{}
unknown's avatar
unknown committed
4799
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
4800
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
4801 4802 4803 4804 4805 4806 4807 4808 4809
	| 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	{}
unknown's avatar
unknown committed
4810
	| MASTER_SERVER_ID_SYM  {}
unknown's avatar
unknown committed
4811
	| MASTER_CONNECT_RETRY_SYM	{}
unknown's avatar
unknown committed
4812 4813 4814 4815 4816 4817
	| 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
4818 4819 4820
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
4821
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
4822
	| MICROSECOND_SYM	{}
unknown's avatar
unknown committed
4823 4824 4825
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
4826
	| MODE_SYM		{}
unknown's avatar
unknown committed
4827
	| MONTH_SYM		{}
4828 4829 4830
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
unknown's avatar
unknown committed
4831
	| NAMES_SYM		{}
unknown's avatar
unknown committed
4832 4833
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
4834
	| NEXT_SYM		{}
unknown's avatar
unknown committed
4835
	| NEW_SYM		{}
unknown's avatar
unknown committed
4836
	| NO_SYM		{}
4837
	| NONE_SYM		{}
unknown's avatar
unknown committed
4838
	| NVARCHAR_SYM		{}
unknown's avatar
unknown committed
4839
	| OFFSET_SYM		{}
unknown's avatar
unknown committed
4840
	| OLD_PASSWORD		{}
4841
	| OPEN_SYM		{}
unknown's avatar
unknown committed
4842
	| PACK_KEYS_SYM		{}
4843
	| PARTIAL		{}
unknown's avatar
unknown committed
4844
	| PASSWORD		{}
4845
	| POINT_SYM		{}
4846
	| POLYGON		{}
4847
	| PREV_SYM		{}
unknown's avatar
unknown committed
4848 4849
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
4850
	| QUERY_SYM		{}
4851
	| QUICK			{}
unknown's avatar
unknown committed
4852
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
4853 4854
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
4855
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
4856
	| RAID_TYPE		{}
unknown's avatar
unknown committed
4857 4858
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
4859 4860
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
4861
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
4862
	| REPLICATION		{}
unknown's avatar
unknown committed
4863
	| RESET_SYM		{}
4864
	| RESOURCES		{}
unknown's avatar
unknown committed
4865
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
4866
	| ROLLBACK_SYM		{}
4867
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
4868 4869 4870
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
unknown's avatar
unknown committed
4871
	| RTREE_SYM		{}
4872
	| SAVEPOINT_SYM		{}
unknown's avatar
unknown committed
4873
	| SECOND_SYM		{}
4874
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
4875 4876
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
4877
	| SIGNED_SYM		{}
4878
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
4879
	| SHARE_SYM		{}
unknown's avatar
unknown committed
4880
	| SHUTDOWN		{}
unknown's avatar
unknown committed
4881
	| SLAVE			{}
unknown's avatar
unknown committed
4882
	| SOUNDS_SYM		{}
unknown's avatar
unknown committed
4883
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
4884
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
4885
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
4886
	| SQL_THREAD		{}
unknown's avatar
unknown committed
4887 4888 4889
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
unknown's avatar
unknown committed
4890
	| STORAGE_SYM		{}
unknown's avatar
unknown committed
4891
	| STRING_SYM		{}
unknown's avatar
unknown committed
4892
	| SUBDATE_SYM		{}
unknown's avatar
unknown committed
4893
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
4894
	| SUPER_SYM		{}
unknown's avatar
unknown committed
4895
	| TABLESPACE		{}
unknown's avatar
unknown committed
4896 4897
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
4898
	| TRANSACTION_SYM	{}
4899
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
4900 4901 4902
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
unknown's avatar
unknown committed
4903
	| TYPES_SYM		{}
unknown's avatar
unknown committed
4904
	| UDF_SYM		{}
unknown's avatar
unknown committed
4905
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
4906
	| UNICODE_SYM		{}
4907
	| UNTIL_SYM		{}
4908
	| USER			{}
unknown's avatar
unknown committed
4909
	| USE_FRM		{}
unknown's avatar
unknown committed
4910
	| VARIABLES		{}
4911
	| VALUE_SYM		{}
4912
	| WARNINGS		{}
unknown's avatar
unknown committed
4913
	| WORK_SYM		{}
4914
	| X509_SYM		{}
unknown's avatar
unknown committed
4915 4916
	| YEAR_SYM		{}
	;
unknown's avatar
unknown committed
4917 4918 4919 4920 4921 4922

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
4923 4924
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
unknown's avatar
unknown committed
4925 4926
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
unknown's avatar
unknown committed
4927
	}
4928 4929 4930
	option_value_list
	{}
	;
unknown's avatar
unknown committed
4931 4932 4933

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
4934
	| OPTION {};
unknown's avatar
unknown committed
4935 4936

option_value_list:
unknown's avatar
unknown committed
4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948
	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
4949
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4950 4951 4952 4953 4954 4955
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
4956
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4957 4958 4959
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
4960 4961

option_value:
unknown's avatar
unknown committed
4962
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
4963
	{
unknown's avatar
unknown committed
4964
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
4965
	}
unknown's avatar
unknown committed
4966
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4967
	  {
unknown's avatar
unknown committed
4968
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4969 4970
	    lex->var_list.push_back(new set_var(lex->option_type, $1.var,
						&$1.base_name, $3));
unknown's avatar
unknown committed
4971
	  }
unknown's avatar
unknown committed
4972
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4973 4974
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4975 4976
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4.var,
						&$4.base_name, $6));
unknown's avatar
unknown committed
4977 4978 4979 4980
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4981 4982 4983
	    LEX_STRING tmp;
	    tmp.str=0;
	    tmp.length=0;
unknown's avatar
unknown committed
4984
	    lex->var_list.push_back(new set_var(lex->option_type,
unknown's avatar
unknown committed
4985
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
4986
						&tmp,
unknown's avatar
unknown committed
4987
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
4988
	  }
4989
	| charset old_or_new_charset_name_or_default
unknown's avatar
unknown committed
4990
	{
unknown's avatar
unknown committed
4991
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4992
	  LEX *lex= Lex;
4993
	  $2= $2 ? $2: global_system_variables.character_set_client;
4994
	  lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
unknown's avatar
unknown committed
4995
	}
4996
	| NAMES_SYM charset_name_or_default opt_collate
4997
	{
unknown's avatar
unknown committed
4998
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4999
	  LEX *lex= Lex;
5000
	  $2= $2 ? $2 : global_system_variables.character_set_client;
5001 5002
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
5003
	  {
unknown's avatar
unknown committed
5004 5005
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
5006
	  }
5007
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
5008
	}
unknown's avatar
unknown committed
5009
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
5010
	  {
5011
	    THD *thd=YYTHD;
unknown's avatar
unknown committed
5012
	    LEX_USER *user;
unknown's avatar
unknown committed
5013
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
unknown's avatar
unknown committed
5014 5015 5016
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
5017
	    thd->lex->var_list.push_back(new set_var_password(user, $3));
unknown's avatar
unknown committed
5018 5019
	  }
	| PASSWORD FOR_SYM user equal text_or_password
unknown's avatar
unknown committed
5020
	  {
unknown's avatar
unknown committed
5021 5022
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
5023
	;
unknown's avatar
unknown committed
5024

unknown's avatar
unknown committed
5025 5026 5027 5028 5029 5030
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
unknown's avatar
unknown committed
5031 5032 5033
	  $$.var= tmp;
	  $$.base_name.str=0;
	  $$.base_name.length=0;
unknown's avatar
unknown committed
5034
	}
5035 5036 5037 5038 5039 5040 5041
	| 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
5042 5043
	    $$.var= tmp;
	    $$.base_name= $1;
5044 5045 5046 5047 5048 5049 5050 5051
	  }
	| 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
5052 5053 5054
	    $$.var= tmp;
	    $$.base_name.str=    (char*) "default";
	    $$.base_name.length= 7;
5055
	  }
5056
        ;
unknown's avatar
unknown committed
5057 5058 5059 5060 5061 5062 5063

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; }
	;
5064

unknown's avatar
unknown committed
5065 5066 5067 5068
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
5069
	    $$= $3.length ? YYTHD->variables.old_passwords ?
unknown's avatar
unknown committed
5070 5071 5072 5073 5074 5075 5076 5077
	        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;
5078 5079
	  }
          ;
unknown's avatar
unknown committed
5080

unknown's avatar
unknown committed
5081

unknown's avatar
unknown committed
5082
set_expr_or_default:
unknown's avatar
unknown committed
5083 5084
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
5085 5086
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
5087
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
unknown's avatar
unknown committed
5088
	;
unknown's avatar
unknown committed
5089 5090


unknown's avatar
unknown committed
5091 5092 5093 5094 5095 5096 5097
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
5098 5099 5100
	table_lock_list
	{}
	;
unknown's avatar
unknown committed
5101 5102 5103

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
5104
	| TABLES;
unknown's avatar
unknown committed
5105 5106 5107

table_lock_list:
	table_lock
unknown's avatar
unknown committed
5108
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
5109 5110 5111

table_lock:
	table_ident opt_table_alias lock_option
5112
	{
unknown's avatar
unknown committed
5113
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
5114 5115
	   YYABORT;
	}
5116
        ;
unknown's avatar
unknown committed
5117 5118 5119

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
5120
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
unknown's avatar
unknown committed
5121
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
5122 5123
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
5124 5125

unlock:
5126 5127
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
5128 5129


5130
/*
unknown's avatar
unknown committed
5131
** Handler: direct access to ISAM functions
5132 5133 5134 5135 5136
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
5137 5138
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
unknown's avatar
unknown committed
5139
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
5140 5141
	    YYABORT;
	}
5142
	| HANDLER_SYM table_ident_ref CLOSE_SYM
5143
	{
5144 5145
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
unknown's avatar
unknown committed
5146
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
5147 5148
	    YYABORT;
	}
5149
	| HANDLER_SYM table_ident_ref READ_SYM
5150
	{
unknown's avatar
unknown committed
5151 5152 5153
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
5154 5155
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
unknown's avatar
unknown committed
5156
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
5157
	    YYABORT;
unknown's avatar
unknown committed
5158
        }
5159
        handler_read_or_scan where_clause opt_limit_clause {}
5160
        ;
5161

unknown's avatar
unknown committed
5162 5163
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
5164 5165
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
5166 5167 5168

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
5169 5170
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
5171 5172 5173 5174 5175 5176

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;  }
5177 5178
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
5179 5180
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
5181
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
5182
	  if (!(lex->insert_list = new List_item))
5183
	    YYABORT;
5184 5185
	} '(' values ')' { }
        ;
5186 5187

handler_rkey_mode:
unknown's avatar
unknown committed
5188 5189 5190 5191
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
5192 5193
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
5194

unknown's avatar
unknown committed
5195 5196 5197 5198 5199
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
5200 5201 5202 5203 5204
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
5205
	  lex->select_lex.db=0;
5206 5207
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
5208
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
5209
	}
5210 5211 5212 5213 5214
	revoke_command
	{}
        ;

revoke_command:
5215 5216
	grant_privileges ON opt_table FROM user_list
	{}
5217
	|
5218
	ALL PRIVILEGES ',' GRANT OPTION FROM user_list
5219 5220 5221
	{
	  Lex->sql_command = SQLCOM_REVOKE_ALL;
	}
5222
	;
unknown's avatar
unknown committed
5223 5224 5225 5226

grant:
	GRANT
	{
unknown's avatar
unknown committed
5227 5228 5229
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
5230 5231
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
5232
	  lex->select_lex.db= 0;
5233 5234
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
5235
	  bzero((char *)&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
5236 5237
	}
	grant_privileges ON opt_table TO_SYM user_list
5238 5239 5240
	require_clause grant_options
	{}
	;
unknown's avatar
unknown committed
5241 5242 5243

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
5244
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
5245 5246
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
unknown's avatar
unknown committed
5247 5248 5249

grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
5250
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
5251 5252

grant_privilege:
unknown's avatar
unknown committed
5253
	SELECT_SYM	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
5254 5255 5256
	| 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
5257 5258
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
5259 5260 5261 5262
	| 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
5263
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
5264 5265 5266 5267
	| 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
5268 5269 5270 5271 5272 5273 5274 5275
	| 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
5276

unknown's avatar
unknown committed
5277

5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289
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
5290 5291 5292 5293
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
5294
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
5295 5296 5297 5298 5299 5300 5301 5302 5303
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
5304
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
5305 5306 5307 5308 5309 5310 5311 5312 5313
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
5314
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
5315 5316 5317 5318 5319
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
5320

unknown's avatar
unknown committed
5321 5322 5323
opt_table:
	'*'
	  {
5324
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5325
	    lex->current_select->db= lex->thd->db;
unknown's avatar
unknown committed
5326
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5327 5328
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5329
	    {
5330
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
5331
	      YYABORT;
unknown's avatar
unknown committed
5332
	    }
unknown's avatar
unknown committed
5333 5334 5335
	  }
	| ident '.' '*'
	  {
5336
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5337
	    lex->current_select->db = $1.str;
unknown's avatar
unknown committed
5338
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5339 5340
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5341
	    {
5342
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
5343 5344 5345 5346 5347
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
5348
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5349
	    lex->current_select->db = NULL;
unknown's avatar
unknown committed
5350 5351
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
5352
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5353
	    {
5354
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
5355 5356 5357 5358 5359
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
5360
	    LEX *lex=Lex;
unknown's avatar
unknown committed
5361
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
unknown's avatar
unknown committed
5362
	      YYABORT;
unknown's avatar
unknown committed
5363
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5364
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
5365 5366
	  }
          ;
unknown's avatar
unknown committed
5367 5368 5369


user_list:
5370 5371 5372 5373 5374 5375 5376
	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
5377 5378 5379 5380 5381 5382 5383 5384


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
5385
             if (YYTHD->variables.old_passwords)
5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402
             {
               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
5403 5404 5405 5406 5407
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
5408 5409
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
5410 5411 5412


opt_column_list:
unknown's avatar
unknown committed
5413 5414 5415 5416 5417
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
5418
	| '(' column_list ')';
unknown's avatar
unknown committed
5419 5420 5421

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
5422
	| column_list_id;
unknown's avatar
unknown committed
5423 5424 5425 5426

column_list_id:
	ident
	{
5427
	  String *new_str = new String((const char*) $1.str,$1.length,system_charset_info);
unknown's avatar
unknown committed
5428 5429
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
5430
	  LEX *lex=Lex;
unknown's avatar
unknown committed
5431 5432
	  while ((point=iter++))
	  {
5433 5434
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
5435 5436
		break;
	  }
unknown's avatar
unknown committed
5437
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
5438
	  if (point)
unknown's avatar
unknown committed
5439
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
5440
	  else
unknown's avatar
unknown committed
5441
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
5442 5443
	}
        ;
unknown's avatar
unknown committed
5444

unknown's avatar
unknown committed
5445 5446

require_clause: /* empty */
5447
        | REQUIRE_SYM require_list
5448 5449 5450
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
5451
        | REQUIRE_SYM SSL_SYM
5452 5453 5454
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
5455
        | REQUIRE_SYM X509_SYM
5456 5457 5458 5459 5460 5461 5462
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
5463
          ;
unknown's avatar
unknown committed
5464

unknown's avatar
unknown committed
5465
grant_options:
unknown's avatar
unknown committed
5466
	/* empty */ {}
unknown's avatar
unknown committed
5467
	| WITH grant_option_list;
unknown's avatar
unknown committed
5468

unknown's avatar
unknown committed
5469 5470
grant_option_list:
	grant_option_list grant_option {}
5471 5472
	| grant_option {}
        ;
unknown's avatar
unknown committed
5473 5474 5475

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
5476
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
5477
        {
5478
	  Lex->mqh.questions=$2;
5479
	  Lex->mqh.bits |= 1;
5480
	}
5481
        | MAX_UPDATES_PER_HOUR ULONG_NUM
5482
        {
5483
	  Lex->mqh.updates=$2;
5484
	  Lex->mqh.bits |= 2;
5485
	}
5486
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
5487
        {
5488
	  Lex->mqh.connections=$2;
5489
	  Lex->mqh.bits |= 4;
5490 5491
	}
        ;
5492

unknown's avatar
unknown committed
5493
begin:
5494 5495
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
unknown's avatar
unknown committed
5496 5497 5498

opt_work:
	/* empty */ {}
5499 5500
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
5501 5502

commit:
unknown's avatar
unknown committed
5503
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
5504 5505

rollback:
unknown's avatar
unknown committed
5506
	ROLLBACK_SYM
5507 5508 5509 5510 5511
	{
	  Lex->sql_command = SQLCOM_ROLLBACK;
	}
	| ROLLBACK_SYM TO_SYM SAVEPOINT_SYM ident
	{
unknown's avatar
unknown committed
5512
	  Lex->sql_command = SQLCOM_ROLLBACK_TO_SAVEPOINT;
5513 5514 5515 5516 5517 5518 5519 5520
	  Lex->savepoint_name = $4.str;
	};
savepoint:
	SAVEPOINT_SYM ident
	{
	  Lex->sql_command = SQLCOM_SAVEPOINT;
	  Lex->savepoint_name = $2.str;
	};
5521 5522

/*
unknown's avatar
unknown committed
5523
   UNIONS : glue selects together
5524 5525 5526
*/


5527
union_clause:
5528
	/* empty */ {}
unknown's avatar
unknown committed
5529 5530
	| union_list
	;
5531 5532

union_list:
unknown's avatar
unknown committed
5533
	UNION_SYM    union_option
5534 5535 5536 5537 5538
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
5539
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
5540
	    YYABORT;
5541
	  }
5542
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
5543
	  {
5544
            yyerror(ER(ER_SYNTAX_ERROR));
5545 5546
	    YYABORT;
	  }
5547
	  if (mysql_new_select(lex, 0))
5548
	    YYABORT;
unknown's avatar
unknown committed
5549
          mysql_init_select(lex);
5550
	  lex->current_select->linkage=UNION_TYPE;
unknown's avatar
unknown committed
5551
	}
5552
	select_init {}
5553
	;
5554 5555

union_opt:
unknown's avatar
unknown committed
5556
	union_list {}
unknown's avatar
unknown committed
5557 5558
	| optional_order_or_limit {}
	;
5559 5560

optional_order_or_limit:
5561
	/* Empty */ {}
5562 5563
	|
	  {
unknown's avatar
unknown committed
5564
	    THD *thd= YYTHD;
5565
	    LEX *lex= thd->lex;
unknown's avatar
unknown committed
5566
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
unknown's avatar
unknown committed
5567
	    SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
5568
	    SELECT_LEX_UNIT *unit= sel->master_unit();
unknown's avatar
unknown committed
5569
	    SELECT_LEX *fake= unit->fake_select_lex;
unknown's avatar
unknown committed
5570 5571 5572 5573 5574 5575
	    if (fake)
	    {
	      unit->global_parameters= fake;
	      fake->no_table_names_allowed= 1;
	      lex->current_select= fake;
	    }
unknown's avatar
unknown committed
5576
	    thd->where= "global ORDER clause";
5577
	  }
5578
	order_or_limit
unknown's avatar
unknown committed
5579 5580
          {
	    THD *thd= YYTHD;
5581
	    thd->lex->current_select->no_table_names_allowed= 0;
unknown's avatar
unknown committed
5582 5583
	    thd->where= "";
          }
5584 5585 5586
	;

order_or_limit:
5587 5588
	order_clause opt_limit_clause_init
	| limit_clause
5589
	;
unknown's avatar
unknown committed
5590 5591

union_option:
5592
	/* empty */ {}
5593
	| DISTINCT {}
unknown's avatar
unknown committed
5594
	| ALL {Select->master_unit()->union_option|= UNION_ALL;};
5595

unknown's avatar
unknown committed
5596 5597
singlerow_subselect:
	subselect_start singlerow_subselect_init
unknown's avatar
unknown committed
5598 5599 5600 5601
	subselect_end
	{
	  $$= $2;
	};
5602

unknown's avatar
unknown committed
5603
singlerow_subselect_init:
5604
	select_init2
unknown's avatar
unknown committed
5605
	{
5606 5607
	  $$= new Item_singlerow_subselect(Lex->current_select->
					   master_unit()->first_select());
unknown's avatar
unknown committed
5608
	};
unknown's avatar
unknown committed
5609 5610

exists_subselect:
unknown's avatar
unknown committed
5611 5612 5613 5614 5615
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
5616 5617

exists_subselect_init:
5618
	select_init2
unknown's avatar
unknown committed
5619
	{
5620 5621
	  $$= new Item_exists_subselect(Lex->current_select->master_unit()->
					first_select());
unknown's avatar
unknown committed
5622
	};
5623

unknown's avatar
unknown committed
5624 5625 5626 5627 5628 5629 5630 5631
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
5632
  select_init2
unknown's avatar
unknown committed
5633
  {
unknown's avatar
unknown committed
5634
    $$= Lex->current_select->master_unit()->first_select();
unknown's avatar
unknown committed
5635 5636
  };

5637
subselect_start:
5638
	'(' SELECT_SYM
unknown's avatar
unknown committed
5639
	{
5640
	  LEX *lex=Lex;
5641
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
5642 5643
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
5644 5645
	  {
            yyerror(ER(ER_SYNTAX_ERROR));
5646 5647
	    YYABORT;
	  }
unknown's avatar
unknown committed
5648 5649 5650
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
5651 5652

subselect_end:
unknown's avatar
unknown committed
5653 5654 5655
	')'
	{
	  LEX *lex=Lex;
5656
	  lex->current_select = lex->current_select->return_after_parsing();
unknown's avatar
unknown committed
5657
	};
unknown's avatar
unknown committed
5658