sql_yacc.yy 119 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 286 287
%token	MERGE_SYM
%token	MIN_ROWS
%token	MYISAM_SYM
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
288
%token	NAMES_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
289 290
%token	NATIONAL_SYM
%token	NATURAL
291
%token	NEW_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
292 293 294 295 296
%token	NCHAR_SYM
%token	NOT
%token	NO_SYM
%token	NULL_SYM
%token	NUM
297
%token	OFFSET_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
298
%token	ON
299
%token	OPEN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
300 301 302
%token	OPTION
%token	OPTIONALLY
%token	OR
303
%token	OR_OR_CONCAT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
304 305 306
%token	ORDER_SYM
%token	OUTER
%token	OUTFILE
307
%token	DUMPFILE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
308 309 310 311 312 313
%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
314
%token	QUERY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
315
%token	RAID_0_SYM
316 317
%token	RAID_STRIPED_SYM
%token	RAID_TYPE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
318 319 320 321 322 323 324 325
%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
326
%token	REPEATABLE_SYM
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
327
%token	REQUIRE_SYM
328 329
%token	RESOURCES
%token	RESTORE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
330 331 332 333 334
%token	RESTRICT
%token	REVOKE
%token	ROWS_SYM
%token	ROW_FORMAT_SYM
%token	ROW_SYM
335
%token	RTREE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
336
%token	SET
337
%token	SERIAL_SYM
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
338 339
%token	SERIALIZABLE_SYM
%token	SESSION_SYM
340
%token	SIMPLE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
341
%token	SHUTDOWN
342
%token	SPATIAL_SYM
343
%token  SSL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
344 345 346
%token	STARTING
%token	STATUS_SYM
%token	STRAIGHT_JOIN
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
347
%token	SUBJECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
348 349 350 351 352
%token	TABLES
%token	TABLE_SYM
%token	TEMPORARY
%token	TERMINATED
%token	TEXT_STRING
353 354 355
%token	TO_SYM
%token	TRAILING
%token	TRANSACTION_SYM
356
%token	TRUE_SYM
357
%token	TYPE_SYM
358
%token  TYPES_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
359 360 361 362
%token	FUNC_ARG0
%token	FUNC_ARG1
%token	FUNC_ARG2
%token	FUNC_ARG3
363 364 365
%token	UDF_RETURNS_SYM
%token	UDF_SONAME_SYM
%token	UDF_SYM
366
%token	UNCOMMITTED_SYM
367
%token	UNDERSCORE_CHARSET
368
%token	UNICODE_SYM
369 370 371
%token	UNION_SYM
%token	UNIQUE_SYM
%token	USAGE
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
372
%token	USE_FRM
373 374
%token	USE_SYM
%token	USING
375
%token	VALUE_SYM
376
%token	VALUES
bk@work.mysql.com's avatar
bk@work.mysql.com committed
377 378 379 380
%token	VARIABLES
%token	WHERE
%token	WITH
%token	WRITE_SYM
381
%token	X509_SYM
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
382
%token	XOR
383
%token	COMPRESSED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
384

385 386 387
%token  ERRORS
%token  WARNINGS

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

429
%token	AGAINST
bk@work.mysql.com's avatar
bk@work.mysql.com committed
430 431 432 433 434 435
%token	ATAN
%token	BETWEEN_SYM
%token	BIT_AND
%token	BIT_OR
%token	CASE_SYM
%token	CONCAT
436
%token	CONCAT_WS
bk@work.mysql.com's avatar
bk@work.mysql.com committed
437 438 439 440 441 442 443 444 445 446
%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
447 448
%token	DES_ENCRYPT_SYM
%token	DES_DECRYPT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
449 450 451 452 453 454 455 456 457 458
%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
459 460
%token	GEOMCOLLFROMTEXT
%token	GEOMFROMTEXT
461
%token  GEOMETRYCOLLECTION
bk@work.mysql.com's avatar
bk@work.mysql.com committed
462 463 464 465 466 467
%token	GROUP_UNIQUE_USERS
%token	HOUR_MINUTE_SYM
%token	HOUR_SECOND_SYM
%token	HOUR_SYM
%token	IDENTIFIED_SYM
%token	IF
468
%token	INSERT_METHOD
bk@work.mysql.com's avatar
bk@work.mysql.com committed
469 470 471
%token	INTERVAL_SYM
%token	LAST_INSERT_ID
%token	LEFT
472
%token	LINEFROMTEXT
473
%token  LINESTRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
474 475
%token	LOCATE
%token	MAKE_SET_SYM
476
%token	MASTER_POS_WAIT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
477 478
%token	MINUTE_SECOND_SYM
%token	MINUTE_SYM
479
%token	MODE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
480 481
%token	MODIFY_SYM
%token	MONTH_SYM
482 483 484
%token	MLINEFROMTEXT
%token	MPOINTFROMTEXT
%token	MPOLYFROMTEXT
485 486 487
%token  MULTILINESTRING
%token  MULTIPOINT
%token  MULTIPOLYGON
bk@work.mysql.com's avatar
bk@work.mysql.com committed
488 489
%token	NOW_SYM
%token	PASSWORD
490
%token	POINTFROMTEXT
491
%token	POINT_SYM
492
%token	POLYFROMTEXT
493
%token  POLYGON
bk@work.mysql.com's avatar
bk@work.mysql.com committed
494 495 496 497 498 499 500
%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
501
%token	SHARE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515
%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
516
%token	WORK_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
517 518 519
%token	YEAR_MONTH_SYM
%token	YEAR_SYM
%token	YEARWEEK
520 521 522
%token	BENCHMARK_SYM
%token	END
%token	THEN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
523

524 525 526 527
%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
528
%token	SQL_SMALL_RESULT
529
%token  SQL_BUFFER_RESULT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
530

531 532
%token  ISSUER_SYM
%token  SUBJECT_SYM
533
%token  CIPHER_SYM
534

bk@work.mysql.com's avatar
bk@work.mysql.com committed
535 536 537 538 539 540 541 542 543
%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	'-' '+'
544
%left	'*' '/' '%' DIV_SYM MOD_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
545
%left	NEG '~'
546 547
%left   XOR
%left   '^'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
548
%right	NOT
549
%right	BINARY COLLATE_SYM
550 551 552 553 554 555
/* 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
556 557
%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
558
	ULONGLONG_NUM field_ident select_alias ident ident_or_text
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
559
        UNDERSCORE_CHARSET
bk@work.mysql.com's avatar
bk@work.mysql.com committed
560 561 562 563 564

%type <lex_str_ptr>
	opt_table_alias

%type <table>
565
	table_ident references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
566 567

%type <simple_string>
568
	remember_name remember_end opt_ident opt_db text_or_password
bk@work.mysql.com's avatar
bk@work.mysql.com committed
569 570 571
	opt_escape

%type <string>
572
	text_string
bk@work.mysql.com's avatar
bk@work.mysql.com committed
573 574

%type <num>
575
	type int_type real_type order_dir opt_field_spec lock_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
576
	udf_type if_exists opt_local opt_table_options table_options
577
	table_option opt_if_not_exists opt_var_type opt_var_ident_type
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
578
	delete_option opt_temporary all_or_any
bk@work.mysql.com's avatar
bk@work.mysql.com committed
579 580

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

583 584
%type <ulonglong_number>
	ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
585

586 587 588
%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
589
%type <item>
590
	literal text_literal insert_ident order_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
591 592
	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
593
	using_list expr_or_default set_expr_or_default interval_expr
594
	param_marker singlerow_subselect singlerow_subselect_init
595
	exists_subselect exists_subselect_init
bk@work.mysql.com's avatar
bk@work.mysql.com committed
596 597

%type <item_list>
598
	expr_list udf_expr_list when_list ident_list ident_list_arg
bk@work.mysql.com's avatar
bk@work.mysql.com committed
599 600

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

603 604 605
%type <key_alg>
	key_alg opt_btree_or_rtree

bk@work.mysql.com's avatar
bk@work.mysql.com committed
606 607 608 609 610 611 612
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
613
	join_table_list  join_table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
614 615 616 617 618 619 620 621 622 623 624

%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

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

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

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
629 630
%type <cast_type> cast_type

bk@work.mysql.com's avatar
bk@work.mysql.com committed
631 632 633 634 635 636
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

637
%type <charset>
638
	opt_collate
639 640
	charset_name
	charset_name_or_default
641 642
	collation_name
	collation_name_or_default
643

644 645
%type <variable> internal_variable_name

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

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

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

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
683 684
	',' '!' '{' '}' '&' '|' 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
685 686 687 688 689
%%


query:
	END_OF_INPUT
690
	{
691
	   THD *thd= YYTHD;
692
	   if (!thd->bootstrap &&
693
	      (!(thd->lex.select_lex.options & OPTION_FOUND_COMMENT)))
694
	   {
695
	     send_error(thd,ER_EMPTY_QUERY);
696
	     YYABORT;
697
	   }
698 699 700 701
	   else
	   {
	     thd->lex.sql_command = SQLCOM_EMPTY_QUERY;
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
702
	}
703
	| verb_clause END_OF_INPUT {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
704 705 706 707

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

745 746
/* help */

747
help:
748
       HELP_SYM ident_or_text
749
       {
750 751 752
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
753
       };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
754 755 756 757

/* change master */

change:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
758
       CHANGE MASTER_SYM TO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
759 760 761
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
762
	  bzero((char*) &lex->mi, sizeof(lex->mi));
763 764 765 766
        }
       master_defs
	{}
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
767 768 769

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

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

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
820 821 822 823 824
/* create a table */

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

866
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
867
	    lex->col_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
868
	  }
869 870 871
	| 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
872
	  {
873 874 875 876
	    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
877
	  }
878
	| CREATE udf_func_type UDF_SYM IDENT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
879
	  {
880 881
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
882
	    lex->udf.name = $4;
883
	    lex->udf.type= $2;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
884 885 886
	  }
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
	  {
887 888 889
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
890 891
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
892 893

create2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
894
	'(' field_list ')' opt_create_table_options create3 {}
895
	| opt_create_table_options create3 {}
venu@myvenu.com's avatar
venu@myvenu.com committed
896 897 898 899 900 901 902
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
  	  ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
903 904

create3:
905 906
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
907
          {
908 909 910
	    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
911
          }
912
          select_options select_item_list opt_select_from union_clause {}
913
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
914

915 916
opt_as:
	/* empty */ {}
917
	| AS	    {};
918

919 920 921 922 923 924 925 926 927 928 929
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; }
930 931 932
	| opt_default charset charset_name_or_default
	  { Lex->create_info.table_charset=$3; }
	;
933

bk@work.mysql.com's avatar
bk@work.mysql.com committed
934
opt_table_options:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
935
	/* empty */	 { $$= 0; }
936
	| table_options  { $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
937 938 939

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
942
table_option:
943
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
944 945

opt_if_not_exists:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
946
	/* empty */	 { $$= 0; }
947
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
948 949 950

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

953 954 955 956
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
957 958
create_table_options:
	create_table_option
959
	| create_table_option     create_table_options
960
	| create_table_option ',' create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
961 962

create_table_option:
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
	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;}
	| PASSWORD opt_equal TEXT_STRING	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM opt_equal TEXT_STRING	{ Lex->create_info.comment=$3.str; }
	| 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 ')'
979 980 981
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
982 983
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
984 985
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
986 987
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
988
	    table_list->next=0;
989
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
990
	  }
991
	| opt_default charset opt_equal charset_name_or_default
992
	  {
993 994 995
	    Lex->create_info.table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
996 997 998 999 1000
	| COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1001 1002 1003
	| INSERT_METHOD opt_equal merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING { Lex->create_info.data_file_name= $4.str; }
	| INDEX DIRECTORY_SYM opt_equal TEXT_STRING    { Lex->create_info.index_file_name= $4.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1004 1005 1006 1007 1008 1009 1010

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
1011
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1012 1013 1014 1015 1016

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
1017
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1018 1019 1020 1021

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

1024 1025 1026
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
1027
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1028

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1029
opt_select_from:
1030
	opt_limit_clause {}
1031
	| FROM DUAL_SYM {}
1032
	| select_from select_lock_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1033 1034 1035

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
1036
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1037 1038 1039 1040

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
1041
	| INT_SYM {$$ = (int) INT_RESULT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1042 1043 1044

field_list:
	  field_list_item
1045
	| field_list ',' field_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1046 1047 1048


field_list_item:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1049
	   column_def
1050 1051 1052 1053
         | key_def
         ;

column_def:
1054
	  field_spec check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1055 1056 1057 1058
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1059
	;
1060 1061

key_def:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1062
	key_type opt_ident key_alg '(' key_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1063
	  {
1064
	    LEX *lex=Lex;
1065
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
1066
	    lex->col_list.empty();		/* Alloced by sql_alloc */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1067
	  }
1068
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1069
	  {
1070 1071 1072 1073 1074 1075 1076 1077
	    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
1078
	  }
1079
	| opt_constraint check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1080 1081
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1082 1083 1084 1085 1086 1087 1088
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1089 1090 1091

opt_constraint:
	/* empty */
1092
	| CONSTRAINT opt_ident;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1093 1094 1095 1096

field_spec:
	field_ident
	 {
1097 1098
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
1099
	   lex->default_value=lex->comment=0;
1100
	   lex->charset=NULL;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1101 1102 1103
	 }
	type opt_attribute
	{
1104
	  LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1105
	  if (add_field_to_list(lex->thd, $1.str,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1106
				(enum enum_field_types) $3,
1107
				lex->length,lex->dec,lex->type,
1108
				lex->default_value, lex->comment,
1109
				lex->change,lex->interval,lex->charset))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1110
	    YYABORT;
1111
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1112 1113

type:
1114
	int_type opt_len field_options	{ $$=$1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1115 1116 1117 1118 1119 1120
	| 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; }
1121 1122
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1123
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1124 1125 1126
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
1127
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
1128
					  Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1129 1130 1131 1132
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
1133
					  Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1134
					  $$=FIELD_TYPE_VAR_STRING; }
1135
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1136 1137
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1138 1139
	| TIMESTAMP
	  {
1140
	    if (YYTHD->variables.sql_mode & MODE_SAPDB)
1141 1142
	      $$=FIELD_TYPE_DATETIME;
	    else
1143
	      $$=FIELD_TYPE_TIMESTAMP;
1144
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1145 1146 1147
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
1148
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1149
					  $$=FIELD_TYPE_TINY_BLOB; }
1150
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1151
					  $$=FIELD_TYPE_BLOB; }
1152
	| GEOMETRY_SYM			{ Lex->charset=&my_charset_bin;
1153
					  $$=FIELD_TYPE_GEOMETRY; }
1154 1155
	| GEOMETRYCOLLECTION		{ Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_GEOMETRY; }
1156
	| POINT_SYM			{ Lex->charset=&my_charset_bin;
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOINT			{ Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_GEOMETRY; }
	| LINESTRING			{ Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTILINESTRING		{ Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_GEOMETRY; }
	| POLYGON			{ Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOLYGON			{ Lex->charset=&my_charset_bin;
					  $$=FIELD_TYPE_GEOMETRY; }
1168
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1169
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1170
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1171
					  $$=FIELD_TYPE_LONG_BLOB; }
1172
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1173
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1174 1175
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1176
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1177 1178
	| 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
1179 1180 1181 1182
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1183 1184
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1185
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1186
	  {
1187 1188
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1189 1190
	    $$=FIELD_TYPE_ENUM;
	  }
1191
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1192
	  {
1193 1194
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1195
	    $$=FIELD_TYPE_SET;
1196
	  }
1197
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
1198 1199 1200 1201 1202 1203
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
1204
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1205 1206 1207 1208

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1211 1212 1213 1214
varchar:
	char VARYING {}
	| VARCHAR {}
	| NATIONAL_SYM VARCHAR {}
1215
	| NCHAR_SYM VARCHAR {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1216 1217 1218 1219 1220 1221

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

real_type:
1225
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1226 1227
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
1228
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1229 1230 1231 1232 1233


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
1234
	| precision		{};
1235 1236 1237 1238 1239 1240

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

field_options:
	/* empty */		{}
1245
	| field_opt_list	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1246 1247 1248

field_opt_list:
	field_opt_list field_option {}
1249
	| field_option {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1250 1251

field_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1252
	SIGNED_SYM	{}
1253
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
1254
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1255 1256

opt_len:
1257 1258
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1259 1260 1261

opt_precision:
	/* empty */	{}
1262
	| precision	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1263 1264 1265

opt_attribute:
	/* empty */ {}
1266
	| opt_attribute_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1267 1268 1269

opt_attribute_list:
	opt_attribute_list attribute {}
1270
	| attribute;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1271 1272 1273 1274 1275 1276

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; }
1277
	| SERIAL_SYM DEFAULT VALUE_SYM
1278 1279
	  { 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
1280
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1281
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
1282
	| COMMENT_SYM text_literal { Lex->comment= $2; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
	| COLLATE_SYM collation_name 
	  { 
	    if (Lex->charset && strcmp(Lex->charset->csname,$2->csname))
	    {
	      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
1297

1298 1299 1300 1301
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
1302

1303
charset_name:
1304
	ident_or_text
1305
	{
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1306
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
1307
	  {
1308
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1309 1310 1311 1312
	    YYABORT;
	  }
	};

1313 1314 1315
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1316

1317
collation_name:
1318
	ident_or_text
1319 1320 1321 1322 1323 1324 1325 1326
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	};

1327 1328 1329 1330 1331
opt_collate:
	/* empty */	{ $$=NULL; }
	| COLLATE_SYM collation_name { $$=$2; }
	;

1332 1333 1334 1335
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1336 1337 1338 1339
opt_default:
	/* empty */	{}
	| DEFAULT	{};

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1340
opt_binary:
1341
	/* empty */			{ Lex->charset=NULL; }
1342 1343 1344
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
	| BINARY			{ Lex->charset=&my_charset_bin; }
1345 1346 1347 1348 1349 1350 1351 1352
	| UNICODE_SYM
	{
	  if (!(Lex->charset=get_charset_by_name("ucs2",MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1353
	| charset charset_name	{ Lex->charset=$2; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1354

1355 1356 1357
opt_primary:
	/* empty */
	| PRIMARY_SYM
1358
	;
1359

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1360
references:
1361 1362
	REFERENCES table_ident
	{
1363
	  LEX *lex=Lex;
1364 1365 1366 1367 1368 1369
	  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
1370
	};
1371

1372
opt_ref_list:
1373
	/* empty */ opt_on_delete {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1374
	| '(' ref_list ')' opt_on_delete {};
1375 1376 1377

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
1378
	| ident			{ Lex->ref_list.push_back(new key_part_spec($1.str)); };
1379

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1380 1381 1382

opt_on_delete:
	/* empty */ {}
1383
	| opt_on_delete_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1384 1385 1386

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
1387
	| opt_on_delete_item {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1388 1389

opt_on_delete_item:
1390 1391 1392 1393
	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
1394
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1395 1396

delete_option:
1397 1398 1399 1400
	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
1401
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1402 1403 1404 1405

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1406 1407
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
1408 1409
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1410
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
1411
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1412 1413 1414

key_or_index:
	KEY_SYM {}
1415
	| INDEX {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1416 1417 1418 1419

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

1422
opt_unique_or_fulltext:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1423 1424
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1425
	| SPATIAL_SYM	{ $$= Key::SPATIAL; };
1426 1427

key_alg:
1428
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1429
	| USING opt_btree_or_rtree { $$= $2; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1430
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
1431 1432 1433 1434

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
1435
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1436 1437 1438

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
1439
	| key_part order_dir		{ Lex->col_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1440 1441 1442

key_part:
	ident			{ $$=new key_part_spec($1.str); }
1443
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1444 1445 1446

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
1447
	| field_ident	{ $$=$1.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1448 1449 1450

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
1451
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1452 1453 1454 1455 1456 1457 1458 1459

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1460
	  THD *thd= YYTHD;
1461
	  LEX *lex=&thd->lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1462 1463
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1464 1465
	  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
1466 1467 1468 1469 1470 1471 1472
	    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();
1473
          lex->select_lex.init_order();
1474
	  lex->select_lex.db=lex->name=0;
1475
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1476
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1477
	  lex->create_info.table_charset= thd->db_charset;
1478
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1479 1480
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1481
	}
1482 1483
	alter_list
	{}
1484
	| ALTER DATABASE ident opt_create_database_options
1485 1486 1487 1488
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1489
	  };
1490 1491


bk@work.mysql.com's avatar
bk@work.mysql.com committed
1492
alter_list:
1493
        | alter_list_item
1494
	| alter_list ',' alter_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1495 1496

add_column:
1497
	ADD opt_column { Lex->change=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1498 1499

alter_list_item:
1500 1501
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1502
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
1503 1504 1505 1506 1507
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1508
          field_spec opt_place
1509 1510 1511 1512 1513
        | 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;
1514
            lex->simple_alter=0;
1515 1516 1517 1518
          }
          type opt_attribute
          {
            LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1519
            if (add_field_to_list(lex->thd,$3.str,
1520 1521 1522
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
1523
				  $3.str, lex->interval, lex->charset))
1524 1525 1526
	       YYABORT;
          }
          opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1527
	| DROP opt_column field_ident opt_restrict
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
	  {
	    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;
	  }
1538
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1539
	| DROP key_or_index field_ident
1540 1541 1542 1543 1544 1545
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1546 1547
	| 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
1548
	| ALTER opt_column field_ident SET DEFAULT literal
1549 1550 1551 1552 1553
	  {
	    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
1554
	| ALTER opt_column field_ident DROP DEFAULT
1555 1556 1557 1558 1559
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1560
	| RENAME opt_to table_ident
1561
	  {
1562
	    LEX *lex=Lex;
1563
	    lex->select_lex.db=$3->db.str;
1564
	    lex->name= $3->table.str;
1565
	  }
1566
        | create_table_options_space_separated { Lex->simple_alter=0; }
1567
	| order_clause         { Lex->simple_alter=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1568 1569 1570

opt_column:
	/* empty */	{}
1571
	| COLUMN_SYM	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1572 1573 1574

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
1575
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1576 1577 1578 1579

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
1580
	| CASCADE	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1581 1582 1583 1584

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
1585
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1586 1587 1588 1589

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1590
	| EQ		{}
1591
	| AS		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1592

nick@mysql.com's avatar
nick@mysql.com committed
1593
/*
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1594 1595 1596
  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
1597
slave:
1598
	START_SYM SLAVE slave_thread_opts
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
        {
	  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
1611

1612 1613 1614 1615 1616
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

1617
slave_thread_opts:
1618 1619
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1620
	;
1621 1622

slave_thread_opt_list:
1623
	slave_thread_opt
1624 1625
	| slave_thread_opt_list ',' slave_thread_opt
	;
1626 1627

slave_thread_opt:
1628
	/*empty*/	{}
1629 1630 1631
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
	| IO_THREAD   	{ Lex->slave_thd_opt|=SLAVE_IO; }
	;
1632

1633 1634 1635 1636 1637 1638 1639 1640
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
	table_list FROM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
1641
        };
1642

1643 1644 1645 1646 1647 1648 1649 1650
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
	table_list TO_SYM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
1651
        };
1652

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1653 1654 1655
repair:
	REPAIR table_or_tables
	{
1656 1657 1658
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1659
	}
1660 1661 1662
	table_list opt_mi_repair_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1663

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1664
opt_mi_repair_type:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1665
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1666
	| mi_repair_types {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1667

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1668 1669
mi_repair_types:
	mi_repair_type {}
1670
	| mi_repair_type mi_repair_types {};
1671

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1672
mi_repair_type:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1673
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1674
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
1675
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1676 1677

analyze:
1678
	ANALYZE_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1679
	{
1680 1681 1682
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1683
	}
1684 1685 1686
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1687 1688

check:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1689
	CHECK_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1690
	{
1691 1692 1693
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1694
	}
1695 1696 1697
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1698

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1699 1700
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
1701
	| mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1702 1703 1704

mi_check_types:
	mi_check_type {}
1705
	| mi_check_type mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1706 1707 1708 1709 1710 1711

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1714
optimize:
1715
	OPTIMIZE table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1716
	{
1717 1718 1719
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1720
	}
1721 1722 1723
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1724

1725 1726 1727 1728 1729
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1730 1731 1732
	table_to_table_list
	{}
	;
1733 1734 1735

table_to_table_list:
	table_to_table
1736
	| table_to_table_list ',' table_to_table;
1737 1738 1739

table_to_table:
	table_ident TO_SYM table_ident
1740
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1741 1742
	  LEX *lex=Lex;	  
	  SELECT_LEX_NODE *sl= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1743 1744 1745 1746
	  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))
1747
	    YYABORT;
1748
	};
1749

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1750
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1751
  Select : retrieve data from table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1752 1753 1754 1755
*/


select:
1756
	select_init { Lex->sql_command=SQLCOM_SELECT; };
1757

1758
/* Need select_init2 for subselects. */
1759
select_init:
1760
	SELECT_SYM select_init2
1761
	|
1762 1763
	'(' SELECT_SYM select_part2 ')'
	  {
1764
	    LEX *lex= Lex;
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1765
            SELECT_LEX * sel= lex->current_select->select_lex();
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1766
	    if (sel->set_braces(1))
1767 1768 1769 1770
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
1771 1772
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1773 1774 1775 1776
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1777
            /* select in braces, can't contain global parameters */
1778
            sel->master_unit()->global_parameters=
1779
               sel->master_unit();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1780
          } union_opt;
1781

1782 1783
select_init2:
	select_part2
1784
        {
1785
	  LEX *lex= Lex;
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1786
          SELECT_LEX * sel= lex->current_select->select_lex();
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1787
          if (lex->current_select->set_braces(0))
1788 1789 1790 1791
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1792 1793
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1794 1795 1796 1797
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1798
	}
1799
	union_clause
1800 1801
	;

1802
select_part2:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1803 1804
	{
	  LEX *lex=Lex;
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
1805
	  SELECT_LEX * sel= lex->current_select->select_lex();
1806
	  if (lex->current_select == &lex->select_lex)
1807
	    lex->lock_option= TL_READ; /* Only for global SELECT */
1808 1809
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1810
	}
1811
	select_options select_item_list select_into select_lock_type;
1812

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1813
select_into:
1814 1815 1816 1817 1818 1819
	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
1820
	| select_from
1821 1822
	| into select_from
	| select_from into;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1823 1824

select_from:
1825
	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
1826 1827 1828

select_options:
	/* empty*/
1829
	| select_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1830 1831 1832

select_option_list:
	select_option_list select_option
1833
	| select_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1834 1835

select_option:
1836
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1837 1838 1839 1840 1841 1842
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1843 1844 1845
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857
	| 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;
	  }
1858
	| SQL_NO_CACHE_SYM { Lex->uncacheable(); }
1859 1860 1861
	| SQL_CACHE_SYM    { Select->options|= OPTION_TO_QUERY_CACHE; }
	| ALL		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1862

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1863 1864 1865
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1866 1867
	  {
	    LEX *lex=Lex;
1868
	    lex->current_select->set_lock_for_tables(TL_WRITE);
1869
	    lex->safe_to_cache_query=0;
1870
	  }
1871
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1872 1873
	  {
	    LEX *lex=Lex;
1874 1875
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
1876
	    lex->safe_to_cache_query=0;
1877 1878
	  }
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
1879

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1880 1881 1882 1883 1884
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
1885 1886
	    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
1887
	      YYABORT;
1888
	    (thd->lex.current_select->select_lex()->with_wild)++;
1889
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1890 1891 1892 1893 1894


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1895
	    if (add_item_to_list(YYTHD, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1896 1897 1898 1899 1900
	      YYABORT;
	    if ($4.str)
	      $2->set_name($4.str);
	    else if (!$2->name)
	      $2->set_name($1,(uint) ($3 - $1));
1901
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1902 1903

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

remember_end:
1907
	{ $$=(char*) Lex->tok_end; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1908 1909 1910

select_item2:
	table_wild	{ $$=$1; } /* table.* */
1911
	| expr		{ $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1912 1913 1914 1915 1916 1917

select_alias:
	{ $$.str=0;}
	| AS ident { $$=$2; }
	| AS TEXT_STRING  { $$=$2; }
	| ident { $$=$1; }
1918
	| TEXT_STRING  { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1919 1920 1921

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1924
/* all possible expressions */
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1925 1926 1927 1928
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1929

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
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
1942 1943
/* expressions that begin with 'expr' */
expr_expr:
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1944
	 expr IN_SYM '(' expr_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1945 1946 1947
	  { $$= 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
1948
        | expr IN_SYM in_subselect
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1949
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1950
	| expr NOT IN_SYM in_subselect
1951
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1952
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1953
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1954 1955 1956 1957
	| 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)); }
1958
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1959
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
1960
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1961
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
1962
	| 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
1963 1964 1965 1966 1967 1968 1969
	| 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
1970 1971 1972
	| expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| expr comp_op all_or_any in_subselect %prec EQ
	{
1973
	  Item_allany_subselect *it=
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1974
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1975 1976 1977 1978 1979
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1980 1981 1982 1983 1984 1985
	| 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); }
1986 1987
	| 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
1988
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
1989
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1990 1991
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
1992 1993 1994 1995
	| 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); }
1996
	| expr COLLATE_SYM ident_or_text
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
1997 1998 1999 2000 2001
	  { 
	    $$= 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
2002 2003 2004 2005 2006 2007 2008

/* 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)); }
2009
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2010
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
2011
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2012
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
2013
	| 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
2014 2015 2016 2017 2018 2019 2020
	| 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
2021 2022 2023
	| no_in_expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
2024
	  Item_allany_subselect *it=
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2025
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2026 2027 2028 2029 2030
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2031 2032 2033 2034 2035 2036
	| 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); }
2037
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2038
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2039
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2040 2041
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2042
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2043 2044 2045 2046
	| 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); }
2047
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2048 2049 2050

/* 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
2051 2052
	  no_and_expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2053 2054
	| 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
2055
        | no_and_expr IN_SYM in_subselect
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2056
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2057
	| no_and_expr NOT IN_SYM in_subselect
2058
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2059
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2060
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2061 2062 2063 2064
	| 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)); }
2065
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2066
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
2067
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
2068
	| 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
2069 2070 2071 2072 2073 2074 2075
	| 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
2076 2077 2078
	| no_and_expr comp_op expr %prec EQ { $$= (*((*$2)(0)))($1,$3); }
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
2079
	  Item_allany_subselect *it=
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2080
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2081 2082 2083 2084 2085
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2086 2087 2088 2089 2090 2091
	| 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); }
2092
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2093
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2094
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2095 2096
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2097
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2098 2099 2100 2101
	| 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); }
2102
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2103

2104
interval_expr:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2105
         INTERVAL_SYM expr { $$=$2; }
2106 2107
        ;

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

udf_expr_list:
	/* empty */	{ $$= NULL; }
2487
	| expr_list	{ $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2488 2489 2490 2491 2492 2493 2494 2495

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); }
2496
	| COUNT_SYM '(' opt_all '*' ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509
	  { $$=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); }
2510 2511
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2512
	| SUM_SYM '(' in_sum_expr ')'
2513
	  { $$=new Item_sum_sum($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2514 2515

in_sum_expr:
2516
	opt_all
2517 2518 2519 2520 2521
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
2522
	    YYABORT;
2523 2524
	  }
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2525 2526
	expr
	{
2527
	  Select->select_lex()->in_sum_expr--;
2528
	  $$= $3;
2529
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2530

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2531
cast_type:
2532
	BINARY			{ $$=ITEM_CAST_BINARY; }
2533
	| CHAR_SYM		{ $$=ITEM_CAST_CHAR; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2534 2535 2536 2537 2538 2539
	| 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; }
2540 2541
	| DATETIME		{ $$=ITEM_CAST_DATETIME; }
	;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2542

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2543
expr_list:
2544
	{ Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2545
	expr_list2
2546
	{ $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2547 2548

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

2552 2553
ident_list_arg:
          ident_list          { $$= $1; }
2554
        | '(' ident_list ')'  { $$= $2; };
2555

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2556
ident_list:
2557
        { Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2558
        ident_list2
2559
        { $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2560 2561

ident_list2:
2562
        simple_ident { Select->expr_list.head()->push_back($1); }
2563
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2564 2565 2566

opt_expr:
	/* empty */      { $$= NULL; }
2567
	| expr         	 { $$= $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2568 2569 2570

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

when_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2574
        { Select->when_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2575
	when_list2
2576
	{ $$= Select->when_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2577 2578

when_list2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2579
	expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2580
	  {
2581
	    SELECT_LEX_NODE *sel=Select;
2582 2583
	    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
2584
	}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2585
	| when_list2 WHEN_SYM expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2586
	  {
2587
	    SELECT_LEX_NODE *sel=Select;
2588 2589
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
2590
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2591 2592

opt_pad:
2593
	/* empty */ { $$=new Item_string(" ",1,default_charset_info); }
2594
	| expr	    { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2595 2596 2597 2598

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
2599
	| join_table_list ',' join_table_list { $$=$3; }
2600
	| join_table_list normal_join join_table_list { $$=$3; }
2601 2602
	| join_table_list STRAIGHT_JOIN join_table_list
	  { $$=$3 ; $$->straight=1; }
2603 2604 2605 2606
	| 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 
2607
	  {
2608
	    SELECT_LEX *sel= Select->select_lex();
2609
	    sel->db1=$1->db; sel->table1=$1->alias;
2610
	    sel->db2=$3->db; sel->table2=$3->alias;
2611
	  }
2612 2613 2614
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

2615
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2616
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2617
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
2618
	  {
2619
	    SELECT_LEX *sel= Select->select_lex();
2620 2621
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2622
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2623
	  USING '(' using_list ')'
2624
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2625
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2626
	  { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
2627
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2628
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2629
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
2630
	  {
2631
	    SELECT_LEX *sel= Select->select_lex();
2632 2633
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
2634
	  }
2635 2636
	  USING '(' using_list ')'
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2637
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2638
	  { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2639
	| join_table_list NATURAL JOIN_SYM join_table_list
2640
	  { add_join_natural($1,$4); $$=$4; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2641 2642

normal_join:
2643 2644 2645 2646
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2647 2648

join_table:
2649
	{
2650
	  SELECT_LEX *sel= Select->select_lex();
2651
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2652
	  sel->table_join_options= 0;
2653
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2654
        table_ident opt_table_alias opt_key_definition
2655
	{
2656 2657
	  LEX *lex= Lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2658
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2659
					   sel->get_table_join_options(),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2660
					   lex->lock_option,
2661 2662
					   sel->get_use_index(),
					   sel->get_ignore_index())))
2663
	    YYABORT;
2664
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2665
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2666
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
2667
        | '(' SELECT_SYM select_derived ')' opt_table_alias
2668 2669
	{
	  LEX *lex=Lex;
2670 2671 2672
	  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
2673
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
2674
				  TL_READ,(List<String> *)0,
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
2675 2676
	                          (List<String> *)0)))

2677
	    YYABORT;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
2678
	};
2679

2680
select_derived:
2681
        {
2682
	  LEX *lex= Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2683
	  lex->derived_tables= 1;
2684 2685 2686 2687 2688 2689
	  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;
	  }
2690
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
2691
              mysql_new_select(lex, 1))
2692 2693
	    YYABORT;
	  mysql_init_select(lex);
2694
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
2695
	}
2696
        select_options select_item_list opt_select_from union_opt
2697
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2698 2699 2700

opt_outer:
	/* empty */	{}
2701
	| OUTER		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2702 2703 2704 2705

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
2706
          {
2707
	    SELECT_LEX *sel= Select->select_lex();
2708 2709 2710
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2711 2712 2713 2714 2715 2716 2717
	| 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
2718
	| IGNORE_SYM key_usage_list
2719
	  {
2720
	    SELECT_LEX *sel= Select->select_lex();
2721 2722
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
2723
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2724 2725

key_usage_list:
2726
	key_or_index { Select->select_lex()->interval_list.empty(); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2727 2728 2729 2730 2731 2732 2733 2734
        '(' 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
2735 2736 2737

key_usage_list2:
	key_usage_list2 ',' ident
2738
        { Select->select_lex()->
2739 2740
	    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
2741
	| ident
2742
        { Select->select_lex()->
2743 2744
	    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
2745
	| PRIMARY_SYM
2746
        { Select->select_lex()->
2747 2748
	    interval_list.push_back(new String("PRIMARY", 7,
				    default_charset_info)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2749 2750 2751

using_list:
	ident
2752
	  {
2753
	    SELECT_LEX *sel= Select->select_lex();
2754 2755 2756 2757
	    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
2758 2759 2760 2761
	      YYABORT;
	  }
	| using_list ',' ident
	  {
2762
	    SELECT_LEX *sel= Select->select_lex();
2763
	    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
2764
	      YYABORT;
2765
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779

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; }
2780
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2781 2782 2783 2784

table_alias:
	/* empty */
	| AS
2785
	| EQ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2786 2787 2788 2789

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

2792 2793 2794 2795
opt_all:
	/* empty */
	| ALL
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2796 2797

where_clause:
2798
	/* empty */  { Select->select_lex()->where= 0; }
2799 2800
	| WHERE expr
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2801
	    Select->select_lex()->where= $2;
2802 2803 2804
	    if ($2)
	      $2->top_level_item();
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2805
 	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2806 2807 2808

having_clause:
	/* empty */
2809
	| HAVING { Select->select_lex()->create_refs= 1; } expr
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2810 2811 2812 2813 2814 2815
	  {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->having= $3; sel->create_refs=0;
	    if ($3)
	      $3->top_level_item();
	  }
2816
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2817 2818 2819

opt_escape:
	ESCAPE_SYM TEXT_STRING	{ $$= $2.str; }
2820
	| /* empty */		{ $$= (char*) "\\"; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2821 2822 2823


/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2824
   group by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2825 2826 2827 2828
*/

group_clause:
	/* empty */
2829
	| GROUP BY group_list olap_opt;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2830 2831

group_list:
2832
	group_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2833
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
2834
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2835
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2836

2837 2838
olap_opt:
	/* empty */ {}
2839
	| WITH CUBE_SYM
2840
          {
2841
	    LEX *lex=Lex;
2842 2843 2844 2845 2846 2847
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE",
		       "global union parameters");
	      YYABORT;
	    }
2848
	    lex->current_select->select_lex()->olap= CUBE_TYPE;
2849
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
2850
	    YYABORT;	/* To be deleted in 4.1 */
2851
	  }
2852
	| WITH ROLLUP_SYM
2853
          {
2854 2855 2856 2857 2858 2859 2860
	    LEX *lex= Lex;
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP",
		       "global union parameters");
	      YYABORT;
	    }
2861
	    lex->current_select->select_lex()->olap= ROLLUP_TYPE;
2862
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "ROLLUP");
2863
	    YYABORT;	/* To be deleted in 4.1 */
2864
	  }
2865
	;
2866

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2867
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2868
   Order by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2869 2870
*/

2871
opt_order_clause:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2872
	/* empty */
2873
	| order_clause;
2874 2875

order_clause:
2876 2877
	ORDER_SYM BY
        {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2878
	  LEX *lex=Lex;
2879
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
2880
	      lex->current_select->select_lex()->olap !=
2881
	      UNSPECIFIED_OLAP_TYPE)
2882
	  {
2883
	    net_printf(lex->thd, ER_WRONG_USAGE,
2884 2885 2886 2887
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
2888
	} order_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2889 2890 2891

order_list:
	order_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2892
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2893
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2894
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2895 2896 2897

order_dir:
	/* empty */ { $$ =  1; }
2898
	| ASC  { $$ =1; }
2899
	| DESC { $$ =0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2900 2901


2902 2903 2904 2905 2906 2907 2908
opt_limit_clause_init:
	/* empty */
	{
	  SELECT_LEX_NODE *sel= Select;
          sel->offset_limit= 0L;
          sel->select_limit= Lex->thd->variables.select_limit;
	}
2909 2910 2911
	| limit_clause {}
	;

2912 2913 2914 2915 2916
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

2917
limit_clause:
2918
	LIMIT
2919
	  {
2920 2921
	    LEX *lex= Lex;
	    if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
2922
	        lex->current_select->select_lex()->olap !=
2923
		UNSPECIFIED_OLAP_TYPE)
2924
	    {
2925
	      net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
2926
		        "LIMIT");
2927
	      YYABORT;
2928
	    }
2929
	  }
2930
	  limit_options
2931
	  {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2932
	;
2933 2934 2935

limit_options:
	ULONG_NUM
2936
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2937
            SELECT_LEX_NODE *sel= Select;
2938 2939 2940 2941 2942
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
2943
	    SELECT_LEX_NODE *sel= Select;
2944 2945
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
2946
	  }
2947
	| ULONG_NUM OFFSET_SYM ULONG_NUM
2948
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2949
	    SELECT_LEX_NODE *sel= Select;
2950 2951 2952 2953
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2954 2955 2956 2957 2958


delete_limit_clause:
	/* empty */
	{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2959
	  LEX *lex=Lex;
2960
	  lex->current_select->select_limit= HA_POS_ERROR;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2961
	}
2962
	| LIMIT ulonglong_num
2963
	{ Select->select_limit= (ha_rows) $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2964 2965

ULONG_NUM:
2966
	NUM	    { $$= strtoul($1.str,NULL,10); }
2967
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2968
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
2969
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
2970
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2971

2972
ulonglong_num:
2973
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2974
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
2975
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
2976
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
2977
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2978 2979 2980 2981 2982 2983

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
2984 2985 2986 2987 2988 2989 2990
	    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
2991 2992 2993
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
2994
	    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
2995
	      YYABORT;
2996
	    Lex->uncacheable();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2997
	  }
2998
	  '(' procedure_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2999 3000 3001 3002


procedure_list:
	/* empty */ {}
3003
	| procedure_list2 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3004 3005 3006

procedure_list2:
	procedure_list2 ',' procedure_item
3007
	| procedure_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3008 3009 3010 3011

procedure_item:
	  remember_name expr
	  {
3012 3013
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3014 3015
	      YYABORT;
	    if (!$2->name)
3016
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1));
3017 3018 3019 3020 3021 3022
	  }
          ;


select_var_list_init:
	   {
3023 3024
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3025 3026
	        YYABORT;
	   }
3027
	   select_var_list
3028
	   {}
3029
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3030

Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3031
select_var_list:
3032 3033 3034 3035 3036
	   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
3037
           {
3038
             LEX *lex=Lex;
3039
	     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
3040 3041
	       YYABORT;
	   }
3042
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3043

3044
into:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3045
        INTO OUTFILE TEXT_STRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3046
	{
3047
	  LEX *lex=Lex;
3048 3049 3050 3051 3052 3053 3054
	  if (!lex->describe)
	  {
	    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
3055 3056 3057 3058
	}
	opt_field_term opt_line_term
	| INTO DUMPFILE TEXT_STRING
	{
3059
	  LEX *lex=Lex;
3060 3061 3062 3063 3064 3065 3066
	  if (!lex->describe)
	  {
	    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
3067
	}
3068
        | INTO select_var_list_init
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3069
	{
3070
	  Lex->uncacheable();
3071 3072
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3073

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3074 3075 3076
/*
  DO statement
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3077

3078
do:	DO_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3079 3080 3081 3082 3083 3084
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
3085 3086 3087 3088
	values
	{}
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3089
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3090
  Drop : delete tables or index
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3091 3092 3093
*/

drop:
3094
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3095
	{
3096 3097
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3098 3099
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3100 3101 3102
	}
	| DROP INDEX ident ON table_ident {}
	  {
3103 3104 3105 3106
	     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
3107
						     $3.str));
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3108 3109
	     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
3110 3111 3112 3113
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
3114 3115 3116 3117
	    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
3118
	 }
3119
	| DROP UDF_SYM IDENT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3120
	  {
3121 3122
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3123
	    lex->udf.name = $3;
3124
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3125 3126 3127


table_list:
3128
	table_name
3129
	| table_list ',' table_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3130

3131
table_name:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3132
	table_ident
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3133 3134 3135 3136 3137
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3138 3139

if_exists:
3140
	/* empty */ { $$= 0; }
3141 3142
	| IF EXISTS { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3143

3144 3145 3146 3147
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3148 3149 3150 3151 3152
/*
** Insert : add new data to table
*/

insert:
3153 3154 3155 3156 3157 3158 3159
	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
3160
	opt_ignore insert2
3161
	{
3162
	  Select->set_lock_for_tables($3);
3163
	}
3164
	insert_field_spec opt_insert_update
3165
	{}
3166
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3167 3168

replace:
3169 3170
	REPLACE
	{
3171
	  LEX *lex=Lex;
3172 3173 3174
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
3175 3176
	replace_lock_option insert2
	{
3177
	  Select->set_lock_for_tables($3);
3178 3179
	}
	insert_field_spec
3180
	{}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3181
	{}
3182
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3183 3184

insert_lock_option:
3185 3186 3187 3188
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3189
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3190 3191

replace_lock_option:
3192 3193
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3194 3195 3196

insert2:
	INTO insert_table {}
3197
	| insert_table {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3198 3199

insert_table:
3200
	table_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3201
	{
3202 3203 3204 3205
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
3206
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3207 3208 3209 3210 3211

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
3212 3213 3214
	    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
3215 3216
	      YYABORT;
	   }
3217
	   ident_eq_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3218 3219 3220 3221

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
3222
	| '(' ')'	  { };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3223 3224 3225

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
3226
	| insert_ident		{ Lex->field_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3227 3228 3229

insert_values:
	VALUES	values_list  {}
3230
	| VALUE_SYM values_list  {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3231 3232 3233 3234 3235
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
3236
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3237
	    mysql_init_select(lex);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3238
	  }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3239
	  select_options select_item_list opt_select_from select_lock_type
3240
          union_clause {}
3241
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3242 3243 3244

values_list:
	values_list ','  no_braces
3245
	| no_braces;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3246 3247 3248 3249

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
3250
	ident_eq_value;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3251 3252

ident_eq_value:
3253
	simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3254
	 {
3255 3256 3257
	  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
3258
	    YYABORT;
3259
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3260 3261

equal:	EQ		{}
3262 3263 3264 3265 3266 3267 3268
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3269 3270 3271 3272 3273 3274 3275 3276 3277

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
3278 3279
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3280
	    YYABORT;
3281
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3282 3283 3284

opt_values:
	/* empty */ {}
3285
	| values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3286 3287

values:
3288
	values ','  expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3289 3290 3291 3292
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
3293 3294 3295 3296 3297 3298 3299 3300
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3301
	expr	  { $$= $1;}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3302
	| DEFAULT {$$= new Item_default_value(); }
3303
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3304

3305 3306
opt_insert_update:
        /* empty */
3307
        | ON DUPLICATE_SYM
3308 3309 3310 3311 3312 3313 3314 3315 3316
          { /* 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;
            }
          }
3317
          KEY_SYM UPDATE_SYM update_list
3318 3319
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3320 3321 3322
/* Update rows in a table */

update:
3323 3324
	UPDATE_SYM
	{
3325 3326
	  LEX *lex= Lex;
          lex->sql_command= SQLCOM_UPDATE;
3327
          lex->select_lex.init_order();
3328
        }
3329 3330 3331
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3332
	  LEX *lex= Lex;
3333
	  Select->set_lock_for_tables($3);
3334
          if (lex->select_lex.table_list.elements > 1)
3335
            lex->sql_command=SQLCOM_UPDATE_MULTI;
3336 3337
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3338 3339

update_list:
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3340
	update_list ',' simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3341
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3342
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3343 3344
	    YYABORT;
	}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3345
	| simple_ident equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3346
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3347
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3348
	      YYABORT;
3349
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3350 3351

opt_low_priority:
3352
	/* empty */	{ $$= YYTHD->update_lock_default; }
3353
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3354 3355 3356 3357

/* Delete rows from a table */

delete:
3358
	DELETE_SYM
3359
	{
3360 3361 3362
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
	  lex->select_lex.options= 0;
3363
	  lex->lock_option= lex->thd->update_lock_default;
3364
	  lex->select_lex.init_order();
3365
	}
3366 3367
	opt_delete_options single_multi {}
	;
3368 3369

single_multi:
3370 3371
 	FROM table_ident
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3372 3373
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
3374 3375 3376
	    YYABORT;
	}
	where_clause opt_order_clause
3377
	delete_limit_clause {}
3378
	| table_wild_list
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3379
	  { mysql_init_multi_delete(Lex); }
3380
          FROM join_table_list where_clause
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3381 3382
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3383 3384 3385
	  USING join_table_list where_clause
	  {}
	;
3386 3387 3388

table_wild_list:
	  table_wild_one {}
3389
	  | table_wild_list ',' table_wild_one {};
3390 3391

table_wild_one:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3392
	ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3393
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3394 3395
	  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
3396 3397
	    YYABORT;
        }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3398
	| ident '.' ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3399
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3400
	    if (!Select->add_table_to_list(YYTHD, new Table_ident($1, $3, 0),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3401 3402
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
3403
	      YYABORT;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3404
	  }
3405
	;
3406 3407

opt_wild:
3408
	/* empty */	{}
3409
	| '.' '*'	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3410 3411


3412
opt_delete_options:
3413
	/* empty */	{}
3414
	| opt_delete_option opt_delete_options {};
3415 3416

opt_delete_option:
3417
	QUICK		{ Select->options|= OPTION_QUICK; }
3418
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
3419

3420
truncate:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3421
	TRUNCATE_SYM opt_table_sym table_name
3422
	{
3423
	  LEX* lex= Lex;
3424
	  lex->sql_command= SQLCOM_TRUNCATE;
3425
	  lex->select_lex.options= 0;
3426
	  lex->select_lex.init_order();
3427 3428
	}
	;
3429

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3430 3431
opt_table_sym:
	/* empty */
3432
	| TABLE_SYM;
3433

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3434 3435
/* Show things */

3436 3437
show:	SHOW
	{
3438 3439 3440 3441
	  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
3442
	show_param
3443 3444
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3445 3446 3447 3448 3449

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
3450
	  {
3451
	    LEX *lex= Lex;
3452
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3453 3454
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
3455
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3456
	| TABLE_SYM STATUS_SYM opt_db wild
3457
	  {
3458
	    LEX *lex= Lex;
3459
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3460 3461
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3462
	  }
3463
	| OPEN_SYM TABLES opt_db wild
3464
	  {
3465
	    LEX *lex= Lex;
3466
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
3467 3468
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
3469
	  }
3470
	| opt_full COLUMNS from_or_in table_ident opt_db wild
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3471 3472
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3473 3474
	    if ($5)
	      $4->change_db($5);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3475
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3476 3477
	      YYABORT;
	  }
3478
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
3479 3480
	  TEXT_STRING AND MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND MASTER_SERVER_ID_SYM EQ
3481 3482 3483 3484 3485
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
3486
	    Lex->mi.server_id = $16;
3487
          }
3488
        | BINARY LOGS_SYM
3489 3490
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
3491 3492 3493 3494 3495
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
3496
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
3497
          {
3498 3499
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
3500
          } opt_limit_clause_init
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3501 3502 3503 3504 3505
	| 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
3506
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3507 3508
	      YYABORT;
	  }
3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523
	| 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;
	  }
3524
        | COUNT_SYM '(' '*' ')' WARNINGS
3525
          { (void) create_select_for_variable("warning_count"); }
3526
        | COUNT_SYM '(' '*' ')' ERRORS
3527
	  { (void) create_select_for_variable("error_count"); }
3528
        | WARNINGS opt_limit_clause_init
3529
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
3530
        | ERRORS opt_limit_clause_init
3531
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3532 3533
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
3534 3535
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3536 3537
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
3538
	| opt_var_type VARIABLES wild
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
3539
	  {
3540
	    THD *thd= YYTHD;
3541
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
3542
	    thd->lex.option_type= (enum_var_type) $1;
3543
	  }
3544
	| charset wild
3545
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
tim@cane.mysql.fi's avatar
tim@cane.mysql.fi committed
3546 3547
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3548
	| GRANTS FOR_SYM user
3549 3550 3551 3552 3553 3554
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
3555
	| CREATE DATABASE opt_if_not_exists ident
3556 3557
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
3558 3559
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
3560
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3561 3562 3563
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3564
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3565 3566 3567 3568 3569
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3570
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3571 3572 3573
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
3574
          };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3575 3576 3577

opt_db:
	/* empty */  { $$= 0; }
3578
	| from_or_in ident { $$= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3579 3580 3581

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

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3584 3585
opt_full:
	/* empty */ { Lex->verbose=0; }
3586
	| FULL	    { Lex->verbose=1; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3587

3588 3589
from_or_in:
	FROM
3590
	| IN_SYM;
3591

3592 3593
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
3594
        | IN_SYM TEXT_STRING { Lex->mi.log_file_name = $2.str; };
3595 3596 3597

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


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3601 3602 3603 3604
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
3605 3606 3607 3608
	  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
3609
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3610 3611
	    YYABORT;
	}
3612
	opt_describe_column {}
3613
	| describe_command { Lex->describe=1; } select
3614
          {
3615
	    LEX *lex=Lex;
3616
	    lex->select_lex.options|= SELECT_DESCRIBE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3617 3618
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3619 3620 3621

describe_command:
	DESC
3622
	| DESCRIBE;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3623 3624 3625 3626

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
3627
	| ident
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3628
	  { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3629 3630 3631 3632 3633


/* flush things */

flush:
3634 3635 3636 3637 3638
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
3639 3640 3641
	flush_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3642 3643 3644

flush_options:
	flush_options ',' flush_option
3645
	| flush_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3646 3647

flush_option:
3648
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3649
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3650
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3651 3652 3653 3654
	| 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
3655 3656
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3657 3658
	| 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
3659

3660
opt_table_list:
3661 3662
	/* empty */  {;}
	| table_list {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3663

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3664
reset:
3665 3666 3667 3668
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
3669 3670 3671 3672
	} reset_options
	{}
	;

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3673 3674
reset_options:
	reset_options ',' reset_option
3675
	| reset_option;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3676 3677

reset_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3678 3679
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
3680
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3681

3682
purge:
3683 3684 3685 3686 3687 3688
	PURGE
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_PURGE;
	  lex->type=0;
	}
3689 3690 3691
        MASTER_SYM LOGS_SYM TO_SYM TEXT_STRING
         {
	   Lex->to_log = $6.str;
3692
         } ;
3693

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3694 3695 3696
/* kill threads */

kill:
3697
	KILL_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3698
	{
3699
	  LEX *lex=Lex;
3700
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
3701
	  {
3702
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
3703 3704 3705 3706
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
3707
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3708 3709 3710 3711

/* change database */

use:	USE_SYM ident
3712 3713
	{
	  LEX *lex=Lex;
3714 3715
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
3716
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3717 3718 3719

/* import, export of files */

3720
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3721
	{
3722 3723
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
3724 3725
	  lex->lock_option= $3;
	  lex->local_file=  $4;
3726
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3727
	    YYABORT;
3728
	  lex->field_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3729 3730 3731 3732
	}
	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
3733
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3734 3735 3736
	    YYABORT;
	}
        |
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3737
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3738 3739
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3740
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3741
	    YYABORT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3742 3743

        }
3744 3745 3746 3747
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
3748
        };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3749 3750 3751

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

3754
load_data_lock:
3755
	/* empty */	{ $$= YYTHD->update_lock_default; }
3756 3757
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
3758 3759


bk@work.mysql.com's avatar
bk@work.mysql.com committed
3760 3761 3762
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
3763
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3764 3765 3766

opt_field_term:
	/* empty */
3767
	| COLUMNS field_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3768 3769 3770

field_term_list:
	field_term_list field_term
3771
	| field_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3772 3773 3774 3775

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
3776 3777 3778 3779 3780
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3781
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
3782
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3783 3784 3785

opt_line_term:
	/* empty */
3786
	| LINES line_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3787 3788 3789

line_term_list:
	line_term_list line_term
3790
	| line_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3791 3792 3793

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
3794
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3795 3796 3797 3798

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
3799
	  { Lex->exchange->skip_lines=atol($2.str); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3800 3801 3802 3803

/* Common definitions */

text_literal:
3804 3805 3806 3807
	TEXT_STRING
	{ $$ = new Item_string($1.str,$1.length,
			       YYTHD->variables.thd_charset); }
	| UNDERSCORE_CHARSET TEXT_STRING
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3808
	  { $$ = new Item_string($2.str,$2.length,Lex->charset,Item::COER_IMPLICIT); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3809
	| text_literal TEXT_STRING
3810
	  { ((Item_string*) $1)->append($2.str,$2.length); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3811 3812

text_string:
3813 3814
	TEXT_STRING
	{ $$=  new String($1.str,$1.length,YYTHD->variables.thd_charset); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3815 3816
	| HEX_NUM
	  {
3817
	    Item *tmp = new Item_varbinary($1.str,$1.length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3818
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
3819 3820 3821
	  }
	;

3822
param_marker:
3823
        '?'
3824
        {
3825
	  LEX *lex=Lex;
3826
          if (YYTHD->prepare_command)
3827 3828
          {
            lex->param_list.push_back($$=new Item_param());
3829
            lex->param_count++;
3830
          }
3831
          else
3832 3833 3834 3835
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
3836 3837 3838
        }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3839 3840
literal:
	text_literal	{ $$ =	$1; }
3841 3842
	| 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); }
3843
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3844 3845 3846 3847
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
			  Lex->next_state=STATE_OPERATOR_OR_IDENT;}
3848
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3849 3850
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
3851
	| TIMESTAMP text_literal { $$ = $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3852 3853 3854 3855 3856 3857 3858

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

insert_ident:
	simple_ident	 { $$=$1; }
3859
	| table_wild	 { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3860 3861

table_wild:
3862 3863 3864 3865 3866
	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
3867
	| ident '.' ident '.' '*'
3868 3869 3870 3871 3872 3873 3874
	{
	  $$ = 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
3875 3876

order_ident:
3877
	expr { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3878 3879 3880

simple_ident:
	ident
3881
	{
3882 3883
	  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);
3884
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3885
	| ident '.' ident
3886
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3887 3888 3889 3890 3891 3892 3893 3894 3895
	  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);
	  }
3896
	  $$ = !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);
3897
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3898
	| '.' ident '.' ident
3899
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3900 3901 3902 3903 3904 3905 3906 3907 3908
	  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);
	  }
3909
	  $$ = !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);
3910
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3911
	| ident '.' ident '.' ident
3912
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3913 3914 3915 3916 3917 3918 3919 3920 3921
	  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);
	  }
3922
	  $$ = !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);
3923
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3924 3925 3926 3927 3928


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
3929
	| '.' ident		{ $$=$2;}	/* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3930 3931 3932 3933

table_ident:
	ident			{ $$=new Table_ident($1); }
	| ident '.' ident	{ $$=new Table_ident($1,$3,0);}
3934 3935
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3936 3937 3938 3939 3940

ident:
	IDENT	    { $$=$1; }
	| keyword
	{
3941 3942
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3943
	  $$.length=$1.length;
3944
	  if (lex->next_state != STATE_END)
3945
	    lex->next_state=STATE_OPERATOR_OR_IDENT;
3946 3947
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3948 3949 3950

ident_or_text:
	ident 		{ $$=$1;}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3951
	| TEXT_STRING	{ $$=$1;}
3952
	| LEX_HOSTNAME	{ $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3953 3954 3955 3956

user:
	ident_or_text
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3957 3958
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3959 3960 3961 3962 3963
	    YYABORT;
	  $$->user = $1; $$->host.str=NullS;
	  }
	| ident_or_text '@' ident_or_text
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3964 3965
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3966 3967
	      YYABORT;
	    $$->user = $1; $$->host=$3;
3968
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3969 3970 3971 3972 3973 3974

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
3975
	| AGAINST		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3976
	| AGGREGATE_SYM		{}
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3977
	| ANY_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3978
	| ASCII_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3979
	| AUTO_INC		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3980 3981
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
3982
	| BACKUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3983
	| BEGIN_SYM		{}
3984
	| BERKELEY_DB_SYM	{}
3985
	| BINLOG_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3986 3987
	| BIT_SYM		{}
	| BOOL_SYM		{}
3988
	| BOOLEAN_SYM		{}
3989
	| BYTE_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3990
	| CACHE_SYM		{}
3991
	| CHANGED		{}
3992
	| CHARSET		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3993
	| CHECKSUM_SYM		{}
3994
	| CIPHER_SYM		{}
3995
	| CLIENT_SYM		{}
3996
	| CLOSE_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3997
	| COLLATION_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3998
	| COMMENT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3999
	| COMMITTED_SYM		{}
4000
	| COMMIT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4001
	| COMPRESSED_SYM	{}
4002
	| CONCURRENT		{}
4003
	| CUBE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4004 4005 4006 4007 4008
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
4009 4010
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4011
	| DO_SYM		{}
4012
	| DUAL_SYM		{}
4013 4014
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4015 4016 4017 4018
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
4019
	| EVENTS_SYM		{}
4020
	| EXECUTE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4021
	| EXTENDED_SYM		{}
4022
	| FAST_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4023 4024
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4025
	| FULL			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4026 4027 4028 4029
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
4030
	| GEOMETRY_SYM		{}
4031
	| GEOMETRYCOLLECTION	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4032
	| GRANTS		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4033
	| GLOBAL_SYM		{}
4034
	| HANDLER_SYM		{}
4035 4036
	| HEAP_SYM		{}
	| HELP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4037 4038 4039
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
4040
	| INDEXES		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4041
	| ISOLATION		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4042
	| ISAM_SYM		{}
4043
	| ISSUER_SYM		{}
4044
	| INNOBASE_SYM		{}
4045
	| INSERT_METHOD		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4046
	| IO_THREAD		{}
4047
	| LAST_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4048
	| LEVEL_SYM		{}
4049
	| LINESTRING		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4050
	| LOCAL_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4051
	| LOCKS_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4052 4053 4054 4055 4056 4057 4058 4059 4060 4061
	| 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
4062 4063 4064
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
4065
	| MEDIUM_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4066 4067 4068 4069
	| MERGE_SYM		{}
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4070
	| MODE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4071
	| MONTH_SYM		{}
4072 4073 4074
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4075
	| MYISAM_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4076
	| NAMES_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4077 4078
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
4079
	| NEXT_SYM		{}
4080
	| NEW_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4081
	| NO_SYM		{}
4082
	| NONE_SYM		{}
4083
	| OFFSET_SYM		{}
4084
	| OPEN_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4085
	| PACK_KEYS_SYM		{}
4086
	| PARTIAL		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4087
	| PASSWORD		{}
4088
	| POINT_SYM		{}
4089
	| POLYGON		{}
4090
	| PREV_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4091 4092
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4093
	| QUERY_SYM		{}
4094
	| QUICK			{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4095
	| RAID_0_SYM		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4096 4097
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4098
	| RAID_STRIPED_SYM	{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4099
	| RAID_TYPE		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4100 4101
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4102 4103
	| RELOAD		{}
	| REPAIR		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4104
	| REPEATABLE_SYM	{}
4105
	| REPLICATION		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4106
	| RESET_SYM		{}
4107
	| RESOURCES		{}
4108
	| RESTORE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4109
	| ROLLBACK_SYM		{}
4110
	| ROLLUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4111 4112 4113 4114
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
	| SECOND_SYM		{}
4115
	| SERIAL_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4116 4117
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4118
	| SIGNED_SYM		{}
4119
	| SIMPLE_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4120
	| SHARE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4121
	| SHUTDOWN		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4122
	| SLAVE			{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4123
	| SQL_CACHE_SYM		{}
4124
	| SQL_BUFFER_RESULT	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4125
	| SQL_NO_CACHE_SYM	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4126
	| SQL_THREAD		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4127 4128 4129 4130
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
4131
	| SUBJECT_SYM		{}
4132
	| SUPER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4133 4134
	| TEMPORARY		{}
	| TEXT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4135
	| TRANSACTION_SYM	{}
4136
	| TRUNCATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4137 4138 4139 4140
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4141
	| UNCOMMITTED_SYM	{}
4142
	| UNICODE_SYM		{}
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4143
	| USE_FRM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4144
	| VARIABLES		{}
4145
	| VALUE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4146
	| WORK_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4147
	| YEAR_SYM		{}
4148
	| SOUNDS_SYM            {}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4149
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4150 4151 4152 4153 4154 4155

/* Option functions */

set:
	SET opt_option
	{
4156 4157
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
4158 4159
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4160
	}
4161 4162 4163
	option_value_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4164 4165 4166

opt_option:
	/* empty */ {}
4167
	| OPTION {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4168 4169

option_value_list:
4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181
	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
4182
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
4183 4184 4185 4186 4187 4188
	| 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
4189
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
4190 4191 4192
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4193 4194

option_value:
4195
	'@' ident_or_text equal expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4196
	{
4197
	  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
4198
	}
4199
	| internal_variable_name equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4200
	  {
4201 4202
	    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
4203
	  }
4204
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
4205 4206 4207 4208 4209 4210 4211 4212
	  {
	    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,
4213
						find_sys_var("tx_isolation"),
4214
						new Item_int((int32) $4)));
4215
	  }
4216
	| charset opt_equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4217
	{
4218 4219 4220
	  LEX *lex=Lex;
	  lex->var_list.push_back(new set_var(lex->option_type,
					      find_sys_var("convert_character_set"),
4221
					      $3));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4222
	}
4223
	| NAMES_SYM charset_name_or_default opt_collate
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4224
	{
4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239
	  THD* thd= YYTHD;
	  LEX *lex= &thd->lex;
	  system_variables vars= thd->variables;
	  CHARSET_INFO *cs= $2 ? $2 : thd->db_charset;
	  CHARSET_INFO *cl= $3 ? $3 : cs;

	  if ((cl != cs) && strcmp(cs->csname,cl->csname))
	  {
	      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
4240
	  lex->var_list.push_back(new set_var(lex->option_type,
4241 4242
					      find_sys_var("client_collation"),
					      csname));
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4243
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4244
	| PASSWORD equal text_or_password
4245
	  {
4246
	    THD *thd=YYTHD;
4247
	    LEX_USER *user;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4248
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
4249 4250 4251 4252 4253 4254
	      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
4255
	  {
4256 4257
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
4258
	;
4259

4260 4261 4262 4263 4264 4265 4266 4267
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
4268
        ;
4269 4270 4271 4272 4273 4274 4275

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4277 4278 4279 4280 4281 4282 4283 4284
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
4285
	      char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
4286 4287
	      make_scrambled_password(buff,$3.str,use_old_passwords,
				      &YYTHD->rand);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4288 4289
	      $$=buff;
	    }
4290 4291
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4292

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

4294
set_expr_or_default:
4295 4296
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
4297 4298
	| 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
4299
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
4300
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
4301 4302


bk@work.mysql.com's avatar
bk@work.mysql.com committed
4303 4304 4305 4306 4307 4308 4309
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
4310 4311 4312
	table_lock_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4313 4314 4315

table_or_tables:
	TABLE_SYM
4316
	| TABLES;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4317 4318 4319

table_lock_list:
	table_lock
4320
	| table_lock_list ',' table_lock;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4321 4322 4323

table_lock:
	table_ident opt_table_alias lock_option
4324
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4325
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
4326 4327
	   YYABORT;
	}
4328
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4329 4330 4331

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
4332
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4333
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
4334 4335
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4336 4337

unlock:
4338 4339
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4340 4341


4342
/*
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4343
** Handler: direct access to ISAM functions
4344 4345 4346 4347 4348
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
4349 4350
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4351
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
4352 4353 4354 4355
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
4356 4357
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4358
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4359 4360
	    YYABORT;
	}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4361
	| HANDLER_SYM table_ident READ_SYM
4362
	{
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
4363 4364 4365
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
4366 4367
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4368
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4369
	    YYABORT;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4370
        }
4371
        handler_read_or_scan where_clause opt_limit_clause {}
4372
        ;
4373

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4374 4375
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
4376 4377
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4378 4379 4380

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
4381 4382
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4383 4384 4385 4386 4387 4388

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;  }
4389 4390
	| handler_rkey_mode
	{
4391 4392
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
4393
	  lex->ha_rkey_mode=$1;
4394
	  if (!(lex->insert_list = new List_item))
4395
	    YYABORT;
4396 4397
	} '(' values ')' { }
        ;
4398 4399

handler_rkey_mode:
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
4400 4401 4402 4403
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
4404 4405
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
4406

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4407 4408 4409 4410 4411
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
4412 4413 4414 4415 4416
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
4417
	  lex->select_lex.db=0;
4418 4419
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4420
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4421
	}
4422 4423 4424
	grant_privileges ON opt_table FROM user_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4425 4426 4427 4428

grant:
	GRANT
	{
4429 4430 4431
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
4432 4433
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
4434
	  lex->select_lex.db= 0;
4435 4436
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4437
	  bzero(&(lex->mqh),sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4438 4439
	}
	grant_privileges ON opt_table TO_SYM user_list
4440 4441 4442
	require_clause grant_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4443 4444 4445

grant_privileges:
	grant_privilege_list {}
4446
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
4447 4448
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4449 4450 4451

grant_privilege_list:
	grant_privilege
4452
	| grant_privilege_list ',' grant_privilege;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4453 4454

grant_privilege:
4455 4456 4457 4458
	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 {}
4459 4460
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4461 4462 4463 4464
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
4465
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4466 4467 4468 4469
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
4470 4471 4472 4473 4474 4475 4476 4477
	| 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
4478

4479

4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
4492 4493 4494 4495
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
4496
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
4497 4498 4499 4500 4501 4502 4503 4504 4505
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
4506
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
4507 4508 4509 4510 4511 4512 4513 4514 4515
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
4516
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
4517 4518 4519 4520 4521
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
4522

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4523 4524 4525
opt_table:
	'*'
	  {
4526
	    LEX *lex= Lex;
4527
	    lex->current_select->select_lex()->db= lex->thd->db;
4528
	    if (lex->grant == GLOBAL_ACLS)
4529 4530
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4531
	    {
4532
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
4533
	      YYABORT;
4534
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4535 4536 4537
	  }
	| ident '.' '*'
	  {
4538
	    LEX *lex= Lex;
4539
	    lex->current_select->select_lex()->db = $1.str;
4540
	    if (lex->grant == GLOBAL_ACLS)
4541 4542
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4543
	    {
4544
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4545 4546 4547 4548 4549
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
4550
	    LEX *lex= Lex;
4551
	    lex->current_select->select_lex()->db = NULL;
4552 4553
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
4554
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4555
	    {
4556
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4557 4558 4559 4560 4561
	      YYABORT;
	    }
	  }
	| table_ident
	  {
4562
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4563
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4564
	      YYABORT;
4565
	    if (lex->grant == GLOBAL_ACLS)
4566
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
4567 4568
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4569 4570 4571


user_list:
4572 4573 4574 4575 4576 4577 4578
	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
4579 4580 4581 4582 4583 4584 4585 4586


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
4587
	     char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4588 4589
	     if (buff)
	     {
4590 4591
	       make_scrambled_password(buff,$4.str,use_old_passwords,
				       &YYTHD->rand);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4592 4593 4594 4595 4596 4597 4598 4599
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
4600 4601
	  { $$=$1; $1->password.str=NullS; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4602 4603 4604


opt_column_list:
4605 4606 4607 4608 4609
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
4610
	| '(' column_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4611 4612 4613

column_list:
	column_list ',' column_list_id
4614
	| column_list_id;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4615 4616 4617 4618

column_list_id:
	ident
	{
4619
	  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
4620 4621
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
4622
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4623 4624
	  while ((point=iter++))
	  {
4625 4626
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4627 4628
		break;
	  }
4629
	  lex->grant_tot_col|= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4630
	  if (point)
4631
	    point->rights |= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4632
	  else
4633
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
4634 4635
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4636

tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
4637 4638

require_clause: /* empty */
4639
        | REQUIRE_SYM require_list
4640 4641 4642
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
4643
        | REQUIRE_SYM SSL_SYM
4644 4645 4646
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
4647
        | REQUIRE_SYM X509_SYM
4648 4649 4650 4651 4652 4653 4654
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
4655
          ;
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
4656

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4657
grant_options:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4658
	/* empty */ {}
4659
	| WITH grant_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4660

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4661 4662
grant_option_list:
	grant_option_list grant_option {}
4663 4664
	| grant_option {}
        ;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4665 4666 4667

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
4668
        | MAX_QUERIES_PER_HOUR ULONG_NUM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4669
        {
4670
	  Lex->mqh.questions=$2;
4671
	  Lex->mqh.bits |= 1;
4672
	}
4673
        | MAX_UPDATES_PER_HOUR ULONG_NUM
4674
        {
4675
	  Lex->mqh.updates=$2;
4676
	  Lex->mqh.bits |= 2;
4677
	}
4678
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
4679
        {
4680
	  Lex->mqh.connections=$2;
4681
	  Lex->mqh.bits |= 4;
4682 4683
	}
        ;
4684

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4685
begin:
4686 4687
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4688 4689 4690

opt_work:
	/* empty */ {}
4691 4692
	| WORK_SYM {;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4693 4694

commit:
4695
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4696 4697

rollback:
4698
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
4699 4700 4701


/*
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4702
   UNIONS : glue selects together
4703 4704 4705
*/


4706
union_clause:
4707
	/* empty */ {}
4708 4709
	| union_list
	;
4710 4711

union_list:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4712
	UNION_SYM    union_option
4713 4714 4715 4716 4717
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
4718
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
4719
	    YYABORT;
4720
	  }
4721
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4722
	  {
4723
	    send_error(lex->thd, ER_SYNTAX_ERROR);
4724 4725
	    YYABORT;
	  }
4726
	  if (mysql_new_select(lex, 0))
4727
	    YYABORT;
4728
          mysql_init_select(lex);
4729
	  lex->current_select->linkage=UNION_TYPE;
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4730
	}
4731
	select_init {}
4732
	;
4733 4734

union_opt:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
4735
	union_list {}
4736 4737
	| optional_order_or_limit {}
	;
4738 4739

optional_order_or_limit:
4740
      	/* Empty */ {}
4741 4742
	|
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4743 4744
	    THD *thd= YYTHD;
	    LEX *lex= &thd->lex;
4745
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
4746
	    SELECT_LEX *sel= lex->current_select->select_lex();
4747
	    sel->master_unit()->global_parameters=
4748 4749
	      sel->master_unit();
	    lex->current_select= sel->master_unit();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4750 4751
	    lex->current_select->no_table_names_allowed= 1;
	    thd->where= "global ORDER clause";
4752
	  }
4753
	order_or_limit
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4754 4755 4756 4757 4758
          {
	    THD *thd= YYTHD;
	    thd->lex.current_select->no_table_names_allowed= 0;
	    thd->where= "";
          }
4759 4760 4761
	;

order_or_limit:
4762 4763
	order_clause opt_limit_clause_init
	| limit_clause
4764
	;
4765 4766

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

4770 4771
singlerow_subselect:
	subselect_start singlerow_subselect_init
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4772 4773 4774 4775
	subselect_end
	{
	  $$= $2;
	};
4776

4777
singlerow_subselect_init:
4778
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4779
	{
4780
	  $$= new Item_singlerow_subselect(YYTHD,
4781 4782
					   Lex->current_select->master_unit()->
                                             first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4783
	};
4784 4785

exists_subselect:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4786 4787 4788 4789 4790
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
4791 4792

exists_subselect_init:
4793
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4794
	{
4795
	  $$= new Item_exists_subselect(YYTHD,
4796 4797
					Lex->current_select->master_unit()->
					  first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4798
	};
4799

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4800 4801 4802 4803 4804 4805 4806 4807
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
4808
  select_init2
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4809
  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4810
    $$= Lex->current_select->master_unit()->first_select();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4811 4812
  };

4813
subselect_start:
4814
	'(' SELECT_SYM
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4815
	{
4816
	  LEX *lex=Lex;
4817
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
4818 4819 4820 4821
	       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
4822 4823 4824
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
4825 4826

subselect_end:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4827 4828 4829
	')'
	{
	  LEX *lex=Lex;
4830
	  lex->current_select = lex->current_select->outer_select();
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4831
	};