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

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

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

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

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

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

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
41
extern void yyerror(const char*);
42
int yylex(void *yylval, void *yythd);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
43

44
#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
45

46
inline Item *or_or_concat(THD *thd, Item* A, Item* B)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
47
{
48
  return (thd->variables.sql_mode & MODE_PIPES_AS_CONCAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
49 50 51 52 53 54 55
          (Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B));
}

%}
%union {
  int  num;
  ulong ulong_num;
56
  ulonglong ulonglong_number;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
57 58 59 60 61 62 63 64
  LEX_STRING lex_str;
  LEX_STRING *lex_str_ptr;
  LEX_SYMBOL symbol;
  Table_ident *table;
  char *simple_string;
  Item *item;
  List<Item> *item_list;
  List<String> *string_list;
65 66 67 68 69 70
  String *string;
  key_part_spec *key_part;
  TABLE_LIST *table_list;
  udf_func *udf;
  LEX_USER *lex_user;
  sys_var *variable;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
71
  Key::Keytype key_type;
72
  enum ha_key_alg  key_alg;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
73 74
  enum db_type db_type;
  enum row_type row_type;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
75
  enum ha_rkey_function ha_rkey_mode;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
76
  enum enum_tx_isolation tx_isolation;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
77
  enum Item_cast cast_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
78
  enum Item_udftype udf_type;
79
  CHARSET_INFO *charset;
80
  thr_lock_type lock_type;
81
  interval_type interval;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
82
  st_select_lex *select_lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
83
  chooser_compare_func_creator boolfunc2creator;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
84 85 86 87 88 89 90 91 92 93
}

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

%pure_parser					/* We have threads */

%token	END_OF_INPUT

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

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

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

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

388 389 390
%token  ERRORS
%token  WARNINGS

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
391
%token	ASCII_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
392 393 394
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
395
%token	CHANGED
bk@work.mysql.com's avatar
bk@work.mysql.com committed
396 397 398 399 400 401
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
402
%token	FAST_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
403
%token	FLOAT_SYM
404
%token  GEOMETRY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
405 406 407 408 409 410 411 412 413
%token	INT_SYM
%token	LIMIT
%token	LONGBLOB
%token	LONGTEXT
%token	MEDIUMBLOB
%token	MEDIUMINT
%token	MEDIUMTEXT
%token	NUMERIC_SYM
%token	PRECISION
414
%token	QUICK
bk@work.mysql.com's avatar
bk@work.mysql.com committed
415
%token	REAL
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
416
%token	SIGNED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
417 418 419 420 421 422 423 424
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
425
%token	ULONGLONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
426
%token	UNSIGNED
427 428 429
%token	VARBINARY
%token	VARCHAR
%token	VARYING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
430 431
%token	ZEROFILL

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

529 530 531 532
%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
533
%token	SQL_SMALL_RESULT
534
%token  SQL_BUFFER_RESULT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
535

536 537
%token  ISSUER_SYM
%token  SUBJECT_SYM
538
%token  CIPHER_SYM
539

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
563 564
%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
565
	ULONGLONG_NUM field_ident select_alias ident ident_or_text
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
566
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_db
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
567
	NCHAR_STRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
568 569 570 571 572

%type <lex_str_ptr>
	opt_table_alias

%type <table>
573
	table_ident references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
574 575

%type <simple_string>
576
	remember_name remember_end opt_ident opt_db text_or_password
bk@work.mysql.com's avatar
bk@work.mysql.com committed
577 578 579
	opt_escape

%type <string>
580
	text_string opt_gconcat_separator
bk@work.mysql.com's avatar
bk@work.mysql.com committed
581 582

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

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

591 592
%type <ulonglong_number>
	ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
593

594 595 596
%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
597
%type <item>
598
	literal text_literal insert_ident order_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
599 600
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
	table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
601
	using_list expr_or_default set_expr_or_default interval_expr
602
	param_marker singlerow_subselect singlerow_subselect_init
603
	exists_subselect exists_subselect_init
bk@work.mysql.com's avatar
bk@work.mysql.com committed
604 605

%type <item_list>
606
	expr_list udf_expr_list when_list ident_list ident_list_arg
bk@work.mysql.com's avatar
bk@work.mysql.com committed
607 608

%type <key_type>
609
	key_type opt_unique_or_fulltext
bk@work.mysql.com's avatar
bk@work.mysql.com committed
610

611 612 613
%type <key_alg>
	key_alg opt_btree_or_rtree

bk@work.mysql.com's avatar
bk@work.mysql.com committed
614 615 616 617 618 619 620
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
621
	join_table_list  join_table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
622 623 624 625 626 627 628 629 630 631 632

%type <udf>
	UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
	UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM

%type <interval> interval

%type <db_type> table_types

%type <row_type> row_types

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

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

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
637 638
%type <cast_type> cast_type

bk@work.mysql.com's avatar
bk@work.mysql.com committed
639 640 641 642 643 644
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

645
%type <charset>
646
	opt_collate
647 648
	charset_name
	charset_name_or_default
649 650
	collation_name
	collation_name_or_default
651

652 653
%type <variable> internal_variable_name

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
654 655
%type <select_lex> in_subselect in_subselect_init

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
656 657
%type <boolfunc2creator> comp_op

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

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
691 692
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
693 694 695 696 697
%%


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

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

753 754
/* help */

755
help:
756
       HELP_SYM ident_or_text
757
       {
758 759 760
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
761
       };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
762 763 764 765

/* change master */

change:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
766
       CHANGE MASTER_SYM TO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
767 768 769
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
770
	  bzero((char*) &lex->mi, sizeof(lex->mi));
771 772 773 774
        }
       master_defs
	{}
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
775 776 777

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

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

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
828 829 830 831 832
/* create a table */

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

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

create2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
902
	'(' field_list ')' opt_create_table_options create3 {}
903
	| opt_create_table_options create3 {}
venu@myvenu.com's avatar
venu@myvenu.com committed
904 905 906 907 908 909 910
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
  	  ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
911 912

create3:
913 914
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
915
          {
916 917 918
	    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
919
          }
920
          select_options select_item_list opt_select_from union_clause {}
921
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
922

923 924
opt_as:
	/* empty */ {}
925
	| AS	    {};
926

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

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
942
opt_table_options:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
943
	/* empty */	 { $$= 0; }
944
	| table_options  { $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
945 946 947

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
950
table_option:
951
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
952 953

opt_if_not_exists:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
954
	/* empty */	 { $$= 0; }
955
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
956 957 958

opt_create_table_options:
	/* empty */
959
	| create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
960

961 962 963 964
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
965 966
create_table_options:
	create_table_option
967
	| create_table_option     create_table_options
968
	| create_table_option ',' create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
969 970

create_table_option:
971 972 973 974
	TYPE_SYM opt_equal table_types          { Lex->create_info.db_type= $3; }
	| MAX_ROWS opt_equal ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS opt_equal ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH opt_equal ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
975 976
	| PASSWORD opt_equal TEXT_STRING_sys	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM opt_equal TEXT_STRING_sys	{ Lex->create_info.comment=$3.str; }
977 978 979 980 981 982 983 984 985 986
	| AUTO_INC opt_equal ulonglong_num	{ Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;}
	| PACK_KEYS_SYM opt_equal ULONG_NUM	{ Lex->create_info.table_options|= $3 ? HA_OPTION_PACK_KEYS : HA_OPTION_NO_PACK_KEYS; Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;}
	| PACK_KEYS_SYM opt_equal DEFAULT	{ Lex->create_info.table_options&= ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS); Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;}
	| CHECKSUM_SYM opt_equal ULONG_NUM	{ Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; }
	| DELAY_KEY_WRITE_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; }
	| ROW_FORMAT_SYM opt_equal row_types	{ Lex->create_info.row_type= $3; }
	| RAID_TYPE opt_equal raid_types	{ Lex->create_info.raid_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKS opt_equal ULONG_NUM	{ Lex->create_info.raid_chunks= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKSIZE opt_equal ULONG_NUM	{ Lex->create_info.raid_chunksize= $3*RAID_BLOCK_SIZE; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| UNION_SYM opt_equal '(' table_list ')'
987 988 989
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
990 991
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
992 993
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
994 995
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
996
	    table_list->next=0;
997
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
998
	  }
999
	| opt_default charset opt_equal charset_name_or_default
1000
	  {
1001 1002 1003
	    Lex->create_info.table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1004 1005 1006 1007 1008
	| COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1009
	| INSERT_METHOD opt_equal merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1010 1011 1012
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
	  { Lex->create_info.data_file_name= $4.str; }
	| INDEX DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1013 1014 1015 1016 1017 1018

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
1019
	| MEMORY_SYM	{ $$= DB_TYPE_HEAP; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1020
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
1021
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1022 1023 1024 1025 1026

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
1027
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1028 1029 1030 1031

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

1034 1035 1036
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
1037
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1038

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1039
opt_select_from:
1040
	opt_limit_clause {}
1041
	| FROM DUAL_SYM {}
1042
	| select_from select_lock_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1043 1044 1045

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
1046
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1047 1048 1049 1050

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
1051
	| INT_SYM {$$ = (int) INT_RESULT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1052 1053 1054

field_list:
	  field_list_item
1055
	| field_list ',' field_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1056 1057 1058


field_list_item:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1059
	   column_def
1060 1061 1062 1063
         | key_def
         ;

column_def:
1064
	  field_spec check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1065 1066 1067 1068
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1069
	;
1070 1071

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

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1099 1100 1101

opt_constraint:
	/* empty */
1102
	| CONSTRAINT opt_ident;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1103 1104 1105 1106

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

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

char:
	CHAR_SYM {}
1236 1237 1238 1239 1240 1241
	;

nchar:
	NCHAR_SYM {}
	| NATIONAL_SYM CHAR_SYM {}
	;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1242

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1243 1244 1245
varchar:
	char VARYING {}
	| VARCHAR {}
1246 1247 1248 1249 1250 1251 1252 1253
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1254 1255 1256 1257 1258 1259

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

real_type:
1263
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1264 1265
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
1266
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1267 1268 1269 1270 1271


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
1272
	| precision		{};
1273 1274 1275 1276 1277 1278

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

field_options:
	/* empty */		{}
1283
	| field_opt_list	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1284 1285 1286

field_opt_list:
	field_opt_list field_option {}
1287
	| field_option {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1288 1289

field_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1290
	SIGNED_SYM	{}
1291
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
1292
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1293 1294

opt_len:
1295 1296
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1297 1298 1299

opt_precision:
	/* empty */	{}
1300
	| precision	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1301 1302 1303

opt_attribute:
	/* empty */ {}
1304
	| opt_attribute_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1305 1306 1307

opt_attribute_list:
	opt_attribute_list attribute {}
1308
	| attribute;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1309 1310 1311 1312 1313 1314

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; }
1315
	| SERIAL_SYM DEFAULT VALUE_SYM
1316 1317
	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; }
	| opt_primary KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1318
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1319
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
1320
	| COMMENT_SYM text_literal { Lex->comment= $2; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1321 1322
	| COLLATE_SYM collation_name 
	  { 
1323
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $2->name,Lex->charset->csname);
	      YYABORT;
	    }
	    else
	    {
	      Lex->charset=$2;
	    }
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1335

1336 1337 1338 1339
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
1340

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

1353 1354 1355
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1356

1357
collation_name:
1358
	ident_or_text
1359 1360 1361 1362 1363 1364 1365 1366
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	};

1367 1368 1369 1370 1371
opt_collate:
	/* empty */	{ $$=NULL; }
	| COLLATE_SYM collation_name { $$=$2; }
	;

1372 1373 1374 1375
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1376 1377 1378 1379
opt_default:
	/* empty */	{}
	| DEFAULT	{};

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1380
opt_binary:
1381
	/* empty */			{ Lex->charset=NULL; }
1382 1383 1384
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
	| BINARY			{ Lex->charset=&my_charset_bin; }
1385 1386 1387 1388 1389 1390 1391 1392
	| UNICODE_SYM
	{
	  if (!(Lex->charset=get_charset_by_name("ucs2",MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1393
	| charset charset_name	{ Lex->charset=$2; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1394

1395 1396 1397
opt_primary:
	/* empty */
	| PRIMARY_SYM
1398
	;
1399

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1400
references:
1401 1402
	REFERENCES table_ident
	{
1403
	  LEX *lex=Lex;
1404 1405 1406 1407 1408 1409
	  lex->fk_delete_opt= lex->fk_update_opt= lex->fk_match_option= 0;
	  lex->ref_list.empty();
	}
	opt_ref_list
	{
	  $$=$2;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1410
	};
1411

1412
opt_ref_list:
1413
	/* empty */ opt_on_delete {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1414
	| '(' ref_list ')' opt_on_delete {};
1415 1416 1417

ref_list:
	ref_list ',' ident	{ Lex->ref_list.push_back(new key_part_spec($3.str)); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1418
	| ident			{ Lex->ref_list.push_back(new key_part_spec($1.str)); };
1419

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1420 1421 1422

opt_on_delete:
	/* empty */ {}
1423
	| opt_on_delete_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1424 1425 1426

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
1427
	| opt_on_delete_item {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1428 1429

opt_on_delete_item:
1430 1431 1432 1433
	ON DELETE_SYM delete_option   { Lex->fk_delete_opt= $3; }
	| ON UPDATE_SYM delete_option { Lex->fk_update_opt= $3; }
	| MATCH FULL	{ Lex->fk_match_option= foreign_key::FK_MATCH_FULL; }
	| MATCH PARTIAL { Lex->fk_match_option= foreign_key::FK_MATCH_PARTIAL; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1434
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1435 1436

delete_option:
1437 1438 1439 1440
	RESTRICT	 { $$= (int) foreign_key::FK_OPTION_RESTRICT; }
	| CASCADE	 { $$= (int) foreign_key::FK_OPTION_CASCADE; }
	| SET NULL_SYM   { $$= (int) foreign_key::FK_OPTION_SET_NULL; }
	| NO_SYM ACTION  { $$= (int) foreign_key::FK_OPTION_NO_ACTION; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1441
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1442 1443 1444 1445

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1446 1447
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
1448 1449
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1450
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
1451
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1452 1453 1454

key_or_index:
	KEY_SYM {}
1455
	| INDEX {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1456 1457 1458 1459

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

1462
opt_unique_or_fulltext:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1463 1464
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1465
	| SPATIAL_SYM	{ $$= Key::SPATIAL; };
1466 1467

key_alg:
1468
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1469
	| USING opt_btree_or_rtree { $$= $2; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1470
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
1471 1472 1473 1474

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
	| RTREE_SYM	{ $$= HA_KEY_ALG_RTREE; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1475
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1476 1477 1478

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
1479
	| key_part order_dir		{ Lex->col_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1480 1481 1482

key_part:
	ident			{ $$=new key_part_spec($1.str); }
1483
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1484 1485 1486

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
1487
	| field_ident	{ $$=$1.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1488 1489 1490

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
1491
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1492 1493 1494 1495 1496 1497 1498 1499

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1500
	  THD *thd= YYTHD;
1501
	  LEX *lex=&thd->lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1502 1503
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1504 1505
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1506 1507 1508 1509 1510 1511 1512
	    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();
1513
          lex->select_lex.init_order();
1514
	  lex->select_lex.db=lex->name=0;
1515
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1516
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1517
	  lex->create_info.table_charset= thd->db_charset;
1518
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1519 1520
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1521
	}
1522 1523
	alter_list
	{}
1524
	| ALTER DATABASE ident opt_create_database_options
1525 1526 1527 1528
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1529
	  };
1530 1531


bk@work.mysql.com's avatar
bk@work.mysql.com committed
1532
alter_list:
1533
        | alter_list_item
1534
	| alter_list ',' alter_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1535 1536

add_column:
1537
	ADD opt_column { Lex->change=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1538 1539

alter_list_item:
1540 1541
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1542
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
1543 1544 1545 1546 1547
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1548
          field_spec opt_place
1549 1550 1551 1552 1553
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
            lex->length=lex->dec=0; lex->type=0; lex->interval=0;
            lex->default_value=lex->comment=0;
1554
            lex->simple_alter=0;
1555 1556 1557 1558
          }
          type opt_attribute
          {
            LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1559
            if (add_field_to_list(lex->thd,$3.str,
1560 1561 1562
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
1563 1564
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
1565 1566 1567
	       YYABORT;
          }
          opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1568
	| DROP opt_column field_ident opt_restrict
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
	  {
	    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;
	  }
1579
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1580
	| DROP key_or_index field_ident
1581 1582 1583 1584 1585 1586
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1587 1588
	| 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
1589
	| ALTER opt_column field_ident SET DEFAULT literal
1590 1591 1592 1593 1594
	  {
	    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
1595
	| ALTER opt_column field_ident DROP DEFAULT
1596 1597 1598 1599 1600
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1601
	| RENAME opt_to table_ident
1602
	  {
1603
	    LEX *lex=Lex;
1604
	    lex->select_lex.db=$3->db.str;
1605
	    lex->name= $3->table.str;
1606
	  }
1607
        | create_table_options_space_separated { Lex->simple_alter=0; }
1608
	| order_clause         { Lex->simple_alter=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1609 1610 1611

opt_column:
	/* empty */	{}
1612
	| COLUMN_SYM	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1613 1614 1615

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
1616
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1617 1618 1619 1620

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
1621
	| CASCADE	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1622 1623 1624 1625

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
1626
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1627 1628 1629 1630

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1631
	| EQ		{}
1632
	| AS		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1633

nick@mysql.com's avatar
nick@mysql.com committed
1634
/*
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1635 1636 1637
  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
1638
slave:
1639
	START_SYM SLAVE slave_thread_opts
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
        {
	  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;
          }
	;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1652

1653 1654 1655 1656 1657
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

1658
slave_thread_opts:
1659 1660
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1661
	;
1662 1663

slave_thread_opt_list:
1664
	slave_thread_opt
1665 1666
	| slave_thread_opt_list ',' slave_thread_opt
	;
1667 1668

slave_thread_opt:
1669
	/*empty*/	{}
1670 1671 1672
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
	| IO_THREAD   	{ Lex->slave_thd_opt|=SLAVE_IO; }
	;
1673

1674 1675 1676 1677 1678
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1679
	table_list FROM TEXT_STRING_sys
1680 1681
        {
	  Lex->backup_dir = $6.str;
1682
        };
1683

1684 1685 1686 1687 1688
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1689
	table_list TO_SYM TEXT_STRING_sys
1690 1691
        {
	  Lex->backup_dir = $6.str;
1692
        };
1693

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1694 1695 1696
repair:
	REPAIR table_or_tables
	{
1697 1698 1699
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1700
	}
1701 1702 1703
	table_list opt_mi_repair_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1704

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1705
opt_mi_repair_type:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1706
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1707
	| mi_repair_types {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1708

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1709 1710
mi_repair_types:
	mi_repair_type {}
1711
	| mi_repair_type mi_repair_types {};
1712

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1713
mi_repair_type:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1714
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1715
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
1716
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1717 1718

analyze:
1719
	ANALYZE_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1720
	{
1721 1722 1723
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1724
	}
1725 1726 1727
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1728 1729

check:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1730
	CHECK_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1731
	{
1732 1733 1734
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1735
	}
1736 1737 1738
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1739

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1740 1741
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1742
	| mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1743 1744 1745

mi_check_types:
	mi_check_type {}
1746
	| mi_check_type mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1747 1748 1749 1750 1751 1752

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1755
optimize:
1756
	OPTIMIZE table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1757
	{
1758 1759 1760
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1761
	}
1762 1763 1764
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1765

1766 1767 1768 1769 1770
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1771 1772 1773
	table_to_table_list
	{}
	;
1774 1775 1776

table_to_table_list:
	table_to_table
1777
	| table_to_table_list ',' table_to_table;
1778 1779 1780

table_to_table:
	table_ident TO_SYM table_ident
1781
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1782 1783
	  LEX *lex=Lex;	  
	  SELECT_LEX_NODE *sl= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1784 1785 1786 1787
	  if (!sl->add_table_to_list(lex->thd, $1,NULL,TL_OPTION_UPDATING,
				     TL_IGNORE) ||
	      !sl->add_table_to_list(lex->thd, $3,NULL,TL_OPTION_UPDATING,
				     TL_IGNORE))
1788
	    YYABORT;
1789
	};
1790

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1791
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1792
  Select : retrieve data from table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1793 1794 1795 1796
*/


select:
1797
	select_init { Lex->sql_command=SQLCOM_SELECT; };
1798

1799
/* Need select_init2 for subselects. */
1800
select_init:
1801
	SELECT_SYM select_init2
1802
	|
1803 1804
	'(' SELECT_SYM select_part2 ')'
	  {
1805
	    LEX *lex= Lex;
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1806
            SELECT_LEX * sel= lex->current_select->select_lex();
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1807
	    if (sel->set_braces(1))
1808 1809 1810 1811
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
1812 1813
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1814 1815 1816 1817
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1818
            /* select in braces, can't contain global parameters */
1819
            sel->master_unit()->global_parameters=
1820
               sel->master_unit();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1821
          } union_opt;
1822

1823 1824
select_init2:
	select_part2
1825
        {
1826
	  LEX *lex= Lex;
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1827
          SELECT_LEX * sel= lex->current_select->select_lex();
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1828
          if (lex->current_select->set_braces(0))
1829 1830 1831 1832
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1833 1834
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1835 1836 1837 1838
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1839
	}
1840
	union_clause
1841 1842
	;

1843
select_part2:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1844 1845
	{
	  LEX *lex=Lex;
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1846
	  SELECT_LEX * sel= lex->current_select->select_lex();
1847
	  if (lex->current_select == &lex->select_lex)
1848
	    lex->lock_option= TL_READ; /* Only for global SELECT */
1849 1850
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1851
	}
1852
	select_options select_item_list select_into select_lock_type;
1853

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1854
select_into:
1855 1856 1857 1858 1859 1860
	opt_limit_clause {}
	| FROM DUAL_SYM /* oracle compatibility: oracle always requires FROM
                           clause, and DUAL is system table without fields.
                           Is "SELECT 1 FROM DUAL" any better than
                           "SELECT 1" ? Hmmm :) */
        | into
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1861
	| select_from
1862 1863
	| into select_from
	| select_from into;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1864 1865

select_from:
1866
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1867 1868 1869

select_options:
	/* empty*/
1870
	| select_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1871 1872 1873

select_option_list:
	select_option_list select_option
1874
	| select_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1875 1876

select_option:
1877
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1878 1879 1880 1881 1882 1883
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1884 1885 1886
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
	| 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;
	  }
1899
	| SQL_NO_CACHE_SYM { Lex->uncacheable(); }
1900 1901 1902
	| SQL_CACHE_SYM    { Select->options|= OPTION_TO_QUERY_CACHE; }
	| ALL		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1903

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1904 1905 1906
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1907 1908
	  {
	    LEX *lex=Lex;
1909
	    lex->current_select->set_lock_for_tables(TL_WRITE);
1910
	    lex->safe_to_cache_query=0;
1911
	  }
1912
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1913 1914
	  {
	    LEX *lex=Lex;
1915 1916
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
1917
	    lex->safe_to_cache_query=0;
1918 1919
	  }
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1920

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1921 1922 1923 1924 1925
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
1926 1927
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1928
	      YYABORT;
1929
	    (thd->lex.current_select->select_lex()->with_wild)++;
1930
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1931 1932 1933 1934 1935


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1936
	    if (add_item_to_list(YYTHD, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1937 1938
	      YYABORT;
	    if ($4.str)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1939
	      $2->set_name($4.str,$4.length,system_charset_info);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1940
	    else if (!$2->name)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1941
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
1942
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1943 1944

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

remember_end:
1948
	{ $$=(char*) Lex->tok_end; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1949 1950 1951

select_item2:
	table_wild	{ $$=$1; } /* table.* */
1952
	| expr		{ $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1953 1954

select_alias:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1955 1956 1957 1958 1959 1960
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1961 1962 1963

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1966
/* all possible expressions */
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1967 1968 1969 1970
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1971

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
comp_op:  EQ		{ $$ = &comp_eq_creator; }
	| GE		{ $$ = &comp_ge_creator; }
	| GT_SYM	{ $$ = &comp_gt_creator; }
	| LE		{ $$ = &comp_le_creator; }
	| LT		{ $$ = &comp_lt_creator; }
	| NE		{ $$ = &comp_ne_creator; }
	;

all_or_any: ALL     { $$ = 1; }
        |   ANY_SYM { $$ = 0; }
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1984 1985
/* expressions that begin with 'expr' */
expr_expr:
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1986
	 expr IN_SYM '(' expr_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1987 1988 1989
	  { $$= new Item_func_in($1,*$4); }
	| expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1990
        | expr IN_SYM in_subselect
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1991
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1992
	| expr NOT IN_SYM in_subselect
1993
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1994
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1995
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1996 1997 1998 1999
	| 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)); }
2000
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2001
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
2002
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2003
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
2004
	| expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2005 2006 2007 2008 2009 2010 2011
	| expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
	| expr NOT LIKE simple_expr opt_escape	{ $$= new Item_func_not(new Item_func_like($1,$4,$5));}
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2012 2013 2014
	| expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| expr comp_op all_or_any in_subselect %prec EQ
	{
2015
	  Item_allany_subselect *it=
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2016
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2017 2018 2019 2020 2021
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2022 2023 2024 2025 2026 2027
	| 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); }
2028 2029
	| expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
	| expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2030
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2031
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2032 2033
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2034 2035 2036 2037
	| expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2038
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2039 2040 2041 2042 2043 2044 2045

/* 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)); }
2046
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2047
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
2048
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2049
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
2050
	| no_in_expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2051 2052 2053 2054 2055 2056 2057
	| no_in_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
	| no_in_expr NOT LIKE simple_expr opt_escape { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| no_in_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| no_in_expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| no_in_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| no_in_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2058 2059 2060
	| no_in_expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
2061
	  Item_allany_subselect *it=
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2062
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2063 2064 2065 2066 2067
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2068 2069 2070 2071 2072 2073
	| 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); }
2074
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2075
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2076
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2077 2078
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2079
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2080 2081 2082 2083
	| no_in_expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| no_in_expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
2084
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2085 2086 2087

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2088 2089
	  no_and_expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2090 2091
	| no_and_expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2092
        | no_and_expr IN_SYM in_subselect
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2093
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2094
	| no_and_expr NOT IN_SYM in_subselect
2095
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2096
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2097
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2098 2099 2100 2101
	| 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)); }
2102
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2103
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
2104
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
2105
	| no_and_expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2106 2107 2108 2109 2110 2111 2112
	| no_and_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
	| no_and_expr NOT LIKE simple_expr opt_escape	{ $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| no_and_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| no_and_expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| no_and_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| no_and_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2113 2114 2115
	| no_and_expr comp_op expr %prec EQ { $$= (*((*$2)(0)))($1,$3); }
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
2116
	  Item_allany_subselect *it=
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2117
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2118 2119 2120 2121 2122
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2123 2124 2125 2126 2127 2128
	| 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); }
2129
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2130
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2131
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2132 2133
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2134
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2135 2136 2137 2138
	| no_and_expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| no_and_expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
2139
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2140

2141
interval_expr:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2142
         INTERVAL_SYM expr { $$=$2; }
2143 2144
        ;

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

udf_expr_list:
	/* empty */	{ $$= NULL; }
2533
	| expr_list	{ $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2534 2535 2536 2537 2538 2539 2540 2541

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); }
2542
	| COUNT_SYM '(' opt_all '*' ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555
	  { $$=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); }
2556 2557
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2558
	| SUM_SYM '(' in_sum_expr ')'
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587
	  { $$=new Item_sum_sum($3); }
	| GROUP_CONCAT_SYM '(' opt_distinct expr_list opt_gorder_clause opt_gconcat_separator ')'
	  { 
	    $$=new Item_func_group_concat($3,$4,Lex->gorder_list,$6); 
	    $4->empty();
	  };

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

opt_gconcat_separator:
    /* empty */        { $$ = new String(" ",1,default_charset_info); }
    |SEPARATOR_SYM text_string  { $$ = $2; };
   

opt_gorder_clause:
    /* empty */ 
      {
        LEX *lex=Lex;
        lex->gorder_list = NULL;
      }
    | order_clause
      {
        LEX *lex=Lex;
        lex->gorder_list= (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,sizeof(st_sql_list));
        lex->current_select->order_list.empty();
      };
	  
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2588 2589

in_sum_expr:
2590
	opt_all
2591 2592 2593 2594 2595
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
2596
	    YYABORT;
2597 2598
	  }
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2599 2600
	expr
	{
2601
	  Select->select_lex()->in_sum_expr--;
2602
	  $$= $3;
2603
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2604

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2605
cast_type:
2606
	BINARY			{ $$=ITEM_CAST_BINARY; }
2607
	| CHAR_SYM		{ $$=ITEM_CAST_CHAR; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2608 2609 2610 2611 2612 2613
	| 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; }
2614 2615
	| DATETIME		{ $$=ITEM_CAST_DATETIME; }
	;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2616

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2617
expr_list:
2618
	{ Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2619
	expr_list2
2620
	{ $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2621 2622

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

2626 2627
ident_list_arg:
          ident_list          { $$= $1; }
2628
        | '(' ident_list ')'  { $$= $2; };
2629

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2630
ident_list:
2631
        { Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2632
        ident_list2
2633
        { $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2634 2635

ident_list2:
2636
        simple_ident { Select->expr_list.head()->push_back($1); }
2637
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2638 2639 2640

opt_expr:
	/* empty */      { $$= NULL; }
2641
	| expr         	 { $$= $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2642 2643 2644

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

when_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2648
        { Select->when_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2649
	when_list2
2650
	{ $$= Select->when_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2651 2652

when_list2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2653
	expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2654
	  {
2655
	    SELECT_LEX_NODE *sel=Select;
2656 2657
	    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
2658
	}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2659
	| when_list2 WHEN_SYM expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2660
	  {
2661
	    SELECT_LEX_NODE *sel=Select;
2662 2663
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
2664
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2665 2666

opt_pad:
2667
	/* empty */ { $$=new Item_string(" ",1,default_charset_info); }
2668
	| expr	    { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2669 2670 2671 2672

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
2673
	| join_table_list ',' join_table_list { $$=$3; }
2674
	| join_table_list normal_join join_table_list { $$=$3; }
2675 2676
	| join_table_list STRAIGHT_JOIN join_table_list
	  { $$=$3 ; $$->straight=1; }
2677 2678 2679 2680
	| join_table_list normal_join join_table_list ON expr
	  { add_join_on($3,$5); $$=$3; }
	| join_table_list normal_join join_table_list
	  USING 
2681
	  {
2682
	    SELECT_LEX *sel= Select->select_lex();
2683
	    sel->db1=$1->db; sel->table1=$1->alias;
2684
	    sel->db2=$3->db; sel->table2=$3->alias;
2685
	  }
2686 2687 2688
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

2689
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2690
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2691
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
2692
	  {
2693
	    SELECT_LEX *sel= Select->select_lex();
2694 2695
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2696
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2697
	  USING '(' using_list ')'
2698
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2699
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2700
	  { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
2701
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2702
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2703
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
2704
	  {
2705
	    SELECT_LEX *sel= Select->select_lex();
2706 2707
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2708
	  }
2709 2710
	  USING '(' using_list ')'
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2711
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2712
	  { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2713
	| join_table_list NATURAL JOIN_SYM join_table_list
2714
	  { add_join_natural($1,$4); $$=$4; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2715 2716

normal_join:
2717 2718 2719 2720
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2721 2722

join_table:
2723
	{
2724
	  SELECT_LEX *sel= Select->select_lex();
2725
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2726
	  sel->table_join_options= 0;
2727
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2728
        table_ident opt_table_alias opt_key_definition
2729
	{
2730 2731
	  LEX *lex= Lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2732
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2733
					   sel->get_table_join_options(),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2734
					   lex->lock_option,
2735 2736
					   sel->get_use_index(),
					   sel->get_ignore_index())))
2737
	    YYABORT;
2738
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2739
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2740
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
2741
        | '(' SELECT_SYM select_derived ')' opt_table_alias
2742 2743
	{
	  LEX *lex=Lex;
2744 2745 2746
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2747
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
2748
				  TL_READ,(List<String> *)0,
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2749 2750
	                          (List<String> *)0)))

2751
	    YYABORT;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2752
	};
2753

2754
select_derived:
2755
        {
2756
	  LEX *lex= Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2757
	  lex->derived_tables= 1;
2758 2759 2760 2761 2762 2763
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN && 
	       lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)
	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
2764
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
2765
              mysql_new_select(lex, 1))
2766 2767
	    YYABORT;
	  mysql_init_select(lex);
2768
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
2769
	}
2770
        select_options select_item_list opt_select_from union_opt
2771
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2772 2773 2774

opt_outer:
	/* empty */	{}
2775
	| OUTER		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2776 2777 2778 2779

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
2780
          {
2781
	    SELECT_LEX *sel= Select->select_lex();
2782 2783 2784
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2785 2786 2787 2788 2789 2790 2791
	| FORCE_SYM key_usage_list
          {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2792
	| IGNORE_SYM key_usage_list
2793
	  {
2794
	    SELECT_LEX *sel= Select->select_lex();
2795 2796
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
2797
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2798 2799

key_usage_list:
2800
	key_or_index { Select->select_lex()->interval_list.empty(); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2801 2802 2803 2804 2805 2806 2807 2808
        '(' key_list_or_empty ')'
        { $$= &Select->select_lex()->interval_list; }
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2809 2810 2811

key_usage_list2:
	key_usage_list2 ',' ident
2812
        { Select->select_lex()->
2813 2814
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
				    default_charset_info)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2815
	| ident
2816
        { Select->select_lex()->
2817 2818
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
				    default_charset_info)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2819
	| PRIMARY_SYM
2820
        { Select->select_lex()->
2821 2822
	    interval_list.push_back(new String("PRIMARY", 7,
				    default_charset_info)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2823 2824 2825

using_list:
	ident
2826
	  {
2827
	    SELECT_LEX *sel= Select->select_lex();
2828 2829 2830 2831
	    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
2832 2833 2834 2835
	      YYABORT;
	  }
	| using_list ',' ident
	  {
2836
	    SELECT_LEX *sel= Select->select_lex();
2837
	    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
2838
	      YYABORT;
2839
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853

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; }
2854
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2855 2856 2857 2858

table_alias:
	/* empty */
	| AS
2859
	| EQ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2860 2861 2862 2863

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

2866 2867 2868 2869
opt_all:
	/* empty */
	| ALL
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2870 2871

where_clause:
2872
	/* empty */  { Select->select_lex()->where= 0; }
2873 2874
	| WHERE expr
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2875
	    Select->select_lex()->where= $2;
2876 2877 2878
	    if ($2)
	      $2->top_level_item();
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2879
 	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2880 2881 2882

having_clause:
	/* empty */
2883
	| HAVING { Select->select_lex()->create_refs= 1; } expr
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2884 2885 2886 2887 2888 2889
	  {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->having= $3; sel->create_refs=0;
	    if ($3)
	      $3->top_level_item();
	  }
2890
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2891 2892

opt_escape:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2893 2894
	ESCAPE_SYM TEXT_STRING_db	{ $$= $2.str; }
	| /* empty */			{ $$= (char*) "\\"; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2895 2896 2897


/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2898
   group by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2899 2900 2901 2902
*/

group_clause:
	/* empty */
2903
	| GROUP BY group_list olap_opt;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2904 2905

group_list:
2906
	group_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2907
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
2908
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2909
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2910

2911 2912
olap_opt:
	/* empty */ {}
2913
	| WITH CUBE_SYM
2914
          {
2915
	    LEX *lex=Lex;
2916 2917 2918 2919 2920 2921
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE",
		       "global union parameters");
	      YYABORT;
	    }
2922
	    lex->current_select->select_lex()->olap= CUBE_TYPE;
2923
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
2924
	    YYABORT;	/* To be deleted in 4.1 */
2925
	  }
2926
	| WITH ROLLUP_SYM
2927
          {
2928 2929 2930 2931 2932 2933 2934
	    LEX *lex= Lex;
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP",
		       "global union parameters");
	      YYABORT;
	    }
2935
	    lex->current_select->select_lex()->olap= ROLLUP_TYPE;
2936
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "ROLLUP");
2937
	    YYABORT;	/* To be deleted in 4.1 */
2938
	  }
2939
	;
2940

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2941
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2942
   Order by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2943 2944
*/

2945
opt_order_clause:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2946
	/* empty */
2947
	| order_clause;
2948 2949

order_clause:
2950 2951
	ORDER_SYM BY
        {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2952
	  LEX *lex=Lex;
2953
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
2954
	      lex->current_select->select_lex()->olap !=
2955
	      UNSPECIFIED_OLAP_TYPE)
2956
	  {
2957
	    net_printf(lex->thd, ER_WRONG_USAGE,
2958 2959 2960 2961
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
2962
	} order_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2963 2964 2965

order_list:
	order_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2966
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2967
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2968
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2969 2970 2971

order_dir:
	/* empty */ { $$ =  1; }
2972
	| ASC  { $$ =1; }
2973
	| DESC { $$ =0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2974 2975


2976 2977 2978 2979 2980 2981 2982
opt_limit_clause_init:
	/* empty */
	{
	  SELECT_LEX_NODE *sel= Select;
          sel->offset_limit= 0L;
          sel->select_limit= Lex->thd->variables.select_limit;
	}
2983 2984 2985
	| limit_clause {}
	;

2986 2987 2988 2989 2990
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

2991
limit_clause:
2992
	LIMIT
2993
	  {
2994 2995
	    LEX *lex= Lex;
	    if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
2996
	        lex->current_select->select_lex()->olap !=
2997
		UNSPECIFIED_OLAP_TYPE)
2998
	    {
2999
	      net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
3000
		        "LIMIT");
3001
	      YYABORT;
3002
	    }
3003
	  }
3004
	  limit_options
3005
	  {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3006
	;
3007 3008 3009

limit_options:
	ULONG_NUM
3010
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3011
            SELECT_LEX_NODE *sel= Select;
3012 3013 3014 3015 3016
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
3017
	    SELECT_LEX_NODE *sel= Select;
3018 3019
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
3020
	  }
3021
	| ULONG_NUM OFFSET_SYM ULONG_NUM
3022
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3023
	    SELECT_LEX_NODE *sel= Select;
3024 3025 3026 3027
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3028 3029 3030 3031 3032


delete_limit_clause:
	/* empty */
	{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3033
	  LEX *lex=Lex;
3034
	  lex->current_select->select_limit= HA_POS_ERROR;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3035
	}
3036
	| LIMIT ulonglong_num
3037
	{ Select->select_limit= (ha_rows) $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3038 3039

ULONG_NUM:
3040
	NUM	    { $$= strtoul($1.str,NULL,10); }
3041
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3042
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
3043
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
3044
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3045

3046
ulonglong_num:
3047
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3048
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
3049
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
3050
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
3051
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3052 3053 3054 3055 3056 3057

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
3058 3059 3060 3061 3062 3063 3064
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3065 3066 3067
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
3068
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3069
	      YYABORT;
3070
	    Lex->uncacheable();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3071
	  }
3072
	  '(' procedure_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3073 3074 3075 3076


procedure_list:
	/* empty */ {}
3077
	| procedure_list2 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3078 3079 3080

procedure_list2:
	procedure_list2 ',' procedure_item
3081
	| procedure_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3082 3083 3084 3085

procedure_item:
	  remember_name expr
	  {
3086 3087
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3088 3089
	      YYABORT;
	    if (!$2->name)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3090
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
3091 3092 3093 3094 3095 3096
	  }
          ;


select_var_list_init:
	   {
3097 3098
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3099 3100
	        YYABORT;
	   }
3101
	   select_var_list
3102
	   {}
3103
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3104

Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3105
select_var_list:
3106 3107 3108 3109 3110
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3111
           {
3112
             LEX *lex=Lex;
3113
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3114 3115
	       YYABORT;
	   }
3116
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3117

3118
into:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3119
        INTO OUTFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3120
	{
3121
	  LEX *lex=Lex;
3122 3123
	  if (!lex->describe)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3124
	    lex->uncacheable();
3125 3126 3127 3128 3129
	    if (!(lex->exchange= new sql_exchange($3.str,0)))
	      YYABORT;
	    if (!(lex->result= new select_export(lex->exchange)))
	      YYABORT;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3130 3131
	}
	opt_field_term opt_line_term
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3132
	| INTO DUMPFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3133
	{
3134
	  LEX *lex=Lex;
3135 3136
	  if (!lex->describe)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3137
	    lex->uncacheable();
3138 3139 3140 3141 3142
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3143
	}
3144
        | INTO select_var_list_init
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3145
	{
3146
	  Lex->uncacheable();
3147 3148
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3149

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3150 3151 3152
/*
  DO statement
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3153

3154
do:	DO_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3155 3156 3157 3158 3159 3160
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
3161 3162 3163 3164
	values
	{}
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3165
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3166
  Drop : delete tables or index
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3167 3168 3169
*/

drop:
3170
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3171
	{
3172 3173
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3174 3175
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3176 3177 3178
	}
	| DROP INDEX ident ON table_ident {}
	  {
3179 3180 3181 3182
	     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
3183
						     $3.str));
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3184 3185
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3186 3187 3188 3189
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
3190 3191 3192 3193
	    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
3194
	 }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3195
	| DROP UDF_SYM IDENT_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3196
	  {
3197 3198
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3199
	    lex->udf.name = $3;
3200
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3201 3202 3203


table_list:
3204
	table_name
3205
	| table_list ',' table_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3206

3207
table_name:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3208
	table_ident
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3209 3210 3211 3212 3213
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3214 3215

if_exists:
3216
	/* empty */ { $$= 0; }
3217 3218
	| IF EXISTS { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3219

3220 3221 3222 3223
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3224 3225 3226 3227 3228
/*
** Insert : add new data to table
*/

insert:
3229 3230 3231 3232 3233 3234 3235
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	} insert_lock_option
3236
	opt_ignore insert2
3237
	{
3238
	  Select->set_lock_for_tables($3);
3239
	}
3240
	insert_field_spec opt_insert_update
3241
	{}
3242
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3243 3244

replace:
3245 3246
	REPLACE
	{
3247
	  LEX *lex=Lex;
3248 3249 3250
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
3251 3252
	replace_lock_option insert2
	{
3253
	  Select->set_lock_for_tables($3);
3254 3255
	}
	insert_field_spec
3256
	{}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3257
	{}
3258
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3259 3260

insert_lock_option:
3261 3262 3263 3264
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3265
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3266 3267

replace_lock_option:
3268 3269
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3270 3271 3272

insert2:
	INTO insert_table {}
3273
	| insert_table {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3274 3275

insert_table:
3276
	table_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3277
	{
3278 3279 3280 3281
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
3282
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3283 3284 3285 3286 3287

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
3288 3289 3290
	    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
3291 3292
	      YYABORT;
	   }
3293
	   ident_eq_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3294 3295 3296 3297

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
3298
	| '(' ')'	  { };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3299 3300 3301

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
3302
	| insert_ident		{ Lex->field_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3303 3304 3305

insert_values:
	VALUES	values_list  {}
3306
	| VALUE_SYM values_list  {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3307 3308 3309 3310 3311
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
3312
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3313
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3314
	  }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3315
	  select_options select_item_list opt_select_from select_lock_type
3316
          union_clause {}
3317
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3318 3319 3320

values_list:
	values_list ','  no_braces
3321
	| no_braces;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3322 3323 3324 3325

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
3326
	ident_eq_value;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3327 3328

ident_eq_value:
3329
	simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3330
	 {
3331 3332 3333
	  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
3334
	    YYABORT;
3335
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3336 3337

equal:	EQ		{}
3338 3339 3340 3341 3342 3343 3344
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3345 3346 3347 3348 3349 3350 3351 3352 3353

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
3354 3355
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3356
	    YYABORT;
3357
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3358 3359 3360

opt_values:
	/* empty */ {}
3361
	| values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3362 3363

values:
3364
	values ','  expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3365 3366 3367 3368
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
3369 3370 3371 3372 3373 3374 3375 3376
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3377
	expr	  { $$= $1;}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3378
	| DEFAULT {$$= new Item_default_value(); }
3379
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3380

3381 3382
opt_insert_update:
        /* empty */
3383
        | ON DUPLICATE_SYM
3384 3385 3386 3387 3388 3389 3390 3391 3392
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
	      send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
          }
3393
          KEY_SYM UPDATE_SYM update_list
3394 3395
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3396 3397 3398
/* Update rows in a table */

update:
3399 3400
	UPDATE_SYM
	{
3401 3402
	  LEX *lex= Lex;
          lex->sql_command= SQLCOM_UPDATE;
3403
          lex->select_lex.init_order();
3404
        }
3405 3406 3407
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3408
	  LEX *lex= Lex;
3409
	  Select->set_lock_for_tables($3);
3410
          if (lex->select_lex.table_list.elements > 1)
3411
            lex->sql_command=SQLCOM_UPDATE_MULTI;
3412 3413
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3414 3415

update_list:
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3416
	update_list ',' simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3417
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3418
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3419 3420
	    YYABORT;
	}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3421
	| simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3422
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3423
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3424
	      YYABORT;
3425
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3426 3427

opt_low_priority:
3428
	/* empty */	{ $$= YYTHD->update_lock_default; }
3429
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3430 3431 3432 3433

/* Delete rows from a table */

delete:
3434
	DELETE_SYM
3435
	{
3436 3437 3438
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
	  lex->select_lex.options= 0;
3439
	  lex->lock_option= lex->thd->update_lock_default;
3440
	  lex->select_lex.init_order();
3441
	}
3442 3443
	opt_delete_options single_multi {}
	;
3444 3445

single_multi:
3446 3447
 	FROM table_ident
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3448 3449
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
3450 3451 3452
	    YYABORT;
	}
	where_clause opt_order_clause
3453
	delete_limit_clause {}
3454
	| table_wild_list
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3455
	  { mysql_init_multi_delete(Lex); }
3456
          FROM join_table_list where_clause
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3457 3458
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3459 3460 3461
	  USING join_table_list where_clause
	  {}
	;
3462 3463 3464

table_wild_list:
	  table_wild_one {}
3465
	  | table_wild_list ',' table_wild_one {};
3466 3467

table_wild_one:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3468
	ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3469
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3470 3471
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3472 3473
	    YYABORT;
        }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3474
	| ident '.' ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3475
	  {
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
3476 3477
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3478 3479
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
3480
	      YYABORT;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3481
	  }
3482
	;
3483 3484

opt_wild:
3485
	/* empty */	{}
3486
	| '.' '*'	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3487 3488


3489
opt_delete_options:
3490
	/* empty */	{}
3491
	| opt_delete_option opt_delete_options {};
3492 3493

opt_delete_option:
3494
	QUICK		{ Select->options|= OPTION_QUICK; }
3495
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
3496

3497
truncate:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3498
	TRUNCATE_SYM opt_table_sym table_name
3499
	{
3500
	  LEX* lex= Lex;
3501
	  lex->sql_command= SQLCOM_TRUNCATE;
3502
	  lex->select_lex.options= 0;
3503
	  lex->select_lex.init_order();
3504 3505
	}
	;
3506

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3507 3508
opt_table_sym:
	/* empty */
3509
	| TABLE_SYM;
3510

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3511 3512
/* Show things */

3513 3514
show:	SHOW
	{
3515 3516 3517 3518
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3519
	show_param
3520 3521
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3522 3523 3524 3525 3526

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

opt_db:
	/* empty */  { $$= 0; }
3657
	| from_or_in ident { $$= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3658 3659 3660

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

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3663 3664
opt_full:
	/* empty */ { Lex->verbose=0; }
3665
	| FULL	    { Lex->verbose=1; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3666

3667 3668
from_or_in:
	FROM
3669
	| IN_SYM;
3670

3671 3672
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3673
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
3674 3675 3676

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


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3680 3681 3682 3683
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
3684 3685 3686 3687
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3688
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3689 3690
	    YYABORT;
	}
3691
	opt_describe_column {}
3692
	| describe_command { Lex->describe=1; } select
3693
          {
3694
	    LEX *lex=Lex;
3695
	    lex->select_lex.options|= SELECT_DESCRIBE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3696 3697
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3698 3699 3700

describe_command:
	DESC
3701
	| DESCRIBE;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3702 3703 3704 3705

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
3706
	| ident
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3707
	  { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3708 3709 3710 3711 3712


/* flush things */

flush:
3713 3714 3715 3716 3717
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
3718 3719 3720
	flush_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3721 3722 3723

flush_options:
	flush_options ',' flush_option
3724
	| flush_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3725 3726

flush_option:
3727
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3728
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3729
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3730 3731 3732 3733
	| 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
3734 3735
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3736 3737
	| 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
3738

3739
opt_table_list:
3740 3741
	/* empty */  {;}
	| table_list {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3742

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3743
reset:
3744 3745 3746 3747
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
3748 3749 3750 3751
	} reset_options
	{}
	;

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3752 3753
reset_options:
	reset_options ',' reset_option
3754
	| reset_option;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3755 3756

reset_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3757 3758
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
3759
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3760

3761
purge:
3762 3763 3764 3765
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
3766 3767 3768 3769 3770
	} purge_options
	{}
	;

purge_options:
3771 3772 3773
	LOGS_SYM purge_option
	| MASTER_SYM LOGS_SYM purge_option
	;
3774 3775

purge_option:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3776
        TO_SYM TEXT_STRING_sys
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790
        {
	   Lex->sql_command = SQLCOM_PURGE;
	   Lex->to_log = $2.str;
        }
	| BEFORE_SYM expr
	{
	  if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2))
	  {
	    net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE");
	    YYABORT;	  
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
	  Lex->purge_time= tmp->val_int();
3791
	}
3792
	;
3793

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3794 3795 3796
/* kill threads */

kill:
3797
	KILL_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3798
	{
3799
	  LEX *lex=Lex;
3800
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
3801
	  {
3802
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
3803 3804 3805 3806
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
3807
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3808 3809 3810 3811

/* change database */

use:	USE_SYM ident
3812 3813
	{
	  LEX *lex=Lex;
3814 3815
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
3816
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3817 3818 3819

/* import, export of files */

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3820
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3821
	{
3822 3823
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
3824 3825
	  lex->lock_option= $3;
	  lex->local_file=  $4;
3826
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3827
	    YYABORT;
3828
	  lex->field_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3829 3830 3831 3832
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3833
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3834 3835 3836
	    YYABORT;
	}
        |
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3837
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3838 3839
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3840
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3841
	    YYABORT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3842 3843

        }
3844 3845 3846 3847
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
3848
        };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3849 3850 3851

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

3854
load_data_lock:
3855
	/* empty */	{ $$= YYTHD->update_lock_default; }
3856 3857
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
3858 3859


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3860 3861 3862
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
3863
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3864 3865 3866

opt_field_term:
	/* empty */
3867
	| COLUMNS field_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3868 3869 3870

field_term_list:
	field_term_list field_term
3871
	| field_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3872 3873 3874 3875

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
3876 3877 3878 3879 3880
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3881
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
3882
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3883 3884 3885

opt_line_term:
	/* empty */
3886
	| LINES line_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3887 3888 3889

line_term_list:
	line_term_list line_term
3890
	| line_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3891 3892 3893

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
3894
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3895 3896 3897 3898

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
3899
	  { Lex->exchange->skip_lines=atol($2.str); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3900 3901 3902 3903

/* Common definitions */

text_literal:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3904 3905 3906 3907 3908 3909 3910
	TEXT_STRING_db
	{
	  THD *thd= YYTHD;
	  CHARSET_INFO *cs= my_charset_same(thd->charset(),thd->db_charset) ?
			    thd->charset() : thd->db_charset;
	  $$ = new Item_string($1.str,$1.length,cs);
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3911
	| NCHAR_STRING
3912
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
3913
	| UNDERSCORE_CHARSET TEXT_STRING
3914
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3915
	| text_literal TEXT_STRING_db
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3916 3917
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3918 3919

text_string:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3920 3921
	TEXT_STRING_db
	{ $$=  new String($1.str,$1.length,YYTHD->db_charset); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3922 3923
	| HEX_NUM
	  {
3924
	    Item *tmp = new Item_varbinary($1.str,$1.length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3925
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
3926 3927 3928
	  }
	;

3929
param_marker:
3930
        '?'
3931
        {
3932
	  LEX *lex=Lex;
3933
          if (YYTHD->prepare_command)
3934
          {
3935
            lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query)));
3936
            lex->param_count++;
3937
          }
3938
          else
3939 3940 3941 3942
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
3943 3944 3945
        }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3946 3947
literal:
	text_literal	{ $$ =	$1; }
3948 3949
	| NUM		{ $$ =	new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); }
	| LONG_NUM	{ $$ =	new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); }
3950
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3951 3952 3953
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
3954
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
3955
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
3956 3957 3958 3959
	| UNDERSCORE_CHARSET HEX_NUM
	  { 
	    Item *tmp= new Item_varbinary($2.str,$2.length);
	    String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0;
3960 3961
	    $$ = new Item_string(str ? str->ptr() : "", str ? str->length() : 0, 
				 Lex->charset);
3962
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3963 3964
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
3965
	| TIMESTAMP text_literal { $$ = $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3966 3967 3968 3969 3970 3971 3972

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

insert_ident:
	simple_ident	 { $$=$1; }
3973
	| table_wild	 { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3974 3975

table_wild:
3976 3977 3978 3979 3980
	ident '.' '*' 
	{
	  $$ = new Item_field(NullS,$1.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3981
	| ident '.' ident '.' '*'
3982 3983 3984 3985 3986 3987 3988
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3989 3990

order_ident:
3991
	expr { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3992 3993 3994

simple_ident:
	ident
3995
	{
3996 3997
	  SELECT_LEX_NODE *sel=Select;
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str);
3998
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3999
	| ident '.' ident
4000
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4001 4002 4003 4004 4005 4006 4007 4008 4009
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
4010
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str);
4011
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4012
	| '.' ident '.' ident
4013
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4014 4015 4016 4017 4018 4019 4020 4021 4022
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
4023
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str);
4024
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4025
	| ident '.' ident '.' ident
4026
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4027 4028 4029 4030 4031 4032 4033 4034 4035
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
4036
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str);
4037
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4038 4039 4040 4041 4042


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
4043
	| '.' ident		{ $$=$2;}	/* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4044 4045 4046

table_ident:
	ident			{ $$=new Table_ident($1); }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4047
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
4048 4049
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4050

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105
IDENT_sys:
	IDENT
	{
	  THD *thd= YYTHD;
	  if (my_charset_same(thd->charset(),system_charset_info))
	  {
	    $$=$1;
	  }
	  else
	  {
	    String ident;
	    ident.copy($1.str,$1.length,thd->charset(),system_charset_info);
	    $$.str= thd->strmake(ident.ptr(),ident.length());
	    $$.length= ident.length();
	  }
	}
	;

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

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


bk@work.mysql.com's avatar
bk@work.mysql.com committed
4106
ident:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4107
	IDENT_sys	    { $$=$1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4108 4109
	| keyword
	{
4110 4111
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4112
	  $$.length=$1.length;
4113 4114
	  if (lex->next_state != MY_LEX_END)
	    lex->next_state= MY_LEX_OPERATOR_OR_IDENT;
4115 4116
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4117 4118

ident_or_text:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4119 4120 4121
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4122 4123 4124 4125

user:
	ident_or_text
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4126 4127
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4128 4129 4130 4131 4132
	    YYABORT;
	  $$->user = $1; $$->host.str=NullS;
	  }
	| ident_or_text '@' ident_or_text
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4133 4134
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4135 4136
	      YYABORT;
	    $$->user = $1; $$->host=$3;
4137
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4138 4139 4140 4141 4142 4143

/* Keyword that we allow for identifiers */

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

/* Option functions */

set:
	SET opt_option
	{
4326 4327
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
4328 4329
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4330
	}
4331 4332 4333
	option_value_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4334 4335 4336

opt_option:
	/* empty */ {}
4337
	| OPTION {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4338 4339

option_value_list:
4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351
	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; }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4352
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
4353 4354 4355 4356 4357 4358
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4359
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
4360 4361 4362
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4363 4364

option_value:
4365
	'@' ident_or_text equal expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4366
	{
4367
	  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
4368
	}
4369
	| internal_variable_name equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4370
	  {
4371 4372
	    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
4373
	  }
4374
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
4375 4376 4377 4378 4379 4380 4381 4382
	  {
	    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,
4383
						find_sys_var("tx_isolation"),
4384
						new Item_int((int32) $4)));
4385
	  }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4386
	| charset set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4387
	{
4388 4389
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4390
	  if (!$2)
4391 4392
	  {
	    CHARSET_INFO *cl= thd->db_charset;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4393
	    $2= new Item_string(cl->name, strlen(cl->name), &my_charset_latin1);
4394
	  }
4395
	  lex->var_list.push_back(new set_var(lex->option_type,
4396
					      find_sys_var("client_collation"),
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4397
					      $2));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4398
	}
4399
	| NAMES_SYM charset_name_or_default opt_collate
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4400
	{
4401 4402 4403 4404 4405
	  THD* thd= YYTHD;
	  LEX *lex= &thd->lex;
	  CHARSET_INFO *cs= $2 ? $2 : thd->db_charset;
	  CHARSET_INFO *cl= $3 ? $3 : cs;

4406
	  if (!my_charset_same(cs,cl))
4407 4408 4409 4410 4411 4412 4413 4414
	  {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH, 
		         cl->name,cs->csname);
	      YYABORT;
	  }
	  Item_string *csname= new Item_string(cl->name, 
					       strlen(cl->name), 
					       &my_charset_latin1);
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4415
	  lex->var_list.push_back(new set_var(lex->option_type,
4416 4417
					      find_sys_var("client_collation"),
					      csname));
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4418
	}
4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434
	| COLLATION_SYM collation_name_or_default
	{
	  THD* thd= YYTHD;
	  LEX *lex= &thd->lex;
	  system_variables *vars= &thd->variables;
	  CHARSET_INFO *cs= vars->thd_charset;
	  CHARSET_INFO *cl= $2;

	  if (!cl)
	  {
	    if (!(cl=get_charset_by_csname(cs->csname,MY_CS_PRIMARY,MYF(0))))
	    {
	      net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"DEFAULT");
	      YYABORT;
	    }
	  }
4435
	  else if (!my_charset_same(cs,cl))
4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447
	  {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH, 
		         cl->name,cs->csname);
	      YYABORT;
	  }
	  Item_string *csname= new Item_string(cl->name, 
					       strlen(cl->name), 
					       &my_charset_latin1);
	  lex->var_list.push_back(new set_var(lex->option_type,
					      find_sys_var("client_collation"),
					      csname));
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4448
	| PASSWORD equal text_or_password
4449
	  {
4450
	    THD *thd=YYTHD;
4451
	    LEX_USER *user;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4452
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
4453 4454 4455 4456 4457 4458
	      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
4459
	  {
4460 4461
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
4462
	;
4463

4464 4465 4466 4467 4468 4469 4470 4471
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
4472
        ;
4473 4474 4475 4476 4477 4478 4479

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4481 4482 4483 4484 4485 4486 4487 4488
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
	    if (!$3.length)
	      $$=$3.str;
	    else
	    {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4489
	      char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
4490 4491
	      make_scrambled_password(buff,$3.str,use_old_passwords,
				      &YYTHD->rand);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4492 4493
	      $$=buff;
	    }
4494 4495
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4496

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

4498
set_expr_or_default:
4499 4500
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
4501 4502
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4503
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
4504
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4505 4506


bk@work.mysql.com's avatar
bk@work.mysql.com committed
4507 4508 4509 4510 4511 4512 4513
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
4514 4515 4516
	table_lock_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4517 4518 4519

table_or_tables:
	TABLE_SYM
4520
	| TABLES;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4521 4522 4523

table_lock_list:
	table_lock
4524
	| table_lock_list ',' table_lock;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4525 4526 4527

table_lock:
	table_ident opt_table_alias lock_option
4528
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4529
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
4530 4531
	   YYABORT;
	}
4532
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4533 4534 4535

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
4536
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4537
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
4538 4539
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4540 4541

unlock:
4542 4543
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4544 4545


4546
/*
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4547
** Handler: direct access to ISAM functions
4548 4549 4550 4551 4552
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
4553 4554
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4555
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
4556 4557 4558 4559
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
4560 4561
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4562
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4563 4564
	    YYABORT;
	}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4565
	| HANDLER_SYM table_ident READ_SYM
4566
	{
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
4567 4568 4569
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
4570 4571
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4572
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4573
	    YYABORT;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4574
        }
4575
        handler_read_or_scan where_clause opt_limit_clause {}
4576
        ;
4577

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4578 4579
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
4580 4581
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4582 4583 4584

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
4585 4586
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4587 4588 4589 4590 4591 4592

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;  }
4593 4594
	| handler_rkey_mode
	{
4595 4596
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
4597
	  lex->ha_rkey_mode=$1;
4598
	  if (!(lex->insert_list = new List_item))
4599
	    YYABORT;
4600 4601
	} '(' values ')' { }
        ;
4602 4603

handler_rkey_mode:
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
4604 4605 4606 4607
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
4608 4609
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
4610

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4611 4612 4613 4614 4615
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
4616 4617 4618 4619 4620
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
4621
	  lex->select_lex.db=0;
4622 4623
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4624
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4625
	}
4626 4627 4628
	grant_privileges ON opt_table FROM user_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4629 4630 4631 4632

grant:
	GRANT
	{
4633 4634 4635
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
4636 4637
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
4638
	  lex->select_lex.db= 0;
4639 4640
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4641
	  bzero(&(lex->mqh),sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4642 4643
	}
	grant_privileges ON opt_table TO_SYM user_list
4644 4645 4646
	require_clause grant_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4647 4648 4649

grant_privileges:
	grant_privilege_list {}
4650
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
4651 4652
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4653 4654 4655

grant_privilege_list:
	grant_privilege
4656
	| grant_privilege_list ',' grant_privilege;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4657 4658

grant_privilege:
4659 4660 4661 4662
	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 {}
4663 4664
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4665 4666 4667 4668
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
4669
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4670 4671 4672 4673
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
4674 4675 4676 4677 4678 4679 4680 4681
	| 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
4682

4683

4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
4696 4697 4698 4699
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
4700
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
4701 4702 4703 4704 4705 4706 4707 4708 4709
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
4710
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
4711 4712 4713 4714 4715 4716 4717 4718 4719
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
4720
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
4721 4722 4723 4724 4725
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
4726

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4727 4728 4729
opt_table:
	'*'
	  {
4730
	    LEX *lex= Lex;
4731
	    lex->current_select->select_lex()->db= lex->thd->db;
4732
	    if (lex->grant == GLOBAL_ACLS)
4733 4734
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4735
	    {
4736
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
4737
	      YYABORT;
4738
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4739 4740 4741
	  }
	| ident '.' '*'
	  {
4742
	    LEX *lex= Lex;
4743
	    lex->current_select->select_lex()->db = $1.str;
4744
	    if (lex->grant == GLOBAL_ACLS)
4745 4746
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4747
	    {
4748
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4749 4750 4751 4752 4753
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
4754
	    LEX *lex= Lex;
4755
	    lex->current_select->select_lex()->db = NULL;
4756 4757
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
4758
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4759
	    {
4760
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4761 4762 4763 4764 4765
	      YYABORT;
	    }
	  }
	| table_ident
	  {
4766
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4767
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4768
	      YYABORT;
4769
	    if (lex->grant == GLOBAL_ACLS)
4770
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
4771 4772
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4773 4774 4775


user_list:
4776 4777 4778 4779 4780 4781 4782
	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
4783 4784 4785 4786 4787 4788 4789 4790


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4791
	     char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4792 4793
	     if (buff)
	     {
4794 4795
	       make_scrambled_password(buff,$4.str,use_old_passwords,
				       &YYTHD->rand);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4796 4797 4798 4799 4800 4801 4802 4803
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
4804 4805
	  { $$=$1; $1->password.str=NullS; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4806 4807 4808


opt_column_list:
4809 4810 4811 4812 4813
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
4814
	| '(' column_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4815 4816 4817

column_list:
	column_list ',' column_list_id
4818
	| column_list_id;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4819 4820 4821 4822

column_list_id:
	ident
	{
4823
	  String *new_str = new String((const char*) $1.str,$1.length,default_charset_info);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4824 4825
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
4826
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4827 4828
	  while ((point=iter++))
	  {
4829 4830
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4831 4832
		break;
	  }
4833
	  lex->grant_tot_col|= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4834
	  if (point)
4835
	    point->rights |= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4836
	  else
4837
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
4838 4839
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4840

tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
4841 4842

require_clause: /* empty */
4843
        | REQUIRE_SYM require_list
4844 4845 4846
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
4847
        | REQUIRE_SYM SSL_SYM
4848 4849 4850
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
4851
        | REQUIRE_SYM X509_SYM
4852 4853 4854 4855 4856 4857 4858
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
4859
          ;
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
4860

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4861
grant_options:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4862
	/* empty */ {}
4863
	| WITH grant_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4864

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4865 4866
grant_option_list:
	grant_option_list grant_option {}
4867 4868
	| grant_option {}
        ;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4869 4870 4871

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
4872
        | MAX_QUERIES_PER_HOUR ULONG_NUM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4873
        {
4874
	  Lex->mqh.questions=$2;
4875
	  Lex->mqh.bits |= 1;
4876
	}
4877
        | MAX_UPDATES_PER_HOUR ULONG_NUM
4878
        {
4879
	  Lex->mqh.updates=$2;
4880
	  Lex->mqh.bits |= 2;
4881
	}
4882
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
4883
        {
4884
	  Lex->mqh.connections=$2;
4885
	  Lex->mqh.bits |= 4;
4886 4887
	}
        ;
4888

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4889
begin:
4890 4891
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4892 4893 4894

opt_work:
	/* empty */ {}
4895 4896
	| WORK_SYM {;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4897 4898

commit:
4899
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4900 4901

rollback:
4902
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
4903 4904 4905


/*
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4906
   UNIONS : glue selects together
4907 4908 4909
*/


4910
union_clause:
4911
	/* empty */ {}
4912 4913
	| union_list
	;
4914 4915

union_list:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4916
	UNION_SYM    union_option
4917 4918 4919 4920 4921
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
4922
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
4923
	    YYABORT;
4924
	  }
4925
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4926
	  {
4927
	    send_error(lex->thd, ER_SYNTAX_ERROR);
4928 4929
	    YYABORT;
	  }
4930
	  if (mysql_new_select(lex, 0))
4931
	    YYABORT;
4932
          mysql_init_select(lex);
4933
	  lex->current_select->linkage=UNION_TYPE;
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4934
	}
4935
	select_init {}
4936
	;
4937 4938

union_opt:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4939
	union_list {}
4940 4941
	| optional_order_or_limit {}
	;
4942 4943

optional_order_or_limit:
4944
      	/* Empty */ {}
4945 4946
	|
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4947 4948
	    THD *thd= YYTHD;
	    LEX *lex= &thd->lex;
4949
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
4950
	    SELECT_LEX *sel= lex->current_select->select_lex();
4951 4952 4953 4954
	    SELECT_LEX_UNIT *unit= sel->master_unit();
	    unit->global_parameters= unit;
	    unit->no_table_names_allowed= 1;
	    lex->current_select= unit;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4955
	    thd->where= "global ORDER clause";
4956
	  }
4957
	order_or_limit
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4958 4959 4960 4961 4962
          {
	    THD *thd= YYTHD;
	    thd->lex.current_select->no_table_names_allowed= 0;
	    thd->where= "";
          }
4963 4964 4965
	;

order_or_limit:
4966 4967
	order_clause opt_limit_clause_init
	| limit_clause
4968
	;
4969 4970

union_option:
4971
	/* empty */ {}
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4972
	| ALL {Select->master_unit()->union_option= 1;};
4973

4974 4975
singlerow_subselect:
	subselect_start singlerow_subselect_init
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4976 4977 4978 4979
	subselect_end
	{
	  $$= $2;
	};
4980

4981
singlerow_subselect_init:
4982
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4983
	{
4984
	  $$= new Item_singlerow_subselect(YYTHD,
4985 4986
					   Lex->current_select->master_unit()->
                                             first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4987
	};
4988 4989

exists_subselect:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4990 4991 4992 4993 4994
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
4995 4996

exists_subselect_init:
4997
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4998
	{
4999
	  $$= new Item_exists_subselect(YYTHD,
5000 5001
					Lex->current_select->master_unit()->
					  first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5002
	};
5003

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5004 5005 5006 5007 5008 5009 5010 5011
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
5012
  select_init2
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5013
  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5014
    $$= Lex->current_select->master_unit()->first_select();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5015 5016
  };

5017
subselect_start:
5018
	'(' SELECT_SYM
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5019
	{
5020
	  LEX *lex=Lex;
5021
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
5022 5023 5024 5025
	       lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5026 5027 5028
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
5029 5030

subselect_end:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5031 5032 5033
	')'
	{
	  LEX *lex=Lex;
5034
	  lex->current_select = lex->current_select->outer_select();
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5035
	};