sql_yacc.yy 191 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"
38 39
#include "sp_head.h"
#include "sp_pcontext.h"
40
#include "sp_rcontext.h"
41
#include "sp.h"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
42
#include <myisam.h>
43
#include <myisammrg.h>
44

45
int yylex(void *yylval, void *yythd);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
46

47
#define yyoverflow(A,B,C,D,E,F) {ulong val= *(F); if(my_yyoverflow((B), (D), &val)) { yyerror((char*) (A)); return 2; } else { *(F)= (YYSIZE_T)val; }}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
48

49 50 51 52 53
#define WARN_DEPRECATED(A,B) \
  push_warning_printf(((THD *)yythd), MYSQL_ERROR::WARN_LEVEL_WARN, \
		      ER_WARN_DEPRECATED_SYNTAX, \
		      ER(ER_WARN_DEPRECATED_SYNTAX), (A), (B)); 

54
inline Item *or_or_concat(THD *thd, Item* A, Item* B)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
55
{
56
  return (thd->variables.sql_mode & MODE_PIPES_AS_CONCAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
57 58 59 60 61 62 63
          (Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B));
}

%}
%union {
  int  num;
  ulong ulong_num;
64
  ulonglong ulonglong_number;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
65 66 67 68 69 70
  LEX_STRING lex_str;
  LEX_STRING *lex_str_ptr;
  LEX_SYMBOL symbol;
  Table_ident *table;
  char *simple_string;
  Item *item;
71
  Item_num *item_num;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
72 73
  List<Item> *item_list;
  List<String> *string_list;
74 75 76 77 78
  String *string;
  key_part_spec *key_part;
  TABLE_LIST *table_list;
  udf_func *udf;
  LEX_USER *lex_user;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
79
  struct sys_var_with_base variable;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
80
  Key::Keytype key_type;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
81
  enum ha_key_alg key_alg;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
82 83
  enum db_type db_type;
  enum row_type row_type;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
84
  enum ha_rkey_function ha_rkey_mode;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
85
  enum enum_tx_isolation tx_isolation;
86
  enum Cast_target cast_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
87
  enum Item_udftype udf_type;
88
  CHARSET_INFO *charset;
89
  thr_lock_type lock_type;
90
  interval_type interval, interval_time_st;
91
  timestamp_type date_time_type;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
92
  st_select_lex *select_lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
93
  chooser_compare_func_creator boolfunc2creator;
94
  struct sp_cond_type *spcondtype;
95
  struct { int vars, conds, hndlrs, curs; } spblock;
96
  sp_name *spname;
97
  struct st_lex *lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
98 99 100
}

%{
101
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
102 103 104 105 106 107
%}

%pure_parser					/* We have threads */

%token	END_OF_INPUT

108 109 110 111 112 113
%token CLOSE_SYM
%token HANDLER_SYM
%token LAST_SYM
%token NEXT_SYM
%token PREV_SYM

114
%token	DIV_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
115 116
%token	EQ
%token	EQUAL_SYM
117
%token	SOUNDS_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
118 119 120 121 122 123
%token	GE
%token	GT_SYM
%token	LE
%token	LT
%token	NE
%token	IS
124
%token	MOD_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
125 126 127 128
%token	SHIFT_LEFT
%token	SHIFT_RIGHT
%token  SET_VAR

129
%token	ABORT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
130 131
%token	ADD
%token	AFTER_SYM
132 133
%token	ALTER
%token	ANALYZE_SYM
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
134
%token	ANY_SYM
135 136 137
%token	AVG_SYM
%token	BEGIN_SYM
%token	BINLOG_SYM
138
%token  CALL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
139
%token	CHANGE
140 141 142 143
%token	CLIENT_SYM
%token	COMMENT_SYM
%token	COMMIT_SYM
%token	COUNT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
144 145
%token	CREATE
%token	CROSS
146
%token  CUBE_SYM
147
%token  DEFINER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
148
%token	DELETE_SYM
149
%token  DETERMINISTIC_SYM
150
%token	DUAL_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
151
%token	DO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
152
%token	DROP
153 154
%token	EVENTS_SYM
%token	EXECUTE_SYM
155
%token	EXPANSION_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
156
%token	FLUSH_SYM
157
%token  HELP_SYM
158
%token	INSERT
159
%token	RELAY_THREAD
bk@work.mysql.com's avatar
bk@work.mysql.com committed
160 161
%token	KILL_SYM
%token	LOAD
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
162
%token	LOCKS_SYM
163 164 165 166
%token	LOCK_SYM
%token	MASTER_SYM
%token	MAX_SYM
%token	MIN_SYM
167
%token	NONE_SYM
168 169 170 171 172 173
%token	OPTIMIZE
%token	PURGE
%token	REPAIR
%token	REPLICATION
%token	RESET_SYM
%token	ROLLBACK_SYM
174
%token  ROLLUP_SYM
175
%token	SAVEPOINT_SYM
176 177 178
%token	SELECT_SYM
%token	SHOW
%token	SLAVE
179
%token  SQL_SYM
180 181 182
%token	SQL_THREAD
%token	START_SYM
%token	STD_SYM
183
%token  VARIANCE_SYM
184 185
%token	STOP_SYM
%token	SUM_SYM
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
186
%token	ADDDATE_SYM
187 188
%token	SUPER_SYM
%token	TRUNCATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
189
%token	UNLOCK_SYM
190
%token	UNTIL_SYM
191
%token	UPDATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
192 193 194

%token	ACTION
%token	AGGREGATE_SYM
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
195
%token	ALGORITHM_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
196
%token	ALL
197
%token	AND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
198 199
%token	AS
%token	ASC
200
%token	AUTO_INC
bk@work.mysql.com's avatar
bk@work.mysql.com committed
201
%token	AVG_ROW_LENGTH
202
%token	BACKUP_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
203 204 205 206
%token	BERKELEY_DB_SYM
%token	BINARY
%token	BIT_SYM
%token	BOOL_SYM
207
%token	BOOLEAN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
208
%token	BOTH
209
%token	BTREE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
210
%token	BY
211
%token	BYTE_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
212
%token	CACHE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
213
%token	CASCADE
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
214
%token  CASCADED
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
215
%token	CAST_SYM
216
%token	CHARSET
bk@work.mysql.com's avatar
bk@work.mysql.com committed
217 218
%token	CHECKSUM_SYM
%token	CHECK_SYM
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
219
%token	COMMITTED_SYM
220
%token	COLLATE_SYM
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
221
%token	COLLATION_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
222 223
%token	COLUMNS
%token	COLUMN_SYM
224
%token	CONCURRENT
225
%token  CONDITION_SYM
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
226
%token	CONNECTION_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
227
%token	CONSTRAINT
228
%token  CONTINUE_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
229
%token	CONVERT_SYM
230
%token  CURRENT_USER
bk@work.mysql.com's avatar
bk@work.mysql.com committed
231 232
%token	DATABASES
%token	DATA_SYM
233
%token  DECLARE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
234 235 236 237 238
%token	DEFAULT
%token	DELAYED_SYM
%token	DELAY_KEY_WRITE_SYM
%token	DESC
%token	DESCRIBE
239
%token	DES_KEY_FILE
240
%token	DISABLE_SYM
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
241
%token	DISCARD
242
%token	DISTINCT
243
%token  DUPLICATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
244
%token	DYNAMIC_SYM
245
%token  EACH_SYM
246
%token	ENABLE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
247 248
%token	ENCLOSED
%token	ESCAPED
249
%token	DIRECTORY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
250 251
%token	ESCAPE_SYM
%token	EXISTS
252
%token  EXIT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
253
%token	EXTENDED_SYM
254
%token	FALSE_SYM
255
%token  FETCH_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
256 257 258 259
%token	FILE_SYM
%token	FIRST_SYM
%token	FIXED_SYM
%token	FLOAT_NUM
260
%token	FORCE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
261
%token	FOREIGN
262
%token  FOUND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
263 264
%token	FROM
%token	FULL
265 266
%token	FULLTEXT_SYM
%token	GLOBAL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
267 268 269 270 271
%token	GRANT
%token	GRANTS
%token	GREATEST_SYM
%token	GROUP
%token	HAVING
272
%token	HASH_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
273 274 275 276
%token	HEX_NUM
%token	HIGH_PRIORITY
%token	HOSTS_SYM
%token	IDENT
277
%token	IDENT_QUOTED
bk@work.mysql.com's avatar
bk@work.mysql.com committed
278
%token	IGNORE_SYM
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
279
%token	IMPORT
280
%token	INDEX_SYM
281
%token	INDEXES
bk@work.mysql.com's avatar
bk@work.mysql.com committed
282 283
%token	INFILE
%token	INNER_SYM
284
%token	INNOBASE_SYM
285
%token  INOUT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
286 287
%token	INTO
%token	IN_SYM
288
%token  INVOKER_SYM
289
%token	ISOLATION
bk@work.mysql.com's avatar
bk@work.mysql.com committed
290 291 292 293 294
%token	JOIN_SYM
%token	KEYS
%token	KEY_SYM
%token	LEADING
%token	LEAST_SYM
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
295
%token	LEAVES
296
%token	LEVEL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
297
%token	LEX_HOSTNAME
298
%token  LANGUAGE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
299 300 301
%token	LIKE
%token	LINES
%token	LOCAL_SYM
302
%token  LOCATOR_SYM
303
%token	LOG_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
304 305 306 307
%token	LOGS_SYM
%token	LONG_NUM
%token	LONG_SYM
%token	LOW_PRIORITY
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
308
%token	MERGE_SYM
309 310 311 312 313 314 315 316
%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
317 318 319 320 321 322
%token	MASTER_SSL_SYM
%token	MASTER_SSL_CA_SYM
%token	MASTER_SSL_CAPATH_SYM
%token	MASTER_SSL_CERT_SYM
%token	MASTER_SSL_CIPHER_SYM
%token	MASTER_SSL_KEY_SYM
323 324
%token	RELAY_LOG_FILE_SYM
%token	RELAY_LOG_POS_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
325 326
%token	MATCH
%token	MAX_ROWS
327 328 329
%token	MAX_CONNECTIONS_PER_HOUR
%token	MAX_QUERIES_PER_HOUR
%token	MAX_UPDATES_PER_HOUR
330
%token	MEDIUM_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
331
%token	MIN_ROWS
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
332
%token	NAMES_SYM
333
%token	NAME_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
334 335
%token	NATIONAL_SYM
%token	NATURAL
336
%token  NDBCLUSTER_SYM
337
%token	NEW_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
338
%token	NCHAR_SYM
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
339
%token	NCHAR_STRING
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
340
%token  NVARCHAR_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
341 342 343 344
%token	NOT
%token	NO_SYM
%token	NULL_SYM
%token	NUM
345
%token	OFFSET_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
346
%token	ON
347
%token  ONE_SHOT_SYM
348
%token	OPEN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
349 350
%token	OPTION
%token	OPTIONALLY
351
%token	OR_SYM
352
%token	OR_OR_CONCAT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
353
%token	ORDER_SYM
354
%token  OUT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
355 356
%token	OUTER
%token	OUTFILE
357
%token	DUMPFILE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
358 359 360 361 362 363
%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
364
%token	QUERY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
365
%token	RAID_0_SYM
366 367
%token	RAID_STRIPED_SYM
%token	RAID_TYPE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
368 369 370 371 372 373 374 375
%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
376
%token	REPEATABLE_SYM
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
377
%token	REQUIRE_SYM
378 379
%token	RESOURCES
%token	RESTORE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
380 381 382 383 384
%token	RESTRICT
%token	REVOKE
%token	ROWS_SYM
%token	ROW_FORMAT_SYM
%token	ROW_SYM
385
%token	RTREE_SYM
386
%token  SECURITY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
387
%token	SET
388
%token  SEPARATOR_SYM
389
%token	SERIAL_SYM
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
390 391
%token	SERIALIZABLE_SYM
%token	SESSION_SYM
392
%token	SIMPLE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
393
%token	SHUTDOWN
394
%token	SPATIAL_SYM
395
%token  SPECIFIC_SYM
396
%token  SQLEXCEPTION_SYM
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
397
%token  SQLSTATE_SYM
398
%token  SQLWARNING_SYM
399
%token  SSL_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
400 401
%token	STARTING
%token	STATUS_SYM
402
%token	STORAGE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
403
%token	STRAIGHT_JOIN
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
404
%token	SUBJECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
405 406
%token	TABLES
%token	TABLE_SYM
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
407
%token	TABLESPACE
bk@work.mysql.com's avatar
bk@work.mysql.com committed
408
%token	TEMPORARY
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
409
%token	TEMPTABLE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
410 411
%token	TERMINATED
%token	TEXT_STRING
412 413 414
%token	TO_SYM
%token	TRAILING
%token	TRANSACTION_SYM
415
%token  TRIGGER_SYM
416
%token	TRUE_SYM
417
%token	TYPE_SYM
418
%token  TYPES_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
419 420 421 422
%token	FUNC_ARG0
%token	FUNC_ARG1
%token	FUNC_ARG2
%token	FUNC_ARG3
423 424
%token	RETURN_SYM
%token	RETURNS_SYM
425
%token	UDF_SONAME_SYM
426
%token	FUNCTION_SYM
427
%token	UNCOMMITTED_SYM
428
%token	UNDERSCORE_CHARSET
429
%token  UNDO_SYM
430
%token	UNICODE_SYM
431 432 433
%token	UNION_SYM
%token	UNIQUE_SYM
%token	USAGE
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
434
%token	USE_FRM
435 436
%token	USE_SYM
%token	USING
437
%token	VALUE_SYM
438
%token	VALUES
bk@work.mysql.com's avatar
bk@work.mysql.com committed
439
%token	VARIABLES
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
440
%token	VIEW_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
441 442 443
%token	WHERE
%token	WITH
%token	WRITE_SYM
444
%token  NO_WRITE_TO_BINLOG
445
%token	X509_SYM
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
446
%token	XOR
447
%token	COMPRESSED_SYM
448
%token  ROW_COUNT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
449

450 451 452
%token  ERRORS
%token  WARNINGS

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
453
%token	ASCII_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
454 455 456
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
457
%token	CHANGED
bk@work.mysql.com's avatar
bk@work.mysql.com committed
458 459 460 461 462 463
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
464
%token	FAST_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
465
%token	FLOAT_SYM
466
%token  GEOMETRY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
467 468 469 470 471 472 473 474 475
%token	INT_SYM
%token	LIMIT
%token	LONGBLOB
%token	LONGTEXT
%token	MEDIUMBLOB
%token	MEDIUMINT
%token	MEDIUMTEXT
%token	NUMERIC_SYM
%token	PRECISION
sergefp@mysql.com's avatar
sergefp@mysql.com committed
476 477
%token  PREPARE_SYM
%token  DEALLOCATE_SYM
478
%token	QUICK
bk@work.mysql.com's avatar
bk@work.mysql.com committed
479
%token	REAL
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
480
%token	SIGNED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
481 482 483 484
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
485 486
%token	TIMESTAMP_ADD
%token	TIMESTAMP_DIFF
bk@work.mysql.com's avatar
bk@work.mysql.com committed
487 488 489 490
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
491
%token	ULONGLONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
492
%token	UNSIGNED
493 494 495
%token	VARBINARY
%token	VARCHAR
%token	VARYING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
496 497
%token	ZEROFILL

gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
498
%token	ADDDATE_SYM
499
%token	AGAINST
bk@work.mysql.com's avatar
bk@work.mysql.com committed
500 501 502 503
%token	ATAN
%token	BETWEEN_SYM
%token	BIT_AND
%token	BIT_OR
504
%token  BIT_XOR
bk@work.mysql.com's avatar
bk@work.mysql.com committed
505 506
%token	CASE_SYM
%token	CONCAT
507
%token	CONCAT_WS
bk@work.mysql.com's avatar
bk@work.mysql.com committed
508 509 510 511 512 513
%token	CURDATE
%token	CURTIME
%token	DATABASE
%token	DATE_ADD_INTERVAL
%token	DATE_SUB_INTERVAL
%token	DAY_HOUR_SYM
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
514
%token	DAY_MICROSECOND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
515 516 517 518
%token	DAY_MINUTE_SYM
%token	DAY_SECOND_SYM
%token	DAY_SYM
%token	DECODE_SYM
519 520
%token	DES_ENCRYPT_SYM
%token	DES_DECRYPT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
521 522 523
%token	ELSE
%token	ELT_FUNC
%token	ENCODE_SYM
524
%token	ENGINE_SYM
525
%token	ENGINES_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
526 527 528 529 530 531
%token	ENCRYPT
%token	EXPORT_SET
%token	EXTRACT_SYM
%token	FIELD_FUNC
%token	FORMAT_SYM
%token	FOR_SYM
532
%token  FRAC_SECOND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
533
%token	FROM_UNIXTIME
534 535
%token	GEOMCOLLFROMTEXT
%token	GEOMFROMTEXT
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
536
%token	GEOMFROMWKB
537
%token  GEOMETRYCOLLECTION
538
%token  GROUP_CONCAT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
539
%token	GROUP_UNIQUE_USERS
540
%token  GET_FORMAT
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
541
%token	HOUR_MICROSECOND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
542 543 544 545 546
%token	HOUR_MINUTE_SYM
%token	HOUR_SECOND_SYM
%token	HOUR_SYM
%token	IDENTIFIED_SYM
%token	IF
547
%token	INSERT_METHOD
bk@work.mysql.com's avatar
bk@work.mysql.com committed
548 549 550
%token	INTERVAL_SYM
%token	LAST_INSERT_ID
%token	LEFT
551
%token	LINEFROMTEXT
552
%token  LINESTRING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
553 554
%token	LOCATE
%token	MAKE_SET_SYM
555
%token	MASTER_POS_WAIT
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
556 557
%token  MICROSECOND_SYM
%token	MINUTE_MICROSECOND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
558 559
%token	MINUTE_SECOND_SYM
%token	MINUTE_SYM
560
%token	MODE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
561 562
%token	MODIFY_SYM
%token	MONTH_SYM
563 564 565
%token	MLINEFROMTEXT
%token	MPOINTFROMTEXT
%token	MPOLYFROMTEXT
566 567 568
%token  MULTILINESTRING
%token  MULTIPOINT
%token  MULTIPOLYGON
bk@work.mysql.com's avatar
bk@work.mysql.com committed
569
%token	NOW_SYM
570
%token	OLD_PASSWORD
bk@work.mysql.com's avatar
bk@work.mysql.com committed
571
%token	PASSWORD
572
%token	POINTFROMTEXT
573
%token	POINT_SYM
574
%token	POLYFROMTEXT
575
%token  POLYGON
bk@work.mysql.com's avatar
bk@work.mysql.com committed
576 577
%token	POSITION_SYM
%token	PROCEDURE
578
%token	QUARTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
579 580 581 582 583
%token	RAND
%token	REPLACE
%token	RIGHT
%token	ROUND
%token	SECOND_SYM
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
584
%token	SECOND_MICROSECOND_SYM
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
585
%token	SHARE_SYM
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
586
%token	SUBDATE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
587 588 589 590 591 592
%token	SUBSTRING
%token	SUBSTRING_INDEX
%token	TRIM
%token	UNIQUE_USERS
%token	UNIX_TIMESTAMP
%token	USER
593 594 595
%token	UTC_DATE_SYM
%token	UTC_TIME_SYM
%token	UTC_TIMESTAMP_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
596 597
%token	WEEK_SYM
%token	WHEN_SYM
598
%token	WORK_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
599 600 601
%token	YEAR_MONTH_SYM
%token	YEAR_SYM
%token	YEARWEEK
602 603 604
%token	BENCHMARK_SYM
%token	END
%token	THEN_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
605

606 607 608 609
%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
610
%token	SQL_SMALL_RESULT
611
%token  SQL_BUFFER_RESULT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
612

613 614 615 616 617
%token  CURSOR_SYM
%token  ELSEIF_SYM
%token  ITERATE_SYM
%token  LEAVE_SYM
%token  LOOP_SYM
618
%token  REPEAT_SYM
619 620 621 622 623
%token  UNTIL_SYM
%token  WHILE_SYM
%token  ASENSITIVE_SYM
%token  INSENSITIVE_SYM
%token  SENSITIVE_SYM
624

625 626
%token  ISSUER_SYM
%token  SUBJECT_SYM
627
%token  CIPHER_SYM
628

629
%token  BEFORE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
630
%left   SET_VAR
631 632
%left	OR_OR_CONCAT OR_SYM XOR
%left	AND_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
633 634 635 636 637 638
%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	'-' '+'
639
%left	'*' '/' '%' DIV_SYM MOD_SYM
640
%left   '^'
monty@mysql.com's avatar
monty@mysql.com committed
641
%left	NEG '~'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
642
%right	NOT
643
%right	BINARY COLLATE_SYM
644

bk@work.mysql.com's avatar
bk@work.mysql.com committed
645
%type <lex_str>
646 647
	IDENT IDENT_QUOTED TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM
	LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
648
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
649
	NCHAR_STRING opt_component key_cache_name
650
        sp_opt_label
bk@work.mysql.com's avatar
bk@work.mysql.com committed
651 652 653 654 655

%type <lex_str_ptr>
	opt_table_alias

%type <table>
serg@serg.mylan's avatar
serg@serg.mylan committed
656
	table_ident table_ident_nodb references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
657 658

%type <simple_string>
659
	remember_name remember_end opt_ident opt_db text_or_password
660
	opt_constraint constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
661 662

%type <string>
663
	text_string opt_gconcat_separator
bk@work.mysql.com's avatar
bk@work.mysql.com committed
664 665

%type <num>
666
	type int_type real_type order_dir opt_field_spec lock_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
667
	udf_type if_exists opt_local opt_table_options table_options
668 669
        table_option opt_if_not_exists opt_no_write_to_binlog opt_var_type
        opt_var_ident_type delete_option opt_temporary all_or_any opt_distinct
670
        opt_ignore_leaves fulltext_options spatial_type union_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
671 672

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

675 676
%type <ulonglong_number>
	ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
677

678 679 680
%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
681
%type <item>
682
	literal text_literal insert_ident order_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
683
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
684
	table_wild no_in_expr expr_expr simple_expr no_and_expr udf_expr
685
	using_list expr_or_default set_expr_or_default interval_expr
686
	param_marker singlerow_subselect singlerow_subselect_init
hf@deer.(none)'s avatar
hf@deer.(none) committed
687
	exists_subselect exists_subselect_init geometry_function
688
	signed_literal now_or_signed_literal opt_escape
pem@mysql.com's avatar
pem@mysql.com committed
689
	sp_opt_default
690
	simple_ident_nospvar simple_ident_q
bk@work.mysql.com's avatar
bk@work.mysql.com committed
691

692 693
%type <item_num>
	NUM_literal
bk@work.mysql.com's avatar
bk@work.mysql.com committed
694 695

%type <item_list>
696
	expr_list udf_expr_list udf_expr_list2 when_list
697
	ident_list ident_list_arg
bk@work.mysql.com's avatar
bk@work.mysql.com committed
698 699

%type <key_type>
700
	key_type opt_unique_or_fulltext constraint_key_type
bk@work.mysql.com's avatar
bk@work.mysql.com committed
701

702 703 704
%type <key_alg>
	key_alg opt_btree_or_rtree

bk@work.mysql.com's avatar
bk@work.mysql.com committed
705 706 707 708 709 710 711
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
712
	join_table_list  join_table
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
713
        table_factor table_ref
bk@work.mysql.com's avatar
bk@work.mysql.com committed
714

715
%type <date_time_type> date_time_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
716 717
%type <interval> interval

718 719
%type <interval_time_st> interval_time_st

720
%type <db_type> storage_engines
bk@work.mysql.com's avatar
bk@work.mysql.com committed
721 722 723

%type <row_type> row_types

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

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

728
%type <cast_type> cast_type
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
729

bk@work.mysql.com's avatar
bk@work.mysql.com committed
730 731 732 733 734 735
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

736
%type <charset>
737
	opt_collate
738 739
	charset_name
	charset_name_or_default
740 741
	old_or_new_charset_name
	old_or_new_charset_name_or_default
742 743
	collation_name
	collation_name_or_default
744

745 746
%type <variable> internal_variable_name

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

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
751
%type <NONE>
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
752
	query verb_clause create change select do drop insert replace insert2
753
	insert_values update delete truncate rename
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
754
	show describe load alter optimize keycache preload flush
755
	reset purge begin commit rollback savepoint
756
	slave master_def master_defs master_file_def slave_until_opts
757
	repair restore backup analyze check start checksum
758
	field_list field_list_item field_spec kill column_def key_def
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
759
	keycache_list assign_to_keycache preload_list preload_keys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
760
	select_item_list select_item values_list no_braces
761
	opt_limit_clause delete_limit_clause fields opt_values values
bk@work.mysql.com's avatar
bk@work.mysql.com committed
762
	procedure_list procedure_list2 procedure_item
763
	when_list2 expr_list2 udf_expr_list3 handler
bk@work.mysql.com's avatar
bk@work.mysql.com committed
764 765
	opt_precision opt_ignore opt_column opt_restrict
	grant revoke set lock unlock string_list field_options field_option
766
	field_opt_list opt_binary table_lock_list table_lock
767
	ref_list opt_on_delete opt_on_delete_list opt_on_delete_item use
768
	opt_delete_options opt_delete_option varchar nchar nvarchar
769
	opt_outer table_list table_name opt_option opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
770 771
	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
772
	grant_privilege grant_privilege_list
773
	flush_options flush_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
774 775
	equal optional_braces opt_key_definition key_usage_list2
	opt_mi_check_type opt_to mi_check_types normal_join
776
	table_to_table_list table_to_table opt_table_list opt_as
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
777
	handler_rkey_function handler_read_or_scan
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
778
	single_multi table_wild_list table_wild_one opt_wild
779
	union_clause union_list
780
	precision subselect_start opt_and charset
781
	subselect_end select_var_list select_var_list_init help opt_len
782
	opt_extended_describe
783
        prepare prepare_src execute deallocate 
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
784
	statement sp_suid opt_view_list view_list or_replace algorithm
785
	sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic sp_a_chistic
786
END_OF_INPUT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
787

788
%type <NONE> call sp_proc_stmts sp_proc_stmt
789 790 791
%type <num>  sp_decl_idents sp_opt_inout sp_handler_type sp_hcond_list
%type <spcondtype> sp_cond sp_hcond
%type <spblock> sp_decls sp_decl
792
%type <lex> sp_cursor_stmt
793
%type <spname> sp_name
794

bk@work.mysql.com's avatar
bk@work.mysql.com committed
795 796
%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
797
	',' '!' '{' '}' '&' '|' AND_SYM OR_SYM OR_OR_CONCAT BETWEEN_SYM CASE_SYM
798
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
799 800 801 802 803
%%


query:
	END_OF_INPUT
804
	{
805
	   THD *thd= YYTHD;
806
	   if (!thd->bootstrap &&
807
	      (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
808
	   {
809
	     send_error(thd,ER_EMPTY_QUERY);
810
	     YYABORT;
811
	   }
812 813
	   else
	   {
814
	     thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
815
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
816
	}
817
	| verb_clause END_OF_INPUT {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
818 819

verb_clause:
820 821 822 823 824 825
	  statement
	| begin
	;

/* Verb clauses, except begin */
statement:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
826 827
	  alter
	| analyze
828
	| backup
829
	| call
bk@work.mysql.com's avatar
bk@work.mysql.com committed
830 831
	| change
	| check
832
	| checksum
bk@work.mysql.com's avatar
bk@work.mysql.com committed
833 834
	| commit
	| create
835
        | deallocate
bk@work.mysql.com's avatar
bk@work.mysql.com committed
836 837
	| delete
	| describe
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
838
	| do
bk@work.mysql.com's avatar
bk@work.mysql.com committed
839
	| drop
840
        | execute
serg@serg.mylan's avatar
serg@serg.mylan committed
841
	| flush
bk@work.mysql.com's avatar
bk@work.mysql.com committed
842
	| grant
serg@serg.mylan's avatar
serg@serg.mylan committed
843 844
	| handler
	| help
bk@work.mysql.com's avatar
bk@work.mysql.com committed
845
	| insert
serg@serg.mylan's avatar
serg@serg.mylan committed
846
	| kill
bk@work.mysql.com's avatar
bk@work.mysql.com committed
847 848 849
	| load
	| lock
	| optimize
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
850
        | keycache
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
851
	| preload
852
        | prepare
853
	| purge
854
	| rename
serg@serg.mylan's avatar
serg@serg.mylan committed
855
	| repair
bk@work.mysql.com's avatar
bk@work.mysql.com committed
856
	| replace
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
857
	| reset
858
	| restore
bk@work.mysql.com's avatar
bk@work.mysql.com committed
859 860
	| revoke
	| rollback
861
	| savepoint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
862 863
	| select
	| set
serg@serg.mylan's avatar
serg@serg.mylan committed
864
	| show
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
865
	| slave
866
	| start
867
	| truncate
bk@work.mysql.com's avatar
bk@work.mysql.com committed
868 869
	| unlock
	| update
870
	| use
serg@serg.mylan's avatar
serg@serg.mylan committed
871
        ;
872

sergefp@mysql.com's avatar
sergefp@mysql.com committed
873
deallocate:
874
        deallocate_or_drop PREPARE_SYM ident
sergefp@mysql.com's avatar
sergefp@mysql.com committed
875 876
        {
          THD *thd=YYTHD;
877
          LEX *lex= thd->lex;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
878 879 880 881 882
          if (thd->command == COM_PREPARE)
          {
            yyerror(ER(ER_SYNTAX_ERROR));
            YYABORT;
          }
883
          lex->sql_command= SQLCOM_DEALLOCATE_PREPARE;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
884 885 886
          lex->prepared_stmt_name= $3;
        };

887 888 889 890 891 892
deallocate_or_drop:
	DEALLOCATE_SYM |
	DROP
	;


sergefp@mysql.com's avatar
sergefp@mysql.com committed
893
prepare:
894
        PREPARE_SYM ident FROM prepare_src
sergefp@mysql.com's avatar
sergefp@mysql.com committed
895 896
        {
          THD *thd=YYTHD;
897
          LEX *lex= thd->lex;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
898 899 900 901 902
          if (thd->command == COM_PREPARE)
          {
            yyerror(ER(ER_SYNTAX_ERROR));
            YYABORT;
          }
903
          lex->sql_command= SQLCOM_PREPARE;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
904 905 906
          lex->prepared_stmt_name= $2;
        };

907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
prepare_src:
        TEXT_STRING_sys
        {
          THD *thd=YYTHD;
          LEX *lex= thd->lex;
          lex->prepared_stmt_code= $1;
          lex->prepared_stmt_code_is_varref= false;
        }
        | '@' ident_or_text
        {
          THD *thd=YYTHD;
          LEX *lex= thd->lex;
          lex->prepared_stmt_code= $2;
          lex->prepared_stmt_code_is_varref= true;
        };
922

sergefp@mysql.com's avatar
sergefp@mysql.com committed
923 924 925 926
execute:
        EXECUTE_SYM ident
        {
          THD *thd=YYTHD;
927
          LEX *lex= thd->lex;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
928 929 930 931 932
          if (thd->command == COM_PREPARE)
          {
            yyerror(ER(ER_SYNTAX_ERROR));
            YYABORT;
          }
933
          lex->sql_command= SQLCOM_EXECUTE;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
934 935 936 937 938 939 940 941 942 943 944 945
          lex->prepared_stmt_name= $2;
        }
        execute_using
        {}
        ;

execute_using:
        /* nothing */
        | USING execute_var_list
        ;

execute_var_list:
946 947
        execute_var_list ',' execute_var_ident
        | execute_var_ident
sergefp@mysql.com's avatar
sergefp@mysql.com committed
948 949 950 951 952 953 954 955
        ;

execute_var_ident: '@' ident_or_text
        {
          LEX *lex=Lex;
          LEX_STRING *lexstr= (LEX_STRING*)sql_memdup(&$2, sizeof(LEX_STRING));
          if (!lexstr || lex->prepared_stmt_params.push_back(lexstr))
              YYABORT;
956
        }
sergefp@mysql.com's avatar
sergefp@mysql.com committed
957 958
        ;

959 960
/* help */

961
help:
962
       HELP_SYM ident_or_text
963
       {
964 965 966
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
967
       };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
968 969 970 971

/* change master */

change:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
972
       CHANGE MASTER_SYM TO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
973 974 975
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
976
	  bzero((char*) &lex->mi, sizeof(lex->mi));
977 978 979 980
        }
       master_defs
	{}
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
981 982 983

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
986
master_def:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
987
       MASTER_HOST_SYM EQ TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
988 989 990 991
       {
	 Lex->mi.host = $3.str;
       }
       |
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
992
       MASTER_USER_SYM EQ TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
993 994 995 996
       {
	 Lex->mi.user = $3.str;
       }
       |
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
997
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
998 999 1000 1001
       {
	 Lex->mi.password = $3.str;
       }
       |
1002
       MASTER_PORT_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1003 1004 1005 1006
       {
	 Lex->mi.port = $3;
       }
       |
1007
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1008 1009 1010
       {
	 Lex->mi.connect_retry = $3;
       }
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
       | MASTER_SSL_SYM EQ ULONG_NUM
         {
           Lex->mi.ssl= $3 ? 
               LEX_MASTER_INFO::SSL_ENABLE : LEX_MASTER_INFO::SSL_DISABLE;
         }
       | MASTER_SSL_CA_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_ca= $3.str;
         }
       | MASTER_SSL_CAPATH_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_capath= $3.str;
         }
       | MASTER_SSL_CERT_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_cert= $3.str;
         }
       | MASTER_SSL_CIPHER_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_cipher= $3.str;
         }
       | MASTER_SSL_KEY_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.ssl_key= $3.str;
1035
	 }
1036
       |
1037
         master_file_def
1038
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1039

1040 1041
master_file_def:
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
1042
       {
1043
	 Lex->mi.log_file_name = $3.str;
1044
       }
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
       | MASTER_LOG_POS_SYM EQ ulonglong_num
         {
           Lex->mi.pos = $3;
           /* 
              If the user specified a value < BIN_LOG_HEADER_SIZE, adjust it
              instead of causing subsequent errors. 
              We need to do it in this file, because only there we know that 
              MASTER_LOG_POS has been explicitely specified. On the contrary
              in change_master() (sql_repl.cc) we cannot distinguish between 0
              (MASTER_LOG_POS explicitely specified as 0) and 0 (unspecified),
              whereas we want to distinguish (specified 0 means "read the binlog
              from 0" (4 in fact), unspecified means "don't change the position
              (keep the preceding value)").
           */
           Lex->mi.pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.pos);
         }
       | RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
         {
           Lex->mi.relay_log_name = $3.str;
         }
       | RELAY_LOG_POS_SYM EQ ULONG_NUM
         {
           Lex->mi.relay_log_pos = $3;
           /* Adjust if < BIN_LOG_HEADER_SIZE (same comment as Lex->mi.pos) */
           Lex->mi.relay_log_pos = max(BIN_LOG_HEADER_SIZE, Lex->mi.relay_log_pos);
         }
1071
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1072 1073 1074 1075 1076 1077

/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
1078
	  THD *thd= YYTHD;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1079 1080
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
pem@mysql.com's avatar
pem@mysql.com committed
1081
	  if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1082
						 TL_OPTION_UPDATING,
pem@mysql.com's avatar
pem@mysql.com committed
1083
						 (using_update_log ?
1084 1085
						  TL_READ_NO_INSERT:
						  TL_READ)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1086 1087 1088 1089 1090 1091 1092
	    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;
1093
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
monty@mysql.com's avatar
monty@mysql.com committed
1094
	  lex->create_info.default_table_charset= NULL;
venu@myvenu.com's avatar
venu@myvenu.com committed
1095
	  lex->name=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1096 1097
	}
	create2
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1098
	  { Lex->current_select= &Lex->select_lex; }
monty@mysql.com's avatar
monty@mysql.com committed
1099
	| CREATE opt_unique_or_fulltext INDEX_SYM ident key_alg ON table_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1100
	  {
1101 1102
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1103 1104
	    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
1105
	      YYABORT;
1106 1107 1108 1109
	    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
1110
	  }
1111
	   '(' key_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1112
	  {
1113
	    LEX *lex=Lex;
1114

pem@mysql.com's avatar
pem@mysql.com committed
1115
	    lex->key_list.push_back(new Key($2,$4.str, $5, 0, lex->col_list));
1116
	    lex->col_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1117 1118
	  }
	| CREATE DATABASE opt_if_not_exists ident
1119
	  { Lex->create_info.default_table_charset=NULL; }
1120
	  opt_create_database_options
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1121
	  {
1122 1123 1124 1125
	    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
1126
	  }
1127
	| CREATE udf_func_type FUNCTION_SYM sp_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1128
	  {
1129
	    LEX *lex=Lex;
1130
	    lex->spname= $4;
1131
	    lex->udf.type= $2;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1132
	  }
1133 1134
	  create_function_tail
	  {}
1135
	| CREATE PROCEDURE sp_name
1136 1137
	  {
	    LEX *lex= Lex;
1138
	    sp_head *sp;
1139

1140 1141 1142 1143 1144
	    if (lex->sphead)
	    {
	      net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "PROCEDURE");
	      YYABORT;
	    }
1145 1146 1147
	    /* Order is important here: new - reset - init */
	    sp= new sp_head();
	    sp->reset_thd_mem_root(YYTHD);
1148
	    sp->init(lex);
1149 1150 1151

	    sp->m_type= TYPE_ENUM_PROCEDURE;
	    lex->sphead= sp;
1152 1153 1154 1155 1156
	    /*
	     * We have to turn of CLIENT_MULTI_QUERIES while parsing a
	     * stored procedure, otherwise yylex will chop it into pieces
	     * at each ';'.
	     */
1157
	    sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
1158
	    YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES);
1159
	  }
1160
          '('
1161
	  {
1162 1163
	    LEX *lex= Lex;

1164 1165 1166 1167 1168 1169 1170 1171
	    lex->sphead->m_param_begin= lex->tok_start+1;
	  }
	  sp_pdparam_list
	  ')'
	  {
	    LEX *lex= Lex;

	    lex->sphead->m_param_end= lex->tok_start;
1172 1173
	    lex->spcont->set_params();
	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
1174
	  }
1175
	  sp_c_chistics
1176
	  {
1177 1178 1179
	    LEX *lex= Lex;

	    lex->sphead->m_chistics= &lex->sp_chistics;
1180
	    lex->sphead->m_body_begin= lex->tok_start;
1181
	  }
1182
	  sp_proc_stmt
1183
	  {
1184 1185
	    LEX *lex= Lex;

1186
	    lex->sphead->init_strings(YYTHD, lex, $3);
1187 1188 1189 1190
	    lex->sql_command= SQLCOM_CREATE_PROCEDURE;
	    /* Restore flag if it was cleared above */
	    if (lex->sphead->m_old_cmq)
	      YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
1191
	    lex->sphead->restore_thd_mem_root(YYTHD);
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
	  }
	| CREATE or_replace algorithm VIEW_SYM table_ident
	  {
	    THD *thd= YYTHD;
	    LEX *lex= thd->lex;
	    lex->sql_command= SQLCOM_CREATE_VIEW;
	    lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
	    /* first table in list is target VIEW name */
	    if (!lex->select_lex.add_table_to_list(thd, $5, NULL, 0))
              YYABORT;
	  }
	  opt_view_list AS select_init check_option
	  {}
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
        | CREATE TRIGGER_SYM ident trg_action_time trg_event 
          ON table_ident FOR_SYM EACH_SYM ROW_SYM
          {
            LEX *lex= Lex;
            sp_head *sp;
           
            lex->name_and_length= $3;
           
            /* QQ: Could we loosen lock type in certain cases ? */
            if (!lex->select_lex.add_table_to_list(YYTHD, $7, 
                                                   (LEX_STRING*) 0,
                                                   TL_OPTION_UPDATING,
                                                   TL_WRITE))
              YYABORT;
              
            if (lex->sphead)
            {
              net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "TRIGGER");
              YYABORT;
            }
            
            sp= new sp_head();
            sp->reset_thd_mem_root(YYTHD);
            sp->init(lex);
            
            sp->m_type= TYPE_ENUM_TRIGGER;
            lex->sphead= sp;
            /*
              We have to turn of CLIENT_MULTI_QUERIES while parsing a
              stored procedure, otherwise yylex will chop it into pieces
              at each ';'.
            */
            sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
            YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
            
            bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
            lex->sphead->m_chistics= &lex->sp_chistics;
            lex->sphead->m_body_begin= lex->tok_start;
          }
          sp_proc_stmt
          {
            LEX *lex= Lex;
            sp_head *sp= lex->sphead;
            
            lex->sql_command= SQLCOM_CREATE_TRIGGER;
            sp->init_strings(YYTHD, lex, NULL);
            /* Restore flag if it was cleared above */
            if (sp->m_old_cmq)
              YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
            sp->restore_thd_mem_root(YYTHD);
          }
1256 1257
	;

1258
sp_name:
1259 1260 1261 1262 1263 1264 1265 1266 1267
	  IDENT_sys '.' IDENT_sys
	  {
	    $$= new sp_name($1, $3);
	    $$->init_qname(YYTHD);
	  }
	| IDENT_sys
	  {
	    $$= sp_name_current_db_new(YYTHD, $1);
	  }
1268 1269
	;

1270
create_function_tail:
pem@mysql.com's avatar
pem@mysql.com committed
1271
	  RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1272
	  {
1273
	    LEX *lex=Lex;
1274
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
1275
	    lex->udf.name = lex->spname->m_name;
1276 1277
	    lex->udf.returns=(Item_result) $2;
	    lex->udf.dl=$4.str;
1278
	  }
1279 1280 1281
	| '('
	  {
	    LEX *lex= Lex;
1282
	    sp_head *sp;
1283

1284 1285 1286 1287 1288
	    if (lex->sphead)
	    {
	      net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "FUNCTION");
	      YYABORT;
	    }
1289 1290 1291
	    /* Order is important here: new - reset - init */
	    sp= new sp_head();
	    sp->reset_thd_mem_root(YYTHD);
1292
	    sp->init(lex);
1293 1294 1295

	    sp->m_type= TYPE_ENUM_FUNCTION;
	    lex->sphead= sp;
1296 1297 1298 1299 1300
	    /*
	     * We have to turn of CLIENT_MULTI_QUERIES while parsing a
	     * stored procedure, otherwise yylex will chop it into pieces
	     * at each ';'.
	     */
1301
	    sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
1302
	    YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
1303
	    lex->sphead->m_param_begin= lex->tok_start+1;
1304 1305 1306
	  }
          sp_fdparam_list ')'
	  {
1307 1308 1309 1310 1311 1312 1313
	    LEX *lex= Lex;

	    lex->spcont->set_params();
	    lex->sphead->m_param_end= lex->tok_start;
	  }
	  RETURNS_SYM
	  {
1314 1315 1316 1317 1318
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;

	    sp->m_returns_begin= lex->tok_start;
	    sp->m_returns_cs= lex->charset= NULL;
1319
	  }
1320
	  type
1321
	  {
1322
	    LEX *lex= Lex;
1323
	    sp_head *sp= lex->sphead;
1324

1325 1326 1327
	    sp->m_returns_end= lex->tok_start;
	    sp->m_returns= (enum enum_field_types)$8;
	    sp->m_returns_cs= lex->charset;
1328
	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
1329
	  }
1330
	  sp_c_chistics
1331
	  {
1332 1333 1334
	    LEX *lex= Lex;

	    lex->sphead->m_chistics= &lex->sp_chistics;
1335
	    lex->sphead->m_body_begin= lex->tok_start;
1336
	  }
1337
	  sp_proc_stmt
1338
	  {
1339
	    LEX *lex= Lex;
1340
	    sp_head *sp= lex->sphead;
1341

1342
	    lex->sql_command= SQLCOM_CREATE_SPFUNCTION;
1343
	    sp->init_strings(YYTHD, lex, lex->spname);
1344
	    /* Restore flag if it was cleared above */
1345
	    if (sp->m_old_cmq)
1346
	      YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
1347
	    sp->restore_thd_mem_root(YYTHD);
1348
	  }
1349 1350
	;

1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
sp_a_chistics:
	  /* Empty */ {}
	| sp_a_chistics sp_a_chistic {}
	;

sp_c_chistics:
	  /* Empty */ {}
	| sp_c_chistics sp_c_chistic {}
	;

/* Characteristics for both create and alter */
sp_chistic:
	  COMMENT_SYM TEXT_STRING_sys { Lex->sp_chistics.comment= $2; }
	| sp_suid { }
1365 1366
	;

1367 1368 1369 1370
/* Alter characteristics */
sp_a_chistic:
	  sp_chistic     { }
	| NAME_SYM ident { Lex->name= $2.str; }
1371 1372
	;

1373 1374 1375 1376 1377 1378 1379
/* Create characteristics */
sp_c_chistic:
	  sp_chistic            { }
	| LANGUAGE_SYM SQL_SYM  { }
	| DETERMINISTIC_SYM     { Lex->sp_chistics.detistic= TRUE; }
	| NOT DETERMINISTIC_SYM { Lex->sp_chistics.detistic= FALSE; }
	;
1380 1381

sp_suid:
1382 1383 1384 1385 1386 1387 1388 1389
	  SQL_SYM SECURITY_SYM DEFINER_SYM
	  {
	    Lex->sp_chistics.suid= IS_SUID;
	  }
	| SQL_SYM SECURITY_SYM INVOKER_SYM
	  {
	    Lex->sp_chistics.suid= IS_NOT_SUID;
	  }
1390 1391
	;

1392
call:
1393
	  CALL_SYM sp_name
1394 1395 1396 1397
	  {
	    LEX *lex = Lex;

	    lex->sql_command= SQLCOM_CALL;
1398
	    lex->spname= $2;
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
	    lex->value_list.empty();
	  }
          '(' sp_cparam_list ')' {}
	;

/* CALL parameters */
sp_cparam_list:
	  /* Empty */
	| sp_cparams
	;

sp_cparams:
	  sp_cparams ',' expr
	  {
	    Lex->value_list.push_back($3);
	  }
	| expr
	  {
	    Lex->value_list.push_back($1);
	  }
	;

1421 1422
/* Stored FUNCTION parameter declaration list */
sp_fdparam_list:
1423
	  /* Empty */
1424
	| sp_fdparams
1425 1426
	;

1427 1428 1429
sp_fdparams:
	  sp_fdparams ',' sp_fdparam
	| sp_fdparam
1430 1431
	;

1432
sp_fdparam:
1433
	  ident type
1434
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1435 1436 1437 1438 1439
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$1, TRUE))
	    {
1440
	      net_printf(YYTHD, ER_SP_DUP_PARAM, $1.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1441 1442 1443
	      YYABORT;
	    }
	    spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in);
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
	  }
	;

/* Stored PROCEDURE parameter declaration list */
sp_pdparam_list:
	  /* Empty */
	| sp_pdparams
	;

sp_pdparams:
	  sp_pdparams ',' sp_pdparam
	| sp_pdparam
	;

sp_pdparam:
1459
	  sp_opt_inout ident type
1460
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1461 1462 1463 1464 1465
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$2, TRUE))
	    {
1466
	      net_printf(YYTHD, ER_SP_DUP_PARAM, $2.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1467 1468 1469 1470
	      YYABORT;
	    }
	    spc->push_pvar(&$2, (enum enum_field_types)$3,
			   (sp_param_mode_t)$1);
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
	  }
	;

sp_opt_inout:
	  /* Empty */ { $$= sp_param_in; }
	| IN_SYM      { $$= sp_param_in; }
	| OUT_SYM     { $$= sp_param_out; }
	| INOUT_SYM   { $$= sp_param_inout; }
	;

sp_proc_stmts:
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1482
	  /* Empty */ {}
1483
	| sp_proc_stmts sp_proc_stmt ';'
1484 1485 1486 1487 1488
	;

sp_decls:
	  /* Empty */
	  {
1489
	    $$.vars= $$.conds= $$.hndlrs= $$.curs= 0;
1490 1491 1492
	  }
	| sp_decls sp_decl ';'
	  {
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
	    /* We check for declarations out of (standard) order this way
	       because letting the grammar rules reflect it caused tricky
	       shift/reduce conflicts with the wrong result. (And we get
	       better error handling this way.) */
	    if (($2.vars || $2.conds) && ($1.curs || $1.hndlrs))
	    { /* Variable or condition following cursor or handler */
	      send_error(YYTHD, ER_SP_VARCOND_AFTER_CURSHNDLR);
	      YYABORT;
	    }
	    if ($2.curs && $1.hndlrs)
	    { /* Cursor following handler */
	      send_error(YYTHD, ER_SP_CURSOR_AFTER_HANDLER);
	      YYABORT;
	    }
1507 1508 1509
	    $$.vars= $1.vars + $2.vars;
	    $$.conds= $1.conds + $2.conds;
	    $$.hndlrs= $1.hndlrs + $2.hndlrs;
1510
	    $$.curs= $1.curs + $2.curs;
1511 1512 1513 1514
	  }
	;

sp_decl:
1515
	  DECLARE_SYM sp_decl_idents type sp_opt_default
1516 1517 1518
	  {
	    LEX *lex= Lex;
	    uint max= lex->spcont->current_framesize();
1519 1520
	    enum enum_field_types type= (enum enum_field_types)$3;
	    Item *it= $4;
1521 1522 1523

	    for (uint i = max-$2 ; i < max ; i++)
	    {
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533
	      lex->spcont->set_type(i, type);
	      if (! it)
	        lex->spcont->set_isset(i, FALSE);
	      else
	      {
	        sp_instr_set *in= new sp_instr_set(lex->sphead->instructions(),
	                                           i, it, type);

	        lex->sphead->add_instr(in);
	        lex->spcont->set_isset(i, TRUE);
1534
		lex->spcont->set_default(i, it);
1535
	      }
1536
	    }
1537
	    $$.vars= $2;
1538
	    $$.conds= $$.hndlrs= $$.curs= 0;
1539 1540 1541
	  }
	| DECLARE_SYM ident CONDITION_SYM FOR_SYM sp_cond
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1542 1543 1544 1545 1546
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_cond(&$2, TRUE))
	    {
1547
	      net_printf(YYTHD, ER_SP_DUP_COND, $2.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1548 1549
	      YYABORT;
	    }
1550
	    YYTHD->lex->spcont->push_cond(&$2, $5);
1551
	    $$.vars= $$.hndlrs= $$.curs= 0;
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
	    $$.conds= 1;
	  }
	| DECLARE_SYM sp_handler_type HANDLER_SYM FOR_SYM
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_pcontext *ctx= lex->spcont;
	    sp_instr_hpush_jump *i=
              new sp_instr_hpush_jump(sp->instructions(), $2,
	                              ctx->current_framesize());

	    sp->add_instr(i);
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
	    ctx->add_handler();
	  }
	  sp_hcond_list sp_proc_stmt
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_label_t *hlab= lex->spcont->pop_label(); /* After this hdlr */

	    if ($2 == SP_HANDLER_CONTINUE)
	      sp->add_instr(new sp_instr_hreturn(sp->instructions(),
	                                         lex->spcont->current_framesize()));
	    else
	    {  /* EXIT or UNDO handler, just jump to the end of the block */
	      sp_instr_jump *i= new sp_instr_jump(sp->instructions());

	      sp->add_instr(i);
	      sp->push_backpatch(i, lex->spcont->last_label()); /* Block end */
	    }
	    lex->sphead->backpatch(hlab);
1584
	    $$.vars= $$.conds= $$.curs= 0;
1585 1586 1587 1588
	    $$.hndlrs= $6;
	  }
	| DECLARE_SYM ident CURSOR_SYM FOR_SYM sp_cursor_stmt
	  {
1589 1590
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1591 1592 1593
	    sp_pcontext *spc= lex->spcont;
	    uint offp;
	    sp_instr_cpush *i;
1594

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1595 1596
	    if (spc->find_cursor(&$2, &offp, TRUE))
	    {
1597 1598
	      net_printf(YYTHD, ER_SP_DUP_CURS, $2.str);
	      delete $5;
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1599 1600 1601
	      YYABORT;
	    }
            i= new sp_instr_cpush(sp->instructions(), $5);
1602 1603
	    sp->add_instr(i);
	    lex->spcont->push_cursor(&$2);
1604
	    $$.vars= $$.conds= $$.hndlrs= 0;
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
	    $$.curs= 1;
	  }
	;

sp_cursor_stmt:
	  {
	    Lex->sphead->reset_lex(YYTHD);

	    /* We use statement here just be able to get a better
	       error message. Using 'select' works too, but will then
	       result in a generic "syntax error" if a non-select
	       statement is given. */
	  }
	  statement
	  {
	    LEX *lex= Lex;

	    if (lex->sql_command != SQLCOM_SELECT)
	    {
	      send_error(YYTHD, ER_SP_BAD_CURSOR_QUERY);
	      YYABORT;
	    }
	    if (lex->result)
	    {
	      send_error(YYTHD, ER_SP_BAD_CURSOR_SELECT);
	      YYABORT;
	    }
	    lex->sp_lex_in_use= TRUE;
	    $$= lex;
	    lex->sphead->restore_lex(YYTHD);
	  }
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
	;

sp_handler_type:
	  EXIT_SYM      { $$= SP_HANDLER_EXIT; }
	| CONTINUE_SYM  { $$= SP_HANDLER_CONTINUE; }
/*	| UNDO_SYM      { QQ No yet } */
	;

sp_hcond_list:
	  sp_hcond
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_instr_hpush_jump *i= (sp_instr_hpush_jump *)sp->last_instruction();

	    i->add_condition($1);
	    $$= 1;
	  }
	| sp_hcond_list ',' sp_hcond
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_instr_hpush_jump *i= (sp_instr_hpush_jump *)sp->last_instruction();

	    i->add_condition($3);
	    $$= $1 + 1;
	  }
	;

sp_cond:
	  ULONG_NUM
	  {			/* mysql errno */
	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
	    $$->type= sp_cond_type_t::number;
	    $$->mysqlerr= $1;
	  }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1672
	| SQLSTATE_SYM opt_value TEXT_STRING_literal
1673
	  {		/* SQLSTATE */
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1674 1675
	    uint len= ($3.length < sizeof($$->sqlstate)-1 ?
                       $3.length : sizeof($$->sqlstate)-1);
1676 1677 1678

	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
	    $$->type= sp_cond_type_t::state;
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1679
	    memcpy($$->sqlstate, $3.str, len);
1680 1681 1682 1683
	    $$->sqlstate[len]= '\0';
	  }
	;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1684 1685 1686 1687 1688
opt_value:
	  /* Empty */  {}
	| VALUE_SYM    {}
	;

1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
sp_hcond:
	  sp_cond
	  {
	    $$= $1;
	  }
	| ident			/* CONDITION name */
	  {
	    $$= Lex->spcont->find_cond(&$1);
	    if ($$ == NULL)
	    {
	      net_printf(YYTHD, ER_SP_COND_MISMATCH, $1.str);
	      YYABORT;
	    }
	  }
	| SQLWARNING_SYM	/* SQLSTATEs 01??? */
	  {
	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
	    $$->type= sp_cond_type_t::warning;
	  }
	| NOT FOUND_SYM		/* SQLSTATEs 02??? */
	  {
	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
	    $$->type= sp_cond_type_t::notfound;
	  }
	| SQLEXCEPTION_SYM	/* All other SQLSTATEs */
	  {
	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
	    $$->type= sp_cond_type_t::exception;
1717 1718 1719 1720 1721 1722
	  }
	;

sp_decl_idents:
	  ident
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1723 1724 1725 1726 1727
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$1, TRUE))
	    {
1728
	      net_printf(YYTHD, ER_SP_DUP_VAR, $1.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1729 1730 1731
	      YYABORT;
	    }
	    spc->push_pvar(&$1, (enum_field_types)0, sp_param_in);
1732 1733 1734 1735
	    $$= 1;
	  }
	| sp_decl_idents ',' ident
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1736 1737 1738 1739 1740
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$3, TRUE))
	    {
1741
	      net_printf(YYTHD, ER_SP_DUP_VAR, $3.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1742 1743 1744
	      YYABORT;
	    }
	    spc->push_pvar(&$3, (enum_field_types)0, sp_param_in);
1745 1746 1747 1748
	    $$= $1 + 1;
	  }
	;

1749 1750 1751 1752 1753
sp_opt_default:
	  /* Empty */ { $$ = NULL; }
        | DEFAULT expr { $$ = $2; }
	;

1754
sp_proc_stmt:
1755 1756 1757
	  {
	    Lex->sphead->reset_lex(YYTHD);
	  }
1758 1759 1760 1761
	  statement
	  {
	    LEX *lex= Lex;

1762 1763 1764 1765 1766 1767
	    /* QQ What else? This doesn't seem to be a practical way,
	          but at the moment we can't think of anything better... */
	    if ((lex->sql_command == SQLCOM_SELECT && !lex->result) ||
	        lex->sql_command == SQLCOM_SHOW_CREATE_PROC ||
	        lex->sql_command == SQLCOM_SHOW_CREATE_FUNC ||
	        lex->sql_command == SQLCOM_SHOW_STATUS_PROC ||
1768 1769
	        lex->sql_command == SQLCOM_SHOW_STATUS_FUNC ||
		lex->sql_command == SQLCOM_ANALYZE)
1770
	    {
1771
	      /* We maybe have one or more SELECT without INTO */
1772
	      lex->sphead->m_multi_results= TRUE;
1773
	    }
1774 1775 1776 1777 1778
	    if (lex->sql_command == SQLCOM_CHANGE_DB)
	    { /* "USE db" doesn't work in a procedure */
	      send_error(YYTHD, ER_SP_NO_USE);
	      YYABORT;
	    }
1779 1780 1781 1782 1783
	    /* Don't add an instruction for empty SET statements.
	    ** (This happens if the SET only contained local variables,
	    **  which get their set instructions generated separately.)
	    */
	    if (lex->sql_command != SQLCOM_SET_OPTION ||
1784
		! lex->var_list.is_empty())
1785
	    {
1786 1787 1788 1789 1790 1791 1792 1793
              /*
                Currently we can't handle queries inside a FUNCTION or
                TRIGGER, because of the way table locking works. This is 
                unfortunate, and limits the usefulness of functions and
                especially triggers a tremendously, but it's nothing we 
                can do about this at the moment.
              */
	      if (lex->sphead->m_type != TYPE_ENUM_PROCEDURE)
1794
	      {
1795
		send_error(YYTHD, ER_SP_BADSTATEMENT);
1796 1797 1798 1799 1800 1801 1802 1803
		YYABORT;
	      }
	      else
	      {
		sp_instr_stmt *i=new sp_instr_stmt(lex->sphead->instructions());

		i->set_lex(lex);
		lex->sphead->add_instr(i);
1804
		lex->sp_lex_in_use= TRUE;
1805 1806 1807
	      }
            }
	    lex->sphead->restore_lex(YYTHD);
1808
          }
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
	| RETURN_SYM expr
	  {
	    LEX *lex= Lex;

	    if (lex->sphead->m_type == TYPE_ENUM_PROCEDURE)
	    {
	      send_error(YYTHD, ER_SP_BADRETURN);
	      YYABORT;
	    }
	    else
	    {
1820
	      sp_instr_freturn *i;
1821

1822 1823 1824 1825 1826 1827 1828
	      if ($2->type() == Item::SUBSELECT_ITEM)
	      {  /* QQ For now, just disallow subselects as values */
	        send_error(lex->thd, ER_SP_BADSTATEMENT);
	        YYABORT;
	      }
	      i= new sp_instr_freturn(lex->sphead->instructions(),
		                      $2, lex->sphead->m_returns);
1829
	      lex->sphead->add_instr(i);
1830
	      lex->sphead->m_has_return= TRUE;
1831 1832
	    }
	  }
1833
	| IF sp_if END IF {}
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
	| CASE_SYM WHEN_SYM
	  {
	    Lex->sphead->m_simple_case= FALSE;
	  }
	  sp_case END CASE_SYM {}
	| CASE_SYM expr WHEN_SYM
	  {
	    /* We "fake" this by using an anonymous variable which we
	       set to the expression. Note that all WHENs are evaluate
	       at the same frame level, so we then know that it's the
	       top-most variable in the frame. */
	    LEX *lex= Lex;
	    uint offset= lex->spcont->current_framesize();
	    sp_instr_set *i = new sp_instr_set(lex->sphead->instructions(),
	                                       offset, $2, MYSQL_TYPE_STRING);
	    LEX_STRING dummy;

	    dummy.str= (char *)"";
	    dummy.length= 0;
1853
	    lex->spcont->push_pvar(&dummy, MYSQL_TYPE_STRING, sp_param_in);
1854 1855 1856 1857 1858
	    lex->sphead->add_instr(i);
	    lex->sphead->m_simple_case= TRUE;
	  }
	  sp_case END CASE_SYM
	  {
1859
	    Lex->spcont->pop_pvar();
1860
	  }
1861 1862 1863 1864 1865
	| sp_labeled_control
	  {}
	| { /* Unlabeled controls get a secret label. */
	    LEX *lex= Lex;

1866
	    lex->spcont->push_label((char *)"", lex->sphead->instructions());
1867 1868 1869
	  }
	  sp_unlabeled_control
	  {
1870 1871
	    LEX *lex= Lex;

1872
	    lex->sphead->backpatch(lex->spcont->pop_label());
1873 1874 1875 1876
	  }
	| LEAVE_SYM IDENT
	  {
	    LEX *lex= Lex;
1877
	    sp_head *sp = lex->sphead;
1878 1879 1880 1881
	    sp_label_t *lab= lex->spcont->find_label($2.str);

	    if (! lab)
	    {
1882
	      net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE", $2.str);
1883 1884 1885 1886
	      YYABORT;
	    }
	    else
	    {
1887
	      sp_instr_jump *i= new sp_instr_jump(sp->instructions());
1888

1889 1890
	      sp->push_backpatch(i, lab);  /* Jumping forward */
              sp->add_instr(i);
1891 1892 1893 1894 1895 1896 1897
	    }
	  }
	| ITERATE_SYM IDENT
	  {
	    LEX *lex= Lex;
	    sp_label_t *lab= lex->spcont->find_label($2.str);

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1898
	    if (! lab || lab->isbegin)
1899
	    {
1900
	      net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE", $2.str);
1901 1902 1903 1904 1905
	      YYABORT;
	    }
	    else
	    {
	      uint ip= lex->sphead->instructions();
1906
	      sp_instr_jump *i= new sp_instr_jump(ip, lab->ip); /* Jump back */
1907 1908 1909 1910

              lex->sphead->add_instr(i);
	    }
	  }
1911
	| OPEN_SYM ident
1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    uint offset;
	    sp_instr_copen *i;

	    if (! lex->spcont->find_cursor(&$2, &offset))
	    {
	      net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str);
	      YYABORT;
	    }
	    i= new sp_instr_copen(sp->instructions(), offset);
	    sp->add_instr(i);
	  }
	| FETCH_SYM ident INTO
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    uint offset;
	    sp_instr_cfetch *i;

	    if (! lex->spcont->find_cursor(&$2, &offset))
	    {
	      net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str);
	      YYABORT;
	    }
	    i= new sp_instr_cfetch(sp->instructions(), offset);
	    sp->add_instr(i);
	  }
	  sp_fetch_list
	  { }
1943
	| CLOSE_SYM ident
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    uint offset;
	    sp_instr_cclose *i;

	    if (! lex->spcont->find_cursor(&$2, &offset))
	    {
	      net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str);
	      YYABORT;
	    }
	    i= new sp_instr_cclose(sp->instructions(), offset);
	    sp->add_instr(i);
	  }
	;

sp_fetch_list:
	  ident
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_pcontext *spc= lex->spcont;
	    sp_pvar_t *spv;

	    if (!spc || !(spv = spc->find_pvar(&$1)))
	    {
	      net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str);
	      YYABORT;
	    }
	    else
	    { /* An SP local variable */
	      sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction();

	      i->add_to_varlist(spv);
	      spv->isset= TRUE;
	    }
	  }
	|
	  sp_fetch_list ',' ident
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_pcontext *spc= lex->spcont;
	    sp_pvar_t *spv;

	    if (!spc || !(spv = spc->find_pvar(&$3)))
	    {
	      net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $3.str);
	      YYABORT;
	    }
	    else
	    { /* An SP local variable */
	      sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction();

	      i->add_to_varlist(spv);
	      spv->isset= TRUE;
	    }
	  }
2002
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2003

2004 2005 2006 2007 2008 2009 2010 2011
sp_if:
	  expr THEN_SYM
	  {
	    sp_head *sp= Lex->sphead;
	    sp_pcontext *ctx= Lex->spcont;
	    uint ip= sp->instructions();
	    sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $1);

2012
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
            sp->add_instr(i);
	  }
	  sp_proc_stmts
	  {
	    sp_head *sp= Lex->sphead;
	    sp_pcontext *ctx= Lex->spcont;
	    uint ip= sp->instructions();
	    sp_instr_jump *i = new sp_instr_jump(ip);

	    sp->add_instr(i);
	    sp->backpatch(ctx->pop_label());
2024
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
2025 2026 2027 2028 2029
	  }
	  sp_elseifs
	  {
	    LEX *lex= Lex;

2030
	    lex->sphead->backpatch(lex->spcont->pop_label());
2031 2032 2033 2034 2035 2036 2037 2038 2039
	  }
	;

sp_elseifs:
	  /* Empty */
	| ELSEIF_SYM sp_if
	| ELSE sp_proc_stmts
	;

2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051
sp_case:
	  expr THEN_SYM
	  {
	    sp_head *sp= Lex->sphead;
	    sp_pcontext *ctx= Lex->spcont;
	    uint ip= sp->instructions();
	    sp_instr_jump_if_not *i;

	    if (! sp->m_simple_case)
	      i= new sp_instr_jump_if_not(ip, $1);
	    else
	    { /* Simple case: <caseval> = <whenval> */
2052 2053
	      LEX_STRING ivar;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2054
	      ivar.str= (char *)"_tmp_";
2055 2056 2057
	      ivar.length= 5;
	      Item *var= (Item*) new Item_splocal(ivar, 
						  ctx->current_framesize()-1);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2058
	      Item *expr= new Item_func_eq(var, $1);
2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084

	      i= new sp_instr_jump_if_not(ip, expr);
	    }
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
            sp->add_instr(i);
	  }
	  sp_proc_stmts
	  {
	    sp_head *sp= Lex->sphead;
	    sp_pcontext *ctx= Lex->spcont;
	    uint ip= sp->instructions();
	    sp_instr_jump *i = new sp_instr_jump(ip);

	    sp->add_instr(i);
	    sp->backpatch(ctx->pop_label());
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
	  }
	  sp_whens
	  {
	    LEX *lex= Lex;

	    lex->sphead->backpatch(lex->spcont->pop_label());
	  }
	;

sp_whens:
2085 2086 2087 2088 2089 2090 2091 2092
	  /* Empty */
	  {
	    sp_head *sp= Lex->sphead;
	    uint ip= sp->instructions();
	    sp_instr_error *i= new sp_instr_error(ip, ER_SP_CASE_NOT_FOUND);

	    sp->add_instr(i);
	  }
2093
	| ELSE sp_proc_stmts {}
2094
	| WHEN_SYM sp_case {}
2095 2096
	;

2097 2098 2099 2100 2101 2102 2103 2104
sp_labeled_control:
	  IDENT ':'
	  {
	    LEX *lex= Lex;
	    sp_label_t *lab= lex->spcont->find_label($1.str);

	    if (lab)
	    {
2105
	      net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $1.str);
2106 2107 2108
	      YYABORT;
	    }
	    else
2109
	    {
2110 2111
	      lex->spcont->push_label($1.str,
	                              lex->sphead->instructions());
2112
	    }
2113
	  }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2114
	  sp_unlabeled_control sp_opt_label
2115 2116 2117
	  {
	    LEX *lex= Lex;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2118
	    if ($5.str)
2119
	    {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2120 2121 2122 2123 2124 2125 2126 2127
	      sp_label_t *lab= lex->spcont->find_label($5.str);

	      if (!lab ||
	          my_strcasecmp(system_charset_info, $5.str, lab->name) != 0)
	      {
	        net_printf(YYTHD, ER_SP_LABEL_MISMATCH, $5.str);
	        YYABORT;
	      }
2128
	    }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2129
	    lex->sphead->backpatch(lex->spcont->pop_label());
2130 2131 2132
	  }
	;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2133 2134 2135 2136 2137 2138 2139
sp_opt_label:
	  /* Empty  */
	  { $$.str= NULL; $$.length= 0; }
	| IDENT
	  { $$= $1; }
	;

2140
sp_unlabeled_control:
2141 2142 2143 2144
	  BEGIN_SYM
	  { /* QQ This is just a dummy for grouping declarations and statements
	       together. No [[NOT] ATOMIC] yet, and we need to figure out how
	       make it coexist with the existing BEGIN COMMIT/ROLLBACK. */
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2145 2146
	    LEX *lex= Lex;
	    sp_label_t *lab= lex->spcont->last_label();
2147

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2148 2149 2150
	    lab->isbegin= TRUE;
	    /* Scope duplicate checking */
	    lex->spcont->push_scope();
2151 2152 2153 2154 2155 2156 2157 2158 2159
	  }
	  sp_decls
	  sp_proc_stmts
	  END
	  {
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
	    sp_pcontext *ctx= lex->spcont;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2160
  	    sp->backpatch(ctx->last_label());	/* We always has a label */
2161 2162
	    ctx->pop_pvar($3.vars);
	    ctx->pop_cond($3.conds);
2163
	    ctx->pop_cursor($3.curs);
2164
	    if ($3.hndlrs)
2165 2166 2167
	      sp->add_instr(new sp_instr_hpop(sp->instructions(),$3.hndlrs));
	    if ($3.curs)
	      sp->add_instr(new sp_instr_cpop(sp->instructions(), $3.curs));
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
2168
	    ctx->pop_scope();
2169 2170
	  }
	| LOOP_SYM
2171 2172 2173 2174 2175 2176 2177 2178 2179
	  sp_proc_stmts END LOOP_SYM
	  {
	    LEX *lex= Lex;
	    uint ip= lex->sphead->instructions();
	    sp_label_t *lab= lex->spcont->last_label();  /* Jumping back */
	    sp_instr_jump *i = new sp_instr_jump(ip, lab->ip);

	    lex->sphead->add_instr(i);
	  }
2180
	| WHILE_SYM expr DO_SYM
2181 2182
	  {
	    LEX *lex= Lex;
2183 2184
	    sp_head *sp= lex->sphead;
	    uint ip= sp->instructions();
2185 2186
	    sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $2);

2187 2188 2189
	    /* Jumping forward */
	    sp->push_backpatch(i, lex->spcont->last_label());
            sp->add_instr(i);
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199
	  }
	  sp_proc_stmts END WHILE_SYM
	  {
	    LEX *lex= Lex;
	    uint ip= lex->sphead->instructions();
	    sp_label_t *lab= lex->spcont->last_label();  /* Jumping back */
	    sp_instr_jump *i = new sp_instr_jump(ip, lab->ip);

	    lex->sphead->add_instr(i);
	  }
2200 2201
	| REPEAT_SYM sp_proc_stmts UNTIL_SYM expr END REPEAT_SYM
	  {
2202 2203 2204 2205 2206 2207 2208
	    LEX *lex= Lex;
	    uint ip= lex->sphead->instructions();
	    sp_label_t *lab= lex->spcont->last_label();  /* Jumping back */
	    sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $4, lab->ip);

            lex->sphead->add_instr(i);
	  }
2209
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2210

2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226
trg_action_time:
            BEFORE_SYM 
            { Lex->trg_chistics.action_time= TRG_ACTION_BEFORE; }
          | AFTER_SYM 
            { Lex->trg_chistics.action_time= TRG_ACTION_AFTER; }
          ;

trg_event:
            INSERT 
            { Lex->trg_chistics.event= TRG_EVENT_INSERT; }
          | UPDATE_SYM
            { Lex->trg_chistics.event= TRG_EVENT_UPDATE; }
          | DELETE_SYM
            { Lex->trg_chistics.event= TRG_EVENT_DELETE; }
          ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2227
create2:
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2228
 	'(' create2a {}
2229
	| opt_create_table_options create3 {}
venu@myvenu.com's avatar
venu@myvenu.com committed
2230 2231 2232 2233 2234 2235
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
2236 2237 2238 2239 2240 2241
	| '(' LIKE table_ident ')'
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$3))
              YYABORT;
    	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2242
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2243

serg@serg.mylan's avatar
serg@serg.mylan committed
2244 2245
create2a:
        field_list ')' opt_create_table_options create3 {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2246
	|  create_select ')' { Select->set_braces(1);} union_opt {}
2247
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2248 2249

create3:
2250
	/* empty */ {}
serg@serg.mylan's avatar
serg@serg.mylan committed
2251
	| opt_duplicate opt_as     create_select
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2252
          { Select->set_braces(0);} union_clause {}
serg@serg.mylan's avatar
serg@serg.mylan committed
2253
	| opt_duplicate opt_as '(' create_select ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2254
          { Select->set_braces(1);} union_opt {}
2255 2256
        ;

serg@serg.mylan's avatar
serg@serg.mylan committed
2257
create_select:
2258
          SELECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2259
          {
2260 2261
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
2262 2263 2264 2265
	    if (lex->sql_command == SQLCOM_INSERT)
	      lex->sql_command= SQLCOM_INSERT_SELECT;
	    else if (lex->sql_command == SQLCOM_REPLACE)
	      lex->sql_command= SQLCOM_REPLACE_SELECT;
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
2266 2267 2268 2269
	    /*
	      following work only with local list, global list is
	      created correctly in this case
	    */
2270
	    lex->current_select->table_list.save_and_clear(&lex->save_list);
2271
	    mysql_init_select(lex);
2272
	    lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2273
          }
2274 2275 2276 2277
          select_options select_item_list
	  {
	    Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2278
	  opt_select_from
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
2279 2280 2281 2282 2283 2284 2285
	  {
	    /*
	      following work only with local list, global list is
	      created correctly in this case
	    */
	    Lex->current_select->table_list.push_front(&Lex->save_list);
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2286
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2287

2288 2289
opt_as:
	/* empty */ {}
2290
	| AS	    {};
2291

2292 2293 2294 2295 2296 2297 2298 2299 2300
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
2301 2302
	  opt_default COLLATE_SYM collation_name_or_default	
	  { Lex->create_info.default_table_charset=$3; }
2303
	| opt_default charset charset_name_or_default
2304
	  { Lex->create_info.default_table_charset=$3; }
2305
	;
2306

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2307
opt_table_options:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2308
	/* empty */	 { $$= 0; }
2309
	| table_options  { $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2310 2311 2312

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2315
table_option:
2316
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2317 2318

opt_if_not_exists:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2319
	/* empty */	 { $$= 0; }
2320
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2321 2322 2323

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

2326 2327 2328 2329
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
2330 2331
create_table_options:
	create_table_option
2332
	| create_table_option     create_table_options
2333
	| create_table_option ',' create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2334 2335

create_table_option:
2336
	ENGINE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; }
2337
	| TYPE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; WARN_DEPRECATED("TYPE=storage_engine","ENGINE=storage_engine"); }
2338 2339 2340
	| MAX_ROWS opt_equal ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS opt_equal ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH opt_equal ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2341 2342
	| PASSWORD opt_equal TEXT_STRING_sys	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM opt_equal TEXT_STRING_sys	{ Lex->create_info.comment=$3.str; }
2343 2344 2345 2346 2347 2348 2349 2350 2351 2352
	| 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 ')'
2353 2354 2355
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
2356 2357
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
2358
	    lex->create_info.merge_list.elements--;
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
2359 2360
	    lex->create_info.merge_list.first=
	      (byte*) (table_list->next_local);
2361
	    lex->select_lex.table_list.elements=1;
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
2362 2363 2364
	    lex->select_lex.table_list.next=
	      (byte**) &(table_list->next_local);
	    table_list->next_local= 0;
2365
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
2366
	  }
2367
	| opt_default charset opt_equal charset_name_or_default
2368
	  {
2369 2370 2371
	    Lex->create_info.default_table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
	  }
2372
	| opt_default COLLATE_SYM opt_equal collation_name_or_default
2373
	  {
2374
	    Lex->create_info.default_table_charset= $4;
2375 2376
	    Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
	  }
2377
	| INSERT_METHOD opt_equal merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2378 2379
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
	  { Lex->create_info.data_file_name= $4.str; }
2380
	| INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2381

2382
storage_engines:
2383 2384 2385 2386
	ident_or_text
	{
	  $$ = ha_resolve_by_name($1.str,$1.length);
	  if ($$ == DB_TYPE_UNKNOWN) {
2387
	    net_printf(YYTHD, ER_UNKNOWN_STORAGE_ENGINE, $1.str);
2388 2389 2390
	    YYABORT;
	  }
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2391 2392 2393 2394 2395

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
2396
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2397 2398 2399 2400

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

2403 2404 2405
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
2406
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
2407

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2408
opt_select_from:
2409
	opt_limit_clause {}
2410
	| select_from select_lock_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2411 2412

udf_func_type:
2413
	/* empty */	{ $$ = UDFTYPE_FUNCTION; }
2414
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2415 2416 2417 2418

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
2419
	| INT_SYM {$$ = (int) INT_RESULT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2420 2421 2422

field_list:
	  field_list_item
2423
	| field_list ',' field_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2424 2425 2426


field_list_item:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
2427
	   column_def
2428 2429 2430 2431
         | key_def
         ;

column_def:
2432
	  field_spec opt_check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2433 2434 2435 2436
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
2437
	;
2438 2439

key_def:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
2440
	key_type opt_ident key_alg '(' key_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2441
	  {
2442
	    LEX *lex=Lex;
2443
	    lex->key_list.push_back(new Key($1,$2, $3, 0, lex->col_list));
2444
	    lex->col_list.empty();		/* Alloced by sql_alloc */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2445
	  }
2446 2447 2448 2449
	| opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')'
	  {
	    LEX *lex=Lex;
	    const char *key_name= $3 ? $3:$1;
2450 2451
	    lex->key_list.push_back(new Key($2, key_name, $4, 0,
				    lex->col_list));
2452 2453
	    lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
2454
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2455
	  {
2456
	    LEX *lex=Lex;
2457
	    lex->key_list.push_back(new foreign_key($4 ? $4:$1, lex->col_list,
2458 2459 2460 2461 2462
				    $8,
				    lex->ref_list,
				    lex->fk_delete_opt,
				    lex->fk_update_opt,
				    lex->fk_match_option));
2463 2464 2465
	    lex->key_list.push_back(new Key(Key::MULTIPLE, $4 ? $4 : $1,
					    HA_KEY_ALG_UNDEF, 1,
					    lex->col_list));
2466
	    lex->col_list.empty();		/* Alloced by sql_alloc */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2467
	  }
2468 2469 2470 2471
	| constraint opt_check_constraint
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
2472
	| opt_constraint check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2473 2474
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
2475 2476 2477
	  }
	;

2478
opt_check_constraint:
2479
	/* empty */
2480 2481 2482 2483 2484
	| check_constraint
	;

check_constraint:
	CHECK_SYM expr
2485
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2486 2487

opt_constraint:
2488
	/* empty */		{ $$=(char*) 0; }
monty@mysql.com's avatar
monty@mysql.com committed
2489 2490 2491 2492 2493 2494
	| constraint		{ $$= $1; }
	;

constraint:
	CONSTRAINT opt_ident	{ $$=$2; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2495 2496 2497 2498

field_spec:
	field_ident
	 {
2499 2500
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
2501
	   lex->default_value= lex->on_update_value= 0;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2502
	   lex->comment=0;
2503
	   lex->charset=NULL;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2504 2505 2506
	 }
	type opt_attribute
	{
2507
	  LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2508
	  if (add_field_to_list(lex->thd, $1.str,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2509
				(enum enum_field_types) $3,
2510
				lex->length,lex->dec,lex->type,
2511 2512
				lex->default_value, lex->on_update_value, 
                                lex->comment,
2513 2514
				lex->change,lex->interval,lex->charset,
				lex->uint_geom_type))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2515
	    YYABORT;
2516
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2517 2518

type:
2519
	int_type opt_len field_options	{ $$=$1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2520 2521 2522 2523 2524 2525
	| 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; }
2526 2527
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
2528
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2529 2530 2531
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
2532
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2533
					  $$=FIELD_TYPE_STRING;
2534
					  Lex->charset=national_charset_info; }
2535
	| nchar				{ Lex->length=(char*) "1";
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2536
					  $$=FIELD_TYPE_STRING;
2537
					  Lex->charset=national_charset_info; }
2538
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
2539
					  Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2540 2541 2542
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
2543 2544
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
2545
					  Lex->charset=national_charset_info; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2546
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
2547
					  Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2548
					  $$=FIELD_TYPE_VAR_STRING; }
2549
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2550 2551
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
2552 2553
	| TIMESTAMP
	  {
2554
	    if (YYTHD->variables.sql_mode & MODE_MAXDB)
2555 2556
	      $$=FIELD_TYPE_DATETIME;
	    else
2557
	      $$=FIELD_TYPE_TIMESTAMP;
2558
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2559 2560 2561
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
2562
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2563
					  $$=FIELD_TYPE_TINY_BLOB; }
2564
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2565
					  $$=FIELD_TYPE_BLOB; }
hf@deer.(none)'s avatar
hf@deer.(none) committed
2566 2567 2568 2569 2570 2571 2572
	| spatial_type			{ 
#ifdef HAVE_SPATIAL
					  Lex->charset=&my_charset_bin;
					  Lex->uint_geom_type= (uint)$1;
					  $$=FIELD_TYPE_GEOMETRY;
#else
	                                  net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2573 2574
			                             sym_group_geom.name,
	                                             sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
2575 2576 2577
					  YYABORT;
#endif
					}
2578
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2579
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
2580
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2581
					  $$=FIELD_TYPE_LONG_BLOB; }
2582
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2583
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
2584 2585
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
2586
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
2587 2588
	| 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
2589 2590 2591 2592
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
2593 2594
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
2595
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2596
	  {
2597 2598
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2599 2600
	    $$=FIELD_TYPE_ENUM;
	  }
2601
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2602
	  {
2603 2604
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2605
	    $$=FIELD_TYPE_SET;
2606
	  }
2607
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
2608 2609 2610 2611 2612 2613
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
2614
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2615

hf@deer.(none)'s avatar
hf@deer.(none) committed
2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626
spatial_type:
	GEOMETRY_SYM	      { $$= Field::GEOM_GEOMETRY; }
	| GEOMETRYCOLLECTION  { $$= Field::GEOM_GEOMETRYCOLLECTION; }
	| POINT_SYM           { $$= Field::GEOM_POINT; }
	| MULTIPOINT          { $$= Field::GEOM_MULTIPOINT; }
	| LINESTRING          { $$= Field::GEOM_LINESTRING; }
	| MULTILINESTRING     { $$= Field::GEOM_MULTILINESTRING; }
	| POLYGON             { $$= Field::GEOM_POLYGON; }
	| MULTIPOLYGON        { $$= Field::GEOM_MULTIPOLYGON; }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2627 2628
char:
	CHAR_SYM {}
2629 2630 2631 2632 2633 2634
	;

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2636 2637 2638
varchar:
	char VARYING {}
	| VARCHAR {}
2639 2640 2641 2642
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2643
	| NVARCHAR_SYM {}
2644 2645 2646 2647
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2648 2649 2650 2651 2652 2653

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

real_type:
2657
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2658 2659
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
2660
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2661 2662 2663 2664 2665


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
2666
	| precision		{};
2667 2668 2669 2670 2671 2672

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

field_options:
	/* empty */		{}
2677
	| field_opt_list	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2678 2679 2680

field_opt_list:
	field_opt_list field_option {}
2681
	| field_option {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2682 2683

field_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2684
	SIGNED_SYM	{}
2685
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
2686
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2687 2688

opt_len:
2689 2690
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2691 2692 2693

opt_precision:
	/* empty */	{}
2694
	| precision	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2695 2696 2697

opt_attribute:
	/* empty */ {}
2698
	| opt_attribute_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2699 2700 2701

opt_attribute_list:
	opt_attribute_list attribute {}
2702
	| attribute;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2703 2704 2705 2706

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
2707 2708 2709
	| DEFAULT now_or_signed_literal { Lex->default_value=$2; }
	| ON UPDATE_SYM NOW_SYM optional_braces 
          { Lex->on_update_value= new Item_func_now_local(); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2710
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
2711
	| SERIAL_SYM DEFAULT VALUE_SYM
2712 2713 2714
	  { 
	    LEX *lex=Lex;
	    lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; 
2715
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
2716 2717 2718 2719 2720
	  }
	| opt_primary KEY_SYM 
	  {
	    LEX *lex=Lex;
	    lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; 
2721
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
2722 2723 2724 2725 2726
	  }
	| UNIQUE_SYM	  
	  {
	    LEX *lex=Lex;
	    lex->type|= UNIQUE_FLAG; 
2727
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
2728 2729 2730 2731 2732
	  }
	| UNIQUE_SYM KEY_SYM 
	  {
	    LEX *lex=Lex;
	    lex->type|= UNIQUE_KEY_FLAG; 
2733
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
2734
	  }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2735
	| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
2736
	| BINARY { Lex->type|= BINCMP_FLAG; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2737 2738
	| COLLATE_SYM collation_name
	  {
2739
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750
	    {
	      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
2751

2752 2753 2754 2755 2756
now_or_signed_literal:
        NOW_SYM optional_braces { $$= new Item_func_now_local(); }
        | signed_literal { $$=$1; }
        ;

2757 2758 2759 2760
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
2761

2762
charset_name:
2763
	ident_or_text
2764
	{
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2765
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
2766
	  {
2767
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
2768 2769
	    YYABORT;
	  }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2770 2771 2772
	}
	| BINARY { $$= &my_charset_bin; }
	;
2773

2774 2775 2776
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2777

2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795

old_or_new_charset_name:
	ident_or_text
	{
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) &&
	      !($$=get_old_charset_by_name($1.str)))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	}
	| BINARY { $$= &my_charset_bin; }
	;

old_or_new_charset_name_or_default:
	old_or_new_charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

2796
collation_name:
2797
	ident_or_text
2798 2799 2800
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
2801
	    net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str);
2802 2803 2804 2805
	    YYABORT;
	  }
	};

2806 2807
opt_collate:
	/* empty */	{ $$=NULL; }
2808
	| COLLATE_SYM collation_name_or_default { $$=$2; }
2809 2810
	;

2811 2812 2813 2814
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

2815 2816 2817 2818
opt_default:
	/* empty */	{}
	| DEFAULT	{};

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2819
opt_binary:
2820
	/* empty */			{ Lex->charset=NULL; }
2821 2822
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
2823 2824
	| UNICODE_SYM
	{
2825
	  if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
2826 2827 2828 2829 2830
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
2831
	| charset charset_name	{ Lex->charset=$2; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2832

2833 2834 2835
opt_primary:
	/* empty */
	| PRIMARY_SYM
2836
	;
2837

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2838
references:
2839 2840
	REFERENCES table_ident
	{
2841
	  LEX *lex=Lex;
2842 2843 2844 2845 2846 2847
	  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
2848
	};
2849

2850
opt_ref_list:
2851
	/* empty */ opt_on_delete {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2852
	| '(' ref_list ')' opt_on_delete {};
2853 2854 2855

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2858 2859 2860

opt_on_delete:
	/* empty */ {}
2861
	| opt_on_delete_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2862 2863 2864

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
2865
	| opt_on_delete_item {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2866 2867

opt_on_delete_item:
2868 2869 2870 2871
	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
2872
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2873 2874

delete_option:
2875 2876 2877 2878
	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
2879
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2880 2881

key_type:
2882
	key_or_index			    { $$= Key::MULTIPLE; }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2883 2884
	| FULLTEXT_SYM opt_key_or_index	    { $$= Key::FULLTEXT; }
	| SPATIAL_SYM opt_key_or_index
hf@deer.(none)'s avatar
hf@deer.(none) committed
2885 2886 2887 2888 2889
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2890
		       sym_group_geom.name, sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
2891 2892 2893
	    YYABORT;
#endif
	  };
2894 2895 2896

constraint_key_type:
	PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2897
	| UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2898 2899 2900

key_or_index:
	KEY_SYM {}
2901
	| INDEX_SYM {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2902

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2903
opt_key_or_index:
2904
	/* empty */ {}
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2905
	| key_or_index
2906 2907
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2908 2909
keys_or_index:
	KEYS {}
2910
	| INDEX_SYM {}
2911
	| INDEXES {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2912

2913
opt_unique_or_fulltext:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2914 2915
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
serg@serg.mylan's avatar
serg@serg.mylan committed
2916
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT;}
hf@deer.(none)'s avatar
hf@deer.(none) committed
2917 2918 2919 2920 2921 2922
	| SPATIAL_SYM
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2923
	               sym_group_geom.name, sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
2924 2925 2926
	    YYABORT;
#endif
	  }
serg@serg.mylan's avatar
serg@serg.mylan committed
2927
        ;
2928 2929

key_alg:
2930
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
2931
	| USING opt_btree_or_rtree { $$= $2; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2932
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
2933 2934 2935

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
hf@deer.(none)'s avatar
hf@deer.(none) committed
2936 2937 2938 2939
	| RTREE_SYM
	  {
	    $$= HA_KEY_ALG_RTREE;
	  }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2940
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2941 2942 2943

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
2944
	| key_part order_dir		{ Lex->col_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2945 2946 2947

key_part:
	ident			{ $$=new key_part_spec($1.str); }
2948
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2949 2950 2951

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

2954 2955 2956
opt_component:
	/* empty */	 { $$.str= 0; $$.length= 0; }
	| '.' ident	 { $$=$2; };
2957

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2958 2959
string_list:
	text_string			{ Lex->interval_list.push_back($1); }
2960
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2961 2962 2963 2964 2965 2966 2967 2968

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
2969
	  THD *thd= YYTHD;
2970
	  LEX *lex= thd->lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2971 2972
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2973 2974
	  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
2975 2976 2977 2978
	    YYABORT;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
2979
          lex->select_lex.init_order();
2980
	  lex->select_lex.db=lex->name=0;
2981
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2982
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
2983
	  lex->create_info.default_table_charset= NULL;
2984
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
2985
	  lex->alter_info.reset();          
2986 2987
	  lex->alter_info.is_simple= 1;
	  lex->alter_info.flags= 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2988
	}
2989 2990
	alter_list
	{}
2991
	| ALTER DATABASE ident opt_create_database_options
2992 2993 2994 2995
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
2996
	  }
2997
	| ALTER PROCEDURE sp_name
2998 2999 3000 3001
	  {
	    LEX *lex= Lex;

	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
3002
	    lex->name= 0;
3003 3004
          }
	  sp_a_chistics
3005
	  {
3006
	    THD *thd= YYTHD;
3007
	    LEX *lex=Lex;
3008

3009
	    lex->sql_command= SQLCOM_ALTER_PROCEDURE;
3010
	    lex->spname= $3;
3011
	  }
3012
	| ALTER FUNCTION_SYM sp_name
3013 3014 3015 3016 3017 3018 3019
	  {
	    LEX *lex= Lex;

	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
	    lex->name= 0;
          }
	  sp_a_chistics
3020
	  {
3021
	    THD *thd= YYTHD;
3022
	    LEX *lex=Lex;
3023

3024
	    lex->sql_command= SQLCOM_ALTER_FUNCTION;
3025
	    lex->spname= $3;
3026
	  }
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038
	| ALTER VIEW_SYM table_ident
	  {
	    THD *thd= YYTHD;
	    LEX *lex= thd->lex;
	    lex->sql_command= SQLCOM_CREATE_VIEW;
	    lex->create_view_mode= VIEW_ALTER;
	    lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
	    /* first table in list is target VIEW name */
	    lex->select_lex.add_table_to_list(thd, $3, NULL, 0);
	  }
	  opt_view_list AS select_init
	  {}
3039
	;
3040

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3041
alter_list:
3042 3043
	| DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
	| IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
3044
        | alter_list_item
3045
	| alter_list ',' alter_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3046 3047

add_column:
3048 3049 3050 3051
	ADD opt_column 
	{
	  LEX *lex=Lex;
	  lex->change=0; 
3052
	  lex->alter_info.flags|= ALTER_ADD_COLUMN; 
3053
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3054 3055

alter_list_item:
3056
	add_column column_def opt_place { Lex->alter_info.is_simple= 0; }
3057 3058 3059
	| ADD key_def 
	  { 
	    LEX *lex=Lex;
3060 3061
	    lex->alter_info.is_simple= 0; 
	    lex->alter_info.flags|= ALTER_ADD_INDEX; 
3062
	  }
3063
	| add_column '(' field_list ')'      { Lex->alter_info.is_simple= 0; }
3064 3065 3066
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
3067
	     lex->change= $3.str; 
3068 3069
	     lex->alter_info.is_simple= 0;
	     lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
3070
	  }
3071
          field_spec opt_place
3072 3073 3074 3075
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
            lex->length=lex->dec=0; lex->type=0; lex->interval=0;
3076
            lex->default_value= lex->on_update_value= 0;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3077
	    lex->comment=0;
3078
	    lex->charset= NULL;
3079 3080
            lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
3081 3082 3083 3084
          }
          type opt_attribute
          {
            LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3085
            if (add_field_to_list(lex->thd,$3.str,
3086 3087
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
3088 3089
                                  lex->default_value, lex->on_update_value,
                                  lex->comment,
3090 3091
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
3092 3093 3094
	       YYABORT;
          }
          opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3095
	| DROP opt_column field_ident opt_restrict
3096 3097
	  {
	    LEX *lex=Lex;
3098 3099 3100 3101
	    lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
	    			                               $3.str)); 
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_DROP_COLUMN;
3102
	  }
3103
	| DROP FOREIGN KEY_SYM opt_ident { Lex->alter_info.is_simple= 0; }
3104 3105 3106
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
3107 3108 3109 3110
	    lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
				               primary_key_name));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_DROP_INDEX;
3111
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3112
	| DROP key_or_index field_ident
3113 3114
	  {
	    LEX *lex=Lex;
3115 3116 3117 3118
	    lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
					                       $3.str));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_DROP_INDEX;
3119
	  }
3120 3121
	| DISABLE_SYM KEYS { Lex->alter_info.keys_onoff= DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_info.keys_onoff= ENABLE; }
3122
	| ALTER opt_column field_ident SET DEFAULT signed_literal
3123 3124
	  {
	    LEX *lex=Lex;
3125 3126 3127
	    lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
3128
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3129
	| ALTER opt_column field_ident DROP DEFAULT
3130 3131
	  {
	    LEX *lex=Lex;
3132 3133 3134 3135
	    lex->alter_info.alter_list.push_back(new Alter_column($3.str,
                                                                  (Item*) 0));
	    lex->alter_info.is_simple= 0;
	    lex->alter_info.flags|= ALTER_CHANGE_COLUMN;
3136
	  }
3137
	| RENAME opt_to table_ident
3138
	  {
3139
	    LEX *lex=Lex;
3140
	    lex->select_lex.db=$3->db.str;
3141
	    lex->name= $3->table.str;
3142
	    lex->alter_info.flags|= ALTER_RENAME;
3143
	  }
3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157
	| CONVERT_SYM TO_SYM charset charset_name_or_default opt_collate
	  {
	    if (!$4)
	    {
	      THD *thd= YYTHD;
	      $4= thd->variables.collation_database;
	    }
	    $5= $5 ? $5 : $4;
	    if (!my_charset_same($4,$5))
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $5->name,$4->csname);
	      YYABORT;
	    }
3158
	    LEX *lex= Lex;
monty@mysql.com's avatar
monty@mysql.com committed
3159 3160 3161 3162
	    lex->create_info.table_charset= 
	      lex->create_info.default_table_charset= $5;
	    lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET |
					    HA_CREATE_USED_DEFAULT_CHARSET);
3163
	    lex->alter_info.is_simple= 0;
3164
	  }
3165 3166 3167
        | create_table_options_space_separated 
	  {
	    LEX *lex=Lex;
3168 3169
	    lex->alter_info.is_simple= 0; 
	    lex->alter_info.flags|= ALTER_OPTIONS;
3170 3171 3172 3173
	  }
	| order_clause         
	  {
	    LEX *lex=Lex;
3174 3175
	    lex->alter_info.is_simple= 0; 
	    lex->alter_info.flags|= ALTER_ORDER;
3176
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3177 3178 3179

opt_column:
	/* empty */	{}
3180
	| COLUMN_SYM	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3181 3182 3183

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
3184
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3185 3186

opt_restrict:
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
3187 3188 3189 3190
	/* empty */	{ Lex->drop_mode= DROP_DEFAULT; }
	| RESTRICT	{ Lex->drop_mode= DROP_RESTRICT; }
	| CASCADE	{ Lex->drop_mode= DROP_CASCADE; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3191 3192 3193 3194

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
3195
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3196 3197 3198 3199

opt_to:
	/* empty */	{}
	| TO_SYM	{}
3200
	| EQ		{}
3201
	| AS		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3202

nick@mysql.com's avatar
nick@mysql.com committed
3203
/*
3204
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3205 3206
*/

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3207
slave:
3208 3209 3210 3211 3212 3213 3214
	  START_SYM SLAVE slave_thread_opts 
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_START;
	    lex->type = 0;
	    /* We'll use mi structure for UNTIL options */
	    bzero((char*) &lex->mi, sizeof(lex->mi));
guilhem@gbichot2.local's avatar
guilhem@gbichot2.local committed
3215
            /* If you change this code don't forget to update SLAVE START too */
3216 3217 3218
          }
          slave_until
          {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3219 3220 3221 3222 3223
        | STOP_SYM SLAVE slave_thread_opts
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_STOP;
	    lex->type = 0;
guilhem@gbichot2.local's avatar
guilhem@gbichot2.local committed
3224
            /* If you change this code don't forget to update SLAVE STOP too */
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3225
          }
3226 3227 3228 3229 3230
	| SLAVE START_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
3231 3232 3233 3234 3235
	    /* We'll use mi structure for UNTIL options */
	    bzero((char*) &lex->mi, sizeof(lex->mi));
          }
          slave_until
          {}
3236 3237 3238 3239 3240 3241 3242 3243
	| SLAVE STOP_SYM 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
3244

3245 3246 3247 3248 3249
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

3250
slave_thread_opts:
3251 3252
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
3253
        {}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3254
	;
3255 3256

slave_thread_opt_list:
3257
	slave_thread_opt
3258 3259
	| slave_thread_opt_list ',' slave_thread_opt
	;
3260 3261

slave_thread_opt:
3262
	/*empty*/	{}
3263
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
3264
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
3265
	;
3266

3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288
slave_until:
	/*empty*/	{}
	| UNTIL_SYM slave_until_opts
          {
            LEX *lex=Lex;
            if ((lex->mi.log_file_name || lex->mi.pos) &&
                (lex->mi.relay_log_name || lex->mi.relay_log_pos) ||
                !((lex->mi.log_file_name && lex->mi.pos) ||
                  (lex->mi.relay_log_name && lex->mi.relay_log_pos)))
            {
               send_error(lex->thd, ER_BAD_SLAVE_UNTIL_COND);
               YYABORT;
            }

          }
	;

slave_until_opts:
       master_file_def
       | slave_until_opts ',' master_file_def ;


3289 3290 3291 3292 3293
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3294
	table_list FROM TEXT_STRING_sys
3295 3296
        {
	  Lex->backup_dir = $6.str;
3297
        };
3298

3299 3300 3301 3302 3303
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3304
	table_list TO_SYM TEXT_STRING_sys
3305 3306
        {
	  Lex->backup_dir = $6.str;
3307
        };
3308

3309 3310 3311 3312 3313 3314
checksum:
        CHECKSUM_SYM table_or_tables
	{
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECKSUM;
	}
3315 3316
	table_list opt_checksum_type
        {}
3317 3318
	;

3319 3320 3321 3322 3323 3324
opt_checksum_type:
        /* nothing */  { Lex->check_opt.flags= 0; }
	| QUICK        { Lex->check_opt.flags= T_QUICK; }
	| EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; }
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3325
repair:
3326
	REPAIR opt_no_write_to_binlog table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3327
	{
3328 3329
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
3330
           lex->no_write_to_binlog= $2;
3331
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3332
	}
3333 3334 3335
	table_list opt_mi_repair_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3336

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3337
opt_mi_repair_type:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3338
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
3339
	| mi_repair_types {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3340

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3341 3342
mi_repair_types:
	mi_repair_type {}
3343
	| mi_repair_type mi_repair_types {};
3344

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3345
mi_repair_type:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3346
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
3347
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
3348
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3349 3350

analyze:
3351
	ANALYZE_SYM opt_no_write_to_binlog table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3352
	{
3353 3354
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
3355
           lex->no_write_to_binlog= $2;
3356
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3357
	}
3358 3359 3360
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3361 3362

check:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3363
	CHECK_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3364
	{
3365 3366 3367
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3368
	}
3369 3370 3371
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3372

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3373 3374
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
3375
	| mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3376 3377 3378

mi_check_types:
	mi_check_type {}
3379
	| mi_check_type mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3380 3381 3382 3383 3384 3385

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3388
optimize:
3389
	OPTIMIZE opt_no_write_to_binlog table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3390
	{
3391 3392
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3393
           lex->no_write_to_binlog= $2;
3394
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3395
	}
3396 3397 3398
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3399

3400 3401 3402
opt_no_write_to_binlog:
	/* empty */        { $$= 0; }
	| NO_WRITE_TO_BINLOG  { $$= 1; }
3403
	| LOCAL_SYM  { $$= 1; }
3404 3405
	;

3406 3407 3408 3409 3410
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
3411 3412 3413
	table_to_table_list
	{}
	;
3414 3415 3416

table_to_table_list:
	table_to_table
3417
	| table_to_table_list ',' table_to_table;
3418 3419 3420

table_to_table:
	table_ident TO_SYM table_ident
3421
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3422
	  LEX *lex=Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3423
	  SELECT_LEX *sl= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3424 3425 3426 3427
	  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))
3428
	    YYABORT;
3429
	};
3430

igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3431
keycache:
3432
        CACHE_SYM INDEX_SYM keycache_list IN_SYM key_cache_name
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3433 3434
        {
          LEX *lex=Lex;
3435 3436
          lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
	  lex->name_and_length= $5;
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3437 3438 3439 3440 3441 3442 3443 3444
        }
        ;

keycache_list:
        assign_to_keycache
        | keycache_list ',' assign_to_keycache;

assign_to_keycache:
3445
        table_ident cache_keys_spec
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3446 3447 3448 3449 3450 3451
        {
          LEX *lex=Lex;
          SELECT_LEX *sel= &lex->select_lex;
          if (!sel->add_table_to_list(lex->thd, $1, NULL, 0,
                                      TL_READ,
                                      sel->get_use_index(),
3452
                                      (List<String> *)0))
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3453 3454 3455 3456
            YYABORT;
        }
        ;

3457 3458 3459
key_cache_name:
	ident	   { $$= $1; }
	| DEFAULT  { $$ = default_key_cache_base; }
3460
	;
3461

igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3462
preload:
3463
	LOAD INDEX_SYM INTO CACHE_SYM
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476
	{
	  LEX *lex=Lex;
	  lex->sql_command=SQLCOM_PRELOAD_KEYS;
	}
	preload_list
	{}
	;

preload_list:
	preload_keys
	| preload_list ',' preload_keys;

preload_keys:
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3477
	table_ident cache_keys_spec opt_ignore_leaves
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3478 3479 3480
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3481 3482
	  if (!sel->add_table_to_list(lex->thd, $1, NULL, $3,
                                      TL_READ,
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3483 3484 3485 3486 3487 3488
                                      sel->get_use_index(),
                                      (List<String> *)0))
            YYABORT;
	}
	;

3489
cache_keys_spec:
3490
        { Select->interval_list.empty(); }
3491 3492 3493 3494 3495 3496 3497
        cache_key_list_or_empty
        {
          LEX *lex=Lex;
          SELECT_LEX *sel= &lex->select_lex;
          sel->use_index= sel->interval_list;
        }
        ;
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3498

igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3499
cache_key_list_or_empty:
3500
	/* empty */	{ Lex->select_lex.use_index_ptr= 0; }
3501
	| opt_key_or_index '(' key_usage_list2 ')'
3502 3503 3504 3505
	  {
            SELECT_LEX *sel= &Lex->select_lex;
	    sel->use_index_ptr= &sel->use_index;
	  }
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3506 3507
	;

3508
opt_ignore_leaves:
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3509 3510 3511 3512 3513
	/* empty */
	{ $$= 0; }
	| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3514
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3515
  Select : retrieve data from table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3516 3517 3518 3519
*/


select:
3520 3521 3522 3523 3524
	select_init
	{
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_SELECT;
	  lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3525 3526
	}
	;
3527

3528
/* Need select_init2 for subselects. */
3529
select_init:
3530
	SELECT_SYM select_init2
3531
	|
3532 3533
	'(' SELECT_SYM select_part2 ')'
	  {
3534
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3535
            SELECT_LEX * sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3536
	    if (sel->set_braces(1))
3537
	    {
3538
	      yyerror(ER(ER_SYNTAX_ERROR));
3539 3540
	      YYABORT;
	    }
3541 3542
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3543
	  {
3544
	    yyerror(ER(ER_SYNTAX_ERROR));
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3545 3546
	    YYABORT;
	  }
3547
            /* select in braces, can't contain global parameters */
3548 3549 3550
	    if (sel->master_unit()->fake_select_lex)
              sel->master_unit()->global_parameters=
                 sel->master_unit()->fake_select_lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3551
          } union_opt;
3552

3553 3554
select_init2:
	select_part2
3555
        {
3556
	  LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3557
          SELECT_LEX * sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3558
          if (lex->current_select->set_braces(0))
3559
	  {
3560
	    yyerror(ER(ER_SYNTAX_ERROR));
3561 3562
	    YYABORT;
	  }
3563 3564
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3565
	  {
3566
	    yyerror(ER(ER_SYNTAX_ERROR));
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3567 3568
	    YYABORT;
	  }
3569
	}
3570
	union_clause
3571 3572
	;

3573
select_part2:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3574
	{
3575 3576 3577
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
	  lex->lock_option= TL_READ;
3578 3579
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
3580 3581 3582 3583 3584
	  lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
	}
	select_options select_item_list
	{
	  Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3585
	}
3586
	select_into select_lock_type;
3587

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3588
select_into:
3589 3590
	opt_limit_clause {}
        | into
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3591
	| select_from
3592 3593
	| into select_from
	| select_from into;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3594 3595

select_from:
3596 3597 3598 3599 3600 3601 3602
	  FROM join_table_list where_clause group_clause having_clause
	       opt_order_clause opt_limit_clause procedure_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 :) */
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3603 3604 3605

select_options:
	/* empty*/
3606
	| select_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3607 3608 3609

select_option_list:
	select_option_list select_option
3610
	| select_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3611 3612

select_option:
3613
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
3614 3615 3616 3617 3618 3619
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
3620 3621 3622
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634
	| 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;
	  }
3635
	| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
3636 3637 3638 3639
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
3640 3641
	| ALL		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3642

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3643 3644 3645
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
3646 3647
	  {
	    LEX *lex=Lex;
3648
	    lex->current_select->set_lock_for_tables(TL_WRITE);
3649
	    lex->safe_to_cache_query=0;
3650
	  }
3651
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
3652 3653
	  {
	    LEX *lex=Lex;
3654 3655
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
3656
	    lex->safe_to_cache_query=0;
3657 3658
	  }
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3659

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3660 3661 3662 3663 3664
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
3665 3666
	    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
3667
	      YYABORT;
pem@mysql.com's avatar
pem@mysql.com committed
3668
	    (thd->lex->current_select->with_wild)++;
3669
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3670 3671 3672 3673 3674


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3675
	    if (add_item_to_list(YYTHD, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3676 3677
	      YYABORT;
	    if ($4.str)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3678
	      $2->set_name($4.str,$4.length,system_charset_info);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3679
	    else if (!$2->name)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3680
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
3681
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3682 3683

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

remember_end:
3687
	{ $$=(char*) Lex->tok_end; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3688 3689 3690

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

select_alias:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3694 3695 3696 3697 3698 3699
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3700 3701 3702

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3705
/* all possible expressions */
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3706 3707 3708 3709
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3710

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722
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
3723 3724
/* expressions that begin with 'expr' */
expr_expr:
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3725
	 expr IN_SYM '(' expr_list ')'
3726
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3727
	| expr NOT IN_SYM '(' expr_list ')'
3728
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3729
        | expr IN_SYM in_subselect
3730
          { $$= new Item_in_subselect($1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3731
	| expr NOT IN_SYM in_subselect
3732
          {
3733
            $$= new Item_func_not(new Item_in_subselect($1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3734
          }
3735
	| expr BETWEEN_SYM no_and_expr AND_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3736
	  { $$= new Item_func_between($1,$3,$5); }
3737
	| expr NOT BETWEEN_SYM no_and_expr AND_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3738
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
3739
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
3740
	| expr OR_SYM expr	{ $$= new Item_cond_or($1,$3); }
3741
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
3742
	| expr AND_SYM expr	{ $$= new Item_cond_and($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3743 3744 3745 3746 3747 3748 3749 3750 3751
	| expr SOUNDS_SYM LIKE expr
	  {
	    $$= new Item_func_eq(new Item_func_soundex($1),
				 new Item_func_soundex($4));
	  }
	| 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));}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3752
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3753 3754
	| expr NOT REGEXP expr
          { $$= new Item_func_not(new Item_func_regex($1,$4)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3755 3756 3757
	| 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
3758
	| expr comp_op expr %prec EQ	{ $$= (*$2)(0)->create($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3759 3760
	| expr comp_op all_or_any in_subselect %prec EQ
	{
3761
	  $$= all_any_subquery_creator($1, $2, $3, $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3762
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3763 3764 3765 3766 3767 3768
	| 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); }
3769 3770
	| 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
3771
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
3772
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3773 3774
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
3775 3776 3777 3778
	| expr '+' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,0); }
	| expr '-' interval_expr interval
	  { $$= new Item_date_add_interval($1,$3,$4,1); }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3779
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3780 3781 3782

/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
3783
	no_in_expr BETWEEN_SYM no_and_expr AND_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3784
	  { $$= new Item_func_between($1,$3,$5); }
3785
	| no_in_expr NOT BETWEEN_SYM no_and_expr AND_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3786
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
3787
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
3788
	| no_in_expr OR_SYM expr	{ $$= new Item_cond_or($1,$3); }
3789
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
3790
	| no_in_expr AND_SYM expr	{ $$= new Item_cond_and($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3791 3792 3793 3794 3795 3796 3797 3798 3799
	| no_in_expr SOUNDS_SYM LIKE expr
	  {
	    $$= new Item_func_eq(new Item_func_soundex($1),
				 new Item_func_soundex($4));
	  }
	| 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)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3800
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3801 3802
	| no_in_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3803 3804 3805
	| 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
3806
	| no_in_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3807 3808
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
3809
	  all_any_subquery_creator($1, $2, $3, $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3810
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3811 3812 3813 3814 3815 3816
	| 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); }
3817
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3818
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
3819
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3820 3821
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
3822
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
3823 3824 3825 3826
	| 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); }
3827
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3828 3829 3830

/* 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
3831
	  no_and_expr IN_SYM '(' expr_list ')'
3832
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3833
	| no_and_expr NOT IN_SYM '(' expr_list ')'
3834
	  { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3835
        | no_and_expr IN_SYM in_subselect
3836
          { $$= new Item_in_subselect($1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3837
	| no_and_expr NOT IN_SYM in_subselect
3838
          {
3839
            $$= new Item_func_not(new Item_in_subselect($1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3840
          }
3841
	| no_and_expr BETWEEN_SYM no_and_expr AND_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3842
	  { $$= new Item_func_between($1,$3,$5); }
3843
	| no_and_expr NOT BETWEEN_SYM no_and_expr AND_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3844
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
3845
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
3846
	| no_and_expr OR_SYM expr	{ $$= new Item_cond_or($1,$3); }
3847
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3848 3849 3850 3851 3852 3853 3854 3855 3856
	| no_and_expr SOUNDS_SYM LIKE expr
	  {
	    $$= new Item_func_eq(new Item_func_soundex($1),
				 new Item_func_soundex($4));
	  }
	| 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)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3857
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3858 3859
	| no_and_expr NOT REGEXP expr
	  { $$= new Item_func_not(new Item_func_regex($1,$4)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3860 3861 3862
	| 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
3863
	| no_and_expr comp_op expr %prec EQ { $$= (*$2)(0)->create($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3864 3865
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
3866
	  all_any_subquery_creator($1, $2, $3, $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3867
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3868 3869 3870 3871 3872 3873
	| 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); }
3874
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3875
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
3876
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3877 3878
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
3879
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
3880 3881 3882 3883
	| 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); }
3884
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3885

3886
interval_expr:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3887
         INTERVAL_SYM expr { $$=$2; }
3888 3889
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3890 3891
simple_expr:
	simple_ident
3892
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3893
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3894 3895 3896
	    $$= new Item_func_set_collation($1,
					    new Item_string($3.str,
							    $3.length,
3897
                                                            YYTHD->charset()));
3898
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3899
	| literal
3900
	| param_marker
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3901
	| '@' ident_or_text SET_VAR expr
3902 3903
	  {
	    $$= new Item_func_set_user_var($2,$4);
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
3904 3905 3906
	    LEX *lex= Lex;
	    lex->uncacheable(UNCACHEABLE_RAND);
	    lex->variables_used= 1;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3907
	  }
3908
	| '@' ident_or_text
3909 3910
	  {
	    $$= new Item_func_get_user_var($2);
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
3911 3912 3913
	    LEX *lex= Lex;
	    lex->uncacheable(UNCACHEABLE_RAND);
	    lex->variables_used= 1;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3914
	  }
3915
	| '@' '@' opt_var_ident_type ident_or_text opt_component
3916
	  {
3917 3918 3919 3920 3921 3922

            if ($4.str && $5.str && check_reserved_words(&$4))
            {
              yyerror(ER(ER_SYNTAX_ERROR));
              YYABORT;
            }
3923
	    if (!($$= get_system_var(YYTHD, (enum_var_type) $3, $4, $5)))
3924
	      YYABORT;
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
3925
	    Lex->variables_used= 1;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3926
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3927
	| sum_expr
3928 3929
	| '+' expr %prec NEG	{ $$= $2; }
	| '-' expr %prec NEG    { $$= new Item_func_neg($2); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3930 3931 3932 3933
	| '~' 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; }
3934 3935 3936 3937 3938
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
3939
	| ROW_SYM '(' expr ',' expr_list ')'
3940
	  {
3941 3942
	    $5->push_front($3);
	    $$= new Item_row(*$5);
3943
	  }
3944
	| EXISTS exists_subselect { $$= $2; }
3945
	| singlerow_subselect   { $$= $1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3946
	| '{' ident expr '}'	{ $$= $3; }
3947
        | MATCH ident_list_arg AGAINST '(' expr fulltext_options ')'
3948
          { $2->push_front($5);
3949 3950
            Select->add_ftfunc_to_list((Item_func_match*)
                                        ($$=new Item_func_match(*$2,$6))); }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3951
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3952
	| BINARY expr %prec NEG
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3953
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3954 3955
	    $$= new Item_func_set_collation($2,new Item_string(binary_keyword,
					    6, &my_charset_latin1));
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3956
	  }
3957
	| CAST_SYM '(' expr AS cast_type ')'
3958 3959
	  {
	    $$= create_func_cast($3, $5,
3960
				 Lex->length ? atoi(Lex->length) : -1,
3961
				 Lex->charset);
3962
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3963
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
3964
	  { $$= new Item_func_case(* $4, $2, $5 ); }
3965
	| CONVERT_SYM '(' expr ',' cast_type ')'
3966 3967 3968 3969 3970
	  {
	    $$= create_func_cast($3, $5,
				 Lex->length ? atoi(Lex->length) : -1,
				 Lex->charset);
	  }
3971 3972
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3973 3974
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
3975 3976
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3977
	| FUNC_ARG0 '(' ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
3978 3979 3980 3981
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3982
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
3983 3984 3985 3986 3987
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(void))($1.symbol->create_func))();
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3988
	| FUNC_ARG1 '(' expr ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
3989 3990 3991 3992
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3993
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
3994 3995 3996 3997 3998
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3999
	| FUNC_ARG2 '(' expr ',' expr ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
4000 4001 4002 4003
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
4004
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
4005 4006 4007 4008 4009
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4010
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
4011 4012 4013 4014
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
4015
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
4016 4017 4018 4019 4020
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
	  }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4021 4022 4023 4024
	| ADDDATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);}
	| ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3, $6, $7, 0); }
4025 4026
	| REPEAT_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_repeat($3,$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4027 4028 4029 4030 4031 4032
	| 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); }
4033 4034
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4035 4036
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
4037 4038
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4039 4040 4041 4042 4043
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
4044
	  { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4045
	| CURTIME optional_braces
4046
	  { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4047
	| CURTIME '(' expr ')'
4048
	  {
4049
	    $$= new Item_func_curtime_local($3);
4050
	    Lex->safe_to_cache_query=0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4051
	  }
4052
	| CURRENT_USER optional_braces
4053
          { $$= create_func_current_user(); }
4054 4055 4056 4057
	| 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
4058
	| DATABASE '(' ')'
4059
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4060
	    $$= new Item_func_database();
4061
            Lex->safe_to_cache_query=0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4062
	  }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4063
	| DATE_SYM '(' expr ')'
4064
	  { $$= new Item_date_typecast($3); }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4065 4066
	| DAY_SYM '(' expr ')'
	  { $$= new Item_func_dayofmonth($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4067
	| ELT_FUNC '(' expr ',' expr_list ')'
4068
	  { $5->push_front($3); $$= new Item_func_elt(*$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4069 4070
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4071 4072 4073
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
4074
	    Lex->uncacheable(UNCACHEABLE_RAND);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4075
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4076
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
4077
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4078
	  { $$= new Item_func_decode($3,$5.str); }
4079
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4080
	 { $$= new Item_func_encode($3,$5.str); }
4081
	| DES_DECRYPT_SYM '(' expr ')'
4082
        { $$= new Item_func_des_decrypt($3); }
4083
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
4084
        { $$= new Item_func_des_decrypt($3,$5); }
4085
	| DES_ENCRYPT_SYM '(' expr ')'
4086
        { $$= new Item_func_des_encrypt($3); }
4087
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
4088
        { $$= new Item_func_des_encrypt($3,$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4089 4090 4091 4092 4093 4094
	| 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); }
4095 4096
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4097 4098 4099 4100 4101 4102
	| 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
4103
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4104 4105
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
4106
	  { $5->push_front($3); $$= new Item_func_field(*$5); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4107 4108 4109 4110 4111 4112
	| geometry_function
	  {
#ifdef HAVE_SPATIAL
	    $$= $1;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
4113
	               sym_group_geom.name, sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
4114 4115 4116
	    YYABORT;
#endif
	  }
4117
	| GET_FORMAT '(' date_time_type  ',' expr ')'
4118
	  { $$= new Item_func_get_format($3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4119 4120 4121 4122 4123 4124
	| 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); }
4125
	| interval_expr interval '+' expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4126
	  /* we cannot put interval before - */
4127 4128 4129 4130 4131
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
4132
              yyerror(ER(ER_SYNTAX_ERROR));
4133 4134 4135 4136
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4137 4138
	| LAST_INSERT_ID '(' ')'
	  {
4139
	    $$= new Item_func_last_insert_id();
4140
	    Lex->safe_to_cache_query= 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4141 4142 4143
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
4144
	    $$= new Item_func_last_insert_id($3);
4145
	    Lex->safe_to_cache_query= 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4146 4147 4148 4149 4150 4151 4152
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
	| LOCATE '(' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3); }
	| LOCATE '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3,$7); }
4153
	| GREATEST_SYM '(' expr ',' expr_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4154 4155 4156
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
4157
	| LOG_SYM '(' expr ')'
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4158
	  { $$= new Item_func_log($3); }
4159
	| LOG_SYM '(' expr ',' expr ')'
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
4160
	  { $$= new Item_func_log($3, $5); }
4161
	| MASTER_POS_WAIT '(' expr ',' expr ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4162
	  {
4163
	    $$= new Item_master_pos_wait($3, $5);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4164
	    Lex->safe_to_cache_query=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4165
		  }
4166
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4167
	  {
4168
	    $$= new Item_master_pos_wait($3, $5, $7);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4169
	    Lex->safe_to_cache_query=0;
4170
	  }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4171 4172
	| MICROSECOND_SYM '(' expr ')'
	  { $$= new Item_func_microsecond($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4173 4174
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
4175 4176
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4177 4178 4179
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
	| NOW_SYM optional_braces
4180
	  { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4181
	| NOW_SYM '(' expr ')'
4182
	  { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4183
	| PASSWORD '(' expr ')'
4184
	  {
4185 4186
	    $$= YYTHD->variables.old_passwords ?
              (Item *) new Item_func_old_password($3) :
4187 4188 4189 4190
	      (Item *) new Item_func_password($3);
	  }
	| OLD_PASSWORD '(' expr ')'
	  { $$=  new Item_func_old_password($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4191 4192
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
4193 4194
	| QUARTER_SYM '(' expr ')'
	  { $$ = new Item_func_quarter($3); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4195
	| RAND '(' expr ')'
4196
	  { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4197
	| RAND '(' ')'
4198
	  { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4199 4200 4201 4202 4203 4204 4205
	| 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); }
4206 4207 4208 4209 4210
	| ROW_COUNT_SYM '(' ')'
	  {
	    $$= new Item_func_row_count();
	    Lex->safe_to_cache_query= 0;
	  }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4211 4212 4213 4214
	| SUBDATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);}
	| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3, $6, $7, 1); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226
	| 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); }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4227
	| TIME_SYM '(' expr ')'
4228 4229 4230
	  { $$= new Item_time_typecast($3); }
	| TIMESTAMP '(' expr ')'
	  { $$= new Item_datetime_typecast($3); }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4231
	| TIMESTAMP '(' expr ',' expr ')'
4232
	  { $$= new Item_func_add_time($3, $5, 1, 0); }
4233 4234 4235 4236
	| TIMESTAMP_ADD '(' interval_time_st ',' expr ',' expr ')'
	  { $$= new Item_date_add_interval($7,$5,$3,0); }
	| TIMESTAMP_DIFF '(' interval_time_st ',' expr ',' expr ')'
	  { $$= new Item_func_timestamp_diff($5,$7,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4237
	| TRIM '(' expr ')'
4238 4239
	  { $$= new Item_func_trim($3); }
	| TRIM '(' LEADING expr FROM expr ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4240
	  { $$= new Item_func_ltrim($6,$4); }
4241
	| TRIM '(' TRAILING expr FROM expr ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4242
	  { $$= new Item_func_rtrim($6,$4); }
4243
	| TRIM '(' BOTH expr FROM expr ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4244
	  { $$= new Item_func_trim($6,$4); }
4245 4246 4247 4248 4249 4250
	| TRIM '(' LEADING FROM expr ')'
	 { $$= new Item_func_ltrim($5); }
	| TRIM '(' TRAILING FROM expr ')'
	  { $$= new Item_func_rtrim($5); }
	| TRIM '(' BOTH FROM expr ')'
	  { $$= new Item_func_trim($5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4251 4252
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
4253 4254
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
4255 4256
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
4257
	| ident '.' ident '(' udf_expr_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4258
	  {
4259 4260
	    LEX *lex= Lex;
	    sp_name *name= new sp_name($1, $3);
4261

4262 4263 4264 4265
	    name->init_qname(YYTHD);
	    sp_add_fun_to_lex(Lex, name);
	    if ($5)
	      $$= new Item_func_sp(name, *$5);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4266
	    else
4267 4268 4269 4270
	      $$= new Item_func_sp(name);
	  }
	| IDENT_sys '(' udf_expr_list ')'
          {
4271
#ifdef HAVE_DLOPEN
4272
            udf_func *udf;
4273

4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329
            if (using_udf_functions && (udf=find_udf($1.str, $1.length)))
            {
              switch (udf->returns) {
              case STRING_RESULT:
                if (udf->type == UDFTYPE_FUNCTION)
                {
                  if ($3 != NULL)
                    $$ = new Item_func_udf_str(udf, *$3);
                  else
                    $$ = new Item_func_udf_str(udf);
                }
                else
                {
                  if ($3 != NULL)
                    $$ = new Item_sum_udf_str(udf, *$3);
                  else
                    $$ = new Item_sum_udf_str(udf);
                }
                break;
              case REAL_RESULT:
                if (udf->type == UDFTYPE_FUNCTION)
                {
                  if ($3 != NULL)
                    $$ = new Item_func_udf_float(udf, *$3);
                  else
                    $$ = new Item_func_udf_float(udf);
                }
                else
                {
                  if ($3 != NULL)
                    $$ = new Item_sum_udf_float(udf, *$3);
                  else
                    $$ = new Item_sum_udf_float(udf);
                }
                break;
              case INT_RESULT:
                if (udf->type == UDFTYPE_FUNCTION)
                {
                  if ($3 != NULL)
                    $$ = new Item_func_udf_int(udf, *$3);
                  else
                    $$ = new Item_func_udf_int(udf);
                }
                else
                {
                  if ($3 != NULL)
                    $$ = new Item_sum_udf_int(udf, *$3);
                  else
                    $$ = new Item_sum_udf_int(udf);
                }
                break;
              default:
                YYABORT;
              }
            }
            else
4330
#endif /* HAVE_DLOPEN */
4331 4332 4333 4334 4335 4336 4337 4338
            {
              sp_name *name= sp_name_current_db_new(YYTHD, $1);

              sp_add_fun_to_lex(Lex, name);
              if ($3)
                $$= new Item_func_sp(name, *$3);
              else
                $$= new Item_func_sp(name);
4339
	    }
4340
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4341
	| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
4342
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4343 4344
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4345
	| UNIX_TIMESTAMP '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4346 4347
	  {
	    $$= new Item_func_unix_timestamp();
4348
	    Lex->safe_to_cache_query=0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4349
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4350 4351 4352
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
4353
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
4354 4355 4356 4357 4358 4359
	| UTC_DATE_SYM optional_braces
	  { $$= new Item_func_curdate_utc(); Lex->safe_to_cache_query=0;}
	| UTC_TIME_SYM optional_braces
	  { $$= new Item_func_curtime_utc(); Lex->safe_to_cache_query=0;}
	| UTC_TIMESTAMP_SYM optional_braces
	  { $$= new Item_func_now_utc(); Lex->safe_to_cache_query=0;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4360
	| WEEK_SYM '(' expr ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4361
	  {
4362
            $$= new Item_func_week($3,new Item_int((char*) "0",
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4363
				   YYTHD->variables.default_week_format,1));
4364
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4365 4366 4367 4368 4369 4370 4371 4372 4373
	| 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 ')'
4374
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4375
	    $$=new Item_func_benchmark($3,$5);
4376
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4377
	  }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4378
	| EXTRACT_SYM '(' interval FROM expr ')'
4379
	{ $$=new Item_extract( $3, $5); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4380

hf@deer.(none)'s avatar
hf@deer.(none) committed
4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391
geometry_function:
	GEOMFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| GEOMFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| GEOMFROMWKB '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_wkb($3)); }
	| GEOMFROMWKB '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_wkb($3, $5)); }
	| GEOMETRYCOLLECTION '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4392 4393
                           Geometry::wkb_geometrycollection,
                           Geometry::wkb_point)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4394 4395
	| LINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4396
                  Geometry::wkb_linestring, Geometry::wkb_point)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4397 4398
 	| MULTILINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW( Item_func_spatial_collection(* $3,
4399
                   Geometry::wkb_multilinestring, Geometry::wkb_linestring)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413
 	| MLINEFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| MLINEFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| MPOINTFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| MPOINTFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| MPOLYFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| MPOLYFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| MULTIPOINT '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4414
                  Geometry::wkb_multipoint, Geometry::wkb_point)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4415 4416
 	| MULTIPOLYGON '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4417
                  Geometry::wkb_multipolygon, Geometry::wkb_polygon)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429
	| POINT_SYM '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_point($3,$5)); }
 	| POINTFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| POINTFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| POLYFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| POLYFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	| POLYGON '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4430
	          Geometry::wkb_polygon, Geometry::wkb_linestring)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4431 4432 4433 4434 4435 4436 4437 4438 4439 4440
 	| GEOMCOLLFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
 	| LINEFROMTEXT '(' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3)); }
	| LINEFROMTEXT '(' expr ',' expr ')'
	  { $$= GEOM_NEW(Item_func_geometry_from_text($3, $5)); }
	;

4441 4442 4443 4444 4445 4446
fulltext_options:
        /* nothing */                   { $$= FT_NL;  }
        | WITH QUERY_SYM EXPANSION_SYM  { $$= FT_NL | FT_EXPAND; }
        | IN_SYM BOOLEAN_SYM MODE_SYM   { $$= FT_BOOL; }
        ;

4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479
udf_expr_list:
	/* empty */	 { $$= NULL; }
	| udf_expr_list2 { $$= $1;}
	;

udf_expr_list2:
	{ Select->expr_list.push_front(new List<Item>); }
	udf_expr_list3
	{ $$= Select->expr_list.pop(); }
	;

udf_expr_list3:
	udf_expr 
	  {
	    Select->expr_list.head()->push_back($1);
	  }
	| udf_expr_list3 ',' udf_expr 
	  {
	    Select->expr_list.head()->push_back($3);
	  }
	;

udf_expr:
	remember_name expr remember_end select_alias
	{
	  if ($4.str)
	    $2->set_name($4.str,$4.length,system_charset_info);
	  else
	    $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
	  $$= $2;
	}
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4480 4481 4482 4483 4484 4485 4486
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); }
4487 4488
	| BIT_XOR  '(' in_sum_expr ')'
	  { $$=new Item_sum_xor($3); }
4489
	| COUNT_SYM '(' opt_all '*' ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4490 4491 4492
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
4493
	| COUNT_SYM '(' DISTINCT
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4494
	  { Select->in_sum_expr++; }
4495
	   expr_list
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4496
	  { Select->in_sum_expr--; }
4497 4498
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4499 4500 4501 4502
	| 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); }
4503 4504 4505 4506 4507 4508 4509
/*
   According to ANSI SQL, DISTINCT is allowed and has
   no sence inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
   is processed like an ordinary MIN | MAX()
 */
	| MIN_SYM '(' DISTINCT in_sum_expr ')'
	  { $$=new Item_sum_min($4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4510 4511
	| MAX_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_max($3); }
4512 4513
	| MAX_SYM '(' DISTINCT in_sum_expr ')'
	  { $$=new Item_sum_max($4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4514 4515
	| STD_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_std($3); }
4516 4517
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4518
	| SUM_SYM '(' in_sum_expr ')'
4519
	  { $$=new Item_sum_sum($3); }
4520 4521
	| SUM_SYM '(' DISTINCT in_sum_expr ')'
	  { $$=new Item_sum_sum_distinct($4); }
monty@mysql.com's avatar
monty@mysql.com committed
4522 4523 4524 4525 4526
	| GROUP_CONCAT_SYM '(' opt_distinct
	  { Select->in_sum_expr++; }
	  expr_list opt_gorder_clause
	  opt_gconcat_separator
	 ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4527
	  {
monty@mysql.com's avatar
monty@mysql.com committed
4528 4529 4530
	    Select->in_sum_expr--;
	    $$=new Item_func_group_concat($3,$5,Select->gorder_list,$7);
	    $5->empty();
4531 4532 4533 4534 4535 4536 4537
	  };

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

opt_gconcat_separator:
monty@mysql.com's avatar
monty@mysql.com committed
4538
    /* empty */        { $$ = new (&YYTHD->mem_root) String(",",1,default_charset_info); }
4539
    |SEPARATOR_SYM text_string  { $$ = $2; };
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4540

4541 4542

opt_gorder_clause:
4543 4544
	  /* empty */
	  {
4545
            Select->gorder_list = NULL;
4546 4547 4548
	  }
	| order_clause
          {
4549 4550 4551
            SELECT_LEX *select= Select;
            select->gorder_list=
	      (SQL_LIST*) sql_memdup((char*) &select->order_list,
4552
				     sizeof(st_sql_list));
4553
	    select->order_list.empty();
4554
	  };
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4555

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4556 4557

in_sum_expr:
4558
	opt_all
4559 4560 4561 4562
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
4563
	    yyerror(ER(ER_SYNTAX_ERROR));
4564
	    YYABORT;
4565 4566
	  }
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4567 4568
	expr
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4569
	  Select->in_sum_expr--;
4570
	  $$= $3;
4571
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4572

4573
cast_type:
4574
	BINARY opt_len		{ $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; }
4575 4576
	| CHAR_SYM opt_len opt_binary	{ $$=ITEM_CAST_CHAR; }
	| NCHAR_SYM opt_len	{ $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; }
4577 4578 4579 4580 4581 4582 4583
	| SIGNED_SYM		{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| SIGNED_SYM INT_SYM	{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| UNSIGNED		{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| UNSIGNED INT_SYM	{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; Lex->length= (char*)0; }
	| DATE_SYM		{ $$=ITEM_CAST_DATE; Lex->charset= NULL; Lex->length= (char*)0; }
	| TIME_SYM		{ $$=ITEM_CAST_TIME; Lex->charset= NULL; Lex->length= (char*)0; }
	| DATETIME		{ $$=ITEM_CAST_DATETIME; Lex->charset= NULL; Lex->length= (char*)0; }
4584
	;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4585

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4586
expr_list:
4587
	{ Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4588
	expr_list2
4589
	{ $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4590 4591

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

4595 4596
ident_list_arg:
          ident_list          { $$= $1; }
4597
        | '(' ident_list ')'  { $$= $2; };
4598

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4599
ident_list:
4600
        { Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4601
        ident_list2
4602
        { $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4603 4604

ident_list2:
4605
        simple_ident { Select->expr_list.head()->push_back($1); }
4606
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4607 4608 4609

opt_expr:
	/* empty */      { $$= NULL; }
4610
	| expr           { $$= $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4611 4612 4613

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

when_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4617
        { Select->when_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4618
	when_list2
4619
	{ $$= Select->when_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4620 4621

when_list2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4622
	expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4623
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4624
	    SELECT_LEX *sel=Select;
4625 4626
	    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
4627
	}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4628
	| when_list2 WHEN_SYM expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4629
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4630
	    SELECT_LEX *sel=Select;
4631 4632
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
4633
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4634

igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4635 4636 4637 4638 4639 4640 4641 4642 4643 4644
table_ref:
        table_factor            { $$=$1; }
        | join_table            { $$=$1; }
          { 
	    LEX *lex= Lex;
            if (!($$= lex->current_select->nest_last_join(lex->thd)))
              YYABORT;
          }     	        
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4645
join_table_list:
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4646 4647 4648 4649 4650 4651 4652 4653 4654
        table_ref { $$=$1; }
        | join_table_list ',' table_ref { $$=$3; }
        ;

join_table:
        table_ref normal_join table_ref { $$=$3; }
	| table_ref STRAIGHT_JOIN table_factor
	  { $3->straight=1; $$=$3 ; }
	| table_ref normal_join table_ref ON expr
4655
	  { add_join_on($3,$5); $$=$3; }
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4656
	| table_ref normal_join table_ref
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4657
	  USING
4658
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4659
	    SELECT_LEX *sel= Select;
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4660
            sel->save_names_for_using_list($1, $3);
4661
	  }
4662 4663 4664
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4665
	| table_ref LEFT opt_outer JOIN_SYM table_factor ON expr
4666
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4667
	| table_ref LEFT opt_outer JOIN_SYM table_factor
4668
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4669
	    SELECT_LEX *sel= Select;
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4670
            sel->save_names_for_using_list($1, $5);
4671
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4672
	  USING '(' using_list ')'
4673
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4674
	| table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
4675
	  {
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4676 4677
	    add_join_natural($1,$6);
	    $6->outer_join|=JOIN_TYPE_LEFT;
4678 4679
	    $$=$6;
	  }
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4680 4681 4682 4683 4684 4685 4686 4687
	| table_ref RIGHT opt_outer JOIN_SYM table_factor ON expr
          { 
	    LEX *lex= Lex;
            if (!($$= lex->current_select->convert_right_join()))
              YYABORT;
            add_join_on($$, $7);
          }
	| table_ref RIGHT opt_outer JOIN_SYM table_factor
4688
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4689
	    SELECT_LEX *sel= Select;
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4690
            sel->save_names_for_using_list($1, $5);
4691
	  }
4692
	  USING '(' using_list ')'
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4693 4694 4695 4696 4697 4698 4699
          { 
	    LEX *lex= Lex;
            if (!($$= lex->current_select->convert_right_join()))
              YYABORT;
            add_join_on($$, $9);
          }
	| table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
4700
	  {
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4701 4702 4703 4704
	    add_join_natural($6,$1);
	    LEX *lex= Lex;
            if (!($$= lex->current_select->convert_right_join()))
              YYABORT;
4705
	  }
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4706 4707 4708
	| table_ref NATURAL JOIN_SYM table_factor
	  { add_join_natural($1,$4); $$=$4; };
        
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4709 4710

normal_join:
4711 4712 4713 4714
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4715

igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4716
table_factor:
4717
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4718
	  SELECT_LEX *sel= Select;
4719
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4720
	  sel->table_join_options= 0;
4721
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4722
        table_ident opt_table_alias opt_key_definition
4723
	{
4724
	  LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4725
	  SELECT_LEX *sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4726
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4727
					   sel->get_table_join_options(),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4728
					   lex->lock_option,
4729 4730
					   sel->get_use_index(),
					   sel->get_ignore_index())))
4731
	    YYABORT;
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4732
          sel->add_joined_table($$); 
4733
	}
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746
        | '('
          { 
            LEX *lex= Lex;
            if (lex->current_select->init_nested_join(lex->thd))
              YYABORT;
          }            
          join_table_list ')'
          {
            LEX *lex= Lex;
            if (!($$= lex->current_select->end_nested_join(lex->thd)))
              YYABORT;
          }	
	| '{' ident table_ref LEFT OUTER JOIN_SYM table_ref ON expr '}'
4747
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
4748
        | '(' SELECT_SYM select_derived ')' opt_table_alias
4749 4750
	{
	  LEX *lex=Lex;
4751 4752 4753
	  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
4754
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
4755
				  TL_READ,(List<String> *)0,
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4756 4757
	                          (List<String> *)0)))

4758
	    YYABORT;
igor@rurik.mysql.com's avatar
af  
igor@rurik.mysql.com committed
4759
          lex->current_select->add_joined_table($$);           
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4760
	};
4761

4762
select_derived:
4763
        {
4764
	  LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
4765
	  lex->derived_tables|= DERIVED_SUBQUERY;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4766 4767 4768
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
4769 4770
	  {
	    yyerror(ER(ER_SYNTAX_ERROR));
4771 4772
	    YYABORT;
	  }
4773
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
4774
              mysql_new_select(lex, 1))
4775 4776
	    YYABORT;
	  mysql_init_select(lex);
4777
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
4778 4779 4780 4781 4782
	  lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
	}
        select_options select_item_list
	{
	  Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
4783
	}
4784
	opt_select_from union_opt
4785
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4786 4787 4788

opt_outer:
	/* empty */	{}
4789
	| OUTER		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4790 4791 4792 4793

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
4794
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4795
	    SELECT_LEX *sel= Select;
4796 4797 4798
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4799 4800
	| FORCE_SYM key_usage_list
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4801
	    SELECT_LEX *sel= Select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4802 4803 4804 4805
	    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
4806
	| IGNORE_SYM key_usage_list
4807
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4808
	    SELECT_LEX *sel= Select;
4809 4810
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
4811
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4812 4813

key_usage_list:
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4814
	key_or_index { Select->interval_list.empty(); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4815
        '(' key_list_or_empty ')'
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4816
        { $$= &Select->interval_list; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4817 4818 4819 4820 4821 4822
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4823 4824 4825

key_usage_list2:
	key_usage_list2 ',' ident
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4826
        { Select->
monty@mysql.com's avatar
monty@mysql.com committed
4827
	    interval_list.push_back(new (&YYTHD->mem_root) String((const char*) $3.str, $3.length,
4828
				    system_charset_info)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4829
	| ident
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4830
        { Select->
monty@mysql.com's avatar
monty@mysql.com committed
4831
	    interval_list.push_back(new (&YYTHD->mem_root) String((const char*) $1.str, $1.length,
4832
				    system_charset_info)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4833
	| PRIMARY_SYM
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4834
        { Select->
monty@mysql.com's avatar
monty@mysql.com committed
4835
	    interval_list.push_back(new (&YYTHD->mem_root) String("PRIMARY", 7,
4836
				    system_charset_info)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4837 4838 4839

using_list:
	ident
4840
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4841
	    SELECT_LEX *sel= Select;
4842 4843 4844 4845
	    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
4846 4847 4848 4849
	      YYABORT;
	  }
	| using_list ',' ident
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4850
	    SELECT_LEX *sel= Select;
4851
	    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
4852
	      YYABORT;
4853
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4854 4855

interval:
4856 4857
	interval_time_st	{}
	| DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4858
	| DAY_MICROSECOND_SYM	{ $$=INTERVAL_DAY_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4859 4860
	| DAY_MINUTE_SYM	{ $$=INTERVAL_DAY_MINUTE; }
	| DAY_SECOND_SYM	{ $$=INTERVAL_DAY_SECOND; }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4861
	| HOUR_MICROSECOND_SYM	{ $$=INTERVAL_HOUR_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4862 4863
	| HOUR_MINUTE_SYM	{ $$=INTERVAL_HOUR_MINUTE; }
	| HOUR_SECOND_SYM	{ $$=INTERVAL_HOUR_SECOND; }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4864 4865
	| MICROSECOND_SYM	{ $$=INTERVAL_MICROSECOND; }
	| MINUTE_MICROSECOND_SYM	{ $$=INTERVAL_MINUTE_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4866
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
4867 4868 4869 4870 4871 4872 4873 4874
	| SECOND_MICROSECOND_SYM	{ $$=INTERVAL_SECOND_MICROSECOND; }
	| YEAR_MONTH_SYM	{ $$=INTERVAL_YEAR_MONTH; };

interval_time_st:
	DAY_SYM			{ $$=INTERVAL_DAY; }
	| WEEK_SYM		{ $$=INTERVAL_WEEK; }
	| HOUR_SYM		{ $$=INTERVAL_HOUR; }
	| FRAC_SECOND_SYM	{ $$=INTERVAL_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4875 4876
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
4877
	| QUARTER_SYM		{ $$=INTERVAL_QUARTER; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4878
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
4879
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4880

4881
date_time_type:
4882 4883 4884
	DATE_SYM		{$$=MYSQL_TIMESTAMP_DATE;}
	| TIME_SYM		{$$=MYSQL_TIMESTAMP_TIME;}
	| DATETIME		{$$=MYSQL_TIMESTAMP_DATETIME;};
4885

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4886 4887 4888
table_alias:
	/* empty */
	| AS
4889
	| EQ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4890 4891 4892 4893

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

4896 4897 4898 4899
opt_all:
	/* empty */
	| ALL
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4900 4901

where_clause:
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4902
	/* empty */  { Select->where= 0; }
4903 4904
	| WHERE expr
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4905
	    Select->where= $2;
4906 4907 4908
	    if ($2)
	      $2->top_level_item();
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4909
 	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4910 4911 4912

having_clause:
	/* empty */
4913 4914
	| HAVING
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4915
	    Select->parsing_place= SELECT_LEX_NODE::IN_HAVING;
4916 4917
          }
	  expr
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4918
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4919
	    SELECT_LEX *sel= Select;
4920 4921
	    sel->having= $3;
	    sel->parsing_place= SELECT_LEX_NODE::NO_MATTER;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4922 4923 4924
	    if ($3)
	      $3->top_level_item();
	  }
4925
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4926 4927

opt_escape:
4928 4929
	ESCAPE_SYM simple_expr { $$= $2; }
	| /* empty */
monty@mysql.com's avatar
Merge  
monty@mysql.com committed
4930 4931 4932 4933 4934
          {

            $$= ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ?
		 new Item_string("", 0, &my_charset_latin1) :
                 new Item_string("\\", 1, &my_charset_latin1));
4935 4936
          }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4937 4938 4939


/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4940
   group by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4941 4942 4943 4944
*/

group_clause:
	/* empty */
4945
	| GROUP BY group_list olap_opt;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4946 4947

group_list:
4948
	group_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4949
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
4950
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4951
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4952

4953 4954
olap_opt:
	/* empty */ {}
4955
	| WITH CUBE_SYM
4956
          {
4957
	    LEX *lex=Lex;
4958 4959 4960 4961 4962 4963
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE",
		       "global union parameters");
	      YYABORT;
	    }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4964
	    lex->current_select->olap= CUBE_TYPE;
4965
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
4966
	    YYABORT;	/* To be deleted in 5.1 */
4967
	  }
4968
	| WITH ROLLUP_SYM
4969
          {
4970 4971 4972 4973 4974 4975 4976
	    LEX *lex= Lex;
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP",
		       "global union parameters");
	      YYABORT;
	    }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4977
	    lex->current_select->olap= ROLLUP_TYPE;
4978
	  }
4979
	;
4980

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4981
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4982
   Order by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4983 4984
*/

4985
opt_order_clause:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4986
	/* empty */
4987
	| order_clause;
4988 4989

order_clause:
4990 4991
	ORDER_SYM BY
        {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4992
	  LEX *lex=Lex;
4993
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4994
	      lex->current_select->olap !=
4995
	      UNSPECIFIED_OLAP_TYPE)
4996
	  {
4997
	    net_printf(lex->thd, ER_WRONG_USAGE,
4998 4999 5000 5001
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
5002
	} order_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5003 5004 5005

order_list:
	order_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5006
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5007
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5008
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5009 5010 5011

order_dir:
	/* empty */ { $$ =  1; }
5012
	| ASC  { $$ =1; }
5013
	| DESC { $$ =0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5014 5015


5016 5017 5018
opt_limit_clause_init:
	/* empty */
	{
5019 5020
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
5021
          sel->offset_limit= 0L;
5022
          sel->select_limit= HA_POS_ERROR;
5023
	}
5024 5025 5026
	| limit_clause {}
	;

5027 5028 5029 5030 5031
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

5032
limit_clause:
5033
	LIMIT limit_options {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5034
	;
5035 5036 5037

limit_options:
	ULONG_NUM
5038
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5039
            SELECT_LEX *sel= Select;
5040 5041
            sel->select_limit= $1;
            sel->offset_limit= 0L;
5042
	    sel->explicit_limit= 1;
5043 5044 5045
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5046
	    SELECT_LEX *sel= Select;
5047 5048
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
5049
	    sel->explicit_limit= 1;
5050
	  }
5051
	| ULONG_NUM OFFSET_SYM ULONG_NUM
5052
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5053
	    SELECT_LEX *sel= Select;
5054 5055
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
5056
	    sel->explicit_limit= 1;
5057 5058
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5059 5060 5061 5062 5063


delete_limit_clause:
	/* empty */
	{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5064
	  LEX *lex=Lex;
5065
	  lex->current_select->select_limit= HA_POS_ERROR;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5066
	}
5067
	| LIMIT ulonglong_num
5068 5069 5070 5071 5072
	{
	  SELECT_LEX *sel= Select;
	  sel->select_limit= (ha_rows) $2;
	  sel->explicit_limit= 1;
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5073 5074

ULONG_NUM:
monty@mysql.com's avatar
monty@mysql.com committed
5075 5076 5077 5078 5079 5080
	NUM	        { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| LONG_NUM      { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| ULONGLONG_NUM { int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| REAL_NUM 	{ int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	| FLOAT_NUM	{ int error; $$= (ulong) my_strtoll10($1.str, (char**) 0, &error); }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5081

5082
ulonglong_num:
monty@mysql.com's avatar
monty@mysql.com committed
5083 5084 5085 5086 5087 5088
	NUM	    { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| ULONGLONG_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| LONG_NUM  { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| REAL_NUM  { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	| FLOAT_NUM { int error; $$= (ulonglong) my_strtoll10($1.str, (char**) 0, &error); }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5089 5090 5091 5092 5093 5094

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
5095 5096 5097 5098 5099 5100 5101
	    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
5102 5103 5104
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
5105
	    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
5106
	      YYABORT;
5107
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5108
	  }
5109
	  '(' procedure_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5110 5111 5112 5113


procedure_list:
	/* empty */ {}
5114
	| procedure_list2 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5115 5116 5117

procedure_list2:
	procedure_list2 ',' procedure_item
5118
	| procedure_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5119 5120 5121 5122

procedure_item:
	  remember_name expr
	  {
5123 5124
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5125 5126
	      YYABORT;
	    if (!$2->name)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5127
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
5128 5129 5130 5131 5132 5133
	  }
          ;


select_var_list_init:
	   {
5134 5135
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
5136 5137
	        YYABORT;
	   }
5138
	   select_var_list
5139
	   {}
5140
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5141

Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5142
select_var_list:
5143 5144 5145 5146
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

5147 5148
select_var_ident:  
	   '@' ident_or_text
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5149
           {
5150
             LEX *lex=Lex;
5151
	     if (lex->result) 
5152
	       ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
5153
	     else
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5154 5155
	       YYABORT;
	   }
5156
           | ident_or_text
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5157
           {
5158
             LEX *lex=Lex;
5159
	     sp_pvar_t *t;
5160 5161

	     if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1)))
5162
	     {
5163
	       net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str);
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5164
	       YYABORT;
5165
	     }
5166
	     if (! lex->result)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5167
	       YYABORT;
5168 5169
	     else
	     {
5170
	       ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset,t->type));
5171 5172
	       t->isset= TRUE;
	     }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5173
	   }
5174
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5175

5176
into:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5177
        INTO OUTFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5178
	{
5179
	  LEX *lex=Lex;
5180 5181
	  if (!lex->describe)
	  {
5182
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
5183 5184 5185 5186 5187
	    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
5188 5189
	}
	opt_field_term opt_line_term
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5190
	| INTO DUMPFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5191
	{
5192
	  LEX *lex=Lex;
5193 5194
	  if (!lex->describe)
	  {
5195
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
5196 5197 5198 5199 5200
	    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
5201
	}
5202
        | INTO select_var_list_init
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5203
	{
5204
	  Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
5205 5206
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5207

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5208 5209 5210
/*
  DO statement
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5211

5212
do:	DO_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5213 5214 5215 5216 5217 5218
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
5219 5220 5221 5222
	values
	{}
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5223
/*
5224
  Drop : delete tables or index or user
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5225 5226 5227
*/

drop:
serg@serg.mylan's avatar
serg@serg.mylan committed
5228
	DROP opt_temporary table_or_tables if_exists table_list opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5229
	{
5230 5231
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
5232 5233
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5234
	}
5235
	| DROP INDEX_SYM ident ON table_ident {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5236
	  {
5237 5238
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
5239 5240 5241
	     lex->alter_info.drop_list.empty();
	     lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
                                                                $3.str));
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5242 5243
	     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
5244 5245 5246 5247
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
5248 5249 5250 5251
	    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
5252
	 }
5253
	| DROP FUNCTION_SYM if_exists sp_name opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5254
	  {
5255 5256
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
5257
	    lex->drop_if_exists= $3;
5258
	    lex->spname= $4;
5259
	  }
5260
	| DROP PROCEDURE if_exists sp_name opt_restrict
5261 5262 5263
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_PROCEDURE;
5264
	    lex->drop_if_exists= $3;
5265
	    lex->spname= $4;
5266 5267 5268 5269 5270 5271
	  }
	| DROP USER
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_USER;
	    lex->users_list.empty();
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5272
	  }
5273 5274
	  user_list
	  {}
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
5275 5276 5277 5278 5279 5280 5281
	| DROP VIEW_SYM if_exists table_list opt_restrict
	  {
	    THD *thd= YYTHD;
	    LEX *lex= thd->lex;
	    lex->sql_command= SQLCOM_DROP_VIEW;
	    lex->drop_if_exists= $3;
	  }
5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296
        | DROP TRIGGER_SYM ident '.' ident
          {
            LEX *lex= Lex;

            lex->sql_command= SQLCOM_DROP_TRIGGER;
            /* QQ: Could we loosen lock type in certain cases ? */
            if (!lex->select_lex.add_table_to_list(YYTHD,
                                                   new Table_ident($3),
                                                   (LEX_STRING*) 0,
                                                   TL_OPTION_UPDATING,
                                                   TL_WRITE))
              YYABORT;
            lex->name_and_length= $5;
          }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5297 5298

table_list:
5299
	table_name
5300
	| table_list ',' table_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5301

5302
table_name:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5303
	table_ident
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5304 5305 5306 5307 5308
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5309 5310

if_exists:
5311
	/* empty */ { $$= 0; }
5312 5313
	| IF EXISTS { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5314

5315 5316 5317 5318
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5319 5320 5321 5322 5323
/*
** Insert : add new data to table
*/

insert:
5324 5325 5326 5327 5328 5329
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
5330
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
5331
	} insert_lock_option
5332
	opt_ignore insert2
5333
	{
5334
	  Select->set_lock_for_tables($3);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5335
	  Lex->current_select= &Lex->select_lex;
5336
	}
5337
	insert_field_spec opt_insert_update
5338
	{}
5339
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5340 5341

replace:
5342 5343
	REPLACE
	{
5344
	  LEX *lex=Lex;
5345 5346
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
5347
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
5348
	}
5349 5350
	replace_lock_option insert2
	{
5351
	  Select->set_lock_for_tables($3);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5352
	  Lex->current_select= &Lex->select_lex;
5353 5354
	}
	insert_field_spec
5355
	{}
5356
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5357 5358

insert_lock_option:
5359 5360 5361 5362
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
5363
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5364 5365

replace_lock_option:
5366 5367
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5368 5369 5370

insert2:
	INTO insert_table {}
5371
	| insert_table {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5372 5373

insert_table:
5374
	table_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5375
	{
5376 5377 5378 5379
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
5380
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5381 5382

insert_field_spec:
serg@serg.mylan's avatar
serg@serg.mylan committed
5383 5384 5385
	insert_values {}
	| '(' ')' insert_values {}
	| '(' fields ')' insert_values {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5386 5387
	| SET
	  {
5388 5389 5390
	    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
5391 5392
	      YYABORT;
	   }
5393
	   ident_eq_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5394 5395 5396 5397

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
5398
	| '(' ')'	  { };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5399 5400 5401

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
5402
	| insert_ident		{ Lex->field_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5403 5404 5405

insert_values:
	VALUES	values_list  {}
5406
	| VALUE_SYM values_list  {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5407 5408
	|     create_select     { Select->set_braces(0);} union_clause {}
	| '(' create_select ')' { Select->set_braces(1);} union_opt {}
5409
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5410 5411 5412

values_list:
	values_list ','  no_braces
5413
	| no_braces;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5414 5415 5416 5417

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
5418
	ident_eq_value;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5419 5420

ident_eq_value:
5421
	simple_ident_nospvar equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5422
	 {
5423 5424 5425
	  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
5426
	    YYABORT;
5427
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5428 5429

equal:	EQ		{}
5430 5431 5432 5433 5434 5435 5436
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5437 5438 5439 5440 5441 5442 5443 5444 5445

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
5446 5447
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5448
	    YYABORT;
5449
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5450 5451 5452

opt_values:
	/* empty */ {}
5453
	| values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5454 5455

values:
5456
	values ','  expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5457 5458 5459 5460
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
5461 5462 5463 5464 5465 5466 5467 5468
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
5469
	expr	  { $$= $1;}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
5470
	| DEFAULT {$$= new Item_default_value(); }
5471
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5472

5473 5474
opt_insert_update:
        /* empty */
5475
        | ON DUPLICATE_SYM
5476 5477 5478 5479 5480
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
5481
	      yyerror(ER(ER_SYNTAX_ERROR));
5482 5483 5484
              YYABORT;
            }
          }
5485
          KEY_SYM UPDATE_SYM update_list
5486 5487
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5488 5489 5490
/* Update rows in a table */

update:
5491 5492
	UPDATE_SYM
	{
5493
	  LEX *lex= Lex;
5494
	  mysql_init_select(lex);
5495
          lex->sql_command= SQLCOM_UPDATE;
5496
	  lex->lock_option= TL_UNLOCK; 	/* Will be set later */
5497
        }
5498 5499 5500
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
5501
	  LEX *lex= Lex;
5502
	  Select->set_lock_for_tables($3);
5503
          if (lex->select_lex.table_list.elements > 1)
5504
            lex->sql_command= SQLCOM_UPDATE_MULTI;
5505 5506 5507 5508 5509 5510 5511
	  else if (lex->select_lex.get_table_list()->derived)
	  {
	    /* it is single table update and it is update of derived table */
	    net_printf(lex->thd, ER_NON_UPDATABLE_TABLE,
		       lex->select_lex.get_table_list()->alias, "UPDATE");
	    YYABORT;
	  }
5512 5513
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5514 5515

update_list:
5516
	update_list ',' simple_ident_nospvar equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5517
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5518
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5519 5520
	    YYABORT;
	}
5521
	| simple_ident_nospvar equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5522
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5523
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5524
	      YYABORT;
5525
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5526 5527

opt_low_priority:
5528
	/* empty */	{ $$= YYTHD->update_lock_default; }
5529
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5530 5531 5532 5533

/* Delete rows from a table */

delete:
5534
	DELETE_SYM
5535
	{
5536 5537
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
5538
	  lex->lock_option= lex->thd->update_lock_default;
5539
	  lex->select_lex.init_order();
5540
	}
5541 5542
	opt_delete_options single_multi {}
	;
5543 5544

single_multi:
5545 5546
 	FROM table_ident
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5547 5548
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
5549 5550 5551
	    YYABORT;
	}
	where_clause opt_order_clause
5552
	delete_limit_clause {}
5553
	| table_wild_list
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5554
	  { mysql_init_multi_delete(Lex); }
5555
          FROM join_table_list where_clause
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5556 5557
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
5558 5559 5560
	  USING join_table_list where_clause
	  {}
	;
5561 5562 5563

table_wild_list:
	  table_wild_one {}
5564
	  | table_wild_list ',' table_wild_one {};
5565 5566

table_wild_one:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5567
	ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5568
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5569 5570
	  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
5571 5572
	    YYABORT;
        }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5573
	| ident '.' ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5574
	  {
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5575 5576
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5577 5578
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
5579
	      YYABORT;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5580
	  }
5581
	;
5582 5583

opt_wild:
5584
	/* empty */	{}
5585
	| '.' '*'	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5586 5587


5588
opt_delete_options:
5589
	/* empty */	{}
5590
	| opt_delete_option opt_delete_options {};
5591 5592

opt_delete_option:
5593
	QUICK		{ Select->options|= OPTION_QUICK; }
5594 5595
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
	| IGNORE_SYM	{ Lex->duplicates= DUP_IGNORE; };
5596

5597
truncate:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
5598
	TRUNCATE_SYM opt_table_sym table_name
5599
	{
5600
	  LEX* lex= Lex;
5601
	  lex->sql_command= SQLCOM_TRUNCATE;
5602
	  lex->select_lex.options= 0;
5603
	  lex->select_lex.init_order();
5604 5605
	}
	;
5606

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5607 5608
opt_table_sym:
	/* empty */
5609
	| TABLE_SYM;
5610

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5611 5612
/* Show things */

5613 5614
show:	SHOW
	{
5615 5616 5617 5618
	  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
5619
	show_param
5620 5621
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5622 5623 5624 5625 5626

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
5627
	  {
5628
	    LEX *lex= Lex;
5629
	    lex->sql_command= SQLCOM_SHOW_TABLES;
5630
	    lex->select_lex.db= $2;
5631
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5632
	| TABLE_SYM STATUS_SYM opt_db wild
5633
	  {
5634
	    LEX *lex= Lex;
5635
	    lex->sql_command= SQLCOM_SHOW_TABLES;
5636
	    lex->describe= DESCRIBE_EXTENDED;
5637
	    lex->select_lex.db= $3;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5638
	  }
5639
	| OPEN_SYM TABLES opt_db wild
5640
	  {
5641
	    LEX *lex= Lex;
5642
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5643
	    lex->select_lex.db= $3;
5644
	  }
5645
	| ENGINE_SYM storage_engines 
5646 5647
	  { Lex->create_info.db_type= $2; }
	  show_engine_param
5648
	| opt_full COLUMNS from_or_in table_ident opt_db wild
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5649 5650
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5651 5652
	    if ($5)
	      $4->change_db($5);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5653
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5654 5655
	      YYABORT;
	  }
5656
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
5657 5658
	  TEXT_STRING_sys AND_SYM MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND_SYM MASTER_SERVER_ID_SYM EQ
5659 5660 5661 5662 5663
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
5664
	    Lex->mi.server_id = $16;
5665
          }
5666
        | master_or_binary LOGS_SYM
5667 5668
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
5669 5670 5671 5672 5673
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
5674
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
5675
          {
5676 5677
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
5678
          } opt_limit_clause_init
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5679 5680 5681 5682 5683
	| 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
5684
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5685 5686
	      YYABORT;
	  }
5687 5688 5689 5690 5691 5692 5693 5694
	| COLUMN_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
	  }
	| TABLE_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
5695 5696 5697 5698 5699 5700 5701
	    lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
	    WARN_DEPRECATED("SHOW TABLE TYPES", "SHOW [STORAGE] ENGINES");
	  }
	| opt_storage ENGINES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
5702 5703 5704 5705 5706 5707
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
5708
        | COUNT_SYM '(' '*' ')' WARNINGS
5709
          { (void) create_select_for_variable("warning_count"); }
5710
        | COUNT_SYM '(' '*' ')' ERRORS
5711
	  { (void) create_select_for_variable("error_count"); }
5712
        | WARNINGS opt_limit_clause_init
5713
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
5714
        | ERRORS opt_limit_clause_init
5715
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5716 5717
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
5718
        | INNOBASE_SYM STATUS_SYM
5719
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS; WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5720 5721
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
5722
	| opt_var_type VARIABLES wild
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5723
	  {
5724
	    THD *thd= YYTHD;
5725 5726
	    thd->lex->sql_command= SQLCOM_SHOW_VARIABLES;
	    thd->lex->option_type= (enum_var_type) $1;
5727
	  }
5728
	| charset wild
5729
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
5730 5731
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
5732
	| BERKELEY_DB_SYM LOGS_SYM
5733
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); }
tim@cane.mysql.fi's avatar
tim@cane.mysql.fi committed
5734
	| LOGS_SYM
5735
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); }
5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758
	| GRANTS
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    THD *thd= lex->thd;
	    LEX_USER *curr_user;
            if (!(curr_user= (LEX_USER*) thd->alloc(sizeof(st_lex_user))))
              YYABORT;
            curr_user->user.str= thd->priv_user;
            curr_user->user.length= strlen(thd->priv_user);
            if (*thd->priv_host != 0)
            {
              curr_user->host.str= thd->priv_host;
              curr_user->host.length= strlen(thd->priv_host);
            }
            else
            {
              curr_user->host.str= (char *) "%";
              curr_user->host.length= 1;
            }
            curr_user->password.str=NullS;
	    lex->grant_user= curr_user;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5759
	| GRANTS FOR_SYM user
5760 5761 5762 5763 5764 5765
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
5766
	| CREATE DATABASE opt_if_not_exists ident
5767 5768
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5769 5770
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
5771
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5772 5773
        | CREATE TABLE_SYM table_ident
          {
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784
            LEX *lex= Lex;
	    lex->sql_command = SQLCOM_SHOW_CREATE;
	    if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
	      YYABORT;
            lex->only_view= 0;
	  }
        | CREATE VIEW_SYM table_ident
          {
            LEX *lex= Lex;
	    lex->sql_command = SQLCOM_SHOW_CREATE;
	    if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5785
	      YYABORT;
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
5786
            lex->only_view= 1;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5787 5788 5789 5790
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5791
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5792 5793 5794
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
5795
          }
5796
	| CREATE PROCEDURE sp_name
5797
	  {
5798 5799 5800 5801
	    LEX *lex= Lex;

	    lex->sql_command = SQLCOM_SHOW_CREATE_PROC;
	    lex->spname= $3;
5802
	  }
5803
	| CREATE FUNCTION_SYM sp_name
5804
	  {
5805 5806 5807 5808
	    LEX *lex= Lex;

	    lex->sql_command = SQLCOM_SHOW_CREATE_FUNC;
	    lex->spname= $3;
5809 5810 5811 5812 5813 5814 5815 5816 5817 5818
	  }
	| PROCEDURE STATUS_SYM wild
	  {
	    Lex->sql_command = SQLCOM_SHOW_STATUS_PROC;
	  }
	| FUNCTION_SYM STATUS_SYM wild
	  {
	    Lex->sql_command = SQLCOM_SHOW_STATUS_FUNC;
	  };

5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841
show_engine_param:
	STATUS_SYM
	  {
	    switch (Lex->create_info.db_type) {
	    case DB_TYPE_INNODB:
	      Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;
	      break;
	    default:
	      net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "STATUS");
	      YYABORT;
	    }
	  }
	| LOGS_SYM
	  {
	    switch (Lex->create_info.db_type) {
	    case DB_TYPE_BERKELEY_DB:
	      Lex->sql_command = SQLCOM_SHOW_LOGS;
	      break;
	    default:
	      net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "LOGS");
	      YYABORT;
	    }
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5842

5843 5844 5845 5846
master_or_binary:
	MASTER_SYM
	| BINARY;

5847 5848 5849 5850
opt_storage:
	/* empty */
	| STORAGE_SYM;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5851 5852
opt_db:
	/* empty */  { $$= 0; }
5853
	| from_or_in ident { $$= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5854 5855 5856

wild:
	/* empty */
5857 5858 5859
	| LIKE TEXT_STRING_sys
	  { Lex->wild=  new (&YYTHD->mem_root) String($2.str, $2.length,
                                                      system_charset_info); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5860

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5861 5862
opt_full:
	/* empty */ { Lex->verbose=0; }
5863
	| FULL	    { Lex->verbose=1; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5864

5865 5866
from_or_in:
	FROM
5867
	| IN_SYM;
5868

5869 5870
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5871
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
5872 5873 5874

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


bk@work.mysql.com's avatar
bk@work.mysql.com committed
5878 5879 5880 5881
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
5882 5883 5884 5885
	  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
5886
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5887 5888
	    YYABORT;
	}
5889
	opt_describe_column {}
5890 5891 5892
	| describe_command opt_extended_describe
	  { Lex->describe|= DESCRIBE_NORMAL; }
	  select
5893
          {
5894
	    LEX *lex=Lex;
5895
	    lex->select_lex.options|= SELECT_DESCRIBE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5896 5897
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5898 5899 5900

describe_command:
	DESC
5901
	| DESCRIBE;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5902

5903 5904 5905 5906 5907
opt_extended_describe:
	/* empty */ {}
	| EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5908 5909 5910
opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
5911
	| ident
monty@mysql.com's avatar
monty@mysql.com committed
5912
	  { Lex->wild= new (&YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5913 5914 5915 5916 5917


/* flush things */

flush:
5918
	FLUSH_SYM opt_no_write_to_binlog
5919 5920 5921
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5922
          lex->no_write_to_binlog= $2;
5923
	}
5924 5925 5926
	flush_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5927 5928 5929

flush_options:
	flush_options ',' flush_option
5930
	| flush_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5931 5932

flush_option:
5933
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5934
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5935
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5936 5937 5938 5939
	| 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
5940 5941
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
5942 5943
	| 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
5944

5945
opt_table_list:
5946 5947
	/* empty */  {;}
	| table_list {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5948

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5949
reset:
5950 5951 5952 5953
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
5954 5955 5956 5957
	} reset_options
	{}
	;

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5958 5959
reset_options:
	reset_options ',' reset_option
5960
	| reset_option;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5961 5962

reset_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5963 5964
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
5965
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5966

5967
purge:
5968 5969 5970 5971
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
5972 5973 5974 5975 5976
	} purge_options
	{}
	;

purge_options:
5977
	master_or_binary LOGS_SYM purge_option
5978
	;
5979 5980

purge_option:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5981
        TO_SYM TEXT_STRING_sys
5982 5983 5984 5985 5986 5987 5988 5989 5990
        {
	   Lex->sql_command = SQLCOM_PURGE;
	   Lex->to_log = $2.str;
        }
	| BEFORE_SYM expr
	{
	  if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2))
	  {
	    net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE");
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5991
	    YYABORT;
5992 5993
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
5994
	  /*
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5995
	    it is OK only emulate fix_fieds, because we need only
5996 5997
            value of constant
	  */
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5998
	  tmp->quick_fix_field();
5999
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
6000
	  Lex->purge_time= (ulong) tmp->val_int();
6001
	}
6002
	;
6003

bk@work.mysql.com's avatar
bk@work.mysql.com committed
6004 6005 6006
/* kill threads */

kill:
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
6007
	KILL_SYM kill_option expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6008
	{
6009
	  LEX *lex=Lex;
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
6010
	  if ($3->fix_fields(lex->thd, 0, &$3) || $3->check_cols(1))
6011
	  {
6012
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
6013 6014 6015
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
6016
	  lex->thread_id= (ulong) $3->val_int();
6017
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6018

hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
6019 6020 6021 6022 6023
kill_option:
	/* empty */	 { Lex->type= 0; }
	| CONNECTION_SYM { Lex->type= 0; }
	| QUERY_SYM      { Lex->type= ONLY_KILL_QUERY; };

bk@work.mysql.com's avatar
bk@work.mysql.com committed
6024 6025 6026
/* change database */

use:	USE_SYM ident
6027 6028
	{
	  LEX *lex=Lex;
6029 6030
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
6031
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6032 6033 6034

/* import, export of files */

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6035
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6036
	{
6037 6038
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
6039 6040
	  lex->lock_option= $3;
	  lex->local_file=  $4;
6041
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6042
	    YYABORT;
6043
	  lex->field_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6044 6045 6046 6047
	}
	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
6048
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6049 6050 6051
	    YYABORT;
	}
        |
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6052
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6053 6054
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6055
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6056
	    YYABORT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6057 6058

        }
6059 6060 6061 6062
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
6063
        };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6064 6065 6066

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

6069
load_data_lock:
6070
	/* empty */	{ $$= YYTHD->update_lock_default; }
6071 6072
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
6073 6074


bk@work.mysql.com's avatar
bk@work.mysql.com committed
6075 6076 6077
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
6078
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6079 6080 6081

opt_field_term:
	/* empty */
6082
	| COLUMNS field_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6083 6084 6085

field_term_list:
	field_term_list field_term
6086
	| field_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6087 6088 6089 6090

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
6091 6092 6093 6094 6095
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6096
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
6097
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6098 6099 6100

opt_line_term:
	/* empty */
6101
	| LINES line_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6102 6103 6104

line_term_list:
	line_term_list line_term
6105
	| line_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6106 6107 6108

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
6109
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6110 6111 6112 6113

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
6114
	  { Lex->exchange->skip_lines=atol($2.str); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6115 6116 6117 6118

/* Common definitions */

text_literal:
6119
	TEXT_STRING_literal
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6120 6121
	{
	  THD *thd= YYTHD;
6122
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6123
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6124
	| NCHAR_STRING
6125
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
6126
	| UNDERSCORE_CHARSET TEXT_STRING
6127
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
6128
	| text_literal TEXT_STRING_literal
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6129 6130
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6131 6132

text_string:
6133
	TEXT_STRING_literal
monty@mysql.com's avatar
monty@mysql.com committed
6134
	{ $$=  new (&YYTHD->mem_root) String($1.str,$1.length,YYTHD->variables.collation_connection); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6135 6136
	| HEX_NUM
	  {
6137
	    Item *tmp = new Item_varbinary($1.str,$1.length);
6138
	    /*
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6139
	      it is OK only emulate fix_fieds, because we need only
6140 6141 6142
              value of constant
	    */
	    $$= tmp ?
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6143
	      tmp->quick_fix_field(), tmp->val_str((String*) 0) :
6144
	      (String*) 0;
6145 6146 6147
	  }
	;

6148
param_marker:
6149
        '?'
6150
        {
6151 6152 6153
          THD *thd=YYTHD;
	  LEX *lex= thd->lex;
          if (thd->command == COM_PREPARE)
6154
          {
6155 6156 6157 6158 6159 6160 6161
            Item_param *item= new Item_param((uint) (lex->tok_start -
                                                     (uchar *) thd->query));
            if (!($$= item) || lex->param_list.push_back(item))
            {
	      send_error(thd, ER_OUT_OF_RESOURCES);
	      YYABORT;
            }
6162
          }
6163
          else
6164
          {
6165
            yyerror(ER(ER_SYNTAX_ERROR));
6166 6167
            YYABORT;
          }
6168 6169 6170
        }
	;

6171 6172 6173
signed_literal:
	literal		{ $$ = $1; }
	| '+' NUM_literal { $$ = $2; }
6174 6175
	| '-' NUM_literal
	  {
6176
	    $2->max_length++;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6177
	    $$= $2->neg();
6178
	  }
6179 6180 6181
	;


bk@work.mysql.com's avatar
bk@work.mysql.com committed
6182 6183
literal:
	text_literal	{ $$ =	$1; }
6184
	| NUM_literal	{ $$ = $1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6185
	| NULL_SYM	{ $$ =	new Item_null();
6186
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
6187
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
6188
	| UNDERSCORE_CHARSET HEX_NUM
6189
	  {
6190
	    Item *tmp= new Item_varbinary($2.str,$2.length);
6191
	    /*
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6192
	      it is OK only emulate fix_fieds, because we need only
6193 6194 6195
              value of constant
	    */
	    String *str= tmp ?
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6196
	      tmp->quick_fix_field(), tmp->val_str((String*) 0) :
6197
	      (String*) 0;
6198 6199 6200
	    $$= new Item_string(str ? str->ptr() : "",
				str ? str->length() : 0,
				Lex->charset);
6201
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6202 6203
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
6204
	| TIMESTAMP text_literal { $$ = $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6205

6206
NUM_literal:
6207 6208
	NUM		{ int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
	| LONG_NUM	{ int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
6209 6210 6211 6212 6213
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	;
	
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6214 6215 6216 6217 6218
/**********************************************************************
** Createing different items.
**********************************************************************/

insert_ident:
6219
	simple_ident_nospvar { $$=$1; }
6220
	| table_wild	 { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6221 6222

table_wild:
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6223
	ident '.' '*'
6224 6225
	{
	  $$ = new Item_field(NullS,$1.str,"*");
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6226
	  Lex->current_select->with_wild++;
6227
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6228
	| ident '.' ident '.' '*'
6229 6230 6231 6232
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6233
	  Lex->current_select->with_wild++;
6234 6235
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6236 6237

order_ident:
6238
	expr { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6239 6240 6241

simple_ident:
	ident
6242
	{
6243 6244 6245 6246 6247 6248 6249 6250
	  sp_pvar_t *spv;
	  LEX *lex = Lex;
          sp_pcontext *spc = lex->spcont;

	  if (spc && (spv = spc->find_pvar(&$1)))
	  { /* We're compiling a stored procedure and found a variable */
	    if (lex->sql_command != SQLCOM_CALL && ! spv->isset)
	    {
6251 6252 6253
	      push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
	                          ER_SP_UNINIT_VAR, ER(ER_SP_UNINIT_VAR),
				  $1.str);
6254
	    }
6255
	    $$ = (Item*) new Item_splocal($1, spv->offset);
6256 6257 6258
	  }
	  else
	  {
pem@mysql.com's avatar
pem@mysql.com committed
6259
	    SELECT_LEX *sel=Select;
6260 6261 6262
	    $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	         sel->get_in_sum_expr() > 0) ?
                 (Item*) new Item_field(NullS,NullS,$1.str) :
pem@mysql.com's avatar
pem@mysql.com committed
6263
	         (Item*) new Item_ref(0,0, NullS,NullS,$1.str);
6264
	  }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
6265
        }
6266 6267 6268 6269 6270 6271 6272 6273 6274 6275
        | simple_ident_q { $$= $1; }
	;

simple_ident_nospvar:
	ident
	{
	  SELECT_LEX *sel=Select;
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
              (Item*) new Item_field(NullS,NullS,$1.str) :
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
6276
	      (Item*) new Item_ref(0,0,NullS,NullS,$1.str);
6277 6278 6279 6280 6281 6282
	}
	| simple_ident_q { $$= $1; }
	;	

simple_ident_q:
	ident '.' ident
6283
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6284
	  THD *thd= YYTHD;
6285
	  LEX *lex= thd->lex;
6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349
         
          /*
            FIXME This will work ok in simple_ident_nospvar case because
            we can't meet simple_ident_nospvar in trigger now. But it
            should be changed in future.
          */
          if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_TRIGGER &&
              (!my_strcasecmp(system_charset_info, $1.str, "NEW") || 
               !my_strcasecmp(system_charset_info, $1.str, "OLD")))
          {
            bool new_row= ($1.str[0]=='N' || $1.str[0]=='n');
            
            if (lex->trg_chistics.event == TRG_EVENT_INSERT &&
                !new_row)
            {
              net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "OLD",
                         "on INSERT");
              YYABORT;
            }
            
            if (lex->trg_chistics.event == TRG_EVENT_DELETE &&
                new_row)
            {
              net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW",
                         "on DELETE");
              YYABORT;
            }
            
            Item_trigger_field *trg_fld= 
              new Item_trigger_field(new_row ? Item_trigger_field::NEW_ROW :
                                               Item_trigger_field::OLD_ROW,
                                               $3.str);
            
            if (lex->trg_table &&
                trg_fld->setup_field(thd, lex->trg_table,
                                     lex->trg_chistics.event))
            {
              /*
                FIXME. Far from perfect solution. See comment for 
                "SET NEW.field_name:=..." for more info.
              */
              net_printf(YYTHD, ER_BAD_FIELD_ERROR, $3.str,
                         new_row ? "NEW": "OLD");
              YYABORT;
            }
            
            $$= (Item *)trg_fld;
          }
          else
          {
            SELECT_LEX *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);
            }
            $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
                 sel->get_in_sum_expr() > 0) ?
                (Item*) new Item_field(NullS,$1.str,$3.str) :
                (Item*) new Item_ref(0,0,NullS,$1.str,$3.str);
          }
        }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6350
	| '.' ident '.' ident
6351
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6352
	  THD *thd= YYTHD;
6353
	  LEX *lex= thd->lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6354
	  SELECT_LEX *sel= lex->current_select;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6355 6356
	  if (sel->no_table_names_allowed)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6357
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6358 6359 6360
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
6361 6362 6363
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$2.str,$4.str) :
hf@deer.(none)'s avatar
hf@deer.(none) committed
6364
              (Item*) new Item_ref(0,0,NullS,$2.str,$4.str);
6365
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6366
	| ident '.' ident '.' ident
6367
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6368
	  THD *thd= YYTHD;
6369
	  LEX *lex= thd->lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6370
	  SELECT_LEX *sel= lex->current_select;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6371 6372
	  if (sel->no_table_names_allowed)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6373
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6374 6375 6376
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
6377 6378 6379 6380 6381
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field((YYTHD->client_capabilities &
				      CLIENT_NO_SCHEMA ? NullS : $1.str),
				     $3.str, $5.str) :
hf@deer.(none)'s avatar
hf@deer.(none) committed
6382 6383
	      (Item*) new Item_ref(0,0,(YYTHD->client_capabilities &
				        CLIENT_NO_SCHEMA ? NullS : $1.str),
6384
                                   $3.str, $5.str);
6385
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6386 6387 6388 6389


field_ident:
	ident			{ $$=$1;}
6390
	| ident '.' ident	{ $$=$3;}	/* Skip schema name in create*/
6391
	| '.' ident		{ $$=$2;}	/* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6392 6393 6394

table_ident:
	ident			{ $$=new Table_ident($1); }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6395
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
6396 6397 6398
	| '.' ident		{ $$=new Table_ident($2);} /* For Delphi */
        ;

serg@serg.mylan's avatar
serg@serg.mylan committed
6399
table_ident_nodb:
monty@mysql.com's avatar
monty@mysql.com committed
6400
	ident			{ LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); }
6401
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6402

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6403
IDENT_sys:
6404 6405 6406 6407 6408
	IDENT { $$= $1; }
	| IDENT_QUOTED
	  {
	    THD *thd= YYTHD;
	    if (thd->charset_is_system_charset)
6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419
            {
              CHARSET_INFO *cs= system_charset_info;
              uint wlen= cs->cset->well_formed_len(cs, $1.str,
                                                   $1.str+$1.length,
                                                   $1.length);
              if (wlen < $1.length)
              {
                net_printf(YYTHD, ER_INVALID_CHARACTER_STRING, cs->csname,
                           $1.str + wlen);
                YYABORT;
              }
6420
	      $$= $1;
6421
            }
6422 6423 6424 6425
	    else
	      thd->convert_string(&$$, system_charset_info,
				  $1.str, $1.length, thd->charset());
	  }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6426 6427 6428 6429 6430 6431
	;

TEXT_STRING_sys:
	TEXT_STRING
	{
	  THD *thd= YYTHD;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6432 6433
	  if (thd->charset_is_system_charset)
	    $$= $1;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6434
	  else
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6435 6436
	    thd->convert_string(&$$, system_charset_info,
				$1.str, $1.length, thd->charset());
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6437 6438 6439
	}
	;

6440
TEXT_STRING_literal:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6441 6442 6443
	TEXT_STRING
	{
	  THD *thd= YYTHD;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6444 6445
	  if (thd->charset_is_collation_connection)
	    $$= $1;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6446
	  else
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6447 6448
	    thd->convert_string(&$$, thd->variables.collation_connection,
				$1.str, $1.length, thd->charset());
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6449 6450 6451 6452
	}
	;


bk@work.mysql.com's avatar
bk@work.mysql.com committed
6453
ident:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6454
	IDENT_sys	    { $$=$1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6455 6456
	| keyword
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6457 6458 6459
	  THD *thd= YYTHD;
	  $$.str=    thd->strmake($1.str, $1.length);
	  $$.length= $1.length;
6460 6461
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6462 6463

ident_or_text:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6464 6465 6466
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6467 6468 6469 6470

user:
	ident_or_text
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6471 6472
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6473
	    YYABORT;
6474 6475 6476 6477
	  $$->user = $1;
	  $$->host.str= (char *) "%";
	  $$->host.length= 1;
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6478 6479
	| ident_or_text '@' ident_or_text
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6480 6481
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6482 6483
	      YYABORT;
	    $$->user = $1; $$->host=$3;
6484
	  }
6485
	| CURRENT_USER optional_braces
6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502
	{
          THD *thd= YYTHD;
          if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
            YYABORT;
          $$->user.str= thd->priv_user;
          $$->user.length= strlen(thd->priv_user);
          if (*thd->priv_host != 0)
          {
            $$->host.str= thd->priv_host;
            $$->host.length= strlen(thd->priv_host);
          }
          else
          {
            $$->host.str= (char *) "%";
            $$->host.length= 1;
          }
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6503 6504 6505 6506 6507

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
6508
	| ADDDATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6509
	| AFTER_SYM		{}
6510
	| AGAINST		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6511
	| AGGREGATE_SYM		{}
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
6512
	| ALGORITHM_SYM		{}
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6513
	| ANY_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6514
	| ASCII_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6515
	| AUTO_INC		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6516 6517
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
6518
	| BACKUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6519
	| BEGIN_SYM		{}
6520
	| BERKELEY_DB_SYM	{}
6521
	| BINLOG_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6522 6523
	| BIT_SYM		{}
	| BOOL_SYM		{}
6524
	| BOOLEAN_SYM		{}
6525
	| BYTE_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6526
	| BTREE_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6527
	| CACHE_SYM		{}
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
6528
	| CASCADED              {}
6529
	| CHANGED		{}
6530
	| CHARSET		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6531
	| CHECKSUM_SYM		{}
6532
	| CIPHER_SYM		{}
6533
	| CLIENT_SYM		{}
6534
	| CLOSE_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6535
	| COLLATION_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6536
	| COMMENT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6537
	| COMMITTED_SYM		{}
6538
	| COMMIT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6539
	| COMPRESSED_SYM	{}
6540
	| CONCURRENT		{}
6541
	| CUBE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6542 6543 6544 6545
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
sergefp@mysql.com's avatar
sergefp@mysql.com committed
6546
        | DEALLOCATE_SYM        {}
6547
	| DEFINER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6548
	| DELAY_KEY_WRITE_SYM	{}
6549 6550
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6551
	| DISCARD		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6552
	| DO_SYM		{}
6553 6554
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6555 6556 6557
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
6558
	| ENGINE_SYM		{}
6559
	| ENGINES_SYM		{}
6560
	| ERRORS		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6561
	| ESCAPE_SYM		{}
6562
	| EVENTS_SYM		{}
6563
	| EXECUTE_SYM		{}
6564
        | EXPANSION_SYM         {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6565
	| EXTENDED_SYM		{}
6566
	| FAST_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6567 6568
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6569
	| FULL			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6570 6571 6572 6573
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
6574
	| GEOMETRY_SYM		{}
6575
	| GEOMETRYCOLLECTION	{}
6576
	| GET_FORMAT		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6577
	| GRANTS		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6578
	| GLOBAL_SYM		{}
6579
	| HANDLER_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6580
	| HASH_SYM		{}
6581
	| HELP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6582 6583 6584
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
6585
	| INVOKER_SYM		{}
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6586
	| IMPORT		{}
6587
	| INDEXES		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6588
	| ISOLATION		{}
6589
	| ISSUER_SYM		{}
6590
	| INNOBASE_SYM		{}
6591
	| INSERT_METHOD		{}
6592
	| RELAY_THREAD		{}
6593
	| LANGUAGE_SYM          {}
6594
	| LAST_SYM		{}
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
6595
	| LEAVES                {}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6596
	| LEVEL_SYM		{}
6597
	| LINESTRING		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6598
	| LOCAL_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6599
	| LOCKS_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6600 6601 6602 6603 6604 6605 6606 6607 6608
	| 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	{}
6609
	| MASTER_SERVER_ID_SYM  {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6610
	| MASTER_CONNECT_RETRY_SYM	{}
6611 6612 6613 6614 6615 6616
	| MASTER_SSL_SYM	{}
	| MASTER_SSL_CA_SYM	{}
	| MASTER_SSL_CAPATH_SYM	{}
	| MASTER_SSL_CERT_SYM	{}
	| MASTER_SSL_CIPHER_SYM	{}
	| MASTER_SSL_KEY_SYM	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6617 6618 6619
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
6620
	| MEDIUM_SYM		{}
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
6621
	| MERGE_SYM		{}
6622
	| MICROSECOND_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6623 6624 6625
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6626
	| MODE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6627
	| MONTH_SYM		{}
6628 6629 6630
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
6631
	| NAME_SYM              {}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6632
	| NAMES_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6633 6634
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
6635
	| NDBCLUSTER_SYM	{}
6636
	| NEXT_SYM		{}
6637
	| NEW_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6638
	| NO_SYM		{}
6639
	| NONE_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6640
	| NVARCHAR_SYM		{}
6641
	| OFFSET_SYM		{}
6642
	| OLD_PASSWORD		{}
6643
	| ONE_SHOT_SYM		{}
6644
	| OPEN_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6645
	| PACK_KEYS_SYM		{}
6646
	| PARTIAL		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6647
	| PASSWORD		{}
6648
	| POINT_SYM		{}
6649
	| POLYGON		{}
sergefp@mysql.com's avatar
sergefp@mysql.com committed
6650
        | PREPARE_SYM           {}
6651
	| PREV_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6652 6653
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
6654
	| QUARTER_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6655
	| QUERY_SYM		{}
6656
	| QUICK			{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6657
	| RAID_0_SYM		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6658 6659
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6660
	| RAID_STRIPED_SYM	{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6661
	| RAID_TYPE		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6662 6663
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6664 6665
	| RELOAD		{}
	| REPAIR		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6666
	| REPEATABLE_SYM	{}
6667
	| REPLICATION		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6668
	| RESET_SYM		{}
6669
	| RESOURCES		{}
6670
	| RESTORE_SYM		{}
6671
	| RETURNS_SYM           {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6672
	| ROLLBACK_SYM		{}
6673
	| ROLLUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6674 6675 6676
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6677
	| RTREE_SYM		{}
6678
	| SAVEPOINT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6679
	| SECOND_SYM		{}
6680
	| SECURITY_SYM		{}
6681
	| SERIAL_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6682 6683
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6684
	| SIGNED_SYM		{}
6685
	| SIMPLE_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6686
	| SHARE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6687
	| SHUTDOWN		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6688
	| SLAVE			{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6689
	| SOUNDS_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6690
	| SQL_CACHE_SYM		{}
6691
	| SQL_BUFFER_RESULT	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6692
	| SQL_NO_CACHE_SYM	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6693
	| SQL_THREAD		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6694 6695 6696
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
6697
	| STORAGE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6698
	| STRING_SYM		{}
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
6699
	| SUBDATE_SYM		{}
6700
	| SUBJECT_SYM		{}
6701
	| SUPER_SYM		{}
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6702
	| TABLESPACE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6703
	| TEMPORARY		{}
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
6704
	| TEMPTABLE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6705
	| TEXT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6706
	| TRANSACTION_SYM	{}
6707
	| TRUNCATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6708
	| TIMESTAMP		{}
6709 6710
	| TIMESTAMP_ADD		{}
	| TIMESTAMP_DIFF	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6711 6712
	| TIME_SYM		{}
	| TYPE_SYM		{}
6713
	| TYPES_SYM		{}
6714
	| FUNCTION_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6715
	| UNCOMMITTED_SYM	{}
6716
	| UNICODE_SYM		{}
6717
	| UNTIL_SYM		{}
6718
	| USER			{}
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6719
	| USE_FRM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6720
	| VARIABLES		{}
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
6721
	| VIEW_SYM		{}
6722
	| VALUE_SYM		{}
6723
	| WARNINGS		{}
6724
	| WEEK_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6725
	| WORK_SYM		{}
6726
	| X509_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6727 6728
	| YEAR_SYM		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6729 6730 6731 6732 6733 6734

/* Option functions */

set:
	SET opt_option
	{
6735 6736
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
6737
	  lex->option_type=OPT_SESSION;
6738
	  lex->var_list.empty();
6739
          lex->one_shot_set= 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6740
	}
6741 6742 6743
	option_value_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6744 6745 6746

opt_option:
	/* empty */ {}
6747
	| OPTION {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6748 6749

option_value_list:
6750 6751 6752 6753 6754 6755 6756 6757
	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; }
6758
	| ONE_SHOT_SYM	{ Lex->option_type= OPT_SESSION; Lex->one_shot_set= 1; }
6759 6760 6761 6762
	;

opt_var_type:
	/* empty */	{ $$=OPT_SESSION; }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6763
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
6764 6765 6766 6767 6768 6769
	| 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
6770
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
6771 6772 6773
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6774 6775

option_value:
6776
	  '@' ident_or_text equal expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6777
	  {
6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794
            LEX *lex= Lex;

            if (lex->sphead && lex->sphead->m_type != TYPE_ENUM_PROCEDURE)
            {
              /*
                We have to use special instruction in functions and triggers
                because sp_instr_stmt will close all tables and thus ruin
                execution of statement invoking function or trigger.
              */
              sp_instr_set_user_var *i= 
                new sp_instr_set_user_var(lex->sphead->instructions(), 
                                          $2, $4);
	      lex->sphead->add_instr(i);
            }
            else
              lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
              
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6795
	  }
6796
	| internal_variable_name equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6797
	  {
6798
	    LEX *lex=Lex;
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6799

6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845
            if ($1.var == &trg_new_row_fake_var)
            {
              /* We are in trigger and assigning value to field of new row */
              Item *it;
              sp_instr_set_trigger_field *i;
              if ($3 && $3->type() == Item::SUBSELECT_ITEM)
              {  /*
                   QQ For now, just disallow subselects as values
                   Unfortunately this doesn't helps in case when we have
                   subselect deeper in expression.
                 */
                send_error(YYTHD, ER_SP_SUBSELECT_NYI);
                YYABORT;
              }
              if ($3)
                it= $3;
              else
              {
                /* QQ: Shouldn't this be field's default value ? */
                it= new Item_null();
              }
              i= new sp_instr_set_trigger_field(lex->sphead->instructions(),
                                                $1.base_name, it);
              if (lex->trg_table && i->setup_field(YYTHD, lex->trg_table,
                                                   lex->trg_chistics.event))
              {
                /*
                  FIXME. Now we are catching this kind of errors only
                  during opening tables. But this doesn't save us from most
                  common user error - misspelling field name, because we
                  will bark too late in this case... Moreover it is easy to
                  make table unusable with such kind of error...

                  So in future we either have to parse trigger definition
                  second time during create trigger or gather all trigger
                  fields in one list and perform setup_field() for them as
                  separate stage.

                  Error message also should be improved.
                */
                net_printf(YYTHD, ER_BAD_FIELD_ERROR, $1.base_name, "NEW");
                YYABORT;
              }
              lex->sphead->add_instr(i);
            }
            else if ($1.var)
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6846 6847 6848 6849 6850 6851
	    { /* System variable */
	      lex->var_list.push_back(new set_var(lex->option_type, $1.var,
						  &$1.base_name, $3));
	    }
            else
	    { /* An SP local variable */
6852 6853 6854 6855
	      sp_pvar_t *spv;
              sp_instr_set *i;
	      Item *it;

6856 6857 6858 6859 6860
	      if ($3 && $3->type() == Item::SUBSELECT_ITEM)
	      {  /* QQ For now, just disallow subselects as values */
	        send_error(lex->thd, ER_SP_SUBSELECT_NYI);
	        YYABORT;
	      }
6861
	      spv= lex->spcont->find_pvar(&$1.base_name);
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6862

6863 6864 6865 6866 6867 6868 6869 6870
	      if ($3)
	        it= $3;
	      else if (spv->dflt)
	        it= spv->dflt;
	      else
	        it= new Item_null();
              i= new sp_instr_set(lex->sphead->instructions(),
	                          spv->offset, it, spv->type);
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6871 6872 6873
	      lex->sphead->add_instr(i);
	      spv->isset= TRUE;
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6874
	  }
6875
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6876 6877
	  {
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6878 6879
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4.var,
						&$4.base_name, $6));
6880 6881 6882 6883
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6884 6885 6886
	    LEX_STRING tmp;
	    tmp.str=0;
	    tmp.length=0;
6887
	    lex->var_list.push_back(new set_var(lex->option_type,
6888
						find_sys_var("tx_isolation"),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6889
						&tmp,
6890
						new Item_int((int32) $4)));
6891
	  }
6892
	| charset old_or_new_charset_name_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6893
	{
6894
	  THD *thd= YYTHD;
6895
	  LEX *lex= Lex;
6896
	  $2= $2 ? $2: global_system_variables.character_set_client;
6897
	  lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6898
	}
6899
	| NAMES_SYM charset_name_or_default opt_collate
6900
	{
6901
	  THD *thd= YYTHD;
6902
	  LEX *lex= Lex;
6903
	  $2= $2 ? $2 : global_system_variables.character_set_client;
6904 6905
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
6906
	  {
6907 6908
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
6909
	  }
6910
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
6911
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6912
	| PASSWORD equal text_or_password
6913
	  {
6914
	    THD *thd=YYTHD;
6915
	    LEX_USER *user;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6916
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
6917 6918 6919
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
6920
	    thd->lex->var_list.push_back(new set_var_password(user, $3));
6921 6922
	  }
	| PASSWORD FOR_SYM user equal text_or_password
6923
	  {
6924 6925
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
6926
	;
6927

6928 6929 6930
internal_variable_name:
	ident
	{
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949
	  LEX *lex= Lex;
          sp_pcontext *spc= lex->spcont;
	  sp_pvar_t *spv;

	  /* We have to lookup here since local vars can shadow sysvars */
	  if (!spc || !(spv = spc->find_pvar(&$1)))
	  { /* Not an SP local variable */
	    sys_var *tmp=find_sys_var($1.str, $1.length);
	    if (!tmp)
	      YYABORT;
	    $$.var= tmp;
	    $$.base_name.str=0;
	    $$.base_name.length=0;
	  }
	  else
	  { /* An SP local variable */
	    $$.var= NULL;
	    $$.base_name= $1;
	  }
6950
	}
6951 6952
	| ident '.' ident
	  {
6953
            LEX *lex= Lex;
6954 6955
            if (check_reserved_words(&$1))
            {
6956
	      yyerror(ER(ER_SYNTAX_ERROR));
6957 6958
              YYABORT;
            }
6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992
            if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_TRIGGER &&
                (!my_strcasecmp(system_charset_info, $1.str, "NEW") || 
                 !my_strcasecmp(system_charset_info, $1.str, "OLD")))
            {
              if ($1.str[0]=='O' || $1.str[0]=='o')
              {
                net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "OLD", "");
                YYABORT;
              }
              if (lex->trg_chistics.event == TRG_EVENT_DELETE)
              {
                net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW",
                           "on DELETE");
                YYABORT;
              }
              if (lex->trg_chistics.action_time == TRG_ACTION_AFTER)
              {
                net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "NEW", "after ");
                YYABORT;
              }
              /* This special combination will denote field of NEW row */
              $$.var= &trg_new_row_fake_var;
              $$.base_name= $3;
            }
            else
            {
              sys_var *tmp=find_sys_var($3.str, $3.length);
              if (!tmp)
                YYABORT;
              if (!tmp->is_struct())
                net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str);
              $$.var= tmp;
              $$.base_name= $1;
            }
6993 6994 6995 6996 6997 6998 6999 7000
	  }
	| DEFAULT '.' ident
	  {
	    sys_var *tmp=find_sys_var($3.str, $3.length);
	    if (!tmp)
	      YYABORT;
	    if (!tmp->is_struct())
	      net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7001 7002 7003
	    $$.var= tmp;
	    $$.base_name.str=    (char*) "default";
	    $$.base_name.length= 7;
7004
	  }
7005
        ;
7006 7007 7008 7009 7010 7011 7012

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
7014 7015 7016 7017
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
7018
	    $$= $3.length ? YYTHD->variables.old_passwords ?
7019 7020 7021 7022 7023 7024 7025 7026
	        Item_func_old_password::alloc(YYTHD, $3.str) :
	        Item_func_password::alloc(YYTHD, $3.str) :
	      $3.str;
	  }
	| OLD_PASSWORD '(' TEXT_STRING ')'
	  {
	    $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str) :
	      $3.str;
7027 7028
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7029

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

7031
set_expr_or_default:
7032 7033
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
7034 7035
	| 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
7036
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
7037
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
7038 7039


bk@work.mysql.com's avatar
bk@work.mysql.com committed
7040 7041 7042 7043 7044 7045 7046
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
7047 7048 7049
	table_lock_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7050 7051 7052

table_or_tables:
	TABLE_SYM
7053
	| TABLES;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7054 7055 7056

table_lock_list:
	table_lock
7057
	| table_lock_list ',' table_lock;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7058 7059 7060

table_lock:
	table_ident opt_table_alias lock_option
7061
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7062
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
7063 7064
	   YYABORT;
	}
7065
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7066 7067 7068

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
7069
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7070
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
7071 7072
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7073 7074

unlock:
7075 7076
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7077 7078


7079
/*
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
7080
** Handler: direct access to ISAM functions
7081 7082 7083 7084 7085
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
7086 7087
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7088
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
7089 7090
	    YYABORT;
	}
serg@serg.mylan's avatar
serg@serg.mylan committed
7091
	| HANDLER_SYM table_ident_nodb CLOSE_SYM
7092
	{
7093 7094
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7095
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
7096 7097
	    YYABORT;
	}
serg@serg.mylan's avatar
serg@serg.mylan committed
7098
	| HANDLER_SYM table_ident_nodb READ_SYM
7099
	{
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
7100 7101 7102
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
7103 7104
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7105
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
7106
	    YYABORT;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
7107
        }
7108
        handler_read_or_scan where_clause opt_limit_clause {}
7109
        ;
7110

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
7111 7112
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
7113 7114
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
7115 7116 7117

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
7118 7119
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
7120 7121 7122 7123 7124 7125

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;  }
7126 7127
	| handler_rkey_mode
	{
7128 7129
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
7130
	  lex->ha_rkey_mode=$1;
7131
	  if (!(lex->insert_list = new List_item))
7132
	    YYABORT;
7133 7134
	} '(' values ')' { }
        ;
7135 7136

handler_rkey_mode:
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
7137 7138 7139 7140
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
7141 7142
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
7143

bk@work.mysql.com's avatar
bk@work.mysql.com committed
7144 7145 7146 7147 7148
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
7149 7150 7151 7152 7153
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
7154
	  lex->select_lex.db=0;
7155 7156
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
7157
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7158
	}
7159 7160 7161 7162 7163
	revoke_command
	{}
        ;

revoke_command:
7164 7165
	grant_privileges ON opt_table FROM user_list
	{}
7166
	|
7167
	ALL PRIVILEGES ',' GRANT OPTION FROM user_list
7168 7169 7170
	{
	  Lex->sql_command = SQLCOM_REVOKE_ALL;
	}
7171
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7172 7173 7174 7175

grant:
	GRANT
	{
7176 7177 7178
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
7179 7180
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
7181
	  lex->select_lex.db= 0;
7182 7183
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
7184
	  bzero((char *)&(lex->mqh),sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7185 7186
	}
	grant_privileges ON opt_table TO_SYM user_list
7187 7188 7189
	require_clause grant_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7190 7191 7192

grant_privileges:
	grant_privilege_list {}
7193
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
7194 7195
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7196 7197 7198

grant_privilege_list:
	grant_privilege
7199
	| grant_privilege_list ',' grant_privilege;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7200 7201

grant_privilege:
serg@serg.mylan's avatar
serg@serg.mylan committed
7202
	SELECT_SYM	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
7203 7204 7205
	| 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 {}
7206 7207
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
7208
	| INDEX_SYM	{ Lex->grant |= INDEX_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7209 7210 7211
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
7212
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7213 7214 7215 7216
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
7217 7218 7219 7220 7221
	| 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; }
bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
7222 7223 7224 7225
	| REPLICATION SLAVE  { Lex->grant |= REPL_SLAVE_ACL; }
	| REPLICATION CLIENT_SYM { Lex->grant |= REPL_CLIENT_ACL; }
	| CREATE VIEW_SYM { Lex->grant |= CREATE_VIEW_ACL; }
	| SHOW VIEW_SYM { Lex->grant |= SHOW_VIEW_ACL; }
7226
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7227

7228

7229 7230
opt_and:
	/* empty */	{}
7231
	| AND_SYM	{}
7232 7233 7234 7235 7236 7237 7238 7239 7240
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
7241 7242 7243 7244
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
7245
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
7246 7247 7248 7249 7250 7251 7252 7253 7254
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
7255
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
7256 7257 7258 7259 7260 7261 7262 7263 7264
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
7265
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
7266 7267 7268 7269 7270
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
7271

bk@work.mysql.com's avatar
bk@work.mysql.com committed
7272 7273 7274
opt_table:
	'*'
	  {
7275
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7276
	    lex->current_select->db= lex->thd->db;
7277
	    if (lex->grant == GLOBAL_ACLS)
7278 7279
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7280
	    {
7281
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
7282
	      YYABORT;
7283
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7284 7285 7286
	  }
	| ident '.' '*'
	  {
7287
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7288
	    lex->current_select->db = $1.str;
7289
	    if (lex->grant == GLOBAL_ACLS)
7290 7291
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7292
	    {
7293
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7294 7295 7296 7297 7298
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
7299
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7300
	    lex->current_select->db = NULL;
7301 7302
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
7303
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7304
	    {
7305
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7306 7307 7308 7309 7310
	      YYABORT;
	    }
	  }
	| table_ident
	  {
7311
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7312
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7313
	      YYABORT;
7314
	    if (lex->grant == GLOBAL_ACLS)
7315
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
7316 7317
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7318 7319 7320


user_list:
7321 7322 7323 7324 7325 7326 7327
	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
7328 7329 7330 7331 7332 7333 7334 7335


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
7336
             if (YYTHD->variables.old_passwords)
7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353
             {
               char *buff= 
                 (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
               if (buff)
                 make_scrambled_password_323(buff, $4.str);
               $1->password.str= buff;
               $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
             }
             else
             {
               char *buff= 
                 (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
               if (buff)
                 make_scrambled_password(buff, $4.str);
               $1->password.str= buff;
               $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH;
             }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7354 7355 7356 7357 7358
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
7359 7360
	  { $$=$1; $1->password.str=NullS; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7361 7362 7363


opt_column_list:
7364 7365 7366 7367 7368
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
7369
	| '(' column_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7370 7371 7372

column_list:
	column_list ',' column_list_id
7373
	| column_list_id;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7374 7375 7376 7377

column_list_id:
	ident
	{
monty@mysql.com's avatar
monty@mysql.com committed
7378
	  String *new_str = new (&YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7379 7380
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
7381
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7382 7383
	  while ((point=iter++))
	  {
7384 7385
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7386 7387
		break;
	  }
7388
	  lex->grant_tot_col|= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7389
	  if (point)
7390
	    point->rights |= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7391
	  else
7392
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
7393 7394
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7395

tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
7396 7397

require_clause: /* empty */
7398
        | REQUIRE_SYM require_list
7399 7400 7401
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
7402
        | REQUIRE_SYM SSL_SYM
7403 7404 7405
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
7406
        | REQUIRE_SYM X509_SYM
7407 7408 7409 7410 7411 7412 7413
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
7414
          ;
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
7415

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
7416
grant_options:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7417
	/* empty */ {}
7418
	| WITH grant_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7419

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
7420 7421
grant_option_list:
	grant_option_list grant_option {}
7422 7423
	| grant_option {}
        ;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
7424 7425 7426

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
7427
        | MAX_QUERIES_PER_HOUR ULONG_NUM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
7428
        {
7429
	  Lex->mqh.questions=$2;
7430
	  Lex->mqh.bits |= 1;
7431
	}
7432
        | MAX_UPDATES_PER_HOUR ULONG_NUM
7433
        {
7434
	  Lex->mqh.updates=$2;
7435
	  Lex->mqh.bits |= 2;
7436
	}
7437
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
7438
        {
7439
	  Lex->mqh.connections=$2;
7440
	  Lex->mqh.bits |= 4;
7441 7442
	}
        ;
7443

bk@work.mysql.com's avatar
bk@work.mysql.com committed
7444
begin:
7445 7446
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7447 7448 7449

opt_work:
	/* empty */ {}
7450 7451
	| WORK_SYM {;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7452 7453

commit:
7454
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
7455 7456

rollback:
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
7457
	ROLLBACK_SYM
7458 7459 7460 7461 7462
	{
	  Lex->sql_command = SQLCOM_ROLLBACK;
	}
	| ROLLBACK_SYM TO_SYM SAVEPOINT_SYM ident
	{
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
7463
	  Lex->sql_command = SQLCOM_ROLLBACK_TO_SAVEPOINT;
7464 7465 7466 7467 7468 7469 7470 7471
	  Lex->savepoint_name = $4.str;
	};
savepoint:
	SAVEPOINT_SYM ident
	{
	  Lex->sql_command = SQLCOM_SAVEPOINT;
	  Lex->savepoint_name = $2.str;
	};
7472 7473

/*
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7474
   UNIONS : glue selects together
7475 7476 7477
*/


7478
union_clause:
7479
	/* empty */ {}
7480 7481
	| union_list
	;
7482 7483

union_list:
7484
	UNION_SYM union_option
7485 7486 7487 7488 7489
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
7490
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
7491
	    YYABORT;
7492
	  }
7493
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
7494
	  {
7495
            yyerror(ER(ER_SYNTAX_ERROR));
7496 7497
	    YYABORT;
	  }
7498
	  if (mysql_new_select(lex, 0))
7499
	    YYABORT;
7500
          mysql_init_select(lex);
7501
	  lex->current_select->linkage=UNION_TYPE;
7502 7503 7504
          if ($2) /* UNION DISTINCT - remember position */
            lex->current_select->master_unit()->union_distinct=
                                                      lex->current_select;
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7505
	}
7506
	select_init {}
7507
	;
7508 7509

union_opt:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
7510
	union_list {}
7511 7512
	| optional_order_or_limit {}
	;
7513 7514

optional_order_or_limit:
7515
	/* Empty */ {}
7516 7517
	|
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7518
	    THD *thd= YYTHD;
7519
	    LEX *lex= thd->lex;
7520
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7521
	    SELECT_LEX *sel= lex->current_select;
7522
	    SELECT_LEX_UNIT *unit= sel->master_unit();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7523
	    SELECT_LEX *fake= unit->fake_select_lex;
7524 7525 7526 7527 7528 7529
	    if (fake)
	    {
	      unit->global_parameters= fake;
	      fake->no_table_names_allowed= 1;
	      lex->current_select= fake;
	    }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7530
	    thd->where= "global ORDER clause";
7531
	  }
7532
	order_or_limit
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7533 7534
          {
	    THD *thd= YYTHD;
7535
	    thd->lex->current_select->no_table_names_allowed= 0;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7536 7537
	    thd->where= "";
          }
7538 7539 7540
	;

order_or_limit:
7541 7542
	order_clause opt_limit_clause_init
	| limit_clause
7543
	;
7544 7545

union_option:
7546 7547 7548 7549
	/* empty */ { $$=1; }
	| DISTINCT  { $$=1; }
	| ALL       { $$=0; }
        ;
7550

7551 7552
singlerow_subselect:
	subselect_start singlerow_subselect_init
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7553 7554 7555 7556
	subselect_end
	{
	  $$= $2;
	};
7557

7558
singlerow_subselect_init:
7559
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7560
	{
7561 7562
	  $$= new Item_singlerow_subselect(Lex->current_select->
					   master_unit()->first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7563
	};
7564 7565

exists_subselect:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7566 7567 7568 7569 7570
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
7571 7572

exists_subselect_init:
7573
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7574
	{
7575 7576
	  $$= new Item_exists_subselect(Lex->current_select->master_unit()->
					first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7577
	};
7578

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7579 7580 7581 7582 7583 7584 7585 7586
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
7587
  select_init2
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7588
  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7589
    $$= Lex->current_select->master_unit()->first_select();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7590 7591
  };

7592
subselect_start:
7593
	'(' SELECT_SYM
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7594
	{
7595
	  LEX *lex=Lex;
7596
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
7597 7598
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
7599 7600
	  {
            yyerror(ER(ER_SYNTAX_ERROR));
7601 7602
	    YYABORT;
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7603 7604 7605
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
7606 7607

subselect_end:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7608 7609 7610
	')'
	{
	  LEX *lex=Lex;
7611
	  lex->current_select = lex->current_select->return_after_parsing();
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
7612
	};
serg@serg.mylan's avatar
serg@serg.mylan committed
7613

bell@sanja.is.com.ua's avatar
VIEW  
bell@sanja.is.com.ua committed
7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651
opt_view_list:
	/* empty */ {}
	| '(' view_list ')'
	;

view_list:
	ident 
	  {
	    Lex->view_list.push_back((LEX_STRING*)
				     sql_memdup(&$1, sizeof(LEX_STRING)));
	  }
	| view_list ',' ident
	  {
	    Lex->view_list.push_back((LEX_STRING*)
				     sql_memdup(&$3, sizeof(LEX_STRING)));
	  }
	;

or_replace:
	/* empty */	 { Lex->create_view_mode= VIEW_CREATE_NEW; }
	| OR_SYM REPLACE { Lex->create_view_mode= VIEW_CREATE_OR_REPLACE; }
	;

algorithm:
	/* empty */
	  { Lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; }
	| ALGORITHM_SYM EQ MERGE_SYM
	  { Lex->create_view_algorithm= VIEW_ALGORITHM_MERGE; }
	| ALGORITHM_SYM EQ TEMPTABLE_SYM
	  { Lex->create_view_algorithm= VIEW_ALGORITHM_TMEPTABLE; }
	;
check_option:
        /* empty */ {}
        | WITH CHECK_SYM OPTION {}
        | WITH CASCADED CHECK_SYM OPTION {}
        | WITH LOCAL_SYM CHECK_SYM OPTION {}
        ;