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

bk@work.mysql.com's avatar
bk@work.mysql.com 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

bk@work.mysql.com's avatar
bk@work.mysql.com 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

bk@work.mysql.com's avatar
bk@work.mysql.com 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 */

tim@cane.mysql.fi's avatar
tim@cane.mysql.fi committed
17
/* sql_yacc.yy */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
18 19 20 21 22 23

%{
#define MYSQL_YACC
#define YYINITDEPTH 100
#define YYMAXDEPTH 3200				/* Because of 64K stack */
#define Lex current_lex
24
#define Select Lex->select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
25
#include "mysql_priv.h"
26
#include "slave.h"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
27 28 29
#include "sql_acl.h"
#include "lex_symbol.h"
#include <myisam.h>
30
#include <myisammrg.h>
31

bk@work.mysql.com's avatar
bk@work.mysql.com committed
32 33 34
extern void yyerror(const char*);
int yylex(void *yylval);

35
#define yyoverflow(A,B,C,D,E,F) if (my_yyoverflow((B),(D),(int*) (F))) { yyerror((char*) (A)); return 2; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
36 37 38

inline Item *or_or_concat(Item* A, Item* B)
{
39
  return (current_thd->sql_mode & MODE_PIPES_AS_CONCAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
40 41 42 43 44 45 46
          (Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B));
}

%}
%union {
  int  num;
  ulong ulong_num;
47
  ulonglong ulonglong_number;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
48 49 50 51 52 53 54 55
  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;
56 57 58 59 60 61
  String *string;
  key_part_spec *key_part;
  TABLE_LIST *table_list;
  udf_func *udf;
  LEX_USER *lex_user;
  sys_var *variable;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
62 63 64
  Key::Keytype key_type;
  enum db_type db_type;
  enum row_type row_type;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
65
  enum ha_rkey_function ha_rkey_mode;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
66
  enum enum_tx_isolation tx_isolation;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
67
  enum Item_cast cast_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
68
  enum Item_udftype udf_type;
69
  thr_lock_type lock_type;
70
  interval_type interval;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
71 72 73 74 75 76 77 78 79 80
}

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

%pure_parser					/* We have threads */

%token	END_OF_INPUT

81 82 83 84 85 86
%token CLOSE_SYM
%token HANDLER_SYM
%token LAST_SYM
%token NEXT_SYM
%token PREV_SYM

bk@work.mysql.com's avatar
bk@work.mysql.com committed
87 88 89 90 91 92 93 94 95 96 97 98
%token	EQ
%token	EQUAL_SYM
%token	GE
%token	GT_SYM
%token	LE
%token	LT
%token	NE
%token	IS
%token	SHIFT_LEFT
%token	SHIFT_RIGHT
%token  SET_VAR

99
%token	ABORT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
100 101
%token	ADD
%token	AFTER_SYM
102 103 104 105 106
%token	ALTER
%token	ANALYZE_SYM
%token	AVG_SYM
%token	BEGIN_SYM
%token	BINLOG_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
107
%token	CHANGE
108 109 110 111
%token	CLIENT_SYM
%token	COMMENT_SYM
%token	COMMIT_SYM
%token	COUNT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
112 113
%token	CREATE
%token	CROSS
114
%token  CUBE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
115
%token	DELETE_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
116
%token	DO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
117
%token	DROP
118 119
%token	EVENTS_SYM
%token	EXECUTE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
120
%token	FLUSH_SYM
121 122
%token	INSERT
%token	IO_THREAD
bk@work.mysql.com's avatar
bk@work.mysql.com committed
123 124
%token	KILL_SYM
%token	LOAD
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
125
%token	LOCKS_SYM
126 127 128 129
%token	LOCK_SYM
%token	MASTER_SYM
%token	MAX_SYM
%token	MIN_SYM
130
%token	NONE_SYM
131 132 133 134 135 136
%token	OPTIMIZE
%token	PURGE
%token	REPAIR
%token	REPLICATION
%token	RESET_SYM
%token	ROLLBACK_SYM
137
%token  ROLLUP_SYM
138
%token	SAVEPOINT_SYM
139 140 141 142 143 144 145 146 147 148
%token	SELECT_SYM
%token	SHOW
%token	SLAVE
%token	SQL_THREAD
%token	START_SYM
%token	STD_SYM
%token	STOP_SYM
%token	SUM_SYM
%token	SUPER_SYM
%token	TRUNCATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
149
%token	UNLOCK_SYM
150
%token	UPDATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
151 152 153 154 155 156 157

%token	ACTION
%token	AGGREGATE_SYM
%token	ALL
%token	AND
%token	AS
%token	ASC
158
%token	AUTO_INC
bk@work.mysql.com's avatar
bk@work.mysql.com committed
159
%token	AVG_ROW_LENGTH
160
%token	BACKUP_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
161 162 163 164
%token	BERKELEY_DB_SYM
%token	BINARY
%token	BIT_SYM
%token	BOOL_SYM
165
%token	BOOLEAN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
166 167
%token	BOTH
%token	BY
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
168
%token	CACHE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
169
%token	CASCADE
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
170
%token	CAST_SYM
171
%token	CHARSET
bk@work.mysql.com's avatar
bk@work.mysql.com committed
172 173
%token	CHECKSUM_SYM
%token	CHECK_SYM
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
174
%token	COMMITTED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
175 176
%token	COLUMNS
%token	COLUMN_SYM
177
%token	CONCURRENT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
178
%token	CONSTRAINT
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
179
%token	CONVERT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
180 181 182 183 184 185 186
%token	DATABASES
%token	DATA_SYM
%token	DEFAULT
%token	DELAYED_SYM
%token	DELAY_KEY_WRITE_SYM
%token	DESC
%token	DESCRIBE
187
%token	DES_KEY_FILE
188
%token	DISABLE_SYM
189
%token	DISTINCT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
190
%token	DYNAMIC_SYM
191
%token	ENABLE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
192 193
%token	ENCLOSED
%token	ESCAPED
194
%token	DIRECTORY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
195 196 197 198 199 200 201
%token	ESCAPE_SYM
%token	EXISTS
%token	EXTENDED_SYM
%token	FILE_SYM
%token	FIRST_SYM
%token	FIXED_SYM
%token	FLOAT_NUM
202
%token	FORCE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
203 204 205
%token	FOREIGN
%token	FROM
%token	FULL
206 207
%token	FULLTEXT_SYM
%token	GLOBAL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
208 209 210 211 212 213 214 215 216 217 218 219
%token	GRANT
%token	GRANTS
%token	GREATEST_SYM
%token	GROUP
%token	HAVING
%token	HEAP_SYM
%token	HEX_NUM
%token	HIGH_PRIORITY
%token	HOSTS_SYM
%token	IDENT
%token	IGNORE_SYM
%token	INDEX
220
%token	INDEXES
bk@work.mysql.com's avatar
bk@work.mysql.com committed
221 222
%token	INFILE
%token	INNER_SYM
223
%token	INNOBASE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
224 225
%token	INTO
%token	IN_SYM
226
%token	ISOLATION
bk@work.mysql.com's avatar
bk@work.mysql.com committed
227 228 229 230 231 232
%token	ISAM_SYM
%token	JOIN_SYM
%token	KEYS
%token	KEY_SYM
%token	LEADING
%token	LEAST_SYM
233
%token	LEVEL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
234 235 236 237
%token	LEX_HOSTNAME
%token	LIKE
%token	LINES
%token	LOCAL_SYM
238
%token	LOG_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
239 240 241 242
%token	LOGS_SYM
%token	LONG_NUM
%token	LONG_SYM
%token	LOW_PRIORITY
243 244 245 246 247 248 249 250 251 252
%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
bk@work.mysql.com's avatar
bk@work.mysql.com committed
253 254
%token	MATCH
%token	MAX_ROWS
255 256 257
%token	MAX_CONNECTIONS_PER_HOUR
%token	MAX_QUERIES_PER_HOUR
%token	MAX_UPDATES_PER_HOUR
258
%token	MEDIUM_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
259
%token	MERGE_SYM
260
%token	MEMORY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
261 262 263 264
%token	MIN_ROWS
%token	MYISAM_SYM
%token	NATIONAL_SYM
%token	NATURAL
265
%token	NEW_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
266 267 268 269 270
%token	NCHAR_SYM
%token	NOT
%token	NO_SYM
%token	NULL_SYM
%token	NUM
271
%token	OFFSET_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
272
%token	ON
273
%token	OPEN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
274 275 276
%token	OPTION
%token	OPTIONALLY
%token	OR
277
%token	OR_OR_CONCAT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
278 279 280
%token	ORDER_SYM
%token	OUTER
%token	OUTFILE
281
%token	DUMPFILE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
282 283 284 285 286 287
%token	PACK_KEYS_SYM
%token	PARTIAL
%token	PRIMARY_SYM
%token	PRIVILEGES
%token	PROCESS
%token	PROCESSLIST_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
288
%token	QUERY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
289
%token	RAID_0_SYM
290 291
%token	RAID_STRIPED_SYM
%token	RAID_TYPE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
292 293 294 295 296 297 298 299
%token	RAID_CHUNKS
%token	RAID_CHUNKSIZE
%token	READ_SYM
%token	REAL_NUM
%token	REFERENCES
%token	REGEXP
%token	RELOAD
%token	RENAME
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
300
%token	REPEATABLE_SYM
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
301
%token	REQUIRE_SYM
302 303
%token	RESOURCES
%token	RESTORE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
304 305 306 307 308 309
%token	RESTRICT
%token	REVOKE
%token	ROWS_SYM
%token	ROW_FORMAT_SYM
%token	ROW_SYM
%token	SET
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
310 311
%token	SERIALIZABLE_SYM
%token	SESSION_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
312
%token	SHUTDOWN
313
%token	SSL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
314 315 316
%token	STARTING
%token	STATUS_SYM
%token	STRAIGHT_JOIN
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
317
%token	SUBJECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
318 319 320 321 322
%token	TABLES
%token	TABLE_SYM
%token	TEMPORARY
%token	TERMINATED
%token	TEXT_STRING
323 324 325 326
%token	TO_SYM
%token	TRAILING
%token	TRANSACTION_SYM
%token	TYPE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
327 328 329 330
%token	FUNC_ARG0
%token	FUNC_ARG1
%token	FUNC_ARG2
%token	FUNC_ARG3
331 332 333
%token	UDF_RETURNS_SYM
%token	UDF_SONAME_SYM
%token	UDF_SYM
334
%token	UNCOMMITTED_SYM
335 336 337
%token	UNION_SYM
%token	UNIQUE_SYM
%token	USAGE
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
338
%token	USE_FRM
339 340 341
%token	USE_SYM
%token	USING
%token	VALUES
bk@work.mysql.com's avatar
bk@work.mysql.com committed
342 343 344 345
%token	VARIABLES
%token	WHERE
%token	WITH
%token	WRITE_SYM
346
%token	X509_SYM
347
%token  XOR
348
%token	COMPRESSED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
349 350 351 352

%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
353
%token	CHANGED
bk@work.mysql.com's avatar
bk@work.mysql.com committed
354 355 356 357 358 359
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
360
%token	FAST_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
361 362 363 364 365 366 367 368 369 370
%token	FLOAT_SYM
%token	INT_SYM
%token	LIMIT
%token	LONGBLOB
%token	LONGTEXT
%token	MEDIUMBLOB
%token	MEDIUMINT
%token	MEDIUMTEXT
%token	NUMERIC_SYM
%token	PRECISION
371
%token	QUICK
bk@work.mysql.com's avatar
bk@work.mysql.com committed
372
%token	REAL
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
373
%token	SIGNED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
374 375 376 377 378 379 380 381
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
382
%token	ULONGLONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
383
%token	UNSIGNED
384 385 386
%token	VARBINARY
%token	VARCHAR
%token	VARYING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
387 388
%token	ZEROFILL

389
%token	AGAINST
bk@work.mysql.com's avatar
bk@work.mysql.com committed
390 391 392 393 394 395
%token	ATAN
%token	BETWEEN_SYM
%token	BIT_AND
%token	BIT_OR
%token	CASE_SYM
%token	CONCAT
396
%token	CONCAT_WS
bk@work.mysql.com's avatar
bk@work.mysql.com committed
397 398 399 400 401 402 403 404 405 406
%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
407 408
%token	DES_ENCRYPT_SYM
%token	DES_DECRYPT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
%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
%token	GROUP_UNIQUE_USERS
%token	HOUR_MINUTE_SYM
%token	HOUR_SECOND_SYM
%token	HOUR_SYM
%token	IDENTIFIED_SYM
%token	IF
425
%token	INSERT_METHOD
bk@work.mysql.com's avatar
bk@work.mysql.com committed
426 427 428 429 430
%token	INTERVAL_SYM
%token	LAST_INSERT_ID
%token	LEFT
%token	LOCATE
%token	MAKE_SET_SYM
431
%token	MASTER_POS_WAIT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
432 433
%token	MINUTE_SECOND_SYM
%token	MINUTE_SYM
434
%token	MODE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
435 436 437 438 439 440 441 442 443 444 445
%token	MODIFY_SYM
%token	MONTH_SYM
%token	NOW_SYM
%token	PASSWORD
%token	POSITION_SYM
%token	PROCEDURE
%token	RAND
%token	REPLACE
%token	RIGHT
%token	ROUND
%token	SECOND_SYM
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
446
%token	SHARE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
447 448 449 450 451 452 453 454 455 456 457 458 459 460
%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
461
%token	WORK_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
462 463 464
%token	YEAR_MONTH_SYM
%token	YEAR_SYM
%token	YEARWEEK
465 466 467
%token	BENCHMARK_SYM
%token	END
%token	THEN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
468

469 470 471 472
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
473
%token	SQL_SMALL_RESULT
474
%token  SQL_BUFFER_RESULT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
475

476 477
%token  ISSUER_SYM
%token  SUBJECT_SYM
478
%token  CIPHER_SYM
479

bk@work.mysql.com's avatar
bk@work.mysql.com committed
480 481 482 483 484 485 486 487 488 489 490
%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	'-' '+'
%left	'*' '/' '%'
%left	NEG '~'
491 492
%left   XOR
%left   '^'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
493 494 495 496 497
%right	NOT
%right	BINARY

%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
498
	ULONGLONG_NUM field_ident select_alias ident ident_or_text
bk@work.mysql.com's avatar
bk@work.mysql.com committed
499 500 501 502 503 504 505 506 507 508 509 510

%type <lex_str_ptr>
	opt_table_alias

%type <table>
	table_ident

%type <simple_string>
	remember_name remember_end opt_len opt_ident opt_db text_or_password
	opt_escape

%type <string>
511
	text_string 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
512 513

%type <num>
514
	type int_type real_type order_dir opt_field_spec lock_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
515
	udf_type if_exists opt_local opt_table_options table_options
516
	table_option opt_if_not_exists opt_var_type opt_var_ident_type
517
	opt_temporary 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
518 519

%type <ulong_num>
520
	ULONG_NUM raid_types merge_insert_types
bk@work.mysql.com's avatar
bk@work.mysql.com committed
521

522 523
%type <ulonglong_number>
	ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
524

525 526 527
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

bk@work.mysql.com's avatar
bk@work.mysql.com committed
528
%type <item>
529
	literal text_literal insert_ident order_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
530 531
	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
532
	using_list expr_or_default set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
533 534

%type <item_list>
535
	expr_list udf_expr_list when_list ident_list ident_list_arg
bk@work.mysql.com's avatar
bk@work.mysql.com committed
536 537

%type <key_type>
538
	key_type opt_unique_or_fulltext
bk@work.mysql.com's avatar
bk@work.mysql.com committed
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
	join_table_list join_table

%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

559
%type <tx_isolation> isolation_types
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
560

monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
561 562
%type <ha_rkey_mode> handler_rkey_mode

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
563 564
%type <cast_type> cast_type

bk@work.mysql.com's avatar
bk@work.mysql.com committed
565 566 567 568 569 570
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

571 572
%type <variable> internal_variable_name

bk@work.mysql.com's avatar
bk@work.mysql.com committed
573
%type <NONE>
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
574
	query verb_clause create change select do drop insert replace insert2
575 576
	insert_values update delete truncate rename
	show describe load alter optimize flush
577 578
	reset purge begin commit rollback savepoint
	slave master_def master_defs
579
	repair restore backup analyze check start
580
	field_list field_list_item field_spec kill column_def key_def
bk@work.mysql.com's avatar
bk@work.mysql.com committed
581 582 583
	select_item_list select_item values_list no_braces
	limit_clause delete_limit_clause fields opt_values values
	procedure_list procedure_list2 procedure_item
584
	when_list2 expr_list2  handler
bk@work.mysql.com's avatar
bk@work.mysql.com committed
585 586 587 588
	opt_precision opt_ignore opt_column opt_restrict
	grant revoke set lock unlock string_list field_options field_option
	field_opt_list opt_binary table_lock_list table_lock varchar
	references opt_on_delete opt_on_delete_list opt_on_delete_item use
589
	opt_delete_options opt_delete_option
590
	opt_outer table_list table_name opt_option opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
591 592
	opt_attribute opt_attribute_list attribute column_list column_list_id
	opt_column_list grant_privileges opt_table user_list grant_option
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
593
	grant_privilege grant_privilege_list
594
	flush_options flush_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
595 596
	equal optional_braces opt_key_definition key_usage_list2
	opt_mi_check_type opt_to mi_check_types normal_join
597
	table_to_table_list table_to_table opt_table_list opt_as
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
598
	handler_rkey_function handler_read_or_scan
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
599
	single_multi table_wild_list table_wild_one opt_wild opt_union union_list
600
	precision union_option opt_and
601
END_OF_INPUT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
602 603 604 605 606 607 608 609 610

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM THEN_SYM WHEN_SYM
%%


query:
	END_OF_INPUT
611
	{
612 613
	   THD *thd=current_thd;
	   if (!thd->bootstrap &&
614
	      (!(thd->lex.select_lex.options & OPTION_FOUND_COMMENT)))
615
	   {
bk@work.mysql.com's avatar
bk@work.mysql.com committed
616
	     send_error(&current_thd->net,ER_EMPTY_QUERY);
617 618 619 620 621 622
	     YYABORT;
 	   }
	   else
	   {
	     thd->lex.sql_command = SQLCOM_EMPTY_QUERY;
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
623
	}
624
	| verb_clause END_OF_INPUT {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
625 626 627 628

verb_clause:
	  alter
	| analyze
629
	| backup
bk@work.mysql.com's avatar
bk@work.mysql.com committed
630 631 632 633 634 635 636
	| begin
	| change
	| check
	| commit
	| create
	| delete
	| describe
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
637
	| do
bk@work.mysql.com's avatar
bk@work.mysql.com committed
638 639 640 641 642 643 644 645
	| drop
	| grant
	| insert
	| flush
	| load
	| lock
	| kill
	| optimize
646
	| purge  
647
	| rename
bk@work.mysql.com's avatar
bk@work.mysql.com committed
648 649
        | repair
	| replace
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
650
	| reset
651
	| restore
bk@work.mysql.com's avatar
bk@work.mysql.com committed
652 653
	| revoke
	| rollback
654
	| savepoint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
655 656
	| select
	| set
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
657
	| slave
658
	| start
bk@work.mysql.com's avatar
bk@work.mysql.com committed
659
	| show
660
	| truncate
661
	| handler
bk@work.mysql.com's avatar
bk@work.mysql.com committed
662 663
	| unlock
	| update
664
	| use;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
665 666 667 668

/* change master */

change:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
669
       CHANGE MASTER_SYM TO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
670 671 672
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
673
	  bzero((char*) &lex->mi, sizeof(lex->mi));
674 675 676 677
        }
       master_defs
	{}
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
678 679 680

master_defs:
       master_def
681
       | master_defs ',' master_def;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
682

bk@work.mysql.com's avatar
bk@work.mysql.com committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
master_def:
       MASTER_HOST_SYM EQ TEXT_STRING
       {
	 Lex->mi.host = $3.str;
       }
       |
       MASTER_USER_SYM EQ TEXT_STRING
       {
	 Lex->mi.user = $3.str;
       }
       |
       MASTER_PASSWORD_SYM EQ TEXT_STRING
       {
	 Lex->mi.password = $3.str;
       }
       |
       MASTER_LOG_FILE_SYM EQ TEXT_STRING
       {
	 Lex->mi.log_file_name = $3.str;
       }
       |
704
       MASTER_PORT_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
705 706 707 708
       {
	 Lex->mi.port = $3;
       }
       |
709
       MASTER_LOG_POS_SYM EQ ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
710 711
       {
	 Lex->mi.pos = $3;
712 713 714 715 716 717 718 719 720 721 722 723
         /* 
            If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
            instead of causing subsequent errors. 
            We need to do it in this file, because only there we know that 
            MASTER_LOG_POS has been explicitely specified. On the contrary
            in change_master() (sql_repl.cc) we cannot distinguish between 0
            (MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
            whereas we want to distinguish (specified 0 means "read the binlog
            from 0" (4 in fact), unspecified means "don't change the position
            (keep the preceding value)").
         */
         Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
724 725
       }
       |
726
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
727 728 729
       {
	 Lex->mi.connect_retry = $3;
       }
730 731 732 733 734 735 736 737 738
       |
       RELAY_LOG_FILE_SYM EQ TEXT_STRING
       {
	 Lex->mi.relay_log_name = $3.str;
       }
       |
       RELAY_LOG_POS_SYM EQ ULONG_NUM
       {
	 Lex->mi.relay_log_pos = $3;
739 740
         /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
         Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
741
       };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
742

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
743

bk@work.mysql.com's avatar
bk@work.mysql.com committed
744 745 746 747 748 749 750
/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
751
	  if (!add_table_to_list($5,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
752
				 ($2 & HA_LEX_CREATE_TMP_TABLE ?
753 754
				   &tmp_table_alias : (LEX_STRING*) 0),
				 TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
755 756 757 758 759 760 761
	    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;
762
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
763 764
	}
	create2
765
	  {Lex->select= &Lex->select_lex;}
766
	| CREATE opt_unique_or_fulltext INDEX ident ON table_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
767
	  {
768 769
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
770
	    if (!add_table_to_list($6, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
771
	      YYABORT;
772 773 774 775
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
776 777 778
	  }
	  '(' key_list ')'
	  {
779 780 781
	    LEX *lex=Lex;
	    lex->key_list.push_back(new Key($2,$4.str,lex->col_list));
	    lex->col_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
782 783 784
	  }
	| CREATE DATABASE opt_if_not_exists ident
	  {
785 786 787 788
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
789 790 791
	  }
	| CREATE udf_func_type UDF_SYM ident
	  {
792 793 794 795 796
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
	    lex->udf.name=$4.str;
	    lex->udf.name_length=$4.length;
	    lex->udf.type= $2;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
797 798 799
	  }
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
	  {
800 801 802
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
803
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
804 805

create2:
serg@serg.mylan's avatar
serg@serg.mylan committed
806
	'(' create2a {}
807
	| opt_create_table_options create3 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
808

serg@serg.mylan's avatar
serg@serg.mylan committed
809 810 811
create2a:
        field_list ')' opt_create_table_options create3 {}
	|  create_select ')' { Select->braces= 1;} union_opt {}
812
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
813 814

create3:
815
	/* empty */ {}
serg@serg.mylan's avatar
serg@serg.mylan committed
816 817 818 819
	| opt_duplicate opt_as     create_select
          { Select->braces= 0;} opt_union {}
	| opt_duplicate opt_as '(' create_select ')'
          { Select->braces= 1;} union_opt {}
820 821
        ;

serg@serg.mylan's avatar
serg@serg.mylan committed
822
create_select:
823
          SELECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
824
          {
825 826
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
827 828 829 830 831
	    if (lex->sql_command == SQLCOM_INSERT)
	      lex->sql_command= SQLCOM_INSERT_SELECT;
	    else if (lex->sql_command == SQLCOM_REPLACE)
	      lex->sql_command= SQLCOM_REPLACE_SELECT;
	    lex->select->table_list.save_and_clear(&lex->save_list);
832
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
833
          }
serg@serg.mylan's avatar
serg@serg.mylan committed
834
          select_options select_item_list opt_select_from
835
	  { Lex->select->table_list.push_front(&Lex->save_list); }
836
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
837

838 839
opt_as:
	/* empty */ {}
840
	| AS	    {};
841

bk@work.mysql.com's avatar
bk@work.mysql.com committed
842
opt_table_options:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
843
	/* empty */	 { $$= 0; }
844
	| table_options  { $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
845 846 847

table_options:
	table_option	{ $$=$1; }
848
	| table_option table_options { $$= $1 | $2; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
849

bk@work.mysql.com's avatar
bk@work.mysql.com committed
850
table_option:
851
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
852 853

opt_if_not_exists:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
854
	/* empty */	 { $$= 0; }
855
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
856 857 858

opt_create_table_options:
	/* empty */
859
	| create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
860 861 862

create_table_options:
	create_table_option
863
	| create_table_option create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
864 865 866

create_table_option:
	TYPE_SYM EQ table_types		{ Lex->create_info.db_type= $3; }
867 868 869
	| MAX_ROWS EQ ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS EQ ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH EQ ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
870 871
	| PASSWORD EQ TEXT_STRING	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM EQ TEXT_STRING	{ Lex->create_info.comment=$3.str; }
872
	| AUTO_INC EQ ulonglong_num	{ Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;}
873 874
	| PACK_KEYS_SYM EQ 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 EQ 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;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
875 876
	| CHECKSUM_SYM EQ ULONG_NUM	{ Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; }
	| DELAY_KEY_WRITE_SYM EQ ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
877
	| ROW_FORMAT_SYM EQ row_types	{ Lex->create_info.row_type= $3; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
878 879 880
	| RAID_TYPE EQ raid_types	{ Lex->create_info.raid_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKS EQ ULONG_NUM	{ Lex->create_info.raid_chunks= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKSIZE EQ ULONG_NUM	{ Lex->create_info.raid_chunksize= $3*RAID_BLOCK_SIZE; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
881 882 883 884
	| UNION_SYM EQ '(' table_list ')'
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
885 886
	    TABLE_LIST *table_list= (TABLE_LIST*) lex->select->table_list.first;
	    lex->create_info.merge_list= lex->select->table_list;
887 888
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
889 890
	    lex->select->table_list.elements=1;
	    lex->select->table_list.next= (byte**) &(table_list->next);
891
	    table_list->next=0;
892
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
893
	  }
894 895
	| CHARSET opt_equal ident {}
	| CHAR_SYM SET opt_equal ident {}
896
	| INSERT_METHOD EQ merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
897
	| DATA_SYM DIRECTORY_SYM EQ TEXT_STRING	{ Lex->create_info.data_file_name= $4.str; }
898
	| INDEX DIRECTORY_SYM EQ TEXT_STRING	{ Lex->create_info.index_file_name= $4.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
899 900 901 902 903 904

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
905
	| MEMORY_SYM	{ $$= DB_TYPE_HEAP; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
906
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
907
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
908 909 910 911 912

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
913
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
914 915 916 917

raid_types:
	RAID_STRIPED_SYM { $$= RAID_TYPE_0; }
	| RAID_0_SYM	 { $$= RAID_TYPE_0; }
918
	| ULONG_NUM	 { $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
919

920 921 922
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
923
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
924

bk@work.mysql.com's avatar
bk@work.mysql.com committed
925 926
opt_select_from:
	/* empty */
927
	| select_from select_lock_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
928 929 930

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
931
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
932 933 934 935

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
936
	| INT_SYM {$$ = (int) INT_RESULT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
937 938 939

field_list:
	  field_list_item
940
	| field_list ',' field_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
941 942 943


field_list_item:
944 945 946 947 948
           column_def
         | key_def
         ;

column_def:
949
	  field_spec check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
950 951 952 953
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
954 955 956 957
        ;

key_def:
	  key_type opt_ident '(' key_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
958
	  {
959 960 961
	    LEX *lex=Lex;
	    lex->key_list.push_back(new Key($1,$2,lex->col_list));
	    lex->col_list.empty();		/* Alloced by sql_alloc */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
962
	  }
963
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
964 965 966
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
967
	| opt_constraint check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
968 969
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
970 971 972 973 974 975 976
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
977 978 979

opt_constraint:
	/* empty */
980
	| CONSTRAINT opt_ident;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
981 982 983 984

field_spec:
	field_ident
	 {
985 986 987
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
	   lex->default_value=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
988 989 990
	 }
	type opt_attribute
	{
991
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
992 993
	  if (add_field_to_list($1.str,
				(enum enum_field_types) $3,
994 995 996
				lex->length,lex->dec,lex->type,
				lex->default_value,lex->change,
				lex->interval))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
997
	    YYABORT;
998
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047

type:
	int_type opt_len field_options	{ Lex->length=$2; $$=$1; }
	| 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; }
	| char '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
	| BINARY '(' NUM ')' 		{ Lex->length=$3.str;
					  Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
					  Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_VAR_STRING; }
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; Lex->length=$2; }
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
	| TIMESTAMP			{ $$=FIELD_TYPE_TIMESTAMP; }
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
	| TINYBLOB			{ Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_TINY_BLOB; }
	| BLOB_SYM			{ Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_BLOB; }
	| MEDIUMBLOB			{ Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGBLOB			{ Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_LONG_BLOB; }
	| LONG_SYM VARBINARY		{ Lex->type|=BINARY_FLAG;
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONG_SYM varchar		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT			{ $$=FIELD_TYPE_TINY_BLOB; }
	| TEXT_SYM			{ $$=FIELD_TYPE_BLOB; }
	| MEDIUMTEXT			{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT			{ $$=FIELD_TYPE_LONG_BLOB; }
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| ENUM {Lex->interval_list.empty();} '(' string_list ')'
	  {
1048 1049
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1050 1051 1052 1053
	    $$=FIELD_TYPE_ENUM;
	  }
	| SET { Lex->interval_list.empty();} '(' string_list ')'
	  {
1054 1055
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1056
	    $$=FIELD_TYPE_SET;
1057
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1058 1059 1060 1061

char:
	CHAR_SYM {}
	| NCHAR_SYM {}
1062
	| NATIONAL_SYM CHAR_SYM {};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1063

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1064 1065 1066 1067
varchar:
	char VARYING {}
	| VARCHAR {}
	| NATIONAL_SYM VARCHAR {}
1068
	| NCHAR_SYM VARCHAR {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1069 1070 1071 1072 1073 1074

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
1075
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1076 1077

real_type:
1078
	REAL		{ $$= current_thd->sql_mode & MODE_REAL_AS_FLOAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1079 1080
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
1081
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1082 1083 1084 1085 1086


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
1087
	| precision		{};
1088 1089 1090 1091 1092 1093

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
1094
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1095 1096 1097

field_options:
	/* empty */		{}
1098
	| field_opt_list	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1099 1100 1101

field_opt_list:
	field_opt_list field_option {}
1102
	| field_option {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1103 1104

field_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1105
	SIGNED_SYM	{}
1106
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
1107
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1108 1109 1110

opt_len:
	/* empty */	{ $$=(char*) 0; }	/* use default length */
1111
	| '(' NUM ')'	{ $$=$2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1112 1113 1114

opt_precision:
	/* empty */	{}
1115
	| precision	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1116 1117 1118

opt_attribute:
	/* empty */ {}
1119
	| opt_attribute_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1120 1121 1122

opt_attribute_list:
	opt_attribute_list attribute {}
1123
	| attribute;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1124 1125 1126 1127 1128 1129 1130 1131

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; }
	| PRIMARY_SYM KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1132 1133
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
	| COMMENT_SYM text_literal {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1134 1135 1136

opt_binary:
	/* empty */	{}
1137
	| BINARY	{ Lex->type|=BINARY_FLAG; }
1138
	| CHAR_SYM SET opt_equal ident {}
1139
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1140 1141 1142 1143 1144 1145

references:
	REFERENCES table_ident opt_on_delete {}
	| REFERENCES table_ident '(' key_list ')' opt_on_delete
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1146
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1147 1148 1149

opt_on_delete:
	/* empty */ {}
1150
	| opt_on_delete_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1151 1152 1153

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
1154
	| opt_on_delete_item {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1155 1156 1157 1158 1159 1160


opt_on_delete_item:
	ON DELETE_SYM delete_option {}
	| ON UPDATE_SYM delete_option {}
	| MATCH FULL	{}
1161
	| MATCH PARTIAL {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1162 1163 1164 1165 1166 1167

delete_option:
	RESTRICT	 {}
	| CASCADE	 {}
	| SET NULL_SYM {}
	| NO_SYM ACTION {}
1168
	| SET DEFAULT {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1169 1170 1171 1172

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1173 1174
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1175
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
1176
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1177 1178 1179

key_or_index:
	KEY_SYM {}
1180
	| INDEX {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1181 1182 1183 1184

keys_or_index:
	KEYS {}
	| INDEX {}
1185
	| INDEXES {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1186

1187
opt_unique_or_fulltext:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1188 1189
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
1190
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1191 1192 1193

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
1194
	| key_part order_dir		{ Lex->col_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1195 1196 1197

key_part:
	ident			{ $$=new key_part_spec($1.str); }
1198
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1199 1200 1201

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
1202
	| field_ident	{ $$=$1.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1203 1204 1205

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
1206
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
1218
	  if (!add_table_to_list($4, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1219 1220 1221 1222 1223 1224 1225
	    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();
1226 1227 1228 1229
          lex->select->order_list.elements=0;
          lex->select->order_list.first=0;
          lex->select->order_list.next= (byte**) &lex->select->order_list.first;
	  lex->select->db=lex->name=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1230 1231
    	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1232
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1233 1234
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1235
	}
1236 1237 1238
	alter_list
	{}
	;
1239
 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1240
alter_list:
1241
        | alter_list_item
1242
	| alter_list ',' alter_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1243 1244

add_column:
1245
	ADD opt_column { Lex->change=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1246 1247

alter_list_item:
1248 1249
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1250
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
1251 1252 1253 1254 1255
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1256
          field_spec opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1257 1258
	| MODIFY_SYM opt_column field_ident
	  {
1259 1260 1261 1262
	    LEX *lex=Lex;
	    lex->length=lex->dec=0; lex->type=0; lex->interval=0;
	    lex->default_value=0;
            lex->simple_alter=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1263 1264 1265
	  }
	  type opt_attribute
	  {
1266
	    LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1267 1268
	    if (add_field_to_list($3.str,
				  (enum enum_field_types) $5,
1269 1270 1271
				  lex->length,lex->dec,lex->type,
				  lex->default_value, $3.str,
				  lex->interval))
1272
	      YYABORT;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1273
	  }
1274
	  opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1275
	| DROP opt_column field_ident opt_restrict
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
	  {
	    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;
	  }
1286
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1287
	| DROP key_or_index field_ident
1288 1289 1290 1291 1292 1293
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1294 1295
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1296
	| ALTER opt_column field_ident SET DEFAULT literal
1297 1298 1299 1300 1301
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1302
	| ALTER opt_column field_ident DROP DEFAULT
1303 1304 1305 1306 1307
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1308
	| RENAME opt_to table_ident
1309 1310
	  { 
	    LEX *lex=Lex;
1311 1312
	    lex->select->db=$3->db.str;
	    lex->name= $3->table.str;
1313
	  }
1314
        | create_table_options { Lex->simple_alter=0; }
1315
	| order_clause         { Lex->simple_alter=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1316 1317 1318

opt_column:
	/* empty */	{}
1319
	| COLUMN_SYM	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1320 1321 1322

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
1323
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1324 1325 1326 1327

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
1328
	| CASCADE	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1329 1330 1331 1332

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
1333
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1334 1335 1336 1337

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1338
	| EQ		{}
1339
	| AS		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1340

nick@mysql.com's avatar
nick@mysql.com committed
1341 1342 1343
/*
 * The first two deprecate the last two--delete the last two for 4.1 release
 */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1344
slave:
nick@mysql.com's avatar
nick@mysql.com committed
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
	START_SYM SLAVE slave_thread_opts
         {
	   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;
         }
         |
1359
	SLAVE START_SYM slave_thread_opts
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1360
         {
1361 1362 1363
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1364 1365
         }
         |
1366
	SLAVE STOP_SYM slave_thread_opts
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1367
         {
1368 1369 1370
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_STOP;
	   lex->type = 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1371
         };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1372

1373 1374 1375 1376 1377
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

1378 1379 1380
slave_thread_opts:
	slave_thread_opt
	| slave_thread_opts ',' slave_thread_opt;
1381 1382

slave_thread_opt:
1383 1384 1385 1386
	/*empty*/	{} 
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
	| IO_THREAD   	{ Lex->slave_thd_opt|=SLAVE_IO; }
	;
1387
  
1388 1389 1390 1391 1392 1393 1394 1395
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
	table_list FROM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
1396
        };
1397

1398 1399 1400 1401 1402 1403 1404 1405
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
	table_list TO_SYM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
1406
        };
1407

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1408 1409 1410
repair:
	REPAIR table_or_tables
	{
1411 1412 1413
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1414
	}
1415 1416 1417
	table_list opt_mi_repair_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1418

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1419
opt_mi_repair_type:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1420
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1421
	| mi_repair_types {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1422

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1423 1424
mi_repair_types:
	mi_repair_type {}
1425
	| mi_repair_type mi_repair_types {};
1426

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1427
mi_repair_type:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1428
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1429
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
1430
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1431 1432

analyze:
1433
	ANALYZE_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1434
	{
1435 1436 1437
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1438
	}
1439 1440 1441
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1442 1443

check:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1444
	CHECK_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1445
	{
1446 1447 1448
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1449
	}
1450 1451 1452
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1453

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1454 1455
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1456
	| mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1457 1458 1459

mi_check_types:
	mi_check_type {}
1460
	| mi_check_type mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1461 1462 1463 1464 1465 1466

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; }
1467
	| CHANGED  { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; };
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1468

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1469
optimize:
1470
	OPTIMIZE table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1471
	{
1472 1473 1474
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1475
	}
1476 1477 1478
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1479

1480 1481 1482 1483 1484
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1485 1486 1487
	table_to_table_list
	{}
	;
1488 1489 1490

table_to_table_list:
	table_to_table
1491
	| table_to_table_list ',' table_to_table;
1492 1493 1494

table_to_table:
	table_ident TO_SYM table_ident
1495 1496 1497
	{
	   if (!add_table_to_list($1, NULL, TL_OPTION_UPDATING, TL_IGNORE) ||
	       !add_table_to_list($3, NULL, TL_OPTION_UPDATING, TL_IGNORE))
1498
	     YYABORT;
1499
 	};
1500

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1501
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1502
  Select : retrieve data from table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1503 1504 1505 1506
*/


select:
1507
	select_init { Lex->sql_command=SQLCOM_SELECT; };
1508 1509

select_init:
1510
	SELECT_SYM select_part2 { Select->braces= 0;	} opt_union
1511
	|
serg@serg.mylan's avatar
serg@serg.mylan committed
1512
	'(' SELECT_SYM select_part2 ')' { Select->braces= 1;} union_opt;
1513

1514 1515

select_part2:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1516 1517
	{
	  LEX *lex=Lex;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1518
	  lex->lock_option=TL_READ;
1519
	   mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1520
	}
1521
	select_options select_item_list select_into select_lock_type;
1522

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1523
select_into:
1524
	limit_clause {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1525 1526
	| select_from
	| opt_into select_from
1527
	| select_from opt_into;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1528 1529

select_from:
1530
	FROM join_table_list where_clause group_clause having_clause opt_order_clause limit_clause procedure_clause;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1531 1532 1533 1534


select_options:
	/* empty*/
1535
	| select_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1536 1537 1538

select_option_list:
	select_option_list select_option
1539
	| select_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1540 1541

select_option:
1542
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1543 1544 1545 1546 1547 1548
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1549 1550 1551
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
	| 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;
	  }
	| SQL_NO_CACHE_SYM { current_thd->safe_to_cache_query=0; }
1565 1566 1567 1568
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
1569 1570
	| ALL		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1571

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1572 1573 1574
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1575 1576 1577 1578 1579 1580 1581
	  {
	    LEX *lex=Lex;
	    if (check_simple_select())
	      YYABORT;	
	    lex->lock_option= TL_WRITE;
	    lex->thd->safe_to_cache_query=0;
	  }
1582
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1583 1584 1585 1586 1587 1588 1589 1590
	  {
	    LEX *lex=Lex;
	    if (check_simple_select())
	      YYABORT;	
	    lex->lock_option= TL_READ_WITH_SHARED_LOCKS;
	    lex->thd->safe_to_cache_query=0;
	  }
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1591

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1592 1593 1594 1595 1596 1597 1598
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
	    if (add_item_to_list(new Item_field(NULL,NULL,"*")))
	      YYABORT;
1599
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
	    if (add_item_to_list($2))
	      YYABORT;
	    if ($4.str)
	      $2->set_name($4.str);
	    else if (!$2->name)
	      $2->set_name($1,(uint) ($3 - $1));
1611
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1612 1613

remember_name:
1614
	{ $$=(char*) Lex->tok_start; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1615 1616

remember_end:
1617
	{ $$=(char*) Lex->tok_end; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1618 1619 1620

select_item2:
	table_wild	{ $$=$1; } /* table.* */
1621
	| expr		{ $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1622 1623 1624 1625 1626 1627

select_alias:
	{ $$.str=0;}
	| AS ident { $$=$2; }
	| AS TEXT_STRING  { $$=$2; }
	| ident { $$=$1; }
1628
	| TEXT_STRING  { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1629 1630 1631

optional_braces:
	/* empty */ {}
1632
	| '(' ')' {};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1633

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1634 1635
/* all possible expressions */
expr:	expr_expr	{$$ = $1; }
1636
	| simple_expr	{$$ = $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649

/* expressions that begin with 'expr' */
expr_expr:
	expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
	| expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
	| 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)); }
	| expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
1650
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
	| 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 EQ expr		{ $$= new Item_func_eq($1,$3); }
	| expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
	| expr GE expr		{ $$= new Item_func_ge($1,$3); }
	| expr GT_SYM expr	{ $$= new Item_func_gt($1,$3); }
	| expr LE expr		{ $$= new Item_func_le($1,$3); }
	| expr LT expr		{ $$= new Item_func_lt($1,$3); }
	| expr NE expr		{ $$= new Item_func_ne($1,$3); }
	| 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); }
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
1672
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }	
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1673 1674 1675 1676 1677
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
	| expr '+' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,0); }
	| expr '-' INTERVAL_SYM expr interval
1678
	  { $$= new Item_date_add_interval($1,$4,$5,1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1679 1680 1681 1682 1683 1684 1685 1686 1687

/* 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)); }
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat($1,$3); }
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
1688
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
	| 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 EQ expr		{ $$= new Item_func_eq($1,$3); }
	| no_in_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
	| no_in_expr GE expr		{ $$= new Item_func_ge($1,$3); }
	| no_in_expr GT_SYM expr	{ $$= new Item_func_gt($1,$3); }
	| no_in_expr LE expr		{ $$= new Item_func_le($1,$3); }
	| no_in_expr LT expr		{ $$= new Item_func_lt($1,$3); }
	| no_in_expr NE expr		{ $$= new Item_func_ne($1,$3); }
	| 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); }
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
1710
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1711 1712 1713 1714 1715 1716
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
	| no_in_expr '+' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,0); }
	| no_in_expr '-' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,1); }
1717
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
	no_and_expr IN_SYM '(' expr_list ')'
	{ $$= new Item_func_in($1,*$4); }
	| no_and_expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
	| 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)); }
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat($1,$3); }
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
1731
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
	| 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 EQ expr		{ $$= new Item_func_eq($1,$3); }
	| no_and_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
	| no_and_expr GE expr		{ $$= new Item_func_ge($1,$3); }
	| no_and_expr GT_SYM expr	{ $$= new Item_func_gt($1,$3); }
	| no_and_expr LE expr		{ $$= new Item_func_le($1,$3); }
	| no_and_expr LT expr		{ $$= new Item_func_lt($1,$3); }
	| no_and_expr NE expr		{ $$= new Item_func_ne($1,$3); }
	| 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); }
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
1752
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1753 1754 1755 1756 1757 1758
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
	| no_and_expr '+' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,0); }
	| no_and_expr '-' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,1); }
1759
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1760 1761 1762 1763

simple_expr:
	simple_ident
	| literal
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1764
	| '@' ident_or_text SET_VAR expr
1765 1766
	  {
	    $$= new Item_func_set_user_var($2,$4);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1767 1768 1769
	    current_thd->safe_to_cache_query=0;
	  }
	| '@' ident_or_text	 
1770 1771
	  {
	    $$= new Item_func_get_user_var($2);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1772 1773
	    current_thd->safe_to_cache_query=0;
	  }
1774 1775 1776 1777
	| '@' '@' opt_var_ident_type ident_or_text
	  {
	    if (!($$= get_system_var((enum_var_type) $3, $4)))
	      YYABORT;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1778
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1779 1780 1781 1782 1783 1784 1785
	| 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; }
	| '{' ident expr '}'	{ $$= $3; }
1786 1787
        | MATCH ident_list_arg AGAINST '(' expr ')'
          { Select->ftfunc_list.push_back((Item_func_match *)
1788
                   ($$=new Item_func_match_nl(*$2,$5))); }
1789 1790
        | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
          { Select->ftfunc_list.push_back((Item_func_match *)
1791
                   ($$=new Item_func_match_bool(*$2,$5))); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1792 1793
	| BINARY expr %prec NEG	{ $$= new Item_func_binary($2); }
	| CAST_SYM '(' expr AS cast_type ')'  { $$= create_func_cast($3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1794
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
1795
	  { $$= new Item_func_case(* $4, $2, $5 ); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1796
	| CONVERT_SYM '(' expr ',' cast_type ')'  { $$= create_func_cast($3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817
	| 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); }
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1818
	  { $$= new Item_func_curdate(); current_thd->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1819
	| CURTIME optional_braces
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1820
	  { $$= new Item_func_curtime(); current_thd->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1821
	| CURTIME '(' expr ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1822 1823 1824 1825
	  { 
	    $$= new Item_func_curtime($3); 
	    current_thd->safe_to_cache_query=0;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1826 1827 1828 1829 1830
	| DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3,$6,$7,0); }
	| DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3,$6,$7,1); }
	| DATABASE '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1831 1832 1833 1834
	  { 
	    $$= new Item_func_database();
            current_thd->safe_to_cache_query=0; 
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1835 1836 1837 1838
	| ELT_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_elt($3, *$5); }
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1839 1840 1841 1842 1843
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
	    current_thd->safe_to_cache_query=0; 
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1844 1845 1846 1847 1848
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
	| DECODE_SYM '(' expr ',' TEXT_STRING ')'
	  { $$= new Item_func_decode($3,$5.str); }
	| ENCODE_SYM '(' expr ',' TEXT_STRING ')'
	 { $$= new Item_func_encode($3,$5.str); }
1849
	| DES_DECRYPT_SYM '(' expr ')'
1850
        { $$= new Item_func_des_decrypt($3); }
1851
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
1852
        { $$= new Item_func_des_decrypt($3,$5); }
1853
	| DES_ENCRYPT_SYM '(' expr ')'
1854
        { $$= new Item_func_des_encrypt($3); }
1855
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
1856
        { $$= new Item_func_des_encrypt($3,$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868
	| 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); }
	| 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 ')'
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1869
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_field($3, *$5); }
	| 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); }
	| INTERVAL_SYM expr interval '+' expr
	  /* we cannot put interval before - */
	  { $$= new Item_date_add_interval($5,$2,$3,0); }
	| INTERVAL_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_interval($3,* $5); }
	| LAST_INSERT_ID '(' ')'
	  {
	    $$= new Item_int((char*) "last_insert_id()",
			     current_thd->insert_id(),21);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1888
	    current_thd->safe_to_cache_query=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1889 1890 1891 1892
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1893
	    current_thd->safe_to_cache_query=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
	| LOCATE '(' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3); }
	| LOCATE '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3,$7); }
 	| GREATEST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
1905 1906 1907 1908
	| LOG_SYM '(' expr ')'
		{ $$= new Item_func_log($3); }
	| LOG_SYM '(' expr ',' expr ')'
		{ $$= new Item_func_log($3, $5); }
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918
	| MASTER_POS_WAIT '(' expr ',' expr ')'
	  { 
	    $$= new Item_master_pos_wait($3, $5);
	    current_thd->safe_to_cache_query=0; 
	  }
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
	  { 
	    $$= new Item_master_pos_wait($3, $5, $7);
	    current_thd->safe_to_cache_query=0; 
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1919 1920 1921 1922 1923
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
	| NOW_SYM optional_braces
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1924
	  { $$= new Item_func_now(); current_thd->safe_to_cache_query=0;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1925
	| NOW_SYM '(' expr ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1926 1927 1928 1929 1930
	  { $$= new Item_func_now($3); current_thd->safe_to_cache_query=0;}
	| PASSWORD '(' expr ')'
	  {
	    $$= new Item_func_password($3);
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1931 1932
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1933 1934 1935 1936
	| RAND '(' expr ')'
	  { $$= new Item_func_rand($3); current_thd->safe_to_cache_query=0;}
	| RAND '(' ')'
	  { $$= new Item_func_rand(); current_thd->safe_to_cache_query=0;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
	| 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 ')'
	  { $$= new Item_func_trim($3,new Item_string(" ",1)); }
	| 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); }
1966 1967
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
	| 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 ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2011 2012 2013
	  { 
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2014
	| UNIX_TIMESTAMP '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2015 2016 2017 2018
	  {
	    $$= new Item_func_unix_timestamp();
	    current_thd->safe_to_cache_query=0;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2019 2020 2021
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2022
	  { $$= new Item_func_user(); current_thd->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2023
	| WEEK_SYM '(' expr ')'
gluh@gluh.mysql.r18.ru's avatar
SCRUM  
gluh@gluh.mysql.r18.ru committed
2024 2025 2026
	  { 
	    LEX *lex=Lex;
	    $$= new Item_func_week($3,new Item_int((char*) "0", 
2027
                                   lex->thd->variables.default_week_format,1));
gluh@gluh.mysql.r18.ru's avatar
SCRUM  
gluh@gluh.mysql.r18.ru committed
2028
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2029 2030 2031 2032 2033 2034 2035 2036 2037
	| 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 ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2038 2039 2040 2041
	  { 
	    $$=new Item_func_benchmark($3,$5);
	    current_thd->safe_to_cache_query=0;
	  }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2042
	| EXTRACT_SYM '(' interval FROM expr ')'
2043
	{ $$=new Item_extract( $3, $5); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2044 2045 2046

udf_expr_list:
	/* empty */	{ $$= NULL; }
2047
	| expr_list	{ $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2048 2049 2050 2051 2052 2053 2054 2055

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); }
2056
	| COUNT_SYM '(' opt_all '*' ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2057 2058 2059
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
2060 2061 2062 2063 2064 2065
	| COUNT_SYM '(' DISTINCT
	  { Select->in_sum_expr++; }
	   expr_list
	  { Select->in_sum_expr--; }
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2066 2067 2068 2069 2070 2071 2072 2073 2074
	| 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); }
	| SUM_SYM '(' in_sum_expr ')'
2075
	  { $$=new Item_sum_sum($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2076 2077

in_sum_expr:
2078
	opt_all
2079
	{ Select->in_sum_expr++; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2080 2081
	expr
	{
2082
	  Select->in_sum_expr--;
2083
	  $$=$3;
2084
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2085

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2086 2087
cast_type:
	BINARY 			{ $$=ITEM_CAST_BINARY; }
2088
	| CHAR_SYM		{ $$=ITEM_CAST_CHAR; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2089 2090 2091 2092 2093 2094
	| 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; }
2095 2096
	| DATETIME		{ $$=ITEM_CAST_DATETIME; }
	;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2097

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2098
expr_list:
2099
	{ Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2100
	expr_list2
2101
	{ $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2102 2103

expr_list2:
2104
	expr { Select->expr_list.head()->push_back($1); }
2105
	| expr_list2 ',' expr { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2106

2107 2108
ident_list_arg:
          ident_list          { $$= $1; }
2109
        | '(' ident_list ')'  { $$= $2; };
2110

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2111
ident_list:
2112
        { Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2113
        ident_list2
2114
        { $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2115 2116

ident_list2:
2117
        simple_ident { Select->expr_list.head()->push_back($1); }
2118
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2119 2120 2121

opt_expr:
	/* empty */      { $$= NULL; }
2122
	| expr         	 { $$= $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2123 2124 2125

opt_else:
	/* empty */    { $$= NULL; }
2126
	| ELSE expr    { $$= $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2127 2128

when_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2129
        { Select->when_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2130
	when_list2
2131
	{ $$= Select->when_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2132 2133

when_list2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2134
	expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2135
	  {
2136 2137 2138
	    SELECT_LEX *sel=Select;	    
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2139
	}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2140
	| when_list2 WHEN_SYM expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2141
	  {
2142 2143 2144
	    SELECT_LEX *sel=Select;
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
2145
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2146 2147 2148

opt_pad:
	/* empty */ { $$=new Item_string(" ",1); }
2149
	| expr	    { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2150 2151 2152 2153

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
2154
	| join_table_list ',' join_table_list { $$=$3; }
2155
	| join_table_list normal_join join_table_list { $$=$3; }
2156
	| join_table_list STRAIGHT_JOIN join_table_list
2157
	  { $$=$3 ; $1->next->straight=1; }
2158 2159 2160 2161
	| 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 
2162 2163
	  {
	    SELECT_LEX *sel=Select;
2164
	    sel->db1=$1->db; sel->table1=$1->alias;
2165
	    sel->db2=$3->db; sel->table2=$3->alias;
2166
	  }
2167 2168 2169
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

2170
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2171
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2172
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
2173 2174
	  {
	    SELECT_LEX *sel=Select;
2175 2176
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2177
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2178
	  USING '(' using_list ')'
2179
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2180
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2181 2182 2183 2184 2185
	  {
	    add_join_natural($1,$1->next);
	    $1->next->outer_join|=JOIN_TYPE_LEFT;
	    $$=$6;
	  }
2186
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2187
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
2188
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
2189 2190
	  {
	    SELECT_LEX *sel=Select;
2191 2192
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2193
	  }
2194
	  USING '(' using_list ')'
2195
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
2196
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2197 2198 2199 2200 2201
	  {
	    add_join_natural($1->next,$1);
	    $1->outer_join|=JOIN_TYPE_RIGHT;
	    $$=$6;
	  }
2202
	| join_table_list NATURAL JOIN_SYM join_table_list
2203
	  { add_join_natural($1,$1->next); $$=$4; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2204 2205

normal_join:
2206 2207 2208 2209
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2210 2211

join_table:
2212 2213 2214
	{
	  SELECT_LEX *sel=Select;
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
2215
	  sel->table_join_options= 0;
2216
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2217
        table_ident opt_table_alias opt_key_definition
2218 2219
	{
	  SELECT_LEX *sel=Select;
2220 2221
	  if (!($$=add_table_to_list($2, $3, sel->table_join_options,
				     TL_UNLOCK, sel->use_index_ptr,
2222 2223
	                             sel->ignore_index_ptr)))
	    YYABORT;
2224
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2225
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2226
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2227 2228 2229

opt_outer:
	/* empty */	{}
2230
	| OUTER		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2231 2232 2233 2234

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
2235 2236 2237 2238 2239
          {
	    SELECT_LEX *sel=Select;
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
2240 2241 2242 2243 2244 2245 2246
	| FORCE_SYM key_usage_list
          {
	    SELECT_LEX *sel=Select;
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2247
	| IGNORE_SYM key_usage_list
2248 2249 2250 2251
	  {
	    SELECT_LEX *sel=Select;
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
2252 2253
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2254 2255

key_usage_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2256
	key_or_index { Select->interval_list.empty(); } '(' key_usage_list2 ')'
2257
        { $$= &Select->interval_list; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2258 2259 2260

key_usage_list2:
	key_usage_list2 ',' ident
2261
        { Select->interval_list.push_back(new String((const char*) $3.str,$3.length)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2262
	| ident
2263
        { Select->interval_list.push_back(new String((const char*) $1.str,$1.length)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2264
	| PRIMARY_SYM
2265
        { Select->interval_list.push_back(new String("PRIMARY",7)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2266 2267 2268

using_list:
	ident
2269 2270 2271
	  {
	    SELECT_LEX *sel=Select;
	    if (!($$= new Item_func_eq(new Item_field(sel->db1,sel->table1, $1.str), new Item_field(sel->db2,sel->table2,$1.str))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2272 2273 2274 2275
	      YYABORT;
	  }
	| using_list ',' ident
	  {
2276 2277
	    SELECT_LEX *sel=Select;
	    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)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2278
	      YYABORT;
2279
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293

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; }
2294
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2295 2296 2297 2298

table_alias:
	/* empty */
	| AS
2299
	| EQ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2300 2301 2302 2303

opt_table_alias:
	/* empty */		{ $$=0; }
	| table_alias ident
2304
	  { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2305

2306 2307 2308 2309
opt_all:
	/* empty */
	| ALL
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2310 2311

where_clause:
2312
	/* empty */  { Select->where= 0; }
2313 2314 2315 2316 2317 2318 2319
	| WHERE expr
	  {
	    Select->where= $2;
	    if ($2)
	      $2->top_level_item();
	  }
	  ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2320 2321 2322

having_clause:
	/* empty */
2323
	| HAVING { Select->create_refs=1; } expr
2324 2325
	{
	  SELECT_LEX *sel=Select;
2326 2327 2328 2329 2330 2331
	  sel->having= $3;
	  sel->create_refs=0;
	  if ($3)
	    $3->top_level_item();
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2332 2333 2334

opt_escape:
	ESCAPE_SYM TEXT_STRING	{ $$= $2.str; }
2335
	| /* empty */		{ $$= (char*) "\\"; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2336 2337 2338


/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2339
   group by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2340 2341 2342 2343
*/

group_clause:
	/* empty */
2344
	| GROUP BY group_list olap_opt;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2345 2346

group_list:
2347 2348 2349
	group_list ',' order_ident order_dir
	  { if (add_group_to_list($3,(bool) $4)) YYABORT; }
	| order_ident order_dir
2350
	  { if (add_group_to_list($1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2351

2352 2353
olap_opt:
	/* empty */ {}
2354
	| WITH CUBE_SYM
2355
          {
2356 2357 2358
	    LEX *lex=Lex;
	    net_printf(&lex->thd->net, ER_NOT_SUPPORTED_YET, "CUBE");
	    YYABORT;	/* To be deleted in 4.1 */
2359
	  }
2360
	| WITH ROLLUP_SYM
2361
          {
2362 2363 2364
	    LEX *lex=Lex;
	    net_printf(&lex->thd->net, ER_NOT_SUPPORTED_YET, "ROLLUP");
	    YYABORT;	/* To be deleted in 4.1 */
2365
	  }
2366
	;
2367

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2368
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2369
   Order by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2370 2371
*/

2372
opt_order_clause:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2373
	/* empty */
2374
	| order_clause;
2375 2376

order_clause:
2377 2378
	ORDER_SYM BY 
        { 
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2379
	  LEX *lex=Lex;
2380 2381 2382 2383 2384 2385 2386
	  if (lex->select->olap != UNSPECIFIED_OLAP_TYPE)
	  {
	    net_printf(&lex->thd->net, ER_WRONG_USAGE,
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2387
	  lex->select->sort_default=1;
2388
	} order_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2389 2390 2391 2392 2393

order_list:
	order_list ',' order_ident order_dir
	  { if (add_order_to_list($3,(bool) $4)) YYABORT; }
	| order_ident order_dir
2394
	  { if (add_order_to_list($1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2395 2396 2397

order_dir:
	/* empty */ { $$ =  1; }
2398
	| ASC  { $$ =1; }
2399
	| DESC { $$ =0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2400 2401 2402


limit_clause:
2403
	/* empty */ {}
2404
	| LIMIT 
2405
	  {
2406
	    LEX *lex=Lex;
2407 2408 2409 2410
	    if (lex->select->olap != UNSPECIFIED_OLAP_TYPE)
	    {
	      net_printf(&lex->thd->net, ER_WRONG_USAGE, "CUBE/ROLLUP",
		        "LIMIT");
2411
	      YYABORT;
2412
	    }
2413
	  }
2414
	  limit_options
2415
	  {}
2416 2417 2418 2419
	  ;

limit_options:
	ULONG_NUM
2420
	  {
2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437
            SELECT_LEX *sel= Select;
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
	    SELECT_LEX *sel= Select;
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
	  }
	| ULONG_NUM OFFSET_SYM ULONG_NUM
	  {
	    SELECT_LEX *sel= Select;
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2438 2439 2440 2441

delete_limit_clause:
	/* empty */
	{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2442 2443
	  LEX *lex=Lex;
	  lex->select->select_limit= HA_POS_ERROR;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2444
	}
2445
	| LIMIT ulonglong_num
2446
	{ Select->select_limit= (ha_rows) $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2447 2448

ULONG_NUM:
2449
	NUM	    { $$= strtoul($1.str,NULL,10); }
2450
	| LONG_NUM  { $$= (ulong) strtoll($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2451
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
2452
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
2453
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2454

2455
ulonglong_num:
2456
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2457
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
2458
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
2459
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
2460
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2461 2462 2463 2464 2465 2466 2467 2468 2469

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
2470
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2471
	      YYABORT;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2472
	    current_thd->safe_to_cache_query=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2473
	  }
2474
	  '(' procedure_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2475 2476 2477 2478


procedure_list:
	/* empty */ {}
2479
	| procedure_list2 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2480 2481 2482

procedure_list2:
	procedure_list2 ',' procedure_item
2483
	| procedure_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2484 2485 2486 2487

procedure_item:
	  remember_name expr
	  {
2488 2489
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2490 2491
	      YYABORT;
	    if (!$2->name)
2492
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1));
2493
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2494 2495 2496 2497

opt_into:
	INTO OUTFILE TEXT_STRING
	{
2498 2499 2500
	  THD *thd= current_thd;
	  thd->safe_to_cache_query= 0; 
	  if (!(thd->lex.exchange= new sql_exchange($3.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2501 2502 2503 2504 2505
	    YYABORT;
	}
	opt_field_term opt_line_term
	| INTO DUMPFILE TEXT_STRING
	{
2506 2507 2508
	  THD *thd= current_thd;
	  thd->safe_to_cache_query= 0;
	  if (!(thd->lex.exchange= new sql_exchange($3.str,1)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2509
	    YYABORT;
2510
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2511

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2512 2513 2514
/*
  DO statement
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2515

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2516 2517 2518 2519 2520 2521 2522
do:	DO_SYM 
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
2523 2524 2525 2526
	values
	{}
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2527
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2528
  Drop : delete tables or index
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2529 2530 2531
*/

drop:
2532
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2533
	{
2534 2535
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
2536 2537
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2538 2539 2540
	}
	| DROP INDEX ident ON table_ident {}
	  {
2541 2542 2543 2544
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
	     lex->drop_list.empty();
	     lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2545
						     $3.str));
2546
	     if (!add_table_to_list($5, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2547 2548 2549 2550
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
2551 2552 2553 2554
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2555 2556 2557
	 }
	| DROP UDF_SYM ident
	  {
2558 2559 2560
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
	    lex->udf.name=$3.str;
2561
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2562 2563 2564


table_list:
2565
	table_name
2566
	| table_list ',' table_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2567

2568
table_name:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2569
	table_ident
2570
	{ if (!add_table_to_list($1,NULL,TL_OPTION_UPDATING)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2571 2572

if_exists:
2573
	/* empty */ { $$= 0; }
2574 2575
	| IF EXISTS { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2576

2577 2578 2579 2580
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2581 2582 2583 2584 2585
/*
** Insert : add new data to table
*/

insert:
2586
	INSERT { Lex->sql_command = SQLCOM_INSERT; } insert_lock_option
serg@serg.mylan's avatar
serg@serg.mylan committed
2587
	opt_ignore insert2
2588 2589
	{
	  set_lock_for_tables($3);
2590
	  Lex->select= &Lex->select_lex;
2591 2592
	}
	insert_field_spec
2593
	{}
2594
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2595 2596

replace:
2597 2598
	REPLACE
	{
serg@serg.mylan's avatar
serg@serg.mylan committed
2599
	  LEX *lex=Lex;
2600 2601 2602
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
2603 2604 2605
	replace_lock_option insert2
	{
	  set_lock_for_tables($3);
2606
          Lex->select= &Lex->select_lex;
2607 2608
	}
	insert_field_spec
2609
	{}
2610
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2611 2612

insert_lock_option:
2613 2614 2615 2616
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
serg@serg.mylan's avatar
serg@serg.mylan committed
2617
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2618 2619

replace_lock_option:
2620 2621
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2622 2623 2624

insert2:
	INTO insert_table {}
2625
	| insert_table {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2626 2627

insert_table:
2628
	table_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2629
	{
2630 2631 2632 2633
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
2634
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2635 2636

insert_field_spec:
serg@serg.mylan's avatar
serg@serg.mylan committed
2637 2638 2639
	insert_values {}
	| '(' ')' insert_values {}
	| '(' fields ')' insert_values {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2640 2641
	| SET
	  {
2642 2643 2644
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2645 2646
	      YYABORT;
	   }
2647
	   ident_eq_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2648 2649 2650 2651

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
2652
	| '(' ')'	  { };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2653 2654 2655

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
2656
	| insert_ident		{ Lex->field_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2657 2658 2659

insert_values:
	VALUES	values_list  {}
serg@serg.mylan's avatar
serg@serg.mylan committed
2660 2661
	|     create_select     { Select->braces= 0;} opt_union {}
	| '(' create_select ')' { Select->braces= 1;} union_opt {}
2662 2663
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2664 2665
values_list:
	values_list ','  no_braces
2666
	| no_braces;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2667 2668 2669 2670

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
2671
	ident_eq_value;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2672 2673

ident_eq_value:
2674
	simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2675
	 {
2676 2677 2678
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2679
	    YYABORT;
2680
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2681 2682

equal:	EQ		{}
2683 2684 2685 2686 2687 2688 2689
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2690 2691 2692 2693 2694 2695 2696 2697 2698

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
2699 2700
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2701
	    YYABORT;
2702
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2703 2704 2705

opt_values:
	/* empty */ {}
2706
	| values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2707 2708

values:
2709
	values ','  expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2710 2711 2712 2713
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
	expr 	  { $$= $1;}
	| DEFAULT {$$= new Item_default(); }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2725 2726 2727 2728

/* Update rows in a table */

update:
2729
        UPDATE_SYM 
2730
	{ 
2731 2732 2733 2734 2735
	  LEX *lex=Lex;
          lex->sql_command = SQLCOM_UPDATE;
          lex->select->order_list.elements=0;
          lex->select->order_list.first=0;
          lex->select->order_list.next= (byte**) &lex->select->order_list.first;
2736
        }
2737 2738 2739 2740 2741 2742
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
	  set_lock_for_tables($3);
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753

update_list:
	update_list ',' simple_ident equal expr
	{
	  if (add_item_to_list($3) || add_value_to_list($5))
	    YYABORT;
	}
	| simple_ident equal expr
	  {
	    if (add_item_to_list($1) || add_value_to_list($3))
	      YYABORT;
2754
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2755 2756

opt_low_priority:
2757 2758
	/* empty */	{ $$= current_thd->update_lock_default; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2759 2760 2761 2762

/* Delete rows from a table */

delete:
2763
	DELETE_SYM
2764
	{ 
2765 2766 2767 2768 2769 2770 2771
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_DELETE; lex->select->options=0;
	  lex->lock_option= lex->thd->update_lock_default;
	  lex->select->order_list.elements=0;
	  lex->select->order_list.first=0;
	  lex->select->order_list.next= (byte**) &lex->select->order_list.first;
	}
2772 2773
	opt_delete_options single_multi {}
	;
2774 2775

single_multi:
2776 2777
 	FROM table_ident
	{
2778 2779
	  if (!add_table_to_list($2, NULL, TL_OPTION_UPDATING,
				 Lex->lock_option))
2780 2781 2782
	    YYABORT;
	}
	where_clause opt_order_clause
2783
	delete_limit_clause {}
2784
	| table_wild_list
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2785
	  { mysql_init_multi_delete(Lex); }
2786
          FROM join_table_list where_clause
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2787 2788
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
2789 2790 2791
	  USING join_table_list where_clause
	  {}
	;
2792 2793 2794

table_wild_list:
	  table_wild_one {}
2795
	  | table_wild_list ',' table_wild_one {};
2796 2797 2798 2799

table_wild_one:
	 ident opt_wild
	 {
2800 2801
	   if (!add_table_to_list(new Table_ident($1), NULL,
				  TL_OPTION_UPDATING, Lex->lock_option))
2802
	     YYABORT;
2803 2804 2805
         }
	 | ident '.' ident opt_wild
	   {
2806 2807
	     if (!add_table_to_list(new Table_ident($1,$3,0), NULL,
				    TL_OPTION_UPDATING,
2808
				    Lex->lock_option))
2809
	      YYABORT;
2810 2811
	   }
	;
2812 2813 2814

opt_wild:
	/* empty */	{} 
2815
	| '.' '*'	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2816 2817


2818
opt_delete_options:
2819
	/* empty */	{}
2820
	| opt_delete_option opt_delete_options {};
2821 2822

opt_delete_option:
2823
	QUICK		{ Select->options|= OPTION_QUICK; }
2824
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
2825

2826
truncate:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
2827
	TRUNCATE_SYM opt_table_sym table_name
2828 2829 2830
	{
	  LEX* lex = Lex;
	  lex->sql_command= SQLCOM_TRUNCATE;
2831 2832 2833 2834
	  lex->select->options=0;
	  lex->select->order_list.elements=0;
          lex->select->order_list.first=0;
          lex->select->order_list.next= (byte**) &lex->select->order_list.first;
2835 2836
	}
	;
2837

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2838 2839
opt_table_sym:
	/* empty */
2840
	| TABLE_SYM;
2841
 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2842 2843
/* Show things */

2844 2845 2846
show:	SHOW { Lex->wild=0;} show_param
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2847 2848 2849 2850 2851

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
2852 2853 2854 2855 2856
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_TABLES;
	    lex->select->db= $2; lex->select->options=0;
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2857
	| TABLE_SYM STATUS_SYM opt_db wild
2858 2859 2860 2861 2862
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_TABLES;
	    lex->select->options|= SELECT_DESCRIBE;
	    lex->select->db= $3;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2863
	  }
2864
	| OPEN_SYM TABLES opt_db wild
2865 2866 2867 2868 2869
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
	    lex->select->db= $3;
	    lex->select->options=0;
2870
	  }
2871
	| opt_full COLUMNS from_or_in table_ident opt_db wild
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2872 2873
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2874 2875
	    if ($5)
	      $4->change_db($5);
2876
	    if (!add_table_to_list($4, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2877 2878
	      YYABORT;
	  }
2879
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ 
2880 2881
	  TEXT_STRING AND MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND MASTER_SERVER_ID_SYM EQ
2882 2883 2884 2885 2886
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
2887
	    Lex->mi.server_id = $16;
2888
          }
2889 2890 2891
        | MASTER_SYM LOGS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
2892 2893 2894 2895 2896
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
2897
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
2898
          {
2899 2900
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_SHOW_BINLOG_EVENTS;
2901
	    lex->select->select_limit= lex->thd->variables.select_limit;
2902 2903
	    lex->select->offset_limit= 0L;
          } limit_clause
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2904 2905 2906 2907 2908
	| keys_or_index FROM table_ident opt_db
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
2909
	    if (!add_table_to_list($3, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2910 2911 2912 2913
	      YYABORT;
	  }
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
2914 2915
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2916 2917
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
2918 2919 2920 2921
	| opt_var_type VARIABLES wild
	{
	    THD *thd= current_thd;
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
2922
	    thd->lex.option_type= (enum_var_type) $1;
2923
	  }
tim@cane.mysql.fi's avatar
tim@cane.mysql.fi committed
2924 2925
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2926
	| GRANTS FOR_SYM user
2927 2928 2929 2930 2931 2932
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2933 2934 2935
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
2936
	    if(!add_table_to_list($3, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2937 2938 2939 2940 2941
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2942
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2943 2944 2945
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
2946
          };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2947 2948 2949

opt_db:
	/* empty */  { $$= 0; }
2950
	| from_or_in ident { $$= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2951 2952 2953

wild:
	/* empty */
2954
	| LIKE text_string { Lex->wild= $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2955

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2956 2957
opt_full:
	/* empty */ { Lex->verbose=0; }
2958
	| FULL	    { Lex->verbose=1; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2959

2960 2961
from_or_in:
	FROM
2962
	| IN_SYM;
2963

2964 2965
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
2966
        | IN_SYM TEXT_STRING { Lex->mi.log_file_name = $2.str; };
2967 2968 2969

binlog_from:
	/* empty */ { Lex->mi.pos = 4; /* skip magic number */ }
2970
        | FROM ulonglong_num { Lex->mi.pos = $2; };
2971 2972


bk@work.mysql.com's avatar
bk@work.mysql.com committed
2973 2974 2975 2976
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
2977 2978 2979 2980
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
2981
	  if (!add_table_to_list($2, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2982 2983
	    YYABORT;
	}
2984
	opt_describe_column {}
2985
	| describe_command select
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2986
          { Lex->select_lex.options|= SELECT_DESCRIBE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2987 2988 2989 2990


describe_command:
	DESC
2991
	| DESCRIBE;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2992 2993 2994 2995

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
2996 2997
	| ident
 { Lex->wild= new String((const char*) $1.str,$1.length); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2998 2999 3000 3001 3002


/* flush things */

flush:
3003 3004 3005 3006 3007
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
3008 3009 3010
	flush_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3011 3012 3013

flush_options:
	flush_options ',' flush_option
3014
	| flush_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3015 3016

flush_option:
3017
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3018
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3019
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3020 3021 3022 3023
	| HOSTS_SYM	{ Lex->type|= REFRESH_HOSTS; }
	| PRIVILEGES	{ Lex->type|= REFRESH_GRANT; }
	| LOGS_SYM	{ Lex->type|= REFRESH_LOG; }
	| STATUS_SYM	{ Lex->type|= REFRESH_STATUS; }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3024 3025
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3026 3027
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3028

3029
opt_table_list:
3030 3031
	/* empty */  {;}
	| table_list {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3032

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3033
reset:
3034 3035 3036 3037
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
3038 3039 3040 3041
	} reset_options
	{}
	;

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3042 3043
reset_options:
	reset_options ',' reset_option
3044
	| reset_option;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3045 3046

reset_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3047 3048
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
3049
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3050

3051
purge:
3052 3053 3054 3055 3056 3057
	PURGE
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_PURGE;
	  lex->type=0;
	}
3058 3059 3060
        MASTER_SYM LOGS_SYM TO_SYM TEXT_STRING
         {
	   Lex->to_log = $6.str;
3061
         } ;
3062

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3063 3064 3065
/* kill threads */

kill:
3066
	KILL_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3067
	{
3068 3069 3070 3071 3072 3073 3074 3075
	  LEX *lex=Lex;
	  if ($2->fix_fields(lex->thd,0))
	  { 
	    send_error(&lex->thd->net, ER_SET_CONSTANTS_ONLY);
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
3076
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3077 3078 3079 3080

/* change database */

use:	USE_SYM ident
3081 3082 3083
	{
	  LEX *lex=Lex;
	  lex->sql_command=SQLCOM_CHANGE_DB; lex->select->db= $2.str;
3084
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3085 3086 3087

/* import, export of files */

3088
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3089
	{
3090 3091
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
3092 3093
	  lex->lock_option= $3;
	  lex->local_file=  $4;
3094
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3095
	    YYABORT;
3096
	  lex->field_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3097 3098 3099 3100
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
3101
	  if (!add_table_to_list($11, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3102 3103 3104
	    YYABORT;
	}
        |
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3105
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3106 3107
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
3108
	  if (!add_table_to_list($3, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3109
	    YYABORT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3110 3111

        }
3112 3113 3114 3115
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
3116
        };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3117 3118 3119

opt_local:
	/* empty */	{ $$=0;}
3120
	| LOCAL_SYM	{ $$=1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3121

3122
load_data_lock:
3123 3124 3125
	/* empty */	{ $$= current_thd->update_lock_default; }
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
3126 3127


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3128 3129 3130
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
3131
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3132 3133 3134

opt_field_term:
	/* empty */
3135
	| COLUMNS field_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3136 3137 3138

field_term_list:
	field_term_list field_term
3139
	| field_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3140 3141 3142 3143

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
3144 3145 3146 3147 3148
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3149
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
3150
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3151 3152 3153

opt_line_term:
	/* empty */
3154
	| LINES line_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3155 3156 3157

line_term_list:
	line_term_list line_term
3158
	| line_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3159 3160 3161

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
3162
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3163 3164 3165 3166

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
3167
	  { Lex->exchange->skip_lines=atol($2.str); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3168 3169 3170 3171 3172 3173

/* Common definitions */

text_literal:
	TEXT_STRING { $$ = new Item_string($1.str,$1.length); }
	| text_literal TEXT_STRING
3174
	{ ((Item_string*) $1)->append($2.str,$2.length); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3175 3176 3177 3178 3179 3180 3181

text_string:
	TEXT_STRING	{ $$=  new String($1.str,$1.length); }
	| HEX_NUM
	  {
	    Item *tmp = new Item_varbinary($1.str,$1.length);
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
3182
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3183 3184 3185

literal:
	text_literal	{ $$ =	$1; }
3186 3187
	| 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); }
3188
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3189 3190 3191 3192
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
			  Lex->next_state=STATE_OPERATOR_OR_IDENT;}
3193
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3194 3195
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
3196
	| TIMESTAMP text_literal { $$ = $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3197 3198 3199 3200 3201 3202 3203

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

insert_ident:
	simple_ident	 { $$=$1; }
3204
	| table_wild	 { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3205 3206 3207 3208

table_wild:
	ident '.' '*' { $$ = new Item_field(NullS,$1.str,"*"); }
	| ident '.' ident '.' '*'
3209 3210
	{ $$ = new Item_field((current_thd->client_capabilities &
   CLIENT_NO_SCHEMA ? NullS : $1.str),$3.str,"*"); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3211 3212

order_ident:
3213
	expr { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3214 3215 3216

simple_ident:
	ident
3217 3218 3219 3220
	{
	  SELECT_LEX *sel=Select;
	  $$ = !sel->create_refs || sel->in_sum_expr > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str);
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3221
	| ident '.' ident
3222 3223 3224 3225
	{
	  SELECT_LEX *sel=Select;
	  $$ = !sel->create_refs || sel->in_sum_expr > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str);
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3226
	| '.' ident '.' ident
3227 3228 3229 3230
	{
	  SELECT_LEX *sel=Select;
	  $$ = !sel->create_refs || sel->in_sum_expr > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str);
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3231
	| ident '.' ident '.' ident
3232 3233 3234
	{
	  SELECT_LEX *sel=Select;
	  $$ = !sel->create_refs || sel->in_sum_expr > 0 ? (Item*) new Item_field((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str);
3235
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3236 3237 3238 3239 3240


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
3241
	| '.' ident		{ $$=$2;}	/* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3242 3243 3244 3245

table_ident:
	ident			{ $$=new Table_ident($1); }
	| ident '.' ident	{ $$=new Table_ident($1,$3,0);}
3246 3247
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3248 3249 3250 3251 3252

ident:
	IDENT	    { $$=$1; }
	| keyword
	{
3253 3254
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3255
	  $$.length=$1.length;
3256
	  if (lex->next_state != STATE_END)
3257
	    lex->next_state=STATE_OPERATOR_OR_IDENT;
3258 3259
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3260 3261 3262

ident_or_text:
	ident 		{ $$=$1;}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3263
	| TEXT_STRING	{ $$=$1;}
3264
	| LEX_HOSTNAME	{ $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277

user:
	ident_or_text
	{
	  if (!($$=(LEX_USER*) sql_alloc(sizeof(st_lex_user))))
	    YYABORT;
	  $$->user = $1; $$->host.str=NullS;
	  }
	| ident_or_text '@' ident_or_text
	  {
	  if (!($$=(LEX_USER*) sql_alloc(sizeof(st_lex_user))))
	      YYABORT;
	    $$->user = $1; $$->host=$3;
3278
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3279 3280 3281 3282 3283 3284

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
3285
	| AGAINST		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3286
	| AGGREGATE_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3287
	| AUTO_INC		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3288 3289
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
3290
	| BACKUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3291
	| BEGIN_SYM		{}
3292
	| BERKELEY_DB_SYM	{}
3293
	| BINLOG_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3294 3295
	| BIT_SYM		{}
	| BOOL_SYM		{}
3296
	| BOOLEAN_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3297
	| CACHE_SYM		{}
3298
	| CHANGED		{}
3299
	| CHARSET		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3300
	| CHECKSUM_SYM		{}
3301
	| CIPHER_SYM		{}
3302
	| CLIENT_SYM		{}
3303
	| CLOSE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3304
	| COMMENT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3305
	| COMMITTED_SYM		{}
3306
	| COMMIT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3307
	| COMPRESSED_SYM	{}
3308
	| CONCURRENT		{}
3309
	| CUBE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3310 3311 3312 3313 3314
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
3315 3316
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3317
	| DO_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3318 3319 3320 3321 3322
	| DUMPFILE		{}
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
3323
	| EVENTS_SYM		{}
3324
	| EXECUTE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3325
	| EXTENDED_SYM		{}
3326
	| FAST_SYM		{}
3327 3328
        | DISABLE_SYM           {}
        | ENABLE_SYM            {}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3329
	| FULL			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3330 3331 3332 3333 3334
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
	| GRANTS                {}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3335
	| GLOBAL_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3336
	| HEAP_SYM		{}
3337
	| HANDLER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3338 3339 3340
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
3341
	| INDEXES		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3342
	| ISOLATION		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3343
	| ISAM_SYM		{}
3344
	| ISSUER_SYM		{}
3345
	| INNOBASE_SYM		{}
3346
	| INSERT_METHOD		{}
3347
        | IO_THREAD		{}
3348
	| LAST_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3349
	| LEVEL_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3350
	| LOCAL_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3351
	| LOCKS_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3352 3353 3354 3355 3356 3357 3358 3359 3360 3361
	| 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	{}
3362
	| MAX_CONNECTIONS_PER_HOUR       {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3363
	| MAX_QUERIES_PER_HOUR  {}
3364
	| MAX_UPDATES_PER_HOUR  {}
3365
	| MEDIUM_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3366
	| MERGE_SYM		{}
3367
	| MEMORY_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3368 3369 3370
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3371
	| MODE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3372 3373 3374 3375
	| MONTH_SYM		{}
	| MYISAM_SYM		{}
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
3376
	| NEXT_SYM		{}
3377
	| NEW_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3378
	| NO_SYM		{}
3379
	| NONE_SYM		{}
3380
	| OFFSET_SYM		{}
3381
	| OPEN_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3382 3383
	| PACK_KEYS_SYM		{}
	| PASSWORD		{}
3384
	| PREV_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3385 3386
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3387
	| QUERY_SYM		{}
3388
	| QUICK			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3389
	| RAID_0_SYM            {}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3390 3391
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3392
	| RAID_STRIPED_SYM      {}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3393
	| RAID_TYPE		{}
3394 3395
        | RELAY_LOG_FILE_SYM	{}
        | RELAY_LOG_POS_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3396 3397
	| RELOAD		{}
	| REPAIR		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3398
	| REPEATABLE_SYM	{}
3399
	| REPLICATION		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3400
	| RESET_SYM		{}
3401
	| RESOURCES		{}
3402
	| RESTORE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3403
	| ROLLBACK_SYM		{}
3404
	| ROLLUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3405 3406 3407
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
3408
	| SAVEPOINT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3409
	| SECOND_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3410 3411
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3412
	| SIGNED_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3413
	| SHARE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3414
	| SHUTDOWN		{}
3415
        | SLAVE		        {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3416
	| SQL_CACHE_SYM		{}
3417
	| SQL_BUFFER_RESULT	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3418
	| SQL_NO_CACHE_SYM	{}
3419
        | SQL_THREAD		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3420 3421 3422 3423
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
3424
	| SUBJECT_SYM		{}
3425
	| SUPER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3426 3427
	| TEMPORARY		{}
	| TEXT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3428
	| TRANSACTION_SYM	{}
3429
	| TRUNCATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3430 3431 3432 3433
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3434
	| UNCOMMITTED_SYM	{}
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3435
	| USE_FRM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3436 3437
	| VARIABLES		{}
	| WORK_SYM		{}
3438
	| X509_SYM		{}
3439
	| YEAR_SYM		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3440 3441 3442 3443 3444 3445

/* Option functions */

set:
	SET opt_option
	{
3446 3447
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
3448 3449
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3450
	}
3451 3452 3453
	option_value_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3454 3455 3456

opt_option:
	/* empty */ {}
3457
	| OPTION {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3458 3459

option_value_list:
3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482
	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; }
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3483 3484

option_value:
3485
	'@' ident_or_text equal expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3486
	{
3487
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3488
	}
3489
	| internal_variable_name equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3490
	  {
3491 3492
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3493
	  }
3494
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
3495 3496 3497 3498 3499 3500 3501 3502
	  {
	    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,
3503
						find_sys_var("tx_isolation"),
3504
						new Item_int((int32) $4)));
3505
	  }
3506
	| CHAR_SYM SET opt_equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3507
	{
3508 3509 3510 3511
	  LEX *lex=Lex;
	  lex->var_list.push_back(new set_var(lex->option_type,
					      find_sys_var("convert_character_set"),
					      $4));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3512 3513
	}
	| PASSWORD equal text_or_password
3514
	  {
3515 3516 3517 3518 3519 3520 3521 3522 3523
	    THD *thd=current_thd;
	    LEX_USER *user;
	    if (!(user=(LEX_USER*) sql_alloc(sizeof(LEX_USER))))
	      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
3524
	  {
3525 3526
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
3527
	;
3528

3529 3530 3531 3532 3533 3534 3535 3536
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
3537
	;
3538 3539 3540 3541 3542 3543 3544

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; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557

text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
	    if (!$3.length)
	      $$=$3.str;
	    else
	    {
	      char *buff=(char*) sql_alloc(HASH_PASSWORD_LENGTH+1);
	      make_scrambled_password(buff,$3.str);
	      $$=buff;
	    }
3558
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3559

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3560

3561
set_expr_or_default:
3562 3563 3564
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
	| ON	  { $$=new Item_string("ON",2); }
3565
	| ALL	  { $$=new Item_string("ALL",3); }
3566
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3567 3568


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3569 3570 3571 3572 3573 3574 3575
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
3576 3577 3578
	table_lock_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3579 3580 3581

table_or_tables:
	TABLE_SYM
3582
	| TABLES;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3583 3584 3585

table_lock_list:
	table_lock
3586
	| table_lock_list ',' table_lock;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3587 3588 3589

table_lock:
	table_ident opt_table_alias lock_option
3590
	{ if (!add_table_to_list($1,$2,0,(thr_lock_type) $3)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3591 3592 3593 3594 3595

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
	| WRITE_SYM     { $$=current_thd->update_lock_default; }
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
3596
	| READ_SYM LOCAL_SYM { $$= TL_READ; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3597 3598

unlock:
3599
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3600 3601


3602
/*
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3603
** Handler: direct access to ISAM functions
3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
	  Lex->sql_command = SQLCOM_HA_OPEN;
	  if (!add_table_to_list($2,$4,0))
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
	  Lex->sql_command = SQLCOM_HA_CLOSE;
	  if (!add_table_to_list($2,0,0))
	    YYABORT;
	}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3619
	| HANDLER_SYM table_ident READ_SYM
3620
	{
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
3621 3622 3623
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
3624 3625
	  lex->select->select_limit= 1;
	  lex->select->offset_limit= 0L;
3626 3627
	  if (!add_table_to_list($2,0,0))
	    YYABORT;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3628
        }
3629
        handler_read_or_scan where_clause limit_clause { };
3630

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3631 3632
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
3633
        | ident handler_rkey_function { Lex->backup_dir= $1.str; };
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3634 3635 3636

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
3637
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  };
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3638 3639 3640 3641 3642 3643

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;  }
3644 3645
	| handler_rkey_mode
	{
3646 3647
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
3648
	  lex->ha_rkey_mode=$1;
3649
	  if (!(lex->insert_list = new List_item))
3650
	    YYABORT;
3651
	} '(' values ')' { };
3652 3653

handler_rkey_mode:
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
3654 3655 3656 3657
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
3658
	| LT     { $$=HA_READ_BEFORE_KEY;  };
3659

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3660 3661 3662 3663 3664
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
3665 3666 3667 3668 3669 3670
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
	  lex->select->db=0;
3671 3672
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
3673
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3674
	}
3675 3676 3677
	grant_privileges ON opt_table FROM user_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3678 3679 3680 3681

grant:
	GRANT
	{
3682 3683 3684
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
3685 3686 3687 3688 3689
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
	  lex->select->db= 0;
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
3690
	  bzero((char *)&(lex->mqh),sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3691 3692
	}
	grant_privileges ON opt_table TO_SYM user_list
3693 3694 3695
	require_clause grant_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3696 3697 3698

grant_privileges:
	grant_privilege_list {}
3699 3700
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
	| ALL			{ Lex->grant = GLOBAL_ACLS;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3701 3702 3703

grant_privilege_list:
	grant_privilege
3704
	| grant_privilege_list ',' grant_privilege;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3705 3706

grant_privilege:
3707 3708 3709 3710
	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 {}
3711 3712
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3713 3714 3715 3716
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
3717
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3718 3719 3720 3721
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
3722 3723 3724 3725 3726 3727 3728 3729
	| 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;}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3730

3731

3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
	    net_printf(&lex->thd->net,ER_DUP_ARGUMENT, "SUBJECT");
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
	    net_printf(&lex->thd->net,ER_DUP_ARGUMENT, "ISSUER");
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
	    net_printf(&lex->thd->net,ER_DUP_ARGUMENT, "CIPHER");
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
3774
 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3775 3776 3777
opt_table:
	'*'
	  {
3778 3779
	    LEX *lex=Lex;
	    lex->select->db=lex->thd->db;
3780
	    if (lex->grant == GLOBAL_ACLS)
3781 3782
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3783
	    {
3784 3785
	      send_error(&lex->thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
	      YYABORT;
3786
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3787 3788 3789
	  }
	| ident '.' '*'
	  {
3790 3791
	    LEX *lex=Lex;
	    lex->select->db = $1.str;
3792
	    if (lex->grant == GLOBAL_ACLS)
3793 3794
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3795
	    {
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3796
	      send_error(&lex->thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3797 3798 3799 3800 3801
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
3802 3803
	    LEX *lex=Lex;
	    lex->select->db = NULL;
3804 3805
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
3806
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3807
	    {
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3808
	      send_error(&lex->thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3809 3810 3811 3812 3813
	      YYABORT;
	    }
	  }
	| table_ident
	  {
3814
	    LEX *lex=Lex;
3815
	    if (!add_table_to_list($1,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3816
	      YYABORT;
3817
	    if (lex->grant == GLOBAL_ACLS)
3818
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
3819
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3820 3821 3822


user_list:
3823 3824 3825 3826 3827 3828 3829
	grant_user  { if (Lex->users_list.push_back($1)) YYABORT;}
	| user_list ',' grant_user
	  {
	    if (Lex->users_list.push_back($3))
	      YYABORT;
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
	     char *buff=(char*) sql_alloc(HASH_PASSWORD_LENGTH+1);
	     if (buff)
	     {
	       make_scrambled_password(buff,$4.str);
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
3850
	  { $$=$1; $1->password.str=NullS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3851 3852 3853


opt_column_list:
3854 3855 3856 3857 3858
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
3859
	| '(' column_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3860 3861 3862

column_list:
	column_list ',' column_list_id
3863
	| column_list_id;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3864 3865 3866 3867 3868 3869 3870

column_list_id:
	ident
	{
	  String *new_str = new String((const char*) $1.str,$1.length);
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
3871
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3872 3873 3874 3875 3876
	  while ((point=iter++))
	  {
	    if (!my_strcasecmp(point->column.ptr(),new_str->ptr()))
		break;
	  }
3877
	  lex->grant_tot_col|= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3878
	  if (point)
3879
	    point->rights |= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3880
	  else
3881
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
3882
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3883

tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
3884 3885

require_clause: /* empty */
3886
        | REQUIRE_SYM require_list 
3887 3888 3889
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
3890
        | REQUIRE_SYM SSL_SYM
3891 3892 3893
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
3894
        | REQUIRE_SYM X509_SYM
3895 3896 3897 3898 3899 3900 3901
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
3902
	;
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
3903

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3904
grant_options:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3905
	/* empty */ {}
3906
	| WITH grant_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3907

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3908 3909
grant_option_list:
	grant_option_list grant_option {}
3910
	| grant_option {};
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3911 3912 3913

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
3914
        | MAX_QUERIES_PER_HOUR ULONG_NUM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3915
        {
3916
	  Lex->mqh.questions=$2;
3917
	  Lex->mqh.bits |= 1;
3918
	}
3919
        | MAX_UPDATES_PER_HOUR ULONG_NUM
3920
        {
3921
	  Lex->mqh.updates=$2;
3922
	  Lex->mqh.bits |= 2;
3923
	}
3924
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
3925
        {
3926
	  Lex->mqh.connections=$2;
3927
	  Lex->mqh.bits |= 4;
3928
	};
3929

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3930
begin:
3931 3932
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3933 3934 3935

opt_work:
	/* empty */ {}
3936
	| WORK_SYM {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3937 3938

commit:
3939
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3940 3941

rollback:
3942 3943 3944 3945 3946 3947
	ROLLBACK_SYM 
	{
	  Lex->sql_command = SQLCOM_ROLLBACK;
	}
	| ROLLBACK_SYM TO_SYM SAVEPOINT_SYM ident
	{
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
3948
	  Lex->sql_command = SQLCOM_ROLLBACK_TO_SAVEPOINT;
3949 3950 3951 3952 3953 3954 3955 3956
	  Lex->savepoint_name = $4.str;
	};
savepoint:
	SAVEPOINT_SYM ident
	{
	  Lex->sql_command = SQLCOM_SAVEPOINT;
	  Lex->savepoint_name = $2.str;
	};
3957 3958 3959 3960 3961 3962

/*
** UNIONS : glue selects together
*/


serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3963
opt_union:	
3964 3965
	/* empty */ {}
	| union_list;
3966 3967

union_list:
3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985
	UNION_SYM union_option
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
	    net_printf(&lex->thd->net, ER_WRONG_USAGE,"UNION","INTO");
	    YYABORT;
	  }
	  if (lex->select->linkage == NOT_A_SELECT)
	  {
	    send_error(&lex->thd->net, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
	  if (mysql_new_select(lex))
	    YYABORT;
	  lex->select->linkage=UNION_TYPE;
	} 
3986
	select_init {}
3987
	;
3988 3989

union_opt:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3990
	union_list {}
3991
	| optional_order_or_limit {};
3992 3993

optional_order_or_limit:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3994 3995 3996 3997
      	/* empty 
           intentional reduce/reduce conflict here !!!
           { code } below should not be executed
           when neither ORDER BY nor LIMIT are used */ {}
3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013
	|
	  {
    	    LEX *lex=Lex;
	    if (!lex->select->braces)
	    {
	      send_error(&lex->thd->net, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
	    if (mysql_new_select(lex))
	      YYABORT;
	    mysql_init_select(lex);
	    lex->select->linkage=NOT_A_SELECT;
	    lex->select->select_limit=lex->thd->variables.select_limit;
	  }
	  opt_order_clause limit_clause
	;
4014 4015

union_option:
4016
	/* empty */ {}
4017
	| DISTINCT {}
4018 4019
	| ALL { Lex->union_option=1; }
	;