sql_yacc.yy 93.7 KB
Newer Older
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1
/* Copyright (C) 2000-2001 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 139 140 141 142 143 144 145 146 147
%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
148
%token	UNLOCK_SYM
149
%token	UPDATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
150 151 152 153 154 155 156

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

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

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

464 465 466 467
%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
468
%token	SQL_SMALL_RESULT
469
%token  SQL_BUFFER_RESULT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
470

471 472
%token  ISSUER_SYM
%token  SUBJECT_SYM
473
%token  CIPHER_SYM
474

bk@work.mysql.com's avatar
bk@work.mysql.com committed
475 476 477 478 479 480 481 482 483 484 485
%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 '~'
486 487
%left   XOR
%left   '^'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
488 489 490
%right	NOT
%right	BINARY

491 492 493 494 495 496
/* These don't actually affect the way the query is really evaluated, but
   they silence a few warnings for shift/reduce conflicts. */
%left	','
%left	STRAIGHT_JOIN JOIN_SYM
%nonassoc	CROSS INNER_SYM NATURAL LEFT RIGHT

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

%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>
512
	text_string 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
513 514

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

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

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

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

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

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

%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

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

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

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

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

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

572 573
%type <variable> internal_variable_name

bk@work.mysql.com's avatar
bk@work.mysql.com committed
574
%type <NONE>
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
575
	query verb_clause create change select do drop insert replace insert2
576 577
	insert_values update delete truncate rename
	show describe load alter optimize flush
578
	reset purge begin commit rollback slave master_def master_defs
579
	repair restore backup analyze check 
580
	field_list field_list_item field_spec kill
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 654 655
	| revoke
	| rollback
	| select
	| set
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
656
	| slave
bk@work.mysql.com's avatar
bk@work.mysql.com committed
657
	| show
658
	| truncate
659
	| handler
bk@work.mysql.com's avatar
bk@work.mysql.com committed
660 661
	| unlock
	| update
662
	| use;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
663 664 665 666

/* change master */

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

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
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;
       }
       |
699
       MASTER_PORT_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
700 701 702 703
       {
	 Lex->mi.port = $3;
       }
       |
704
       MASTER_LOG_POS_SYM EQ ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
705 706 707 708
       {
	 Lex->mi.pos = $3;
       }
       |
709
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
710 711 712
       {
	 Lex->mi.connect_retry = $3;
       }
713 714 715 716 717 718 719 720 721
       |
       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;
722
       };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
723

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
725 726 727 728 729 730 731
/* 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
732
	  if (!add_table_to_list($5,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
733
				 ($2 & HA_LEX_CREATE_TMP_TABLE ?
734
				   &tmp_table_alias : (LEX_STRING*) 0),1))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
735 736 737 738 739 740 741
	    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;
742
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
743 744 745
	}
	create2

746
	| CREATE opt_unique_or_fulltext INDEX ident ON table_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
747
	  {
748 749
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
750
	    if (!add_table_to_list($6,NULL,1))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
751
	      YYABORT;
752 753 754 755
	    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
756 757 758
	  }
	  '(' key_list ')'
	  {
759 760 761
	    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
762 763 764
	  }
	| CREATE DATABASE opt_if_not_exists ident
	  {
765 766 767 768
	    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
769 770 771
	  }
	| CREATE udf_func_type UDF_SYM ident
	  {
772 773 774 775 776
	    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
777 778 779
	  }
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
	  {
780 781 782
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
783
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
784 785

create2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
786
	'(' field_list ')' opt_create_table_options create3 {}
787
	| opt_create_table_options create3 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
788 789

create3:
790 791
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
792
          {
793 794 795
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
796
          }
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
797
          select_options select_item_list opt_select_from opt_union {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
798

799 800
opt_as:
	/* empty */ {}
801
	| AS	    {};
802

bk@work.mysql.com's avatar
bk@work.mysql.com committed
803
opt_table_options:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
804
	/* empty */	 { $$= 0; }
805
	| table_options  { $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
806 807 808

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
811
table_option:
812
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
813 814

opt_if_not_exists:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
815
	/* empty */	 { $$= 0; }
816
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
817 818 819

opt_create_table_options:
	/* empty */
820
	| create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
821 822 823

create_table_options:
	create_table_option
824
	| create_table_option create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
825 826 827

create_table_option:
	TYPE_SYM EQ table_types		{ Lex->create_info.db_type= $3; }
828 829 830
	| 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
831 832
	| PASSWORD EQ TEXT_STRING	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM EQ TEXT_STRING	{ Lex->create_info.comment=$3.str; }
833
	| AUTO_INC EQ ulonglong_num	{ Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;}
834 835
	| 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
836 837
	| 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
838
	| ROW_FORMAT_SYM EQ row_types	{ Lex->create_info.row_type= $3; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
839 840 841
	| 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;}
842 843 844 845
	| UNION_SYM EQ '(' table_list ')'
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
846 847
	    TABLE_LIST *table_list= (TABLE_LIST*) lex->select->table_list.first;
	    lex->create_info.merge_list= lex->select->table_list;
848 849
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
850 851
	    lex->select->table_list.elements=1;
	    lex->select->table_list.next= (byte**) &(table_list->next);
852
	    table_list->next=0;
853
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
854
	  }
855
	| INSERT_METHOD EQ merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
856
	| DATA_SYM DIRECTORY_SYM EQ TEXT_STRING	{ Lex->create_info.data_file_name= $4.str; }
857
	| 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
858 859 860 861 862 863 864

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
865
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
866 867 868 869 870

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
871
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
872 873 874 875

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

878 879 880
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
881
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
882

bk@work.mysql.com's avatar
bk@work.mysql.com committed
883 884
opt_select_from:
	/* empty */
885
	| select_from select_lock_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
886 887 888

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
889
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
890 891 892 893

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
894
	| INT_SYM {$$ = (int) INT_RESULT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
895 896 897

field_list:
	  field_list_item
898
	| field_list ',' field_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
899 900 901 902 903 904 905 906 907 908


field_list_item:
	  field_spec
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
	| key_type opt_ident '(' key_list ')'
	  {
909 910 911
	    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
912
	  }
913
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
914 915 916 917 918 919
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
	| opt_constraint CHECK_SYM '(' expr ')'
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
920
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
921 922 923

opt_constraint:
	/* empty */
924
	| CONSTRAINT opt_ident;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
925 926 927 928

field_spec:
	field_ident
	 {
929 930 931
	   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
932 933 934
	 }
	type opt_attribute
	{
935
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
936 937
	  if (add_field_to_list($1.str,
				(enum enum_field_types) $3,
938 939 940
				lex->length,lex->dec,lex->type,
				lex->default_value,lex->change,
				lex->interval))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
941
	    YYABORT;
942
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991

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 ')'
	  {
992 993
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
994 995 996 997
	    $$=FIELD_TYPE_ENUM;
	  }
	| SET { Lex->interval_list.empty();} '(' string_list ')'
	  {
998 999
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1000
	    $$=FIELD_TYPE_SET;
1001
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1002 1003 1004 1005

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1008 1009 1010 1011
varchar:
	char VARYING {}
	| VARCHAR {}
	| NATIONAL_SYM VARCHAR {}
1012
	| NCHAR_SYM VARCHAR {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1013 1014 1015 1016 1017 1018

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

real_type:
1022
	REAL		{ $$= current_thd->sql_mode & MODE_REAL_AS_FLOAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1023 1024
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
1025
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1026 1027 1028 1029 1030


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
1031
	| precision		{};
1032 1033 1034 1035 1036 1037

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

field_options:
	/* empty */		{}
1042
	| field_opt_list	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1043 1044 1045

field_opt_list:
	field_opt_list field_option {}
1046
	| field_option {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1047 1048

field_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1049
	SIGNED_SYM	{}
1050
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
1051
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1052 1053 1054

opt_len:
	/* empty */	{ $$=(char*) 0; }	/* use default length */
1055
	| '(' NUM ')'	{ $$=$2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1056 1057 1058

opt_precision:
	/* empty */	{}
1059
	| precision	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1060 1061 1062

opt_attribute:
	/* empty */ {}
1063
	| opt_attribute_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1064 1065 1066

opt_attribute_list:
	opt_attribute_list attribute {}
1067
	| attribute;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1068 1069 1070 1071 1072 1073 1074 1075

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; }
1076 1077
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
	| COMMENT_SYM text_literal {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1078 1079 1080

opt_binary:
	/* empty */	{}
1081
	| BINARY	{ Lex->type|=BINARY_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1082 1083 1084 1085 1086 1087

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

opt_on_delete:
	/* empty */ {}
1092
	| opt_on_delete_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1093 1094 1095

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
1096
	| opt_on_delete_item {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1097 1098 1099 1100 1101 1102


opt_on_delete_item:
	ON DELETE_SYM delete_option {}
	| ON UPDATE_SYM delete_option {}
	| MATCH FULL	{}
1103
	| MATCH PARTIAL {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1104 1105 1106 1107 1108 1109

delete_option:
	RESTRICT	 {}
	| CASCADE	 {}
	| SET NULL_SYM {}
	| NO_SYM ACTION {}
1110
	| SET DEFAULT {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1111 1112 1113 1114

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1115 1116
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1117
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
1118
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1119 1120 1121

key_or_index:
	KEY_SYM {}
1122
	| INDEX {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1123 1124 1125 1126

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

1129
opt_unique_or_fulltext:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1130 1131
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
1132
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1133 1134 1135

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
1136
	| key_part order_dir		{ Lex->col_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1137 1138 1139

key_part:
	ident			{ $$=new key_part_spec($1.str); }
1140
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1141 1142 1143

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
1144
	| field_ident	{ $$=$1.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1145 1146 1147

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
1148
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
1160
	  if (!add_table_to_list($4, NULL,1))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1161 1162 1163 1164 1165 1166 1167
	    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();
1168 1169 1170 1171
          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
1172 1173
    	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1174
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1175 1176
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1177
	}
1178
	alter_list;
1179
 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1180
alter_list:
1181
        | alter_list_item
1182
	| alter_list ',' alter_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1183 1184

add_column:
1185
	ADD opt_column { Lex->change=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1186 1187

alter_list_item:
1188 1189
	add_column field_list_item opt_place { Lex->simple_alter=0; }
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
1190 1191 1192 1193 1194
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1195
          field_spec opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1196 1197
	| MODIFY_SYM opt_column field_ident
	  {
1198 1199 1200 1201
	    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
1202 1203 1204
	  }
	  type opt_attribute
	  {
1205
	    LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1206 1207
	    if (add_field_to_list($3.str,
				  (enum enum_field_types) $5,
1208 1209 1210
				  lex->length,lex->dec,lex->type,
				  lex->default_value, $3.str,
				  lex->interval))
1211
	      YYABORT;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1212
	  }
1213
	  opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1214
	| DROP opt_column field_ident opt_restrict
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
	  {
	    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;
	  }
1225
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1226
	| DROP key_or_index field_ident
1227 1228 1229 1230 1231 1232
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1233 1234
	| 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
1235
	| ALTER opt_column field_ident SET DEFAULT literal
1236 1237 1238 1239 1240
	  {
	    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
1241
	| ALTER opt_column field_ident DROP DEFAULT
1242 1243 1244 1245 1246
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1247
	| RENAME opt_to table_ident
1248 1249
	  { 
	    LEX *lex=Lex;
1250 1251
	    lex->select->db=$3->db.str;
	    lex->name= $3->table.str;
1252
	  }
1253
        | create_table_options { Lex->simple_alter=0; }
1254
	| order_clause         { Lex->simple_alter=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1255 1256 1257

opt_column:
	/* empty */	{}
1258
	| COLUMN_SYM	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1259 1260 1261

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
1262
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1263 1264 1265 1266

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
1267
	| CASCADE	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1268 1269 1270 1271

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
1272
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1273 1274 1275 1276

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1277
	| EQ		{}
1278
	| AS		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1279

nick@mysql.com's avatar
nick@mysql.com committed
1280 1281 1282
/*
 * 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
1283
slave:
nick@mysql.com's avatar
nick@mysql.com committed
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
	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;
         }
         |
1298
	SLAVE START_SYM slave_thread_opts
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1299
         {
1300 1301 1302
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1303 1304
         }
         |
1305
	SLAVE STOP_SYM slave_thread_opts
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1306
         {
1307 1308 1309
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_STOP;
	   lex->type = 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1310
         };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1311

1312 1313 1314
slave_thread_opts:
	slave_thread_opt
	| slave_thread_opts ',' slave_thread_opt;
1315 1316

slave_thread_opt:
1317 1318 1319 1320
	/*empty*/	{} 
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
	| IO_THREAD   	{ Lex->slave_thd_opt|=SLAVE_IO; }
	;
1321
  
1322 1323 1324 1325 1326 1327 1328 1329
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
	table_list FROM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
1330
        };
1331

1332 1333 1334 1335 1336 1337 1338 1339
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
	table_list TO_SYM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
1340
        };
1341

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1342 1343 1344
repair:
	REPAIR table_or_tables
	{
1345 1346 1347
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1348
	}
1349
	table_list opt_mi_repair_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1350

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1351
opt_mi_repair_type:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1352
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1353
	| mi_repair_types {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1354

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1355 1356
mi_repair_types:
	mi_repair_type {}
1357
	| mi_repair_type mi_repair_types {};
1358

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1359
mi_repair_type:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1360
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1361
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
1362
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1363 1364

analyze:
1365
	ANALYZE_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1366
	{
1367 1368 1369
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1370
	}
1371
	table_list opt_mi_check_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1372 1373

check:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1374
	CHECK_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1375
	{
1376 1377 1378
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1379
	}
1380
	table_list opt_mi_check_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1381

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1382 1383
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1384
	| mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1385 1386 1387

mi_check_types:
	mi_check_type {}
1388
	| mi_check_type mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1389 1390 1391 1392 1393 1394

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1397
optimize:
1398
	OPTIMIZE table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1399
	{
1400 1401 1402
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1403
	}
1404
	table_list opt_mi_check_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1405

1406 1407 1408 1409 1410
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1411
	table_to_table_list;
1412 1413 1414

table_to_table_list:
	table_to_table
1415
	| table_to_table_list ',' table_to_table;
1416 1417 1418

table_to_table:
	table_ident TO_SYM table_ident
1419 1420
	{ if (!add_table_to_list($1,NULL,1,TL_IGNORE) ||
	      !add_table_to_list($3,NULL,1,TL_IGNORE))
1421
	     YYABORT;
1422
 	};
1423

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1424
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1425
  Select : retrieve data from table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1426 1427 1428 1429
*/


select:
1430
	select_init { Lex->sql_command=SQLCOM_SELECT; };
1431 1432

select_init:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1433
	SELECT_SYM select_part2 { Select->braces=false;	} opt_union
1434
	|
1435
	'(' SELECT_SYM 	select_part2 ')' { Select->braces=true;} union_opt;
1436

1437 1438

select_part2:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1439 1440
	{
	  LEX *lex=Lex;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1441
	  lex->lock_option=TL_READ;
1442
	   mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1443
	}
1444
	select_options select_item_list select_into select_lock_type;
1445

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1446
select_into:
1447
	limit_clause {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1448 1449
	| select_from
	| opt_into select_from
1450
	| select_from opt_into;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1451 1452

select_from:
1453
	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
1454 1455 1456 1457


select_options:
	/* empty*/
1458
	| select_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1459 1460 1461

select_option_list:
	select_option_list select_option
1462
	| select_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1463 1464

select_option:
1465
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1466 1467 1468 1469 1470 1471
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1472 1473 1474
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
	| 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; }
	| SQL_CACHE_SYM    { Select->options|= OPTION_TO_QUERY_CACHE; }
	| ALL		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1491

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1492 1493 1494
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1495 1496 1497 1498 1499 1500 1501
	  {
	    LEX *lex=Lex;
	    if (check_simple_select())
	      YYABORT;	
	    lex->lock_option= TL_WRITE;
	    lex->thd->safe_to_cache_query=0;
	  }
1502
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1503 1504 1505 1506 1507 1508 1509 1510
	  {
	    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
1511

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1512 1513 1514 1515 1516 1517 1518
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
	    if (add_item_to_list(new Item_field(NULL,NULL,"*")))
	      YYABORT;
1519
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530


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));
1531
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1532 1533

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

remember_end:
1537
	{ $$=(char*) Lex->tok_end; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1538 1539 1540

select_item2:
	table_wild	{ $$=$1; } /* table.* */
1541
	| expr		{ $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1542 1543 1544 1545 1546 1547

select_alias:
	{ $$.str=0;}
	| AS ident { $$=$2; }
	| AS TEXT_STRING  { $$=$2; }
	| ident { $$=$1; }
1548
	| TEXT_STRING  { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1549 1550 1551

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1554 1555
/* all possible expressions */
expr:	expr_expr	{$$ = $1; }
1556
	| simple_expr	{$$ = $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569

/* 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); }
1570
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591
	| 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); }
1592
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }	
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1593 1594 1595 1596 1597
	| 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
1598
	  { $$= new Item_date_add_interval($1,$4,$5,1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1599 1600 1601 1602 1603 1604 1605 1606 1607

/* 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); }
1608
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
	| 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); }
1630
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1631 1632 1633 1634 1635 1636
	| 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); }
1637
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650

/* 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); }
1651
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
	| 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); }
1672
        | no_and_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 1678
	| 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); }
1679
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1680 1681 1682 1683

simple_expr:
	simple_ident
	| literal
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1684
	| '@' ident_or_text SET_VAR expr
1685 1686
	  {
	    $$= new Item_func_set_user_var($2,$4);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1687 1688 1689
	    current_thd->safe_to_cache_query=0;
	  }
	| '@' ident_or_text	 
1690 1691
	  {
	    $$= new Item_func_get_user_var($2);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1692 1693
	    current_thd->safe_to_cache_query=0;
	  }
1694 1695 1696 1697
	| '@' '@' 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
1698
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1699 1700 1701 1702 1703 1704 1705
	| 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; }
1706 1707
        | MATCH ident_list_arg AGAINST '(' expr ')'
          { Select->ftfunc_list.push_back((Item_func_match *)
1708
                   ($$=new Item_func_match_nl(*$2,$5))); }
1709 1710
        | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
          { Select->ftfunc_list.push_back((Item_func_match *)
1711
                   ($$=new Item_func_match_bool(*$2,$5))); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1712 1713
	| 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
1714
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
1715
	  { $$= new Item_func_case(* $4, $2, $5 ); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1716
	| CONVERT_SYM '(' expr ',' cast_type ')'  { $$= create_func_cast($3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737
	| 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
1738
	  { $$= new Item_func_curdate(); current_thd->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1739
	| CURTIME optional_braces
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1740
	  { $$= new Item_func_curtime(); current_thd->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1741
	| CURTIME '(' expr ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1742 1743 1744 1745
	  { 
	    $$= new Item_func_curtime($3); 
	    current_thd->safe_to_cache_query=0;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1746 1747 1748 1749 1750
	| 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
1751 1752 1753 1754
	  { 
	    $$= new Item_func_database();
            current_thd->safe_to_cache_query=0; 
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1755 1756 1757 1758
	| 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
1759 1760 1761 1762 1763
	| 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
1764 1765 1766 1767 1768
	| 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); }
1769
	| DES_DECRYPT_SYM '(' expr ')'
1770
        { $$= new Item_func_des_decrypt($3); }
1771
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
1772
        { $$= new Item_func_des_decrypt($3,$5); }
1773
	| DES_ENCRYPT_SYM '(' expr ')'
1774
        { $$= new Item_func_des_encrypt($3); }
1775
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
1776
        { $$= new Item_func_des_encrypt($3,$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788
	| 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
1789
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
	  }
	| 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
1808
	    current_thd->safe_to_cache_query=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1809 1810 1811 1812
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1813
	    current_thd->safe_to_cache_query=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824
	  }
	| 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); }
1825 1826 1827 1828
	| LOG_SYM '(' expr ')'
		{ $$= new Item_func_log($3); }
	| LOG_SYM '(' expr ',' expr ')'
		{ $$= new Item_func_log($3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1829 1830 1831 1832 1833
	| 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
1834
	  { $$= new Item_func_now(); current_thd->safe_to_cache_query=0;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1835
	| NOW_SYM '(' expr ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1836 1837 1838 1839 1840
	  { $$= 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
1841 1842
	| 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
1843 1844 1845 1846
	| 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
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875
	| 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); }
1876 1877
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
	| 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
1921 1922 1923
	  { 
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1924
	| UNIX_TIMESTAMP '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1925 1926 1927 1928
	  {
	    $$= new Item_func_unix_timestamp();
	    current_thd->safe_to_cache_query=0;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1929 1930 1931
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1932
	  { $$= new Item_func_user(); current_thd->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
	| WEEK_SYM '(' expr ')'
	  { $$= new Item_func_week($3,new Item_int((char*) "0",0,1)); }
	| 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
1944 1945 1946 1947
	  { 
	    $$=new Item_func_benchmark($3,$5);
	    current_thd->safe_to_cache_query=0;
	  }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1948
	| EXTRACT_SYM '(' interval FROM expr ')'
1949
	{ $$=new Item_extract( $3, $5); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1950 1951 1952

udf_expr_list:
	/* empty */	{ $$= NULL; }
1953
	| expr_list	{ $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976

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); }
	| COUNT_SYM '(' '*' ')'
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
	| COUNT_SYM '(' DISTINCT expr_list ')'
	  { $$=new Item_sum_count_distinct(* $4); }
	| GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
	  { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
	| MIN_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_min($3); }
	| MAX_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_max($3); }
	| STD_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_std($3); }
	| SUM_SYM '(' in_sum_expr ')'
1977
	  { $$=new Item_sum_sum($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1978 1979

in_sum_expr:
1980
	{ Select->in_sum_expr++; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1981 1982
	expr
	{
1983
	  Select->in_sum_expr--;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1984
	  $$=$2;
1985
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1986

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1987 1988 1989 1990 1991 1992 1993 1994
cast_type:
	BINARY 			{ $$=ITEM_CAST_BINARY; }
	| 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; }
1995
	| DATETIME		{ $$=ITEM_CAST_DATETIME; };
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1996

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1997
expr_list:
1998
	{ Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1999
	expr_list2
2000
	{ $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2001 2002

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

2006 2007
ident_list_arg:
          ident_list          { $$= $1; }
2008
        | '(' ident_list ')'  { $$= $2; };
2009

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2010
ident_list:
2011
        { Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2012
        ident_list2
2013
        { $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2014 2015

ident_list2:
2016
        simple_ident { Select->expr_list.head()->push_back($1); }
2017
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2018 2019 2020

opt_expr:
	/* empty */      { $$= NULL; }
2021
	| expr         	 { $$= $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2022 2023 2024

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

when_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2028
        { Select->when_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2029
	when_list2
2030
	{ $$= Select->when_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2031 2032

when_list2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2033
	expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2034
	  {
2035 2036 2037
	    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
2038
	}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2039
	| when_list2 WHEN_SYM expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2040
	  {
2041 2042 2043
	    SELECT_LEX *sel=Select;
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
2044
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2045 2046 2047

opt_pad:
	/* empty */ { $$=new Item_string(" ",1); }
2048
	| expr	    { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2049 2050 2051 2052

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
2053
	| join_table_list normal_join join_table_list { $$=$3; }
2054 2055 2056
	| join_table_list STRAIGHT_JOIN join_table_list
	  { $$=$3 ; $$->straight=1; }
	| join_table_list INNER_SYM JOIN_SYM join_table_list ON expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2057
	  { add_join_on($4,$6); $$=$4; }
2058
	| join_table_list INNER_SYM JOIN_SYM join_table_list
2059 2060
	  {
	    SELECT_LEX *sel=Select;
2061 2062
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$4->db; sel->table2=$4->alias;
2063
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2064 2065
	  USING '(' using_list ')'
	  { add_join_on($4,$8); $$=$4; }
2066
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2067
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2068
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
2069 2070
	  {
	    SELECT_LEX *sel=Select;
2071 2072
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2073
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2074
	  USING '(' using_list ')'
2075
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2076
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2077
	  { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
2078
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2079
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2080
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
2081 2082
	  {
	    SELECT_LEX *sel=Select;
2083 2084
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2085
	  }
2086 2087
	  USING '(' using_list ')'
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2088
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2089
	  { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2090
	| join_table_list NATURAL JOIN_SYM join_table_list
2091
	  { add_join_natural($1,$4); $$=$4; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2092 2093 2094 2095

normal_join:
	',' {}
	| JOIN_SYM {}
2096
	| CROSS JOIN_SYM {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2097 2098

join_table:
2099 2100 2101 2102
	{
	  SELECT_LEX *sel=Select;
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2103
        table_ident opt_table_alias opt_key_definition
2104 2105 2106
	{
	  SELECT_LEX *sel=Select;
	  if (!($$=add_table_to_list($2,$3,0,TL_UNLOCK, sel->use_index_ptr,
2107 2108
	                             sel->ignore_index_ptr)))
	    YYABORT;
2109
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2110
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2111
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2112 2113 2114

opt_outer:
	/* empty */	{}
2115
	| OUTER		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2116 2117 2118 2119

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
2120 2121 2122 2123 2124
          {
	    SELECT_LEX *sel=Select;
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2125
	| IGNORE_SYM key_usage_list
2126 2127 2128 2129
	  {
	    SELECT_LEX *sel=Select;
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
2130
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2131 2132

key_usage_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2133
	key_or_index { Select->interval_list.empty(); } '(' key_usage_list2 ')'
2134
        { $$= &Select->interval_list; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2135 2136 2137

key_usage_list2:
	key_usage_list2 ',' ident
2138
        { Select->interval_list.push_back(new String((const char*) $3.str,$3.length)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2139
	| ident
2140
        { Select->interval_list.push_back(new String((const char*) $1.str,$1.length)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2141
	| PRIMARY_SYM
2142
        { Select->interval_list.push_back(new String("PRIMARY",7)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2143 2144 2145

using_list:
	ident
2146 2147 2148
	  {
	    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
2149 2150 2151 2152
	      YYABORT;
	  }
	| using_list ',' ident
	  {
2153 2154
	    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
2155
	      YYABORT;
2156
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170

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; }
2171
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2172 2173 2174 2175

table_alias:
	/* empty */
	| AS
2176
	| EQ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2177 2178 2179 2180

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


where_clause:
2185
	/* empty */  { Select->where= 0; }
2186 2187 2188 2189 2190 2191 2192
	| WHERE expr
	  {
	    Select->where= $2;
	    if ($2)
	      $2->top_level_item();
	  }
	  ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2193 2194 2195

having_clause:
	/* empty */
2196
	| HAVING { Select->create_refs=1; } expr
2197 2198
	{
	  SELECT_LEX *sel=Select;
2199 2200 2201 2202 2203 2204
	  sel->having= $3;
	  sel->create_refs=0;
	  if ($3)
	    $3->top_level_item();
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2205 2206 2207

opt_escape:
	ESCAPE_SYM TEXT_STRING	{ $$= $2.str; }
2208
	| /* empty */		{ $$= (char*) "\\"; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2209 2210 2211


/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2212
   group by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2213 2214 2215 2216
*/

group_clause:
	/* empty */
2217
	| GROUP BY group_list olap_opt;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2218 2219

group_list:
2220 2221 2222
	group_list ',' order_ident order_dir
	  { if (add_group_to_list($3,(bool) $4)) YYABORT; }
	| order_ident order_dir
2223
	  { if (add_group_to_list($1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2224

2225 2226
olap_opt:
	/* empty */ {}
2227
	| WITH CUBE_SYM
2228
          {
2229 2230 2231 2232 2233
	    LEX *lex=Lex;
	    lex->olap = true;
	    lex->select->olap= CUBE_TYPE;
	    net_printf(&lex->thd->net, ER_NOT_SUPPORTED_YET, "CUBE");
	    YYABORT;	/* To be deleted in 4.1 */
2234
	  }
2235
	| WITH ROLLUP_SYM
2236
          {
2237 2238 2239 2240 2241
	    LEX *lex=Lex;
	    lex->olap = true;
	    lex->select->olap= ROLLUP_TYPE;
	    net_printf(&lex->thd->net, ER_NOT_SUPPORTED_YET, "ROLLUP");
	    YYABORT;	/* To be deleted in 4.1 */
2242
	  }
2243
	;
2244

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2245
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2246
   Order by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2247 2248
*/

2249
opt_order_clause:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2250
	/* empty */
2251
	| order_clause;
2252 2253

order_clause:
2254 2255
	ORDER_SYM BY 
        { 
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2256
	  LEX *lex=Lex;
2257 2258 2259 2260 2261 2262 2263
	  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
2264
	  lex->select->sort_default=1;
2265
	} order_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2266 2267 2268 2269 2270

order_list:
	order_list ',' order_ident order_dir
	  { if (add_order_to_list($3,(bool) $4)) YYABORT; }
	| order_ident order_dir
2271
	  { if (add_order_to_list($1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2272 2273 2274

order_dir:
	/* empty */ { $$ =  1; }
2275
	| ASC  { $$ =1; }
2276
	| DESC { $$ =0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2277 2278 2279


limit_clause:
2280
	/* empty */ {}
2281
	| LIMIT 
2282
	  {
2283
	    LEX *lex=Lex;
2284 2285 2286 2287
	    if (lex->select->olap != UNSPECIFIED_OLAP_TYPE)
	    {
	      net_printf(&lex->thd->net, ER_WRONG_USAGE, "CUBE/ROLLUP",
		        "LIMIT");
2288
	      YYABORT;
2289
	    }
2290
	  }
2291 2292 2293 2294 2295
	  limit_options
	  ;

limit_options:
	ULONG_NUM
2296
	  {
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
            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
2314 2315 2316 2317

delete_limit_clause:
	/* empty */
	{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2318 2319
	  LEX *lex=Lex;
	  lex->select->select_limit= HA_POS_ERROR;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2320
	}
2321
	| LIMIT ulonglong_num
2322
	{ Select->select_limit= (ha_rows) $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2323 2324

ULONG_NUM:
2325
	NUM	    { $$= strtoul($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2326
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
2327
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
2328
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2329

2330
ulonglong_num:
2331
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2332 2333
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
	| LONG_NUM  { $$= (ulonglong) strtoul($1.str,NULL,10); }
2334
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
2335
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346

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;
	    if (add_proc_to_list(new Item_field(NULL,NULL,$2.str)))
	      YYABORT;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2347
	    current_thd->safe_to_cache_query=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2348
	  }
2349
	  '(' procedure_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2350 2351 2352 2353


procedure_list:
	/* empty */ {}
2354
	| procedure_list2 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2355 2356 2357

procedure_list2:
	procedure_list2 ',' procedure_item
2358
	| procedure_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2359 2360 2361 2362 2363 2364 2365 2366

procedure_item:
	  remember_name expr
	  {
	    if (add_proc_to_list($2))
	      YYABORT;
	    if (!$2->name)
	      $2->set_name($1,(uint) ((char*) Lex->tok_end - $1));
2367
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379

opt_into:
	INTO OUTFILE TEXT_STRING
	{
	  if (!(Lex->exchange= new sql_exchange($3.str,0)))
	    YYABORT;
	}
	opt_field_term opt_line_term
	| INTO DUMPFILE TEXT_STRING
	{
	  if (!(Lex->exchange= new sql_exchange($3.str,1)))
	    YYABORT;
2380
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2381

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2382 2383 2384
/*
  DO statement
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2385

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2386 2387 2388 2389 2390 2391 2392
do:	DO_SYM 
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
2393
	values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2394
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2395
  Drop : delete tables or index
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2396 2397 2398
*/

drop:
2399
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2400
	{
2401 2402
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
2403 2404
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2405 2406 2407
	}
	| DROP INDEX ident ON table_ident {}
	  {
2408 2409 2410 2411
	     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
2412
						     $3.str));
2413
	     if (!add_table_to_list($5,NULL, 1))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2414 2415 2416 2417
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
2418 2419 2420 2421
	    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
2422 2423 2424
	 }
	| DROP UDF_SYM ident
	  {
2425 2426 2427
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
	    lex->udf.name=$3.str;
2428
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2429 2430 2431


table_list:
2432
	table_name
2433
	| table_list ',' table_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2434

2435
table_name:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2436
	table_ident
2437
	{ if (!add_table_to_list($1,NULL,1)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2438 2439 2440

if_exists:
	/* empty */ { $$=0; }
2441 2442
	| IF EXISTS { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2443

2444 2445 2446 2447
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2448 2449 2450 2451 2452
/*
** Insert : add new data to table
*/

insert:
2453 2454 2455 2456 2457 2458 2459
	INSERT { Lex->sql_command = SQLCOM_INSERT; } insert_lock_option
	opt_ignore insert2 
	{
	  set_lock_for_tables($3);
	}
	insert_field_spec
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2460 2461

replace:
2462 2463 2464 2465 2466 2467
	REPLACE
	{
	  LEX *lex=Lex;	
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
2468 2469 2470 2471 2472 2473
	replace_lock_option insert2
	{
	  set_lock_for_tables($3);
	}
	insert_field_spec
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2474 2475

insert_lock_option:
2476 2477 2478 2479 2480
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
	;	
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2481 2482

replace_lock_option:
2483 2484
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2485 2486 2487

insert2:
	INTO insert_table {}
2488
	| insert_table {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2489 2490

insert_table:
2491
	table_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2492
	{
2493 2494 2495 2496
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
2497
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2498 2499 2500 2501 2502

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
2503 2504 2505
	    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
2506 2507
	      YYABORT;
	   }
2508
	   ident_eq_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2509 2510 2511 2512

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
2513
	| '(' ')'	  { };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2514 2515 2516

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
2517
	| insert_ident		{ Lex->field_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2518 2519 2520 2521 2522 2523 2524 2525

insert_values:
	VALUES	values_list  {}
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
2526
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
2527
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2528
	  }
2529
	  select_options select_item_list select_from select_lock_type
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
2530
          opt_union {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2531 2532 2533

values_list:
	values_list ','  no_braces
2534
	| no_braces;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2535 2536 2537 2538

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
2539
	ident_eq_value;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2540 2541

ident_eq_value:
2542
	simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2543
	 {
2544 2545 2546
	  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
2547
	    YYABORT;
2548
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2549 2550

equal:	EQ		{}
2551 2552 2553 2554 2555 2556 2557
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2558 2559 2560 2561 2562 2563 2564 2565 2566

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
2567 2568
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2569
	    YYABORT;
2570
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2571 2572 2573

opt_values:
	/* empty */ {}
2574
	| values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2575 2576

values:
2577
	values ','  expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2578 2579 2580 2581
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592
	| 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
2593 2594 2595 2596

/* Update rows in a table */

update:
2597
        UPDATE_SYM 
2598
	{ 
2599 2600 2601 2602 2603
	  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;
2604
        }
2605 2606 2607 2608 2609 2610
        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
2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621

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;
2622
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2623 2624

opt_low_priority:
2625 2626
	/* empty */	{ $$= current_thd->update_lock_default; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2627 2628 2629 2630

/* Delete rows from a table */

delete:
2631
	DELETE_SYM
2632
	{ 
2633 2634 2635 2636 2637 2638 2639
	  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;
	}
2640 2641
	opt_delete_options single_multi {}
	;
2642 2643

single_multi:
2644 2645 2646 2647 2648 2649 2650
 	FROM table_ident
	{
	  if (!add_table_to_list($2, NULL, 1, Lex->lock_option))
	    YYABORT;
	}
	where_clause opt_order_clause
	delete_limit_clause
2651
	| table_wild_list
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2652
	  { mysql_init_multi_delete(Lex); }
2653
          FROM join_table_list where_clause
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2654 2655
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
2656
	  USING join_table_list where_clause;
2657 2658 2659

table_wild_list:
	  table_wild_one {}
2660
	  | table_wild_list ',' table_wild_one {};
2661 2662 2663 2664

table_wild_one:
	 ident opt_wild
	 {
2665 2666 2667
	   if (!add_table_to_list(new Table_ident($1), NULL, 1,
				  Lex->lock_option))
	     YYABORT;
2668 2669 2670
         }
	 | ident '.' ident opt_wild
	   {
2671 2672
	     if (!add_table_to_list(new Table_ident($1,$3,0), NULL, 1,
				    Lex->lock_option))
2673
	      YYABORT;
2674 2675
	   }
	;
2676 2677 2678

opt_wild:
	/* empty */	{} 
2679
	| '.' '*'	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2680 2681


2682
opt_delete_options:
2683
	/* empty */	{}
2684
	| opt_delete_option opt_delete_options {};
2685 2686

opt_delete_option:
2687
	QUICK		{ Select->options|= OPTION_QUICK; }
2688
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
2689

2690
truncate:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
2691
	TRUNCATE_SYM opt_table_sym table_name
2692 2693 2694
	{
	  LEX* lex = Lex;
	  lex->sql_command= SQLCOM_TRUNCATE;
2695 2696 2697 2698
	  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;
2699 2700
	}
	;
2701

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2702 2703
opt_table_sym:
	/* empty */
2704
	| TABLE_SYM;
2705
 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2706 2707
/* Show things */

2708
show:	SHOW { Lex->wild=0;} show_param;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2709 2710 2711 2712 2713

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
2714 2715 2716 2717 2718
	  {
	    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
2719
	| TABLE_SYM STATUS_SYM opt_db wild
2720 2721 2722 2723 2724
	  {
	    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
2725
	  }
2726
	| OPEN_SYM TABLES opt_db wild
2727 2728 2729 2730 2731
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
	    lex->select->db= $3;
	    lex->select->options=0;
2732
	  }
2733
	| opt_full COLUMNS from_or_in table_ident opt_db wild
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2734 2735
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2736 2737 2738
	    if ($5)
	      $4->change_db($5);
	    if (!add_table_to_list($4,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2739 2740
	      YYABORT;
	  }
2741
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ 
2742 2743
	  TEXT_STRING AND MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND MASTER_SERVER_ID_SYM EQ
2744 2745 2746 2747 2748
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
2749
	    Lex->mi.server_id = $16;
2750
          }
2751 2752 2753
        | MASTER_SYM LOGS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
2754 2755 2756 2757 2758
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
2759
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
2760
          {
2761 2762
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_SHOW_BINLOG_EVENTS;
2763
	    lex->select->select_limit= lex->thd->variables.select_limit;
2764 2765
	    lex->select->offset_limit= 0L;
          } limit_clause
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2766 2767 2768 2769 2770
	| keys_or_index FROM table_ident opt_db
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
2771
	    if (!add_table_to_list($3,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2772 2773 2774 2775
	      YYABORT;
	  }
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
2776 2777
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2778 2779
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
2780 2781 2782 2783
	| opt_var_type VARIABLES wild
	{
	    THD *thd= current_thd;
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
2784
	    thd->lex.option_type= (enum_var_type) $1;
2785
	  }
tim@cane.mysql.fi's avatar
tim@cane.mysql.fi committed
2786 2787
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2788
	| GRANTS FOR_SYM user
2789 2790 2791 2792 2793 2794
	  {
	    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
2795 2796 2797
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
2798
	    if(!add_table_to_list($3, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2799 2800 2801 2802 2803
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2804
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2805 2806 2807
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
2808
          };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2809 2810 2811

opt_db:
	/* empty */  { $$= 0; }
2812
	| from_or_in ident { $$= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2813 2814 2815

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

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2818 2819
opt_full:
	/* empty */ { Lex->verbose=0; }
2820
	| FULL	    { Lex->verbose=1; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2821

2822 2823
from_or_in:
	FROM
2824
	| IN_SYM;
2825

2826 2827
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
2828
        | IN_SYM TEXT_STRING { Lex->mi.log_file_name = $2.str; };
2829 2830 2831

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


bk@work.mysql.com's avatar
bk@work.mysql.com committed
2835 2836 2837 2838
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
2839 2840 2841 2842
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
2843
	  if (!add_table_to_list($2, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2844 2845 2846
	    YYABORT;
	}
	opt_describe_column
2847
	| describe_command select
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2848
          { Lex->select_lex.options|= SELECT_DESCRIBE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2849 2850 2851 2852


describe_command:
	DESC
2853
	| DESCRIBE;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2854 2855 2856 2857

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
2858 2859
	| ident
 { Lex->wild= new String((const char*) $1.str,$1.length); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2860 2861 2862 2863 2864


/* flush things */

flush:
2865 2866 2867 2868 2869
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
2870
	flush_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2871 2872 2873

flush_options:
	flush_options ',' flush_option
2874
	| flush_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2875 2876

flush_option:
2877
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2878
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2879
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2880 2881 2882 2883
	| 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
2884 2885
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
2886 2887
	| 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
2888

2889
opt_table_list:
2890 2891
	/* empty */  {;}
	| table_list {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2892

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2893
reset:
2894 2895 2896 2897
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
2898
	} reset_options;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2899 2900
reset_options:
	reset_options ',' reset_option
2901
	| reset_option;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2902 2903

reset_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2904 2905
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
2906
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2907

2908
purge:
2909 2910 2911 2912 2913 2914
	PURGE
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_PURGE;
	  lex->type=0;
	}
2915 2916 2917
        MASTER_SYM LOGS_SYM TO_SYM TEXT_STRING
         {
	   Lex->to_log = $6.str;
2918
         } ;
2919

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2920 2921 2922
/* kill threads */

kill:
2923
	KILL_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2924
	{
2925 2926 2927 2928 2929 2930 2931 2932
	  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();
2933
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2934 2935 2936 2937

/* change database */

use:	USE_SYM ident
2938 2939 2940
	{
	  LEX *lex=Lex;
	  lex->sql_command=SQLCOM_CHANGE_DB; lex->select->db= $2.str;
2941
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2942 2943 2944

/* import, export of files */

2945
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2946
	{
2947 2948
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
2949 2950
	  lex->lock_option= $3;
	  lex->local_file=  $4;
2951
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2952
	    YYABORT;
2953
	  lex->field_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2954 2955 2956 2957
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
2958
	  if (!add_table_to_list($11,NULL,1))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2959 2960 2961
	    YYABORT;
	}
        |
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2962
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2963 2964
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
2965
	  if (!add_table_to_list($3,NULL,1))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2966
	    YYABORT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2967 2968

        }
2969 2970 2971 2972
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
2973
        };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2974 2975 2976

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

2979
load_data_lock:
2980 2981 2982
	/* empty */	{ $$= current_thd->update_lock_default; }
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
2983 2984


bk@work.mysql.com's avatar
bk@work.mysql.com committed
2985 2986 2987
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
2988
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2989 2990 2991

opt_field_term:
	/* empty */
2992
	| COLUMNS field_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2993 2994 2995

field_term_list:
	field_term_list field_term
2996
	| field_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2997 2998 2999 3000

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
3001 3002 3003 3004 3005
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3006
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
3007
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3008 3009 3010

opt_line_term:
	/* empty */
3011
	| LINES line_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3012 3013 3014

line_term_list:
	line_term_list line_term
3015
	| line_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3016 3017 3018

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
3019
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3020 3021 3022 3023

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
3024
	  { Lex->exchange->skip_lines=atol($2.str); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3025 3026 3027 3028 3029 3030

/* Common definitions */

text_literal:
	TEXT_STRING { $$ = new Item_string($1.str,$1.length); }
	| text_literal TEXT_STRING
3031
	{ ((Item_string*) $1)->append($2.str,$2.length); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3032 3033 3034 3035 3036 3037 3038

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;
3039
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3040 3041 3042 3043 3044

literal:
	text_literal	{ $$ =	$1; }
	| NUM		{ $$ =	new Item_int($1.str, (longlong) atol($1.str),$1.length); }
	| LONG_NUM	{ $$ =	new Item_int($1.str); }
3045
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3046 3047 3048 3049
	| 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;}
3050
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3051 3052
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
3053
	| TIMESTAMP text_literal { $$ = $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3054 3055 3056 3057 3058 3059 3060

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

insert_ident:
	simple_ident	 { $$=$1; }
3061
	| table_wild	 { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3062 3063 3064 3065

table_wild:
	ident '.' '*' { $$ = new Item_field(NullS,$1.str,"*"); }
	| ident '.' ident '.' '*'
3066 3067
	{ $$ = 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
3068 3069

order_ident:
3070
	expr { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3071 3072 3073

simple_ident:
	ident
3074 3075 3076 3077
	{
	  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
3078
	| ident '.' ident
3079 3080 3081 3082
	{
	  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
3083
	| '.' ident '.' ident
3084 3085 3086 3087
	{
	  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
3088
	| ident '.' ident '.' ident
3089 3090 3091
	{
	  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);
3092
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3093 3094 3095 3096 3097


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
3098
	| '.' ident		{ $$=$2;}	/* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3099 3100 3101 3102

table_ident:
	ident			{ $$=new Table_ident($1); }
	| ident '.' ident	{ $$=new Table_ident($1,$3,0);}
3103 3104
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3105 3106 3107 3108 3109

ident:
	IDENT	    { $$=$1; }
	| keyword
	{
3110 3111
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3112
	  $$.length=$1.length;
3113
	  if (lex->next_state != STATE_END)
3114
	    lex->next_state=STATE_OPERATOR_OR_IDENT;
3115 3116
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3117 3118 3119

ident_or_text:
	ident 		{ $$=$1;}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3120
	| TEXT_STRING	{ $$=$1;}
3121
	| LEX_HOSTNAME	{ $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134

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;
3135
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3136 3137 3138 3139 3140 3141

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
3142
	| AGAINST		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3143
	| AGGREGATE_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3144
	| AUTO_INC		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3145 3146
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
3147
	| BACKUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3148
	| BEGIN_SYM		{}
3149
	| BERKELEY_DB_SYM	{}
3150
	| BINLOG_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3151 3152
	| BIT_SYM		{}
	| BOOL_SYM		{}
3153
	| BOOLEAN_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3154
	| CACHE_SYM		{}
3155
	| CHANGED		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3156 3157
	| CHECKSUM_SYM		{}
	| CHECK_SYM		{}
3158
	| CIPHER_SYM		{}
3159
	| CLIENT_SYM		{}
3160
	| CLOSE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3161
	| COMMENT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3162
	| COMMITTED_SYM		{}
3163
	| COMMIT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3164
	| COMPRESSED_SYM	{}
3165
	| CONCURRENT		{}
3166
	| CUBE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3167 3168 3169 3170 3171
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
3172 3173
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3174
	| DO_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3175 3176 3177 3178 3179
	| DUMPFILE		{}
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
3180
	| EVENTS_SYM		{}
3181
	| EXECUTE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3182
	| EXTENDED_SYM		{}
3183
	| FAST_SYM		{}
3184 3185
        | DISABLE_SYM           {}
        | ENABLE_SYM            {}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3186
	| FULL			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3187 3188 3189 3190 3191
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
	| GRANTS                {}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3192
	| GLOBAL_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3193
	| HEAP_SYM		{}
3194
	| HANDLER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3195 3196 3197
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
3198
	| INDEXES		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3199
	| ISOLATION		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3200
	| ISAM_SYM		{}
3201
	| ISSUER_SYM		{}
3202
	| INNOBASE_SYM		{}
3203
	| INSERT_METHOD		{}
3204
        | IO_THREAD		{}
3205
	| LAST_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3206
	| LEVEL_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3207
	| LOCAL_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3208
	| LOCKS_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3209 3210 3211 3212 3213 3214 3215 3216 3217 3218
	| 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	{}
3219
	| MAX_CONNECTIONS_PER_HOUR       {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3220
	| MAX_QUERIES_PER_HOUR  {}
3221
	| MAX_UPDATES_PER_HOUR  {}
3222
	| MEDIUM_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3223 3224 3225 3226
	| MERGE_SYM		{}
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3227
	| MODE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3228 3229 3230 3231
	| MONTH_SYM		{}
	| MYISAM_SYM		{}
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
3232
	| NEXT_SYM		{}
3233
	| NEW_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3234
	| NO_SYM		{}
3235
	| NONE_SYM		{}
3236
	| OFFSET_SYM		{}
3237
	| OPEN_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3238 3239
	| PACK_KEYS_SYM		{}
	| PASSWORD		{}
3240
	| PREV_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3241 3242
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3243
	| QUERY_SYM		{}
3244
	| QUICK			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3245
	| RAID_0_SYM            {}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3246 3247
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3248
	| RAID_STRIPED_SYM      {}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3249
	| RAID_TYPE		{}
3250 3251
        | RELAY_LOG_FILE_SYM	{}
        | RELAY_LOG_POS_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3252 3253
	| RELOAD		{}
	| REPAIR		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3254
	| REPEATABLE_SYM	{}
3255
	| REPLICATION		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3256
	| RESET_SYM		{}
3257
	| RESOURCES		{}
3258
	| RESTORE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3259
	| ROLLBACK_SYM		{}
3260
	| ROLLUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3261 3262 3263 3264
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
	| SECOND_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3265 3266
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3267
	| SIGNED_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3268
	| SHARE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3269
	| SHUTDOWN		{}
3270
        | SLAVE		        {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3271
	| SQL_CACHE_SYM		{}
3272
	| SQL_BUFFER_RESULT	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3273
	| SQL_NO_CACHE_SYM	{}
3274
        | SQL_THREAD		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3275 3276 3277 3278
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
3279
	| SUBJECT_SYM		{}
3280
	| SUPER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3281 3282
	| TEMPORARY		{}
	| TEXT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3283
	| TRANSACTION_SYM	{}
3284
	| TRUNCATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3285 3286 3287 3288
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3289
	| UNCOMMITTED_SYM	{}
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3290
	| USE_FRM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3291 3292
	| VARIABLES		{}
	| WORK_SYM		{}
3293
	| YEAR_SYM		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3294 3295 3296 3297 3298 3299

/* Option functions */

set:
	SET opt_option
	{
3300 3301
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
3302 3303
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3304
	}
3305
	option_value_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3306 3307 3308

opt_option:
	/* empty */ {}
3309
	| OPTION {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3310 3311

option_value_list:
3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334
	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
3335 3336

option_value:
3337
	'@' ident_or_text equal expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3338
	{
3339
	  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
3340
	}
3341
	| internal_variable_name equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3342
	  {
3343 3344
	    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
3345
	  }
3346
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
3347 3348 3349 3350 3351 3352 3353 3354
	  {
	    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,
3355
						find_sys_var("tx_isolation"),
3356
						new Item_int((int32) $4)));
3357
	  }
3358
	| CHAR_SYM SET opt_equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3359
	{
3360 3361 3362 3363
	  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
3364 3365
	}
	| PASSWORD equal text_or_password
3366
	  {
3367 3368 3369 3370 3371 3372 3373 3374 3375
	    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
3376
	  {
3377 3378
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
3379
	;
3380

3381 3382 3383 3384 3385 3386 3387 3388
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
3389
	;
3390 3391 3392 3393 3394 3395 3396

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
3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409

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;
	    }
3410
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3411

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

3413
set_expr_or_default:
3414 3415 3416
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
	| ON	  { $$=new Item_string("ON",2); }
3417
	| ALL	  { $$=new Item_string("ALL",3); }
3418
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3419 3420


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3421 3422 3423 3424 3425 3426 3427
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
3428
	table_lock_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3429 3430 3431

table_or_tables:
	TABLE_SYM
3432
	| TABLES;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3433 3434 3435

table_lock_list:
	table_lock
3436
	| table_lock_list ',' table_lock;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3437 3438 3439

table_lock:
	table_ident opt_table_alias lock_option
3440
	{ if (!add_table_to_list($1,$2,0,(thr_lock_type) $3)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3441 3442 3443 3444 3445

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

unlock:
3449
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3450 3451


3452
/*
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3453
** Handler: direct access to ISAM functions
3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468
*/

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
3469
	| HANDLER_SYM table_ident READ_SYM
3470
	{
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
3471 3472 3473
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
3474 3475
	  lex->select->select_limit= 1;
	  lex->select->offset_limit= 0L;
3476 3477
	  if (!add_table_to_list($2,0,0))
	    YYABORT;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3478
        }
3479
        handler_read_or_scan where_clause limit_clause { };
3480

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3481 3482
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
3483
        | ident handler_rkey_function { Lex->backup_dir= $1.str; };
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3484 3485 3486

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
3487
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  };
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3488 3489 3490 3491 3492 3493

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;  }
3494 3495
	| handler_rkey_mode
	{
3496 3497
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
3498
	  lex->ha_rkey_mode=$1;
3499
	  if (!(lex->insert_list = new List_item))
3500
	    YYABORT;
3501
	} '(' values ')' { };
3502 3503

handler_rkey_mode:
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
3504 3505 3506 3507
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
3508
	| LT     { $$=HA_READ_BEFORE_KEY;  };
3509

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3510 3511 3512 3513 3514
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
3515 3516 3517 3518 3519 3520
	  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;
3521 3522
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
3523
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3524
	}
3525
	grant_privileges ON opt_table FROM user_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3526 3527 3528 3529

grant:
	GRANT
	{
3530 3531 3532
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
3533 3534 3535 3536 3537
	  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;
3538
	  bzero(&(lex->mqh),sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3539 3540
	}
	grant_privileges ON opt_table TO_SYM user_list
3541
	require_clause grant_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3542 3543 3544

grant_privileges:
	grant_privilege_list {}
3545 3546
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
	| ALL			{ Lex->grant = GLOBAL_ACLS;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3547 3548 3549

grant_privilege_list:
	grant_privilege
3550
	| grant_privilege_list ',' grant_privilege;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3551 3552

grant_privilege:
3553 3554 3555 3556 3557 3558
	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
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3559 3560 3561 3562
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
3563
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3564 3565 3566 3567
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
3568 3569 3570 3571 3572 3573 3574 3575
	| 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
3576

3577

3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619
	{
	  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;
	}
	;
3620
 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3621 3622 3623
opt_table:
	'*'
	  {
3624 3625
	    LEX *lex=Lex;
	    lex->select->db=lex->thd->db;
3626
	    if (lex->grant == GLOBAL_ACLS)
3627 3628
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3629
	    {
3630 3631
	      send_error(&lex->thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
	      YYABORT;
3632
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3633 3634 3635
	  }
	| ident '.' '*'
	  {
3636 3637
	    LEX *lex=Lex;
	    lex->select->db = $1.str;
3638
	    if (lex->grant == GLOBAL_ACLS)
3639 3640
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3641
	    {
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3642
	      send_error(&lex->thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3643 3644 3645 3646 3647
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
3648 3649
	    LEX *lex=Lex;
	    lex->select->db = NULL;
3650 3651
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
3652
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3653
	    {
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3654
	      send_error(&lex->thd->net,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3655 3656 3657 3658 3659
	      YYABORT;
	    }
	  }
	| table_ident
	  {
3660
	    LEX *lex=Lex;
3661
	    if (!add_table_to_list($1,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3662
	      YYABORT;
3663
	    if (lex->grant == GLOBAL_ACLS)
3664
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
3665
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3666 3667 3668


user_list:
3669 3670 3671 3672 3673 3674 3675
	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
3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695


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
3696
	  { $$=$1; $1->password.str=NullS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3697 3698 3699


opt_column_list:
3700 3701 3702 3703 3704
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
3705
	| '(' column_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3706 3707 3708

column_list:
	column_list ',' column_list_id
3709
	| column_list_id;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3710 3711 3712 3713 3714 3715 3716

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;
3717
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3718 3719 3720 3721 3722
	  while ((point=iter++))
	  {
	    if (!my_strcasecmp(point->column.ptr(),new_str->ptr()))
		break;
	  }
3723
	  lex->grant_tot_col|= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3724
	  if (point)
3725
	    point->rights |= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3726
	  else
3727
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
3728
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3729

tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
3730 3731

require_clause: /* empty */
3732
        | REQUIRE_SYM require_list 
3733 3734 3735
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
3736
        | REQUIRE_SYM SSL_SYM
3737 3738 3739
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
3740
        | REQUIRE_SYM X509_SYM
3741 3742 3743 3744 3745 3746 3747
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
3748
	;
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
3749

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3750
grant_options:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3751
	/* empty */ {}
3752
	| WITH grant_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3753

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3754 3755
grant_option_list:
	grant_option_list grant_option {}
3756
	| grant_option {};
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3757 3758 3759

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
3760
        | MAX_QUERIES_PER_HOUR ULONG_NUM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3761
        {
3762
	  Lex->mqh.questions=$2;
3763
	  Lex->mqh.bits |= 1;
3764
	}
3765
        | MAX_UPDATES_PER_HOUR ULONG_NUM
3766
        {
3767
	  Lex->mqh.updates=$2;
3768
	  Lex->mqh.bits |= 2;
3769
	}
3770
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
3771
        {
3772
	  Lex->mqh.connections=$2;
3773
	  Lex->mqh.bits |= 4;
3774
	};
3775

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3776
begin:
3777
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3778 3779 3780

opt_work:
	/* empty */ {}
3781
	| WORK_SYM {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3782 3783

commit:
3784
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3785 3786

rollback:
3787
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
3788 3789 3790 3791 3792 3793 3794


/*
** UNIONS : glue selects together
*/


serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3795
opt_union:	
3796 3797
	/* empty */ {}
	| union_list;
3798 3799

union_list:
3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819
	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;
	} 
	select_init
	;
3820 3821

union_opt:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3822
	union_list {}
3823
	| optional_order_or_limit {};
3824 3825

optional_order_or_limit:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3826 3827 3828 3829
      	/* empty 
           intentional reduce/reduce conflict here !!!
           { code } below should not be executed
           when neither ORDER BY nor LIMIT are used */ {}
3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845
	|
	  {
    	    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
	;
3846 3847

union_option:
3848 3849 3850
	/* empty */ {}
	| ALL { Lex->union_option=1; }
	;