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

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

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

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

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

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

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

unknown's avatar
unknown committed
41
extern void yyerror(const char*);
42
int yylex(void *yylval, void *yythd);
unknown's avatar
unknown committed
43

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

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

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

%pure_parser					/* We have threads */

%token	END_OF_INPUT

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

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

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

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

unknown's avatar
unknown committed
388 389 390
%token  ERRORS
%token  WARNINGS

unknown's avatar
unknown committed
391
%token	ASCII_SYM
unknown's avatar
unknown committed
392 393 394
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
unknown's avatar
unknown committed
395
%token	CHANGED
unknown's avatar
unknown committed
396 397 398 399 400 401
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
402
%token	FAST_SYM
unknown's avatar
unknown committed
403
%token	FLOAT_SYM
unknown's avatar
unknown committed
404
%token  GEOMETRY_SYM
unknown's avatar
unknown committed
405 406 407 408 409 410 411 412 413
%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
414
%token	QUICK
unknown's avatar
unknown committed
415
%token	REAL
unknown's avatar
unknown committed
416
%token	SIGNED_SYM
unknown's avatar
unknown committed
417 418 419 420 421 422 423 424
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
unknown's avatar
unknown committed
425
%token	ULONGLONG_NUM
unknown's avatar
unknown committed
426
%token	UNSIGNED
427 428 429
%token	VARBINARY
%token	VARCHAR
%token	VARYING
unknown's avatar
unknown committed
430 431
%token	ZEROFILL

unknown's avatar
unknown committed
432
%token	AGAINST
unknown's avatar
unknown committed
433 434 435 436 437 438
%token	ATAN
%token	BETWEEN_SYM
%token	BIT_AND
%token	BIT_OR
%token	CASE_SYM
%token	CONCAT
unknown's avatar
unknown committed
439
%token	CONCAT_WS
unknown's avatar
unknown committed
440 441 442 443 444 445 446 447 448 449
%token	CURDATE
%token	CURTIME
%token	DATABASE
%token	DATE_ADD_INTERVAL
%token	DATE_SUB_INTERVAL
%token	DAY_HOUR_SYM
%token	DAY_MINUTE_SYM
%token	DAY_SECOND_SYM
%token	DAY_SYM
%token	DECODE_SYM
unknown's avatar
unknown committed
450 451
%token	DES_ENCRYPT_SYM
%token	DES_DECRYPT_SYM
unknown's avatar
unknown committed
452 453 454 455 456 457 458 459 460 461
%token	ELSE
%token	ELT_FUNC
%token	ENCODE_SYM
%token	ENCRYPT
%token	EXPORT_SET
%token	EXTRACT_SYM
%token	FIELD_FUNC
%token	FORMAT_SYM
%token	FOR_SYM
%token	FROM_UNIXTIME
unknown's avatar
unknown committed
462 463
%token	GEOMCOLLFROMTEXT
%token	GEOMFROMTEXT
unknown's avatar
unknown committed
464
%token	GEOMFROMWKB
unknown's avatar
unknown committed
465
%token  GEOMETRYCOLLECTION
466
%token  GROUP_CONCAT_SYM
unknown's avatar
unknown committed
467 468 469 470 471 472
%token	GROUP_UNIQUE_USERS
%token	HOUR_MINUTE_SYM
%token	HOUR_SECOND_SYM
%token	HOUR_SYM
%token	IDENTIFIED_SYM
%token	IF
473
%token	INSERT_METHOD
unknown's avatar
unknown committed
474 475 476
%token	INTERVAL_SYM
%token	LAST_INSERT_ID
%token	LEFT
unknown's avatar
unknown committed
477
%token	LINEFROMTEXT
unknown's avatar
unknown committed
478
%token  LINESTRING
unknown's avatar
unknown committed
479 480
%token	LOCATE
%token	MAKE_SET_SYM
481
%token	MASTER_POS_WAIT
unknown's avatar
unknown committed
482 483
%token	MINUTE_SECOND_SYM
%token	MINUTE_SYM
unknown's avatar
unknown committed
484
%token	MODE_SYM
unknown's avatar
unknown committed
485 486
%token	MODIFY_SYM
%token	MONTH_SYM
unknown's avatar
unknown committed
487 488 489
%token	MLINEFROMTEXT
%token	MPOINTFROMTEXT
%token	MPOLYFROMTEXT
unknown's avatar
unknown committed
490 491 492
%token  MULTILINESTRING
%token  MULTIPOINT
%token  MULTIPOLYGON
unknown's avatar
unknown committed
493 494
%token	NOW_SYM
%token	PASSWORD
unknown's avatar
unknown committed
495
%token	POINTFROMTEXT
496
%token	POINT_SYM
unknown's avatar
unknown committed
497
%token	POLYFROMTEXT
unknown's avatar
unknown committed
498
%token  POLYGON
unknown's avatar
unknown committed
499 500 501 502 503 504 505
%token	POSITION_SYM
%token	PROCEDURE
%token	RAND
%token	REPLACE
%token	RIGHT
%token	ROUND
%token	SECOND_SYM
unknown's avatar
unknown committed
506
%token	SHARE_SYM
unknown's avatar
unknown committed
507 508 509 510 511 512 513 514 515 516 517 518 519 520
%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
%token	WEEK_SYM
%token	WHEN_SYM
unknown's avatar
unknown committed
521
%token	WORK_SYM
unknown's avatar
unknown committed
522 523 524
%token	YEAR_MONTH_SYM
%token	YEAR_SYM
%token	YEARWEEK
unknown's avatar
unknown committed
525 526 527
%token	BENCHMARK_SYM
%token	END
%token	THEN_SYM
unknown's avatar
unknown committed
528

unknown's avatar
unknown committed
529 530 531 532
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
533
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
534
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
535

unknown's avatar
unknown committed
536 537
%token  ISSUER_SYM
%token  SUBJECT_SYM
538
%token  CIPHER_SYM
unknown's avatar
unknown committed
539

unknown's avatar
unknown committed
540
%token  HELP
541
%token  BEFORE_SYM
unknown's avatar
unknown committed
542 543 544 545 546 547 548 549 550
%left   SET_VAR
%left	OR_OR_CONCAT OR
%left	AND
%left	BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
%left	EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP IN_SYM
%left	'|'
%left	'&'
%left	SHIFT_LEFT SHIFT_RIGHT
%left	'-' '+'
551
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
552
%left	NEG '~'
unknown's avatar
unknown committed
553 554
%left   XOR
%left   '^'
unknown's avatar
unknown committed
555
%right	NOT
unknown's avatar
unknown committed
556
%right	BINARY COLLATE_SYM
557 558 559 560 561 562
/* These don't actually affect the way the query is really evaluated, but
   they silence a few warnings for shift/reduce conflicts. */
%left	','
%left	STRAIGHT_JOIN JOIN_SYM
%nonassoc	CROSS INNER_SYM NATURAL LEFT RIGHT

unknown's avatar
unknown committed
563 564
%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
565
	ULONGLONG_NUM field_ident select_alias ident ident_or_text
566
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
unknown's avatar
unknown committed
567
	NCHAR_STRING
unknown's avatar
unknown committed
568 569 570 571 572

%type <lex_str_ptr>
	opt_table_alias

%type <table>
573
	table_ident references
unknown's avatar
unknown committed
574 575

%type <simple_string>
576
	remember_name remember_end opt_ident opt_db text_or_password
unknown's avatar
unknown committed
577 578 579
	opt_escape

%type <string>
580
	text_string opt_gconcat_separator
unknown's avatar
unknown committed
581 582

%type <num>
unknown's avatar
unknown committed
583
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
584
	udf_type if_exists opt_local opt_table_options table_options
unknown's avatar
unknown committed
585
	table_option opt_if_not_exists opt_var_type opt_var_ident_type
586
	delete_option opt_temporary all_or_any opt_distinct
unknown's avatar
unknown committed
587 588

%type <ulong_num>
589
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
590

unknown's avatar
unknown committed
591 592
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
593

unknown's avatar
unknown committed
594 595 596
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

unknown's avatar
unknown committed
597
%type <item>
unknown's avatar
unknown committed
598
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
599 600
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
	table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
601
	using_list expr_or_default set_expr_or_default interval_expr
unknown's avatar
unknown committed
602
	param_marker singlerow_subselect singlerow_subselect_init
unknown's avatar
unknown committed
603
	exists_subselect exists_subselect_init
unknown's avatar
unknown committed
604 605

%type <item_list>
unknown's avatar
unknown committed
606
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
607 608

%type <key_type>
609
	key_type opt_unique_or_fulltext
unknown's avatar
unknown committed
610

unknown's avatar
unknown committed
611 612 613
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
614 615 616 617 618 619 620
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
621
	join_table_list  join_table
unknown's avatar
unknown committed
622 623 624 625 626 627 628 629 630 631 632

%type <udf>
	UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
	UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM

%type <interval> interval

%type <db_type> table_types

%type <row_type> row_types

unknown's avatar
unknown committed
633
%type <tx_isolation> isolation_types
unknown's avatar
unknown committed
634

unknown's avatar
unknown committed
635 636
%type <ha_rkey_mode> handler_rkey_mode

unknown's avatar
unknown committed
637 638
%type <cast_type> cast_type

unknown's avatar
unknown committed
639 640 641 642 643 644
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

645
%type <charset>
646
	opt_collate
647 648
	charset_name
	charset_name_or_default
unknown's avatar
unknown committed
649 650
	old_or_new_charset_name
	old_or_new_charset_name_or_default
651 652
	collation_name
	collation_name_or_default
653

unknown's avatar
unknown committed
654 655
%type <variable> internal_variable_name

unknown's avatar
unknown committed
656 657
%type <select_lex> in_subselect in_subselect_init

unknown's avatar
unknown committed
658 659
%type <boolfunc2creator> comp_op

unknown's avatar
unknown committed
660
%type <NONE>
unknown's avatar
unknown committed
661
	query verb_clause create change select do drop insert replace insert2
662 663
	insert_values update delete truncate rename
	show describe load alter optimize flush
unknown's avatar
unknown committed
664
	reset purge begin commit rollback slave master_def master_defs
unknown's avatar
unknown committed
665
	repair restore backup analyze check start
666
	field_list field_list_item field_spec kill column_def key_def
unknown's avatar
unknown committed
667
	select_item_list select_item values_list no_braces
668
	opt_limit_clause delete_limit_clause fields opt_values values
unknown's avatar
unknown committed
669
	procedure_list procedure_list2 procedure_item
670
	when_list2 expr_list2  handler
unknown's avatar
unknown committed
671 672
	opt_precision opt_ignore opt_column opt_restrict
	grant revoke set lock unlock string_list field_options field_option
unknown's avatar
unknown committed
673
	field_opt_list opt_binary table_lock_list table_lock
674
	ref_list opt_on_delete opt_on_delete_list opt_on_delete_item use
unknown's avatar
unknown committed
675
	opt_delete_options opt_delete_option varchar nchar nvarchar
unknown's avatar
unknown committed
676
	opt_outer table_list table_name opt_option opt_place
unknown's avatar
unknown committed
677 678
	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
679
	grant_privilege grant_privilege_list
unknown's avatar
unknown committed
680
	flush_options flush_option
unknown's avatar
unknown committed
681 682
	equal optional_braces opt_key_definition key_usage_list2
	opt_mi_check_type opt_to mi_check_types normal_join
683
	table_to_table_list table_to_table opt_table_list opt_as
unknown's avatar
unknown committed
684
	handler_rkey_function handler_read_or_scan
unknown's avatar
unknown committed
685
	single_multi table_wild_list table_wild_one opt_wild
686
	union_clause union_list union_option
687
	precision subselect_start opt_and charset
688
	subselect_end select_var_list select_var_list_init help opt_len
689
END_OF_INPUT
unknown's avatar
unknown committed
690 691 692

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
693 694
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
unknown's avatar
unknown committed
695 696 697 698 699
%%


query:
	END_OF_INPUT
unknown's avatar
unknown committed
700
	{
701
	   THD *thd= YYTHD;
702
	   if (!thd->bootstrap &&
unknown's avatar
unknown committed
703
	      (!(thd->lex.select_lex.options & OPTION_FOUND_COMMENT)))
704
	   {
705
	     send_error(thd,ER_EMPTY_QUERY);
706
	     YYABORT;
707
	   }
708 709 710 711
	   else
	   {
	     thd->lex.sql_command = SQLCOM_EMPTY_QUERY;
	   }
unknown's avatar
unknown committed
712
	}
unknown's avatar
unknown committed
713
	| verb_clause END_OF_INPUT {};
unknown's avatar
unknown committed
714 715 716 717

verb_clause:
	  alter
	| analyze
718
	| backup
unknown's avatar
unknown committed
719 720 721 722 723 724 725
	| begin
	| change
	| check
	| commit
	| create
	| delete
	| describe
unknown's avatar
unknown committed
726
	| do
unknown's avatar
unknown committed
727 728 729 730 731 732 733 734
	| drop
	| grant
	| insert
	| flush
	| load
	| lock
	| kill
	| optimize
735
	| purge
736
	| rename
unknown's avatar
unknown committed
737 738
        | repair
	| replace
unknown's avatar
unknown committed
739
	| reset
740
	| restore
unknown's avatar
unknown committed
741 742 743 744
	| revoke
	| rollback
	| select
	| set
unknown's avatar
unknown committed
745
	| slave
unknown's avatar
unknown committed
746
	| start
unknown's avatar
unknown committed
747
	| show
748
	| truncate
749
	| handler
unknown's avatar
unknown committed
750 751
	| unlock
	| update
unknown's avatar
unknown committed
752 753
	| use
	| help;
754

unknown's avatar
unknown committed
755 756
/* help */

757
help:
758
       HELP_SYM ident_or_text
unknown's avatar
unknown committed
759
       {
760 761 762
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
763
       };
unknown's avatar
unknown committed
764 765 766 767

/* change master */

change:
unknown's avatar
unknown committed
768
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
769 770 771
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
unknown's avatar
unknown committed
772
	  bzero((char*) &lex->mi, sizeof(lex->mi));
773 774 775 776
        }
       master_defs
	{}
       ;
unknown's avatar
unknown committed
777 778 779

master_defs:
       master_def
unknown's avatar
unknown committed
780
       | master_defs ',' master_def;
unknown's avatar
unknown committed
781

unknown's avatar
unknown committed
782
master_def:
unknown's avatar
unknown committed
783
       MASTER_HOST_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
784 785 786 787
       {
	 Lex->mi.host = $3.str;
       }
       |
unknown's avatar
unknown committed
788
       MASTER_USER_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
789 790 791 792
       {
	 Lex->mi.user = $3.str;
       }
       |
unknown's avatar
unknown committed
793
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
794 795 796 797
       {
	 Lex->mi.password = $3.str;
       }
       |
unknown's avatar
unknown committed
798
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
799 800 801 802
       {
	 Lex->mi.log_file_name = $3.str;
       }
       |
unknown's avatar
unknown committed
803
       MASTER_PORT_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
804 805 806 807
       {
	 Lex->mi.port = $3;
       }
       |
unknown's avatar
unknown committed
808
       MASTER_LOG_POS_SYM EQ ulonglong_num
unknown's avatar
unknown committed
809 810 811 812
       {
	 Lex->mi.pos = $3;
       }
       |
unknown's avatar
unknown committed
813
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
814 815 816
       {
	 Lex->mi.connect_retry = $3;
       }
817
       |
unknown's avatar
unknown committed
818
       RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
819 820 821 822 823 824 825
       {
	 Lex->mi.relay_log_name = $3.str;
       }
       |
       RELAY_LOG_POS_SYM EQ ULONG_NUM
       {
	 Lex->mi.relay_log_pos = $3;
826 827
       }
       ;
unknown's avatar
unknown committed
828

unknown's avatar
unknown committed
829

unknown's avatar
unknown committed
830 831 832 833 834
/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
835
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
836 837
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
unknown's avatar
unknown committed
838
	  if (!lex->select_lex.add_table_to_list(thd,$5,
839
						 ($2 &
840 841
						  HA_LEX_CREATE_TMP_TABLE ?
						  &tmp_table_alias :
unknown's avatar
unknown committed
842 843
						  (LEX_STRING*) 0),
						 TL_OPTION_UPDATING,
unknown's avatar
unknown committed
844 845 846
						 ((using_update_log)?
						  TL_READ_NO_INSERT:
						  TL_READ)))
unknown's avatar
unknown committed
847 848 849 850 851 852 853
	    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
854
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
855
	  lex->create_info.table_charset= thd->db_charset;
unknown's avatar
unknown committed
856
	  lex->name=0;
unknown's avatar
unknown committed
857 858
	}
	create2
unknown's avatar
unknown committed
859
	{}
unknown's avatar
unknown committed
860
	| CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
unknown's avatar
unknown committed
861
	  {
unknown's avatar
unknown committed
862 863
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
unknown's avatar
unknown committed
864 865
	    if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
866
	      YYABORT;
unknown's avatar
unknown committed
867 868 869 870
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
unknown's avatar
unknown committed
871
	  }
872
	   '(' key_list ')'
unknown's avatar
unknown committed
873
	  {
unknown's avatar
unknown committed
874
	    LEX *lex=Lex;
unknown's avatar
unknown committed
875

876
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
unknown's avatar
unknown committed
877
	    lex->col_list.empty();
unknown's avatar
unknown committed
878
	  }
879 880 881
	| CREATE DATABASE opt_if_not_exists ident 
	  { Lex->create_info.table_charset=NULL; }
	  opt_create_database_options
unknown's avatar
unknown committed
882
	  {
unknown's avatar
unknown committed
883 884 885 886
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
unknown's avatar
unknown committed
887
	  }
unknown's avatar
unknown committed
888
	| CREATE udf_func_type UDF_SYM IDENT_sys
unknown's avatar
unknown committed
889
	  {
unknown's avatar
unknown committed
890 891
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
892
	    lex->udf.name = $4;
unknown's avatar
unknown committed
893
	    lex->udf.type= $2;
unknown's avatar
unknown committed
894
	  }
unknown's avatar
unknown committed
895
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
896
	  {
unknown's avatar
unknown committed
897 898 899
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
900 901
	  }
          ;
unknown's avatar
unknown committed
902 903

create2:
unknown's avatar
unknown committed
904
	'(' field_list ')' opt_create_table_options create3 {}
905
	| opt_create_table_options create3 {}
unknown's avatar
unknown committed
906 907 908 909 910 911 912
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
  	  ;
unknown's avatar
unknown committed
913 914

create3:
915 916
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
unknown's avatar
unknown committed
917
          {
unknown's avatar
unknown committed
918 919 920
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	    mysql_init_select(lex);
unknown's avatar
unknown committed
921
          }
922
          select_options select_item_list opt_select_from union_clause {}
923
          ;
unknown's avatar
unknown committed
924

925 926
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
927
	| AS	    {};
928

929 930 931 932 933 934 935 936 937 938 939
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
	  COLLATE_SYM collation_name_or_default	
	  { Lex->create_info.table_charset=$2; }
940 941 942
	| opt_default charset charset_name_or_default
	  { Lex->create_info.table_charset=$3; }
	;
943

unknown's avatar
unknown committed
944
opt_table_options:
unknown's avatar
unknown committed
945
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
946
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
947 948 949

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

unknown's avatar
unknown committed
952
table_option:
unknown's avatar
unknown committed
953
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
954 955

opt_if_not_exists:
unknown's avatar
unknown committed
956
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
957
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
958 959 960

opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
961
	| create_table_options;
unknown's avatar
unknown committed
962

unknown's avatar
unknown committed
963 964 965 966
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
967 968
create_table_options:
	create_table_option
969
	| create_table_option     create_table_options
unknown's avatar
unknown committed
970
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
971 972

create_table_option:
973 974 975 976
	TYPE_SYM opt_equal table_types          { Lex->create_info.db_type= $3; }
	| MAX_ROWS opt_equal ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS opt_equal ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH opt_equal ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
unknown's avatar
unknown committed
977 978
	| 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; }
979 980 981 982 983 984 985 986 987 988
	| 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 ')'
989 990 991
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
992 993
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
994 995
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
996 997
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
998
	    table_list->next=0;
999
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
1000
	  }
1001
	| opt_default charset opt_equal charset_name_or_default
1002
	  {
1003 1004 1005
	    Lex->create_info.table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1006 1007 1008 1009 1010
	| COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1011
	| 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
1012 1013 1014
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
	  { Lex->create_info.data_file_name= $4.str; }
	| INDEX DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; };
unknown's avatar
unknown committed
1015 1016 1017 1018 1019 1020

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
1021
	| MEMORY_SYM	{ $$= DB_TYPE_HEAP; }
unknown's avatar
unknown committed
1022
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
unknown's avatar
unknown committed
1023
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
unknown's avatar
unknown committed
1024 1025 1026 1027 1028

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
1029
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
1030 1031 1032 1033

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

1036 1037 1038
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
1039
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1040

unknown's avatar
unknown committed
1041
opt_select_from:
1042
	opt_limit_clause {}
unknown's avatar
unknown committed
1043
	| FROM DUAL_SYM {}
unknown's avatar
unknown committed
1044
	| select_from select_lock_type;
unknown's avatar
unknown committed
1045 1046 1047

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
1048
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
1049 1050 1051 1052

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
1053
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
1054 1055 1056

field_list:
	  field_list_item
unknown's avatar
unknown committed
1057
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
1058 1059 1060


field_list_item:
unknown's avatar
unknown committed
1061
	   column_def
1062 1063 1064 1065
         | key_def
         ;

column_def:
1066
	  field_spec check_constraint
unknown's avatar
unknown committed
1067 1068 1069 1070
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1071
	;
1072 1073

key_def:
unknown's avatar
unknown committed
1074
	key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1075
	  {
unknown's avatar
unknown committed
1076
	    LEX *lex=Lex;
1077
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
unknown's avatar
unknown committed
1078
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1079
	  }
1080
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1081
	  {
1082 1083 1084 1085 1086 1087 1088 1089
	    LEX *lex=Lex;
	    lex->key_list.push_back(new foreign_key($4, lex->col_list,
				    $8,
				    lex->ref_list,
				    lex->fk_delete_opt,
				    lex->fk_update_opt,
				    lex->fk_match_option));
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1090
	  }
1091
	| opt_constraint check_constraint
unknown's avatar
unknown committed
1092 1093
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1094 1095 1096 1097 1098 1099 1100
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
unknown's avatar
unknown committed
1101 1102 1103

opt_constraint:
	/* empty */
unknown's avatar
unknown committed
1104
	| CONSTRAINT opt_ident;
unknown's avatar
unknown committed
1105 1106 1107 1108

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1109 1110
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
1111
	   lex->default_value=lex->comment=0;
1112
	   lex->charset=NULL;
unknown's avatar
unknown committed
1113 1114 1115
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1116
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1117
	  if (add_field_to_list(lex->thd, $1.str,
unknown's avatar
unknown committed
1118
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1119
				lex->length,lex->dec,lex->type,
1120
				lex->default_value, lex->comment,
unknown's avatar
unknown committed
1121 1122
				lex->change,lex->interval,lex->charset,
				lex->uint_geom_type))
unknown's avatar
unknown committed
1123
	    YYABORT;
unknown's avatar
unknown committed
1124
	};
unknown's avatar
unknown committed
1125 1126

type:
1127
	int_type opt_len field_options	{ $$=$1; }
unknown's avatar
unknown committed
1128 1129 1130 1131 1132 1133
	| 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; }
1134 1135
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1136
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1137 1138 1139
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
unknown's avatar
unknown committed
1140 1141
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_STRING; 
1142
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1143 1144
	| nchar				{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; 
1145
					  Lex->charset=national_charset_info; }
1146
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1147
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1148 1149 1150
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
unknown's avatar
unknown committed
1151 1152
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
1153
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1154
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1155
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1156
					  $$=FIELD_TYPE_VAR_STRING; }
1157
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
unknown's avatar
unknown committed
1158 1159
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1160 1161
	| TIMESTAMP
	  {
1162
	    if (YYTHD->variables.sql_mode & MODE_SAPDB)
1163 1164
	      $$=FIELD_TYPE_DATETIME;
	    else
1165
	      $$=FIELD_TYPE_TIMESTAMP;
1166
	   }
unknown's avatar
unknown committed
1167 1168 1169
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
unknown's avatar
unknown committed
1170
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1171
					  $$=FIELD_TYPE_TINY_BLOB; }
unknown's avatar
unknown committed
1172
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1173
					  $$=FIELD_TYPE_BLOB; }
unknown's avatar
unknown committed
1174
	| GEOMETRY_SYM			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1175
					  Lex->uint_geom_type= (uint) Field::GEOM_GEOMETRY;
unknown's avatar
unknown committed
1176
					  $$=FIELD_TYPE_GEOMETRY; }
1177
	| GEOMETRYCOLLECTION		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1178
					  Lex->uint_geom_type= (uint) Field::GEOM_GEOMETRYCOLLECTION;
1179
					  $$=FIELD_TYPE_GEOMETRY; }
1180
	| POINT_SYM			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1181
					  Lex->uint_geom_type= (uint) Field::GEOM_POINT;
1182 1183
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOINT			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1184
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTIPOINT;
1185 1186
					  $$=FIELD_TYPE_GEOMETRY; }
	| LINESTRING			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1187
					  Lex->uint_geom_type= (uint) Field::GEOM_LINESTRING;
1188 1189
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTILINESTRING		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1190
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTILINESTRING;
1191 1192
					  $$=FIELD_TYPE_GEOMETRY; }
	| POLYGON			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1193
					  Lex->uint_geom_type= (uint) Field::GEOM_POLYGON;
1194 1195
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOLYGON			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1196
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTIPOLYGON;
1197
					  $$=FIELD_TYPE_GEOMETRY; }
unknown's avatar
unknown committed
1198
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1199
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1200
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1201
					  $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1202
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1203
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1204 1205
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1206
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1207 1208
	| MEDIUMTEXT opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT opt_binary		{ $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1209 1210 1211 1212
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1213 1214
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1215
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1216
	  {
unknown's avatar
unknown committed
1217 1218
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1219 1220
	    $$=FIELD_TYPE_ENUM;
	  }
1221
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1222
	  {
unknown's avatar
unknown committed
1223 1224
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1225
	    $$=FIELD_TYPE_SET;
1226
	  }
1227
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1228 1229 1230 1231 1232 1233
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
1234
	;
unknown's avatar
unknown committed
1235 1236 1237

char:
	CHAR_SYM {}
unknown's avatar
unknown committed
1238 1239 1240 1241 1242 1243
	;

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

unknown's avatar
unknown committed
1245 1246 1247
varchar:
	char VARYING {}
	| VARCHAR {}
unknown's avatar
unknown committed
1248 1249 1250 1251 1252 1253 1254 1255
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
unknown's avatar
unknown committed
1256 1257 1258 1259 1260 1261

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1262
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1263 1264

real_type:
1265
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1266 1267
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1268
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1269 1270 1271 1272 1273


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1274
	| precision		{};
unknown's avatar
unknown committed
1275 1276 1277 1278 1279 1280

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1281
	};
unknown's avatar
unknown committed
1282 1283 1284

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1285
	| field_opt_list	{};
unknown's avatar
unknown committed
1286 1287 1288

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1289
	| field_option {};
unknown's avatar
unknown committed
1290 1291

field_option:
unknown's avatar
unknown committed
1292
	SIGNED_SYM	{}
1293
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1294
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1295 1296

opt_len:
1297 1298
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1299 1300 1301

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1302
	| precision	{};
unknown's avatar
unknown committed
1303 1304 1305

opt_attribute:
	/* empty */ {}
unknown's avatar
unknown committed
1306
	| opt_attribute_list {};
unknown's avatar
unknown committed
1307 1308 1309

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1310
	| attribute;
unknown's avatar
unknown committed
1311 1312 1313 1314 1315 1316

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
	| DEFAULT literal { Lex->default_value=$2; }
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1317
	| SERIAL_SYM DEFAULT VALUE_SYM
unknown's avatar
unknown committed
1318 1319
	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; }
	| opt_primary KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
unknown's avatar
unknown committed
1320
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1321
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
1322
	| COMMENT_SYM text_literal { Lex->comment= $2; }
unknown's avatar
unknown committed
1323 1324
	| COLLATE_SYM collation_name 
	  { 
unknown's avatar
unknown committed
1325
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
unknown's avatar
unknown committed
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $2->name,Lex->charset->csname);
	      YYABORT;
	    }
	    else
	    {
	      Lex->charset=$2;
	    }
	  }
	;
unknown's avatar
unknown committed
1337

1338 1339 1340 1341
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
unknown's avatar
unknown committed
1342

1343
charset_name:
1344
	ident_or_text
1345
	{
unknown's avatar
unknown committed
1346
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
1347
	  {
1348
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1349 1350
	    YYABORT;
	  }
unknown's avatar
unknown committed
1351 1352 1353
	}
	| BINARY { $$= &my_charset_bin; }
	;
1354

1355 1356 1357
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1358

unknown's avatar
unknown committed
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376

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

1377
collation_name:
1378
	ident_or_text
1379 1380 1381 1382 1383 1384 1385 1386
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	};

1387 1388
opt_collate:
	/* empty */	{ $$=NULL; }
unknown's avatar
unknown committed
1389
	| COLLATE_SYM collation_name_or_default { $$=$2; }
1390 1391
	;

1392 1393 1394 1395
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1396 1397 1398 1399
opt_default:
	/* empty */	{}
	| DEFAULT	{};

unknown's avatar
unknown committed
1400
opt_binary:
1401
	/* empty */			{ Lex->charset=NULL; }
unknown's avatar
unknown committed
1402 1403 1404
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
	| BINARY			{ Lex->charset=&my_charset_bin; }
unknown's avatar
unknown committed
1405 1406 1407 1408 1409 1410 1411 1412
	| UNICODE_SYM
	{
	  if (!(Lex->charset=get_charset_by_name("ucs2",MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1413
	| charset charset_name	{ Lex->charset=$2; } ;
unknown's avatar
unknown committed
1414

unknown's avatar
unknown committed
1415 1416 1417
opt_primary:
	/* empty */
	| PRIMARY_SYM
1418
	;
unknown's avatar
unknown committed
1419

unknown's avatar
unknown committed
1420
references:
1421 1422
	REFERENCES table_ident
	{
1423
	  LEX *lex=Lex;
1424 1425 1426 1427 1428 1429
	  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
1430
	};
1431

1432
opt_ref_list:
unknown's avatar
unknown committed
1433
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1434
	| '(' ref_list ')' opt_on_delete {};
1435 1436 1437

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

unknown's avatar
unknown committed
1440 1441 1442

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1443
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1444 1445 1446

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1447
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1448 1449

opt_on_delete_item:
1450 1451 1452 1453
	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
1454
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1455 1456

delete_option:
1457 1458 1459 1460
	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
1461
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1462 1463 1464 1465

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1466 1467
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
unknown's avatar
unknown committed
1468 1469
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; }
unknown's avatar
unknown committed
1470
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1471
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1472 1473 1474

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1475
	| INDEX {};
unknown's avatar
unknown committed
1476 1477 1478 1479

keys_or_index:
	KEYS {}
	| INDEX {}
unknown's avatar
unknown committed
1480
	| INDEXES {};
unknown's avatar
unknown committed
1481

1482
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1483 1484
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1485
	| SPATIAL_SYM	{ $$= Key::SPATIAL; };
unknown's avatar
unknown committed
1486 1487

key_alg:
1488
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1489
	| USING opt_btree_or_rtree { $$= $2; }
unknown's avatar
unknown committed
1490
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
unknown's avatar
unknown committed
1491 1492 1493 1494

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
	| RTREE_SYM	{ $$= HA_KEY_ALG_RTREE; }
unknown's avatar
unknown committed
1495
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1496 1497 1498

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1499
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1500 1501 1502

key_part:
	ident			{ $$=new key_part_spec($1.str); }
unknown's avatar
unknown committed
1503
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
unknown's avatar
unknown committed
1504 1505 1506

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

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1511
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1512 1513 1514 1515 1516 1517 1518 1519

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1520
	  THD *thd= YYTHD;
1521
	  LEX *lex=&thd->lex;
unknown's avatar
unknown committed
1522 1523
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
unknown's avatar
unknown committed
1524 1525
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1526 1527 1528 1529 1530 1531 1532
	    YYABORT;
	  lex->drop_primary=0;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
	  lex->drop_list.empty();
	  lex->alter_list.empty();
1533
          lex->select_lex.init_order();
1534
	  lex->select_lex.db=lex->name=0;
1535
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
unknown's avatar
unknown committed
1536
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1537
	  lex->create_info.table_charset= thd->db_charset;
1538
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1539 1540
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
unknown's avatar
unknown committed
1541
	}
1542 1543
	alter_list
	{}
1544
	| ALTER DATABASE ident opt_create_database_options
1545 1546 1547 1548
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1549
	  };
1550 1551


unknown's avatar
unknown committed
1552
alter_list:
unknown's avatar
unknown committed
1553
        | alter_list_item
unknown's avatar
unknown committed
1554
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1555 1556

add_column:
unknown's avatar
unknown committed
1557
	ADD opt_column { Lex->change=0; };
unknown's avatar
unknown committed
1558 1559

alter_list_item:
1560 1561
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1562
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1563 1564 1565 1566 1567
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1568
          field_spec opt_place
unknown's avatar
unknown committed
1569 1570 1571 1572 1573
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
            lex->length=lex->dec=0; lex->type=0; lex->interval=0;
            lex->default_value=lex->comment=0;
unknown's avatar
unknown committed
1574
            lex->simple_alter=0;
unknown's avatar
unknown committed
1575 1576 1577 1578
          }
          type opt_attribute
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
1579
            if (add_field_to_list(lex->thd,$3.str,
unknown's avatar
unknown committed
1580 1581 1582
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
unknown's avatar
unknown committed
1583 1584
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
unknown's avatar
unknown committed
1585 1586 1587
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1588
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
					    $3.str)); lex->simple_alter=0;
	  }
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
	    lex->drop_primary=1; lex->simple_alter=0;
	  }
1599
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1600
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1601 1602 1603 1604 1605 1606
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1607 1608
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
unknown's avatar
unknown committed
1609
	| ALTER opt_column field_ident SET DEFAULT literal
unknown's avatar
unknown committed
1610 1611 1612 1613 1614
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
unknown's avatar
unknown committed
1615
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1616 1617 1618 1619 1620
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1621
	| RENAME opt_to table_ident
1622
	  {
1623
	    LEX *lex=Lex;
1624
	    lex->select_lex.db=$3->db.str;
1625
	    lex->name= $3->table.str;
1626
	  }
unknown's avatar
unknown committed
1627
        | create_table_options_space_separated { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1628
	| order_clause         { Lex->simple_alter=0; };
unknown's avatar
unknown committed
1629 1630 1631

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
1632
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
1633 1634 1635

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
unknown's avatar
unknown committed
1636
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
1637 1638 1639 1640

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
1641
	| CASCADE	{};
unknown's avatar
unknown committed
1642 1643 1644 1645

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
1646
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
1647 1648 1649 1650

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1651
	| EQ		{}
unknown's avatar
unknown committed
1652
	| AS		{};
unknown's avatar
unknown committed
1653

unknown's avatar
unknown committed
1654
/*
unknown's avatar
unknown committed
1655 1656 1657
  The first two deprecate the last two--delete the last two for 4.1 release
*/

unknown's avatar
unknown committed
1658
slave:
1659
	START_SYM SLAVE slave_thread_opts
unknown's avatar
unknown committed
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
        {
	  LEX *lex=Lex;
          lex->sql_command = SQLCOM_SLAVE_START;
	  lex->type = 0;
        }
        | STOP_SYM SLAVE slave_thread_opts
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_STOP;
	    lex->type = 0;
          }
	;
unknown's avatar
unknown committed
1672

unknown's avatar
unknown committed
1673 1674 1675 1676 1677
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

unknown's avatar
unknown committed
1678
slave_thread_opts:
1679 1680
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
unknown's avatar
unknown committed
1681
	;
1682 1683

slave_thread_opt_list:
unknown's avatar
unknown committed
1684
	slave_thread_opt
1685 1686
	| slave_thread_opt_list ',' slave_thread_opt
	;
1687 1688

slave_thread_opt:
1689
	/*empty*/	{}
unknown's avatar
unknown committed
1690
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
unknown's avatar
unknown committed
1691
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
unknown's avatar
unknown committed
1692
	;
1693

unknown's avatar
unknown committed
1694 1695 1696 1697 1698
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
unknown's avatar
unknown committed
1699
	table_list FROM TEXT_STRING_sys
unknown's avatar
unknown committed
1700 1701
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1702
        };
unknown's avatar
unknown committed
1703

unknown's avatar
unknown committed
1704 1705 1706 1707 1708
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
unknown's avatar
unknown committed
1709
	table_list TO_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
1710 1711
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1712
        };
unknown's avatar
unknown committed
1713

unknown's avatar
unknown committed
1714 1715 1716
repair:
	REPAIR table_or_tables
	{
unknown's avatar
unknown committed
1717 1718 1719
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1720
	}
1721 1722 1723
	table_list opt_mi_repair_type
	{}
	;
unknown's avatar
unknown committed
1724

unknown's avatar
unknown committed
1725
opt_mi_repair_type:
unknown's avatar
unknown committed
1726
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1727
	| mi_repair_types {};
unknown's avatar
unknown committed
1728

unknown's avatar
unknown committed
1729 1730
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
1731
	| mi_repair_type mi_repair_types {};
1732

unknown's avatar
unknown committed
1733
mi_repair_type:
unknown's avatar
unknown committed
1734
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1735
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1736
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
1737 1738

analyze:
1739
	ANALYZE_SYM table_or_tables
unknown's avatar
unknown committed
1740
	{
unknown's avatar
unknown committed
1741 1742 1743
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1744
	}
1745 1746 1747
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1748 1749

check:
unknown's avatar
unknown committed
1750
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
1751
	{
unknown's avatar
unknown committed
1752 1753 1754
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1755
	}
1756 1757 1758
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1759

unknown's avatar
unknown committed
1760 1761
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1762
	| mi_check_types {};
unknown's avatar
unknown committed
1763 1764 1765

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
1766
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
1767 1768 1769 1770 1771 1772

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

unknown's avatar
unknown committed
1775
optimize:
1776
	OPTIMIZE table_or_tables
unknown's avatar
unknown committed
1777
	{
unknown's avatar
unknown committed
1778 1779 1780
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1781
	}
1782 1783 1784
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1785

1786 1787 1788 1789 1790
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1791 1792 1793
	table_to_table_list
	{}
	;
1794 1795 1796

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
1797
	| table_to_table_list ',' table_to_table;
1798 1799 1800

table_to_table:
	table_ident TO_SYM table_ident
1801
	{
unknown's avatar
unknown committed
1802 1803
	  LEX *lex=Lex;	  
	  SELECT_LEX_NODE *sl= lex->current_select;
unknown's avatar
unknown committed
1804 1805 1806 1807
	  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))
1808
	    YYABORT;
1809
	};
1810

unknown's avatar
unknown committed
1811
/*
unknown's avatar
unknown committed
1812
  Select : retrieve data from table
unknown's avatar
unknown committed
1813 1814 1815 1816
*/


select:
unknown's avatar
unknown committed
1817
	select_init { Lex->sql_command=SQLCOM_SELECT; };
unknown's avatar
unknown committed
1818

1819
/* Need select_init2 for subselects. */
unknown's avatar
unknown committed
1820
select_init:
1821
	SELECT_SYM select_init2
1822
	|
1823 1824
	'(' SELECT_SYM select_part2 ')'
	  {
1825
	    LEX *lex= Lex;
unknown's avatar
unknown committed
1826
            SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1827
	    if (sel->set_braces(1))
1828 1829 1830 1831
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
1832 1833
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
1834 1835 1836 1837
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1838
            /* select in braces, can't contain global parameters */
1839
            sel->master_unit()->global_parameters=
1840
               sel->master_unit();
unknown's avatar
unknown committed
1841
          } union_opt;
1842

1843 1844
select_init2:
	select_part2
1845
        {
1846
	  LEX *lex= Lex;
unknown's avatar
unknown committed
1847
          SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1848
          if (lex->current_select->set_braces(0))
1849 1850 1851 1852
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1853 1854
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
1855 1856 1857 1858
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1859
	}
1860
	union_clause
1861 1862
	;

1863
select_part2:
unknown's avatar
unknown committed
1864 1865
	{
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1866
	  SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1867
	  if (lex->current_select == &lex->select_lex)
1868
	    lex->lock_option= TL_READ; /* Only for global SELECT */
unknown's avatar
unknown committed
1869 1870
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
unknown's avatar
unknown committed
1871
	}
unknown's avatar
unknown committed
1872
	select_options select_item_list select_into select_lock_type;
1873

unknown's avatar
unknown committed
1874
select_into:
1875 1876 1877 1878 1879 1880
	opt_limit_clause {}
	| FROM DUAL_SYM /* oracle compatibility: oracle always requires FROM
                           clause, and DUAL is system table without fields.
                           Is "SELECT 1 FROM DUAL" any better than
                           "SELECT 1" ? Hmmm :) */
        | into
unknown's avatar
unknown committed
1881
	| select_from
1882 1883
	| into select_from
	| select_from into;
unknown's avatar
unknown committed
1884 1885

select_from:
1886
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
unknown's avatar
unknown committed
1887 1888 1889

select_options:
	/* empty*/
unknown's avatar
unknown committed
1890
	| select_option_list;
unknown's avatar
unknown committed
1891 1892 1893

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
1894
	| select_option;
unknown's avatar
unknown committed
1895 1896

select_option:
1897
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1898 1899 1900 1901 1902 1903
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1904 1905 1906
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918
	| 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;
	  }
unknown's avatar
unknown committed
1919
	| SQL_NO_CACHE_SYM { Lex->uncacheable(); }
1920 1921 1922
	| SQL_CACHE_SYM    { Select->options|= OPTION_TO_QUERY_CACHE; }
	| ALL		{}
	;
unknown's avatar
unknown committed
1923

unknown's avatar
unknown committed
1924 1925 1926
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1927 1928
	  {
	    LEX *lex=Lex;
1929
	    lex->current_select->set_lock_for_tables(TL_WRITE);
1930
	    lex->safe_to_cache_query=0;
1931
	  }
unknown's avatar
unknown committed
1932
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1933 1934
	  {
	    LEX *lex=Lex;
1935 1936
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
1937
	    lex->safe_to_cache_query=0;
1938 1939
	  }
	;
unknown's avatar
unknown committed
1940

unknown's avatar
unknown committed
1941 1942 1943 1944 1945
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
1946 1947
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
unknown's avatar
unknown committed
1948
	      YYABORT;
1949
	    (thd->lex.current_select->select_lex()->with_wild)++;
unknown's avatar
unknown committed
1950
	  };
unknown's avatar
unknown committed
1951 1952 1953 1954 1955


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
unknown's avatar
unknown committed
1956
	    if (add_item_to_list(YYTHD, $2))
unknown's avatar
unknown committed
1957 1958
	      YYABORT;
	    if ($4.str)
unknown's avatar
unknown committed
1959
	      $2->set_name($4.str,$4.length,system_charset_info);
unknown's avatar
unknown committed
1960
	    else if (!$2->name)
unknown's avatar
unknown committed
1961
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
unknown's avatar
unknown committed
1962
	  };
unknown's avatar
unknown committed
1963 1964

remember_name:
unknown's avatar
unknown committed
1965
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
1966 1967

remember_end:
unknown's avatar
unknown committed
1968
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
1969 1970 1971

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
1972
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
1973 1974

select_alias:
unknown's avatar
unknown committed
1975 1976 1977 1978 1979 1980
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
unknown's avatar
unknown committed
1981 1982 1983

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

unknown's avatar
unknown committed
1986
/* all possible expressions */
unknown's avatar
SCRUM  
unknown committed
1987 1988 1989 1990
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
unknown's avatar
unknown committed
1991

unknown's avatar
unknown committed
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
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
2004 2005
/* expressions that begin with 'expr' */
expr_expr:
unknown's avatar
SCRUM  
unknown committed
2006
	 expr IN_SYM '(' expr_list ')'
unknown's avatar
unknown committed
2007 2008 2009
	  { $$= new Item_func_in($1,*$4); }
	| expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
unknown's avatar
unknown committed
2010
        | expr IN_SYM in_subselect
unknown's avatar
unknown committed
2011
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
unknown's avatar
unknown committed
2012
	| expr NOT IN_SYM in_subselect
2013
          {
unknown's avatar
unknown committed
2014
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
unknown's avatar
unknown committed
2015
          }
unknown's avatar
unknown committed
2016 2017 2018 2019
	| expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2020
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2021
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2022
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2023
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2024
	| expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
unknown's avatar
unknown committed
2025 2026 2027 2028 2029 2030 2031
	| 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));}
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| 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
2032 2033 2034
	| expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| expr comp_op all_or_any in_subselect %prec EQ
	{
2035
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2036
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2037 2038 2039 2040 2041
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2042 2043 2044 2045 2046 2047
	| 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); }
2048 2049
	| 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
2050
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2051
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2052 2053
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2054 2055 2056 2057
	| 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
2058
	;
unknown's avatar
unknown committed
2059 2060 2061 2062 2063 2064 2065

/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
	no_in_expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| no_in_expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2066
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2067
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2068
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2069
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2070
	| no_in_expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
unknown's avatar
unknown committed
2071 2072 2073 2074 2075 2076 2077
	| 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)); }
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| no_in_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| 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
2078 2079 2080
	| no_in_expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
2081
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2082
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2083 2084 2085 2086 2087
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2088 2089 2090 2091 2092 2093
	| 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); }
2094
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2095
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2096
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2097 2098
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2099
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2100 2101 2102 2103
	| 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
2104
	| simple_expr;
unknown's avatar
unknown committed
2105 2106 2107

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
unknown's avatar
unknown committed
2108 2109
	  no_and_expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
unknown's avatar
unknown committed
2110 2111
	| no_and_expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
unknown's avatar
unknown committed
2112
        | no_and_expr IN_SYM in_subselect
unknown's avatar
unknown committed
2113
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
unknown's avatar
unknown committed
2114
	| no_and_expr NOT IN_SYM in_subselect
2115
          {
unknown's avatar
unknown committed
2116
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
unknown's avatar
unknown committed
2117
          }
unknown's avatar
unknown committed
2118 2119 2120 2121
	| no_and_expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| no_and_expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
2122
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2123
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2124
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2125
	| no_and_expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
unknown's avatar
unknown committed
2126 2127 2128 2129 2130 2131 2132
	| 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)); }
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| no_and_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| 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
2133 2134 2135
	| no_and_expr comp_op expr %prec EQ { $$= (*((*$2)(0)))($1,$3); }
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
2136
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2137
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2138 2139 2140 2141 2142
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2143 2144 2145 2146 2147 2148
	| 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); }
2149
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2150
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2151
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2152 2153
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2154
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2155 2156 2157 2158
	| 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
2159
	| simple_expr;
unknown's avatar
unknown committed
2160

2161
interval_expr:
unknown's avatar
unknown committed
2162
         INTERVAL_SYM expr { $$=$2; }
2163 2164
        ;

unknown's avatar
unknown committed
2165 2166
simple_expr:
	simple_ident
2167 2168 2169
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
	  { 
	    $$= new Item_func_set_collation($1,new Item_string($3.str,$3.length,
2170
					    YYTHD->charset()));
2171
	  }
unknown's avatar
unknown committed
2172
	| literal
unknown's avatar
unknown committed
2173
	| param_marker
unknown's avatar
unknown committed
2174
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
2175 2176
	  {
	    $$= new Item_func_set_user_var($2,$4);
unknown's avatar
unknown committed
2177
	    Lex->uncacheable();
unknown's avatar
unknown committed
2178
	  }
2179
	| '@' ident_or_text
unknown's avatar
unknown committed
2180 2181
	  {
	    $$= new Item_func_get_user_var($2);
unknown's avatar
unknown committed
2182
	    Lex->uncacheable();
unknown's avatar
unknown committed
2183
	  }
unknown's avatar
unknown committed
2184 2185 2186 2187
	| '@' '@' opt_var_ident_type ident_or_text
	  {
	    if (!($$= get_system_var((enum_var_type) $3, $4)))
	      YYABORT;
unknown's avatar
unknown committed
2188
	  }
unknown's avatar
unknown committed
2189 2190 2191 2192 2193 2194
	| sum_expr
	| '-' expr %prec NEG	{ $$= new Item_func_neg($2); }
	| '~' expr %prec NEG	{ $$= new Item_func_bit_neg($2); }
	| NOT expr %prec NEG	{ $$= new Item_func_not($2); }
	| '!' expr %prec NEG	{ $$= new Item_func_not($2); }
	| '(' expr ')'		{ $$= $2; }
2195 2196 2197 2198 2199
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
2200
	| ROW_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2201
	  {
2202 2203
	    $5->push_front($3);
	    $$= new Item_row(*$5);
unknown's avatar
unknown committed
2204
	  }
unknown's avatar
unknown committed
2205
	| EXISTS exists_subselect { $$= $2; }
unknown's avatar
unknown committed
2206
	| singlerow_subselect   { $$= $1; }
unknown's avatar
unknown committed
2207
	| '{' ident expr '}'	{ $$= $3; }
unknown's avatar
unknown committed
2208
        | MATCH ident_list_arg AGAINST '(' expr ')'
2209
          { Select->add_ftfunc_to_list((Item_func_match *)
2210
                   ($$=new Item_func_match_nl(*$2,$5))); }
unknown's avatar
unknown committed
2211
        | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
2212
          { Select->add_ftfunc_to_list((Item_func_match *)
2213
                   ($$=new Item_func_match_bool(*$2,$5))); }
unknown's avatar
unknown committed
2214
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
unknown's avatar
unknown committed
2215 2216 2217 2218 2219
	| BINARY expr %prec NEG 
	  {
	    $$= new Item_func_set_collation($2,new Item_string("BINARY",6,
					    &my_charset_latin1));
	  }
unknown's avatar
unknown committed
2220
	| CAST_SYM '(' expr AS cast_type ')'  { $$= create_func_cast($3, $5); }
unknown's avatar
unknown committed
2221
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
2222
	  { $$= new Item_func_case(* $4, $2, $5 ); }
unknown's avatar
unknown committed
2223
	| CONVERT_SYM '(' expr ',' cast_type ')'  { $$= create_func_cast($3, $5); }
2224 2225
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
2226
	| CONVERT_SYM '(' expr ',' expr ',' expr ')'
2227
	  { $$= new Item_func_conv_charset3($3,$7,$5); }
unknown's avatar
SCRUM  
unknown committed
2228 2229
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
unknown's avatar
unknown committed
2230 2231
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
unknown's avatar
unknown committed
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245
	| FUNC_ARG0 '(' ')'
	  { $$= ((Item*(*)(void))($1.symbol->create_func))();}
	| FUNC_ARG1 '(' expr ')'
	  { $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);}
	| FUNC_ARG2 '(' expr ',' expr ')'
	  { $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);}
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
	  { $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);}
	| 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
2246 2247
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
2248 2249
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
unknown's avatar
unknown committed
2250 2251
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
unknown's avatar
unknown committed
2252 2253 2254 2255 2256
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
2257
	  { $$= new Item_func_curdate(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2258
	| CURTIME optional_braces
2259
	  { $$= new Item_func_curtime(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2260
	| CURTIME '(' expr ')'
2261 2262
	  {
	    $$= new Item_func_curtime($3);
2263
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2264
	  }
2265 2266 2267 2268
	| 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
2269
	| DATABASE '(' ')'
2270
	  {
unknown's avatar
unknown committed
2271
	    $$= new Item_func_database();
2272
            Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2273
	  }
unknown's avatar
unknown committed
2274 2275 2276 2277
	| ELT_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_elt($3, *$5); }
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
unknown's avatar
unknown committed
2278 2279 2280
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
unknown's avatar
unknown committed
2281
	    Lex->uncacheable();
unknown's avatar
unknown committed
2282
	  }
unknown's avatar
unknown committed
2283
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
2284
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2285
	  { $$= new Item_func_decode($3,$5.str); }
2286
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2287
	 { $$= new Item_func_encode($3,$5.str); }
unknown's avatar
unknown committed
2288
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2289
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
2290
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2291
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
2292
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2293
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
2294
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2295
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
2296 2297 2298 2299 2300 2301
	| 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); }
2302 2303
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
2304 2305 2306 2307 2308 2309
	| 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
2310
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2311 2312 2313
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_field($3, *$5); }
unknown's avatar
unknown committed
2314
	| GEOMFROMTEXT '(' expr ')'
2315
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2316
	| GEOMFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2317 2318 2319 2320 2321
	  { $$= new Item_func_geometry_from_text($3, $5); }
	| GEOMFROMWKB '(' expr ')'
	  { $$= new Item_func_geometry_from_wkb($3); }
	| GEOMFROMWKB '(' expr ',' expr ')'
	  { $$= new Item_func_geometry_from_wkb($3, $5); }
unknown's avatar
unknown committed
2322
	| GEOMETRYCOLLECTION '(' expr_list ')'
2323 2324
	  { $$= new Item_func_spatial_collection(* $3,
                       Geometry::wkbGeometryCollection,
unknown's avatar
unknown committed
2325
                       Geometry::wkbPoint); }
unknown's avatar
unknown committed
2326 2327 2328 2329 2330 2331
	| 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); }
2332
	| interval_expr interval '+' expr
unknown's avatar
unknown committed
2333
	  /* we cannot put interval before - */
2334 2335 2336 2337 2338 2339 2340 2341 2342 2343
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
              send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
unknown's avatar
unknown committed
2344 2345
	| LAST_INSERT_ID '(' ')'
	  {
2346
	    $$= get_system_var(OPT_SESSION, "last_insert_id", 14,
2347
			      "last_insert_id()");
2348
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2349 2350 2351 2352
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
2353
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2354 2355 2356
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
unknown's avatar
unknown committed
2357
	| LINESTRING '(' expr_list ')'
2358
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2359
               Geometry::wkbLineString, Geometry::wkbPoint); }
unknown's avatar
unknown committed
2360 2361 2362 2363
	| 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
2364
 	| GEOMCOLLFROMTEXT '(' expr ')'
2365
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2366
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2367
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2368
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2369 2370 2371
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
2372
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
2373
	  { $$= new Item_func_log($3); }
2374
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2375
	  { $$= new Item_func_log($3, $5); }
unknown's avatar
unknown committed
2376
 	| LINEFROMTEXT '(' expr ')'
2377
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2378
	| LINEFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2379
	  { $$= new Item_func_geometry_from_text($3, $5); }
2380 2381 2382
	| MASTER_POS_WAIT '(' expr ',' expr ')'
	  { 
	    $$= new Item_master_pos_wait($3, $5);
unknown's avatar
unknown committed
2383 2384
	    Lex->safe_to_cache_query=0; 
		  }
2385 2386 2387
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
	  { 
	    $$= new Item_master_pos_wait($3, $5, $7);
unknown's avatar
unknown committed
2388
	    Lex->safe_to_cache_query=0; 
2389
	  }
unknown's avatar
unknown committed
2390 2391
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
2392 2393
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
2394 2395
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
unknown's avatar
unknown committed
2396
 	| MULTILINESTRING '(' expr_list ')'
2397
 	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2398
                    Geometry::wkbMultiLineString, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2399
 	| MLINEFROMTEXT '(' expr ')'
2400
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2401
	| MLINEFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2402
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2403
	| MPOINTFROMTEXT '(' expr ')'
2404
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2405
	| MPOINTFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2406
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2407
	| MPOLYFROMTEXT '(' expr ')'
2408
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2409
	| MPOLYFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2410
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2411
	| MULTIPOINT '(' expr_list ')'
2412
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2413 2414
                    Geometry::wkbMultiPoint, Geometry::wkbPoint); }
 	| MULTIPOLYGON '(' expr_list ')'
2415
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2416
                       Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
unknown's avatar
unknown committed
2417
	| NOW_SYM optional_braces
2418
	  { $$= new Item_func_now(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2419
	| NOW_SYM '(' expr ')'
2420
	  { $$= new Item_func_now($3); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2421
	| PASSWORD '(' expr ')'
unknown's avatar
SCRUM  
unknown committed
2422 2423 2424
	  { $$= new Item_func_password($3); }
        | PASSWORD '(' expr ',' expr ')'
          { $$= new Item_func_password($3,$5); }
2425
	| POINT_SYM '(' expr ',' expr ')'
2426
	  { $$= new Item_func_point($3,$5); }
unknown's avatar
unknown committed
2427
 	| POINTFROMTEXT '(' expr ')'
2428
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2429
	| POINTFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2430
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2431
	| POLYFROMTEXT '(' expr ')'
2432
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2433
	| POLYFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2434
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2435
	| POLYGON '(' expr_list ')'
2436
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2437
			Geometry::wkbPolygon, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2438 2439
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
2440
	| RAND '(' expr ')'
2441
	  { $$= new Item_func_rand($3); Lex->uncacheable();}
unknown's avatar
unknown committed
2442
	| RAND '(' ')'
2443
	  { $$= new Item_func_rand(); Lex->uncacheable();}
unknown's avatar
unknown committed
2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
	| 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); }
	| 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); }
	| TRIM '(' expr ')'
2464
	  { $$= new Item_func_trim($3,new Item_string(" ",1,default_charset_info)); }
unknown's avatar
unknown committed
2465 2466 2467 2468 2469 2470 2471 2472
	| TRIM '(' LEADING opt_pad FROM expr ')'
	  { $$= new Item_func_ltrim($6,$4); }
	| TRIM '(' TRAILING opt_pad FROM expr ')'
	  { $$= new Item_func_rtrim($6,$4); }
	| TRIM '(' BOTH opt_pad FROM expr ')'
	  { $$= new Item_func_trim($6,$4); }
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
2473 2474
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
2475 2476
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519
	| 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 ')'
2520
	  {
unknown's avatar
unknown committed
2521 2522
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
2523
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
2524 2525
	  {
	    $$= new Item_func_unix_timestamp();
2526
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2527
	  }
unknown's avatar
unknown committed
2528 2529 2530
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
2531
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2532
	| WEEK_SYM '(' expr ')'
2533 2534 2535 2536
	  { 
            $$= new Item_func_week($3,new Item_int((char*) "0",
				   YYTHD->variables.default_week_format,1)); 
          }
unknown's avatar
unknown committed
2537 2538 2539 2540 2541 2542 2543 2544 2545
	| 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 ')'
2546
	  {
unknown's avatar
unknown committed
2547
	    $$=new Item_func_benchmark($3,$5);
2548
	    Lex->uncacheable();
unknown's avatar
unknown committed
2549
	  }
unknown's avatar
unknown committed
2550
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
2551
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
2552 2553 2554

udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
2555
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
2556 2557 2558 2559 2560 2561 2562 2563

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); }
unknown's avatar
unknown committed
2564
	| COUNT_SYM '(' opt_all '*' ')'
unknown's avatar
unknown committed
2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
	| COUNT_SYM '(' DISTINCT expr_list ')'
	  { $$=new Item_sum_count_distinct(* $4); }
	| 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
2578 2579
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
unknown's avatar
unknown committed
2580
	| SUM_SYM '(' in_sum_expr ')'
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592
	  { $$=new Item_sum_sum($3); }
	| GROUP_CONCAT_SYM '(' opt_distinct expr_list opt_gorder_clause opt_gconcat_separator ')'
	  { 
	    $$=new Item_func_group_concat($3,$4,Lex->gorder_list,$6); 
	    $4->empty();
	  };

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

opt_gconcat_separator:
2593
    /* empty */        { $$ = new String(",",1,default_charset_info); }
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609
    |SEPARATOR_SYM text_string  { $$ = $2; };
   

opt_gorder_clause:
    /* empty */ 
      {
        LEX *lex=Lex;
        lex->gorder_list = NULL;
      }
    | order_clause
      {
        LEX *lex=Lex;
        lex->gorder_list= (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,sizeof(st_sql_list));
        lex->current_select->order_list.empty();
      };
	  
unknown's avatar
unknown committed
2610 2611

in_sum_expr:
unknown's avatar
unknown committed
2612
	opt_all
2613 2614 2615 2616 2617
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
2618
	    YYABORT;
2619 2620
	  }
	}
unknown's avatar
unknown committed
2621 2622
	expr
	{
unknown's avatar
unknown committed
2623
	  Select->select_lex()->in_sum_expr--;
2624
	  $$= $3;
unknown's avatar
unknown committed
2625
	};
unknown's avatar
unknown committed
2626

unknown's avatar
unknown committed
2627
cast_type:
2628
	BINARY			{ $$=ITEM_CAST_BINARY; }
2629
	| CHAR_SYM		{ $$=ITEM_CAST_CHAR; }
unknown's avatar
unknown committed
2630 2631 2632 2633 2634 2635
	| SIGNED_SYM		{ $$=ITEM_CAST_SIGNED_INT; }
	| SIGNED_SYM INT_SYM	{ $$=ITEM_CAST_SIGNED_INT; }
	| UNSIGNED		{ $$=ITEM_CAST_UNSIGNED_INT; }
	| UNSIGNED INT_SYM	{ $$=ITEM_CAST_UNSIGNED_INT; }
	| DATE_SYM		{ $$=ITEM_CAST_DATE; }
	| TIME_SYM		{ $$=ITEM_CAST_TIME; }
2636 2637
	| DATETIME		{ $$=ITEM_CAST_DATETIME; }
	;
unknown's avatar
unknown committed
2638

unknown's avatar
unknown committed
2639
expr_list:
2640
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2641
	expr_list2
unknown's avatar
unknown committed
2642
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2643 2644

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

unknown's avatar
unknown committed
2648 2649
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
2650
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
2651

unknown's avatar
unknown committed
2652
ident_list:
2653
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2654
        ident_list2
unknown's avatar
unknown committed
2655
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2656 2657

ident_list2:
2658
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
2659
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
2660 2661 2662

opt_expr:
	/* empty */      { $$= NULL; }
unknown's avatar
unknown committed
2663
	| expr         	 { $$= $1; };
unknown's avatar
unknown committed
2664 2665 2666

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
2667
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
2668 2669

when_list:
unknown's avatar
unknown committed
2670
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2671
	when_list2
unknown's avatar
unknown committed
2672
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
2673 2674

when_list2:
unknown's avatar
unknown committed
2675
	expr THEN_SYM expr
unknown's avatar
unknown committed
2676
	  {
2677
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2678 2679
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
2680
	}
unknown's avatar
unknown committed
2681
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
2682
	  {
2683
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2684 2685
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
2686
	  };
unknown's avatar
unknown committed
2687 2688

opt_pad:
2689
	/* empty */ { $$=new Item_string(" ",1,default_charset_info); }
unknown's avatar
unknown committed
2690
	| expr	    { $$=$1; };
unknown's avatar
unknown committed
2691 2692 2693 2694

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
unknown's avatar
unknown committed
2695
	| join_table_list ',' join_table_list { $$=$3; }
2696
	| join_table_list normal_join join_table_list { $$=$3; }
2697 2698
	| join_table_list STRAIGHT_JOIN join_table_list
	  { $$=$3 ; $$->straight=1; }
unknown's avatar
unknown committed
2699 2700 2701 2702
	| join_table_list normal_join join_table_list ON expr
	  { add_join_on($3,$5); $$=$3; }
	| join_table_list normal_join join_table_list
	  USING 
unknown's avatar
unknown committed
2703
	  {
unknown's avatar
unknown committed
2704
	    SELECT_LEX *sel= Select->select_lex();
2705
	    sel->db1=$1->db; sel->table1=$1->alias;
unknown's avatar
unknown committed
2706
	    sel->db2=$3->db; sel->table2=$3->alias;
unknown's avatar
unknown committed
2707
	  }
unknown's avatar
unknown committed
2708 2709 2710
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

2711
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2712
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2713
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2714
	  {
unknown's avatar
unknown committed
2715
	    SELECT_LEX *sel= Select->select_lex();
2716 2717
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2718
	  }
unknown's avatar
unknown committed
2719
	  USING '(' using_list ')'
2720
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2721
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2722
	  { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
2723
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2724
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2725
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2726
	  {
unknown's avatar
unknown committed
2727
	    SELECT_LEX *sel= Select->select_lex();
2728 2729
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2730
	  }
2731 2732
	  USING '(' using_list ')'
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2733
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2734
	  { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2735
	| join_table_list NATURAL JOIN_SYM join_table_list
unknown's avatar
unknown committed
2736
	  { add_join_natural($1,$4); $$=$4; };
unknown's avatar
unknown committed
2737 2738

normal_join:
unknown's avatar
unknown committed
2739 2740 2741 2742
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
unknown's avatar
unknown committed
2743 2744

join_table:
unknown's avatar
unknown committed
2745
	{
unknown's avatar
unknown committed
2746
	  SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2747
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
unknown's avatar
unknown committed
2748
	  sel->table_join_options= 0;
unknown's avatar
unknown committed
2749
	}
unknown's avatar
unknown committed
2750
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
2751
	{
unknown's avatar
unknown committed
2752 2753
	  LEX *lex= Lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
unknown's avatar
unknown committed
2754
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
unknown's avatar
unknown committed
2755
					   sel->get_table_join_options(),
unknown's avatar
unknown committed
2756
					   lex->lock_option,
2757 2758
					   sel->get_use_index(),
					   sel->get_ignore_index())))
2759
	    YYABORT;
unknown's avatar
unknown committed
2760
	}
unknown's avatar
unknown committed
2761
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2762
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
2763
        | '(' SELECT_SYM select_derived ')' opt_table_alias
unknown's avatar
unknown committed
2764 2765
	{
	  LEX *lex=Lex;
2766 2767 2768
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
unknown's avatar
unknown committed
2769
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
2770
				  TL_READ,(List<String> *)0,
unknown's avatar
unknown committed
2771 2772
	                          (List<String> *)0)))

unknown's avatar
unknown committed
2773
	    YYABORT;
unknown's avatar
unknown committed
2774
	};
unknown's avatar
unknown committed
2775

2776
select_derived:
unknown's avatar
unknown committed
2777
        {
unknown's avatar
unknown committed
2778
	  LEX *lex= Lex;
unknown's avatar
unknown committed
2779
	  lex->derived_tables= 1;
2780 2781 2782 2783 2784 2785
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN && 
	       lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)
	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
2786
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
unknown's avatar
unknown committed
2787
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
2788 2789
	    YYABORT;
	  mysql_init_select(lex);
2790
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
unknown's avatar
unknown committed
2791
	}
2792
        select_options select_item_list opt_select_from union_opt
2793
        ;
unknown's avatar
unknown committed
2794 2795 2796

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
2797
	| OUTER		{};
unknown's avatar
unknown committed
2798 2799 2800 2801

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
2802
          {
unknown's avatar
unknown committed
2803
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2804 2805 2806
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2807 2808 2809 2810 2811 2812 2813
	| FORCE_SYM key_usage_list
          {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
unknown's avatar
unknown committed
2814
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
2815
	  {
unknown's avatar
unknown committed
2816
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2817 2818
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
2819
	  };
unknown's avatar
unknown committed
2820 2821

key_usage_list:
unknown's avatar
unknown committed
2822
	key_or_index { Select->select_lex()->interval_list.empty(); }
unknown's avatar
unknown committed
2823 2824 2825 2826 2827 2828 2829 2830
        '(' key_list_or_empty ')'
        { $$= &Select->select_lex()->interval_list; }
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
unknown's avatar
unknown committed
2831 2832 2833

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
2834
        { Select->select_lex()->
2835 2836
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
				    default_charset_info)); }
unknown's avatar
unknown committed
2837
	| ident
unknown's avatar
unknown committed
2838
        { Select->select_lex()->
2839 2840
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
				    default_charset_info)); }
unknown's avatar
unknown committed
2841
	| PRIMARY_SYM
unknown's avatar
unknown committed
2842
        { Select->select_lex()->
2843 2844
	    interval_list.push_back(new String("PRIMARY", 7,
				    default_charset_info)); };
unknown's avatar
unknown committed
2845 2846 2847

using_list:
	ident
unknown's avatar
unknown committed
2848
	  {
unknown's avatar
unknown committed
2849
	    SELECT_LEX *sel= Select->select_lex();
2850 2851 2852 2853
	    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
2854 2855 2856 2857
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
2858
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2859
	    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
2860
	      YYABORT;
unknown's avatar
unknown committed
2861
	  };
unknown's avatar
unknown committed
2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875

interval:
	 DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
	| DAY_MINUTE_SYM	{ $$=INTERVAL_DAY_MINUTE; }
	| DAY_SECOND_SYM	{ $$=INTERVAL_DAY_SECOND; }
	| DAY_SYM		{ $$=INTERVAL_DAY; }
	| HOUR_MINUTE_SYM	{ $$=INTERVAL_HOUR_MINUTE; }
	| HOUR_SECOND_SYM	{ $$=INTERVAL_HOUR_SECOND; }
	| HOUR_SYM		{ $$=INTERVAL_HOUR; }
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
	| YEAR_MONTH_SYM	{ $$=INTERVAL_YEAR_MONTH; }
unknown's avatar
unknown committed
2876
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
unknown's avatar
unknown committed
2877 2878 2879 2880

table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
2881
	| EQ;
unknown's avatar
unknown committed
2882 2883 2884 2885

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

unknown's avatar
unknown committed
2888 2889 2890 2891
opt_all:
	/* empty */
	| ALL
	;
unknown's avatar
unknown committed
2892 2893

where_clause:
2894
	/* empty */  { Select->select_lex()->where= 0; }
2895 2896
	| WHERE expr
	  {
unknown's avatar
unknown committed
2897
	    Select->select_lex()->where= $2;
2898 2899 2900
	    if ($2)
	      $2->top_level_item();
	  }
unknown's avatar
unknown committed
2901
 	;
unknown's avatar
unknown committed
2902 2903 2904

having_clause:
	/* empty */
unknown's avatar
unknown committed
2905
	| HAVING { Select->select_lex()->create_refs= 1; } expr
unknown's avatar
unknown committed
2906 2907 2908 2909 2910 2911
	  {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->having= $3; sel->create_refs=0;
	    if ($3)
	      $3->top_level_item();
	  }
2912
	;
unknown's avatar
unknown committed
2913 2914

opt_escape:
2915
	ESCAPE_SYM TEXT_STRING_literal	{ $$= $2.str; }
unknown's avatar
unknown committed
2916
	| /* empty */			{ $$= (char*) "\\"; };
unknown's avatar
unknown committed
2917 2918 2919


/*
unknown's avatar
unknown committed
2920
   group by statement in select
unknown's avatar
unknown committed
2921 2922 2923 2924
*/

group_clause:
	/* empty */
2925
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
2926 2927

group_list:
unknown's avatar
unknown committed
2928
	group_list ',' order_ident order_dir
unknown's avatar
unknown committed
2929
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
2930
	| order_ident order_dir
unknown's avatar
unknown committed
2931
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
2932

2933 2934
olap_opt:
	/* empty */ {}
2935
	| WITH CUBE_SYM
2936
          {
2937
	    LEX *lex=Lex;
2938 2939 2940 2941 2942 2943
	    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
2944
	    lex->current_select->select_lex()->olap= CUBE_TYPE;
2945
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
2946
	    YYABORT;	/* To be deleted in 4.1 */
2947
	  }
2948
	| WITH ROLLUP_SYM
2949
          {
2950 2951 2952 2953 2954 2955 2956
	    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
2957
	    lex->current_select->select_lex()->olap= ROLLUP_TYPE;
2958
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "ROLLUP");
2959
	    YYABORT;	/* To be deleted in 4.1 */
2960
	  }
2961
	;
2962

unknown's avatar
unknown committed
2963
/*
unknown's avatar
unknown committed
2964
   Order by statement in select
unknown's avatar
unknown committed
2965 2966
*/

2967
opt_order_clause:
unknown's avatar
unknown committed
2968
	/* empty */
unknown's avatar
unknown committed
2969
	| order_clause;
2970 2971

order_clause:
2972 2973
	ORDER_SYM BY
        {
unknown's avatar
unknown committed
2974
	  LEX *lex=Lex;
2975
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
2976
	      lex->current_select->select_lex()->olap !=
2977
	      UNSPECIFIED_OLAP_TYPE)
2978
	  {
2979
	    net_printf(lex->thd, ER_WRONG_USAGE,
2980 2981 2982 2983
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
2984
	} order_list;
unknown's avatar
unknown committed
2985 2986 2987

order_list:
	order_list ',' order_ident order_dir
unknown's avatar
unknown committed
2988
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
2989
	| order_ident order_dir
unknown's avatar
unknown committed
2990
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
2991 2992 2993

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
2994
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
2995
	| DESC { $$ =0; };
unknown's avatar
unknown committed
2996 2997


2998 2999 3000 3001 3002 3003 3004
opt_limit_clause_init:
	/* empty */
	{
	  SELECT_LEX_NODE *sel= Select;
          sel->offset_limit= 0L;
          sel->select_limit= Lex->thd->variables.select_limit;
	}
3005 3006 3007
	| limit_clause {}
	;

3008 3009 3010 3011 3012
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

3013
limit_clause:
3014
	LIMIT
unknown's avatar
unknown committed
3015
	  {
3016 3017
	    LEX *lex= Lex;
	    if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
3018
	        lex->current_select->select_lex()->olap !=
3019
		UNSPECIFIED_OLAP_TYPE)
3020
	    {
3021
	      net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
3022
		        "LIMIT");
3023
	      YYABORT;
3024
	    }
unknown's avatar
unknown committed
3025
	  }
unknown's avatar
unknown committed
3026
	  limit_options
3027
	  {}
unknown's avatar
unknown committed
3028
	;
unknown's avatar
unknown committed
3029 3030 3031

limit_options:
	ULONG_NUM
unknown's avatar
unknown committed
3032
	  {
unknown's avatar
unknown committed
3033
            SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
3034 3035 3036 3037 3038
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
3039
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
3040 3041
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
unknown's avatar
unknown committed
3042
	  }
unknown's avatar
unknown committed
3043
	| ULONG_NUM OFFSET_SYM ULONG_NUM
unknown's avatar
unknown committed
3044
	  {
unknown's avatar
unknown committed
3045
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
3046 3047 3048 3049
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
unknown's avatar
unknown committed
3050 3051 3052 3053 3054


delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
3055
	  LEX *lex=Lex;
3056
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
3057
	}
unknown's avatar
unknown committed
3058
	| LIMIT ulonglong_num
unknown's avatar
unknown committed
3059
	{ Select->select_limit= (ha_rows) $2; };
unknown's avatar
unknown committed
3060 3061

ULONG_NUM:
unknown's avatar
unknown committed
3062
	NUM	    { $$= strtoul($1.str,NULL,10); }
3063
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3064
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3065
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3066
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
unknown's avatar
unknown committed
3067

unknown's avatar
unknown committed
3068
ulonglong_num:
unknown's avatar
unknown committed
3069
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3070
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
3071
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3072
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3073
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
unknown's avatar
unknown committed
3074 3075 3076 3077 3078 3079

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
3080 3081 3082 3083 3084 3085 3086
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3087 3088 3089
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
unknown's avatar
unknown committed
3090
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
unknown's avatar
unknown committed
3091
	      YYABORT;
3092
	    Lex->uncacheable();
unknown's avatar
unknown committed
3093
	  }
unknown's avatar
unknown committed
3094
	  '(' procedure_list ')';
unknown's avatar
unknown committed
3095 3096 3097 3098


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
3099
	| procedure_list2 {};
unknown's avatar
unknown committed
3100 3101 3102

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
3103
	| procedure_item;
unknown's avatar
unknown committed
3104 3105 3106 3107

procedure_item:
	  remember_name expr
	  {
unknown's avatar
unknown committed
3108 3109
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
unknown's avatar
unknown committed
3110 3111
	      YYABORT;
	    if (!$2->name)
unknown's avatar
unknown committed
3112
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
3113 3114 3115 3116 3117 3118
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
3119 3120
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3121 3122
	        YYABORT;
	   }
3123
	   select_var_list
3124
	   {}
3125
           ;
unknown's avatar
unknown committed
3126

unknown's avatar
unknown committed
3127
select_var_list:
3128 3129 3130 3131 3132
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
3133
           {
3134
             LEX *lex=Lex;
unknown's avatar
unknown committed
3135
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
3136 3137
	       YYABORT;
	   }
unknown's avatar
unknown committed
3138
           ;
unknown's avatar
unknown committed
3139

3140
into:
unknown's avatar
unknown committed
3141
        INTO OUTFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3142
	{
3143
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3144 3145
	  if (!lex->describe)
	  {
unknown's avatar
unknown committed
3146
	    lex->uncacheable();
unknown's avatar
unknown committed
3147 3148 3149 3150 3151
	    if (!(lex->exchange= new sql_exchange($3.str,0)))
	      YYABORT;
	    if (!(lex->result= new select_export(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3152 3153
	}
	opt_field_term opt_line_term
unknown's avatar
unknown committed
3154
	| INTO DUMPFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3155
	{
3156
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3157 3158
	  if (!lex->describe)
	  {
unknown's avatar
unknown committed
3159
	    lex->uncacheable();
unknown's avatar
unknown committed
3160 3161 3162 3163 3164
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3165
	}
3166
        | INTO select_var_list_init
unknown's avatar
unknown committed
3167
	{
3168
	  Lex->uncacheable();
3169 3170
	}
        ;
unknown's avatar
unknown committed
3171

unknown's avatar
unknown committed
3172 3173 3174
/*
  DO statement
*/
unknown's avatar
unknown committed
3175

3176
do:	DO_SYM
unknown's avatar
unknown committed
3177 3178 3179 3180 3181 3182
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
3183 3184 3185 3186
	values
	{}
	;

unknown's avatar
unknown committed
3187
/*
unknown's avatar
unknown committed
3188
  Drop : delete tables or index
unknown's avatar
unknown committed
3189 3190 3191
*/

drop:
3192
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
unknown's avatar
unknown committed
3193
	{
unknown's avatar
unknown committed
3194 3195
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3196 3197
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
unknown's avatar
unknown committed
3198 3199 3200
	}
	| DROP INDEX ident ON table_ident {}
	  {
unknown's avatar
unknown committed
3201 3202 3203 3204
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
	     lex->drop_list.empty();
	     lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
unknown's avatar
unknown committed
3205
						     $3.str));
unknown's avatar
unknown committed
3206 3207
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3208 3209 3210 3211
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
3212 3213 3214 3215
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
3216
	 }
unknown's avatar
unknown committed
3217
	| DROP UDF_SYM IDENT_sys
unknown's avatar
unknown committed
3218
	  {
unknown's avatar
unknown committed
3219 3220
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3221
	    lex->udf.name = $3;
unknown's avatar
unknown committed
3222
	  };
unknown's avatar
unknown committed
3223 3224 3225


table_list:
3226
	table_name
unknown's avatar
unknown committed
3227
	| table_list ',' table_name;
unknown's avatar
unknown committed
3228

3229
table_name:
unknown's avatar
unknown committed
3230
	table_ident
unknown's avatar
unknown committed
3231 3232 3233 3234 3235
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
unknown's avatar
unknown committed
3236 3237

if_exists:
3238
	/* empty */ { $$= 0; }
3239 3240
	| IF EXISTS { $$= 1; }
	;
unknown's avatar
unknown committed
3241

3242 3243 3244 3245
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
unknown's avatar
unknown committed
3246 3247 3248 3249 3250
/*
** Insert : add new data to table
*/

insert:
3251 3252 3253 3254 3255 3256 3257
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	} insert_lock_option
3258
	opt_ignore insert2
unknown's avatar
unknown committed
3259
	{
unknown's avatar
unknown committed
3260
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3261
	}
3262
	insert_field_spec opt_insert_update
3263
	{}
unknown's avatar
unknown committed
3264
	;
unknown's avatar
unknown committed
3265 3266

replace:
3267 3268
	REPLACE
	{
3269
	  LEX *lex=Lex;
3270 3271 3272
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
unknown's avatar
unknown committed
3273 3274
	replace_lock_option insert2
	{
unknown's avatar
unknown committed
3275
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3276 3277
	}
	insert_field_spec
3278
	{}
unknown's avatar
unknown committed
3279
	{}
unknown's avatar
unknown committed
3280
	;
unknown's avatar
unknown committed
3281 3282

insert_lock_option:
unknown's avatar
unknown committed
3283 3284 3285 3286
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3287
	;
unknown's avatar
unknown committed
3288 3289

replace_lock_option:
unknown's avatar
unknown committed
3290 3291
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
3292 3293 3294

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
3295
	| insert_table {};
unknown's avatar
unknown committed
3296 3297

insert_table:
3298
	table_name
unknown's avatar
unknown committed
3299
	{
unknown's avatar
unknown committed
3300 3301 3302 3303
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
3304
	};
unknown's avatar
unknown committed
3305 3306 3307 3308 3309

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
unknown's avatar
unknown committed
3310 3311 3312
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3313 3314
	      YYABORT;
	   }
unknown's avatar
unknown committed
3315
	   ident_eq_list;
unknown's avatar
unknown committed
3316 3317 3318 3319

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
3320
	| '(' ')'	  { };
unknown's avatar
unknown committed
3321 3322 3323

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
3324
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
3325 3326 3327

insert_values:
	VALUES	values_list  {}
unknown's avatar
unknown committed
3328
	| VALUE_SYM values_list  {}
unknown's avatar
unknown committed
3329 3330 3331 3332 3333
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
unknown's avatar
unknown committed
3334
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3335
	    mysql_init_select(lex);
unknown's avatar
unknown committed
3336
	  }
unknown's avatar
unknown committed
3337
	  select_options select_item_list opt_select_from select_lock_type
3338
          union_clause {}
unknown's avatar
unknown committed
3339
	;
unknown's avatar
unknown committed
3340 3341 3342

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
3343
	| no_braces;
unknown's avatar
unknown committed
3344 3345 3346 3347

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
3348
	ident_eq_value;
unknown's avatar
unknown committed
3349 3350

ident_eq_value:
unknown's avatar
unknown committed
3351
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
3352
	 {
unknown's avatar
unknown committed
3353 3354 3355
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
3356
	    YYABORT;
unknown's avatar
unknown committed
3357
	 };
unknown's avatar
unknown committed
3358 3359

equal:	EQ		{}
unknown's avatar
unknown committed
3360 3361 3362 3363 3364 3365 3366
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
3367 3368 3369 3370 3371 3372 3373 3374 3375

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
3376 3377
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3378
	    YYABORT;
unknown's avatar
unknown committed
3379
	 };
unknown's avatar
unknown committed
3380 3381 3382

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
3383
	| values;
unknown's avatar
unknown committed
3384 3385

values:
unknown's avatar
unknown committed
3386
	values ','  expr_or_default
unknown's avatar
unknown committed
3387 3388 3389 3390
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
3391 3392 3393 3394 3395 3396 3397 3398
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3399
	expr	  { $$= $1;}
unknown's avatar
SCRUM  
unknown committed
3400
	| DEFAULT {$$= new Item_default_value(); }
unknown's avatar
unknown committed
3401
	;
unknown's avatar
unknown committed
3402

3403 3404
opt_insert_update:
        /* empty */
unknown's avatar
unknown committed
3405
        | ON DUPLICATE_SYM
3406 3407 3408 3409 3410 3411 3412 3413 3414
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
	      send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
          }
3415
          KEY_SYM UPDATE_SYM update_list
3416 3417
        ;

unknown's avatar
unknown committed
3418 3419 3420
/* Update rows in a table */

update:
3421 3422
	UPDATE_SYM
	{
3423
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3424
	  mysql_init_select(lex);
3425
          lex->sql_command= SQLCOM_UPDATE;
3426
        }
unknown's avatar
unknown committed
3427 3428 3429
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3430
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3431
	  Select->set_lock_for_tables($3);
3432
          if (lex->select_lex.table_list.elements > 1)
unknown's avatar
unknown committed
3433
            lex->sql_command= SQLCOM_UPDATE_MULTI;
unknown's avatar
unknown committed
3434 3435
	}
	;
unknown's avatar
unknown committed
3436 3437

update_list:
unknown's avatar
SCRUM  
unknown committed
3438
	update_list ',' simple_ident equal expr_or_default
unknown's avatar
unknown committed
3439
	{
unknown's avatar
unknown committed
3440
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
unknown's avatar
unknown committed
3441 3442
	    YYABORT;
	}
unknown's avatar
SCRUM  
unknown committed
3443
	| simple_ident equal expr_or_default
unknown's avatar
unknown committed
3444
	  {
unknown's avatar
unknown committed
3445
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
unknown's avatar
unknown committed
3446
	      YYABORT;
unknown's avatar
unknown committed
3447
	  };
unknown's avatar
unknown committed
3448 3449

opt_low_priority:
3450
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3451
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3452 3453 3454 3455

/* Delete rows from a table */

delete:
3456
	DELETE_SYM
3457
	{
3458 3459 3460
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
	  lex->select_lex.options= 0;
unknown's avatar
unknown committed
3461
	  lex->lock_option= lex->thd->update_lock_default;
3462
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3463
	}
unknown's avatar
unknown committed
3464 3465
	opt_delete_options single_multi {}
	;
3466 3467

single_multi:
unknown's avatar
unknown committed
3468 3469
 	FROM table_ident
	{
unknown's avatar
unknown committed
3470 3471
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
unknown's avatar
unknown committed
3472 3473 3474
	    YYABORT;
	}
	where_clause opt_order_clause
3475
	delete_limit_clause {}
unknown's avatar
unknown committed
3476
	| table_wild_list
unknown's avatar
unknown committed
3477
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
3478
          FROM join_table_list where_clause
unknown's avatar
unknown committed
3479 3480
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3481 3482 3483
	  USING join_table_list where_clause
	  {}
	;
unknown's avatar
unknown committed
3484 3485 3486

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
3487
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
3488 3489

table_wild_one:
unknown's avatar
unknown committed
3490
	ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3491
	{
unknown's avatar
unknown committed
3492 3493
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
unknown's avatar
unknown committed
3494 3495
	    YYABORT;
        }
unknown's avatar
unknown committed
3496
	| ident '.' ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3497
	  {
unknown's avatar
unknown committed
3498 3499
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
unknown's avatar
unknown committed
3500 3501
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
unknown's avatar
unknown committed
3502
	      YYABORT;
unknown's avatar
unknown committed
3503
	  }
unknown's avatar
unknown committed
3504
	;
unknown's avatar
unknown committed
3505 3506

opt_wild:
3507
	/* empty */	{}
unknown's avatar
unknown committed
3508
	| '.' '*'	{};
unknown's avatar
unknown committed
3509 3510


3511
opt_delete_options:
unknown's avatar
unknown committed
3512
	/* empty */	{}
unknown's avatar
unknown committed
3513
	| opt_delete_option opt_delete_options {};
3514 3515

opt_delete_option:
3516
	QUICK		{ Select->options|= OPTION_QUICK; }
unknown's avatar
unknown committed
3517
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
3518

3519
truncate:
unknown's avatar
unknown committed
3520
	TRUNCATE_SYM opt_table_sym table_name
3521
	{
3522
	  LEX* lex= Lex;
3523
	  lex->sql_command= SQLCOM_TRUNCATE;
3524
	  lex->select_lex.options= 0;
3525
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3526 3527
	}
	;
3528

unknown's avatar
unknown committed
3529 3530
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
3531
	| TABLE_SYM;
3532

unknown's avatar
unknown committed
3533 3534
/* Show things */

3535 3536
show:	SHOW
	{
unknown's avatar
unknown committed
3537 3538 3539 3540
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
unknown's avatar
unknown committed
3541
	show_param
3542 3543
	{}
	;
unknown's avatar
unknown committed
3544 3545 3546 3547 3548

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
3549
	  {
3550
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3551
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3552 3553
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
unknown's avatar
unknown committed
3554
	   }
unknown's avatar
unknown committed
3555
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
3556
	  {
3557
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3558
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3559 3560
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
3561
	  }
3562
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
3563
	  {
3564
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3565
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
3566 3567
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
3568
	  }
unknown's avatar
unknown committed
3569
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
3570 3571
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3572 3573
	    if ($5)
	      $4->change_db($5);
unknown's avatar
unknown committed
3574
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
unknown's avatar
unknown committed
3575 3576
	      YYABORT;
	  }
3577
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
unknown's avatar
unknown committed
3578
	  TEXT_STRING_sys AND MASTER_LOG_POS_SYM EQ ulonglong_num
3579
	  AND MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
3580 3581 3582 3583 3584
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
3585
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
3586
          }
3587
        | BINARY LOGS_SYM
unknown's avatar
unknown committed
3588 3589
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
3590 3591 3592 3593 3594
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
3595
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
3596
          {
3597 3598
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
3599
          } opt_limit_clause_init
unknown's avatar
unknown committed
3600 3601 3602 3603 3604
	| keys_or_index FROM table_ident opt_db
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
unknown's avatar
unknown committed
3605
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
unknown's avatar
unknown committed
3606 3607
	      YYABORT;
	  }
unknown's avatar
unknown committed
3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622
	| COLUMN_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
	  }
	| TABLE_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_TABLE_TYPES;
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
3623
        | COUNT_SYM '(' '*' ')' WARNINGS
3624
          { (void) create_select_for_variable("warning_count"); }
3625
        | COUNT_SYM '(' '*' ')' ERRORS
3626
	  { (void) create_select_for_variable("error_count"); }
3627
        | WARNINGS opt_limit_clause_init
unknown's avatar
unknown committed
3628
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
3629
        | ERRORS opt_limit_clause_init
3630
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
unknown's avatar
unknown committed
3631 3632
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
3633 3634
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
unknown's avatar
unknown committed
3635 3636
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
3637
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
3638
	  {
3639
	    THD *thd= YYTHD;
3640
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
unknown's avatar
unknown committed
3641
	    thd->lex.option_type= (enum_var_type) $1;
3642
	  }
3643
	| charset wild
3644
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
3645 3646
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
unknown's avatar
unknown committed
3647 3648
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
unknown's avatar
unknown committed
3649
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
3650 3651 3652 3653 3654 3655
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
3656
	| CREATE DATABASE opt_if_not_exists ident
unknown's avatar
unknown committed
3657 3658
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
3659 3660
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
3661
	  }
unknown's avatar
unknown committed
3662 3663 3664
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
unknown's avatar
unknown committed
3665
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
unknown's avatar
unknown committed
3666 3667 3668 3669 3670
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
3671
          }
unknown's avatar
unknown committed
3672 3673 3674
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
3675
          };
unknown's avatar
unknown committed
3676 3677 3678

opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
3679
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
3680 3681 3682

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

unknown's avatar
unknown committed
3685 3686
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
3687
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
3688

unknown's avatar
unknown committed
3689 3690
from_or_in:
	FROM
unknown's avatar
unknown committed
3691
	| IN_SYM;
unknown's avatar
unknown committed
3692

unknown's avatar
unknown committed
3693 3694
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
3695
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
3696 3697 3698

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


unknown's avatar
unknown committed
3702 3703 3704 3705
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
3706 3707 3708 3709
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3710
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
unknown's avatar
unknown committed
3711 3712
	    YYABORT;
	}
3713
	opt_describe_column {}
unknown's avatar
unknown committed
3714
	| describe_command { Lex->describe=1; } select
3715
          {
unknown's avatar
unknown committed
3716
	    LEX *lex=Lex;
3717
	    lex->select_lex.options|= SELECT_DESCRIBE;
unknown's avatar
unknown committed
3718 3719
	  }
	;
unknown's avatar
unknown committed
3720 3721 3722

describe_command:
	DESC
unknown's avatar
unknown committed
3723
	| DESCRIBE;
unknown's avatar
unknown committed
3724 3725 3726 3727

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
3728
	| ident
unknown's avatar
unknown committed
3729
	  { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); };
unknown's avatar
unknown committed
3730 3731 3732 3733 3734


/* flush things */

flush:
unknown's avatar
unknown committed
3735 3736 3737 3738 3739
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
3740 3741 3742
	flush_options
	{}
	;
unknown's avatar
unknown committed
3743 3744 3745

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
3746
	| flush_option;
unknown's avatar
unknown committed
3747 3748

flush_option:
3749
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
unknown's avatar
unknown committed
3750
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
3751
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
3752 3753 3754 3755
	| 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
3756 3757
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3758 3759
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
3760

unknown's avatar
unknown committed
3761
opt_table_list:
3762 3763
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
3764

unknown's avatar
unknown committed
3765
reset:
unknown's avatar
unknown committed
3766 3767 3768 3769
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
3770 3771 3772 3773
	} reset_options
	{}
	;

unknown's avatar
unknown committed
3774 3775
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
3776
	| reset_option;
unknown's avatar
unknown committed
3777 3778

reset_option:
unknown's avatar
unknown committed
3779 3780
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
3781
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
3782

unknown's avatar
unknown committed
3783
purge:
unknown's avatar
unknown committed
3784 3785 3786 3787
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
3788 3789 3790 3791 3792
	} purge_options
	{}
	;

purge_options:
unknown's avatar
unknown committed
3793 3794 3795
	LOGS_SYM purge_option
	| MASTER_SYM LOGS_SYM purge_option
	;
3796 3797

purge_option:
unknown's avatar
unknown committed
3798
        TO_SYM TEXT_STRING_sys
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812
        {
	   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");
	    YYABORT;	  
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
	  Lex->purge_time= tmp->val_int();
unknown's avatar
unknown committed
3813
	}
unknown's avatar
unknown committed
3814
	;
unknown's avatar
unknown committed
3815

unknown's avatar
unknown committed
3816 3817 3818
/* kill threads */

kill:
3819
	KILL_SYM expr
unknown's avatar
unknown committed
3820
	{
unknown's avatar
unknown committed
3821
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3822
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
3823
	  {
3824
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
3825 3826 3827 3828
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
3829
	};
unknown's avatar
unknown committed
3830 3831 3832 3833

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
3834 3835
	{
	  LEX *lex=Lex;
3836 3837
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
3838
	};
unknown's avatar
unknown committed
3839 3840 3841

/* import, export of files */

unknown's avatar
unknown committed
3842
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3843
	{
unknown's avatar
unknown committed
3844 3845
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
unknown's avatar
unknown committed
3846 3847
	  lex->lock_option= $3;
	  lex->local_file=  $4;
unknown's avatar
unknown committed
3848
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
3849
	    YYABORT;
unknown's avatar
unknown committed
3850
	  lex->field_list.empty();
unknown's avatar
unknown committed
3851 3852 3853 3854
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
unknown's avatar
unknown committed
3855
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3856 3857 3858
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
3859
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
3860 3861
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
unknown's avatar
unknown committed
3862
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3863
	    YYABORT;
unknown's avatar
unknown committed
3864 3865

        }
3866 3867 3868 3869
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
3870
        };
unknown's avatar
unknown committed
3871 3872 3873

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

unknown's avatar
unknown committed
3876
load_data_lock:
3877
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3878 3879
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3880 3881


unknown's avatar
unknown committed
3882 3883 3884
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
unknown's avatar
unknown committed
3885
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
3886 3887 3888

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
3889
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
3890 3891 3892

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
3893
	| field_term;
unknown's avatar
unknown committed
3894 3895 3896 3897

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
3898 3899 3900 3901 3902
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
unknown's avatar
unknown committed
3903
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
unknown's avatar
unknown committed
3904
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
unknown's avatar
unknown committed
3905 3906 3907

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
3908
	| LINES line_term_list;
unknown's avatar
unknown committed
3909 3910 3911

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
3912
	| line_term;
unknown's avatar
unknown committed
3913 3914 3915

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
unknown's avatar
unknown committed
3916
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
unknown's avatar
unknown committed
3917 3918 3919 3920

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
unknown's avatar
unknown committed
3921
	  { Lex->exchange->skip_lines=atol($2.str); };
unknown's avatar
unknown committed
3922 3923 3924 3925

/* Common definitions */

text_literal:
3926
	TEXT_STRING_literal
unknown's avatar
unknown committed
3927 3928
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
3929
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
unknown's avatar
unknown committed
3930
	}
unknown's avatar
unknown committed
3931
	| NCHAR_STRING
3932
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
3933
	| UNDERSCORE_CHARSET TEXT_STRING
3934
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
3935
	| text_literal TEXT_STRING_literal
unknown's avatar
unknown committed
3936 3937
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
unknown's avatar
unknown committed
3938 3939

text_string:
3940
	TEXT_STRING_literal
unknown's avatar
unknown committed
3941
	{ $$=  new String($1.str,$1.length,YYTHD->variables.collation_connection); }
unknown's avatar
unknown committed
3942 3943
	| HEX_NUM
	  {
3944
	    Item *tmp = new Item_varbinary($1.str,$1.length);
unknown's avatar
unknown committed
3945
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
3946 3947 3948
	  }
	;

unknown's avatar
unknown committed
3949
param_marker:
3950
        '?'
unknown's avatar
unknown committed
3951
        {
3952
	  LEX *lex=Lex;
3953
          if (YYTHD->prepare_command)
3954
          {
3955
            lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query)));
3956
            lex->param_count++;
unknown's avatar
unknown committed
3957
          }
3958
          else
unknown's avatar
unknown committed
3959 3960 3961 3962
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
3963 3964 3965
        }
	;

unknown's avatar
unknown committed
3966 3967
literal:
	text_literal	{ $$ =	$1; }
3968 3969
	| NUM		{ $$ =	new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); }
	| LONG_NUM	{ $$ =	new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); }
unknown's avatar
unknown committed
3970
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
unknown's avatar
unknown committed
3971 3972 3973
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
3974
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
3975
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
3976 3977 3978 3979
	| UNDERSCORE_CHARSET HEX_NUM
	  { 
	    Item *tmp= new Item_varbinary($2.str,$2.length);
	    String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0;
3980 3981
	    $$ = new Item_string(str ? str->ptr() : "", str ? str->length() : 0, 
				 Lex->charset);
3982
	  }
unknown's avatar
unknown committed
3983 3984
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
3985
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
3986 3987 3988 3989 3990 3991 3992

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

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
3993
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
3994 3995

table_wild:
3996 3997 3998 3999 4000
	ident '.' '*' 
	{
	  $$ = new Item_field(NullS,$1.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
unknown's avatar
unknown committed
4001
	| ident '.' ident '.' '*'
4002 4003 4004 4005 4006 4007 4008
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
	;
unknown's avatar
unknown committed
4009 4010

order_ident:
unknown's avatar
unknown committed
4011
	expr { $$=$1; };
unknown's avatar
unknown committed
4012 4013 4014

simple_ident:
	ident
unknown's avatar
unknown committed
4015
	{
4016 4017
	  SELECT_LEX_NODE *sel=Select;
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str);
unknown's avatar
unknown committed
4018
	}
unknown's avatar
unknown committed
4019
	| ident '.' ident
unknown's avatar
unknown committed
4020
	{
unknown's avatar
unknown committed
4021 4022 4023 4024 4025 4026 4027 4028 4029
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
4030
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str);
unknown's avatar
unknown committed
4031
	}
unknown's avatar
unknown committed
4032
	| '.' ident '.' ident
unknown's avatar
unknown committed
4033
	{
unknown's avatar
unknown committed
4034 4035 4036 4037 4038 4039 4040 4041 4042
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
4043
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str);
unknown's avatar
unknown committed
4044
	}
unknown's avatar
unknown committed
4045
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
4046
	{
unknown's avatar
unknown committed
4047 4048 4049 4050 4051 4052 4053 4054 4055
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
4056
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str);
unknown's avatar
unknown committed
4057
	};
unknown's avatar
unknown committed
4058 4059 4060 4061 4062


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
unknown's avatar
unknown committed
4063
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
4064 4065 4066

table_ident:
	ident			{ $$=new Table_ident($1); }
unknown's avatar
unknown committed
4067
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
unknown's avatar
unknown committed
4068 4069
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
unknown's avatar
unknown committed
4070

unknown's avatar
unknown committed
4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106
IDENT_sys:
	IDENT
	{
	  THD *thd= YYTHD;
	  if (my_charset_same(thd->charset(),system_charset_info))
	  {
	    $$=$1;
	  }
	  else
	  {
	    String ident;
	    ident.copy($1.str,$1.length,thd->charset(),system_charset_info);
	    $$.str= thd->strmake(ident.ptr(),ident.length());
	    $$.length= ident.length();
	  }
	}
	;

TEXT_STRING_sys:
	TEXT_STRING
	{
	  THD *thd= YYTHD;
	  if (my_charset_same(thd->charset(),system_charset_info))
	  {
	    $$=$1;
	  }
	  else
	  {
	    String ident;
	    ident.copy($1.str,$1.length,thd->charset(),system_charset_info);
	    $$.str= thd->strmake(ident.ptr(),ident.length());
	    $$.length= ident.length();
	  }
	}
	;

4107
TEXT_STRING_literal:
unknown's avatar
unknown committed
4108 4109 4110
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4111
	  if (my_charset_same(thd->charset(),thd->variables.collation_connection))
unknown's avatar
unknown committed
4112 4113 4114 4115 4116 4117
	  {
	    $$=$1;
	  }
	  else
	  {
	    String ident;
unknown's avatar
unknown committed
4118
	    ident.copy($1.str,$1.length,thd->charset(),thd->variables.collation_connection);
unknown's avatar
unknown committed
4119 4120 4121 4122 4123 4124 4125
	    $$.str= thd->strmake(ident.ptr(),ident.length());
	    $$.length= ident.length();
	  }
	}
	;


unknown's avatar
unknown committed
4126
ident:
unknown's avatar
unknown committed
4127
	IDENT_sys	    { $$=$1; }
unknown's avatar
unknown committed
4128 4129
	| keyword
	{
4130 4131
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
unknown's avatar
unknown committed
4132
	  $$.length=$1.length;
4133 4134
	  if (lex->next_state != MY_LEX_END)
	    lex->next_state= MY_LEX_OPERATOR_OR_IDENT;
4135 4136
	}
	;
unknown's avatar
unknown committed
4137 4138

ident_or_text:
unknown's avatar
unknown committed
4139 4140 4141
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
unknown's avatar
unknown committed
4142 4143 4144 4145

user:
	ident_or_text
	{
unknown's avatar
unknown committed
4146 4147
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4148 4149 4150 4151 4152
	    YYABORT;
	  $$->user = $1; $$->host.str=NullS;
	  }
	| ident_or_text '@' ident_or_text
	  {
unknown's avatar
unknown committed
4153 4154
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4155 4156
	      YYABORT;
	    $$->user = $1; $$->host=$3;
unknown's avatar
unknown committed
4157
	  };
unknown's avatar
unknown committed
4158 4159 4160 4161 4162 4163

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
4164
	| AGAINST		{}
unknown's avatar
unknown committed
4165
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
4166
	| ANY_SYM		{}
unknown's avatar
unknown committed
4167
	| ASCII_SYM		{}
unknown's avatar
unknown committed
4168
	| AUTO_INC		{}
unknown's avatar
unknown committed
4169 4170
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
4171
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
4172
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
4173
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
4174
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
4175 4176
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
4177
	| BOOLEAN_SYM		{}
4178
	| BYTE_SYM		{}
unknown's avatar
unknown committed
4179
	| CACHE_SYM		{}
4180
	| CHANGED		{}
4181
	| CHARSET		{}
unknown's avatar
unknown committed
4182
	| CHECKSUM_SYM		{}
4183
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
4184
	| CLIENT_SYM		{}
4185
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
4186
	| COLLATION_SYM		{}
unknown's avatar
unknown committed
4187
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
4188
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
4189
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
4190
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
4191
	| CONCURRENT		{}
4192
	| CUBE_SYM		{}
unknown's avatar
unknown committed
4193 4194 4195 4196 4197
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
4198 4199
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
4200
	| DO_SYM		{}
4201
	| DUAL_SYM		{}
unknown's avatar
unknown committed
4202 4203
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
unknown's avatar
unknown committed
4204 4205 4206 4207
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
4208
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
4209
	| EXECUTE_SYM		{}
unknown's avatar
unknown committed
4210
	| EXTENDED_SYM		{}
4211
	| FAST_SYM		{}
unknown's avatar
unknown committed
4212 4213
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
4214
	| FULL			{}
unknown's avatar
unknown committed
4215 4216 4217 4218
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
4219
	| GEOMETRY_SYM		{}
4220
	| GEOMETRYCOLLECTION	{}
unknown's avatar
unknown committed
4221
	| GRANTS		{}
unknown's avatar
unknown committed
4222
	| GLOBAL_SYM		{}
4223
	| HANDLER_SYM		{}
4224 4225
	| HEAP_SYM		{}
	| HELP_SYM		{}
unknown's avatar
unknown committed
4226 4227 4228
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
4229
	| INDEXES		{}
unknown's avatar
unknown committed
4230
	| ISOLATION		{}
unknown's avatar
unknown committed
4231
	| ISAM_SYM		{}
unknown's avatar
unknown committed
4232
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
4233
	| INNOBASE_SYM		{}
4234
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
4235
	| RELAY_THREAD		{}
4236
	| LAST_SYM		{}
unknown's avatar
unknown committed
4237
	| LEVEL_SYM		{}
4238
	| LINESTRING		{}
unknown's avatar
unknown committed
4239
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
4240
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
4241 4242 4243 4244 4245 4246 4247 4248 4249 4250
	| LOGS_SYM		{}
	| MAX_ROWS		{}
	| MASTER_SYM		{}
	| MASTER_HOST_SYM	{}
	| MASTER_PORT_SYM	{}
	| MASTER_LOG_FILE_SYM	{}
	| MASTER_LOG_POS_SYM	{}
	| MASTER_USER_SYM	{}
	| MASTER_PASSWORD_SYM	{}
	| MASTER_CONNECT_RETRY_SYM	{}
unknown's avatar
unknown committed
4251 4252 4253
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
4254
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
4255
	| MERGE_SYM		{}
4256
	| MEMORY_SYM		{}
unknown's avatar
unknown committed
4257 4258 4259
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
4260
	| MODE_SYM		{}
unknown's avatar
unknown committed
4261
	| MONTH_SYM		{}
4262 4263 4264
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
unknown's avatar
unknown committed
4265
	| MYISAM_SYM		{}
unknown's avatar
unknown committed
4266
	| NAMES_SYM		{}
unknown's avatar
unknown committed
4267 4268
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
4269
	| NEXT_SYM		{}
unknown's avatar
unknown committed
4270
	| NEW_SYM		{}
unknown's avatar
unknown committed
4271
	| NO_SYM		{}
4272
	| NONE_SYM		{}
unknown's avatar
unknown committed
4273
	| OFFSET_SYM		{}
4274
	| OPEN_SYM		{}
unknown's avatar
unknown committed
4275
	| PACK_KEYS_SYM		{}
4276
	| PARTIAL		{}
unknown's avatar
unknown committed
4277
	| PASSWORD		{}
4278
	| POINT_SYM		{}
4279
	| POLYGON		{}
4280
	| PREV_SYM		{}
unknown's avatar
unknown committed
4281 4282
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
4283
	| QUERY_SYM		{}
4284
	| QUICK			{}
unknown's avatar
unknown committed
4285
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
4286 4287
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
4288
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
4289
	| RAID_TYPE		{}
unknown's avatar
unknown committed
4290 4291
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
4292 4293
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
4294
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
4295
	| REPLICATION		{}
unknown's avatar
unknown committed
4296
	| RESET_SYM		{}
4297
	| RESOURCES		{}
unknown's avatar
unknown committed
4298
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
4299
	| ROLLBACK_SYM		{}
4300
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
4301 4302 4303 4304
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
	| SECOND_SYM		{}
4305
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
4306 4307
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
4308
	| SIGNED_SYM		{}
4309
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
4310
	| SHARE_SYM		{}
unknown's avatar
unknown committed
4311
	| SHUTDOWN		{}
unknown's avatar
unknown committed
4312
	| SLAVE			{}
unknown's avatar
unknown committed
4313
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
4314
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
4315
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
4316
	| SQL_THREAD		{}
unknown's avatar
unknown committed
4317 4318 4319 4320
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
unknown's avatar
unknown committed
4321
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
4322
	| SUPER_SYM		{}
unknown's avatar
unknown committed
4323 4324
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
4325
	| TRANSACTION_SYM	{}
4326
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
4327 4328 4329 4330
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
unknown's avatar
unknown committed
4331
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
4332
	| UNICODE_SYM		{}
unknown's avatar
unknown committed
4333
	| USE_FRM		{}
unknown's avatar
unknown committed
4334
	| VARIABLES		{}
4335
	| VALUE_SYM		{}
unknown's avatar
unknown committed
4336
	| WORK_SYM		{}
unknown's avatar
unknown committed
4337
	| YEAR_SYM		{}
unknown's avatar
unknown committed
4338
	| SOUNDS_SYM            {}
unknown's avatar
unknown committed
4339
	;
unknown's avatar
unknown committed
4340 4341 4342 4343 4344 4345

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
4346 4347
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
unknown's avatar
unknown committed
4348 4349
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
unknown's avatar
unknown committed
4350
	}
4351 4352 4353
	option_value_list
	{}
	;
unknown's avatar
unknown committed
4354 4355 4356

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
4357
	| OPTION {};
unknown's avatar
unknown committed
4358 4359

option_value_list:
unknown's avatar
unknown committed
4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371
	option_type option_value
	| option_value_list ',' option_type option_value;

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

opt_var_type:
	/* empty */	{ $$=OPT_SESSION; }
unknown's avatar
unknown committed
4372
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4373 4374 4375 4376 4377 4378
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
4379
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4380 4381 4382
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
4383 4384

option_value:
unknown's avatar
unknown committed
4385
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
4386
	{
unknown's avatar
unknown committed
4387
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
4388
	}
unknown's avatar
unknown committed
4389
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4390
	  {
unknown's avatar
unknown committed
4391 4392
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
unknown's avatar
unknown committed
4393
	  }
unknown's avatar
unknown committed
4394
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4395 4396 4397 4398 4399 4400 4401 4402
	  {
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4, $6));
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type,
unknown's avatar
unknown committed
4403
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
4404
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
4405
	  }
4406
	| charset old_or_new_charset_name_or_default opt_collate
unknown's avatar
unknown committed
4407
	{
unknown's avatar
unknown committed
4408
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4409
	  LEX *lex= Lex;
unknown's avatar
unknown committed
4410
	  $2= $2 ? $2: global_system_variables.collation_client;
4411 4412
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
4413
	  {
unknown's avatar
unknown committed
4414 4415
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
4416
	  }
unknown's avatar
unknown committed
4417
	  lex->var_list.push_back(new set_var_collation_client($3,thd->db_charset,$3));
unknown's avatar
unknown committed
4418
	}
4419
	| NAMES_SYM charset_name_or_default opt_collate
4420
	{
unknown's avatar
unknown committed
4421
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4422
	  LEX *lex= Lex;
unknown's avatar
unknown committed
4423
	  $2= $2 ? $2 : global_system_variables.collation_client;
4424 4425
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
4426
	  {
unknown's avatar
unknown committed
4427 4428
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
4429
	  }
unknown's avatar
unknown committed
4430
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
4431
	}
unknown's avatar
unknown committed
4432
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
4433
	  {
4434
	    THD *thd=YYTHD;
unknown's avatar
unknown committed
4435
	    LEX_USER *user;
unknown's avatar
unknown committed
4436
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
unknown's avatar
unknown committed
4437 4438 4439 4440 4441 4442
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
	    thd->lex.var_list.push_back(new set_var_password(user, $3));
	  }
	| PASSWORD FOR_SYM user equal text_or_password
unknown's avatar
unknown committed
4443
	  {
unknown's avatar
unknown committed
4444 4445
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
4446
	;
unknown's avatar
unknown committed
4447

unknown's avatar
unknown committed
4448 4449 4450 4451 4452 4453 4454 4455
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
4456
        ;
unknown's avatar
unknown committed
4457 4458 4459 4460 4461 4462 4463

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

unknown's avatar
unknown committed
4465 4466 4467 4468 4469 4470 4471 4472
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
	    if (!$3.length)
	      $$=$3.str;
	    else
	    {
unknown's avatar
unknown committed
4473
	      char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
4474 4475
	      make_scrambled_password(buff,$3.str,use_old_passwords,
				      &YYTHD->rand);
unknown's avatar
unknown committed
4476 4477
	      $$=buff;
	    }
4478 4479
	  }
          ;
unknown's avatar
unknown committed
4480

unknown's avatar
unknown committed
4481

unknown's avatar
unknown committed
4482
set_expr_or_default:
unknown's avatar
unknown committed
4483 4484
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
4485 4486
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
4487
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
unknown's avatar
unknown committed
4488
	;
unknown's avatar
unknown committed
4489 4490


unknown's avatar
unknown committed
4491 4492 4493 4494 4495 4496 4497
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
4498 4499 4500
	table_lock_list
	{}
	;
unknown's avatar
unknown committed
4501 4502 4503

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
4504
	| TABLES;
unknown's avatar
unknown committed
4505 4506 4507

table_lock_list:
	table_lock
unknown's avatar
unknown committed
4508
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
4509 4510 4511

table_lock:
	table_ident opt_table_alias lock_option
4512
	{
unknown's avatar
unknown committed
4513
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
4514 4515
	   YYABORT;
	}
4516
        ;
unknown's avatar
unknown committed
4517 4518 4519

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
4520
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4521
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
4522 4523
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
4524 4525

unlock:
4526 4527
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
4528 4529


4530
/*
unknown's avatar
unknown committed
4531
** Handler: direct access to ISAM functions
4532 4533 4534 4535 4536
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
4537 4538
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
unknown's avatar
unknown committed
4539
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
4540 4541 4542 4543
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
4544 4545
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
unknown's avatar
unknown committed
4546
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4547 4548
	    YYABORT;
	}
unknown's avatar
unknown committed
4549
	| HANDLER_SYM table_ident READ_SYM
4550
	{
unknown's avatar
unknown committed
4551 4552 4553
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
4554 4555
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
unknown's avatar
unknown committed
4556
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4557
	    YYABORT;
unknown's avatar
unknown committed
4558
        }
4559
        handler_read_or_scan where_clause opt_limit_clause {}
4560
        ;
4561

unknown's avatar
unknown committed
4562 4563
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
4564 4565
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
4566 4567 4568

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
4569 4570
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
4571 4572 4573 4574 4575 4576

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;  }
4577 4578
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
4579 4580
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
4581
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
4582
	  if (!(lex->insert_list = new List_item))
4583
	    YYABORT;
4584 4585
	} '(' values ')' { }
        ;
4586 4587

handler_rkey_mode:
unknown's avatar
unknown committed
4588 4589 4590 4591
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
4592 4593
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
4594

unknown's avatar
unknown committed
4595 4596 4597 4598 4599
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
4600 4601 4602 4603 4604
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
4605
	  lex->select_lex.db=0;
4606 4607
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4608
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
4609
	}
4610 4611 4612
	grant_privileges ON opt_table FROM user_list
	{}
	;
unknown's avatar
unknown committed
4613 4614 4615 4616

grant:
	GRANT
	{
unknown's avatar
unknown committed
4617 4618 4619
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
4620 4621
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
4622
	  lex->select_lex.db= 0;
4623 4624
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4625
	  bzero(&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
4626 4627
	}
	grant_privileges ON opt_table TO_SYM user_list
4628 4629 4630
	require_clause grant_options
	{}
	;
unknown's avatar
unknown committed
4631 4632 4633

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
4634
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
4635 4636
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
unknown's avatar
unknown committed
4637 4638 4639

grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
4640
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
4641 4642

grant_privilege:
4643 4644 4645 4646
	SELECT_SYM 	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
	| 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
4647 4648
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
4649 4650 4651 4652
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
unknown's avatar
unknown committed
4653
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
4654 4655 4656 4657
	| 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
4658 4659 4660 4661 4662 4663 4664 4665
	| 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
4666

unknown's avatar
unknown committed
4667

4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
unknown's avatar
unknown committed
4680 4681 4682 4683
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
4684
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
4685 4686 4687 4688 4689 4690 4691 4692 4693
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
4694
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
4695 4696 4697 4698 4699 4700 4701 4702 4703
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
4704
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
4705 4706 4707 4708 4709
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
4710

unknown's avatar
unknown committed
4711 4712 4713
opt_table:
	'*'
	  {
4714
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4715
	    lex->current_select->select_lex()->db= lex->thd->db;
unknown's avatar
unknown committed
4716
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4717 4718
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4719
	    {
4720
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
4721
	      YYABORT;
unknown's avatar
unknown committed
4722
	    }
unknown's avatar
unknown committed
4723 4724 4725
	  }
	| ident '.' '*'
	  {
4726
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4727
	    lex->current_select->select_lex()->db = $1.str;
unknown's avatar
unknown committed
4728
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4729 4730
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4731
	    {
4732
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4733 4734 4735 4736 4737
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
4738
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4739
	    lex->current_select->select_lex()->db = NULL;
unknown's avatar
unknown committed
4740 4741
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
4742
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4743
	    {
4744
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4745 4746 4747 4748 4749
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
4750
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4751
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
unknown's avatar
unknown committed
4752
	      YYABORT;
unknown's avatar
unknown committed
4753
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4754
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
4755 4756
	  }
          ;
unknown's avatar
unknown committed
4757 4758 4759


user_list:
4760 4761 4762 4763 4764 4765 4766
	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
4767 4768 4769 4770 4771 4772 4773 4774


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
unknown's avatar
unknown committed
4775
	     char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
unknown's avatar
unknown committed
4776 4777
	     if (buff)
	     {
4778 4779
	       make_scrambled_password(buff,$4.str,use_old_passwords,
				       &YYTHD->rand);
unknown's avatar
unknown committed
4780 4781 4782 4783 4784 4785 4786 4787
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
4788 4789
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
4790 4791 4792


opt_column_list:
unknown's avatar
unknown committed
4793 4794 4795 4796 4797
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
4798
	| '(' column_list ')';
unknown's avatar
unknown committed
4799 4800 4801

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
4802
	| column_list_id;
unknown's avatar
unknown committed
4803 4804 4805 4806

column_list_id:
	ident
	{
4807
	  String *new_str = new String((const char*) $1.str,$1.length,default_charset_info);
unknown's avatar
unknown committed
4808 4809
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
4810
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4811 4812
	  while ((point=iter++))
	  {
4813 4814
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
4815 4816
		break;
	  }
unknown's avatar
unknown committed
4817
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
4818
	  if (point)
unknown's avatar
unknown committed
4819
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
4820
	  else
unknown's avatar
unknown committed
4821
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
4822 4823
	}
        ;
unknown's avatar
unknown committed
4824

unknown's avatar
unknown committed
4825 4826

require_clause: /* empty */
4827
        | REQUIRE_SYM require_list
4828 4829 4830
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
4831
        | REQUIRE_SYM SSL_SYM
4832 4833 4834
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
4835
        | REQUIRE_SYM X509_SYM
4836 4837 4838 4839 4840 4841 4842
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
4843
          ;
unknown's avatar
unknown committed
4844

unknown's avatar
unknown committed
4845
grant_options:
unknown's avatar
unknown committed
4846
	/* empty */ {}
unknown's avatar
unknown committed
4847
	| WITH grant_option_list;
unknown's avatar
unknown committed
4848

unknown's avatar
unknown committed
4849 4850
grant_option_list:
	grant_option_list grant_option {}
4851 4852
	| grant_option {}
        ;
unknown's avatar
unknown committed
4853 4854 4855

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
4856
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
4857
        {
4858
	  Lex->mqh.questions=$2;
4859
	  Lex->mqh.bits |= 1;
4860
	}
4861
        | MAX_UPDATES_PER_HOUR ULONG_NUM
4862
        {
4863
	  Lex->mqh.updates=$2;
4864
	  Lex->mqh.bits |= 2;
4865
	}
4866
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
4867
        {
4868
	  Lex->mqh.connections=$2;
4869
	  Lex->mqh.bits |= 4;
4870 4871
	}
        ;
4872

unknown's avatar
unknown committed
4873
begin:
4874 4875
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
unknown's avatar
unknown committed
4876 4877 4878

opt_work:
	/* empty */ {}
4879 4880
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
4881 4882

commit:
unknown's avatar
unknown committed
4883
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
4884 4885

rollback:
unknown's avatar
unknown committed
4886
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
4887 4888 4889


/*
unknown's avatar
unknown committed
4890
   UNIONS : glue selects together
4891 4892 4893
*/


4894
union_clause:
4895
	/* empty */ {}
unknown's avatar
unknown committed
4896 4897
	| union_list
	;
4898 4899

union_list:
unknown's avatar
unknown committed
4900
	UNION_SYM    union_option
4901 4902 4903 4904 4905
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
4906
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
4907
	    YYABORT;
4908
	  }
4909
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4910
	  {
4911
	    send_error(lex->thd, ER_SYNTAX_ERROR);
4912 4913
	    YYABORT;
	  }
4914
	  if (mysql_new_select(lex, 0))
4915
	    YYABORT;
unknown's avatar
unknown committed
4916
          mysql_init_select(lex);
4917
	  lex->current_select->linkage=UNION_TYPE;
unknown's avatar
unknown committed
4918
	}
4919
	select_init {}
4920
	;
4921 4922

union_opt:
unknown's avatar
unknown committed
4923
	union_list {}
unknown's avatar
unknown committed
4924 4925
	| optional_order_or_limit {}
	;
4926 4927

optional_order_or_limit:
4928
      	/* Empty */ {}
4929 4930
	|
	  {
unknown's avatar
unknown committed
4931 4932
	    THD *thd= YYTHD;
	    LEX *lex= &thd->lex;
unknown's avatar
unknown committed
4933
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
unknown's avatar
unknown committed
4934
	    SELECT_LEX *sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
4935 4936 4937 4938
	    SELECT_LEX_UNIT *unit= sel->master_unit();
	    unit->global_parameters= unit;
	    unit->no_table_names_allowed= 1;
	    lex->current_select= unit;
unknown's avatar
unknown committed
4939
	    thd->where= "global ORDER clause";
4940
	  }
4941
	order_or_limit
unknown's avatar
unknown committed
4942 4943 4944 4945 4946
          {
	    THD *thd= YYTHD;
	    thd->lex.current_select->no_table_names_allowed= 0;
	    thd->where= "";
          }
4947 4948 4949
	;

order_or_limit:
4950 4951
	order_clause opt_limit_clause_init
	| limit_clause
4952
	;
unknown's avatar
unknown committed
4953 4954

union_option:
4955
	/* empty */ {}
unknown's avatar
unknown committed
4956
	| ALL {Select->master_unit()->union_option= 1;};
4957

unknown's avatar
unknown committed
4958 4959
singlerow_subselect:
	subselect_start singlerow_subselect_init
unknown's avatar
unknown committed
4960 4961 4962 4963
	subselect_end
	{
	  $$= $2;
	};
4964

unknown's avatar
unknown committed
4965
singlerow_subselect_init:
4966
	select_init2
unknown's avatar
unknown committed
4967
	{
unknown's avatar
unknown committed
4968
	  $$= new Item_singlerow_subselect(YYTHD,
4969 4970
					   Lex->current_select->master_unit()->
                                             first_select());
unknown's avatar
unknown committed
4971
	};
unknown's avatar
unknown committed
4972 4973

exists_subselect:
unknown's avatar
unknown committed
4974 4975 4976 4977 4978
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
4979 4980

exists_subselect_init:
4981
	select_init2
unknown's avatar
unknown committed
4982
	{
4983
	  $$= new Item_exists_subselect(YYTHD,
4984 4985
					Lex->current_select->master_unit()->
					  first_select());
unknown's avatar
unknown committed
4986
	};
4987

unknown's avatar
unknown committed
4988 4989 4990 4991 4992 4993 4994 4995
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
4996
  select_init2
unknown's avatar
unknown committed
4997
  {
unknown's avatar
unknown committed
4998
    $$= Lex->current_select->master_unit()->first_select();
unknown's avatar
unknown committed
4999 5000
  };

5001
subselect_start:
5002
	'(' SELECT_SYM
unknown's avatar
unknown committed
5003
	{
5004
	  LEX *lex=Lex;
5005
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
5006 5007 5008 5009
	       lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
unknown's avatar
unknown committed
5010 5011 5012
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
5013 5014

subselect_end:
unknown's avatar
unknown committed
5015 5016 5017
	')'
	{
	  LEX *lex=Lex;
5018
	  lex->current_select = lex->current_select->return_after_parsing();
unknown's avatar
unknown committed
5019
	};