sql_yacc.yy 151 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
#include "lex_symbol.h"
36
#include "item_create.h"
unknown's avatar
unknown committed
37
#include <myisam.h>
38
#include <myisammrg.h>
39

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

42
#define yyoverflow(A,B,C,D,E,F) {ulong val= *(F); if(my_yyoverflow((B), (D), &val)) { yyerror((char*) (A)); return 2; } else { *(F)= (YYSIZE_T)val; }}
unknown's avatar
unknown committed
43

unknown's avatar
unknown committed
44 45 46 47 48
#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)); 

49
inline Item *or_or_concat(THD *thd, Item* A, Item* B)
unknown's avatar
unknown committed
50
{
51
  return (thd->variables.sql_mode & MODE_PIPES_AS_CONCAT ?
unknown's avatar
unknown committed
52 53 54 55 56 57 58
          (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
59
  ulonglong ulonglong_number;
unknown's avatar
unknown committed
60 61 62 63 64 65
  LEX_STRING lex_str;
  LEX_STRING *lex_str_ptr;
  LEX_SYMBOL symbol;
  Table_ident *table;
  char *simple_string;
  Item *item;
66
  Item_num *item_num;
unknown's avatar
unknown committed
67 68
  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
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
unknown's avatar
unknown committed
93 94 95 96 97 98
%}

%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
%token	CLIENT_SYM
%token	COMMENT_SYM
%token	COMMIT_SYM
133
%token  CONSISTENT_SYM
unknown's avatar
unknown committed
134
%token	COUNT_SYM
unknown's avatar
unknown committed
135 136
%token	CREATE
%token	CROSS
137
%token  CUBE_SYM
unknown's avatar
unknown committed
138
%token	DELETE_SYM
139
%token	DUAL_SYM
unknown's avatar
unknown committed
140
%token	DO_SYM
unknown's avatar
unknown committed
141
%token	DROP
unknown's avatar
unknown committed
142 143
%token	EVENTS_SYM
%token	EXECUTE_SYM
144
%token	EXPANSION_SYM
unknown's avatar
unknown committed
145
%token	FLUSH_SYM
146
%token  HELP_SYM
unknown's avatar
unknown committed
147
%token	INSERT
unknown's avatar
unknown committed
148
%token	RELAY_THREAD
unknown's avatar
unknown committed
149 150
%token	KILL_SYM
%token	LOAD
unknown's avatar
unknown committed
151
%token	LOCKS_SYM
unknown's avatar
unknown committed
152 153 154 155
%token	LOCK_SYM
%token	MASTER_SYM
%token	MAX_SYM
%token	MIN_SYM
156
%token	NONE_SYM
unknown's avatar
unknown committed
157 158 159 160 161 162
%token	OPTIMIZE
%token	PURGE
%token	REPAIR
%token	REPLICATION
%token	RESET_SYM
%token	ROLLBACK_SYM
163
%token  ROLLUP_SYM
164
%token	SAVEPOINT_SYM
unknown's avatar
unknown committed
165 166 167
%token	SELECT_SYM
%token	SHOW
%token	SLAVE
168
%token  SNAPSHOT_SYM
unknown's avatar
unknown committed
169 170 171
%token	SQL_THREAD
%token	START_SYM
%token	STD_SYM
unknown's avatar
unknown committed
172
%token  VARIANCE_SYM
unknown's avatar
unknown committed
173 174
%token	STOP_SYM
%token	SUM_SYM
unknown's avatar
unknown committed
175
%token	ADDDATE_SYM
unknown's avatar
unknown committed
176 177
%token	SUPER_SYM
%token	TRUNCATE_SYM
unknown's avatar
unknown committed
178
%token	UNLOCK_SYM
179
%token	UNTIL_SYM
unknown's avatar
unknown committed
180
%token	UPDATE_SYM
unknown's avatar
unknown committed
181 182 183 184

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

unknown's avatar
unknown committed
411 412 413
%token  ERRORS
%token  WARNINGS

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

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

unknown's avatar
unknown committed
570 571 572 573
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
574
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
575
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
576

unknown's avatar
unknown committed
577 578
%token  ISSUER_SYM
%token  SUBJECT_SYM
579
%token  CIPHER_SYM
unknown's avatar
unknown committed
580

581
%token  BEFORE_SYM
unknown's avatar
unknown committed
582
%left   SET_VAR
unknown's avatar
unknown committed
583 584
%left	OR_OR_CONCAT OR_SYM XOR
%left	AND_SYM
unknown's avatar
unknown committed
585 586 587 588 589 590
%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	'-' '+'
591
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
592
%left   '^'
unknown's avatar
unknown committed
593
%left	NEG '~'
unknown's avatar
unknown committed
594
%right	NOT
unknown's avatar
unknown committed
595
%right	BINARY COLLATE_SYM
596

unknown's avatar
unknown committed
597
%type <lex_str>
598 599
	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
600
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
601
	NCHAR_STRING opt_component key_cache_name
unknown's avatar
unknown committed
602 603 604 605 606

%type <lex_str_ptr>
	opt_table_alias

%type <table>
unknown's avatar
unknown committed
607
	table_ident table_ident_nodb references
unknown's avatar
unknown committed
608 609

%type <simple_string>
610
	remember_name remember_end opt_ident opt_db text_or_password
611
	opt_constraint constraint ident_or_empty
unknown's avatar
unknown committed
612 613

%type <string>
614
	text_string opt_gconcat_separator
unknown's avatar
unknown committed
615 616

%type <num>
unknown's avatar
unknown committed
617
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
618
	udf_type if_exists opt_local opt_table_options table_options
619 620
        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
621
        opt_ignore_leaves fulltext_options spatial_type union_option
622
        start_transaction_opts
unknown's avatar
unknown committed
623 624

%type <ulong_num>
625
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
626

unknown's avatar
unknown committed
627 628
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
629

unknown's avatar
unknown committed
630 631 632
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

unknown's avatar
unknown committed
633
%type <item>
unknown's avatar
unknown committed
634
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
635
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
636
	table_wild no_in_expr expr_expr simple_expr no_and_expr
637
	using_list expr_or_default set_expr_or_default interval_expr
unknown's avatar
unknown committed
638
	param_marker singlerow_subselect singlerow_subselect_init
unknown's avatar
unknown committed
639
	exists_subselect exists_subselect_init geometry_function
640
	signed_literal now_or_signed_literal opt_escape
641 642 643

%type <item_num>
	NUM_literal
unknown's avatar
unknown committed
644 645

%type <item_list>
unknown's avatar
unknown committed
646
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
647 648

%type <key_type>
649
	key_type opt_unique_or_fulltext constraint_key_type
unknown's avatar
unknown committed
650

unknown's avatar
unknown committed
651 652 653
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
654 655 656 657 658 659 660
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
661
	join_table_list  join_table
unknown's avatar
unknown committed
662 663 664 665 666

%type <udf>
	UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
	UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM

667
%type <date_time_type> date_time_type;
unknown's avatar
unknown committed
668 669
%type <interval> interval

unknown's avatar
unknown committed
670
%type <db_type> storage_engines
unknown's avatar
unknown committed
671 672 673

%type <row_type> row_types

unknown's avatar
unknown committed
674
%type <tx_isolation> isolation_types
unknown's avatar
unknown committed
675

unknown's avatar
unknown committed
676 677
%type <ha_rkey_mode> handler_rkey_mode

678
%type <cast_type> cast_type
unknown's avatar
unknown committed
679

unknown's avatar
unknown committed
680 681 682 683 684 685
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

686
%type <charset>
687
	opt_collate
688 689
	charset_name
	charset_name_or_default
unknown's avatar
unknown committed
690 691
	old_or_new_charset_name
	old_or_new_charset_name_or_default
692 693
	collation_name
	collation_name_or_default
694

unknown's avatar
unknown committed
695 696
%type <variable> internal_variable_name

unknown's avatar
unknown committed
697 698
%type <select_lex> in_subselect in_subselect_init

unknown's avatar
unknown committed
699 700
%type <boolfunc2creator> comp_op

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

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
unknown's avatar
unknown committed
738
	',' '!' '{' '}' '&' '|' AND_SYM OR_SYM OR_OR_CONCAT BETWEEN_SYM CASE_SYM
739
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
unknown's avatar
unknown committed
740 741 742 743 744
%%


query:
	END_OF_INPUT
unknown's avatar
unknown committed
745
	{
746
	   THD *thd= YYTHD;
747
	   if (!thd->bootstrap &&
748
	      (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
749
	   {
750
	     send_error(thd,ER_EMPTY_QUERY);
751
	     YYABORT;
752
	   }
753 754
	   else
	   {
755
	     thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
756
	   }
unknown's avatar
unknown committed
757
	}
unknown's avatar
unknown committed
758
	| verb_clause END_OF_INPUT {};
unknown's avatar
unknown committed
759 760 761 762

verb_clause:
	  alter
	| analyze
763
	| backup
unknown's avatar
unknown committed
764 765 766
	| begin
	| change
	| check
767
	| checksum
unknown's avatar
unknown committed
768 769
	| commit
	| create
770
        | deallocate
unknown's avatar
unknown committed
771 772
	| delete
	| describe
unknown's avatar
unknown committed
773
	| do
unknown's avatar
unknown committed
774
	| drop
775
        | execute
unknown's avatar
unknown committed
776
	| flush
unknown's avatar
unknown committed
777
	| grant
unknown's avatar
unknown committed
778 779
	| handler
	| help
unknown's avatar
unknown committed
780
	| insert
unknown's avatar
unknown committed
781
	| kill
unknown's avatar
unknown committed
782 783 784
	| load
	| lock
	| optimize
unknown's avatar
unknown committed
785
        | keycache
unknown's avatar
unknown committed
786
	| preload
787
        | prepare
788
	| purge
789
	| rename
unknown's avatar
unknown committed
790
	| repair
unknown's avatar
unknown committed
791
	| replace
unknown's avatar
unknown committed
792
	| reset
793
	| restore
unknown's avatar
unknown committed
794 795
	| revoke
	| rollback
796
	| savepoint
unknown's avatar
unknown committed
797 798
	| select
	| set
unknown's avatar
unknown committed
799
	| show
unknown's avatar
unknown committed
800
	| slave
unknown's avatar
unknown committed
801
	| start
802
	| truncate
unknown's avatar
unknown committed
803 804
	| unlock
	| update
unknown's avatar
unknown committed
805
	| use
unknown's avatar
unknown committed
806
        ;
807

unknown's avatar
unknown committed
808
deallocate:
809
        deallocate_or_drop PREPARE_SYM ident
unknown's avatar
unknown committed
810 811
        {
          THD *thd=YYTHD;
812
          LEX *lex= thd->lex;
unknown's avatar
unknown committed
813 814 815 816 817
          if (thd->command == COM_PREPARE)
          {
            yyerror(ER(ER_SYNTAX_ERROR));
            YYABORT;
          }
818
          lex->sql_command= SQLCOM_DEALLOCATE_PREPARE;
unknown's avatar
unknown committed
819 820 821
          lex->prepared_stmt_name= $3;
        };

822 823 824 825 826 827
deallocate_or_drop:
	DEALLOCATE_SYM |
	DROP
	;


unknown's avatar
unknown committed
828
prepare:
829
        PREPARE_SYM ident FROM prepare_src
unknown's avatar
unknown committed
830 831
        {
          THD *thd=YYTHD;
832
          LEX *lex= thd->lex;
unknown's avatar
unknown committed
833 834 835 836 837
          if (thd->command == COM_PREPARE)
          {
            yyerror(ER(ER_SYNTAX_ERROR));
            YYABORT;
          }
838
          lex->sql_command= SQLCOM_PREPARE;
unknown's avatar
unknown committed
839 840 841
          lex->prepared_stmt_name= $2;
        };

842 843 844 845 846 847
prepare_src:
        TEXT_STRING_sys
        {
          THD *thd=YYTHD;
          LEX *lex= thd->lex;
          lex->prepared_stmt_code= $1;
unknown's avatar
unknown committed
848
          lex->prepared_stmt_code_is_varref= FALSE;
849 850 851 852 853 854
        }
        | '@' ident_or_text
        {
          THD *thd=YYTHD;
          LEX *lex= thd->lex;
          lex->prepared_stmt_code= $2;
unknown's avatar
unknown committed
855
          lex->prepared_stmt_code_is_varref= TRUE;
856
        };
857

unknown's avatar
unknown committed
858 859 860 861
execute:
        EXECUTE_SYM ident
        {
          THD *thd=YYTHD;
862
          LEX *lex= thd->lex;
unknown's avatar
unknown committed
863 864 865 866 867
          if (thd->command == COM_PREPARE)
          {
            yyerror(ER(ER_SYNTAX_ERROR));
            YYABORT;
          }
868
          lex->sql_command= SQLCOM_EXECUTE;
unknown's avatar
unknown committed
869 870 871 872 873 874 875 876 877 878 879 880
          lex->prepared_stmt_name= $2;
        }
        execute_using
        {}
        ;

execute_using:
        /* nothing */
        | USING execute_var_list
        ;

execute_var_list:
881 882
        execute_var_list ',' execute_var_ident
        | execute_var_ident
unknown's avatar
unknown committed
883 884 885 886 887 888 889 890
        ;

execute_var_ident: '@' ident_or_text
        {
          LEX *lex=Lex;
          LEX_STRING *lexstr= (LEX_STRING*)sql_memdup(&$2, sizeof(LEX_STRING));
          if (!lexstr || lex->prepared_stmt_params.push_back(lexstr))
              YYABORT;
891
        }
unknown's avatar
unknown committed
892 893
        ;

unknown's avatar
unknown committed
894 895
/* help */

896
help:
897
       HELP_SYM ident_or_text
unknown's avatar
unknown committed
898
       {
899 900 901
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
902
       };
unknown's avatar
unknown committed
903 904 905 906

/* change master */

change:
unknown's avatar
unknown committed
907
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
908 909 910
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
unknown's avatar
unknown committed
911
	  bzero((char*) &lex->mi, sizeof(lex->mi));
912 913 914 915
        }
       master_defs
	{}
       ;
unknown's avatar
unknown committed
916 917 918

master_defs:
       master_def
unknown's avatar
unknown committed
919
       | master_defs ',' master_def;
unknown's avatar
unknown committed
920

unknown's avatar
unknown committed
921
master_def:
unknown's avatar
unknown committed
922
       MASTER_HOST_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
923 924 925 926
       {
	 Lex->mi.host = $3.str;
       }
       |
unknown's avatar
unknown committed
927
       MASTER_USER_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
928 929 930 931
       {
	 Lex->mi.user = $3.str;
       }
       |
unknown's avatar
unknown committed
932
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
933 934 935 936
       {
	 Lex->mi.password = $3.str;
       }
       |
unknown's avatar
unknown committed
937
       MASTER_PORT_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
938 939 940 941
       {
	 Lex->mi.port = $3;
       }
       |
unknown's avatar
unknown committed
942
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
943 944 945
       {
	 Lex->mi.connect_retry = $3;
       }
unknown's avatar
unknown committed
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
       | 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;
970
	 }
971
       |
972
         master_file_def
973
       ;
unknown's avatar
unknown committed
974

975 976
master_file_def:
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
977
       {
978
	 Lex->mi.log_file_name = $3.str;
979
       }
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
       | 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);
         }
1006
       ;
unknown's avatar
unknown committed
1007 1008 1009 1010 1011 1012

/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
1013
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
1014 1015
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
1016
	  if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
unknown's avatar
unknown committed
1017
						 TL_OPTION_UPDATING,
unknown's avatar
unknown committed
1018
						 (using_update_log ?
unknown's avatar
unknown committed
1019 1020
						  TL_READ_NO_INSERT:
						  TL_READ)))
unknown's avatar
unknown committed
1021 1022 1023 1024 1025 1026 1027
	    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
1028
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
1029
	  lex->create_info.default_table_charset= NULL;
unknown's avatar
unknown committed
1030
	  lex->name=0;
unknown's avatar
unknown committed
1031 1032
	}
	create2
unknown's avatar
unknown committed
1033
	  { Lex->current_select= &Lex->select_lex; }
unknown's avatar
unknown committed
1034
	| CREATE opt_unique_or_fulltext INDEX_SYM ident key_alg ON table_ident
unknown's avatar
unknown committed
1035
	  {
unknown's avatar
unknown committed
1036 1037
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
unknown's avatar
unknown committed
1038 1039
	    if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1040
	      YYABORT;
unknown's avatar
unknown committed
1041 1042 1043 1044
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
unknown's avatar
unknown committed
1045
	  }
1046
	   '(' key_list ')'
unknown's avatar
unknown committed
1047
	  {
unknown's avatar
unknown committed
1048
	    LEX *lex=Lex;
unknown's avatar
unknown committed
1049

1050
	    lex->key_list.push_back(new Key($2,$4.str, $5, 0, lex->col_list));
unknown's avatar
unknown committed
1051
	    lex->col_list.empty();
unknown's avatar
unknown committed
1052 1053
	  }
	| CREATE DATABASE opt_if_not_exists ident
1054 1055 1056 1057
	  {
             Lex->create_info.default_table_charset= NULL;
             Lex->create_info.used_fields= 0;
          }
1058
	  opt_create_database_options
unknown's avatar
unknown committed
1059
	  {
unknown's avatar
unknown committed
1060 1061 1062 1063
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
unknown's avatar
unknown committed
1064
	  }
unknown's avatar
unknown committed
1065
	| CREATE udf_func_type UDF_SYM IDENT_sys
unknown's avatar
unknown committed
1066
	  {
unknown's avatar
unknown committed
1067 1068
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
1069
	    lex->udf.name = $4;
unknown's avatar
unknown committed
1070
	    lex->udf.type= $2;
unknown's avatar
unknown committed
1071
	  }
unknown's avatar
unknown committed
1072
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
1073
	  {
unknown's avatar
unknown committed
1074 1075 1076
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
1077 1078
	  }
          ;
unknown's avatar
unknown committed
1079 1080

create2:
unknown's avatar
unknown committed
1081 1082 1083 1084 1085 1086
        '(' create2a {}
        | opt_create_table_options create3 {}
        | LIKE table_ident
          {
            LEX *lex=Lex;
            if (!(lex->name= (char *)$2))
unknown's avatar
unknown committed
1087
              YYABORT;
unknown's avatar
unknown committed
1088 1089 1090 1091 1092
          }
        | '(' LIKE table_ident ')'
          {
            LEX *lex=Lex;
            if (!(lex->name= (char *)$3))
1093
              YYABORT;
unknown's avatar
unknown committed
1094
          }
unknown's avatar
unknown committed
1095
        ;
unknown's avatar
unknown committed
1096

unknown's avatar
unknown committed
1097 1098
create2a:
        field_list ')' opt_create_table_options create3 {}
unknown's avatar
unknown committed
1099
	|  create_select ')' { Select->set_braces(1);} union_opt {}
1100
        ;
unknown's avatar
unknown committed
1101 1102

create3:
1103
	/* empty */ {}
unknown's avatar
unknown committed
1104
	| opt_duplicate opt_as     create_select
unknown's avatar
unknown committed
1105
          { Select->set_braces(0);} union_clause {}
unknown's avatar
unknown committed
1106
	| opt_duplicate opt_as '(' create_select ')'
unknown's avatar
unknown committed
1107
          { Select->set_braces(1);} union_opt {}
1108 1109
        ;

unknown's avatar
unknown committed
1110
create_select:
1111
          SELECT_SYM
unknown's avatar
unknown committed
1112
          {
unknown's avatar
unknown committed
1113 1114
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
1115 1116 1117 1118
	    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
1119
	    lex->current_select->table_list.save_and_clear(&lex->save_list);
unknown's avatar
unknown committed
1120
	    mysql_init_select(lex);
1121
	    lex->current_select->parsing_place= SELECT_LIST;
unknown's avatar
unknown committed
1122
          }
unknown's avatar
unknown committed
1123 1124
          select_options select_item_list
	  {
1125
	    Select->parsing_place= NO_MATTER;
unknown's avatar
unknown committed
1126
	  }
unknown's avatar
unknown committed
1127
	  opt_select_from
unknown's avatar
unknown committed
1128
	  { Lex->current_select->table_list.push_front(&Lex->save_list); }
unknown's avatar
unknown committed
1129
        ;
unknown's avatar
unknown committed
1130

1131 1132
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
1133
	| AS	    {};
1134

1135 1136 1137 1138 1139 1140 1141 1142 1143
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
1144 1145
	default_collation   {}
	| default_charset   {};
1146

unknown's avatar
unknown committed
1147
opt_table_options:
unknown's avatar
unknown committed
1148
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
1149
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
1150 1151 1152

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

unknown's avatar
unknown committed
1155
table_option:
unknown's avatar
unknown committed
1156
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
1157 1158

opt_if_not_exists:
unknown's avatar
unknown committed
1159
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
1160
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
1161 1162 1163

opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
1164
	| create_table_options;
unknown's avatar
unknown committed
1165

unknown's avatar
unknown committed
1166 1167 1168 1169
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
1170 1171
create_table_options:
	create_table_option
1172
	| create_table_option     create_table_options
unknown's avatar
unknown committed
1173
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
1174 1175

create_table_option:
unknown's avatar
unknown committed
1176
	ENGINE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; }
1177
	| TYPE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; WARN_DEPRECATED("TYPE=storage_engine","ENGINE=storage_engine"); }
1178 1179 1180
	| 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
1181 1182
	| 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; }
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
	| 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 ')'
1193 1194 1195
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
1196 1197
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
1198 1199
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
1200 1201
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
1202
	    table_list->next=0;
1203
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
1204
	  }
1205 1206
	| default_charset
	| default_collation
1207
	| 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
1208 1209
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
	  { Lex->create_info.data_file_name= $4.str; }
unknown's avatar
unknown committed
1210
	| INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; };
unknown's avatar
unknown committed
1211

1212 1213 1214 1215 1216 1217 1218 1219
default_charset:
        opt_default charset opt_equal charset_name_or_default
        {
          HA_CREATE_INFO *cinfo= &Lex->create_info;
          if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
               cinfo->default_table_charset && $4 &&
               !my_charset_same(cinfo->default_table_charset,$4))
          {
1220 1221 1222
            net_printf(YYTHD, ER_CONFLICTING_DECLARATIONS,
                       "CHARACTER SET ", cinfo->default_table_charset->csname,
                       "CHARACTER SET ", $4->csname);
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
            YYABORT;
          }
	  Lex->create_info.default_table_charset= $4;
          Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
        };

default_collation:
        opt_default COLLATE_SYM opt_equal collation_name_or_default
        {
          HA_CREATE_INFO *cinfo= &Lex->create_info;
          if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
               cinfo->default_table_charset && $4 &&
               !my_charset_same(cinfo->default_table_charset,$4))
            {
              net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
                         $4->name, cinfo->default_table_charset->csname);
              YYABORT;
            }
            Lex->create_info.default_table_charset= $4;
            Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
        };

unknown's avatar
unknown committed
1245
storage_engines:
1246 1247 1248 1249
	ident_or_text
	{
	  $$ = ha_resolve_by_name($1.str,$1.length);
	  if ($$ == DB_TYPE_UNKNOWN) {
unknown's avatar
unknown committed
1250
	    net_printf(YYTHD, ER_UNKNOWN_STORAGE_ENGINE, $1.str);
1251 1252 1253
	    YYABORT;
	  }
	};
unknown's avatar
unknown committed
1254 1255 1256 1257 1258

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
1259
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
1260 1261 1262 1263

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

1266 1267 1268
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
1269
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1270

unknown's avatar
unknown committed
1271
opt_select_from:
1272
	opt_limit_clause {}
unknown's avatar
unknown committed
1273
	| select_from select_lock_type;
unknown's avatar
unknown committed
1274 1275

udf_func_type:
1276
	/* empty */	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
1277
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
1278 1279 1280 1281

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
1282
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
1283 1284 1285

field_list:
	  field_list_item
unknown's avatar
unknown committed
1286
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
1287 1288 1289


field_list_item:
unknown's avatar
unknown committed
1290
	   column_def
1291 1292 1293 1294
         | key_def
         ;

column_def:
unknown's avatar
unknown committed
1295
	  field_spec opt_check_constraint
unknown's avatar
unknown committed
1296 1297 1298 1299
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1300
	;
1301 1302

key_def:
unknown's avatar
unknown committed
1303
	key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1304
	  {
unknown's avatar
unknown committed
1305
	    LEX *lex=Lex;
1306
	    lex->key_list.push_back(new Key($1,$2, $3, 0, lex->col_list));
unknown's avatar
unknown committed
1307
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1308
	  }
1309 1310 1311 1312
	| opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')'
	  {
	    LEX *lex=Lex;
	    const char *key_name= $3 ? $3:$1;
1313 1314
	    lex->key_list.push_back(new Key($2, key_name, $4, 0,
				    lex->col_list));
1315 1316
	    lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
1317
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1318
	  {
1319
	    LEX *lex=Lex;
1320
	    lex->key_list.push_back(new foreign_key($4 ? $4:$1, lex->col_list,
1321 1322 1323 1324 1325
				    $8,
				    lex->ref_list,
				    lex->fk_delete_opt,
				    lex->fk_update_opt,
				    lex->fk_match_option));
1326 1327 1328
	    lex->key_list.push_back(new Key(Key::MULTIPLE, $4 ? $4 : $1,
					    HA_KEY_ALG_UNDEF, 1,
					    lex->col_list));
1329
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1330
	  }
unknown's avatar
unknown committed
1331 1332 1333 1334
	| constraint opt_check_constraint
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
1335
	| opt_constraint check_constraint
unknown's avatar
unknown committed
1336 1337
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1338 1339 1340
	  }
	;

unknown's avatar
unknown committed
1341
opt_check_constraint:
1342
	/* empty */
unknown's avatar
unknown committed
1343 1344 1345 1346 1347
	| check_constraint
	;

check_constraint:
	CHECK_SYM expr
1348
	;
unknown's avatar
unknown committed
1349 1350

opt_constraint:
1351
	/* empty */		{ $$=(char*) 0; }
unknown's avatar
unknown committed
1352 1353 1354 1355 1356 1357
	| constraint		{ $$= $1; }
	;

constraint:
	CONSTRAINT opt_ident	{ $$=$2; }
	;
unknown's avatar
unknown committed
1358 1359 1360 1361

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1362
	   LEX *lex=Lex;
1363
	   lex->length=lex->dec=0; lex->type=0;
1364
	   lex->default_value= lex->on_update_value= 0;
unknown's avatar
unknown committed
1365
	   lex->comment=0;
1366
	   lex->charset=NULL;
unknown's avatar
unknown committed
1367 1368 1369
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1370
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1371
	  if (add_field_to_list(lex->thd, $1.str,
unknown's avatar
unknown committed
1372
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1373
				lex->length,lex->dec,lex->type,
1374 1375
				lex->default_value, lex->on_update_value, 
                                lex->comment,
1376
				lex->change,&lex->interval_list,lex->charset,
unknown's avatar
unknown committed
1377
				lex->uint_geom_type))
unknown's avatar
unknown committed
1378
	    YYABORT;
unknown's avatar
unknown committed
1379
	};
unknown's avatar
unknown committed
1380 1381

type:
1382
	int_type opt_len field_options	{ $$=$1; }
unknown's avatar
unknown committed
1383 1384 1385 1386 1387 1388
	| 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; }
1389 1390
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1391
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1392 1393 1394
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
unknown's avatar
unknown committed
1395
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1396
					  $$=FIELD_TYPE_STRING;
1397
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1398
	| nchar				{ Lex->length=(char*) "1";
unknown's avatar
unknown committed
1399
					  $$=FIELD_TYPE_STRING;
1400
					  Lex->charset=national_charset_info; }
1401
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1402
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1403
					  $$=FIELD_TYPE_STRING; }
1404 1405 1406
	| BINARY			{ Lex->length= (char*) "1";
					  Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_STRING; }
unknown's avatar
unknown committed
1407 1408
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
unknown's avatar
unknown committed
1409 1410
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
1411
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1412
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1413
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1414
					  $$=FIELD_TYPE_VAR_STRING; }
1415
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
unknown's avatar
unknown committed
1416 1417
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1418
	| TIMESTAMP opt_len
1419
	  {
1420
	    if (YYTHD->variables.sql_mode & MODE_MAXDB)
1421 1422
	      $$=FIELD_TYPE_DATETIME;
	    else
1423 1424 1425 1426 1427
            {
              /* 
                Unlike other types TIMESTAMP fields are NOT NULL by default.
              */
              Lex->type|= NOT_NULL_FLAG;
1428
	      $$=FIELD_TYPE_TIMESTAMP;
1429
            }
1430
	   }
unknown's avatar
unknown committed
1431
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
unknown's avatar
unknown committed
1432
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1433
					  $$=FIELD_TYPE_TINY_BLOB; }
unknown's avatar
unknown committed
1434
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1435
					  $$=FIELD_TYPE_BLOB; }
unknown's avatar
unknown committed
1436 1437 1438 1439 1440 1441 1442
	| 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,
unknown's avatar
SCRUM  
unknown committed
1443 1444
			                             sym_group_geom.name,
	                                             sym_group_geom.needed_define);
unknown's avatar
unknown committed
1445 1446 1447
					  YYABORT;
#endif
					}
unknown's avatar
unknown committed
1448
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1449
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1450
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1451
					  $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1452
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1453
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1454 1455
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1456
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1457 1458
	| MEDIUMTEXT opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT opt_binary		{ $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1459 1460 1461 1462
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1463 1464
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1465
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
1466
	  { $$=FIELD_TYPE_ENUM; }
1467
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
1468
	  { $$=FIELD_TYPE_SET; }
1469
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1470 1471 1472 1473 1474 1475
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
1476
	;
unknown's avatar
unknown committed
1477

unknown's avatar
unknown committed
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
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
1489 1490
char:
	CHAR_SYM {}
unknown's avatar
unknown committed
1491 1492 1493 1494 1495 1496
	;

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

unknown's avatar
unknown committed
1498 1499 1500
varchar:
	char VARYING {}
	| VARCHAR {}
unknown's avatar
unknown committed
1501 1502 1503 1504
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
unknown's avatar
unknown committed
1505
	| NVARCHAR_SYM {}
unknown's avatar
unknown committed
1506 1507 1508 1509
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
unknown's avatar
unknown committed
1510 1511 1512 1513 1514 1515

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1516
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1517 1518

real_type:
1519
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1520 1521
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1522
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1523 1524 1525 1526 1527


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1528
	| precision		{};
unknown's avatar
unknown committed
1529 1530 1531 1532 1533 1534

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1535
	};
unknown's avatar
unknown committed
1536 1537 1538

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1539
	| field_opt_list	{};
unknown's avatar
unknown committed
1540 1541 1542

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1543
	| field_option {};
unknown's avatar
unknown committed
1544 1545

field_option:
unknown's avatar
unknown committed
1546
	SIGNED_SYM	{}
1547
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1548
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1549 1550

opt_len:
1551 1552
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1553 1554 1555

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1556
	| precision	{};
unknown's avatar
unknown committed
1557 1558 1559

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

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1564
	| attribute;
unknown's avatar
unknown committed
1565 1566 1567 1568

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
1569 1570 1571
	| DEFAULT now_or_signed_literal { Lex->default_value=$2; }
	| ON UPDATE_SYM NOW_SYM optional_braces 
          { Lex->on_update_value= new Item_func_now_local(); }
unknown's avatar
unknown committed
1572
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1573
	| SERIAL_SYM DEFAULT VALUE_SYM
1574 1575 1576
	  { 
	    LEX *lex=Lex;
	    lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; 
1577
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
1578 1579 1580 1581 1582
	  }
	| opt_primary KEY_SYM 
	  {
	    LEX *lex=Lex;
	    lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; 
1583
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
1584 1585 1586 1587 1588
	  }
	| UNIQUE_SYM	  
	  {
	    LEX *lex=Lex;
	    lex->type|= UNIQUE_FLAG; 
1589
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
1590 1591 1592 1593 1594
	  }
	| UNIQUE_SYM KEY_SYM 
	  {
	    LEX *lex=Lex;
	    lex->type|= UNIQUE_KEY_FLAG; 
1595
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
1596
	  }
unknown's avatar
unknown committed
1597
	| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
1598
	| BINARY { Lex->type|= BINCMP_FLAG; }
unknown's avatar
unknown committed
1599 1600
	| COLLATE_SYM collation_name
	  {
unknown's avatar
unknown committed
1601
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
unknown's avatar
unknown committed
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $2->name,Lex->charset->csname);
	      YYABORT;
	    }
	    else
	    {
	      Lex->charset=$2;
	    }
	  }
	;
unknown's avatar
unknown committed
1613

1614 1615 1616 1617 1618
now_or_signed_literal:
        NOW_SYM optional_braces { $$= new Item_func_now_local(); }
        | signed_literal { $$=$1; }
        ;

1619 1620 1621 1622
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
unknown's avatar
unknown committed
1623

1624
charset_name:
1625
	ident_or_text
1626
	{
unknown's avatar
unknown committed
1627
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
1628
	  {
1629
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1630 1631
	    YYABORT;
	  }
unknown's avatar
unknown committed
1632 1633 1634
	}
	| BINARY { $$= &my_charset_bin; }
	;
1635

1636 1637 1638
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1639

unknown's avatar
unknown committed
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657

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

1658
collation_name:
1659
	ident_or_text
1660 1661 1662
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
1663
	    net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str);
1664 1665 1666 1667
	    YYABORT;
	  }
	};

1668 1669
opt_collate:
	/* empty */	{ $$=NULL; }
unknown's avatar
unknown committed
1670
	| COLLATE_SYM collation_name_or_default { $$=$2; }
1671 1672
	;

1673 1674 1675 1676
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1677 1678 1679 1680
opt_default:
	/* empty */	{}
	| DEFAULT	{};

unknown's avatar
unknown committed
1681
opt_binary:
1682
	/* empty */			{ Lex->charset=NULL; }
unknown's avatar
unknown committed
1683 1684
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
unknown's avatar
unknown committed
1685 1686
	| UNICODE_SYM
	{
1687
	  if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
unknown's avatar
unknown committed
1688 1689 1690 1691 1692
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1693
	| charset charset_name	{ Lex->charset=$2; } ;
unknown's avatar
unknown committed
1694

unknown's avatar
unknown committed
1695 1696 1697
opt_primary:
	/* empty */
	| PRIMARY_SYM
1698
	;
unknown's avatar
unknown committed
1699

unknown's avatar
unknown committed
1700
references:
1701 1702
	REFERENCES table_ident
	{
1703
	  LEX *lex=Lex;
1704 1705 1706 1707 1708 1709
	  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
1710
	};
1711

1712
opt_ref_list:
unknown's avatar
unknown committed
1713
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1714
	| '(' ref_list ')' opt_on_delete {};
1715 1716 1717

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

unknown's avatar
unknown committed
1720 1721 1722

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1723
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1724 1725 1726

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1727
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1728 1729

opt_on_delete_item:
1730 1731 1732 1733
	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
1734
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1735 1736

delete_option:
1737 1738 1739 1740
	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
1741
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1742 1743

key_type:
1744
	key_or_index			    { $$= Key::MULTIPLE; }
unknown's avatar
SCRUM  
unknown committed
1745 1746
	| FULLTEXT_SYM opt_key_or_index	    { $$= Key::FULLTEXT; }
	| SPATIAL_SYM opt_key_or_index
unknown's avatar
unknown committed
1747 1748 1749 1750 1751
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
1752
		       sym_group_geom.name, sym_group_geom.needed_define);
unknown's avatar
unknown committed
1753 1754 1755
	    YYABORT;
#endif
	  };
1756 1757 1758

constraint_key_type:
	PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
unknown's avatar
SCRUM  
unknown committed
1759
	| UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1760 1761 1762

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1763
	| INDEX_SYM {};
unknown's avatar
unknown committed
1764

unknown's avatar
SCRUM  
unknown committed
1765 1766 1767 1768 1769
opt_key_or_index:
	/* empty */ {}
	| key_or_index
	;

unknown's avatar
unknown committed
1770 1771
keys_or_index:
	KEYS {}
unknown's avatar
unknown committed
1772
	| INDEX_SYM {}
unknown's avatar
unknown committed
1773
	| INDEXES {};
unknown's avatar
unknown committed
1774

1775
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1776 1777
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1778
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT;}
unknown's avatar
unknown committed
1779 1780 1781 1782 1783 1784
	| SPATIAL_SYM
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
1785
	               sym_group_geom.name, sym_group_geom.needed_define);
unknown's avatar
unknown committed
1786 1787 1788
	    YYABORT;
#endif
	  }
unknown's avatar
unknown committed
1789
        ;
unknown's avatar
unknown committed
1790 1791

key_alg:
1792
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1793
	| USING opt_btree_or_rtree { $$= $2; }
unknown's avatar
unknown committed
1794
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
unknown's avatar
unknown committed
1795 1796 1797

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
unknown's avatar
unknown committed
1798 1799 1800 1801
	| RTREE_SYM
	  {
	    $$= HA_KEY_ALG_RTREE;
	  }
unknown's avatar
unknown committed
1802
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1803 1804 1805

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1806
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1807 1808 1809

key_part:
	ident			{ $$=new key_part_spec($1.str); }
1810 1811 1812
	| ident '(' NUM ')'	
        {
          int key_part_len= atoi($3.str);
unknown's avatar
unknown committed
1813
#if MYSQL_VERSION_ID < 50000
1814 1815 1816 1817 1818 1819 1820 1821 1822
          if (!key_part_len)
          {
            my_printf_error(ER_UNKNOWN_ERROR,
                            "Key part '%s' length cannot be 0",
                            MYF(0), $1.str);
          }
#endif
          $$=new key_part_spec($1.str,(uint) key_part_len);
        };
unknown's avatar
unknown committed
1823 1824 1825

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

1828 1829 1830
opt_component:
	/* empty */	 { $$.str= 0; $$.length= 0; }
	| '.' ident	 { $$=$2; };
1831

unknown's avatar
unknown committed
1832 1833
string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1834
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1835 1836 1837 1838 1839 1840 1841 1842

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1843
	  THD *thd= YYTHD;
1844
	  LEX *lex= thd->lex;
1845 1846 1847
	  lex->sql_command= SQLCOM_ALTER_TABLE;
	  lex->name= 0;
	  lex->duplicates= DUP_ERROR; 
unknown's avatar
unknown committed
1848 1849
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1850 1851 1852 1853
	    YYABORT;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
1854
          lex->select_lex.init_order();
1855
	  lex->select_lex.db=lex->name=0;
1856
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
unknown's avatar
unknown committed
1857
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1858
	  lex->create_info.default_table_charset= NULL;
1859
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
unknown's avatar
unknown committed
1860
	  lex->alter_info.reset();          
1861 1862
	  lex->alter_info.is_simple= 1;
	  lex->alter_info.flags= 0;
unknown's avatar
unknown committed
1863
	}
1864 1865
	alter_list
	{}
1866
	| ALTER DATABASE ident_or_empty
1867 1868 1869 1870 1871
          {
            Lex->create_info.default_table_charset= NULL;
            Lex->create_info.used_fields= 0;
          }
          opt_create_database_options
1872 1873 1874
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
1875
	    lex->name= $3;
1876
	  };
1877 1878


1879 1880 1881 1882 1883
ident_or_empty:
	/* empty */  { $$= 0; }
	| ident      { $$= $1.str; };


unknown's avatar
unknown committed
1884
alter_list:
1885 1886
	| DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
	| IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
unknown's avatar
unknown committed
1887
        | alter_list_item
unknown's avatar
unknown committed
1888
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1889 1890

add_column:
1891 1892 1893 1894
	ADD opt_column 
	{
	  LEX *lex=Lex;
	  lex->change=0; 
1895
	  lex->alter_info.flags|= ALTER_ADD_COLUMN; 
1896
	};
unknown's avatar
unknown committed
1897 1898

alter_list_item:
1899
	add_column column_def opt_place { Lex->alter_info.is_simple= 0; }
1900 1901 1902
	| ADD key_def 
	  { 
	    LEX *lex=Lex;
1903 1904
	    lex->alter_info.is_simple= 0; 
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
1905
	  }
1906
	| add_column '(' field_list ')'      { Lex->alter_info.is_simple= 0; }
unknown's avatar
unknown committed
1907 1908 1909
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
1910
	     lex->change= $3.str; 
1911 1912
	     lex->alter_info.is_simple= 0;
	     lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
unknown's avatar
unknown committed
1913
	  }
1914
          field_spec opt_place
unknown's avatar
unknown committed
1915 1916 1917
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
1918
            lex->length=lex->dec=0; lex->type=0;
1919
            lex->default_value= lex->on_update_value= 0;
unknown's avatar
unknown committed
1920
	    lex->comment=0;
1921
	    lex->charset= NULL;
1922 1923
            lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
unknown's avatar
unknown committed
1924 1925 1926 1927
          }
          type opt_attribute
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
1928
            if (add_field_to_list(lex->thd,$3.str,
unknown's avatar
unknown committed
1929 1930
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
1931 1932
                                  lex->default_value, lex->on_update_value,
                                  lex->comment,
1933
				  $3.str, &lex->interval_list, lex->charset,
unknown's avatar
unknown committed
1934
				  lex->uint_geom_type))
unknown's avatar
unknown committed
1935 1936 1937
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1938
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1939 1940
	  {
	    LEX *lex=Lex;
1941 1942 1943 1944
	    lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
	    			                               $3.str)); 
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_DROP_COLUMN;
unknown's avatar
unknown committed
1945
	  }
1946
	| DROP FOREIGN KEY_SYM opt_ident { Lex->alter_info.is_simple= 0; }
unknown's avatar
unknown committed
1947 1948 1949
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
1950 1951 1952 1953
	    lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
				               primary_key_name));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_DROP_INDEX;
unknown's avatar
unknown committed
1954
	  }
unknown's avatar
unknown committed
1955
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1956 1957
	  {
	    LEX *lex=Lex;
1958 1959 1960 1961
	    lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
					                       $3.str));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_DROP_INDEX;
unknown's avatar
unknown committed
1962
	  }
1963 1964
	| DISABLE_SYM KEYS { Lex->alter_info.keys_onoff= DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_info.keys_onoff= ENABLE; }
unknown's avatar
unknown committed
1965
	| ALTER opt_column field_ident SET DEFAULT signed_literal
unknown's avatar
unknown committed
1966 1967
	  {
	    LEX *lex=Lex;
1968 1969 1970
	    lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
unknown's avatar
unknown committed
1971
	  }
unknown's avatar
unknown committed
1972
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1973 1974
	  {
	    LEX *lex=Lex;
1975 1976 1977 1978
	    lex->alter_info.alter_list.push_back(new Alter_column($3.str,
                                                                  (Item*) 0));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
unknown's avatar
unknown committed
1979
	  }
1980
	| RENAME opt_to table_ident
1981
	  {
1982
	    LEX *lex=Lex;
1983
	    lex->select_lex.db=$3->db.str;
1984
	    lex->name= $3->table.str;
1985 1986 1987
            if (check_table_name($3->table.str,$3->table.length) ||
                $3->db.str && check_db_name($3->db.str))
            {
unknown's avatar
unknown committed
1988
              net_printf(lex->thd,ER_WRONG_TABLE_NAME,$3->table.str);
1989 1990
              YYABORT;
            }
1991
	    lex->alter_info.flags|= ALTER_RENAME;
1992
	  }
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
	| CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
	  {
	    if (!$4)
	    {
	      THD *thd= YYTHD;
	      $4= thd->variables.collation_database;
	    }
	    $5= $5 ? $5 : $4;
	    if (!my_charset_same($4,$5))
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $5->name,$4->csname);
	      YYABORT;
	    }
2007
	    LEX *lex= Lex;
unknown's avatar
unknown committed
2008 2009 2010 2011
	    lex->create_info.table_charset= 
	      lex->create_info.default_table_charset= $5;
	    lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
					    HA_CREATE_USED_DEFAULT_CHARSET);
2012
	    lex->alter_info.is_simple= 0;
2013
	  }
2014 2015 2016
        | create_table_options_space_separated 
	  {
	    LEX *lex=Lex;
2017 2018
	    lex->alter_info.is_simple= 0; 
	    lex->alter_info.flags|= ALTER_OPTIONS;
2019 2020 2021 2022
	  }
	| order_clause         
	  {
	    LEX *lex=Lex;
2023 2024
	    lex->alter_info.is_simple= 0; 
	    lex->alter_info.flags|= ALTER_ORDER;
2025
	  };
unknown's avatar
unknown committed
2026 2027 2028

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
2029
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
2030 2031

opt_ignore:
2032 2033 2034
	/* empty */	{ Lex->ignore= 0;}
	| IGNORE_SYM	{ Lex->ignore= 1;}
	;
unknown's avatar
unknown committed
2035 2036 2037 2038

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
2039
	| CASCADE	{};
unknown's avatar
unknown committed
2040 2041 2042 2043

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
2044
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
2045 2046 2047 2048

opt_to:
	/* empty */	{}
	| TO_SYM	{}
2049
	| EQ		{}
unknown's avatar
unknown committed
2050
	| AS		{};
unknown's avatar
unknown committed
2051

unknown's avatar
unknown committed
2052
/*
2053
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
unknown's avatar
unknown committed
2054 2055
*/

unknown's avatar
unknown committed
2056
slave:
2057 2058 2059 2060 2061 2062 2063
	  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
2064
            /* If you change this code don't forget to update SLAVE START too */
2065 2066 2067
          }
          slave_until
          {}
unknown's avatar
unknown committed
2068 2069 2070 2071 2072
        | STOP_SYM SLAVE slave_thread_opts
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_STOP;
	    lex->type = 0;
unknown's avatar
unknown committed
2073
            /* If you change this code don't forget to update SLAVE STOP too */
unknown's avatar
unknown committed
2074
          }
2075 2076 2077 2078 2079
	| SLAVE START_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
2080 2081 2082 2083 2084
	    /* We'll use mi structure for UNTIL options */
	    bzero((char*) &lex->mi, sizeof(lex->mi));
          }
          slave_until
          {}
2085 2086 2087 2088 2089 2090 2091 2092
	| SLAVE STOP_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_STOP;
	   lex->type = 0;
         }
        ;

unknown's avatar
unknown committed
2093

unknown's avatar
unknown committed
2094
start:
2095 2096 2097 2098 2099
	START_SYM TRANSACTION_SYM start_transaction_opts
        {
           Lex->sql_command = SQLCOM_BEGIN;
           Lex->start_transaction_opt= $3;
        }
unknown's avatar
unknown committed
2100 2101
	;

2102 2103 2104 2105 2106 2107
start_transaction_opts:
        /*empty*/ { $$ = 0; }
        | WITH CONSISTENT_SYM SNAPSHOT_SYM
        {
           $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
        }
2108
        ;
2109

unknown's avatar
unknown committed
2110
slave_thread_opts:
2111 2112
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
2113
        {}
unknown's avatar
unknown committed
2114
	;
2115 2116

slave_thread_opt_list:
unknown's avatar
unknown committed
2117
	slave_thread_opt
2118 2119
	| slave_thread_opt_list ',' slave_thread_opt
	;
2120 2121

slave_thread_opt:
2122
	/*empty*/	{}
unknown's avatar
unknown committed
2123
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
unknown's avatar
unknown committed
2124
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
unknown's avatar
unknown committed
2125
	;
2126

2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148
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
2149 2150 2151 2152 2153
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
unknown's avatar
unknown committed
2154
	table_list FROM TEXT_STRING_sys
unknown's avatar
unknown committed
2155 2156
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
2157
        };
unknown's avatar
unknown committed
2158

unknown's avatar
unknown committed
2159 2160 2161 2162 2163
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
unknown's avatar
unknown committed
2164
	table_list TO_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
2165 2166
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
2167
        };
unknown's avatar
unknown committed
2168

2169 2170 2171 2172 2173 2174
checksum:
        CHECKSUM_SYM table_or_tables
	{
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECKSUM;
	}
2175 2176
	table_list opt_checksum_type
        {}
2177 2178
	;

2179 2180 2181 2182 2183 2184
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
2185
repair:
2186
	REPAIR opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
2187
	{
unknown's avatar
unknown committed
2188 2189
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
2190
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
2191
	   lex->check_opt.init();
unknown's avatar
unknown committed
2192
	}
2193 2194 2195
	table_list opt_mi_repair_type
	{}
	;
unknown's avatar
unknown committed
2196

unknown's avatar
unknown committed
2197
opt_mi_repair_type:
unknown's avatar
unknown committed
2198
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
2199
	| mi_repair_types {};
unknown's avatar
unknown committed
2200

unknown's avatar
unknown committed
2201 2202
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
2203
	| mi_repair_type mi_repair_types {};
2204

unknown's avatar
unknown committed
2205
mi_repair_type:
unknown's avatar
unknown committed
2206
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
2207
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
2208
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
2209 2210

analyze:
2211
	ANALYZE_SYM opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
2212
	{
unknown's avatar
unknown committed
2213 2214
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
2215
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
2216
	   lex->check_opt.init();
unknown's avatar
unknown committed
2217
	}
2218 2219 2220
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
2221 2222

check:
unknown's avatar
unknown committed
2223
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
2224
	{
unknown's avatar
unknown committed
2225 2226 2227
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
2228
	}
2229 2230 2231
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
2232

unknown's avatar
unknown committed
2233 2234
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
2235
	| mi_check_types {};
unknown's avatar
unknown committed
2236 2237 2238

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
2239
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
2240 2241 2242 2243 2244 2245

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

unknown's avatar
unknown committed
2248
optimize:
2249
	OPTIMIZE opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
2250
	{
unknown's avatar
unknown committed
2251 2252
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
unknown's avatar
unknown committed
2253
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
2254
	   lex->check_opt.init();
unknown's avatar
unknown committed
2255
	}
2256 2257 2258
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
2259

2260 2261 2262
opt_no_write_to_binlog:
	/* empty */        { $$= 0; }
	| NO_WRITE_TO_BINLOG  { $$= 1; }
2263
	| LOCAL_SYM  { $$= 1; }
2264 2265
	;

2266 2267 2268 2269 2270
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
2271 2272 2273
	table_to_table_list
	{}
	;
2274 2275 2276

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
2277
	| table_to_table_list ',' table_to_table;
2278 2279 2280

table_to_table:
	table_ident TO_SYM table_ident
2281
	{
unknown's avatar
unknown committed
2282
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2283
	  SELECT_LEX *sl= lex->current_select;
unknown's avatar
unknown committed
2284 2285 2286 2287
	  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))
2288
	    YYABORT;
2289
	};
2290

unknown's avatar
unknown committed
2291
keycache:
unknown's avatar
unknown committed
2292
        CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
unknown's avatar
unknown committed
2293 2294
        {
          LEX *lex=Lex;
2295 2296
          lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
	  lex->name_and_length= $5;
unknown's avatar
unknown committed
2297 2298 2299 2300 2301 2302 2303 2304
        }
        ;

keycache_list:
        assign_to_keycache
        | keycache_list ',' assign_to_keycache;

assign_to_keycache:
2305
        table_ident cache_keys_spec
unknown's avatar
unknown committed
2306 2307 2308 2309 2310 2311
        {
          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(),
2312
                                      (List<String> *)0))
unknown's avatar
unknown committed
2313 2314 2315 2316
            YYABORT;
        }
        ;

2317 2318 2319
key_cache_name:
	ident	   { $$= $1; }
	| DEFAULT  { $$ = default_key_cache_base; }
2320
	;
2321

unknown's avatar
unknown committed
2322
preload:
unknown's avatar
unknown committed
2323
	LOAD INDEX_SYM INTO CACHE_SYM
unknown's avatar
unknown committed
2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
	{
	  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
2337
	table_ident cache_keys_spec opt_ignore_leaves
unknown's avatar
unknown committed
2338 2339 2340
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
unknown's avatar
unknown committed
2341 2342
	  if (!sel->add_table_to_list(lex->thd, $1, NULL, $3,
                                      TL_READ,
unknown's avatar
unknown committed
2343 2344 2345 2346 2347 2348
                                      sel->get_use_index(),
                                      (List<String> *)0))
            YYABORT;
	}
	;

2349
cache_keys_spec:
2350
        { Select->interval_list.empty(); }
2351 2352 2353 2354 2355 2356 2357
        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
2358

unknown's avatar
unknown committed
2359
cache_key_list_or_empty:
2360
	/* empty */	{ Lex->select_lex.use_index_ptr= 0; }
2361
	| opt_key_or_index '(' key_usage_list2 ')'
2362 2363 2364 2365
	  {
            SELECT_LEX *sel= &Lex->select_lex;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2366 2367
	;

unknown's avatar
unknown committed
2368
opt_ignore_leaves:
unknown's avatar
unknown committed
2369 2370 2371 2372 2373
	/* empty */
	{ $$= 0; }
	| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
	;

unknown's avatar
unknown committed
2374
/*
unknown's avatar
unknown committed
2375
  Select : retrieve data from table
unknown's avatar
unknown committed
2376 2377 2378 2379
*/


select:
2380 2381 2382 2383 2384
	select_init
	{
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_SELECT;
	  lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
unknown's avatar
unknown committed
2385 2386
	}
	;
unknown's avatar
unknown committed
2387

2388
/* Need select_init2 for subselects. */
unknown's avatar
unknown committed
2389
select_init:
2390
	SELECT_SYM select_init2
2391
	|
2392 2393
	'(' SELECT_SYM select_part2 ')'
	  {
2394
	    LEX *lex= Lex;
unknown's avatar
unknown committed
2395
            SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2396
	    if (sel->set_braces(1))
2397
	    {
2398
	      yyerror(ER(ER_SYNTAX_ERROR));
2399 2400
	      YYABORT;
	    }
2401 2402
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
2403
	  {
2404
	    yyerror(ER(ER_SYNTAX_ERROR));
unknown's avatar
unknown committed
2405 2406
	    YYABORT;
	  }
2407
            /* select in braces, can't contain global parameters */
unknown's avatar
unknown committed
2408 2409 2410
	    if (sel->master_unit()->fake_select_lex)
              sel->master_unit()->global_parameters=
                 sel->master_unit()->fake_select_lex;
unknown's avatar
unknown committed
2411
          } union_opt;
2412

2413 2414
select_init2:
	select_part2
2415
        {
2416
	  LEX *lex= Lex;
unknown's avatar
unknown committed
2417
          SELECT_LEX * sel= lex->current_select;
unknown's avatar
unknown committed
2418
          if (lex->current_select->set_braces(0))
2419
	  {
2420
	    yyerror(ER(ER_SYNTAX_ERROR));
2421 2422
	    YYABORT;
	  }
2423 2424
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
2425
	  {
2426
	    yyerror(ER(ER_SYNTAX_ERROR));
unknown's avatar
unknown committed
2427 2428
	    YYABORT;
	  }
2429
	}
2430
	union_clause
2431 2432
	;

2433
select_part2:
unknown's avatar
unknown committed
2434
	{
unknown's avatar
unknown committed
2435 2436 2437
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
	  lex->lock_option= TL_READ;
unknown's avatar
unknown committed
2438 2439
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
2440
	  lex->current_select->parsing_place= SELECT_LIST;
unknown's avatar
unknown committed
2441 2442 2443
	}
	select_options select_item_list
	{
2444
	  Select->parsing_place= NO_MATTER;
unknown's avatar
unknown committed
2445
	}
unknown's avatar
unknown committed
2446
	select_into select_lock_type;
2447

unknown's avatar
unknown committed
2448
select_into:
2449 2450
	opt_limit_clause {}
        | into
unknown's avatar
unknown committed
2451
	| select_from
2452 2453
	| into select_from
	| select_from into;
unknown's avatar
unknown committed
2454 2455

select_from:
2456 2457 2458 2459 2460 2461 2462
	  FROM join_table_list where_clause group_clause having_clause
	       opt_order_clause opt_limit_clause procedure_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 :) */
	;
unknown's avatar
unknown committed
2463 2464 2465

select_options:
	/* empty*/
unknown's avatar
unknown committed
2466
	| select_option_list;
unknown's avatar
unknown committed
2467 2468 2469

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
2470
	| select_option;
unknown's avatar
unknown committed
2471 2472

select_option:
2473
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
2474 2475 2476 2477 2478 2479
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
2480 2481 2482
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494
	| 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;
	  }
2495
	| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
2496 2497 2498 2499
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
2500 2501
	| ALL		{}
	;
unknown's avatar
unknown committed
2502

unknown's avatar
unknown committed
2503 2504 2505
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
2506 2507
	  {
	    LEX *lex=Lex;
2508
	    lex->current_select->set_lock_for_tables(TL_WRITE);
2509
	    lex->safe_to_cache_query=0;
2510
	  }
unknown's avatar
unknown committed
2511
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2512 2513
	  {
	    LEX *lex=Lex;
2514 2515
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2516
	    lex->safe_to_cache_query=0;
2517 2518
	  }
	;
unknown's avatar
unknown committed
2519

unknown's avatar
unknown committed
2520 2521 2522 2523 2524
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
2525 2526
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
unknown's avatar
unknown committed
2527
	      YYABORT;
2528
	    (thd->lex->current_select->with_wild)++;
unknown's avatar
unknown committed
2529
	  };
unknown's avatar
unknown committed
2530 2531 2532 2533 2534


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
unknown's avatar
unknown committed
2535
	    if (add_item_to_list(YYTHD, $2))
unknown's avatar
unknown committed
2536 2537
	      YYABORT;
	    if ($4.str)
unknown's avatar
unknown committed
2538
	      $2->set_name($4.str,$4.length,system_charset_info);
unknown's avatar
unknown committed
2539
	    else if (!$2->name)
unknown's avatar
unknown committed
2540
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
unknown's avatar
unknown committed
2541
	  };
unknown's avatar
unknown committed
2542 2543

remember_name:
unknown's avatar
unknown committed
2544
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
2545 2546

remember_end:
unknown's avatar
unknown committed
2547
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
2548 2549 2550

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
2551
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
2552 2553

select_alias:
unknown's avatar
unknown committed
2554 2555 2556 2557 2558 2559
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
unknown's avatar
unknown committed
2560 2561 2562

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

unknown's avatar
unknown committed
2565
/* all possible expressions */
unknown's avatar
SCRUM  
unknown committed
2566 2567 2568 2569
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
unknown's avatar
unknown committed
2570

unknown's avatar
unknown committed
2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582
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
2583 2584
/* expressions that begin with 'expr' */
expr_expr:
unknown's avatar
SCRUM  
unknown committed
2585
	 expr IN_SYM '(' expr_list ')'
2586
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
unknown's avatar
unknown committed
2587
	| expr NOT IN_SYM '(' expr_list ')'
2588
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
unknown's avatar
unknown committed
2589
        | expr IN_SYM in_subselect
2590
          { $$= new Item_in_subselect($1, $3); }
unknown's avatar
unknown committed
2591
	| expr NOT IN_SYM in_subselect
2592
          {
2593
            $$= new Item_func_not(new Item_in_subselect($1, $4));
unknown's avatar
unknown committed
2594
          }
unknown's avatar
unknown committed
2595
	| expr BETWEEN_SYM no_and_expr AND_SYM expr
unknown's avatar
unknown committed
2596
	  { $$= new Item_func_between($1,$3,$5); }
unknown's avatar
unknown committed
2597
	| expr NOT BETWEEN_SYM no_and_expr AND_SYM expr
unknown's avatar
unknown committed
2598
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2599
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2600
	| expr OR_SYM expr	{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2601
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2602
	| expr AND_SYM expr	{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2603 2604 2605 2606 2607 2608 2609 2610 2611
	| 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
2612
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2613 2614
	| expr NOT REGEXP expr
          { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2615 2616 2617
	| 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
2618
	| expr comp_op expr %prec EQ	{ $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2619 2620
	| expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2621
	  $$= all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2622
	}
unknown's avatar
unknown committed
2623 2624 2625 2626 2627 2628
	| 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); }
2629 2630
	| 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
2631
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2632
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2633 2634
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2635 2636 2637 2638
	| 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
2639
	;
unknown's avatar
unknown committed
2640 2641 2642

/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
unknown's avatar
unknown committed
2643
	no_in_expr BETWEEN_SYM no_and_expr AND_SYM expr
unknown's avatar
unknown committed
2644
	  { $$= new Item_func_between($1,$3,$5); }
unknown's avatar
unknown committed
2645
	| no_in_expr NOT BETWEEN_SYM no_and_expr AND_SYM expr
unknown's avatar
unknown committed
2646
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2647
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2648
	| no_in_expr OR_SYM expr	{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2649
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2650
	| no_in_expr AND_SYM expr	{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2651 2652 2653 2654 2655 2656 2657 2658 2659
	| 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
2660
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2661 2662
	| no_in_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2663 2664 2665
	| 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
2666
	| no_in_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2667 2668
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2669
	  all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2670
	}
unknown's avatar
unknown committed
2671 2672 2673 2674 2675 2676
	| 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); }
2677
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2678
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2679
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2680 2681
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2682
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2683 2684 2685 2686
	| 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
2687
	| simple_expr;
unknown's avatar
unknown committed
2688 2689 2690

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
unknown's avatar
unknown committed
2691
	  no_and_expr IN_SYM '(' expr_list ')'
2692
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
unknown's avatar
unknown committed
2693
	| no_and_expr NOT IN_SYM '(' expr_list ')'
2694
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
unknown's avatar
unknown committed
2695
        | no_and_expr IN_SYM in_subselect
2696
          { $$= new Item_in_subselect($1, $3); }
unknown's avatar
unknown committed
2697
	| no_and_expr NOT IN_SYM in_subselect
2698
          {
2699
            $$= new Item_func_not(new Item_in_subselect($1, $4));
unknown's avatar
unknown committed
2700
          }
unknown's avatar
unknown committed
2701
	| no_and_expr BETWEEN_SYM no_and_expr AND_SYM expr
unknown's avatar
unknown committed
2702
	  { $$= new Item_func_between($1,$3,$5); }
unknown's avatar
unknown committed
2703
	| no_and_expr NOT BETWEEN_SYM no_and_expr AND_SYM expr
unknown's avatar
unknown committed
2704
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2705
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2706
	| no_and_expr OR_SYM expr	{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2707
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2708 2709 2710 2711 2712 2713 2714 2715 2716
	| 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
2717
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
unknown's avatar
unknown committed
2718 2719
	| no_and_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
unknown's avatar
unknown committed
2720 2721 2722
	| 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
2723
	| no_and_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
unknown's avatar
unknown committed
2724 2725
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
unknown's avatar
unknown committed
2726
	  all_any_subquery_creator($1, $2, $3, $4);
unknown's avatar
unknown committed
2727
	}
unknown's avatar
unknown committed
2728 2729 2730 2731 2732 2733
	| 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); }
2734
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2735
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2736
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2737 2738
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2739
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2740 2741 2742 2743
	| 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
2744
	| simple_expr;
unknown's avatar
unknown committed
2745

2746
interval_expr:
unknown's avatar
unknown committed
2747
         INTERVAL_SYM expr { $$=$2; }
2748 2749
        ;

unknown's avatar
unknown committed
2750 2751
simple_expr:
	simple_ident
2752
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
unknown's avatar
unknown committed
2753
	  {
unknown's avatar
unknown committed
2754 2755 2756
	    $$= new Item_func_set_collation($1,
					    new Item_string($3.str,
							    $3.length,
2757
                                                            YYTHD->charset()));
2758
	  }
unknown's avatar
unknown committed
2759
	| literal
unknown's avatar
unknown committed
2760
	| param_marker
unknown's avatar
unknown committed
2761
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
2762 2763
	  {
	    $$= new Item_func_set_user_var($2,$4);
2764
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2765
	  }
2766
	| '@' ident_or_text
unknown's avatar
unknown committed
2767 2768
	  {
	    $$= new Item_func_get_user_var($2);
2769
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2770
	  }
2771
	| '@' '@' opt_var_ident_type ident_or_text opt_component
unknown's avatar
unknown committed
2772
	  {
2773 2774 2775 2776 2777 2778

            if ($4.str && $5.str && check_reserved_words(&$4))
            {
              yyerror(ER(ER_SYNTAX_ERROR));
              YYABORT;
            }
2779
	    if (!($$= get_system_var(YYTHD, (enum_var_type) $3, $4, $5)))
unknown's avatar
unknown committed
2780
	      YYABORT;
unknown's avatar
unknown committed
2781
	  }
unknown's avatar
unknown committed
2782
	| sum_expr
2783 2784
	| '+' expr %prec NEG	{ $$= $2; }
	| '-' expr %prec NEG    { $$= new Item_func_neg($2); }
unknown's avatar
unknown committed
2785
	| '~' expr %prec NEG	{ $$= new Item_func_bit_neg($2); }
2786 2787
	| NOT expr %prec NEG
          {
unknown's avatar
unknown committed
2788
            $$= negate_expression(YYTHD, $2);
2789 2790 2791
          }
	| '!' expr %prec NEG
          {
unknown's avatar
unknown committed
2792
            $$= negate_expression(YYTHD, $2);
2793
          }
unknown's avatar
unknown committed
2794
	| '(' expr ')'		{ $$= $2; }
2795 2796 2797 2798 2799
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
2800
	| ROW_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2801
	  {
2802 2803
	    $5->push_front($3);
	    $$= new Item_row(*$5);
unknown's avatar
unknown committed
2804
	  }
unknown's avatar
unknown committed
2805
	| EXISTS exists_subselect { $$= $2; }
unknown's avatar
unknown committed
2806
	| singlerow_subselect   { $$= $1; }
unknown's avatar
unknown committed
2807
	| '{' ident expr '}'	{ $$= $3; }
2808
        | MATCH ident_list_arg AGAINST '(' expr fulltext_options ')'
2809
          { $2->push_front($5);
2810 2811
            Select->add_ftfunc_to_list((Item_func_match*)
                                        ($$=new Item_func_match(*$2,$6))); }
unknown's avatar
unknown committed
2812
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
unknown's avatar
unknown committed
2813
	| BINARY expr %prec NEG
unknown's avatar
unknown committed
2814
	  {
2815
	    $$= create_func_cast($2, ITEM_CAST_CHAR, -1, &my_charset_bin);
unknown's avatar
unknown committed
2816
	  }
2817
	| CAST_SYM '(' expr AS cast_type ')'
2818 2819
	  {
	    $$= create_func_cast($3, $5,
2820
				 Lex->length ? atoi(Lex->length) : -1,
2821
				 Lex->charset);
2822
	  }
unknown's avatar
unknown committed
2823
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
2824
	  { $$= new Item_func_case(* $4, $2, $5 ); }
2825
	| CONVERT_SYM '(' expr ',' cast_type ')'
2826 2827 2828 2829 2830
	  {
	    $$= create_func_cast($3, $5,
				 Lex->length ? atoi(Lex->length) : -1,
				 Lex->charset);
	  }
2831 2832
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
unknown's avatar
SCRUM  
unknown committed
2833 2834
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
unknown's avatar
unknown committed
2835 2836
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
unknown's avatar
unknown committed
2837
	| FUNC_ARG0 '(' ')'
unknown's avatar
unknown committed
2838 2839 2840 2841
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
2842
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2843 2844 2845 2846 2847
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(void))($1.symbol->create_func))();
	  }
unknown's avatar
unknown committed
2848
	| FUNC_ARG1 '(' expr ')'
unknown's avatar
unknown committed
2849 2850 2851 2852
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
2853
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2854 2855 2856 2857 2858
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
	  }
unknown's avatar
unknown committed
2859
	| FUNC_ARG2 '(' expr ',' expr ')'
unknown's avatar
unknown committed
2860 2861 2862 2863
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
2864
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2865 2866 2867 2868 2869
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
	  }
unknown's avatar
unknown committed
2870
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
unknown's avatar
unknown committed
2871 2872 2873 2874
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
2875
			 $1.symbol->group->name,
unknown's avatar
unknown committed
2876 2877 2878 2879 2880
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
	  }
unknown's avatar
unknown committed
2881 2882 2883 2884
	| 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
2885 2886 2887 2888 2889 2890
	| 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
2891 2892
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
2893 2894
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
unknown's avatar
unknown committed
2895 2896
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
unknown's avatar
unknown committed
2897 2898 2899
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
2900
	  { $5->push_front($3); $$= new Item_func_concat_ws(*$5); }
2901 2902 2903 2904 2905
	| CONVERT_TZ_SYM '(' expr ',' expr ',' expr ')'
	  {
	    Lex->time_zone_tables_used= &fake_time_zone_tables_list;
	    $$= new Item_func_convert_tz($3, $5, $7);
	  }
unknown's avatar
unknown committed
2906
	| CURDATE optional_braces
2907
	  { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2908
	| CURTIME optional_braces
2909
	  { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2910
	| CURTIME '(' expr ')'
2911
	  {
2912
	    $$= new Item_func_curtime_local($3);
2913
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2914
	  }
unknown's avatar
unknown committed
2915
	| CURRENT_USER optional_braces
2916
          { $$= create_func_current_user(); }
2917 2918 2919 2920
	| 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
2921
	| DATABASE '(' ')'
2922
	  {
unknown's avatar
unknown committed
2923
	    $$= new Item_func_database();
2924
            Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2925
	  }
unknown's avatar
unknown committed
2926
	| DATE_SYM '(' expr ')'
unknown's avatar
unknown committed
2927
	  { $$= new Item_date_typecast($3); }
unknown's avatar
unknown committed
2928 2929
	| DAY_SYM '(' expr ')'
	  { $$= new Item_func_dayofmonth($3); }
unknown's avatar
unknown committed
2930
	| ELT_FUNC '(' expr ',' expr_list ')'
2931
	  { $5->push_front($3); $$= new Item_func_elt(*$5); }
unknown's avatar
unknown committed
2932 2933
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
unknown's avatar
unknown committed
2934 2935 2936
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
2937
	    Lex->uncacheable(UNCACHEABLE_RAND);
unknown's avatar
unknown committed
2938
	  }
unknown's avatar
unknown committed
2939
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
2940
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2941
	  { $$= new Item_func_decode($3,$5.str); }
2942
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2943
	 { $$= new Item_func_encode($3,$5.str); }
unknown's avatar
unknown committed
2944
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2945
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
2946
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2947
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
2948
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2949
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
2950
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2951
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
2952 2953 2954 2955 2956 2957
	| 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); }
2958 2959
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
2960 2961 2962 2963 2964 2965
	| 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
2966
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2967 2968
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
2969
	  { $5->push_front($3); $$= new Item_func_field(*$5); }
unknown's avatar
unknown committed
2970 2971 2972 2973 2974 2975
	| geometry_function
	  {
#ifdef HAVE_SPATIAL
	    $$= $1;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
unknown's avatar
SCRUM  
unknown committed
2976
	               sym_group_geom.name, sym_group_geom.needed_define);
unknown's avatar
unknown committed
2977 2978 2979
	    YYABORT;
#endif
	  }
2980
	| GET_FORMAT '(' date_time_type  ',' expr ')'
2981
	  { $$= new Item_func_get_format($3, $5); }
unknown's avatar
unknown committed
2982 2983 2984 2985 2986 2987
	| 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); }
2988
	| interval_expr interval '+' expr
unknown's avatar
unknown committed
2989
	  /* we cannot put interval before - */
2990 2991 2992 2993 2994
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
2995
              yyerror(ER(ER_SYNTAX_ERROR));
2996 2997 2998 2999
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
unknown's avatar
unknown committed
3000 3001
	| LAST_INSERT_ID '(' ')'
	  {
3002
	    $$= new Item_func_last_insert_id();
3003
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
3004 3005 3006
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
3007
	    $$= new Item_func_last_insert_id($3);
3008
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
3009 3010 3011 3012 3013 3014 3015
	  }
	| 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
3016
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
3017 3018 3019
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
3020
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
3021
	  { $$= new Item_func_log($3); }
3022
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
3023
	  { $$= new Item_func_log($3, $5); }
3024
	| MASTER_POS_WAIT '(' expr ',' expr ')'
unknown's avatar
unknown committed
3025
	  {
3026
	    $$= new Item_master_pos_wait($3, $5);
unknown's avatar
unknown committed
3027
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
3028
		  }
3029
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
unknown's avatar
unknown committed
3030
	  {
3031
	    $$= new Item_master_pos_wait($3, $5, $7);
unknown's avatar
unknown committed
3032
	    Lex->safe_to_cache_query=0;
3033
	  }
unknown's avatar
unknown committed
3034 3035
	| MICROSECOND_SYM '(' expr ')'
	  { $$= new Item_func_microsecond($3); }
unknown's avatar
unknown committed
3036 3037
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
3038 3039
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
3040 3041 3042
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
	| NOW_SYM optional_braces
3043
	  { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
3044
	| NOW_SYM '(' expr ')'
3045
	  { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
3046
	| PASSWORD '(' expr ')'
3047
	  {
3048 3049
	    $$= YYTHD->variables.old_passwords ?
              (Item *) new Item_func_old_password($3) :
unknown's avatar
unknown committed
3050 3051 3052 3053
	      (Item *) new Item_func_password($3);
	  }
	| OLD_PASSWORD '(' expr ')'
	  { $$=  new Item_func_old_password($3); }
unknown's avatar
unknown committed
3054 3055
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
3056
	| RAND '(' expr ')'
3057
	  { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
unknown's avatar
unknown committed
3058
	| RAND '(' ')'
3059
	  { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
unknown's avatar
unknown committed
3060 3061 3062 3063 3064 3065 3066
	| 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
3067 3068 3069 3070
	| 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
3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082
	| 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
3083
	| TIME_SYM '(' expr ')'
unknown's avatar
unknown committed
3084 3085 3086
	  { $$= new Item_time_typecast($3); }
	| TIMESTAMP '(' expr ')'
	  { $$= new Item_datetime_typecast($3); }
unknown's avatar
unknown committed
3087
	| TIMESTAMP '(' expr ',' expr ')'
unknown's avatar
unknown committed
3088
	  { $$= new Item_func_add_time($3, $5, 1, 0); }
unknown's avatar
unknown committed
3089
	| TRIM '(' expr ')'
3090 3091
	  { $$= new Item_func_trim($3); }
	| TRIM '(' LEADING expr FROM expr ')'
unknown's avatar
unknown committed
3092
	  { $$= new Item_func_ltrim($6,$4); }
3093
	| TRIM '(' TRAILING expr FROM expr ')'
unknown's avatar
unknown committed
3094
	  { $$= new Item_func_rtrim($6,$4); }
3095
	| TRIM '(' BOTH expr FROM expr ')'
unknown's avatar
unknown committed
3096
	  { $$= new Item_func_trim($6,$4); }
3097 3098 3099 3100 3101 3102
	| 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
3103 3104
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
3105 3106
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
3107 3108
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151
	| 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 ')'
3152
	  {
unknown's avatar
unknown committed
3153 3154
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
3155
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
3156 3157
	  {
	    $$= new Item_func_unix_timestamp();
3158
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
3159
	  }
unknown's avatar
unknown committed
3160 3161 3162
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
3163
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
3164 3165 3166 3167 3168 3169
	| 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
3170
	| WEEK_SYM '(' expr ')'
unknown's avatar
unknown committed
3171
	  {
3172
            $$= new Item_func_week($3,new Item_int((char*) "0",
unknown's avatar
unknown committed
3173
				   YYTHD->variables.default_week_format,1));
3174
          }
unknown's avatar
unknown committed
3175 3176 3177 3178 3179 3180 3181 3182 3183
	| 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 ')'
3184
	  {
unknown's avatar
unknown committed
3185
	    $$=new Item_func_benchmark($3,$5);
3186
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3187
	  }
unknown's avatar
unknown committed
3188
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
3189
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
3190

unknown's avatar
unknown committed
3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201
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,
3202 3203
                           Geometry::wkb_geometrycollection,
                           Geometry::wkb_point)); }
unknown's avatar
unknown committed
3204 3205
	| LINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
3206
                  Geometry::wkb_linestring, Geometry::wkb_point)); }
unknown's avatar
unknown committed
3207 3208
 	| MULTILINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW( Item_func_spatial_collection(* $3,
3209
                   Geometry::wkb_multilinestring, Geometry::wkb_linestring)); }
unknown's avatar
unknown committed
3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223
 	| 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,
3224
                  Geometry::wkb_multipoint, Geometry::wkb_point)); }
unknown's avatar
unknown committed
3225 3226
 	| MULTIPOLYGON '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
3227
                  Geometry::wkb_multipolygon, Geometry::wkb_polygon)); }
unknown's avatar
unknown committed
3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239
	| 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,
3240
	          Geometry::wkb_polygon, Geometry::wkb_linestring)); }
unknown's avatar
unknown committed
3241 3242 3243 3244 3245 3246 3247 3248 3249 3250
 	| 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)); }
	;

3251 3252 3253 3254 3255 3256
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
3257 3258
udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
3259
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
3260 3261 3262 3263 3264 3265 3266 3267

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); }
3268 3269
	| BIT_XOR  '(' in_sum_expr ')'
	  { $$=new Item_sum_xor($3); }
unknown's avatar
unknown committed
3270
	| COUNT_SYM '(' opt_all '*' ')'
unknown's avatar
unknown committed
3271 3272 3273
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
3274
	| COUNT_SYM '(' DISTINCT
unknown's avatar
unknown committed
3275
	  { Select->in_sum_expr++; }
3276
	   expr_list
unknown's avatar
unknown committed
3277
	  { Select->in_sum_expr--; }
3278 3279
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
unknown's avatar
unknown committed
3280 3281 3282 3283 3284 3285 3286 3287
	| 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
3288 3289
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
unknown's avatar
unknown committed
3290
	| SUM_SYM '(' in_sum_expr ')'
3291
	  { $$=new Item_sum_sum($3); }
unknown's avatar
unknown committed
3292 3293 3294 3295 3296
	| GROUP_CONCAT_SYM '(' opt_distinct
	  { Select->in_sum_expr++; }
	  expr_list opt_gorder_clause
	  opt_gconcat_separator
	 ')'
unknown's avatar
unknown committed
3297
	  {
unknown's avatar
unknown committed
3298 3299 3300
	    Select->in_sum_expr--;
	    $$=new Item_func_group_concat($3,$5,Select->gorder_list,$7);
	    $5->empty();
3301 3302 3303 3304 3305 3306 3307
	  };

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

opt_gconcat_separator:
unknown's avatar
unknown committed
3308
    /* empty */        { $$ = new (YYTHD->mem_root) String(",",1,default_charset_info); }
3309
    |SEPARATOR_SYM text_string  { $$ = $2; };
unknown's avatar
unknown committed
3310

3311 3312

opt_gorder_clause:
3313 3314
	  /* empty */
	  {
unknown's avatar
unknown committed
3315
            Select->gorder_list = NULL;
3316 3317 3318
	  }
	| order_clause
          {
unknown's avatar
unknown committed
3319 3320 3321
            SELECT_LEX *select= Select;
            select->gorder_list=
	      (SQL_LIST*) sql_memdup((char*) &select->order_list,
3322
				     sizeof(st_sql_list));
unknown's avatar
unknown committed
3323
	    select->order_list.empty();
3324
	  };
unknown's avatar
unknown committed
3325

unknown's avatar
unknown committed
3326 3327

in_sum_expr:
unknown's avatar
unknown committed
3328
	opt_all
3329 3330 3331 3332
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
3333
	    yyerror(ER(ER_SYNTAX_ERROR));
3334
	    YYABORT;
3335 3336
	  }
	}
unknown's avatar
unknown committed
3337 3338
	expr
	{
unknown's avatar
unknown committed
3339
	  Select->in_sum_expr--;
3340
	  $$= $3;
unknown's avatar
unknown committed
3341
	};
unknown's avatar
unknown committed
3342

3343
cast_type:
3344
	BINARY opt_len		{ $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; }
3345 3346
	| 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
3347 3348 3349 3350 3351 3352 3353
	| 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; }
3354 3355
	;

unknown's avatar
unknown committed
3356
expr_list:
3357
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3358
	expr_list2
unknown's avatar
unknown committed
3359
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
3360 3361

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

unknown's avatar
unknown committed
3365 3366
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
3367
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
3368

unknown's avatar
unknown committed
3369
ident_list:
3370
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3371
        ident_list2
unknown's avatar
unknown committed
3372
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
3373 3374

ident_list2:
3375
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
3376
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
3377 3378 3379

opt_expr:
	/* empty */      { $$= NULL; }
3380
	| expr           { $$= $1; };
unknown's avatar
unknown committed
3381 3382 3383

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
3384
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
3385 3386

when_list:
unknown's avatar
unknown committed
3387
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
3388
	when_list2
unknown's avatar
unknown committed
3389
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
3390 3391

when_list2:
unknown's avatar
unknown committed
3392
	expr THEN_SYM expr
unknown's avatar
unknown committed
3393
	  {
unknown's avatar
unknown committed
3394
	    SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
3395 3396
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
3397
	}
unknown's avatar
unknown committed
3398
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
3399
	  {
unknown's avatar
unknown committed
3400
	    SELECT_LEX *sel=Select;
unknown's avatar
unknown committed
3401 3402
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
3403
	  };
unknown's avatar
unknown committed
3404 3405 3406 3407

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
unknown's avatar
unknown committed
3408
	| join_table_list ',' join_table_list { $$=$3; }
3409
	| join_table_list normal_join join_table_list { $$=$3; }
3410
	| join_table_list STRAIGHT_JOIN join_table_list
3411
	  { $$=$3 ; $1->next->straight=1; }
unknown's avatar
unknown committed
3412 3413 3414
	| 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
3415
	  USING
unknown's avatar
unknown committed
3416
	  {
unknown's avatar
unknown committed
3417
	    SELECT_LEX *sel= Select;
3418
	    sel->db1=$1->db; sel->table1=$1->alias;
unknown's avatar
unknown committed
3419
	    sel->db2=$3->db; sel->table2=$3->alias;
unknown's avatar
unknown committed
3420
	  }
unknown's avatar
unknown committed
3421 3422 3423
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

3424
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
3425
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
3426
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
3427
	  {
unknown's avatar
unknown committed
3428
	    SELECT_LEX *sel= Select;
3429 3430
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
3431
	  }
unknown's avatar
unknown committed
3432
	  USING '(' using_list ')'
3433
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
3434
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
3435 3436 3437 3438 3439
	  {
	    add_join_natural($1,$1->next);
	    $1->next->outer_join|=JOIN_TYPE_LEFT;
	    $$=$6;
	  }
3440
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
3441
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
3442
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
3443
	  {
unknown's avatar
unknown committed
3444
	    SELECT_LEX *sel= Select;
3445 3446
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
3447
	  }
3448
	  USING '(' using_list ')'
3449
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
3450
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
3451 3452 3453 3454 3455
	  {
	    add_join_natural($1->next,$1);
	    $1->outer_join|=JOIN_TYPE_RIGHT;
	    $$=$6;
	  }
3456
	| join_table_list NATURAL JOIN_SYM join_table_list
3457
	  { add_join_natural($1,$1->next); $$=$4; };
unknown's avatar
unknown committed
3458 3459

normal_join:
unknown's avatar
unknown committed
3460 3461 3462 3463
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
unknown's avatar
unknown committed
3464 3465

join_table:
unknown's avatar
unknown committed
3466
	{
unknown's avatar
unknown committed
3467
	  SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3468
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
unknown's avatar
unknown committed
3469
	  sel->table_join_options= 0;
unknown's avatar
unknown committed
3470
	}
unknown's avatar
unknown committed
3471
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
3472
	{
unknown's avatar
unknown committed
3473
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3474
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
3475
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
unknown's avatar
unknown committed
3476
					   sel->get_table_join_options(),
unknown's avatar
unknown committed
3477
					   lex->lock_option,
3478 3479
					   sel->get_use_index(),
					   sel->get_ignore_index())))
3480
	    YYABORT;
unknown's avatar
unknown committed
3481
	}
unknown's avatar
unknown committed
3482
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
3483
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
3484
        | '(' SELECT_SYM select_derived ')' opt_table_alias
unknown's avatar
unknown committed
3485 3486
	{
	  LEX *lex=Lex;
3487 3488 3489
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
unknown's avatar
unknown committed
3490
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
3491
				  TL_READ,(List<String> *)0,
unknown's avatar
unknown committed
3492 3493
	                          (List<String> *)0)))

unknown's avatar
unknown committed
3494
	    YYABORT;
unknown's avatar
unknown committed
3495
	};
unknown's avatar
unknown committed
3496

3497
select_derived:
unknown's avatar
unknown committed
3498
        {
unknown's avatar
unknown committed
3499
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3500
	  lex->derived_tables= 1;
unknown's avatar
unknown committed
3501 3502 3503
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
3504 3505
	  {
	    yyerror(ER(ER_SYNTAX_ERROR));
3506 3507
	    YYABORT;
	  }
3508
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
unknown's avatar
unknown committed
3509
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
3510 3511
	    YYABORT;
	  mysql_init_select(lex);
3512
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
3513
	  lex->current_select->parsing_place= SELECT_LIST;
3514 3515 3516
	}
        select_options select_item_list
	{
3517
	  Select->parsing_place= NO_MATTER;
unknown's avatar
unknown committed
3518
	}
3519
	opt_select_from union_opt
3520
        ;
unknown's avatar
unknown committed
3521 3522 3523

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
3524
	| OUTER		{};
unknown's avatar
unknown committed
3525 3526 3527 3528

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
3529
          {
unknown's avatar
unknown committed
3530
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3531 3532 3533
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
3534 3535
	| FORCE_SYM key_usage_list
          {
unknown's avatar
unknown committed
3536
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3537 3538 3539 3540
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
unknown's avatar
unknown committed
3541
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
3542
	  {
unknown's avatar
unknown committed
3543
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3544 3545
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
3546
	  };
unknown's avatar
unknown committed
3547 3548

key_usage_list:
unknown's avatar
unknown committed
3549
	key_or_index { Select->interval_list.empty(); }
unknown's avatar
unknown committed
3550
        '(' key_list_or_empty ')'
unknown's avatar
unknown committed
3551
        { $$= &Select->interval_list; }
unknown's avatar
unknown committed
3552 3553 3554 3555 3556 3557
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
unknown's avatar
unknown committed
3558 3559 3560

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
3561
        { Select->
unknown's avatar
unknown committed
3562
	    interval_list.push_back(new (YYTHD->mem_root) String((const char*) $3.str, $3.length,
3563
				    system_charset_info)); }
unknown's avatar
unknown committed
3564
	| ident
unknown's avatar
unknown committed
3565
        { Select->
unknown's avatar
unknown committed
3566
	    interval_list.push_back(new (YYTHD->mem_root) String((const char*) $1.str, $1.length,
3567
				    system_charset_info)); }
unknown's avatar
unknown committed
3568
	| PRIMARY_SYM
unknown's avatar
unknown committed
3569
        { Select->
unknown's avatar
unknown committed
3570
	    interval_list.push_back(new (YYTHD->mem_root) String("PRIMARY", 7,
3571
				    system_charset_info)); };
unknown's avatar
unknown committed
3572 3573 3574

using_list:
	ident
unknown's avatar
unknown committed
3575
	  {
unknown's avatar
unknown committed
3576
	    SELECT_LEX *sel= Select;
3577 3578 3579 3580
	    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
3581 3582 3583 3584
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
3585
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3586
	    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
3587
	      YYABORT;
unknown's avatar
unknown committed
3588
	  };
unknown's avatar
unknown committed
3589 3590 3591

interval:
	 DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
unknown's avatar
unknown committed
3592
	| DAY_MICROSECOND_SYM	{ $$=INTERVAL_DAY_MICROSECOND; }
unknown's avatar
unknown committed
3593 3594 3595
	| DAY_MINUTE_SYM	{ $$=INTERVAL_DAY_MINUTE; }
	| DAY_SECOND_SYM	{ $$=INTERVAL_DAY_SECOND; }
	| DAY_SYM		{ $$=INTERVAL_DAY; }
unknown's avatar
unknown committed
3596
	| HOUR_MICROSECOND_SYM	{ $$=INTERVAL_HOUR_MICROSECOND; }
unknown's avatar
unknown committed
3597 3598 3599
	| HOUR_MINUTE_SYM	{ $$=INTERVAL_HOUR_MINUTE; }
	| HOUR_SECOND_SYM	{ $$=INTERVAL_HOUR_SECOND; }
	| HOUR_SYM		{ $$=INTERVAL_HOUR; }
unknown's avatar
unknown committed
3600 3601
	| MICROSECOND_SYM	{ $$=INTERVAL_MICROSECOND; }
	| MINUTE_MICROSECOND_SYM	{ $$=INTERVAL_MINUTE_MICROSECOND; }
unknown's avatar
unknown committed
3602 3603 3604
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
unknown's avatar
unknown committed
3605
	| SECOND_MICROSECOND_SYM	{ $$=INTERVAL_SECOND_MICROSECOND; }
unknown's avatar
unknown committed
3606 3607
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
	| YEAR_MONTH_SYM	{ $$=INTERVAL_YEAR_MONTH; }
3608 3609
	| YEAR_SYM		{ $$=INTERVAL_YEAR; }
        ;
unknown's avatar
unknown committed
3610

3611
date_time_type:
3612 3613 3614 3615 3616
          DATE_SYM              {$$=MYSQL_TIMESTAMP_DATE;}
        | TIME_SYM              {$$=MYSQL_TIMESTAMP_TIME;}
        | DATETIME              {$$=MYSQL_TIMESTAMP_DATETIME;}
        | TIMESTAMP             {$$=MYSQL_TIMESTAMP_DATETIME;}
        ;
3617

unknown's avatar
unknown committed
3618 3619 3620
table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
3621
	| EQ;
unknown's avatar
unknown committed
3622 3623 3624 3625

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

unknown's avatar
unknown committed
3628 3629 3630 3631
opt_all:
	/* empty */
	| ALL
	;
unknown's avatar
unknown committed
3632 3633

where_clause:
unknown's avatar
unknown committed
3634
	/* empty */  { Select->where= 0; }
unknown's avatar
unknown committed
3635 3636 3637 3638 3639
	| WHERE
          {
            Select->parsing_place= IN_WHERE;
          }
          expr
3640
	  {
unknown's avatar
unknown committed
3641 3642 3643 3644 3645
            SELECT_LEX *select= Select;
	    select->where= $3;
            select->parsing_place= NO_MATTER;
	    if ($3)
	      $3->top_level_item();
3646
	  }
unknown's avatar
unknown committed
3647
 	;
unknown's avatar
unknown committed
3648 3649 3650

having_clause:
	/* empty */
unknown's avatar
unknown committed
3651 3652
	| HAVING
	  {
3653
	    Select->parsing_place= IN_HAVING;
unknown's avatar
unknown committed
3654 3655
          }
	  expr
unknown's avatar
unknown committed
3656
	  {
unknown's avatar
unknown committed
3657
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3658
	    sel->having= $3;
3659
	    sel->parsing_place= NO_MATTER;
unknown's avatar
unknown committed
3660 3661 3662
	    if ($3)
	      $3->top_level_item();
	  }
3663
	;
unknown's avatar
unknown committed
3664 3665

opt_escape:
3666 3667 3668 3669 3670 3671
	ESCAPE_SYM simple_expr { $$= $2; }
	| /* empty */
          { 
            $$= new Item_string("\\", 1, &my_charset_latin1);
          }
        ;
unknown's avatar
unknown committed
3672 3673 3674


/*
unknown's avatar
unknown committed
3675
   group by statement in select
unknown's avatar
unknown committed
3676 3677 3678 3679
*/

group_clause:
	/* empty */
3680
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
3681 3682

group_list:
unknown's avatar
unknown committed
3683
	group_list ',' order_ident order_dir
unknown's avatar
unknown committed
3684
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3685
	| order_ident order_dir
unknown's avatar
unknown committed
3686
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3687

3688 3689
olap_opt:
	/* empty */ {}
3690
	| WITH CUBE_SYM
3691
          {
3692
	    LEX *lex=Lex;
3693 3694 3695 3696 3697 3698
	    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
3699
	    lex->current_select->olap= CUBE_TYPE;
3700
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
3701
	    YYABORT;	/* To be deleted in 5.1 */
3702
	  }
3703
	| WITH ROLLUP_SYM
3704
          {
3705 3706 3707 3708 3709 3710 3711
	    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
3712
	    lex->current_select->olap= ROLLUP_TYPE;
3713
	  }
3714
	;
3715

unknown's avatar
unknown committed
3716
/*
unknown's avatar
unknown committed
3717
   Order by statement in select
unknown's avatar
unknown committed
3718 3719
*/

3720
opt_order_clause:
unknown's avatar
unknown committed
3721
	/* empty */
unknown's avatar
unknown committed
3722
	| order_clause;
3723 3724

order_clause:
3725 3726
	ORDER_SYM BY
        {
unknown's avatar
unknown committed
3727
	  LEX *lex=Lex;
3728
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
3729
	      lex->current_select->olap !=
3730
	      UNSPECIFIED_OLAP_TYPE)
3731
	  {
3732
	    net_printf(lex->thd, ER_WRONG_USAGE,
3733 3734 3735 3736
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
3737
	} order_list;
unknown's avatar
unknown committed
3738 3739 3740

order_list:
	order_list ',' order_ident order_dir
unknown's avatar
unknown committed
3741
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3742
	| order_ident order_dir
unknown's avatar
unknown committed
3743
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3744 3745 3746

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
3747
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
3748
	| DESC { $$ =0; };
unknown's avatar
unknown committed
3749 3750


3751 3752 3753
opt_limit_clause_init:
	/* empty */
	{
3754 3755
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
3756
          sel->offset_limit= 0L;
3757
          sel->select_limit= HA_POS_ERROR;
3758
	}
3759 3760 3761
	| limit_clause {}
	;

3762 3763 3764 3765 3766
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

3767
limit_clause:
3768
	LIMIT limit_options {}
unknown's avatar
unknown committed
3769
	;
unknown's avatar
unknown committed
3770 3771 3772

limit_options:
	ULONG_NUM
unknown's avatar
unknown committed
3773
	  {
unknown's avatar
unknown committed
3774
            SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3775 3776
            sel->select_limit= $1;
            sel->offset_limit= 0L;
3777
	    sel->explicit_limit= 1;
unknown's avatar
unknown committed
3778 3779 3780
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
unknown's avatar
unknown committed
3781
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3782 3783
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
3784
	    sel->explicit_limit= 1;
unknown's avatar
unknown committed
3785
	  }
unknown's avatar
unknown committed
3786
	| ULONG_NUM OFFSET_SYM ULONG_NUM
unknown's avatar
unknown committed
3787
	  {
unknown's avatar
unknown committed
3788
	    SELECT_LEX *sel= Select;
unknown's avatar
unknown committed
3789 3790
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
3791
	    sel->explicit_limit= 1;
unknown's avatar
unknown committed
3792 3793
	  }
	;
unknown's avatar
unknown committed
3794 3795 3796 3797 3798


delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
3799
	  LEX *lex=Lex;
3800
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
3801
	}
unknown's avatar
unknown committed
3802
	| LIMIT ulonglong_num
3803 3804 3805 3806 3807
	{
	  SELECT_LEX *sel= Select;
	  sel->select_limit= (ha_rows) $2;
	  sel->explicit_limit= 1;
	};
unknown's avatar
unknown committed
3808 3809

ULONG_NUM:
unknown's avatar
unknown committed
3810 3811 3812 3813 3814 3815
	NUM	        { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| REAL_NUM 	{ int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| FLOAT_NUM	{ int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	;
unknown's avatar
unknown committed
3816

unknown's avatar
unknown committed
3817
ulonglong_num:
unknown's avatar
unknown committed
3818 3819 3820 3821 3822 3823
	NUM	    { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| LONG_NUM  { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| REAL_NUM  { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| FLOAT_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	;
unknown's avatar
unknown committed
3824 3825 3826 3827 3828 3829

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
3830 3831 3832 3833 3834 3835 3836
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3837 3838 3839
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
unknown's avatar
unknown committed
3840
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
unknown's avatar
unknown committed
3841
	      YYABORT;
3842
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3843
	  }
unknown's avatar
unknown committed
3844
	  '(' procedure_list ')';
unknown's avatar
unknown committed
3845 3846 3847 3848


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
3849
	| procedure_list2 {};
unknown's avatar
unknown committed
3850 3851 3852

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
3853
	| procedure_item;
unknown's avatar
unknown committed
3854 3855 3856 3857

procedure_item:
	  remember_name expr
	  {
unknown's avatar
unknown committed
3858 3859
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
unknown's avatar
unknown committed
3860 3861
	      YYABORT;
	    if (!$2->name)
unknown's avatar
unknown committed
3862
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
3863 3864 3865 3866 3867 3868
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
3869 3870
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3871 3872
	        YYABORT;
	   }
3873
	   select_var_list
3874
	   {}
3875
           ;
unknown's avatar
unknown committed
3876

unknown's avatar
unknown committed
3877
select_var_list:
3878 3879 3880 3881 3882
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
3883
           {
3884
             LEX *lex=Lex;
unknown's avatar
unknown committed
3885
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
3886 3887
	       YYABORT;
	   }
unknown's avatar
unknown committed
3888
           ;
unknown's avatar
unknown committed
3889

3890
into:
unknown's avatar
unknown committed
3891
        INTO OUTFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3892
	{
unknown's avatar
unknown committed
3893
          LEX *lex= Lex;
3894 3895 3896 3897
          lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
          if (!(lex->exchange= new sql_exchange($3.str, 0)) ||
              !(lex->result= new select_export(lex->exchange)))
            YYABORT;
unknown's avatar
unknown committed
3898 3899
	}
	opt_field_term opt_line_term
unknown's avatar
unknown committed
3900
	| INTO DUMPFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3901
	{
3902
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3903 3904
	  if (!lex->describe)
	  {
3905
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
unknown's avatar
unknown committed
3906 3907 3908 3909 3910
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3911
	}
3912
        | INTO select_var_list_init
unknown's avatar
unknown committed
3913
	{
3914
	  Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
3915 3916
	}
        ;
unknown's avatar
unknown committed
3917

unknown's avatar
unknown committed
3918 3919 3920
/*
  DO statement
*/
unknown's avatar
unknown committed
3921

3922
do:	DO_SYM
unknown's avatar
unknown committed
3923 3924 3925
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
3926 3927 3928 3929 3930
	  mysql_init_select(lex);
	}
	expr_list
	{
	  Lex->insert_list= $3;
unknown's avatar
unknown committed
3931
	}
3932 3933
	;

unknown's avatar
unknown committed
3934
/*
3935
  Drop : delete tables or index or user
unknown's avatar
unknown committed
3936 3937 3938
*/

drop:
unknown's avatar
unknown committed
3939
	DROP opt_temporary table_or_tables if_exists table_list opt_restrict
unknown's avatar
unknown committed
3940
	{
unknown's avatar
unknown committed
3941 3942
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3943 3944
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
unknown's avatar
unknown committed
3945
	}
unknown's avatar
unknown committed
3946
	| DROP INDEX_SYM ident ON table_ident {}
unknown's avatar
unknown committed
3947
	  {
unknown's avatar
unknown committed
3948 3949
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
3950 3951 3952
	     lex->alter_info.drop_list.empty();
	     lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
                                                                $3.str));
unknown's avatar
unknown committed
3953 3954
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3955 3956 3957 3958
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
3959 3960 3961 3962
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
3963
	 }
unknown's avatar
unknown committed
3964
	| DROP UDF_SYM IDENT_sys
unknown's avatar
unknown committed
3965
	  {
unknown's avatar
unknown committed
3966 3967
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3968
	    lex->udf.name = $3;
3969 3970 3971 3972 3973 3974
	  }
	| DROP USER
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_USER;
	    lex->users_list.empty();
unknown's avatar
unknown committed
3975
	  }
3976 3977 3978
	  user_list
	  {}
	  ;
unknown's avatar
unknown committed
3979 3980 3981


table_list:
3982
	table_name
unknown's avatar
unknown committed
3983
	| table_list ',' table_name;
unknown's avatar
unknown committed
3984

3985
table_name:
unknown's avatar
unknown committed
3986
	table_ident
unknown's avatar
unknown committed
3987 3988 3989 3990 3991
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
unknown's avatar
unknown committed
3992 3993

if_exists:
3994
	/* empty */ { $$= 0; }
3995 3996
	| IF EXISTS { $$= 1; }
	;
unknown's avatar
unknown committed
3997

3998 3999 4000 4001
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
unknown's avatar
unknown committed
4002 4003 4004 4005 4006
/*
** Insert : add new data to table
*/

insert:
4007 4008 4009
	INSERT
	{
	  LEX *lex= Lex;
4010 4011
	  lex->sql_command= SQLCOM_INSERT;
	  lex->duplicates= DUP_ERROR; 
4012 4013
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
4014
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
4015
	} insert_lock_option
4016
	opt_ignore insert2
unknown's avatar
unknown committed
4017
	{
unknown's avatar
unknown committed
4018
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
4019
	  Lex->current_select= &Lex->select_lex;
unknown's avatar
unknown committed
4020
	}
4021
	insert_field_spec opt_insert_update
4022
	{}
unknown's avatar
unknown committed
4023
	;
unknown's avatar
unknown committed
4024 4025

replace:
4026 4027
	REPLACE
	{
4028
	  LEX *lex=Lex;
4029 4030
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
4031
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
4032
	}
unknown's avatar
unknown committed
4033 4034
	replace_lock_option insert2
	{
unknown's avatar
unknown committed
4035
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
4036
	  Lex->current_select= &Lex->select_lex;
unknown's avatar
unknown committed
4037 4038
	}
	insert_field_spec
4039
	{}
unknown's avatar
unknown committed
4040
	{}
unknown's avatar
unknown committed
4041
	;
unknown's avatar
unknown committed
4042 4043

insert_lock_option:
unknown's avatar
unknown committed
4044 4045 4046 4047
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
4048
	;
unknown's avatar
unknown committed
4049 4050

replace_lock_option:
unknown's avatar
unknown committed
4051 4052
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
4053 4054 4055

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
4056
	| insert_table {};
unknown's avatar
unknown committed
4057 4058

insert_table:
4059
	table_name
unknown's avatar
unknown committed
4060
	{
unknown's avatar
unknown committed
4061 4062 4063 4064
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
4065
	};
unknown's avatar
unknown committed
4066 4067

insert_field_spec:
unknown's avatar
unknown committed
4068 4069 4070
	insert_values {}
	| '(' ')' insert_values {}
	| '(' fields ')' insert_values {}
unknown's avatar
unknown committed
4071 4072
	| SET
	  {
unknown's avatar
unknown committed
4073 4074 4075
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
4076 4077
	      YYABORT;
	   }
unknown's avatar
unknown committed
4078
	   ident_eq_list;
unknown's avatar
unknown committed
4079 4080 4081 4082

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
4083
	| '(' ')'	  { };
unknown's avatar
unknown committed
4084 4085 4086

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
4087
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
4088 4089 4090

insert_values:
	VALUES	values_list  {}
unknown's avatar
unknown committed
4091
	| VALUE_SYM values_list  {}
unknown's avatar
unknown committed
4092 4093
	|     create_select     { Select->set_braces(0);} union_clause {}
	| '(' create_select ')' { Select->set_braces(1);} union_opt {}
4094
        ;
unknown's avatar
unknown committed
4095 4096 4097

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
4098
	| no_braces;
unknown's avatar
unknown committed
4099 4100 4101 4102

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
4103
	ident_eq_value;
unknown's avatar
unknown committed
4104 4105

ident_eq_value:
unknown's avatar
unknown committed
4106
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
4107
	 {
unknown's avatar
unknown committed
4108 4109 4110
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
4111
	    YYABORT;
unknown's avatar
unknown committed
4112
	 };
unknown's avatar
unknown committed
4113 4114

equal:	EQ		{}
unknown's avatar
unknown committed
4115 4116 4117 4118 4119 4120 4121
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
4122 4123 4124 4125 4126 4127 4128 4129 4130

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
4131 4132
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
4133
	    YYABORT;
unknown's avatar
unknown committed
4134
	 };
unknown's avatar
unknown committed
4135 4136 4137

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
4138
	| values;
unknown's avatar
unknown committed
4139 4140

values:
unknown's avatar
unknown committed
4141
	values ','  expr_or_default
unknown's avatar
unknown committed
4142 4143 4144 4145
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
4146 4147 4148 4149 4150 4151 4152 4153
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
4154
	expr	  { $$= $1;}
unknown's avatar
SCRUM  
unknown committed
4155
	| DEFAULT {$$= new Item_default_value(); }
unknown's avatar
unknown committed
4156
	;
unknown's avatar
unknown committed
4157

4158 4159
opt_insert_update:
        /* empty */
unknown's avatar
unknown committed
4160 4161
        | ON DUPLICATE_SYM	{ Lex->duplicates= DUP_UPDATE; }
          KEY_SYM UPDATE_SYM insert_update_list
4162 4163
        ;

unknown's avatar
unknown committed
4164 4165 4166
/* Update rows in a table */

update:
4167 4168
	UPDATE_SYM
	{
4169
	  LEX *lex= Lex;
unknown's avatar
unknown committed
4170
	  mysql_init_select(lex);
4171
          lex->sql_command= SQLCOM_UPDATE;
unknown's avatar
unknown committed
4172
	  lex->lock_option= TL_UNLOCK; 	/* Will be set later */
4173
	  lex->duplicates= DUP_ERROR; 
4174
        }
unknown's avatar
unknown committed
4175
        opt_low_priority opt_ignore join_table_list
unknown's avatar
unknown committed
4176
	SET update_list
unknown's avatar
unknown committed
4177
	{
4178 4179
	  LEX *lex= Lex;
          if (lex->select_lex.table_list.elements > 1)
4180
	  {
unknown's avatar
unknown committed
4181
            lex->sql_command= SQLCOM_UPDATE_MULTI;
unknown's avatar
unknown committed
4182
	    lex->multi_lock_option= $3;
4183
	  }
4184 4185 4186 4187 4188 4189 4190
	  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;
	  }
4191
	  else
unknown's avatar
unknown committed
4192
	    Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
4193
	}
4194
	where_clause opt_order_clause delete_limit_clause {}
unknown's avatar
unknown committed
4195
	;
unknown's avatar
unknown committed
4196 4197

update_list:
unknown's avatar
unknown committed
4198 4199 4200 4201 4202
	update_list ',' update_elem
	| update_elem;

update_elem:
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
4203
	{
unknown's avatar
unknown committed
4204
	  if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
unknown's avatar
unknown committed
4205
	    YYABORT;
unknown's avatar
unknown committed
4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219
	};

insert_update_list:
	insert_update_list ',' insert_update_elem
	| insert_update_elem;

insert_update_elem:
	simple_ident equal expr_or_default
	{
	  LEX *lex= Lex;
	  if (lex->update_list.push_back($1) || 
	      lex->value_list.push_back($3))
	    YYABORT;
	};
unknown's avatar
unknown committed
4220 4221

opt_low_priority:
4222
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4223
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
4224 4225 4226 4227

/* Delete rows from a table */

delete:
4228
	DELETE_SYM
4229
	{
4230 4231
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
unknown's avatar
unknown committed
4232
	  lex->lock_option= lex->thd->update_lock_default;
4233
	  lex->ignore= 0;
4234
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
4235
	}
unknown's avatar
unknown committed
4236 4237
	opt_delete_options single_multi {}
	;
4238 4239

single_multi:
unknown's avatar
unknown committed
4240 4241
 	FROM table_ident
	{
unknown's avatar
unknown committed
4242 4243
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
unknown's avatar
unknown committed
4244 4245 4246
	    YYABORT;
	}
	where_clause opt_order_clause
4247
	delete_limit_clause {}
unknown's avatar
unknown committed
4248
	| table_wild_list
unknown's avatar
unknown committed
4249
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
4250
          FROM join_table_list where_clause
unknown's avatar
unknown committed
4251 4252
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
4253 4254 4255
	  USING join_table_list where_clause
	  {}
	;
unknown's avatar
unknown committed
4256 4257 4258

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
4259
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
4260 4261

table_wild_one:
unknown's avatar
unknown committed
4262
	ident opt_wild opt_table_alias
unknown's avatar
unknown committed
4263
	{
unknown's avatar
unknown committed
4264 4265
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
unknown's avatar
unknown committed
4266 4267
	    YYABORT;
        }
unknown's avatar
unknown committed
4268
	| ident '.' ident opt_wild opt_table_alias
unknown's avatar
unknown committed
4269
	  {
unknown's avatar
unknown committed
4270 4271
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
unknown's avatar
unknown committed
4272 4273
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
unknown's avatar
unknown committed
4274
	      YYABORT;
unknown's avatar
unknown committed
4275
	  }
unknown's avatar
unknown committed
4276
	;
unknown's avatar
unknown committed
4277 4278

opt_wild:
4279
	/* empty */	{}
unknown's avatar
unknown committed
4280
	| '.' '*'	{};
unknown's avatar
unknown committed
4281 4282


4283
opt_delete_options:
unknown's avatar
unknown committed
4284
	/* empty */	{}
unknown's avatar
unknown committed
4285
	| opt_delete_option opt_delete_options {};
4286 4287

opt_delete_option:
4288
	QUICK		{ Select->options|= OPTION_QUICK; }
4289
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
4290
	| IGNORE_SYM	{ Lex->ignore= 1; };
4291

4292
truncate:
unknown's avatar
unknown committed
4293
	TRUNCATE_SYM opt_table_sym table_name
4294
	{
4295
	  LEX* lex= Lex;
4296
	  lex->sql_command= SQLCOM_TRUNCATE;
4297
	  lex->select_lex.options= 0;
4298
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
4299 4300
	}
	;
4301

unknown's avatar
unknown committed
4302 4303
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
4304
	| TABLE_SYM;
4305

unknown's avatar
unknown committed
4306 4307
/* Show things */

4308 4309
show:	SHOW
	{
unknown's avatar
unknown committed
4310 4311 4312 4313
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
unknown's avatar
unknown committed
4314
	show_param
4315 4316
	{}
	;
unknown's avatar
unknown committed
4317 4318 4319 4320 4321

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
4322
	  {
4323
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4324
	    lex->sql_command= SQLCOM_SHOW_TABLES;
4325
	    lex->select_lex.db= $2;
unknown's avatar
unknown committed
4326
	   }
unknown's avatar
unknown committed
4327
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
4328
	  {
4329
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4330
	    lex->sql_command= SQLCOM_SHOW_TABLES;
4331
	    lex->describe= DESCRIBE_EXTENDED;
4332
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
4333
	  }
4334
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
4335
	  {
4336
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4337
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
4338
	    lex->select_lex.db= $3;
4339
	  }
unknown's avatar
unknown committed
4340
	| ENGINE_SYM storage_engines 
unknown's avatar
unknown committed
4341 4342
	  { Lex->create_info.db_type= $2; }
	  show_engine_param
unknown's avatar
unknown committed
4343
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
4344 4345
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
4346 4347
	    if ($5)
	      $4->change_db($5);
unknown's avatar
unknown committed
4348
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
unknown's avatar
unknown committed
4349 4350
	      YYABORT;
	  }
4351
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
unknown's avatar
unknown committed
4352 4353
	  TEXT_STRING_sys AND_SYM MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND_SYM MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
4354 4355 4356 4357 4358
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
4359
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
4360
          }
4361
        | master_or_binary LOGS_SYM
unknown's avatar
unknown committed
4362 4363
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
4364 4365 4366 4367 4368
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
4369
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
4370
          {
4371 4372
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
4373
          } opt_limit_clause_init
unknown's avatar
unknown committed
4374
	| keys_or_index from_or_in table_ident opt_db
unknown's avatar
unknown committed
4375 4376 4377 4378
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
unknown's avatar
unknown committed
4379
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
unknown's avatar
unknown committed
4380 4381
	      YYABORT;
	  }
unknown's avatar
unknown committed
4382 4383 4384 4385 4386 4387 4388 4389
	| 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
4390 4391 4392 4393 4394 4395 4396
	    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
4397 4398 4399 4400 4401 4402
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
4403
        | COUNT_SYM '(' '*' ')' WARNINGS
4404
          { (void) create_select_for_variable("warning_count"); }
4405
        | COUNT_SYM '(' '*' ')' ERRORS
4406
	  { (void) create_select_for_variable("error_count"); }
4407
        | WARNINGS opt_limit_clause_init
unknown's avatar
unknown committed
4408
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4409
        | ERRORS opt_limit_clause_init
4410
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
unknown's avatar
unknown committed
4411 4412
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
4413
        | INNOBASE_SYM STATUS_SYM
unknown's avatar
unknown committed
4414
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS; WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); }
unknown's avatar
unknown committed
4415 4416
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
4417
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
4418
	  {
4419
	    THD *thd= YYTHD;
4420 4421
	    thd->lex->sql_command= SQLCOM_SHOW_VARIABLES;
	    thd->lex->option_type= (enum_var_type) $1;
4422
	  }
4423
	| charset wild
4424
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
4425 4426
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
4427
	| BERKELEY_DB_SYM LOGS_SYM
unknown's avatar
unknown committed
4428
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); }
unknown's avatar
unknown committed
4429
	| LOGS_SYM
unknown's avatar
unknown committed
4430
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); }
4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453
	| GRANTS
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    THD *thd= lex->thd;
	    LEX_USER *curr_user;
            if (!(curr_user= (LEX_USER*) thd->alloc(sizeof(st_lex_user))))
              YYABORT;
            curr_user->user.str= thd->priv_user;
            curr_user->user.length= strlen(thd->priv_user);
            if (*thd->priv_host != 0)
            {
              curr_user->host.str= thd->priv_host;
              curr_user->host.length= strlen(thd->priv_host);
            }
            else
            {
              curr_user->host.str= (char *) "%";
              curr_user->host.length= 1;
            }
            curr_user->password.str=NullS;
	    lex->grant_user= curr_user;
	  }
unknown's avatar
unknown committed
4454
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
4455 4456 4457 4458 4459 4460
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
4461
	| CREATE DATABASE opt_if_not_exists ident
unknown's avatar
unknown committed
4462 4463
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
4464 4465
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
4466
	  }
unknown's avatar
unknown committed
4467 4468 4469
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
unknown's avatar
unknown committed
4470
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
unknown's avatar
unknown committed
4471 4472 4473 4474 4475
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
4476
          }
unknown's avatar
unknown committed
4477 4478 4479
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
4480
          };
unknown's avatar
unknown committed
4481

unknown's avatar
unknown committed
4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505
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;
	    }
	  };

4506 4507 4508 4509
master_or_binary:
	MASTER_SYM
	| BINARY;

unknown's avatar
unknown committed
4510 4511 4512 4513
opt_storage:
	/* empty */
	| STORAGE_SYM;

unknown's avatar
unknown committed
4514 4515
opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
4516
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
4517 4518 4519

wild:
	/* empty */
4520
	| LIKE TEXT_STRING_sys
unknown's avatar
unknown committed
4521
	  { Lex->wild=  new (YYTHD->mem_root) String($2.str, $2.length,
4522
                                                      system_charset_info); };
unknown's avatar
unknown committed
4523

unknown's avatar
unknown committed
4524 4525
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
4526
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
4527

unknown's avatar
unknown committed
4528 4529
from_or_in:
	FROM
unknown's avatar
unknown committed
4530
	| IN_SYM;
unknown's avatar
unknown committed
4531

unknown's avatar
unknown committed
4532 4533
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
4534
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
4535 4536 4537

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


unknown's avatar
unknown committed
4541 4542 4543 4544
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
4545 4546 4547 4548
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
4549
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
unknown's avatar
unknown committed
4550 4551
	    YYABORT;
	}
4552
	opt_describe_column {}
unknown's avatar
unknown committed
4553 4554 4555
	| describe_command opt_extended_describe
	  { Lex->describe|= DESCRIBE_NORMAL; }
	  select
4556
          {
unknown's avatar
unknown committed
4557
	    LEX *lex=Lex;
4558
	    lex->select_lex.options|= SELECT_DESCRIBE;
unknown's avatar
unknown committed
4559 4560
	  }
	;
unknown's avatar
unknown committed
4561 4562 4563

describe_command:
	DESC
unknown's avatar
unknown committed
4564
	| DESCRIBE;
unknown's avatar
unknown committed
4565

unknown's avatar
unknown committed
4566 4567 4568 4569 4570
opt_extended_describe:
	/* empty */ {}
	| EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; }
	;

unknown's avatar
unknown committed
4571 4572 4573
opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
4574
	| ident
unknown's avatar
unknown committed
4575
	  { Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info); };
unknown's avatar
unknown committed
4576 4577 4578 4579 4580


/* flush things */

flush:
4581
	FLUSH_SYM opt_no_write_to_binlog
unknown's avatar
unknown committed
4582 4583 4584
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
unknown's avatar
unknown committed
4585
          lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
4586
	}
4587 4588 4589
	flush_options
	{}
	;
unknown's avatar
unknown committed
4590 4591 4592

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
4593
	| flush_option;
unknown's avatar
unknown committed
4594 4595

flush_option:
4596
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
unknown's avatar
unknown committed
4597
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
4598
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
4599 4600 4601 4602
	| 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
4603 4604
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
4605 4606
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
4607

unknown's avatar
unknown committed
4608
opt_table_list:
4609 4610
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
4611

unknown's avatar
unknown committed
4612
reset:
unknown's avatar
unknown committed
4613 4614 4615 4616
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
4617 4618 4619 4620
	} reset_options
	{}
	;

unknown's avatar
unknown committed
4621 4622
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
4623
	| reset_option;
unknown's avatar
unknown committed
4624 4625

reset_option:
unknown's avatar
unknown committed
4626 4627
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
4628
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
4629

unknown's avatar
unknown committed
4630
purge:
unknown's avatar
unknown committed
4631 4632 4633 4634
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
4635 4636 4637 4638 4639
	} purge_options
	{}
	;

purge_options:
4640
	master_or_binary LOGS_SYM purge_option
unknown's avatar
unknown committed
4641
	;
4642 4643

purge_option:
unknown's avatar
unknown committed
4644
        TO_SYM TEXT_STRING_sys
4645 4646 4647 4648 4649 4650 4651 4652 4653
        {
	   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
4654
	    YYABORT;
4655 4656
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
4657
	  /*
unknown's avatar
unknown committed
4658
	    it is OK only emulate fix_fieds, because we need only
4659 4660
            value of constant
	  */
unknown's avatar
unknown committed
4661
	  tmp->quick_fix_field();
4662
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
4663
	  Lex->purge_time= (ulong) tmp->val_int();
unknown's avatar
unknown committed
4664
	}
unknown's avatar
unknown committed
4665
	;
unknown's avatar
unknown committed
4666

unknown's avatar
unknown committed
4667 4668 4669
/* kill threads */

kill:
4670
	KILL_SYM expr
unknown's avatar
unknown committed
4671
	{
unknown's avatar
unknown committed
4672
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4673
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
4674
	  {
4675
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
4676 4677 4678 4679
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
4680
	};
unknown's avatar
unknown committed
4681 4682 4683 4684

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
4685 4686
	{
	  LEX *lex=Lex;
4687 4688
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
4689
	};
unknown's avatar
unknown committed
4690 4691 4692

/* import, export of files */

unknown's avatar
unknown committed
4693
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
unknown's avatar
unknown committed
4694
	{
unknown's avatar
unknown committed
4695 4696
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
unknown's avatar
unknown committed
4697 4698
	  lex->lock_option= $3;
	  lex->local_file=  $4;
4699 4700
	  lex->duplicates= DUP_ERROR;
	  lex->ignore= 0;
unknown's avatar
unknown committed
4701
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
4702
	    YYABORT;
unknown's avatar
unknown committed
4703
	  lex->field_list.empty();
unknown's avatar
unknown committed
4704 4705 4706 4707
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
unknown's avatar
unknown committed
4708
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
4709 4710 4711
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
4712
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
4713 4714
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
unknown's avatar
unknown committed
4715
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
4716
	    YYABORT;
unknown's avatar
unknown committed
4717 4718

        }
4719 4720 4721 4722
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
4723
        };
unknown's avatar
unknown committed
4724 4725 4726

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

unknown's avatar
unknown committed
4729
load_data_lock:
4730
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4731 4732
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
4733 4734


unknown's avatar
unknown committed
4735 4736 4737
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
4738
	| IGNORE_SYM	{ Lex->ignore= 1; };
unknown's avatar
unknown committed
4739 4740 4741

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
4742
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
4743 4744 4745

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
4746
	| field_term;
unknown's avatar
unknown committed
4747 4748

field_term:
4749 4750 4751 4752 4753
	TERMINATED BY text_string 
          {
            DBUG_ASSERT(Lex->exchange);
            Lex->exchange->field_term= $3;
          }
unknown's avatar
unknown committed
4754
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
4755
	  {
unknown's avatar
unknown committed
4756
            LEX *lex= Lex;
4757
            DBUG_ASSERT(lex->exchange);
unknown's avatar
unknown committed
4758 4759
            lex->exchange->enclosed= $4;
            lex->exchange->opt_enclosed= 1;
unknown's avatar
unknown committed
4760
	  }
unknown's avatar
unknown committed
4761
        | ENCLOSED BY text_string
4762 4763 4764 4765
          {
            DBUG_ASSERT(Lex->exchange);
            Lex->exchange->enclosed= $3;
          }
unknown's avatar
unknown committed
4766
        | ESCAPED BY text_string
4767 4768 4769 4770
          {
            DBUG_ASSERT(Lex->exchange);
            Lex->exchange->escaped= $3;
          };
unknown's avatar
unknown committed
4771 4772 4773

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
4774
	| LINES line_term_list;
unknown's avatar
unknown committed
4775 4776 4777

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
4778
	| line_term;
unknown's avatar
unknown committed
4779 4780

line_term:
unknown's avatar
unknown committed
4781
        TERMINATED BY text_string
4782 4783 4784 4785
          {
            DBUG_ASSERT(Lex->exchange);
            Lex->exchange->line_term= $3;
          }
unknown's avatar
unknown committed
4786
        | STARTING BY text_string
4787 4788 4789 4790
          {
            DBUG_ASSERT(Lex->exchange);
            Lex->exchange->line_start= $3;
          };
unknown's avatar
unknown committed
4791 4792 4793

opt_ignore_lines:
	/* empty */
unknown's avatar
unknown committed
4794 4795
        | IGNORE_SYM NUM LINES
          {
4796 4797 4798
            DBUG_ASSERT(Lex->exchange);
            Lex->exchange->skip_lines= atol($2.str);
          };
unknown's avatar
unknown committed
4799 4800 4801 4802

/* Common definitions */

text_literal:
4803
	TEXT_STRING_literal
unknown's avatar
unknown committed
4804 4805
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4806
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
unknown's avatar
unknown committed
4807
	}
unknown's avatar
unknown committed
4808
	| NCHAR_STRING
4809
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
4810
	| UNDERSCORE_CHARSET TEXT_STRING
4811
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
4812
	| text_literal TEXT_STRING_literal
unknown's avatar
unknown committed
4813 4814
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
unknown's avatar
unknown committed
4815 4816

text_string:
4817
	TEXT_STRING_literal
unknown's avatar
unknown committed
4818
	{ $$=  new (YYTHD->mem_root) String($1.str,$1.length,YYTHD->variables.collation_connection); }
unknown's avatar
unknown committed
4819 4820
	| HEX_NUM
	  {
4821
	    Item *tmp = new Item_varbinary($1.str,$1.length);
4822
	    /*
unknown's avatar
unknown committed
4823
	      it is OK only emulate fix_fieds, because we need only
4824 4825 4826
              value of constant
	    */
	    $$= tmp ?
unknown's avatar
unknown committed
4827
	      tmp->quick_fix_field(), tmp->val_str((String*) 0) :
4828
	      (String*) 0;
4829 4830 4831
	  }
	;

unknown's avatar
unknown committed
4832
param_marker:
4833
        '?'
unknown's avatar
unknown committed
4834
        {
4835 4836 4837
          THD *thd=YYTHD;
	  LEX *lex= thd->lex;
          if (thd->command == COM_PREPARE)
4838
          {
4839 4840 4841 4842 4843 4844 4845
            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
4846
          }
4847
          else
unknown's avatar
unknown committed
4848
          {
4849
            yyerror(ER(ER_SYNTAX_ERROR));
unknown's avatar
unknown committed
4850 4851
            YYABORT;
          }
4852 4853 4854
        }
	;

unknown's avatar
unknown committed
4855 4856 4857
signed_literal:
	literal		{ $$ = $1; }
	| '+' NUM_literal { $$ = $2; }
4858 4859
	| '-' NUM_literal
	  {
4860
	    $2->max_length++;
unknown's avatar
unknown committed
4861
	    $$= $2->neg();
4862
	  }
unknown's avatar
unknown committed
4863 4864 4865
	;


unknown's avatar
unknown committed
4866 4867
literal:
	text_literal	{ $$ =	$1; }
unknown's avatar
unknown committed
4868
	| NUM_literal	{ $$ = $1; }
unknown's avatar
unknown committed
4869
	| NULL_SYM	{ $$ =	new Item_null();
4870
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
4871
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
4872
	| UNDERSCORE_CHARSET HEX_NUM
4873
	  {
4874
	    Item *tmp= new Item_varbinary($2.str,$2.length);
4875
	    /*
unknown's avatar
unknown committed
4876
	      it is OK only emulate fix_fieds, because we need only
4877 4878 4879
              value of constant
	    */
	    String *str= tmp ?
unknown's avatar
unknown committed
4880
	      tmp->quick_fix_field(), tmp->val_str((String*) 0) :
4881
	      (String*) 0;
unknown's avatar
unknown committed
4882 4883 4884
	    $$= new Item_string(str ? str->ptr() : "",
				str ? str->length() : 0,
				Lex->charset);
4885
	  }
unknown's avatar
unknown committed
4886 4887
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
4888
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
4889

4890
NUM_literal:
4891 4892
	NUM		{ int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
	| LONG_NUM	{ int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
4893 4894 4895 4896 4897
	| 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
4898 4899 4900 4901 4902 4903
/**********************************************************************
** Createing different items.
**********************************************************************/

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
4904
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
4905 4906

table_wild:
unknown's avatar
unknown committed
4907
	ident '.' '*'
4908 4909
	{
	  $$ = new Item_field(NullS,$1.str,"*");
unknown's avatar
unknown committed
4910
	  Lex->current_select->with_wild++;
4911
	}
unknown's avatar
unknown committed
4912
	| ident '.' ident '.' '*'
4913 4914 4915 4916
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
unknown's avatar
unknown committed
4917
	  Lex->current_select->with_wild++;
4918 4919
	}
	;
unknown's avatar
unknown committed
4920 4921

order_ident:
unknown's avatar
unknown committed
4922
	expr { $$=$1; };
unknown's avatar
unknown committed
4923 4924 4925

simple_ident:
	ident
unknown's avatar
unknown committed
4926
	{
unknown's avatar
unknown committed
4927
	  SELECT_LEX *sel=Select;
4928
	  $$= (sel->parsing_place != IN_HAVING ||
unknown's avatar
unknown committed
4929 4930
	       sel->get_in_sum_expr() > 0) ?
              (Item*) new Item_field(NullS,NullS,$1.str) :
4931
	      (Item*) new Item_ref(NullS, NullS, $1.str);
unknown's avatar
unknown committed
4932
	}
unknown's avatar
unknown committed
4933
	| ident '.' ident
unknown's avatar
unknown committed
4934
	{
unknown's avatar
unknown committed
4935
	  THD *thd= YYTHD;
4936
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
4937
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4938 4939
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4940
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4941 4942 4943
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
4944
	  $$= (sel->parsing_place != IN_HAVING ||
unknown's avatar
unknown committed
4945 4946
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$1.str,$3.str) :
4947
	      (Item*) new Item_ref(NullS, $1.str, $3.str);
unknown's avatar
unknown committed
4948
	}
unknown's avatar
unknown committed
4949
	| '.' ident '.' ident
unknown's avatar
unknown committed
4950
	{
unknown's avatar
unknown committed
4951
	  THD *thd= YYTHD;
4952
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
4953
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4954 4955
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4956
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4957 4958 4959
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
4960
	  $$= (sel->parsing_place != IN_HAVING ||
unknown's avatar
unknown committed
4961 4962
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$2.str,$4.str) :
4963
              (Item*) new Item_ref(NullS, $2.str, $4.str);
unknown's avatar
unknown committed
4964
	}
unknown's avatar
unknown committed
4965
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
4966
	{
unknown's avatar
unknown committed
4967
	  THD *thd= YYTHD;
4968
	  LEX *lex= thd->lex;
unknown's avatar
unknown committed
4969
	  SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
4970 4971
	  if (sel->no_table_names_allowed)
	  {
unknown's avatar
unknown committed
4972
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
unknown's avatar
unknown committed
4973 4974 4975
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
4976
	  $$= (sel->parsing_place != IN_HAVING ||
unknown's avatar
unknown committed
4977 4978 4979 4980
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field((YYTHD->client_capabilities &
				      CLIENT_NO_SCHEMA ? NullS : $1.str),
				     $3.str, $5.str) :
4981 4982
	      (Item*) new Item_ref((YYTHD->client_capabilities &
				    CLIENT_NO_SCHEMA ? NullS : $1.str),
unknown's avatar
unknown committed
4983
                                   $3.str, $5.str);
unknown's avatar
unknown committed
4984
	};
unknown's avatar
unknown committed
4985 4986 4987 4988


field_ident:
	ident			{ $$=$1;}
4989
	| ident '.' ident	{ $$=$3;}	/* Skip schema name in create*/
unknown's avatar
unknown committed
4990
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
4991 4992 4993

table_ident:
	ident			{ $$=new Table_ident($1); }
unknown's avatar
unknown committed
4994
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
4995 4996 4997
	| '.' ident		{ $$=new Table_ident($2);} /* For Delphi */
        ;

unknown's avatar
unknown committed
4998
table_ident_nodb:
unknown's avatar
unknown committed
4999
	ident			{ LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); }
5000
        ;
unknown's avatar
unknown committed
5001

unknown's avatar
unknown committed
5002
IDENT_sys:
5003 5004 5005 5006 5007
	IDENT { $$= $1; }
	| IDENT_QUOTED
	  {
	    THD *thd= YYTHD;
	    if (thd->charset_is_system_charset)
5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018
            {
              CHARSET_INFO *cs= system_charset_info;
              uint wlen= cs->cset->well_formed_len(cs, $1.str,
                                                   $1.str+$1.length,
                                                   $1.length);
              if (wlen < $1.length)
              {
                net_printf(YYTHD, ER_INVALID_CHARACTER_STRING, cs->csname,
                           $1.str + wlen);
                YYABORT;
              }
5019
	      $$= $1;
5020
            }
5021 5022 5023 5024
	    else
	      thd->convert_string(&$$, system_charset_info,
				  $1.str, $1.length, thd->charset());
	  }
unknown's avatar
unknown committed
5025 5026 5027 5028 5029 5030
	;

TEXT_STRING_sys:
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
5031 5032
	  if (thd->charset_is_system_charset)
	    $$= $1;
unknown's avatar
unknown committed
5033
	  else
unknown's avatar
unknown committed
5034 5035
	    thd->convert_string(&$$, system_charset_info,
				$1.str, $1.length, thd->charset());
unknown's avatar
unknown committed
5036 5037 5038
	}
	;

5039
TEXT_STRING_literal:
unknown's avatar
unknown committed
5040 5041 5042
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
5043 5044
	  if (thd->charset_is_collation_connection)
	    $$= $1;
unknown's avatar
unknown committed
5045
	  else
unknown's avatar
unknown committed
5046 5047
	    thd->convert_string(&$$, thd->variables.collation_connection,
				$1.str, $1.length, thd->charset());
unknown's avatar
unknown committed
5048 5049 5050 5051
	}
	;


unknown's avatar
unknown committed
5052
ident:
unknown's avatar
unknown committed
5053
	IDENT_sys	    { $$=$1; }
unknown's avatar
unknown committed
5054 5055
	| keyword
	{
unknown's avatar
unknown committed
5056 5057 5058
	  THD *thd= YYTHD;
	  $$.str=    thd->strmake($1.str, $1.length);
	  $$.length= $1.length;
5059 5060
	}
	;
unknown's avatar
unknown committed
5061 5062

ident_or_text:
unknown's avatar
unknown committed
5063 5064 5065
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
unknown's avatar
unknown committed
5066 5067 5068 5069

user:
	ident_or_text
	{
unknown's avatar
unknown committed
5070 5071
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
5072
	    YYABORT;
5073 5074 5075 5076
	  $$->user = $1;
	  $$->host.str= (char *) "%";
	  $$->host.length= 1;
	}
unknown's avatar
unknown committed
5077 5078
	| ident_or_text '@' ident_or_text
	  {
unknown's avatar
unknown committed
5079 5080
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
5081 5082
	      YYABORT;
	    $$->user = $1; $$->host=$3;
5083
	  }
unknown's avatar
unknown committed
5084
	| CURRENT_USER optional_braces
5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101
	{
          THD *thd= YYTHD;
          if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
            YYABORT;
          $$->user.str= thd->priv_user;
          $$->user.length= strlen(thd->priv_user);
          if (*thd->priv_host != 0)
          {
            $$->host.str= thd->priv_host;
            $$->host.length= strlen(thd->priv_host);
          }
          else
          {
            $$->host.str= (char *) "%";
            $$->host.length= 1;
          }
	};
unknown's avatar
unknown committed
5102 5103 5104 5105 5106

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
unknown's avatar
unknown committed
5107
	| ADDDATE_SYM		{}
unknown's avatar
unknown committed
5108
	| AFTER_SYM		{}
5109
	| AGAINST		{}
unknown's avatar
unknown committed
5110
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
5111
	| ANY_SYM		{}
unknown's avatar
unknown committed
5112
	| ASCII_SYM		{}
unknown's avatar
unknown committed
5113
	| AUTO_INC		{}
unknown's avatar
unknown committed
5114 5115
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
5116
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
5117
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
5118
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
5119
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
5120 5121
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
5122
	| BOOLEAN_SYM		{}
5123
	| BYTE_SYM		{}
unknown's avatar
unknown committed
5124
	| BTREE_SYM		{}
unknown's avatar
unknown committed
5125
	| CACHE_SYM		{}
5126
	| CHANGED		{}
5127
	| CHARSET		{}
unknown's avatar
unknown committed
5128
	| CHECKSUM_SYM		{}
5129
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
5130
	| CLIENT_SYM		{}
5131
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
5132
	| COLLATION_SYM		{}
unknown's avatar
unknown committed
5133
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
5134
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
5135
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
5136
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
5137
	| CONCURRENT		{}
5138
	| CONSISTENT_SYM	{}
5139
	| CUBE_SYM		{}
unknown's avatar
unknown committed
5140 5141 5142 5143
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
unknown's avatar
unknown committed
5144
        | DEALLOCATE_SYM        {}
unknown's avatar
unknown committed
5145
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
5146 5147
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
5148
	| DISCARD		{}
unknown's avatar
unknown committed
5149
	| DO_SYM		{}
unknown's avatar
unknown committed
5150 5151
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
unknown's avatar
unknown committed
5152 5153 5154
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
unknown's avatar
unknown committed
5155
	| ENGINE_SYM		{}
unknown's avatar
unknown committed
5156
	| ENGINES_SYM		{}
5157
	| ERRORS		{}
unknown's avatar
unknown committed
5158
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
5159
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
5160
	| EXECUTE_SYM		{}
5161
        | EXPANSION_SYM         {}
unknown's avatar
unknown committed
5162
	| EXTENDED_SYM		{}
5163
	| FAST_SYM		{}
unknown's avatar
unknown committed
5164 5165
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
5166
	| FULL			{}
unknown's avatar
unknown committed
5167 5168 5169 5170
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
5171
	| GEOMETRY_SYM		{}
5172
	| GEOMETRYCOLLECTION	{}
5173
	| GET_FORMAT		{}
unknown's avatar
unknown committed
5174
	| GRANTS		{}
unknown's avatar
unknown committed
5175
	| GLOBAL_SYM		{}
5176
	| HANDLER_SYM		{}
unknown's avatar
unknown committed
5177
	| HASH_SYM		{}
5178
	| HELP_SYM		{}
unknown's avatar
unknown committed
5179 5180 5181
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
5182
	| IMPORT		{}
unknown's avatar
unknown committed
5183
	| INDEXES		{}
unknown's avatar
unknown committed
5184
	| ISOLATION		{}
unknown's avatar
unknown committed
5185
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
5186
	| INNOBASE_SYM		{}
5187
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
5188
	| RELAY_THREAD		{}
5189
	| LAST_SYM		{}
unknown's avatar
unknown committed
5190
	| LEAVES                {}
unknown's avatar
unknown committed
5191
	| LEVEL_SYM		{}
5192
	| LINESTRING		{}
unknown's avatar
unknown committed
5193
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
5194
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
5195 5196 5197 5198 5199 5200 5201 5202 5203
	| 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
5204
	| MASTER_SERVER_ID_SYM  {}
unknown's avatar
unknown committed
5205
	| MASTER_CONNECT_RETRY_SYM	{}
unknown's avatar
unknown committed
5206 5207 5208 5209 5210 5211
	| 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
5212 5213 5214
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
5215
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
5216
	| MICROSECOND_SYM	{}
unknown's avatar
unknown committed
5217 5218 5219
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
5220
	| MODE_SYM		{}
unknown's avatar
unknown committed
5221
	| MONTH_SYM		{}
5222 5223 5224
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
unknown's avatar
unknown committed
5225
	| NAMES_SYM		{}
unknown's avatar
unknown committed
5226 5227
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
unknown's avatar
unknown committed
5228
	| NDBCLUSTER_SYM	{}
5229
	| NEXT_SYM		{}
unknown's avatar
unknown committed
5230
	| NEW_SYM		{}
unknown's avatar
unknown committed
5231
	| NO_SYM		{}
5232
	| NONE_SYM		{}
unknown's avatar
unknown committed
5233
	| NVARCHAR_SYM		{}
unknown's avatar
unknown committed
5234
	| OFFSET_SYM		{}
unknown's avatar
unknown committed
5235
	| OLD_PASSWORD		{}
5236
	| ONE_SHOT_SYM		{}
5237
	| OPEN_SYM		{}
unknown's avatar
unknown committed
5238
	| PACK_KEYS_SYM		{}
5239
	| PARTIAL		{}
unknown's avatar
unknown committed
5240
	| PASSWORD		{}
5241
	| POINT_SYM		{}
5242
	| POLYGON		{}
unknown's avatar
unknown committed
5243
        | PREPARE_SYM           {}
5244
	| PREV_SYM		{}
unknown's avatar
unknown committed
5245 5246
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
5247
	| QUERY_SYM		{}
5248
	| QUICK			{}
unknown's avatar
unknown committed
5249
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
5250 5251
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
5252
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
5253
	| RAID_TYPE		{}
unknown's avatar
unknown committed
5254 5255
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
5256 5257
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
5258
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
5259
	| REPLICATION		{}
unknown's avatar
unknown committed
5260
	| RESET_SYM		{}
5261
	| RESOURCES		{}
unknown's avatar
unknown committed
5262
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
5263
	| ROLLBACK_SYM		{}
5264
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
5265 5266 5267
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
unknown's avatar
unknown committed
5268
	| RTREE_SYM		{}
5269
	| SAVEPOINT_SYM		{}
unknown's avatar
unknown committed
5270
	| SECOND_SYM		{}
5271
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
5272 5273
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
5274
	| SIGNED_SYM		{}
5275
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
5276
	| SHARE_SYM		{}
unknown's avatar
unknown committed
5277
	| SHUTDOWN		{}
unknown's avatar
unknown committed
5278
	| SLAVE			{}
5279
	| SNAPSHOT_SYM		{}
unknown's avatar
unknown committed
5280
	| SOUNDS_SYM		{}
unknown's avatar
unknown committed
5281
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
5282
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
5283
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
5284
	| SQL_THREAD		{}
unknown's avatar
unknown committed
5285 5286 5287
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
unknown's avatar
unknown committed
5288
	| STORAGE_SYM		{}
unknown's avatar
unknown committed
5289
	| STRING_SYM		{}
unknown's avatar
unknown committed
5290
	| SUBDATE_SYM		{}
unknown's avatar
unknown committed
5291
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
5292
	| SUPER_SYM		{}
unknown's avatar
unknown committed
5293
	| TABLESPACE		{}
unknown's avatar
unknown committed
5294 5295
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
5296
	| TRANSACTION_SYM	{}
5297
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
5298 5299 5300
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
unknown's avatar
unknown committed
5301
	| TYPES_SYM		{}
unknown's avatar
unknown committed
5302
        | UDF_RETURNS_SYM       {}
unknown's avatar
unknown committed
5303
	| UDF_SYM		{}
unknown's avatar
unknown committed
5304
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
5305
	| UNICODE_SYM		{}
5306
	| UNTIL_SYM		{}
5307
	| USER			{}
unknown's avatar
unknown committed
5308
	| USE_FRM		{}
unknown's avatar
unknown committed
5309
	| VARIABLES		{}
5310
	| VALUE_SYM		{}
5311
	| WARNINGS		{}
unknown's avatar
unknown committed
5312
	| WORK_SYM		{}
5313
	| X509_SYM		{}
unknown's avatar
unknown committed
5314 5315
	| YEAR_SYM		{}
	;
unknown's avatar
unknown committed
5316 5317 5318 5319 5320 5321

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
5322 5323
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
5324
	  lex->option_type=OPT_SESSION;
unknown's avatar
unknown committed
5325
	  lex->var_list.empty();
5326
          lex->one_shot_set= 0;
unknown's avatar
unknown committed
5327
	}
5328 5329 5330
	option_value_list
	{}
	;
unknown's avatar
unknown committed
5331 5332 5333

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
5334
	| OPTION {};
unknown's avatar
unknown committed
5335 5336

option_value_list:
unknown's avatar
unknown committed
5337 5338 5339 5340 5341 5342 5343 5344
	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; }
5345
	| ONE_SHOT_SYM	{ Lex->option_type= OPT_SESSION; Lex->one_shot_set= 1; }
unknown's avatar
unknown committed
5346 5347 5348 5349
	;

opt_var_type:
	/* empty */	{ $$=OPT_SESSION; }
unknown's avatar
unknown committed
5350
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
5351 5352 5353 5354 5355 5356
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
5357
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
5358 5359 5360
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
5361 5362

option_value:
unknown's avatar
unknown committed
5363
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
5364
	{
unknown's avatar
unknown committed
5365
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
5366
	}
unknown's avatar
unknown committed
5367
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
5368
	  {
unknown's avatar
unknown committed
5369
	    LEX *lex=Lex;
unknown's avatar
unknown committed
5370 5371
	    lex->var_list.push_back(new set_var(lex->option_type, $1.var,
						&$1.base_name, $3));
unknown's avatar
unknown committed
5372
	  }
unknown's avatar
unknown committed
5373
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
5374 5375
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
5376 5377
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4.var,
						&$4.base_name, $6));
unknown's avatar
unknown committed
5378 5379 5380 5381
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
unknown's avatar
unknown committed
5382 5383 5384
	    LEX_STRING tmp;
	    tmp.str=0;
	    tmp.length=0;
unknown's avatar
unknown committed
5385
	    lex->var_list.push_back(new set_var(lex->option_type,
unknown's avatar
unknown committed
5386
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
5387
						&tmp,
unknown's avatar
unknown committed
5388
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
5389
	  }
5390
	| charset old_or_new_charset_name_or_default
unknown's avatar
unknown committed
5391
	{
unknown's avatar
unknown committed
5392
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
5393
	  LEX *lex= Lex;
5394
	  $2= $2 ? $2: global_system_variables.character_set_client;
5395
	  lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
unknown's avatar
unknown committed
5396
	}
5397
	| NAMES_SYM charset_name_or_default opt_collate
5398
	{
unknown's avatar
unknown committed
5399
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
5400
	  LEX *lex= Lex;
5401
	  $2= $2 ? $2 : global_system_variables.character_set_client;
5402 5403
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
5404
	  {
unknown's avatar
unknown committed
5405 5406
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
5407
	  }
5408
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
5409
	}
unknown's avatar
unknown committed
5410
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
5411
	  {
5412
	    THD *thd=YYTHD;
unknown's avatar
unknown committed
5413
	    LEX_USER *user;
unknown's avatar
unknown committed
5414
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
unknown's avatar
unknown committed
5415 5416 5417
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
5418
	    thd->lex->var_list.push_back(new set_var_password(user, $3));
unknown's avatar
unknown committed
5419 5420
	  }
	| PASSWORD FOR_SYM user equal text_or_password
unknown's avatar
unknown committed
5421
	  {
unknown's avatar
unknown committed
5422 5423
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
5424
	;
unknown's avatar
unknown committed
5425

unknown's avatar
unknown committed
5426 5427 5428 5429 5430 5431
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
unknown's avatar
unknown committed
5432 5433 5434
	  $$.var= tmp;
	  $$.base_name.str=0;
	  $$.base_name.length=0;
5435 5436 5437 5438 5439 5440
          /*
            If this is time_zone variable we should open time zone
            describing tables 
          */
          if (tmp == &sys_time_zone)
	    Lex->time_zone_tables_used= &fake_time_zone_tables_list;
unknown's avatar
unknown committed
5441
	}
5442 5443
	| ident '.' ident
	  {
5444 5445
            if (check_reserved_words(&$1))
            {
5446
	      yyerror(ER(ER_SYNTAX_ERROR));
5447 5448
              YYABORT;
            }
5449 5450 5451 5452 5453
	    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
5454 5455
	    $$.var= tmp;
	    $$.base_name= $1;
5456 5457 5458 5459 5460 5461 5462 5463
	  }
	| 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
5464 5465 5466
	    $$.var= tmp;
	    $$.base_name.str=    (char*) "default";
	    $$.base_name.length= 7;
5467
	  }
5468
        ;
unknown's avatar
unknown committed
5469 5470 5471 5472 5473 5474 5475

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

unknown's avatar
unknown committed
5477 5478 5479 5480
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
5481
	    $$= $3.length ? YYTHD->variables.old_passwords ?
unknown's avatar
unknown committed
5482 5483 5484 5485 5486 5487 5488 5489
	        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;
5490 5491
	  }
          ;
unknown's avatar
unknown committed
5492

unknown's avatar
unknown committed
5493

unknown's avatar
unknown committed
5494
set_expr_or_default:
unknown's avatar
unknown committed
5495 5496
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
5497 5498
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
5499
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
unknown's avatar
unknown committed
5500
	;
unknown's avatar
unknown committed
5501 5502


unknown's avatar
unknown committed
5503 5504 5505 5506 5507 5508 5509
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
5510 5511 5512
	table_lock_list
	{}
	;
unknown's avatar
unknown committed
5513 5514 5515

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
5516
	| TABLES;
unknown's avatar
unknown committed
5517 5518 5519

table_lock_list:
	table_lock
unknown's avatar
unknown committed
5520
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
5521 5522 5523

table_lock:
	table_ident opt_table_alias lock_option
5524
	{
unknown's avatar
unknown committed
5525
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
5526 5527
	   YYABORT;
	}
5528
        ;
unknown's avatar
unknown committed
5529 5530 5531

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
5532
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
unknown's avatar
unknown committed
5533
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
5534 5535
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
5536 5537

unlock:
5538 5539
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
5540 5541


5542
/*
unknown's avatar
unknown committed
5543
** Handler: direct access to ISAM functions
5544 5545 5546 5547 5548
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
5549 5550
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
unknown's avatar
unknown committed
5551
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
5552 5553
	    YYABORT;
	}
unknown's avatar
unknown committed
5554
	| HANDLER_SYM table_ident_nodb CLOSE_SYM
5555
	{
5556 5557
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
unknown's avatar
unknown committed
5558
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
5559 5560
	    YYABORT;
	}
unknown's avatar
unknown committed
5561
	| HANDLER_SYM table_ident_nodb READ_SYM
5562
	{
unknown's avatar
unknown committed
5563 5564 5565
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
5566 5567
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
unknown's avatar
unknown committed
5568
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
5569
	    YYABORT;
unknown's avatar
unknown committed
5570
        }
5571
        handler_read_or_scan where_clause opt_limit_clause {}
5572
        ;
5573

unknown's avatar
unknown committed
5574 5575
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
5576 5577
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
5578 5579 5580

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
5581 5582
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
5583 5584 5585 5586 5587 5588

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;  }
5589 5590
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
5591 5592
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
5593
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
5594
	  if (!(lex->insert_list = new List_item))
5595
	    YYABORT;
5596 5597
	} '(' values ')' { }
        ;
5598 5599

handler_rkey_mode:
unknown's avatar
unknown committed
5600 5601 5602 5603
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
5604 5605
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
5606

unknown's avatar
unknown committed
5607 5608 5609 5610 5611
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
5612 5613 5614 5615 5616
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
5617
	  lex->select_lex.db=0;
5618 5619
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
5620
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
5621
	}
5622 5623 5624 5625 5626
	revoke_command
	{}
        ;

revoke_command:
5627 5628
	grant_privileges ON opt_table FROM user_list
	{}
5629
	|
unknown's avatar
unknown committed
5630
	ALL opt_privileges ',' GRANT OPTION FROM user_list
5631 5632 5633
	{
	  Lex->sql_command = SQLCOM_REVOKE_ALL;
	}
5634
	;
unknown's avatar
unknown committed
5635 5636 5637 5638

grant:
	GRANT
	{
unknown's avatar
unknown committed
5639 5640 5641
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
5642 5643
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
5644
	  lex->select_lex.db= 0;
5645 5646
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
5647
	  bzero((char *)&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
5648 5649
	}
	grant_privileges ON opt_table TO_SYM user_list
5650 5651 5652
	require_clause grant_options
	{}
	;
unknown's avatar
unknown committed
5653 5654 5655

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
5656
	| ALL opt_privileges	{ Lex->grant = GLOBAL_ACLS;}
5657
        ;
unknown's avatar
unknown committed
5658

unknown's avatar
unknown committed
5659 5660 5661 5662 5663
opt_privileges:
	/* empty */
	| PRIVILEGES
	;

unknown's avatar
unknown committed
5664 5665
grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
5666
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
5667 5668

grant_privilege:
unknown's avatar
unknown committed
5669
	SELECT_SYM	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
5670 5671 5672
	| 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
5673 5674
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
5675
	| INDEX_SYM	{ Lex->grant |= INDEX_ACL;}
unknown's avatar
unknown committed
5676 5677 5678
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
unknown's avatar
unknown committed
5679
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
5680 5681 5682 5683
	| 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
5684 5685 5686 5687 5688 5689 5690 5691
	| 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
5692

unknown's avatar
unknown committed
5693

5694 5695
opt_and:
	/* empty */	{}
unknown's avatar
unknown committed
5696
	| AND_SYM	{}
5697 5698 5699 5700 5701 5702 5703 5704 5705
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
unknown's avatar
unknown committed
5706 5707 5708 5709
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
5710
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
5711 5712 5713 5714 5715 5716 5717 5718 5719
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
5720
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
5721 5722 5723 5724 5725 5726 5727 5728 5729
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
5730
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
5731 5732 5733 5734 5735
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
5736

unknown's avatar
unknown committed
5737 5738 5739
opt_table:
	'*'
	  {
5740
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5741
	    lex->current_select->db= lex->thd->db;
unknown's avatar
unknown committed
5742
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5743 5744
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5745
	    {
5746
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
5747
	      YYABORT;
unknown's avatar
unknown committed
5748
	    }
unknown's avatar
unknown committed
5749 5750 5751
	  }
	| ident '.' '*'
	  {
5752
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5753
	    lex->current_select->db = $1.str;
unknown's avatar
unknown committed
5754
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5755 5756
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5757
	    {
5758
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
5759 5760 5761 5762 5763
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
5764
	    LEX *lex= Lex;
unknown's avatar
unknown committed
5765
	    lex->current_select->db = NULL;
unknown's avatar
unknown committed
5766 5767
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
5768
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
5769
	    {
5770
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
5771 5772 5773 5774 5775
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
5776
	    LEX *lex=Lex;
unknown's avatar
unknown committed
5777
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
unknown's avatar
unknown committed
5778
	      YYABORT;
unknown's avatar
unknown committed
5779
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
5780
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
5781 5782
	  }
          ;
unknown's avatar
unknown committed
5783 5784 5785


user_list:
5786 5787 5788 5789 5790 5791 5792
	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
5793 5794 5795 5796 5797 5798 5799 5800


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
5801
             if (YYTHD->variables.old_passwords)
5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818
             {
               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
5819 5820 5821 5822 5823
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
5824 5825
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
5826 5827 5828


opt_column_list:
unknown's avatar
unknown committed
5829 5830 5831 5832 5833
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
5834
	| '(' column_list ')';
unknown's avatar
unknown committed
5835 5836 5837

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
5838
	| column_list_id;
unknown's avatar
unknown committed
5839 5840 5841 5842

column_list_id:
	ident
	{
unknown's avatar
unknown committed
5843
	  String *new_str = new (YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
unknown's avatar
unknown committed
5844 5845
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
5846
	  LEX *lex=Lex;
unknown's avatar
unknown committed
5847 5848
	  while ((point=iter++))
	  {
5849 5850
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
5851 5852
		break;
	  }
unknown's avatar
unknown committed
5853
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
5854
	  if (point)
unknown's avatar
unknown committed
5855
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
5856
	  else
unknown's avatar
unknown committed
5857
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
5858 5859
	}
        ;
unknown's avatar
unknown committed
5860

unknown's avatar
unknown committed
5861 5862

require_clause: /* empty */
5863
        | REQUIRE_SYM require_list
5864 5865 5866
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
5867
        | REQUIRE_SYM SSL_SYM
5868 5869 5870
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
5871
        | REQUIRE_SYM X509_SYM
5872 5873 5874 5875 5876 5877 5878
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
5879
          ;
unknown's avatar
unknown committed
5880

unknown's avatar
unknown committed
5881
grant_options:
unknown's avatar
unknown committed
5882
	/* empty */ {}
unknown's avatar
unknown committed
5883
	| WITH grant_option_list;
unknown's avatar
unknown committed
5884

unknown's avatar
unknown committed
5885 5886
grant_option_list:
	grant_option_list grant_option {}
5887 5888
	| grant_option {}
        ;
unknown's avatar
unknown committed
5889 5890 5891

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
5892
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
5893
        {
5894
	  Lex->mqh.questions=$2;
5895
	  Lex->mqh.bits |= 1;
5896
	}
5897
        | MAX_UPDATES_PER_HOUR ULONG_NUM
5898
        {
5899
	  Lex->mqh.updates=$2;
5900
	  Lex->mqh.bits |= 2;
5901
	}
5902
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
5903
        {
5904
	  Lex->mqh.connections=$2;
5905
	  Lex->mqh.bits |= 4;
5906 5907
	}
        ;
5908

unknown's avatar
unknown committed
5909
begin:
5910
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN; Lex->start_transaction_opt= 0;} opt_work {}
5911
	;
unknown's avatar
unknown committed
5912 5913 5914

opt_work:
	/* empty */ {}
5915 5916
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
5917 5918

commit:
unknown's avatar
unknown committed
5919
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
5920 5921

rollback:
unknown's avatar
unknown committed
5922
	ROLLBACK_SYM
5923 5924 5925 5926 5927
	{
	  Lex->sql_command = SQLCOM_ROLLBACK;
	}
	| ROLLBACK_SYM TO_SYM SAVEPOINT_SYM ident
	{
unknown's avatar
unknown committed
5928
	  Lex->sql_command = SQLCOM_ROLLBACK_TO_SAVEPOINT;
5929 5930 5931 5932 5933 5934 5935 5936
	  Lex->savepoint_name = $4.str;
	};
savepoint:
	SAVEPOINT_SYM ident
	{
	  Lex->sql_command = SQLCOM_SAVEPOINT;
	  Lex->savepoint_name = $2.str;
	};
5937 5938

/*
unknown's avatar
unknown committed
5939
   UNIONS : glue selects together
5940 5941 5942
*/


5943
union_clause:
5944
	/* empty */ {}
unknown's avatar
unknown committed
5945 5946
	| union_list
	;
5947 5948

union_list:
5949
	UNION_SYM union_option
5950 5951 5952 5953 5954
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
5955
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
5956
	    YYABORT;
5957
	  }
5958
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
5959
	  {
5960
            yyerror(ER(ER_SYNTAX_ERROR));
5961 5962
	    YYABORT;
	  }
5963
	  if (mysql_new_select(lex, 0))
5964
	    YYABORT;
unknown's avatar
unknown committed
5965
          mysql_init_select(lex);
5966
	  lex->current_select->linkage=UNION_TYPE;
5967 5968 5969
          if ($2) /* UNION DISTINCT - remember position */
            lex->current_select->master_unit()->union_distinct=
                                                      lex->current_select;
unknown's avatar
unknown committed
5970
	}
5971
	select_init {}
5972
	;
5973 5974

union_opt:
unknown's avatar
unknown committed
5975
	union_list {}
unknown's avatar
unknown committed
5976 5977
	| optional_order_or_limit {}
	;
5978 5979

optional_order_or_limit:
5980
	/* Empty */ {}
5981 5982
	|
	  {
unknown's avatar
unknown committed
5983
	    THD *thd= YYTHD;
5984
	    LEX *lex= thd->lex;
unknown's avatar
unknown committed
5985
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
unknown's avatar
unknown committed
5986
	    SELECT_LEX *sel= lex->current_select;
unknown's avatar
unknown committed
5987
	    SELECT_LEX_UNIT *unit= sel->master_unit();
unknown's avatar
unknown committed
5988
	    SELECT_LEX *fake= unit->fake_select_lex;
unknown's avatar
unknown committed
5989 5990 5991 5992 5993 5994
	    if (fake)
	    {
	      unit->global_parameters= fake;
	      fake->no_table_names_allowed= 1;
	      lex->current_select= fake;
	    }
unknown's avatar
unknown committed
5995
	    thd->where= "global ORDER clause";
5996
	  }
5997
	order_or_limit
unknown's avatar
unknown committed
5998 5999
          {
	    THD *thd= YYTHD;
6000
	    thd->lex->current_select->no_table_names_allowed= 0;
unknown's avatar
unknown committed
6001 6002
	    thd->where= "";
          }
6003 6004 6005
	;

order_or_limit:
6006 6007
	order_clause opt_limit_clause_init
	| limit_clause
6008
	;
unknown's avatar
unknown committed
6009 6010

union_option:
6011 6012 6013 6014
	/* empty */ { $$=1; }
	| DISTINCT  { $$=1; }
	| ALL       { $$=0; }
        ;
6015

unknown's avatar
unknown committed
6016 6017
singlerow_subselect:
	subselect_start singlerow_subselect_init
unknown's avatar
unknown committed
6018 6019 6020 6021
	subselect_end
	{
	  $$= $2;
	};
6022

unknown's avatar
unknown committed
6023
singlerow_subselect_init:
6024
	select_init2
unknown's avatar
unknown committed
6025
	{
6026 6027
	  $$= new Item_singlerow_subselect(Lex->current_select->
					   master_unit()->first_select());
unknown's avatar
unknown committed
6028
	};
unknown's avatar
unknown committed
6029 6030

exists_subselect:
unknown's avatar
unknown committed
6031 6032 6033 6034 6035
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
6036 6037

exists_subselect_init:
6038
	select_init2
unknown's avatar
unknown committed
6039
	{
6040 6041
	  $$= new Item_exists_subselect(Lex->current_select->master_unit()->
					first_select());
unknown's avatar
unknown committed
6042
	};
6043

unknown's avatar
unknown committed
6044 6045 6046 6047 6048 6049 6050 6051
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
6052
  select_init2
unknown's avatar
unknown committed
6053
  {
unknown's avatar
unknown committed
6054
    $$= Lex->current_select->master_unit()->first_select();
unknown's avatar
unknown committed
6055 6056
  };

6057
subselect_start:
6058
	'(' SELECT_SYM
unknown's avatar
unknown committed
6059
	{
6060
	  LEX *lex=Lex;
6061
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
6062 6063
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
6064 6065
	  {
            yyerror(ER(ER_SYNTAX_ERROR));
6066 6067
	    YYABORT;
	  }
unknown's avatar
unknown committed
6068 6069 6070
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
6071 6072

subselect_end:
unknown's avatar
unknown committed
6073 6074 6075
	')'
	{
	  LEX *lex=Lex;
6076
	  lex->current_select = lex->current_select->return_after_parsing();
unknown's avatar
unknown committed
6077
	};
unknown's avatar
unknown committed
6078