sql_yacc.yy 174 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) if (my_yyoverflow((B),(D),(int*) (F))) { yyerror((char*) (A)); return 2; }
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 102 103 104 105 106 107
}

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

%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 195 196 197 198

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

440 441 442
%token  ERRORS
%token  WARNINGS

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
443
%token	ASCII_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
444 445 446
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
447
%token	CHANGED
bk@work.mysql.com's avatar
bk@work.mysql.com committed
448 449 450 451 452 453
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
454
%token	FAST_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
455
%token	FLOAT_SYM
456
%token  GEOMETRY_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
457 458 459 460 461 462 463 464 465
%token	INT_SYM
%token	LIMIT
%token	LONGBLOB
%token	LONGTEXT
%token	MEDIUMBLOB
%token	MEDIUMINT
%token	MEDIUMTEXT
%token	NUMERIC_SYM
%token	PRECISION
466
%token	QUICK
bk@work.mysql.com's avatar
bk@work.mysql.com committed
467
%token	REAL
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
468
%token	SIGNED_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
469 470 471 472
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
473 474
%token	TIMESTAMP_ADD
%token	TIMESTAMP_DIFF
bk@work.mysql.com's avatar
bk@work.mysql.com committed
475 476 477 478
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
479
%token	ULONGLONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
480
%token	UNSIGNED
481 482 483
%token	VARBINARY
%token	VARCHAR
%token	VARYING
bk@work.mysql.com's avatar
bk@work.mysql.com committed
484 485
%token	ZEROFILL

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

594 595 596 597
%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
598
%token	SQL_SMALL_RESULT
599
%token  SQL_BUFFER_RESULT
bk@work.mysql.com's avatar
bk@work.mysql.com committed
600

601 602 603 604 605
%token  CURSOR_SYM
%token  ELSEIF_SYM
%token  ITERATE_SYM
%token  LEAVE_SYM
%token  LOOP_SYM
606
%token  REPEAT_SYM
607 608 609 610 611
%token  UNTIL_SYM
%token  WHILE_SYM
%token  ASENSITIVE_SYM
%token  INSENSITIVE_SYM
%token  SENSITIVE_SYM
612

613 614
%token  ISSUER_SYM
%token  SUBJECT_SYM
615
%token  CIPHER_SYM
616

617
%token  BEFORE_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
618
%left   SET_VAR
619
%left	OR_OR_CONCAT OR XOR
bk@work.mysql.com's avatar
bk@work.mysql.com committed
620 621 622 623 624 625 626
%left	AND
%left	BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
%left	EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP IN_SYM
%left	'|'
%left	'&'
%left	SHIFT_LEFT SHIFT_RIGHT
%left	'-' '+'
627
%left	'*' '/' '%' DIV_SYM MOD_SYM
628
%left   '^'
monty@mysql.com's avatar
monty@mysql.com committed
629
%left	NEG '~'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
630
%right	NOT
631
%right	BINARY COLLATE_SYM
632

bk@work.mysql.com's avatar
bk@work.mysql.com committed
633
%type <lex_str>
634 635
	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
636
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
637
	NCHAR_STRING opt_component key_cache_name
638
        sp_opt_label
bk@work.mysql.com's avatar
bk@work.mysql.com committed
639 640 641 642 643

%type <lex_str_ptr>
	opt_table_alias

%type <table>
monty@mysql.com's avatar
monty@mysql.com committed
644
	table_ident table_ident_ref references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
645 646

%type <simple_string>
647
	remember_name remember_end opt_ident opt_db text_or_password
648
	opt_escape opt_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
649 650

%type <string>
651
	text_string opt_gconcat_separator
bk@work.mysql.com's avatar
bk@work.mysql.com committed
652 653

%type <num>
654
	type int_type real_type order_dir opt_field_spec lock_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
655
	udf_type if_exists opt_local opt_table_options table_options
656 657
        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
658
        opt_ignore_leaves fulltext_options spatial_type union_option
bk@work.mysql.com's avatar
bk@work.mysql.com committed
659 660

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

663 664
%type <ulonglong_number>
	ulonglong_num
bk@work.mysql.com's avatar
bk@work.mysql.com committed
665

666 667 668
%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
669
%type <item>
670
	literal text_literal insert_ident order_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
671
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
672
	table_wild no_in_expr expr_expr simple_expr no_and_expr udf_expr
673
	using_list expr_or_default set_expr_or_default interval_expr
674
	param_marker singlerow_subselect singlerow_subselect_init
hf@deer.(none)'s avatar
hf@deer.(none) committed
675
	exists_subselect exists_subselect_init geometry_function
676
	signed_literal now_or_signed_literal
pem@mysql.com's avatar
pem@mysql.com committed
677
	sp_opt_default
678
	simple_ident_nospvar simple_ident_q
bk@work.mysql.com's avatar
bk@work.mysql.com committed
679

680 681
%type <item_num>
	NUM_literal
bk@work.mysql.com's avatar
bk@work.mysql.com committed
682 683

%type <item_list>
684
	expr_list udf_expr_list udf_expr_list2 when_list
685
	ident_list ident_list_arg
bk@work.mysql.com's avatar
bk@work.mysql.com committed
686 687

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

690 691 692
%type <key_alg>
	key_alg opt_btree_or_rtree

bk@work.mysql.com's avatar
bk@work.mysql.com committed
693 694 695 696 697 698 699
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
700
	join_table_list  join_table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
701

702
%type <date_time_type> date_time_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
703 704
%type <interval> interval

705 706
%type <interval_time_st> interval_time_st

707
%type <db_type> storage_engines
bk@work.mysql.com's avatar
bk@work.mysql.com committed
708 709 710

%type <row_type> row_types

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

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

715
%type <cast_type> cast_type
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
716

bk@work.mysql.com's avatar
bk@work.mysql.com committed
717 718 719 720 721 722
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

723
%type <charset>
724
	opt_collate
725 726
	charset_name
	charset_name_or_default
727 728
	old_or_new_charset_name
	old_or_new_charset_name_or_default
729 730
	collation_name
	collation_name_or_default
731

732 733
%type <variable> internal_variable_name

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

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

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

774
%type <NONE> call sp_proc_stmts sp_proc_stmt
775 776 777
%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
778
%type <lex> sp_cursor_stmt
779
%type <spname> sp_name
780

bk@work.mysql.com's avatar
bk@work.mysql.com committed
781 782
%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
783 784
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
785 786 787 788 789
%%


query:
	END_OF_INPUT
790
	{
791
	   THD *thd= YYTHD;
792
	   if (!thd->bootstrap &&
793
	      (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
794
	   {
795
	     send_error(thd,ER_EMPTY_QUERY);
796
	     YYABORT;
797
	   }
798 799
	   else
	   {
800
	     thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
801
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
802
	}
803
	| verb_clause END_OF_INPUT {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
804 805

verb_clause:
806 807 808 809 810 811
	  statement
	| begin
	;

/* Verb clauses, except begin */
statement:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
812 813
	  alter
	| analyze
814
	| backup
815
	| call
bk@work.mysql.com's avatar
bk@work.mysql.com committed
816 817
	| change
	| check
818
	| checksum
bk@work.mysql.com's avatar
bk@work.mysql.com committed
819 820 821 822
	| commit
	| create
	| delete
	| describe
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
823
	| do
bk@work.mysql.com's avatar
bk@work.mysql.com committed
824
	| drop
serg@serg.mylan's avatar
serg@serg.mylan committed
825
	| flush
bk@work.mysql.com's avatar
bk@work.mysql.com committed
826
	| grant
serg@serg.mylan's avatar
serg@serg.mylan committed
827 828
	| handler
	| help
bk@work.mysql.com's avatar
bk@work.mysql.com committed
829
	| insert
serg@serg.mylan's avatar
serg@serg.mylan committed
830
	| kill
bk@work.mysql.com's avatar
bk@work.mysql.com committed
831 832 833
	| load
	| lock
	| optimize
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
834
        | keycache
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
835
	| preload
836
	| purge
837
	| rename
serg@serg.mylan's avatar
serg@serg.mylan committed
838
	| repair
bk@work.mysql.com's avatar
bk@work.mysql.com committed
839
	| replace
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
840
	| reset
841
	| restore
bk@work.mysql.com's avatar
bk@work.mysql.com committed
842 843
	| revoke
	| rollback
844
	| savepoint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
845 846
	| select
	| set
serg@serg.mylan's avatar
serg@serg.mylan committed
847
	| show
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
848
	| slave
849
	| start
850
	| truncate
bk@work.mysql.com's avatar
bk@work.mysql.com committed
851 852
	| unlock
	| update
853
	| use
serg@serg.mylan's avatar
serg@serg.mylan committed
854
        ;
855

856 857
/* help */

858
help:
859
       HELP_SYM ident_or_text
860
       {
861 862 863
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_HELP;
	  lex->help_arg= $2.str;
864
       };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
865 866 867 868

/* change master */

change:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
869
       CHANGE MASTER_SYM TO_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
870 871 872
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
873
	  bzero((char*) &lex->mi, sizeof(lex->mi));
874 875 876 877
        }
       master_defs
	{}
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
878 879 880

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
883
master_def:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
884
       MASTER_HOST_SYM EQ TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
885 886 887 888
       {
	 Lex->mi.host = $3.str;
       }
       |
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
889
       MASTER_USER_SYM EQ TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
890 891 892 893
       {
	 Lex->mi.user = $3.str;
       }
       |
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
894
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
895 896 897 898
       {
	 Lex->mi.password = $3.str;
       }
       |
899
       MASTER_PORT_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
900 901 902 903
       {
	 Lex->mi.port = $3;
       }
       |
904
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
905 906 907
       {
	 Lex->mi.connect_retry = $3;
       }
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
       | 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;
932
	 }
933
       |
934
         master_file_def
935
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
936

937 938
master_file_def:
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
939
       {
940
	 Lex->mi.log_file_name = $3.str;
941
       }
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
       | 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);
         }
968
       ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
969 970 971 972 973 974

/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
975
	  THD *thd= YYTHD;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
976 977
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
978
	  if (!lex->select_lex.add_table_to_list(thd,$5,
979
						 ($2 &
980 981
						  HA_LEX_CREATE_TMP_TABLE ?
						  &tmp_table_alias :
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
982 983
						  (LEX_STRING*) 0),
						 TL_OPTION_UPDATING,
pem@mysql.com's avatar
pem@mysql.com committed
984
						 (using_update_log ?
985 986
						  TL_READ_NO_INSERT:
						  TL_READ)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
987 988 989 990 991 992 993
	    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;
994
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
995
	  lex->create_info.default_table_charset= thd->variables.collation_database;
venu@myvenu.com's avatar
venu@myvenu.com committed
996
	  lex->name=0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
997 998
	}
	create2
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
999
	  { Lex->current_select= &Lex->select_lex; }
1000
	| CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1001
	  {
1002 1003
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1004 1005
	    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
1006
	      YYABORT;
1007 1008 1009 1010
	    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
1011
	  }
1012
	   '(' key_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1013
	  {
1014
	    LEX *lex=Lex;
1015

1016
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
1017
	    lex->col_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1018 1019
	  }
	| CREATE DATABASE opt_if_not_exists ident
1020
	  { Lex->create_info.default_table_charset=NULL; }
1021
	  opt_create_database_options
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1022
	  {
1023 1024 1025 1026
	    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
1027
	  }
1028
	| CREATE udf_func_type FUNCTION_SYM sp_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1029
	  {
1030
	    LEX *lex=Lex;
1031
	    lex->spname= $4;
1032
	    lex->udf.type= $2;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1033
	  }
1034 1035
	  create_function_tail
	  {}
1036
	| CREATE PROCEDURE sp_name
1037 1038
	  {
	    LEX *lex= Lex;
1039
	    sp_head *sp;
1040

1041 1042 1043 1044 1045
	    if (lex->sphead)
	    {
	      net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "PROCEDURE");
	      YYABORT;
	    }
1046 1047 1048
	    /* Order is important here: new - reset - init */
	    sp= new sp_head();
	    sp->reset_thd_mem_root(YYTHD);
1049
	    sp->init(lex);
1050 1051 1052

	    sp->m_type= TYPE_ENUM_PROCEDURE;
	    lex->sphead= sp;
1053 1054 1055 1056 1057
	    /*
	     * We have to turn of CLIENT_MULTI_QUERIES while parsing a
	     * stored procedure, otherwise yylex will chop it into pieces
	     * at each ';'.
	     */
1058
	    sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
1059
	    YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES);
1060
	  }
1061
          '('
1062
	  {
1063 1064
	    LEX *lex= Lex;

1065 1066 1067 1068 1069 1070 1071 1072
	    lex->sphead->m_param_begin= lex->tok_start+1;
	  }
	  sp_pdparam_list
	  ')'
	  {
	    LEX *lex= Lex;

	    lex->sphead->m_param_end= lex->tok_start;
1073 1074
	    lex->spcont->set_params();
	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
1075
	  }
1076
	  sp_c_chistics
1077
	  {
1078 1079 1080
	    LEX *lex= Lex;

	    lex->sphead->m_chistics= &lex->sp_chistics;
1081
	    lex->sphead->m_body_begin= lex->tok_start;
1082
	  }
1083
	  sp_proc_stmt
1084
	  {
1085 1086
	    LEX *lex= Lex;

1087
	    lex->sphead->init_strings(YYTHD, lex, $3);
1088 1089 1090 1091
	    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;
1092
	    lex->sphead->restore_thd_mem_root(YYTHD);
1093 1094 1095
	  } 
	;

1096
sp_name:
1097 1098 1099 1100 1101 1102 1103 1104 1105
	  IDENT_sys '.' IDENT_sys
	  {
	    $$= new sp_name($1, $3);
	    $$->init_qname(YYTHD);
	  }
	| IDENT_sys
	  {
	    $$= sp_name_current_db_new(YYTHD, $1);
	  }
1106 1107
	;

1108
create_function_tail:
pem@mysql.com's avatar
pem@mysql.com committed
1109
	  RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1110
	  {
1111
	    LEX *lex=Lex;
1112
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
1113
	    lex->udf.name = lex->spname->m_name;
1114 1115
	    lex->udf.returns=(Item_result) $2;
	    lex->udf.dl=$4.str;
1116
	  }
1117 1118 1119
	| '('
	  {
	    LEX *lex= Lex;
1120
	    sp_head *sp;
1121

1122 1123 1124 1125 1126
	    if (lex->sphead)
	    {
	      net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "FUNCTION");
	      YYABORT;
	    }
1127 1128 1129
	    /* Order is important here: new - reset - init */
	    sp= new sp_head();
	    sp->reset_thd_mem_root(YYTHD);
1130
	    sp->init(lex);
1131 1132 1133

	    sp->m_type= TYPE_ENUM_FUNCTION;
	    lex->sphead= sp;
1134 1135 1136 1137 1138
	    /*
	     * We have to turn of CLIENT_MULTI_QUERIES while parsing a
	     * stored procedure, otherwise yylex will chop it into pieces
	     * at each ';'.
	     */
1139
	    sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
1140
	    YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
1141
	    lex->sphead->m_param_begin= lex->tok_start+1;
1142 1143 1144
	  }
          sp_fdparam_list ')'
	  {
1145 1146 1147 1148 1149 1150 1151
	    LEX *lex= Lex;

	    lex->spcont->set_params();
	    lex->sphead->m_param_end= lex->tok_start;
	  }
	  RETURNS_SYM
	  {
1152 1153 1154 1155 1156
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;

	    sp->m_returns_begin= lex->tok_start;
	    sp->m_returns_cs= lex->charset= NULL;
1157
	  }
1158
	  type
1159
	  {
1160
	    LEX *lex= Lex;
1161
	    sp_head *sp= lex->sphead;
1162

1163 1164 1165
	    sp->m_returns_end= lex->tok_start;
	    sp->m_returns= (enum enum_field_types)$8;
	    sp->m_returns_cs= lex->charset;
1166
	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
1167
	  }
1168
	  sp_c_chistics
1169
	  {
1170 1171 1172
	    LEX *lex= Lex;

	    lex->sphead->m_chistics= &lex->sp_chistics;
1173
	    lex->sphead->m_body_begin= lex->tok_start;
1174
	  }
1175
	  sp_proc_stmt
1176
	  {
1177
	    LEX *lex= Lex;
1178
	    sp_head *sp= lex->sphead;
1179

1180
	    lex->sql_command= SQLCOM_CREATE_SPFUNCTION;
1181
	    sp->init_strings(YYTHD, lex, lex->spname);
1182
	    /* Restore flag if it was cleared above */
1183
	    if (sp->m_old_cmq)
1184
	      YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
1185
	    sp->restore_thd_mem_root(YYTHD);
1186
	  }
1187 1188
	;

1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
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 { }
1203 1204
	;

1205 1206 1207 1208
/* Alter characteristics */
sp_a_chistic:
	  sp_chistic     { }
	| NAME_SYM ident { Lex->name= $2.str; }
1209 1210
	;

1211 1212 1213 1214 1215 1216 1217
/* 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; }
	;
1218 1219

sp_suid:
1220 1221 1222 1223 1224 1225 1226 1227
	  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;
	  }
1228 1229
	;

1230
call:
1231
	  CALL_SYM sp_name
1232 1233 1234 1235
	  {
	    LEX *lex = Lex;

	    lex->sql_command= SQLCOM_CALL;
1236
	    lex->spname= $2;
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
	    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);
	  }
	;

1259 1260
/* Stored FUNCTION parameter declaration list */
sp_fdparam_list:
1261
	  /* Empty */
1262
	| sp_fdparams
1263 1264
	;

1265 1266 1267
sp_fdparams:
	  sp_fdparams ',' sp_fdparam
	| sp_fdparam
1268 1269
	;

1270
sp_fdparam:
1271
	  ident type
1272
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1273 1274 1275 1276 1277
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$1, TRUE))
	    {
1278
	      net_printf(YYTHD, ER_SP_DUP_PARAM, $1.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1279 1280 1281
	      YYABORT;
	    }
	    spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in);
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
	  }
	;

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

sp_pdparams:
	  sp_pdparams ',' sp_pdparam
	| sp_pdparam
	;

sp_pdparam:
1297
	  sp_opt_inout ident type
1298
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1299 1300 1301 1302 1303
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$2, TRUE))
	    {
1304
	      net_printf(YYTHD, ER_SP_DUP_PARAM, $2.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1305 1306 1307 1308
	      YYABORT;
	    }
	    spc->push_pvar(&$2, (enum enum_field_types)$3,
			   (sp_param_mode_t)$1);
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
	  }
	;

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
1320
	  /* Empty */ {}
1321
	| sp_proc_stmts sp_proc_stmt ';'
1322 1323 1324 1325 1326
	;

sp_decls:
	  /* Empty */
	  {
1327
	    $$.vars= $$.conds= $$.hndlrs= $$.curs= 0;
1328 1329 1330
	  }
	| sp_decls sp_decl ';'
	  {
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
	    /* 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;
	    }
1345 1346 1347
	    $$.vars= $1.vars + $2.vars;
	    $$.conds= $1.conds + $2.conds;
	    $$.hndlrs= $1.hndlrs + $2.hndlrs;
1348
	    $$.curs= $1.curs + $2.curs;
1349 1350 1351 1352
	  }
	;

sp_decl:
1353
	  DECLARE_SYM sp_decl_idents type sp_opt_default
1354 1355 1356
	  {
	    LEX *lex= Lex;
	    uint max= lex->spcont->current_framesize();
1357 1358
	    enum enum_field_types type= (enum enum_field_types)$3;
	    Item *it= $4;
1359 1360 1361

	    for (uint i = max-$2 ; i < max ; i++)
	    {
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
	      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);
1372
		lex->spcont->set_default(i, it);
1373
	      }
1374
	    }
1375
	    $$.vars= $2;
1376
	    $$.conds= $$.hndlrs= $$.curs= 0;
1377 1378 1379
	  }
	| DECLARE_SYM ident CONDITION_SYM FOR_SYM sp_cond
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1380 1381 1382 1383 1384
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_cond(&$2, TRUE))
	    {
1385
	      net_printf(YYTHD, ER_SP_DUP_COND, $2.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1386 1387
	      YYABORT;
	    }
1388
	    YYTHD->lex->spcont->push_cond(&$2, $5);
1389
	    $$.vars= $$.hndlrs= $$.curs= 0;
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
	    $$.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);
1422
	    $$.vars= $$.conds= $$.curs= 0;
1423 1424 1425 1426
	    $$.hndlrs= $6;
	  }
	| DECLARE_SYM ident CURSOR_SYM FOR_SYM sp_cursor_stmt
	  {
1427 1428
	    LEX *lex= Lex;
	    sp_head *sp= lex->sphead;
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1429 1430 1431
	    sp_pcontext *spc= lex->spcont;
	    uint offp;
	    sp_instr_cpush *i;
1432

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1433 1434
	    if (spc->find_cursor(&$2, &offp, TRUE))
	    {
1435 1436
	      net_printf(YYTHD, ER_SP_DUP_CURS, $2.str);
	      delete $5;
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1437 1438 1439
	      YYABORT;
	    }
            i= new sp_instr_cpush(sp->instructions(), $5);
1440 1441
	    sp->add_instr(i);
	    lex->spcont->push_cursor(&$2);
1442
	    $$.vars= $$.conds= $$.hndlrs= 0;
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
	    $$.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);
	  }
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
	;

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
1510
	| SQLSTATE_SYM opt_value TEXT_STRING_literal
1511
	  {		/* SQLSTATE */
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1512 1513
	    uint len= ($3.length < sizeof($$->sqlstate)-1 ?
                       $3.length : sizeof($$->sqlstate)-1);
1514 1515 1516

	    $$= (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
1517
	    memcpy($$->sqlstate, $3.str, len);
1518 1519 1520 1521
	    $$->sqlstate[len]= '\0';
	  }
	;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1522 1523 1524 1525 1526
opt_value:
	  /* Empty */  {}
	| VALUE_SYM    {}
	;

1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554
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;
1555 1556 1557 1558 1559 1560
	  }
	;

sp_decl_idents:
	  ident
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1561 1562 1563 1564 1565
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$1, TRUE))
	    {
1566
	      net_printf(YYTHD, ER_SP_DUP_VAR, $1.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1567 1568 1569
	      YYABORT;
	    }
	    spc->push_pvar(&$1, (enum_field_types)0, sp_param_in);
1570 1571 1572 1573
	    $$= 1;
	  }
	| sp_decl_idents ',' ident
	  {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1574 1575 1576 1577 1578
	    LEX *lex= Lex;
	    sp_pcontext *spc= lex->spcont;

	    if (spc->find_pvar(&$3, TRUE))
	    {
1579
	      net_printf(YYTHD, ER_SP_DUP_VAR, $3.str);
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1580 1581 1582
	      YYABORT;
	    }
	    spc->push_pvar(&$3, (enum_field_types)0, sp_param_in);
1583 1584 1585 1586
	    $$= $1 + 1;
	  }
	;

1587 1588 1589 1590 1591
sp_opt_default:
	  /* Empty */ { $$ = NULL; }
        | DEFAULT expr { $$ = $2; }
	;

1592
sp_proc_stmt:
1593 1594 1595
	  {
	    Lex->sphead->reset_lex(YYTHD);
	  }
1596 1597 1598 1599
	  statement
	  {
	    LEX *lex= Lex;

1600 1601 1602 1603 1604 1605 1606
	    /* 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 ||
	        lex->sql_command == SQLCOM_SHOW_STATUS_FUNC)
1607
	    {
1608
	      /* We maybe have one or more SELECT without INTO */
1609
	      lex->sphead->m_multi_results= TRUE;
1610
	    }
1611 1612 1613 1614 1615
	    if (lex->sql_command == SQLCOM_CHANGE_DB)
	    { /* "USE db" doesn't work in a procedure */
	      send_error(YYTHD, ER_SP_NO_USE);
	      YYABORT;
	    }
1616 1617 1618 1619 1620
	    /* 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 ||
1621
		! lex->var_list.is_empty())
1622
	    {
1623 1624 1625 1626 1627
	      /* Currently we can't handle queries inside a FUNCTION,
	      ** because of the way table locking works.
	      ** This is unfortunate, and limits the usefulness of functions
	      ** a great deal, but it's nothing we can do about this at the
	      ** moment.
1628
	      */
1629 1630
	      if (lex->sphead->m_type == TYPE_ENUM_FUNCTION &&
		  lex->sql_command != SQLCOM_SET_OPTION)
1631
	      {
1632
		send_error(YYTHD, ER_SP_BADSTATEMENT);
1633 1634 1635 1636 1637 1638 1639 1640
		YYABORT;
	      }
	      else
	      {
		sp_instr_stmt *i=new sp_instr_stmt(lex->sphead->instructions());

		i->set_lex(lex);
		lex->sphead->add_instr(i);
1641
		lex->sp_lex_in_use= TRUE;
1642 1643 1644
	      }
            }
	    lex->sphead->restore_lex(YYTHD);
1645
          }
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
	| RETURN_SYM expr
	  {
	    LEX *lex= Lex;

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

1659 1660 1661 1662 1663 1664 1665
	      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);
1666
	      lex->sphead->add_instr(i);
1667
	      lex->sphead->m_has_return= TRUE;
1668 1669
	    }
	  }
1670
	| IF sp_if END IF {}
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689
	| 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;
1690
	    lex->spcont->push_pvar(&dummy, MYSQL_TYPE_STRING, sp_param_in);
1691 1692 1693 1694 1695
	    lex->sphead->add_instr(i);
	    lex->sphead->m_simple_case= TRUE;
	  }
	  sp_case END CASE_SYM
	  {
1696
	    Lex->spcont->pop_pvar();
1697
	  }
1698 1699 1700 1701 1702
	| sp_labeled_control
	  {}
	| { /* Unlabeled controls get a secret label. */
	    LEX *lex= Lex;

1703
	    lex->spcont->push_label((char *)"", lex->sphead->instructions());
1704 1705 1706
	  }
	  sp_unlabeled_control
	  {
1707 1708
	    LEX *lex= Lex;

1709
	    lex->sphead->backpatch(lex->spcont->pop_label());
1710 1711 1712 1713
	  }
	| LEAVE_SYM IDENT
	  {
	    LEX *lex= Lex;
1714
	    sp_head *sp = lex->sphead;
1715 1716 1717 1718
	    sp_label_t *lab= lex->spcont->find_label($2.str);

	    if (! lab)
	    {
1719
	      net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE", $2.str);
1720 1721 1722 1723
	      YYABORT;
	    }
	    else
	    {
1724
	      sp_instr_jump *i= new sp_instr_jump(sp->instructions());
1725

1726 1727
	      sp->push_backpatch(i, lab);  /* Jumping forward */
              sp->add_instr(i);
1728 1729 1730 1731 1732 1733 1734
	    }
	  }
	| 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
1735
	    if (! lab || lab->isbegin)
1736
	    {
1737
	      net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE", $2.str);
1738 1739 1740 1741 1742
	      YYABORT;
	    }
	    else
	    {
	      uint ip= lex->sphead->instructions();
1743
	      sp_instr_jump *i= new sp_instr_jump(ip, lab->ip); /* Jump back */
1744 1745 1746 1747

              lex->sphead->add_instr(i);
	    }
	  }
1748
	| OPEN_SYM ident
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
	  {
	    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
	  { }
1780
	| CLOSE_SYM ident
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
	  {
	    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;
	    }
	  }
1839
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1840

1841 1842 1843 1844 1845 1846 1847 1848
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);

1849
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
            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());
1861
	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
1862 1863 1864 1865 1866
	  }
	  sp_elseifs
	  {
	    LEX *lex= Lex;

1867
	    lex->sphead->backpatch(lex->spcont->pop_label());
1868 1869 1870 1871 1872 1873 1874 1875 1876
	  }
	;

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

1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
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> */
1889 1890
	      LEX_STRING ivar;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1891
	      ivar.str= (char *)"_tmp_";
1892 1893 1894
	      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
1895
	      Item *expr= new Item_func_eq(var, $1);
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921

	      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:
1922 1923 1924 1925 1926 1927 1928 1929
	  /* 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);
	  }
1930
	| ELSE sp_proc_stmts {}
1931
	| WHEN_SYM sp_case {}
1932 1933
	;

1934 1935 1936 1937 1938 1939 1940 1941
sp_labeled_control:
	  IDENT ':'
	  {
	    LEX *lex= Lex;
	    sp_label_t *lab= lex->spcont->find_label($1.str);

	    if (lab)
	    {
1942
	      net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $1.str);
1943 1944 1945
	      YYABORT;
	    }
	    else
1946
	    {
1947 1948
	      lex->spcont->push_label($1.str,
	                              lex->sphead->instructions());
1949
	    }
1950
	  }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1951
	  sp_unlabeled_control sp_opt_label
1952 1953 1954
	  {
	    LEX *lex= Lex;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1955
	    if ($5.str)
1956
	    {
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1957 1958 1959 1960 1961 1962 1963 1964
	      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;
	      }
1965
	    }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1966
	    lex->sphead->backpatch(lex->spcont->pop_label());
1967 1968 1969
	  }
	;

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1970 1971 1972 1973 1974 1975 1976
sp_opt_label:
	  /* Empty  */
	  { $$.str= NULL; $$.length= 0; }
	| IDENT
	  { $$= $1; }
	;

1977
sp_unlabeled_control:
1978 1979 1980 1981
	  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
1982 1983
	    LEX *lex= Lex;
	    sp_label_t *lab= lex->spcont->last_label();
1984

pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
1985 1986 1987
	    lab->isbegin= TRUE;
	    /* Scope duplicate checking */
	    lex->spcont->push_scope();
1988 1989 1990 1991 1992 1993 1994 1995 1996
	  }
	  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
1997
  	    sp->backpatch(ctx->last_label());	/* We always has a label */
1998 1999
	    ctx->pop_pvar($3.vars);
	    ctx->pop_cond($3.conds);
2000
	    ctx->pop_cursor($3.curs);
2001
	    if ($3.hndlrs)
2002 2003 2004
	      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
2005
	    ctx->pop_scope();
2006 2007
	  }
	| LOOP_SYM
2008 2009 2010 2011 2012 2013 2014 2015 2016
	  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);
	  }
2017
	| WHILE_SYM expr DO_SYM
2018 2019
	  {
	    LEX *lex= Lex;
2020 2021
	    sp_head *sp= lex->sphead;
	    uint ip= sp->instructions();
2022 2023
	    sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, $2);

2024 2025 2026
	    /* Jumping forward */
	    sp->push_backpatch(i, lex->spcont->last_label());
            sp->add_instr(i);
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
	  }
	  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);
	  }
2037 2038
	| REPEAT_SYM sp_proc_stmts UNTIL_SYM expr END REPEAT_SYM
	  {
2039 2040 2041 2042 2043 2044 2045
	    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);
	  }
2046
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2047 2048

create2:
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2049
 	'(' create2a {}
2050
	| opt_create_table_options create3 {}
venu@myvenu.com's avatar
venu@myvenu.com committed
2051 2052 2053 2054 2055 2056
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
2057 2058 2059 2060 2061 2062
	| '(' LIKE table_ident ')'
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$3))
              YYABORT;
    	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2063
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2064

serg@serg.mylan's avatar
serg@serg.mylan committed
2065 2066
create2a:
        field_list ')' opt_create_table_options create3 {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2067
	|  create_select ')' { Select->set_braces(1);} union_opt {}
2068
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2069 2070

create3:
2071
	/* empty */ {}
serg@serg.mylan's avatar
serg@serg.mylan committed
2072
	| opt_duplicate opt_as     create_select
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2073
          { Select->set_braces(0);} union_clause {}
serg@serg.mylan's avatar
serg@serg.mylan committed
2074
	| opt_duplicate opt_as '(' create_select ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2075
          { Select->set_braces(1);} union_opt {}
2076 2077
        ;

serg@serg.mylan's avatar
serg@serg.mylan committed
2078
create_select:
2079
          SELECT_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2080
          {
2081 2082
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
2083 2084 2085 2086
	    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;
2087
	    lex->current_select->table_list.save_and_clear(&lex->save_list);
2088
	    mysql_init_select(lex);
2089
	    lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2090
          }
2091 2092 2093 2094
          select_options select_item_list
	  {
	    Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2095
	  opt_select_from
2096
	  { Lex->current_select->table_list.push_front(&Lex->save_list); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2097
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2098

2099 2100
opt_as:
	/* empty */ {}
2101
	| AS	    {};
2102

2103 2104 2105 2106 2107 2108 2109 2110 2111
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
2112 2113
	  opt_default COLLATE_SYM collation_name_or_default	
	  { Lex->create_info.default_table_charset=$3; }
2114
	| opt_default charset charset_name_or_default
2115
	  { Lex->create_info.default_table_charset=$3; }
2116
	;
2117

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2118
opt_table_options:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2119
	/* empty */	 { $$= 0; }
2120
	| table_options  { $$= $1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2121 2122 2123

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2126
table_option:
2127
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2128 2129

opt_if_not_exists:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2130
	/* empty */	 { $$= 0; }
2131
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2132 2133 2134

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

2137 2138 2139 2140
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
2141 2142
create_table_options:
	create_table_option
2143
	| create_table_option     create_table_options
2144
	| create_table_option ',' create_table_options;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2145 2146

create_table_option:
2147
	ENGINE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; }
2148
	| TYPE_SYM opt_equal storage_engines    { Lex->create_info.db_type= $3; WARN_DEPRECATED("TYPE=storage_engine","ENGINE=storage_engine"); }
2149 2150 2151
	| 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
2152 2153
	| 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; }
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
	| 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 ')'
2164 2165 2166
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
2167 2168
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
2169 2170
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
2171 2172
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
2173
	    table_list->next=0;
2174
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
2175
	  }
2176
	| opt_default charset opt_equal charset_name_or_default
2177
	  {
2178 2179 2180
	    Lex->create_info.default_table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
	  }
2181
	| opt_default COLLATE_SYM opt_equal collation_name_or_default
2182
	  {
2183
	    Lex->create_info.default_table_charset= $4;
2184 2185
	    Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
	  }
2186
	| 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
2187 2188 2189
	| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys
	  { Lex->create_info.data_file_name= $4.str; }
	| INDEX DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2190

2191
storage_engines:
2192 2193 2194 2195
	ident_or_text
	{
	  $$ = ha_resolve_by_name($1.str,$1.length);
	  if ($$ == DB_TYPE_UNKNOWN) {
2196
	    net_printf(YYTHD, ER_UNKNOWN_STORAGE_ENGINE, $1.str);
2197 2198 2199
	    YYABORT;
	  }
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2200 2201 2202 2203 2204

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
2205
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2206 2207 2208 2209

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

2212 2213 2214
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
2215
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
2216

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2217
opt_select_from:
2218
	opt_limit_clause {}
2219
	| FROM DUAL_SYM {}
2220
	| select_from select_lock_type;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2221 2222

udf_func_type:
2223
	/* empty */	{ $$ = UDFTYPE_FUNCTION; }
2224
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2225 2226 2227 2228

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
2229
	| INT_SYM {$$ = (int) INT_RESULT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2230 2231 2232

field_list:
	  field_list_item
2233
	| field_list ',' field_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2234 2235 2236


field_list_item:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
2237
	   column_def
2238 2239 2240 2241
         | key_def
         ;

column_def:
2242
	  field_spec check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2243 2244 2245 2246
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
2247
	;
2248 2249

key_def:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
2250
	key_type opt_ident key_alg '(' key_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2251
	  {
2252
	    LEX *lex=Lex;
2253
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
2254
	    lex->col_list.empty();		/* Alloced by sql_alloc */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2255
	  }
2256 2257 2258 2259 2260 2261 2262
	| opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')'
	  {
	    LEX *lex=Lex;
	    const char *key_name= $3 ? $3:$1;
	    lex->key_list.push_back(new Key($2, key_name, $4, lex->col_list));
	    lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
2263
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2264
	  {
2265 2266 2267 2268 2269 2270 2271 2272
	    LEX *lex=Lex;
	    lex->key_list.push_back(new foreign_key($4, lex->col_list,
				    $8,
				    lex->ref_list,
				    lex->fk_delete_opt,
				    lex->fk_update_opt,
				    lex->fk_match_option));
	    lex->col_list.empty();		/* Alloced by sql_alloc */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2273
	  }
2274
	| opt_constraint check_constraint
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2275 2276
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
2277 2278 2279 2280 2281 2282 2283
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2284 2285

opt_constraint:
2286 2287
	/* empty */		{ $$=(char*) 0; }
	| CONSTRAINT opt_ident	{ $$=$2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2288 2289 2290 2291

field_spec:
	field_ident
	 {
2292 2293
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
2294
	   lex->default_value= lex->on_update_value= 0;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2295
	   lex->comment=0;
2296
	   lex->charset=NULL;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2297 2298 2299
	 }
	type opt_attribute
	{
2300
	  LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2301
	  if (add_field_to_list(lex->thd, $1.str,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2302
				(enum enum_field_types) $3,
2303
				lex->length,lex->dec,lex->type,
2304 2305
				lex->default_value, lex->on_update_value, 
                                lex->comment,
2306 2307
				lex->change,lex->interval,lex->charset,
				lex->uint_geom_type))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2308
	    YYABORT;
2309
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2310 2311

type:
2312
	int_type opt_len field_options	{ $$=$1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2313 2314 2315 2316 2317 2318
	| 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; }
2319 2320
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
2321
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2322 2323 2324
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
2325
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2326
					  $$=FIELD_TYPE_STRING;
2327
					  Lex->charset=national_charset_info; }
2328
	| nchar				{ Lex->length=(char*) "1";
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2329
					  $$=FIELD_TYPE_STRING;
2330
					  Lex->charset=national_charset_info; }
2331
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
2332
					  Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2333 2334 2335
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
2336 2337
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
2338
					  Lex->charset=national_charset_info; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2339
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
2340
					  Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2341
					  $$=FIELD_TYPE_VAR_STRING; }
2342
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2343 2344
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
2345 2346
	| TIMESTAMP
	  {
2347
	    if (YYTHD->variables.sql_mode & MODE_MAXDB)
2348 2349
	      $$=FIELD_TYPE_DATETIME;
	    else
2350
	      $$=FIELD_TYPE_TIMESTAMP;
2351
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2352 2353 2354
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
2355
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2356
					  $$=FIELD_TYPE_TINY_BLOB; }
2357
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2358
					  $$=FIELD_TYPE_BLOB; }
hf@deer.(none)'s avatar
hf@deer.(none) committed
2359 2360 2361 2362 2363 2364 2365 2366
	| 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,
			                             ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2367 2368
			                             sym_group_geom.name,
	                                             sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
2369 2370 2371
					  YYABORT;
#endif
					}
2372
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2373
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
2374
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2375
					  $$=FIELD_TYPE_LONG_BLOB; }
2376
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2377
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
2378 2379
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
2380
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
2381 2382
	| 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
2383 2384 2385 2386
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
2387 2388
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
2389
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2390
	  {
2391 2392
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2393 2394
	    $$=FIELD_TYPE_ENUM;
	  }
2395
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2396
	  {
2397 2398
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2399
	    $$=FIELD_TYPE_SET;
2400
	  }
2401
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
2402 2403 2404 2405 2406 2407
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
2408
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2409

hf@deer.(none)'s avatar
hf@deer.(none) committed
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420
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
2421 2422
char:
	CHAR_SYM {}
2423 2424 2425 2426 2427 2428
	;

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2430 2431 2432
varchar:
	char VARYING {}
	| VARCHAR {}
2433 2434 2435 2436
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2437
	| NVARCHAR_SYM {}
2438 2439 2440 2441
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2442 2443 2444 2445 2446 2447

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

real_type:
2451
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2452 2453
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
2454
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2455 2456 2457 2458 2459


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
2460
	| precision		{};
2461 2462 2463 2464 2465 2466

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

field_options:
	/* empty */		{}
2471
	| field_opt_list	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2472 2473 2474

field_opt_list:
	field_opt_list field_option {}
2475
	| field_option {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2476 2477

field_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2478
	SIGNED_SYM	{}
2479
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
2480
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2481 2482

opt_len:
2483 2484
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2485 2486 2487

opt_precision:
	/* empty */	{}
2488
	| precision	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2489 2490 2491

opt_attribute:
	/* empty */ {}
2492
	| opt_attribute_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2493 2494 2495

opt_attribute_list:
	opt_attribute_list attribute {}
2496
	| attribute;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2497 2498 2499 2500

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
2501 2502 2503
	| 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
2504
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
2505
	| SERIAL_SYM DEFAULT VALUE_SYM
2506 2507
	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; }
	| opt_primary KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2508
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
2509
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2510
	| COMMENT_SYM TEXT_STRING_sys { Lex->comment= &$2; }
2511
	| BINARY { Lex->type|= BINCMP_FLAG; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2512 2513
	| COLLATE_SYM collation_name
	  {
2514
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525
	    {
	      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
2526

2527 2528 2529 2530 2531
now_or_signed_literal:
        NOW_SYM optional_braces { $$= new Item_func_now_local(); }
        | signed_literal { $$=$1; }
        ;

2532 2533 2534 2535
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
2536

2537
charset_name:
2538
	ident_or_text
2539
	{
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2540
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
2541
	  {
2542
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
2543 2544
	    YYABORT;
	  }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2545 2546 2547
	}
	| BINARY { $$= &my_charset_bin; }
	;
2548

2549 2550 2551
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2552

2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570

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

2571
collation_name:
2572
	ident_or_text
2573 2574 2575
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
2576
	    net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str);
2577 2578 2579 2580
	    YYABORT;
	  }
	};

2581 2582
opt_collate:
	/* empty */	{ $$=NULL; }
2583
	| COLLATE_SYM collation_name_or_default { $$=$2; }
2584 2585
	;

2586 2587 2588 2589
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

2590 2591 2592 2593
opt_default:
	/* empty */	{}
	| DEFAULT	{};

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2594
opt_binary:
2595
	/* empty */			{ Lex->charset=NULL; }
2596 2597
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
2598 2599
	| UNICODE_SYM
	{
2600
	  if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
2601 2602 2603 2604 2605
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
2606
	| charset charset_name	{ Lex->charset=$2; } ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2607

2608 2609 2610
opt_primary:
	/* empty */
	| PRIMARY_SYM
2611
	;
2612

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2613
references:
2614 2615
	REFERENCES table_ident
	{
2616
	  LEX *lex=Lex;
2617 2618 2619 2620 2621 2622
	  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
2623
	};
2624

2625
opt_ref_list:
2626
	/* empty */ opt_on_delete {}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2627
	| '(' ref_list ')' opt_on_delete {};
2628 2629 2630

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2633 2634 2635

opt_on_delete:
	/* empty */ {}
2636
	| opt_on_delete_list {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2637 2638 2639

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
2640
	| opt_on_delete_item {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2641 2642

opt_on_delete_item:
2643 2644 2645 2646
	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
2647
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2648 2649

delete_option:
2650 2651 2652 2653
	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
2654
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2655 2656

key_type:
2657
	key_or_index			    { $$= Key::MULTIPLE; }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2658 2659
	| FULLTEXT_SYM opt_key_or_index	    { $$= Key::FULLTEXT; }
	| SPATIAL_SYM opt_key_or_index
hf@deer.(none)'s avatar
hf@deer.(none) committed
2660 2661 2662 2663 2664 2665
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
	               ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2666
		       sym_group_geom.name, sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
2667 2668 2669
	    YYABORT;
#endif
	  };
2670 2671 2672

constraint_key_type:
	PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2673
	| UNIQUE_SYM opt_key_or_index { $$= Key::UNIQUE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2674 2675 2676

key_or_index:
	KEY_SYM {}
2677
	| INDEX {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2678

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2679
opt_key_or_index:
2680
	/* empty */ {}
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2681
	| key_or_index
2682 2683
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2684 2685 2686
keys_or_index:
	KEYS {}
	| INDEX {}
2687
	| INDEXES {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2688

2689
opt_unique_or_fulltext:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2690 2691
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
serg@serg.mylan's avatar
serg@serg.mylan committed
2692
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT;}
hf@deer.(none)'s avatar
hf@deer.(none) committed
2693 2694 2695 2696 2697 2698 2699
	| SPATIAL_SYM
	  {
#ifdef HAVE_SPATIAL
	    $$= Key::SPATIAL;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
	               ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
2700
	               sym_group_geom.name, sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
2701 2702 2703
	    YYABORT;
#endif
	  }
serg@serg.mylan's avatar
serg@serg.mylan committed
2704
        ;
2705 2706

key_alg:
2707
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
2708
	| USING opt_btree_or_rtree { $$= $2; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2709
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
2710 2711 2712

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
hf@deer.(none)'s avatar
hf@deer.(none) committed
2713 2714 2715 2716
	| RTREE_SYM
	  {
	    $$= HA_KEY_ALG_RTREE;
	  }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2717
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2718 2719 2720

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
2721
	| key_part order_dir		{ Lex->col_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2722 2723 2724

key_part:
	ident			{ $$=new key_part_spec($1.str); }
2725
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2726 2727 2728

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

2731 2732 2733
opt_component:
	/* empty */	 { $$.str= 0; $$.length= 0; }
	| '.' ident	 { $$=$2; };
2734

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2735 2736
string_list:
	text_string			{ Lex->interval_list.push_back($1); }
2737
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2738 2739 2740 2741 2742 2743 2744 2745

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
2746
	  THD *thd= YYTHD;
2747
	  LEX *lex= thd->lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2748 2749
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2750 2751
	  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
2752 2753 2754 2755 2756 2757
	    YYABORT;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
	  lex->drop_list.empty();
	  lex->alter_list.empty();
2758
          lex->select_lex.init_order();
2759
	  lex->select_lex.db=lex->name=0;
2760
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2761
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
2762
	  lex->create_info.default_table_charset= thd->variables.collation_database;
2763
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
2764
          lex->alter_keys_onoff=LEAVE_AS_IS;
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
2765
	  lex->tablespace_op=NO_TABLESPACE_OP;
2766
          lex->simple_alter=1;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2767
	}
2768 2769
	alter_list
	{}
2770
	| ALTER DATABASE ident opt_create_database_options
2771 2772 2773 2774
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
2775
	  }
2776
	| ALTER PROCEDURE sp_name
2777 2778 2779 2780
	  {
	    LEX *lex= Lex;

	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
2781
	    lex->name= 0;
2782 2783
          }
	  sp_a_chistics
2784
	  {
2785
	    THD *thd= YYTHD;
2786
	    LEX *lex=Lex;
2787

2788
	    lex->sql_command= SQLCOM_ALTER_PROCEDURE;
2789
	    lex->spname= $3;
2790
	  }
2791
	| ALTER FUNCTION_SYM sp_name
2792 2793 2794 2795 2796 2797 2798
	  {
	    LEX *lex= Lex;

	    bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
	    lex->name= 0;
          }
	  sp_a_chistics
2799
	  {
2800
	    THD *thd= YYTHD;
2801
	    LEX *lex=Lex;
2802

2803
	    lex->sql_command= SQLCOM_ALTER_FUNCTION;
2804
	    lex->spname= $3;
2805
	  }
2806
	;
2807

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2808
alter_list:
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
2809 2810
	| DISCARD TABLESPACE { Lex->tablespace_op=DISCARD_TABLESPACE; }
	| IMPORT TABLESPACE { Lex->tablespace_op=IMPORT_TABLESPACE; }
2811
        | alter_list_item
2812
	| alter_list ',' alter_list_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2813 2814

add_column:
2815
	ADD opt_column { Lex->change=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2816 2817

alter_list_item:
2818 2819
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
2820
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
2821 2822 2823 2824 2825
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
2826
          field_spec opt_place
2827 2828 2829 2830
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
            lex->length=lex->dec=0; lex->type=0; lex->interval=0;
2831
            lex->default_value= lex->on_update_value= 0;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2832
	    lex->comment=0;
2833
	    lex->charset= NULL;
2834
            lex->simple_alter=0;
2835 2836 2837 2838
          }
          type opt_attribute
          {
            LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2839
            if (add_field_to_list(lex->thd,$3.str,
2840 2841
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
2842 2843
                                  lex->default_value, lex->on_update_value,
                                  lex->comment,
2844 2845
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
2846 2847 2848
	       YYABORT;
          }
          opt_place
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2849
	| DROP opt_column field_ident opt_restrict
2850 2851 2852 2853 2854
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
					    $3.str)); lex->simple_alter=0;
	  }
2855
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
2856 2857 2858
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
2859 2860 2861
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    primary_key_name));
	    lex->simple_alter=0;
2862
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2863
	| DROP key_or_index field_ident
2864 2865 2866 2867 2868 2869
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
2870 2871
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
2872
	| ALTER opt_column field_ident SET DEFAULT signed_literal
2873 2874 2875 2876 2877
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2878
	| ALTER opt_column field_ident DROP DEFAULT
2879 2880 2881 2882 2883
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
2884
	| RENAME opt_to table_ident
2885
	  {
2886
	    LEX *lex=Lex;
2887
	    lex->select_lex.db=$3->db.str;
2888
	    lex->name= $3->table.str;
2889
	  }
2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903
	| 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;
	    }
2904
	    LEX *lex= Lex;
monty@mysql.com's avatar
monty@mysql.com committed
2905 2906 2907 2908
	    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);
2909
	    lex->simple_alter= 0;
2910
	  }
2911
        | create_table_options_space_separated { Lex->simple_alter=0; }
2912
	| order_clause         { Lex->simple_alter=0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2913 2914 2915

opt_column:
	/* empty */	{}
2916
	| COLUMN_SYM	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2917 2918 2919

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
2920
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2921 2922 2923 2924

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
2925
	| CASCADE	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2926 2927 2928 2929

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
2930
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2931 2932 2933 2934

opt_to:
	/* empty */	{}
	| TO_SYM	{}
2935
	| EQ		{}
2936
	| AS		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2937

nick@mysql.com's avatar
nick@mysql.com committed
2938
/*
2939
  SLAVE START and SLAVE STOP are deprecated. We keep them for compatibility.
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2940 2941
*/

bk@work.mysql.com's avatar
bk@work.mysql.com committed
2942
slave:
2943 2944 2945 2946 2947 2948 2949
	  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
2950
            /* If you change this code don't forget to update SLAVE START too */
2951 2952 2953
          }
          slave_until
          {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2954 2955 2956 2957 2958
        | 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
2959
            /* If you change this code don't forget to update SLAVE STOP too */
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
2960
          }
2961 2962 2963 2964 2965
	| SLAVE START_SYM slave_thread_opts
         {
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
2966 2967 2968 2969 2970
	    /* We'll use mi structure for UNTIL options */
	    bzero((char*) &lex->mi, sizeof(lex->mi));
          }
          slave_until
          {}
2971 2972 2973 2974 2975 2976 2977 2978
	| 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
2979

2980 2981 2982 2983 2984
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

2985
slave_thread_opts:
2986 2987
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
2988
        {}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
2989
	;
2990 2991

slave_thread_opt_list:
2992
	slave_thread_opt
2993 2994
	| slave_thread_opt_list ',' slave_thread_opt
	;
2995 2996

slave_thread_opt:
2997
	/*empty*/	{}
2998
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
2999
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
3000
	;
3001

3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023
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 ;


3024 3025 3026 3027 3028
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
3029
	table_list FROM TEXT_STRING_sys
3030 3031
        {
	  Lex->backup_dir = $6.str;
3032
        };
3033

3034 3035 3036 3037 3038
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
3039
	table_list TO_SYM TEXT_STRING_sys
3040 3041
        {
	  Lex->backup_dir = $6.str;
3042
        };
3043

3044 3045 3046 3047 3048 3049
checksum:
        CHECKSUM_SYM table_or_tables
	{
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECKSUM;
	}
3050 3051
	table_list opt_checksum_type
        {}
3052 3053
	;

3054 3055 3056 3057 3058 3059
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
3060
repair:
3061
	REPAIR opt_no_write_to_binlog table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3062
	{
3063 3064
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
3065
           lex->no_write_to_binlog= $2;
3066
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3067
	}
3068 3069 3070
	table_list opt_mi_repair_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3071

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3072
opt_mi_repair_type:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3073
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
3074
	| mi_repair_types {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3075

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3076 3077
mi_repair_types:
	mi_repair_type {}
3078
	| mi_repair_type mi_repair_types {};
3079

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3080
mi_repair_type:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3081
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
3082
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
3083
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3084 3085

analyze:
3086
	ANALYZE_SYM opt_no_write_to_binlog table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3087
	{
3088 3089
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
3090
           lex->no_write_to_binlog= $2;
3091
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3092
	}
3093 3094 3095
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3096 3097

check:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
3098
	CHECK_SYM table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3099
	{
3100 3101 3102
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3103
	}
3104 3105 3106
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3107

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3108 3109
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
3110
	| mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3111 3112 3113

mi_check_types:
	mi_check_type {}
3114
	| mi_check_type mi_check_types {};
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
3115 3116 3117 3118 3119 3120

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3123
optimize:
3124
	OPTIMIZE opt_no_write_to_binlog table_or_tables
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3125
	{
3126 3127
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3128
           lex->no_write_to_binlog= $2;
3129
	   lex->check_opt.init();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3130
	}
3131 3132 3133
	table_list opt_mi_check_type
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3134

3135 3136 3137
opt_no_write_to_binlog:
	/* empty */        { $$= 0; }
	| NO_WRITE_TO_BINLOG  { $$= 1; }
3138
	| LOCAL_SYM  { $$= 1; }
3139 3140
	;

3141 3142 3143 3144 3145
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
3146 3147 3148
	table_to_table_list
	{}
	;
3149 3150 3151

table_to_table_list:
	table_to_table
3152
	| table_to_table_list ',' table_to_table;
3153 3154 3155

table_to_table:
	table_ident TO_SYM table_ident
3156
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3157
	  LEX *lex=Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3158
	  SELECT_LEX *sl= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3159 3160 3161 3162
	  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))
3163
	    YYABORT;
3164
	};
3165

igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3166
keycache:
3167
        CACHE_SYM INDEX keycache_list IN_SYM key_cache_name
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3168 3169
        {
          LEX *lex=Lex;
3170 3171
          lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
	  lex->name_and_length= $5;
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3172 3173 3174 3175 3176 3177 3178 3179
        }
        ;

keycache_list:
        assign_to_keycache
        | keycache_list ',' assign_to_keycache;

assign_to_keycache:
3180
        table_ident cache_keys_spec
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3181 3182 3183 3184 3185 3186
        {
          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(),
3187
                                      (List<String> *)0))
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3188 3189 3190 3191
            YYABORT;
        }
        ;

3192 3193 3194
key_cache_name:
	ident	   { $$= $1; }
	| DEFAULT  { $$ = default_key_cache_base; }
3195
	;
3196

igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3197
preload:
3198
	LOAD INDEX INTO CACHE_SYM
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
	{
	  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
3212
	table_ident cache_keys_spec opt_ignore_leaves
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3213 3214 3215
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3216 3217
	  if (!sel->add_table_to_list(lex->thd, $1, NULL, $3,
                                      TL_READ,
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3218 3219 3220 3221 3222 3223
                                      sel->get_use_index(),
                                      (List<String> *)0))
            YYABORT;
	}
	;

3224
cache_keys_spec:
3225
        { Select->interval_list.empty(); }
3226 3227 3228 3229 3230 3231 3232
        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
3233

igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3234
cache_key_list_or_empty:
3235
	/* empty */	{ Lex->select_lex.use_index_ptr= 0; }
3236
	| opt_key_or_index '(' key_usage_list2 ')'
3237 3238 3239 3240
	  {
            SELECT_LEX *sel= &Lex->select_lex;
	    sel->use_index_ptr= &sel->use_index;
	  }
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3241 3242
	;

3243
opt_ignore_leaves:
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
3244 3245 3246 3247 3248
	/* empty */
	{ $$= 0; }
	| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3249
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3250
  Select : retrieve data from table
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3251 3252 3253 3254
*/


select:
3255 3256 3257 3258 3259
	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
3260 3261
	}
	;
3262

3263
/* Need select_init2 for subselects. */
3264
select_init:
3265
	SELECT_SYM select_init2
3266
	|
3267 3268
	'(' SELECT_SYM select_part2 ')'
	  {
3269
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3270
            SELECT_LEX * sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3271
	    if (sel->set_braces(1))
3272
	    {
3273
	      yyerror(ER(ER_SYNTAX_ERROR));
3274 3275
	      YYABORT;
	    }
3276 3277
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3278
	  {
3279
	    yyerror(ER(ER_SYNTAX_ERROR));
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3280 3281
	    YYABORT;
	  }
3282
            /* select in braces, can't contain global parameters */
3283 3284 3285
	    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
3286
          } union_opt;
3287

3288 3289
select_init2:
	select_part2
3290
        {
3291
	  LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3292
          SELECT_LEX * sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3293
          if (lex->current_select->set_braces(0))
3294
	  {
3295
	    yyerror(ER(ER_SYNTAX_ERROR));
3296 3297
	    YYABORT;
	  }
3298 3299
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3300
	  {
3301
	    yyerror(ER(ER_SYNTAX_ERROR));
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
3302 3303
	    YYABORT;
	  }
3304
	}
3305
	union_clause
3306 3307
	;

3308
select_part2:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3309
	{
3310 3311 3312
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
	  lex->lock_option= TL_READ;
3313 3314
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
3315 3316 3317 3318 3319
	  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
3320
	}
3321
	select_into select_lock_type;
3322

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3323
select_into:
3324 3325 3326 3327 3328 3329
	opt_limit_clause {}
	| FROM DUAL_SYM /* oracle compatibility: oracle always requires FROM
                           clause, and DUAL is system table without fields.
                           Is "SELECT 1 FROM DUAL" any better than
                           "SELECT 1" ? Hmmm :) */
        | into
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3330
	| select_from
3331 3332
	| into select_from
	| select_from into;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3333 3334

select_from:
3335
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3336 3337 3338

select_options:
	/* empty*/
3339
	| select_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3340 3341 3342

select_option_list:
	select_option_list select_option
3343
	| select_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3344 3345

select_option:
3346
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
3347 3348 3349 3350 3351 3352
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
3353 3354 3355
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367
	| 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;
	  }
3368
	| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
3369 3370 3371 3372
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
3373 3374
	| ALL		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3375

monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3376 3377 3378
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
3379 3380
	  {
	    LEX *lex=Lex;
3381
	    lex->current_select->set_lock_for_tables(TL_WRITE);
3382
	    lex->safe_to_cache_query=0;
3383
	  }
3384
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
3385 3386
	  {
	    LEX *lex=Lex;
3387 3388
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
3389
	    lex->safe_to_cache_query=0;
3390 3391
	  }
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
3392

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3393 3394 3395 3396 3397
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
3398 3399
	    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
3400
	      YYABORT;
pem@mysql.com's avatar
pem@mysql.com committed
3401
	    (thd->lex->current_select->with_wild)++;
3402
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3403 3404 3405 3406 3407


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3408
	    if (add_item_to_list(YYTHD, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3409 3410
	      YYABORT;
	    if ($4.str)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3411
	      $2->set_name($4.str,$4.length,system_charset_info);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3412
	    else if (!$2->name)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3413
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
3414
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3415 3416

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

remember_end:
3420
	{ $$=(char*) Lex->tok_end; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3421 3422 3423

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

select_alias:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3427 3428 3429 3430 3431 3432
	/* 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
3433 3434 3435

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3438
/* all possible expressions */
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3439 3440 3441 3442
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3443

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455
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
3456 3457
/* expressions that begin with 'expr' */
expr_expr:
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
3458
	 expr IN_SYM '(' expr_list ')'
3459
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3460
	| expr NOT IN_SYM '(' expr_list ')'
3461
	  { $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
3462
        | expr IN_SYM in_subselect
3463
          { $$= new Item_in_subselect($1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3464
	| expr NOT IN_SYM in_subselect
3465
          {
3466
            $$= new Item_func_not(new Item_in_subselect($1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3467
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3468 3469 3470 3471
	| expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
3472
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3473
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
3474
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3475
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3476 3477 3478 3479 3480 3481 3482 3483 3484
	| 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
3485
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3486 3487
	| 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
3488 3489 3490
	| 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
3491
	| expr comp_op expr %prec EQ	{ $$= (*$2)(0)->create($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3492 3493
	| expr comp_op all_or_any in_subselect %prec EQ
	{
3494
	  $$= all_any_subquery_creator($1, $2, $3, $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3495
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3496 3497 3498 3499 3500 3501
	| 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); }
3502 3503
	| 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
3504
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
3505
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3506 3507
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
3508 3509 3510 3511
	| 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
3512
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3513 3514 3515 3516 3517 3518 3519

/* expressions that begin with 'expr' that do NOT follow IN_SYM */
no_in_expr:
	no_in_expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| no_in_expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
3520
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3521
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
3522
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3523
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3524 3525 3526 3527 3528 3529 3530 3531 3532
	| 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
3533
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3534 3535
	| 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
3536 3537 3538
	| 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
3539
	| 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
3540 3541
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
3542
	  all_any_subquery_creator($1, $2, $3, $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3543
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3544 3545 3546 3547 3548 3549
	| 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); }
3550
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3551
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
3552
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3553 3554
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
3555
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
3556 3557 3558 3559
	| 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); }
3560
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3561 3562 3563

/* 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
3564
	  no_and_expr IN_SYM '(' expr_list ')'
3565
	  { $4->push_front($1); $$= new Item_func_in(*$4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3566
	| no_and_expr NOT IN_SYM '(' expr_list ')'
3567
	  { $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
3568
        | no_and_expr IN_SYM in_subselect
3569
          { $$= new Item_in_subselect($1, $3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3570
	| no_and_expr NOT IN_SYM in_subselect
3571
          {
3572
            $$= new Item_func_not(new Item_in_subselect($1, $4));
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3573
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3574 3575 3576 3577
	| no_and_expr BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_between($1,$3,$5); }
	| no_and_expr NOT BETWEEN_SYM no_and_expr AND expr
	  { $$= new Item_func_not(new Item_func_between($1,$4,$6)); }
3578
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3579
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
3580
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3581 3582 3583 3584 3585 3586 3587 3588 3589
	| 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
3590
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3591 3592
	| 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
3593 3594 3595
	| 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
3596
	| 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
3597 3598
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
3599
	  all_any_subquery_creator($1, $2, $3, $4);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
3600
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3601 3602 3603 3604 3605 3606
	| 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); }
3607
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3608
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
3609
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3610 3611
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
3612
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
3613 3614 3615 3616
	| 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); }
3617
	| simple_expr;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3618

3619
interval_expr:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3620
         INTERVAL_SYM expr { $$=$2; }
3621 3622
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
3623 3624
simple_expr:
	simple_ident
3625
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3626
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3627 3628 3629
	    $$= new Item_func_set_collation($1,
					    new Item_string($3.str,
							    $3.length,
3630
                                                            YYTHD->charset()));
3631
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3632
	| literal
3633
	| param_marker
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3634
	| '@' ident_or_text SET_VAR expr
3635 3636
	  {
	    $$= new Item_func_set_user_var($2,$4);
3637
	    Lex->uncacheable(UNCACHEABLE_RAND);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3638
	  }
3639
	| '@' ident_or_text
3640 3641
	  {
	    $$= new Item_func_get_user_var($2);
3642
	    Lex->uncacheable(UNCACHEABLE_RAND);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3643
	  }
3644
	| '@' '@' opt_var_ident_type ident_or_text opt_component
3645
	  {
3646 3647 3648 3649 3650 3651

            if ($4.str && $5.str && check_reserved_words(&$4))
            {
              yyerror(ER(ER_SYNTAX_ERROR));
              YYABORT;
            }
3652
	    if (!($$= get_system_var(YYTHD, (enum_var_type) $3, $4, $5)))
3653
	      YYABORT;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3654
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3655
	| sum_expr
3656 3657
	| '+' expr %prec NEG	{ $$= $2; }
	| '-' expr %prec NEG    { $$= new Item_func_neg($2); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3658 3659 3660 3661
	| '~' 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; }
3662 3663 3664 3665 3666
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
3667
	| ROW_SYM '(' expr ',' expr_list ')'
3668
	  {
3669 3670
	    $5->push_front($3);
	    $$= new Item_row(*$5);
3671
	  }
3672
	| EXISTS exists_subselect { $$= $2; }
3673
	| singlerow_subselect   { $$= $1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3674
	| '{' ident expr '}'	{ $$= $3; }
3675
        | MATCH ident_list_arg AGAINST '(' expr fulltext_options ')'
3676
          { $2->push_front($5);
3677 3678
            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
3679
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3680
	| BINARY expr %prec NEG
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
3681
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3682 3683
	    $$= 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
3684
	  }
3685
	| CAST_SYM '(' expr AS cast_type ')'
3686 3687
	  {
	    $$= create_func_cast($3, $5,
3688
				 Lex->length ? atoi(Lex->length) : -1,
3689
				 Lex->charset);
3690
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3691
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
3692
	  { $$= new Item_func_case(* $4, $2, $5 ); }
3693
	| CONVERT_SYM '(' expr ',' cast_type ')'
3694 3695 3696 3697 3698
	  {
	    $$= create_func_cast($3, $5,
				 Lex->length ? atoi(Lex->length) : -1,
				 Lex->charset);
	  }
3699 3700
	| 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
3701 3702
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
3703 3704
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3705
	| FUNC_ARG0 '(' ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
3706 3707 3708 3709 3710
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3711
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
3712 3713 3714 3715 3716
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(void))($1.symbol->create_func))();
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3717
	| FUNC_ARG1 '(' expr ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
3718 3719 3720 3721 3722
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3723
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
3724 3725 3726 3727 3728
	                 $1.symbol->group->needed_define);
	      YYABORT;
	    }
	    $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3729
	| FUNC_ARG2 '(' expr ',' expr ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
3730 3731 3732 3733 3734
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3735
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
3736 3737 3738 3739 3740
	                 $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
3741
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
hf@deer.(none)'s avatar
hf@deer.(none) committed
3742 3743 3744 3745 3746
	  {
	    if (!$1.symbol->create_func)
	    {
	      net_printf(Lex->thd, ER_FEATURE_DISABLED,
			 ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3747
			 $1.symbol->group->name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
3748 3749 3750 3751 3752
	                 $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
3753 3754 3755 3756
	| 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); }
3757 3758
	| REPEAT_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_repeat($3,$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3759 3760 3761 3762 3763 3764
	| 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); }
3765 3766
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3767 3768
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
3769 3770
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3771 3772 3773 3774 3775
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
3776
	  { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3777
	| CURTIME optional_braces
3778
	  { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3779
	| CURTIME '(' expr ')'
3780
	  {
3781
	    $$= new Item_func_curtime_local($3);
3782
	    Lex->safe_to_cache_query=0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3783
	  }
3784
	| CURRENT_USER optional_braces
3785
          { $$= create_func_current_user(); }
3786 3787 3788 3789
	| 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
3790
	| DATABASE '(' ')'
3791
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3792
	    $$= new Item_func_database();
3793
            Lex->safe_to_cache_query=0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3794
	  }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
3795
	| DATE_SYM '(' expr ')'
3796
	  { $$= new Item_date_typecast($3); }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
3797 3798
	| DAY_SYM '(' expr ')'
	  { $$= new Item_func_dayofmonth($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3799
	| ELT_FUNC '(' expr ',' expr_list ')'
3800
	  { $5->push_front($3); $$= new Item_func_elt(*$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3801 3802
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3803 3804 3805
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
3806
	    Lex->uncacheable(UNCACHEABLE_RAND);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3807
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3808
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
3809
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3810
	  { $$= new Item_func_decode($3,$5.str); }
3811
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3812
	 { $$= new Item_func_encode($3,$5.str); }
3813
	| DES_DECRYPT_SYM '(' expr ')'
3814
        { $$= new Item_func_des_decrypt($3); }
3815
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
3816
        { $$= new Item_func_des_decrypt($3,$5); }
3817
	| DES_ENCRYPT_SYM '(' expr ')'
3818
        { $$= new Item_func_des_encrypt($3); }
3819
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
3820
        { $$= new Item_func_des_encrypt($3,$5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3821 3822 3823 3824 3825 3826
	| 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); }
3827 3828
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3829 3830 3831 3832 3833 3834
	| 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
3835
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3836 3837
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
3838
	  { $5->push_front($3); $$= new Item_func_field(*$5); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
3839 3840 3841 3842 3843 3844 3845
	| geometry_function
	  {
#ifdef HAVE_SPATIAL
	    $$= $1;
#else
	    net_printf(Lex->thd, ER_FEATURE_DISABLED,
	               ER(ER_FEATURE_DISABLED),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
3846
	               sym_group_geom.name, sym_group_geom.needed_define);
hf@deer.(none)'s avatar
hf@deer.(none) committed
3847 3848 3849
	    YYABORT;
#endif
	  }
3850
	| GET_FORMAT '(' date_time_type  ',' expr ')'
3851
	  { $$= new Item_func_get_format($3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3852 3853 3854 3855 3856 3857
	| 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); }
3858
	| interval_expr interval '+' expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3859
	  /* we cannot put interval before - */
3860 3861 3862 3863 3864
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
3865
              yyerror(ER(ER_SYNTAX_ERROR));
3866 3867 3868 3869
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3870 3871
	| LAST_INSERT_ID '(' ')'
	  {
3872
	    $$= new Item_func_last_insert_id();
3873
	    Lex->safe_to_cache_query= 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3874 3875 3876
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
3877
	    $$= new Item_func_last_insert_id($3);
3878
	    Lex->safe_to_cache_query= 0;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3879 3880 3881 3882 3883 3884 3885
	  }
	| 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); }
3886
	| GREATEST_SYM '(' expr ',' expr_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3887 3888 3889
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
3890
	| LOG_SYM '(' expr ')'
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
3891
	  { $$= new Item_func_log($3); }
3892
	| LOG_SYM '(' expr ',' expr ')'
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
3893
	  { $$= new Item_func_log($3, $5); }
3894
	| MASTER_POS_WAIT '(' expr ',' expr ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3895
	  {
3896
	    $$= new Item_master_pos_wait($3, $5);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3897
	    Lex->safe_to_cache_query=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3898
		  }
3899
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3900
	  {
3901
	    $$= new Item_master_pos_wait($3, $5, $7);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
3902
	    Lex->safe_to_cache_query=0;
3903
	  }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
3904 3905
	| MICROSECOND_SYM '(' expr ')'
	  { $$= new Item_func_microsecond($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3906 3907
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
3908 3909
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3910 3911 3912
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
	| NOW_SYM optional_braces
3913
	  { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3914
	| NOW_SYM '(' expr ')'
3915
	  { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3916
	| PASSWORD '(' expr ')'
3917
	  {
3918 3919
	    $$= YYTHD->variables.old_passwords ?
              (Item *) new Item_func_old_password($3) :
3920 3921 3922 3923
	      (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
3924 3925
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
3926 3927
	| QUARTER_SYM '(' expr ')'
	  { $$ = new Item_func_quarter($3); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3928
	| RAND '(' expr ')'
3929
	  { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3930
	| RAND '(' ')'
3931
	  { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3932 3933 3934 3935 3936 3937 3938
	| 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); }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
3939 3940 3941 3942
	| 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
3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954
	| 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
3955
	| TIME_SYM '(' expr ')'
3956 3957 3958
	  { $$= 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
3959
	| TIMESTAMP '(' expr ',' expr ')'
3960
	  { $$= new Item_func_add_time($3, $5, 1, 0); }
3961 3962 3963 3964
	| 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
3965
	| TRIM '(' expr ')'
3966 3967
	  { $$= new Item_func_trim($3); }
	| TRIM '(' LEADING expr FROM expr ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3968
	  { $$= new Item_func_ltrim($6,$4); }
3969
	| TRIM '(' TRAILING expr FROM expr ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3970
	  { $$= new Item_func_rtrim($6,$4); }
3971
	| TRIM '(' BOTH expr FROM expr ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3972
	  { $$= new Item_func_trim($6,$4); }
3973 3974 3975 3976 3977 3978
	| 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
3979 3980
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
3981 3982
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
3983 3984
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
3985
	| ident '.' ident '(' udf_expr_list ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
3986
	  {
3987 3988
	    LEX *lex= Lex;
	    sp_name *name= new sp_name($1, $3);
3989

3990 3991 3992 3993
	    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
3994
	    else
3995 3996 3997 3998
	      $$= new Item_func_sp(name);
	  }
	| IDENT_sys '(' udf_expr_list ')'
          {
3999
#ifdef HAVE_DLOPEN
4000
            udf_func *udf;
4001

4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057
            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
4058
#endif /* HAVE_DLOPEN */
4059 4060 4061 4062 4063 4064 4065 4066
            {
              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);
4067
	    }
4068
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4069
	| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
4070
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4071 4072
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4073
	| UNIX_TIMESTAMP '(' ')'
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4074 4075
	  {
	    $$= new Item_func_unix_timestamp();
4076
	    Lex->safe_to_cache_query=0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4077
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4078 4079 4080
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
4081
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
4082 4083 4084 4085 4086 4087
	| 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
4088
	| WEEK_SYM '(' expr ')'
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4089
	  {
4090
            $$= new Item_func_week($3,new Item_int((char*) "0",
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4091
				   YYTHD->variables.default_week_format,1));
4092
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4093 4094 4095 4096 4097 4098 4099 4100 4101
	| 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 ')'
4102
	  {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4103
	    $$=new Item_func_benchmark($3,$5);
4104
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4105
	  }
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4106
	| EXTRACT_SYM '(' interval FROM expr ')'
4107
	{ $$=new Item_extract( $3, $5); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4108

hf@deer.(none)'s avatar
hf@deer.(none) committed
4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119
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,
4120 4121
                           Geometry::wkb_geometrycollection,
                           Geometry::wkb_point)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4122 4123
	| LINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4124
                  Geometry::wkb_linestring, Geometry::wkb_point)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4125 4126
 	| MULTILINESTRING '(' expr_list ')'
	  { $$= GEOM_NEW( Item_func_spatial_collection(* $3,
4127
                   Geometry::wkb_multilinestring, Geometry::wkb_linestring)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141
 	| 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,
4142
                  Geometry::wkb_multipoint, Geometry::wkb_point)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4143 4144
 	| MULTIPOLYGON '(' expr_list ')'
	  { $$= GEOM_NEW(Item_func_spatial_collection(* $3,
4145
                  Geometry::wkb_multipolygon, Geometry::wkb_polygon)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157
	| 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,
4158
	          Geometry::wkb_polygon, Geometry::wkb_linestring)); }
hf@deer.(none)'s avatar
hf@deer.(none) committed
4159 4160 4161 4162 4163 4164 4165 4166 4167 4168
 	| 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)); }
	;

4169 4170 4171 4172 4173 4174
fulltext_options:
        /* nothing */                   { $$= FT_NL;  }
        | WITH QUERY_SYM EXPANSION_SYM  { $$= FT_NL | FT_EXPAND; }
        | IN_SYM BOOLEAN_SYM MODE_SYM   { $$= FT_BOOL; }
        ;

4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207
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
4208 4209 4210 4211 4212 4213 4214
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); }
4215 4216
	| BIT_XOR  '(' in_sum_expr ')'
	  { $$=new Item_sum_xor($3); }
4217
	| COUNT_SYM '(' opt_all '*' ')'
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4218 4219 4220
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
4221
	| COUNT_SYM '(' DISTINCT
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4222
	  { Select->in_sum_expr++; }
4223
	   expr_list
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4224
	  { Select->in_sum_expr--; }
4225 4226
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4227 4228 4229 4230
	| 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); }
4231 4232 4233 4234 4235 4236 4237
/*
   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
4238 4239
	| MAX_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_max($3); }
4240 4241
	| MAX_SYM '(' DISTINCT in_sum_expr ')'
	  { $$=new Item_sum_max($4); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4242 4243
	| STD_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_std($3); }
4244 4245
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4246
	| SUM_SYM '(' in_sum_expr ')'
4247
	  { $$=new Item_sum_sum($3); }
4248 4249
	| SUM_SYM '(' DISTINCT in_sum_expr ')'
	  { $$=new Item_sum_sum_distinct($4); }
monty@mysql.com's avatar
monty@mysql.com committed
4250 4251 4252 4253 4254
	| 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
4255
	  {
monty@mysql.com's avatar
monty@mysql.com committed
4256 4257 4258
	    Select->in_sum_expr--;
	    $$=new Item_func_group_concat($3,$5,Select->gorder_list,$7);
	    $5->empty();
4259 4260 4261 4262 4263 4264 4265
	  };

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

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

4269 4270

opt_gorder_clause:
4271 4272
	  /* empty */
	  {
4273
            Select->gorder_list = NULL;
4274 4275 4276
	  }
	| order_clause
          {
4277 4278 4279
            SELECT_LEX *select= Select;
            select->gorder_list=
	      (SQL_LIST*) sql_memdup((char*) &select->order_list,
4280
				     sizeof(st_sql_list));
4281
	    select->order_list.empty();
4282
	  };
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4283

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4284 4285

in_sum_expr:
4286
	opt_all
4287 4288 4289 4290
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
4291
	    yyerror(ER(ER_SYNTAX_ERROR));
4292
	    YYABORT;
4293 4294
	  }
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4295 4296
	expr
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4297
	  Select->in_sum_expr--;
4298
	  $$= $3;
4299
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4300

4301
cast_type:
4302
	BINARY opt_len		{ $$=ITEM_CAST_CHAR; Lex->charset= &my_charset_bin; }
4303 4304
	| CHAR_SYM opt_len opt_binary	{ $$=ITEM_CAST_CHAR; }
	| NCHAR_SYM opt_len	{ $$=ITEM_CAST_CHAR; Lex->charset= national_charset_info; }
4305 4306 4307 4308 4309 4310 4311
	| 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; }
4312
	;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4313

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4314
expr_list:
4315
	{ Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4316
	expr_list2
4317
	{ $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4318 4319

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

4323 4324
ident_list_arg:
          ident_list          { $$= $1; }
4325
        | '(' ident_list ')'  { $$= $2; };
4326

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4327
ident_list:
4328
        { Select->expr_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4329
        ident_list2
4330
        { $$= Select->expr_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4331 4332

ident_list2:
4333
        simple_ident { Select->expr_list.head()->push_back($1); }
4334
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4335 4336 4337

opt_expr:
	/* empty */      { $$= NULL; }
4338
	| expr           { $$= $1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4339 4340 4341

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

when_list:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4345
        { Select->when_list.push_front(new List<Item>); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4346
	when_list2
4347
	{ $$= Select->when_list.pop(); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4348 4349

when_list2:
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4350
	expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4351
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4352
	    SELECT_LEX *sel=Select;
4353 4354
	    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
4355
	}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4356
	| when_list2 WHEN_SYM expr THEN_SYM expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4357
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4358
	    SELECT_LEX *sel=Select;
4359 4360
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
4361
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4362 4363 4364 4365

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
4366
	| join_table_list ',' join_table_list { $$=$3; }
4367
	| join_table_list normal_join join_table_list { $$=$3; }
4368
	| join_table_list STRAIGHT_JOIN join_table_list
4369
	  { $$=$3 ; $1->next->straight=1; }
4370 4371 4372
	| join_table_list normal_join join_table_list ON expr
	  { add_join_on($3,$5); $$=$3; }
	| join_table_list normal_join join_table_list
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4373
	  USING
4374
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4375
	    SELECT_LEX *sel= Select;
4376
	    sel->db1=$1->db; sel->table1=$1->alias;
4377
	    sel->db2=$3->db; sel->table2=$3->alias;
4378
	  }
4379 4380 4381
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

4382
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
4383
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
4384
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
4385
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4386
	    SELECT_LEX *sel= Select;
4387 4388
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
4389
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4390
	  USING '(' using_list ')'
4391
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
4392
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
4393 4394 4395 4396 4397
	  {
	    add_join_natural($1,$1->next);
	    $1->next->outer_join|=JOIN_TYPE_LEFT;
	    $$=$6;
	  }
4398
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
4399
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
4400
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
4401
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4402
	    SELECT_LEX *sel= Select;
4403 4404
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
4405
	  }
4406
	  USING '(' using_list ')'
4407
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
4408
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
4409 4410 4411 4412 4413
	  {
	    add_join_natural($1->next,$1);
	    $1->outer_join|=JOIN_TYPE_RIGHT;
	    $$=$6;
	  }
4414
	| join_table_list NATURAL JOIN_SYM join_table_list
4415
	  { add_join_natural($1,$1->next); $$=$4; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4416 4417

normal_join:
4418 4419 4420 4421
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4422 4423

join_table:
4424
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4425
	  SELECT_LEX *sel= Select;
4426
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4427
	  sel->table_join_options= 0;
4428
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4429
        table_ident opt_table_alias opt_key_definition
4430
	{
4431
	  LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4432
	  SELECT_LEX *sel= lex->current_select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4433
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4434
					   sel->get_table_join_options(),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4435
					   lex->lock_option,
4436 4437
					   sel->get_use_index(),
					   sel->get_ignore_index())))
4438
	    YYABORT;
4439
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4440
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
4441
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
4442
        | '(' SELECT_SYM select_derived ')' opt_table_alias
4443 4444
	{
	  LEX *lex=Lex;
4445 4446 4447
	  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
4448
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
4449
				  TL_READ,(List<String> *)0,
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4450 4451
	                          (List<String> *)0)))

4452
	    YYABORT;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4453
	};
4454

4455
select_derived:
4456
        {
4457
	  LEX *lex= Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4458
	  lex->derived_tables= 1;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4459 4460 4461
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
4462 4463
	  {
	    yyerror(ER(ER_SYNTAX_ERROR));
4464 4465
	    YYABORT;
	  }
4466
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
4467
              mysql_new_select(lex, 1))
4468 4469
	    YYABORT;
	  mysql_init_select(lex);
4470
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
4471 4472 4473 4474 4475
	  lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
	}
        select_options select_item_list
	{
	  Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
4476
	}
4477
	opt_select_from union_opt
4478
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4479 4480 4481

opt_outer:
	/* empty */	{}
4482
	| OUTER		{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4483 4484 4485 4486

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
4487
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4488
	    SELECT_LEX *sel= Select;
4489 4490 4491
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4492 4493
	| FORCE_SYM key_usage_list
          {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4494
	    SELECT_LEX *sel= Select;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4495 4496 4497 4498
	    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
4499
	| IGNORE_SYM key_usage_list
4500
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4501
	    SELECT_LEX *sel= Select;
4502 4503
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
4504
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4505 4506

key_usage_list:
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4507
	key_or_index { Select->interval_list.empty(); }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4508
        '(' key_list_or_empty ')'
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4509
        { $$= &Select->interval_list; }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4510 4511 4512 4513 4514 4515
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4516 4517 4518

key_usage_list2:
	key_usage_list2 ',' ident
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4519
        { Select->
monty@mysql.com's avatar
monty@mysql.com committed
4520
	    interval_list.push_back(new (&YYTHD->mem_root) String((const char*) $3.str, $3.length,
4521
				    system_charset_info)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4522
	| ident
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4523
        { Select->
monty@mysql.com's avatar
monty@mysql.com committed
4524
	    interval_list.push_back(new (&YYTHD->mem_root) String((const char*) $1.str, $1.length,
4525
				    system_charset_info)); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4526
	| PRIMARY_SYM
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4527
        { Select->
monty@mysql.com's avatar
monty@mysql.com committed
4528
	    interval_list.push_back(new (&YYTHD->mem_root) String("PRIMARY", 7,
4529
				    system_charset_info)); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4530 4531 4532

using_list:
	ident
4533
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4534
	    SELECT_LEX *sel= Select;
4535 4536 4537 4538
	    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
4539 4540 4541 4542
	      YYABORT;
	  }
	| using_list ',' ident
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4543
	    SELECT_LEX *sel= Select;
4544
	    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
4545
	      YYABORT;
4546
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4547 4548

interval:
4549 4550
	interval_time_st	{}
	| DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
4551
	| DAY_MICROSECOND_SYM	{ $$=INTERVAL_DAY_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4552 4553
	| 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
4554
	| HOUR_MICROSECOND_SYM	{ $$=INTERVAL_HOUR_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4555 4556
	| 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
4557 4558
	| MICROSECOND_SYM	{ $$=INTERVAL_MICROSECOND; }
	| MINUTE_MICROSECOND_SYM	{ $$=INTERVAL_MINUTE_MICROSECOND; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4559
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
4560 4561 4562 4563 4564 4565 4566 4567
	| 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
4568 4569
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
4570
	| QUARTER_SYM		{ $$=INTERVAL_QUARTER; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4571
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
4572
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4573

4574 4575 4576 4577
date_time_type:
	DATE_SYM		{$$=TIMESTAMP_DATE;}
	| TIME_SYM		{$$=TIMESTAMP_TIME;}
	| DATETIME		{$$=TIMESTAMP_DATETIME;};
4578

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4579 4580 4581
table_alias:
	/* empty */
	| AS
4582
	| EQ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4583 4584 4585 4586

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

4589 4590 4591 4592
opt_all:
	/* empty */
	| ALL
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4593 4594

where_clause:
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4595
	/* empty */  { Select->where= 0; }
4596 4597
	| WHERE expr
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4598
	    Select->where= $2;
4599 4600 4601
	    if ($2)
	      $2->top_level_item();
	  }
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4602
 	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4603 4604 4605

having_clause:
	/* empty */
4606 4607
	| HAVING
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4608
	    Select->parsing_place= SELECT_LEX_NODE::IN_HAVING;
4609 4610
          }
	  expr
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4611
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4612
	    SELECT_LEX *sel= Select;
4613 4614
	    sel->having= $3;
	    sel->parsing_place= SELECT_LEX_NODE::NO_MATTER;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4615 4616 4617
	    if ($3)
	      $3->top_level_item();
	  }
4618
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4619 4620

opt_escape:
4621
	ESCAPE_SYM TEXT_STRING_literal	{ $$= $2.str; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4622
	| /* empty */			{ $$= (char*) "\\"; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4623 4624 4625


/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4626
   group by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4627 4628 4629 4630
*/

group_clause:
	/* empty */
4631
	| GROUP BY group_list olap_opt;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4632 4633

group_list:
4634
	group_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4635
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
4636
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4637
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4638

4639 4640
olap_opt:
	/* empty */ {}
4641
	| WITH CUBE_SYM
4642
          {
4643
	    LEX *lex=Lex;
4644 4645 4646 4647 4648 4649
	    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
4650
	    lex->current_select->olap= CUBE_TYPE;
4651
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
4652
	    YYABORT;	/* To be deleted in 5.1 */
4653
	  }
4654
	| WITH ROLLUP_SYM
4655
          {
4656 4657 4658 4659 4660 4661 4662
	    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
4663
	    lex->current_select->olap= ROLLUP_TYPE;
4664
	  }
4665
	;
4666

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4667
/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4668
   Order by statement in select
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4669 4670
*/

4671
opt_order_clause:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4672
	/* empty */
4673
	| order_clause;
4674 4675

order_clause:
4676 4677
	ORDER_SYM BY
        {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4678
	  LEX *lex=Lex;
4679
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4680
	      lex->current_select->olap !=
4681
	      UNSPECIFIED_OLAP_TYPE)
4682
	  {
4683
	    net_printf(lex->thd, ER_WRONG_USAGE,
4684 4685 4686 4687
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
4688
	} order_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4689 4690 4691

order_list:
	order_list ',' order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4692
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4693
	| order_ident order_dir
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4694
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4695 4696 4697

order_dir:
	/* empty */ { $$ =  1; }
4698
	| ASC  { $$ =1; }
4699
	| DESC { $$ =0; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4700 4701


4702 4703 4704
opt_limit_clause_init:
	/* empty */
	{
4705 4706
	  LEX *lex= Lex;
	  SELECT_LEX *sel= lex->current_select;
4707
          sel->offset_limit= 0L;
4708 4709 4710
          sel->select_limit= (&lex->select_lex == sel) ?
	    Lex->thd->variables.select_limit :	/* primary SELECT */
	    HA_POS_ERROR;			/* subquery */
4711
	}
4712 4713 4714
	| limit_clause {}
	;

4715 4716 4717 4718 4719
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

4720
limit_clause:
4721
	LIMIT limit_options {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4722
	;
4723 4724 4725

limit_options:
	ULONG_NUM
4726
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4727
            SELECT_LEX *sel= Select;
4728 4729 4730 4731 4732
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4733
	    SELECT_LEX *sel= Select;
4734 4735
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
4736
	  }
4737
	| ULONG_NUM OFFSET_SYM ULONG_NUM
4738
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
4739
	    SELECT_LEX *sel= Select;
4740 4741 4742 4743
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4744 4745 4746 4747 4748


delete_limit_clause:
	/* empty */
	{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4749
	  LEX *lex=Lex;
4750
	  lex->current_select->select_limit= HA_POS_ERROR;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4751
	}
4752
	| LIMIT ulonglong_num
4753
	{ Select->select_limit= (ha_rows) $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4754 4755

ULONG_NUM:
4756
	NUM	    { $$= strtoul($1.str,NULL,10); }
4757
	| LONG_NUM  { $$= (ulong) strtoll($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4758
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
4759
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
4760
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4761

4762
ulonglong_num:
4763
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4764
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
4765
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
4766
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
4767
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4768 4769 4770 4771 4772 4773

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
4774 4775 4776 4777 4778 4779 4780
	    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
4781 4782 4783
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
4784
	    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
4785
	      YYABORT;
4786
	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4787
	  }
4788
	  '(' procedure_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4789 4790 4791 4792


procedure_list:
	/* empty */ {}
4793
	| procedure_list2 {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4794 4795 4796

procedure_list2:
	procedure_list2 ',' procedure_item
4797
	| procedure_item;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4798 4799 4800 4801

procedure_item:
	  remember_name expr
	  {
4802 4803
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4804 4805
	      YYABORT;
	    if (!$2->name)
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4806
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
4807 4808 4809 4810 4811 4812
	  }
          ;


select_var_list_init:
	   {
4813 4814
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
4815 4816
	        YYABORT;
	   }
4817
	   select_var_list
4818
	   {}
4819
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4820

Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4821
select_var_list:
4822 4823 4824 4825
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

4826 4827
select_var_ident:  
	   '@' ident_or_text
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4828
           {
4829
             LEX *lex=Lex;
4830
	     if (lex->result) 
4831
	       ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
4832
	     else
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4833 4834
	       YYABORT;
	   }
4835
           | ident_or_text
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4836
           {
4837
             LEX *lex=Lex;
4838
	     sp_pvar_t *t;
4839 4840

	     if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1)))
4841
	     {
4842
	       net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str);
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4843
	       YYABORT;
4844
	     }
4845
	     if (! lex->result)
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4846
	       YYABORT;
4847 4848
	     else
	     {
4849
	       ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset,t->type));
4850 4851
	       t->isset= TRUE;
	     }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4852
	   }
4853
           ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4854

4855
into:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4856
        INTO OUTFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4857
	{
4858
	  LEX *lex=Lex;
4859 4860
	  if (!lex->describe)
	  {
4861
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4862 4863 4864 4865 4866
	    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
4867 4868
	}
	opt_field_term opt_line_term
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
4869
	| INTO DUMPFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4870
	{
4871
	  LEX *lex=Lex;
4872 4873
	  if (!lex->describe)
	  {
4874
	    lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4875 4876 4877 4878 4879
	    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
4880
	}
4881
        | INTO select_var_list_init
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
4882
	{
4883
	  Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
4884 4885
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4886

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4887 4888 4889
/*
  DO statement
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4890

4891
do:	DO_SYM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
4892 4893 4894 4895 4896 4897
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
4898 4899 4900 4901
	values
	{}
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
4902
/*
4903
  Drop : delete tables or index or user
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4904 4905 4906
*/

drop:
serg@serg.mylan's avatar
serg@serg.mylan committed
4907
	DROP opt_temporary table_or_tables if_exists table_list opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4908
	{
4909 4910
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
4911 4912
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4913 4914 4915
	}
	| DROP INDEX ident ON table_ident {}
	  {
4916 4917 4918 4919
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
	     lex->drop_list.empty();
	     lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4920
						     $3.str));
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4921 4922
	     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
4923 4924 4925 4926
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
4927 4928 4929 4930
	    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
4931
	 }
4932
	| DROP FUNCTION_SYM if_exists sp_name opt_restrict
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4933
	  {
4934 4935
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
4936
	    lex->drop_if_exists= $3;
4937
	    lex->spname= $4;
4938
	  }
4939
	| DROP PROCEDURE if_exists sp_name opt_restrict
4940 4941 4942
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_PROCEDURE;
4943
	    lex->drop_if_exists= $3;
4944
	    lex->spname= $4;
4945 4946 4947 4948 4949 4950
	  }
	| 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
4951
	  }
4952 4953 4954
	  user_list
	  {}
	  ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4955 4956

table_list:
4957
	table_name
4958
	| table_list ',' table_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4959

4960
table_name:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4961
	table_ident
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4962 4963 4964 4965 4966
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4967 4968

if_exists:
4969
	/* empty */ { $$= 0; }
4970 4971
	| IF EXISTS { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4972

4973 4974 4975 4976
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4977 4978 4979 4980 4981
/*
** Insert : add new data to table
*/

insert:
4982 4983 4984 4985 4986 4987
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
4988
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
4989
	} insert_lock_option
4990
	opt_ignore insert2
4991
	{
4992
	  Select->set_lock_for_tables($3);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
4993
	  Lex->current_select= &Lex->select_lex;
4994
	}
4995
	insert_field_spec opt_insert_update
4996
	{}
4997
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
4998 4999

replace:
5000 5001
	REPLACE
	{
5002
	  LEX *lex=Lex;
5003 5004
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
5005
	  lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE;
5006
	}
5007 5008
	replace_lock_option insert2
	{
5009
	  Select->set_lock_for_tables($3);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5010
	  Lex->current_select= &Lex->select_lex;
5011 5012
	}
	insert_field_spec
5013
	{}
5014
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5015 5016

insert_lock_option:
5017 5018 5019 5020
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
5021
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5022 5023

replace_lock_option:
5024 5025
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5026 5027 5028

insert2:
	INTO insert_table {}
5029
	| insert_table {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5030 5031

insert_table:
5032
	table_name
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5033
	{
5034 5035 5036 5037
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
5038
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5039 5040

insert_field_spec:
serg@serg.mylan's avatar
serg@serg.mylan committed
5041 5042 5043
	insert_values {}
	| '(' ')' insert_values {}
	| '(' fields ')' insert_values {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5044 5045
	| SET
	  {
5046 5047 5048
	    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
5049 5050
	      YYABORT;
	   }
5051
	   ident_eq_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5052 5053 5054 5055

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
5056
	| '(' ')'	  { };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5057 5058 5059

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
5060
	| insert_ident		{ Lex->field_list.push_back($1); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5061 5062 5063

insert_values:
	VALUES	values_list  {}
5064
	| VALUE_SYM values_list  {}
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5065 5066
	|     create_select     { Select->set_braces(0);} union_clause {}
	| '(' create_select ')' { Select->set_braces(1);} union_opt {}
5067
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5068 5069 5070

values_list:
	values_list ','  no_braces
5071
	| no_braces;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5072 5073 5074 5075

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
5076
	ident_eq_value;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5077 5078

ident_eq_value:
5079
	simple_ident_nospvar equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5080
	 {
5081 5082 5083
	  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
5084
	    YYABORT;
5085
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5086 5087

equal:	EQ		{}
5088 5089 5090 5091 5092 5093 5094
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5095 5096 5097 5098 5099 5100 5101 5102 5103

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
5104 5105
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5106
	    YYABORT;
5107
	 };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5108 5109 5110

opt_values:
	/* empty */ {}
5111
	| values;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5112 5113

values:
5114
	values ','  expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5115 5116 5117 5118
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
5119 5120 5121 5122 5123 5124 5125 5126
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
5127
	expr	  { $$= $1;}
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
5128
	| DEFAULT {$$= new Item_default_value(); }
5129
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5130

5131 5132
opt_insert_update:
        /* empty */
5133
        | ON DUPLICATE_SYM
5134 5135 5136 5137 5138
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
5139
	      yyerror(ER(ER_SYNTAX_ERROR));
5140 5141 5142
              YYABORT;
            }
          }
5143
          KEY_SYM UPDATE_SYM update_list
5144 5145
        ;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5146 5147 5148
/* Update rows in a table */

update:
5149 5150
	UPDATE_SYM
	{
5151
	  LEX *lex= Lex;
5152
	  mysql_init_select(lex);
5153
          lex->sql_command= SQLCOM_UPDATE;
5154
	  lex->lock_option= TL_UNLOCK; 	/* Will be set later */
5155
        }
5156 5157 5158
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
5159
	  LEX *lex= Lex;
5160
	  Select->set_lock_for_tables($3);
5161
          if (lex->select_lex.table_list.elements > 1)
5162
            lex->sql_command= SQLCOM_UPDATE_MULTI;
5163 5164 5165 5166 5167 5168 5169
	  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;
	  }
5170 5171
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5172 5173

update_list:
5174
	update_list ',' simple_ident_nospvar equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5175
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5176
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5177 5178
	    YYABORT;
	}
5179
	| simple_ident_nospvar equal expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5180
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5181
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5182
	      YYABORT;
5183
	  };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5184 5185

opt_low_priority:
5186
	/* empty */	{ $$= YYTHD->update_lock_default; }
5187
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5188 5189 5190 5191

/* Delete rows from a table */

delete:
5192
	DELETE_SYM
5193
	{
5194 5195
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
5196
	  lex->lock_option= lex->thd->update_lock_default;
5197
	  lex->select_lex.init_order();
5198
	}
5199 5200
	opt_delete_options single_multi {}
	;
5201 5202

single_multi:
5203 5204
 	FROM table_ident
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5205 5206
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
5207 5208 5209
	    YYABORT;
	}
	where_clause opt_order_clause
5210
	delete_limit_clause {}
5211
	| table_wild_list
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5212
	  { mysql_init_multi_delete(Lex); }
5213
          FROM join_table_list where_clause
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5214 5215
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
5216 5217 5218
	  USING join_table_list where_clause
	  {}
	;
5219 5220 5221

table_wild_list:
	  table_wild_one {}
5222
	  | table_wild_list ',' table_wild_one {};
5223 5224

table_wild_one:
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5225
	ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5226
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5227 5228
	  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
5229 5230
	    YYABORT;
        }
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
5231
	| ident '.' ident opt_wild opt_table_alias
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5232
	  {
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5233 5234
	    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
5235 5236
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
5237
	      YYABORT;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5238
	  }
5239
	;
5240 5241

opt_wild:
5242
	/* empty */	{}
5243
	| '.' '*'	{};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5244 5245


5246
opt_delete_options:
5247
	/* empty */	{}
5248
	| opt_delete_option opt_delete_options {};
5249 5250

opt_delete_option:
5251
	QUICK		{ Select->options|= OPTION_QUICK; }
5252 5253
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
	| IGNORE_SYM	{ Lex->duplicates= DUP_IGNORE; };
5254

5255
truncate:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
5256
	TRUNCATE_SYM opt_table_sym table_name
5257
	{
5258
	  LEX* lex= Lex;
5259
	  lex->sql_command= SQLCOM_TRUNCATE;
5260
	  lex->select_lex.options= 0;
5261
	  lex->select_lex.init_order();
5262 5263
	}
	;
5264

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5265 5266
opt_table_sym:
	/* empty */
5267
	| TABLE_SYM;
5268

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5269 5270
/* Show things */

5271 5272
show:	SHOW
	{
5273 5274 5275 5276
	  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
5277
	show_param
5278 5279
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5280 5281 5282 5283 5284

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
5285
	  {
5286
	    LEX *lex= Lex;
5287
	    lex->sql_command= SQLCOM_SHOW_TABLES;
5288 5289
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
5290
	   }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5291
	| TABLE_SYM STATUS_SYM opt_db wild
5292
	  {
5293
	    LEX *lex= Lex;
5294
	    lex->sql_command= SQLCOM_SHOW_TABLES;
5295 5296
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5297
	  }
5298
	| OPEN_SYM TABLES opt_db wild
5299
	  {
5300
	    LEX *lex= Lex;
5301
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
5302 5303
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
5304
	  }
5305
	| ENGINE_SYM storage_engines 
5306 5307
	  { Lex->create_info.db_type= $2; }
	  show_engine_param
5308
	| opt_full COLUMNS from_or_in table_ident opt_db wild
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5309 5310
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5311 5312
	    if ($5)
	      $4->change_db($5);
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5313
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5314 5315
	      YYABORT;
	  }
5316
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5317
	  TEXT_STRING_sys AND MASTER_LOG_POS_SYM EQ ulonglong_num
5318
	  AND MASTER_SERVER_ID_SYM EQ
5319 5320 5321 5322 5323
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
5324
	    Lex->mi.server_id = $16;
5325
          }
5326
        | master_or_binary LOGS_SYM
5327 5328
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
5329 5330 5331 5332 5333
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
5334
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
5335
          {
5336 5337
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
5338
          } opt_limit_clause_init
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5339 5340 5341 5342 5343
	| 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
5344
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5345 5346
	      YYABORT;
	  }
5347 5348 5349 5350 5351 5352 5353 5354
	| COLUMN_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
	  }
	| TABLE_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
5355 5356 5357 5358 5359 5360 5361
	    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;
5362 5363 5364 5365 5366 5367
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
5368
        | COUNT_SYM '(' '*' ')' WARNINGS
5369
          { (void) create_select_for_variable("warning_count"); }
5370
        | COUNT_SYM '(' '*' ')' ERRORS
5371
	  { (void) create_select_for_variable("error_count"); }
5372
        | WARNINGS opt_limit_clause_init
5373
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
5374
        | ERRORS opt_limit_clause_init
5375
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5376 5377
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
5378
        | INNOBASE_SYM STATUS_SYM
5379
          { 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
5380 5381
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
5382
	| opt_var_type VARIABLES wild
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5383
	  {
5384
	    THD *thd= YYTHD;
5385 5386
	    thd->lex->sql_command= SQLCOM_SHOW_VARIABLES;
	    thd->lex->option_type= (enum_var_type) $1;
5387
	  }
5388
	| charset wild
5389
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
5390 5391
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
5392
	| BERKELEY_DB_SYM LOGS_SYM
5393
	  { 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
5394
	| LOGS_SYM
5395
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW LOGS", "SHOW ENGINE BDB LOGS"); }
5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418
	| 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
5419
	| GRANTS FOR_SYM user
5420 5421 5422 5423 5424 5425
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
5426
	| CREATE DATABASE opt_if_not_exists ident
5427 5428
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5429 5430
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
5431
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5432 5433 5434
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5435
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5436 5437 5438 5439 5440
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5441
          }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5442 5443 5444
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
5445
          }
5446
	| CREATE PROCEDURE sp_name
5447
	  {
5448 5449 5450 5451
	    LEX *lex= Lex;

	    lex->sql_command = SQLCOM_SHOW_CREATE_PROC;
	    lex->spname= $3;
5452
	  }
5453
	| CREATE FUNCTION_SYM sp_name
5454
	  {
5455 5456 5457 5458
	    LEX *lex= Lex;

	    lex->sql_command = SQLCOM_SHOW_CREATE_FUNC;
	    lex->spname= $3;
5459 5460 5461 5462 5463 5464 5465 5466 5467 5468
	  }
	| PROCEDURE STATUS_SYM wild
	  {
	    Lex->sql_command = SQLCOM_SHOW_STATUS_PROC;
	  }
	| FUNCTION_SYM STATUS_SYM wild
	  {
	    Lex->sql_command = SQLCOM_SHOW_STATUS_FUNC;
	  };

5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491
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
5492

5493 5494 5495 5496
master_or_binary:
	MASTER_SYM
	| BINARY;

5497 5498 5499 5500
opt_storage:
	/* empty */
	| STORAGE_SYM;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5501 5502
opt_db:
	/* empty */  { $$= 0; }
5503
	| from_or_in ident { $$= $2.str; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5504 5505 5506

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

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5509 5510
opt_full:
	/* empty */ { Lex->verbose=0; }
5511
	| FULL	    { Lex->verbose=1; };
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5512

5513 5514
from_or_in:
	FROM
5515
	| IN_SYM;
5516

5517 5518
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5519
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
5520 5521 5522

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


bk@work.mysql.com's avatar
bk@work.mysql.com committed
5526 5527 5528 5529
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
5530 5531 5532 5533
	  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
5534
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5535 5536
	    YYABORT;
	}
5537
	opt_describe_column {}
5538 5539 5540
	| describe_command opt_extended_describe
	  { Lex->describe|= DESCRIBE_NORMAL; }
	  select
5541
          {
5542
	    LEX *lex=Lex;
5543
	    lex->select_lex.options|= SELECT_DESCRIBE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5544 5545
	  }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5546 5547 5548

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

5551 5552 5553 5554 5555
opt_extended_describe:
	/* empty */ {}
	| EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; }
	;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5556 5557 5558
opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
5559
	| ident
monty@mysql.com's avatar
monty@mysql.com committed
5560
	  { 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
5561 5562 5563 5564 5565


/* flush things */

flush:
5566
	FLUSH_SYM opt_no_write_to_binlog
5567 5568 5569
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5570
          lex->no_write_to_binlog= $2;
5571
	}
5572 5573 5574
	flush_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5575 5576 5577

flush_options:
	flush_options ',' flush_option
5578
	| flush_option;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5579 5580

flush_option:
5581
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5582
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5583
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5584 5585 5586 5587
	| 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
5588 5589
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
5590 5591
	| 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
5592

5593
opt_table_list:
5594 5595
	/* empty */  {;}
	| table_list {;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5596

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5597
reset:
5598 5599 5600 5601
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
5602 5603 5604 5605
	} reset_options
	{}
	;

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5606 5607
reset_options:
	reset_options ',' reset_option
5608
	| reset_option;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5609 5610

reset_option:
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
5611 5612
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
5613
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5614

5615
purge:
5616 5617 5618 5619
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
5620 5621 5622 5623 5624
	} purge_options
	{}
	;

purge_options:
5625
	master_or_binary LOGS_SYM purge_option
5626
	;
5627 5628

purge_option:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5629
        TO_SYM TEXT_STRING_sys
5630 5631 5632 5633 5634 5635 5636 5637 5638
        {
	   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
5639
	    YYABORT;
5640 5641
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
5642
	  /*
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5643
	    it is OK only emulate fix_fieds, because we need only
5644 5645
            value of constant
	  */
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5646
	  tmp->quick_fix_field();
5647
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
5648
	  Lex->purge_time= (ulong) tmp->val_int();
5649
	}
5650
	;
5651

bk@work.mysql.com's avatar
bk@work.mysql.com committed
5652 5653 5654
/* kill threads */

kill:
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
5655
	KILL_SYM kill_option expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5656
	{
5657
	  LEX *lex=Lex;
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
5658
	  if ($3->fix_fields(lex->thd, 0, &$3) || $3->check_cols(1))
5659
	  {
5660
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
5661 5662 5663
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
5664
	  lex->thread_id= (ulong) $3->val_int();
5665
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5666

hf@genie.(none)'s avatar
SCRUM  
hf@genie.(none) committed
5667 5668 5669 5670 5671
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
5672 5673 5674
/* change database */

use:	USE_SYM ident
5675 5676
	{
	  LEX *lex=Lex;
5677 5678
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
5679
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5680 5681 5682

/* import, export of files */

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5683
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5684
	{
5685 5686
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
5687 5688
	  lex->lock_option= $3;
	  lex->local_file=  $4;
5689
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5690
	    YYABORT;
5691
	  lex->field_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5692 5693 5694 5695
	}
	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
5696
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5697 5698 5699
	    YYABORT;
	}
        |
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5700
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5701 5702
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5703
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5704
	    YYABORT;
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
5705 5706

        }
5707 5708 5709 5710
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
5711
        };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5712 5713 5714

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

5717
load_data_lock:
5718
	/* empty */	{ $$= YYTHD->update_lock_default; }
5719 5720
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
5721 5722


bk@work.mysql.com's avatar
bk@work.mysql.com committed
5723 5724 5725
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
5726
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5727 5728 5729

opt_field_term:
	/* empty */
5730
	| COLUMNS field_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5731 5732 5733

field_term_list:
	field_term_list field_term
5734
	| field_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5735 5736 5737 5738

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
5739 5740 5741 5742 5743
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5744
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
5745
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5746 5747 5748

opt_line_term:
	/* empty */
5749
	| LINES line_term_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5750 5751 5752

line_term_list:
	line_term_list line_term
5753
	| line_term;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5754 5755 5756

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
5757
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5758 5759 5760 5761

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
5762
	  { Lex->exchange->skip_lines=atol($2.str); };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5763 5764 5765 5766

/* Common definitions */

text_literal:
5767
	TEXT_STRING_literal
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5768 5769
	{
	  THD *thd= YYTHD;
5770
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5771
	}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5772
	| NCHAR_STRING
5773
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
5774
	| UNDERSCORE_CHARSET TEXT_STRING
5775
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
5776
	| text_literal TEXT_STRING_literal
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
5777 5778
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5779 5780

text_string:
5781
	TEXT_STRING_literal
monty@mysql.com's avatar
monty@mysql.com committed
5782
	{ $$=  new (&YYTHD->mem_root) String($1.str,$1.length,YYTHD->variables.collation_connection); }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5783 5784
	| HEX_NUM
	  {
5785
	    Item *tmp = new Item_varbinary($1.str,$1.length);
5786
	    /*
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5787
	      it is OK only emulate fix_fieds, because we need only
5788 5789 5790
              value of constant
	    */
	    $$= tmp ?
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5791
	      tmp->quick_fix_field(), tmp->val_str((String*) 0) :
5792
	      (String*) 0;
5793 5794 5795
	  }
	;

5796
param_marker:
5797
        '?'
5798
        {
5799 5800 5801
          THD *thd=YYTHD;
	  LEX *lex= thd->lex;
          if (thd->command == COM_PREPARE)
5802
          {
5803 5804 5805 5806 5807 5808 5809
            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;
            }
5810
          }
5811
          else
5812
          {
5813
            yyerror(ER(ER_SYNTAX_ERROR));
5814 5815
            YYABORT;
          }
5816 5817 5818
        }
	;

5819 5820 5821
signed_literal:
	literal		{ $$ = $1; }
	| '+' NUM_literal { $$ = $2; }
5822 5823
	| '-' NUM_literal
	  {
5824
	    $2->max_length++;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5825
	    $$= $2->neg();
5826
	  }
5827 5828 5829
	;


bk@work.mysql.com's avatar
bk@work.mysql.com committed
5830 5831
literal:
	text_literal	{ $$ =	$1; }
5832
	| NUM_literal	{ $$ = $1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5833
	| NULL_SYM	{ $$ =	new Item_null();
5834
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
5835
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
5836
	| UNDERSCORE_CHARSET HEX_NUM
5837
	  {
5838
	    Item *tmp= new Item_varbinary($2.str,$2.length);
5839
	    /*
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5840
	      it is OK only emulate fix_fieds, because we need only
5841 5842 5843
              value of constant
	    */
	    String *str= tmp ?
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5844
	      tmp->quick_fix_field(), tmp->val_str((String*) 0) :
5845
	      (String*) 0;
5846 5847 5848
	    $$= new Item_string(str ? str->ptr() : "",
				str ? str->length() : 0,
				Lex->charset);
5849
	  }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5850 5851
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
5852
	| TIMESTAMP text_literal { $$ = $2; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5853

5854 5855 5856 5857 5858 5859 5860 5861
NUM_literal:
	NUM		{ $$ =	new Item_int($1.str, (longlong) strtol($1.str, NULL, 10),$1.length); }
	| LONG_NUM	{ $$ =	new Item_int($1.str, (longlong) strtoll($1.str,NULL,10), $1.length); }
	| 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
5862 5863 5864 5865 5866
/**********************************************************************
** Createing different items.
**********************************************************************/

insert_ident:
5867
	simple_ident_nospvar { $$=$1; }
5868
	| table_wild	 { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5869 5870

table_wild:
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5871
	ident '.' '*'
5872 5873
	{
	  $$ = new Item_field(NullS,$1.str,"*");
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5874
	  Lex->current_select->with_wild++;
5875
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5876
	| ident '.' ident '.' '*'
5877 5878 5879 5880
	{
	  $$ = 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
5881
	  Lex->current_select->with_wild++;
5882 5883
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5884 5885

order_ident:
5886
	expr { $$=$1; };
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5887 5888 5889

simple_ident:
	ident
5890
	{
5891 5892 5893 5894 5895 5896 5897 5898
	  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)
	    {
5899 5900 5901
	      push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
	                          ER_SP_UNINIT_VAR, ER(ER_SP_UNINIT_VAR),
				  $1.str);
5902
	    }
5903
	    $$ = (Item*) new Item_splocal($1, spv->offset);
5904 5905 5906
	  }
	  else
	  {
pem@mysql.com's avatar
pem@mysql.com committed
5907
	    SELECT_LEX *sel=Select;
5908 5909 5910
	    $$= (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
5911
	         (Item*) new Item_ref(0,0, NullS,NullS,$1.str);
5912
	  }
pem@mysql.comhem.se's avatar
pem@mysql.comhem.se committed
5913
        }
5914 5915 5916 5917 5918 5919 5920 5921 5922 5923
        | 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
5924
	      (Item*) new Item_ref(0,0,NullS,NullS,$1.str);
5925 5926 5927 5928 5929 5930
	}
	| simple_ident_q { $$= $1; }
	;	

simple_ident_q:
	ident '.' ident
5931
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5932
	  THD *thd= YYTHD;
5933
	  LEX *lex= thd->lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5934
	  SELECT_LEX *sel= lex->current_select;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5935 5936
	  if (sel->no_table_names_allowed)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5937
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5938 5939 5940
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
5941 5942 5943
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$1.str,$3.str) :
hf@deer.(none)'s avatar
hf@deer.(none) committed
5944
	      (Item*) new Item_ref(0,0,NullS,$1.str,$3.str);
5945
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5946
	| '.' ident '.' ident
5947
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5948
	  THD *thd= YYTHD;
5949
	  LEX *lex= thd->lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5950
	  SELECT_LEX *sel= lex->current_select;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5951 5952
	  if (sel->no_table_names_allowed)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5953
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5954 5955 5956
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
5957 5958 5959
	  $$= (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
5960
              (Item*) new Item_ref(0,0,NullS,$2.str,$4.str);
5961
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5962
	| ident '.' ident '.' ident
5963
	{
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5964
	  THD *thd= YYTHD;
5965
	  LEX *lex= thd->lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5966
	  SELECT_LEX *sel= lex->current_select;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5967 5968
	  if (sel->no_table_names_allowed)
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
5969
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
5970 5971 5972
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
5973 5974 5975 5976 5977
	  $$= (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
5978 5979
	      (Item*) new Item_ref(0,0,(YYTHD->client_capabilities &
				        CLIENT_NO_SCHEMA ? NullS : $1.str),
5980
                                   $3.str, $5.str);
5981
	};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5982 5983 5984 5985 5986


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
5987
	| '.' ident		{ $$=$2;}	/* For Delphi */;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5988 5989 5990

table_ident:
	ident			{ $$=new Table_ident($1); }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
5991
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
5992 5993 5994 5995
	| '.' ident		{ $$=new Table_ident($2);} /* For Delphi */
        ;

table_ident_ref:
monty@mysql.com's avatar
monty@mysql.com committed
5996 5997
	ident			{ LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); }
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
5998
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
5999

bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6000
IDENT_sys:
6001 6002 6003 6004 6005 6006 6007 6008 6009 6010
	IDENT { $$= $1; }
	| IDENT_QUOTED
	  {
	    THD *thd= YYTHD;
	    if (thd->charset_is_system_charset)
	      $$= $1;
	    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
6011 6012 6013 6014 6015 6016
	;

TEXT_STRING_sys:
	TEXT_STRING
	{
	  THD *thd= YYTHD;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6017 6018
	  if (thd->charset_is_system_charset)
	    $$= $1;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6019
	  else
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6020 6021
	    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
6022 6023 6024
	}
	;

6025
TEXT_STRING_literal:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6026 6027 6028
	TEXT_STRING
	{
	  THD *thd= YYTHD;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6029 6030
	  if (thd->charset_is_collation_connection)
	    $$= $1;
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6031
	  else
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6032 6033
	    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
6034 6035 6036 6037
	}
	;


bk@work.mysql.com's avatar
bk@work.mysql.com committed
6038
ident:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6039
	IDENT_sys	    { $$=$1; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6040 6041
	| keyword
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6042 6043 6044
	  THD *thd= YYTHD;
	  $$.str=    thd->strmake($1.str, $1.length);
	  $$.length= $1.length;
6045 6046
	}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6047 6048

ident_or_text:
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6049 6050 6051
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6052 6053 6054 6055

user:
	ident_or_text
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6056 6057
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6058
	    YYABORT;
6059 6060 6061 6062
	  $$->user = $1;
	  $$->host.str= (char *) "%";
	  $$->host.length= 1;
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6063 6064
	| ident_or_text '@' ident_or_text
	  {
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6065 6066
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6067 6068
	      YYABORT;
	    $$->user = $1; $$->host=$3;
6069
	  }
6070
	| CURRENT_USER optional_braces
6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087
	{
          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
6088 6089 6090 6091 6092

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
6093
	| ADDDATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6094
	| AFTER_SYM		{}
6095
	| AGAINST		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6096
	| AGGREGATE_SYM		{}
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6097
	| ANY_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6098
	| ASCII_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6099
	| AUTO_INC		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6100 6101
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
6102
	| BACKUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6103
	| BEGIN_SYM		{}
6104
	| BERKELEY_DB_SYM	{}
6105
	| BINLOG_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6106 6107
	| BIT_SYM		{}
	| BOOL_SYM		{}
6108
	| BOOLEAN_SYM		{}
6109
	| BYTE_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6110
	| BTREE_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6111
	| CACHE_SYM		{}
6112
	| CHANGED		{}
6113
	| CHARSET		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6114
	| CHECKSUM_SYM		{}
6115
	| CIPHER_SYM		{}
6116
	| CLIENT_SYM		{}
6117
	| CLOSE_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6118
	| COLLATION_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6119
	| COMMENT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6120
	| COMMITTED_SYM		{}
6121
	| COMMIT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6122
	| COMPRESSED_SYM	{}
6123
	| CONCURRENT		{}
6124
	| CUBE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6125 6126 6127 6128
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
6129
	| DEFINER_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6130
	| DELAY_KEY_WRITE_SYM	{}
6131 6132
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6133
	| DISCARD		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6134
	| DO_SYM		{}
6135
	| DUAL_SYM		{}
6136 6137
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6138 6139 6140
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
6141
	| ENGINE_SYM		{}
6142
	| ENGINES_SYM		{}
6143
	| ERRORS		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6144
	| ESCAPE_SYM		{}
6145
	| EVENTS_SYM		{}
6146
	| EXECUTE_SYM		{}
6147
        | EXPANSION_SYM         {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6148
	| EXTENDED_SYM		{}
6149
	| FAST_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6150 6151
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6152
	| FULL			{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6153 6154 6155 6156
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
6157
	| GEOMETRY_SYM		{}
6158
	| GEOMETRYCOLLECTION	{}
6159
	| GET_FORMAT		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6160
	| GRANTS		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6161
	| GLOBAL_SYM		{}
6162
	| HANDLER_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6163
	| HASH_SYM		{}
6164
	| HELP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6165 6166 6167
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
6168
	| INVOKER_SYM		{}
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6169
	| IMPORT		{}
6170
	| INDEXES		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6171
	| ISOLATION		{}
6172
	| ISSUER_SYM		{}
6173
	| INNOBASE_SYM		{}
6174
	| INSERT_METHOD		{}
6175
	| RELAY_THREAD		{}
6176
	| LANGUAGE_SYM          {}
6177
	| LAST_SYM		{}
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
6178
	| LEAVES                {}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6179
	| LEVEL_SYM		{}
6180
	| LINESTRING		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6181
	| LOCAL_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6182
	| LOCKS_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6183 6184 6185 6186 6187 6188 6189 6190 6191
	| 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	{}
6192
	| MASTER_SERVER_ID_SYM  {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6193
	| MASTER_CONNECT_RETRY_SYM	{}
6194 6195 6196 6197 6198 6199
	| 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
6200 6201 6202
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
6203
	| MEDIUM_SYM		{}
6204
	| MICROSECOND_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6205 6206 6207
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6208
	| MODE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6209
	| MONTH_SYM		{}
6210 6211 6212
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
6213
	| NAME_SYM              {}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6214
	| NAMES_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6215 6216
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
6217
	| NEXT_SYM		{}
6218
	| NEW_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6219
	| NO_SYM		{}
6220
	| NONE_SYM		{}
bar@bar.mysql.r18.ru's avatar
bar@bar.mysql.r18.ru committed
6221
	| NVARCHAR_SYM		{}
6222
	| OFFSET_SYM		{}
6223
	| OLD_PASSWORD		{}
6224
	| OPEN_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6225
	| PACK_KEYS_SYM		{}
6226
	| PARTIAL		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6227
	| PASSWORD		{}
6228
	| POINT_SYM		{}
6229
	| POLYGON		{}
6230
	| PREV_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6231 6232
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
6233
	| QUARTER_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6234
	| QUERY_SYM		{}
6235
	| QUICK			{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6236
	| RAID_0_SYM		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6237 6238
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6239
	| RAID_STRIPED_SYM	{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6240
	| RAID_TYPE		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6241 6242
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6243 6244
	| RELOAD		{}
	| REPAIR		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6245
	| REPEATABLE_SYM	{}
6246
	| REPLICATION		{}
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
6247
	| RESET_SYM		{}
6248
	| RESOURCES		{}
6249
	| RESTORE_SYM		{}
6250
	| RETURNS_SYM           {}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6251
	| ROLLBACK_SYM		{}
6252
	| ROLLUP_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6253 6254 6255
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6256
	| RTREE_SYM		{}
6257
	| SAVEPOINT_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6258
	| SECOND_SYM		{}
6259
	| SECURITY_SYM		{}
6260
	| SERIAL_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6261 6262
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6263
	| SIGNED_SYM		{}
6264
	| SIMPLE_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6265
	| SHARE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6266
	| SHUTDOWN		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6267
	| SLAVE			{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6268
	| SOUNDS_SYM		{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6269
	| SQL_CACHE_SYM		{}
6270
	| SQL_BUFFER_RESULT	{}
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6271
	| SQL_NO_CACHE_SYM	{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6272
	| SQL_THREAD		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6273 6274 6275
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
6276
	| STORAGE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6277
	| STRING_SYM		{}
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
6278
	| SUBDATE_SYM		{}
6279
	| SUBJECT_SYM		{}
6280
	| SUPER_SYM		{}
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6281
	| TABLESPACE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6282 6283
	| TEMPORARY		{}
	| TEXT_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6284
	| TRANSACTION_SYM	{}
6285
	| TRUNCATE_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6286
	| TIMESTAMP		{}
6287 6288
	| TIMESTAMP_ADD		{}
	| TIMESTAMP_DIFF	{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6289 6290
	| TIME_SYM		{}
	| TYPE_SYM		{}
6291
	| TYPES_SYM		{}
6292
	| FUNCTION_SYM		{}
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6293
	| UNCOMMITTED_SYM	{}
6294
	| UNICODE_SYM		{}
6295
	| UNTIL_SYM		{}
6296
	| USER			{}
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6297
	| USE_FRM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6298
	| VARIABLES		{}
6299
	| VALUE_SYM		{}
6300
	| WARNINGS		{}
6301
	| WEEK_SYM		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6302
	| WORK_SYM		{}
6303
	| X509_SYM		{}
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6304 6305
	| YEAR_SYM		{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6306 6307 6308 6309 6310 6311

/* Option functions */

set:
	SET opt_option
	{
6312 6313
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
6314
	  lex->option_type=OPT_SESSION;
6315
	  lex->var_list.empty();
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6316
	}
6317 6318 6319
	option_value_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6320 6321 6322

opt_option:
	/* empty */ {}
6323
	| OPTION {};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6324 6325

option_value_list:
6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337
	option_type option_value
	| option_value_list ',' option_type option_value;

option_type:
	/* empty */	{}
	| GLOBAL_SYM	{ Lex->option_type= OPT_GLOBAL; }
	| LOCAL_SYM	{ Lex->option_type= OPT_SESSION; }
	| SESSION_SYM	{ Lex->option_type= OPT_SESSION; }
	;

opt_var_type:
	/* empty */	{ $$=OPT_SESSION; }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6338
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
6339 6340 6341 6342 6343 6344
	| 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
6345
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
6346 6347 6348
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6349 6350

option_value:
6351
	  '@' ident_or_text equal expr
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6352
	  {
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6353 6354
	    Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
	  }
6355
	| internal_variable_name equal set_expr_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6356
	  {
6357
	    LEX *lex=Lex;
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6358 6359 6360 6361 6362 6363 6364 6365

	    if ($1.var)
	    { /* System variable */
	      lex->var_list.push_back(new set_var(lex->option_type, $1.var,
						  &$1.base_name, $3));
	    }
            else
	    { /* An SP local variable */
6366 6367 6368 6369
	      sp_pvar_t *spv;
              sp_instr_set *i;
	      Item *it;

6370 6371 6372 6373 6374
	      if ($3 && $3->type() == Item::SUBSELECT_ITEM)
	      {  /* QQ For now, just disallow subselects as values */
	        send_error(lex->thd, ER_SP_SUBSELECT_NYI);
	        YYABORT;
	      }
6375
	      spv= lex->spcont->find_pvar(&$1.base_name);
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6376

6377 6378 6379 6380 6381 6382 6383 6384
	      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
6385 6386 6387
	      lex->sphead->add_instr(i);
	      spv->isset= TRUE;
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6388
	  }
6389
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
6390 6391
	  {
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6392 6393
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4.var,
						&$4.base_name, $6));
6394 6395 6396 6397
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6398 6399 6400
	    LEX_STRING tmp;
	    tmp.str=0;
	    tmp.length=0;
6401
	    lex->var_list.push_back(new set_var(lex->option_type,
6402
						find_sys_var("tx_isolation"),
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6403
						&tmp,
6404
						new Item_int((int32) $4)));
6405
	  }
6406
	| charset old_or_new_charset_name_or_default
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6407
	{
6408
	  THD *thd= YYTHD;
6409
	  LEX *lex= Lex;
6410
	  $2= $2 ? $2: global_system_variables.character_set_client;
6411
	  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
6412
	}
6413
	| NAMES_SYM charset_name_or_default opt_collate
6414
	{
6415
	  THD *thd= YYTHD;
6416
	  LEX *lex= Lex;
6417
	  $2= $2 ? $2 : global_system_variables.character_set_client;
6418 6419
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
6420
	  {
6421 6422
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
6423
	  }
6424
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
6425
	}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6426
	| PASSWORD equal text_or_password
6427
	  {
6428
	    THD *thd=YYTHD;
6429
	    LEX_USER *user;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6430
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
6431 6432 6433
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
6434
	    thd->lex->var_list.push_back(new set_var_password(user, $3));
6435 6436
	  }
	| PASSWORD FOR_SYM user equal text_or_password
6437
	  {
6438 6439
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
6440
	;
6441

6442 6443 6444
internal_variable_name:
	ident
	{
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463
	  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;
	  }
6464
	}
6465 6466
	| ident '.' ident
	  {
6467 6468
            if (check_reserved_words(&$1))
            {
6469
	      yyerror(ER(ER_SYNTAX_ERROR));
6470 6471
              YYABORT;
            }
6472 6473 6474 6475 6476
	    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
6477 6478
	    $$.var= tmp;
	    $$.base_name= $1;
6479 6480 6481 6482 6483 6484 6485 6486
	  }
	| 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
6487 6488 6489
	    $$.var= tmp;
	    $$.base_name.str=    (char*) "default";
	    $$.base_name.length= 7;
6490
	  }
6491
        ;
6492 6493 6494 6495 6496 6497 6498

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
6500 6501 6502 6503
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
6504
	    $$= $3.length ? YYTHD->variables.old_passwords ?
6505 6506 6507 6508 6509 6510 6511 6512
	        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;
6513 6514
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6515

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

6517
set_expr_or_default:
6518 6519
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
6520 6521
	| 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
6522
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
6523
	;
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
6524 6525


bk@work.mysql.com's avatar
bk@work.mysql.com committed
6526 6527 6528 6529 6530 6531 6532
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
6533 6534 6535
	table_lock_list
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6536 6537 6538

table_or_tables:
	TABLE_SYM
6539
	| TABLES;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6540 6541 6542

table_lock_list:
	table_lock
6543
	| table_lock_list ',' table_lock;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6544 6545 6546

table_lock:
	table_ident opt_table_alias lock_option
6547
	{
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6548
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
6549 6550
	   YYABORT;
	}
6551
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6552 6553 6554

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
6555
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6556
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
6557 6558
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6559 6560

unlock:
6561 6562
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6563 6564


6565
/*
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6566
** Handler: direct access to ISAM functions
6567 6568 6569 6570 6571
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
6572 6573
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6574
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
6575 6576
	    YYABORT;
	}
6577
	| HANDLER_SYM table_ident_ref CLOSE_SYM
6578
	{
6579 6580
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6581
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
6582 6583
	    YYABORT;
	}
6584
	| HANDLER_SYM table_ident_ref READ_SYM
6585
	{
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
6586 6587 6588
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
6589 6590
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6591
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
6592
	    YYABORT;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6593
        }
6594
        handler_read_or_scan where_clause opt_limit_clause {}
6595
        ;
6596

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6597 6598
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
6599 6600
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6601 6602 6603

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
6604 6605
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6606 6607 6608 6609 6610 6611

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;  }
6612 6613
	| handler_rkey_mode
	{
6614 6615
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
6616
	  lex->ha_rkey_mode=$1;
6617
	  if (!(lex->insert_list = new List_item))
6618
	    YYABORT;
6619 6620
	} '(' values ')' { }
        ;
6621 6622

handler_rkey_mode:
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
6623 6624 6625 6626
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
6627 6628
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
6629

bk@work.mysql.com's avatar
bk@work.mysql.com committed
6630 6631 6632 6633 6634
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
6635 6636 6637 6638 6639
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
6640
	  lex->select_lex.db=0;
6641 6642
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
6643
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6644
	}
6645 6646 6647 6648 6649
	revoke_command
	{}
        ;

revoke_command:
6650 6651
	grant_privileges ON opt_table FROM user_list
	{}
6652
	|
6653
	ALL PRIVILEGES ',' GRANT OPTION FROM user_list
6654 6655 6656
	{
	  Lex->sql_command = SQLCOM_REVOKE_ALL;
	}
6657
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6658 6659 6660 6661

grant:
	GRANT
	{
6662 6663 6664
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
6665 6666
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
6667
	  lex->select_lex.db= 0;
6668 6669
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
6670
	  bzero((char *)&(lex->mqh),sizeof(lex->mqh));
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6671 6672
	}
	grant_privileges ON opt_table TO_SYM user_list
6673 6674 6675
	require_clause grant_options
	{}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6676 6677 6678

grant_privileges:
	grant_privilege_list {}
6679
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
6680 6681
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6682 6683 6684

grant_privilege_list:
	grant_privilege
6685
	| grant_privilege_list ',' grant_privilege;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6686 6687

grant_privilege:
serg@serg.mylan's avatar
serg@serg.mylan committed
6688
	SELECT_SYM	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
6689 6690 6691
	| 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 {}
6692 6693
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6694 6695 6696 6697
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
6698
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6699 6700 6701 6702
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
6703 6704 6705 6706 6707 6708 6709 6710
	| GRANT OPTION  { Lex->grant |= GRANT_ACL;}
	| SHOW DATABASES { Lex->grant |= SHOW_DB_ACL;}
	| SUPER_SYM	{ Lex->grant |= SUPER_ACL;}
	| CREATE TEMPORARY TABLES { Lex->grant |= CREATE_TMP_ACL;}
	| LOCK_SYM TABLES   { Lex->grant |= LOCK_TABLES_ACL; }
	| REPLICATION SLAVE  { Lex->grant |= REPL_SLAVE_ACL;}
	| REPLICATION CLIENT_SYM { Lex->grant |= REPL_CLIENT_ACL;}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6711

6712

6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
6725 6726 6727 6728
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
6729
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
6730 6731 6732 6733 6734 6735 6736 6737 6738
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
6739
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
6740 6741 6742 6743 6744 6745 6746 6747 6748
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
6749
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
6750 6751 6752 6753 6754
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
6755

bk@work.mysql.com's avatar
bk@work.mysql.com committed
6756 6757 6758
opt_table:
	'*'
	  {
6759
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6760
	    lex->current_select->db= lex->thd->db;
6761
	    if (lex->grant == GLOBAL_ACLS)
6762 6763
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6764
	    {
6765
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
6766
	      YYABORT;
6767
	    }
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6768 6769 6770
	  }
	| ident '.' '*'
	  {
6771
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6772
	    lex->current_select->db = $1.str;
6773
	    if (lex->grant == GLOBAL_ACLS)
6774 6775
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6776
	    {
6777
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6778 6779 6780 6781 6782
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
6783
	    LEX *lex= Lex;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
6784
	    lex->current_select->db = NULL;
6785 6786
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
6787
	    else if (lex->columns.elements)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6788
	    {
6789
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6790 6791 6792 6793 6794
	      YYABORT;
	    }
	  }
	| table_ident
	  {
6795
	    LEX *lex=Lex;
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6796
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6797
	      YYABORT;
6798
	    if (lex->grant == GLOBAL_ACLS)
6799
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
6800 6801
	  }
          ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6802 6803 6804


user_list:
6805 6806 6807 6808 6809 6810 6811
	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
6812 6813 6814 6815 6816 6817 6818 6819


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
6820
             if (YYTHD->variables.old_passwords)
6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837
             {
               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
6838 6839 6840 6841 6842
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
6843 6844
	  { $$=$1; $1->password.str=NullS; }
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6845 6846 6847


opt_column_list:
6848 6849 6850 6851 6852
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
6853
	| '(' column_list ')';
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6854 6855 6856

column_list:
	column_list ',' column_list_id
6857
	| column_list_id;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6858 6859 6860 6861

column_list_id:
	ident
	{
monty@mysql.com's avatar
monty@mysql.com committed
6862
	  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
6863 6864
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
6865
	  LEX *lex=Lex;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6866 6867
	  while ((point=iter++))
	  {
6868 6869
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6870 6871
		break;
	  }
6872
	  lex->grant_tot_col|= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6873
	  if (point)
6874
	    point->rights |= lex->which_columns;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6875
	  else
6876
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
6877 6878
	}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6879

tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
6880 6881

require_clause: /* empty */
6882
        | REQUIRE_SYM require_list
6883 6884 6885
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
6886
        | REQUIRE_SYM SSL_SYM
6887 6888 6889
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
6890
        | REQUIRE_SYM X509_SYM
6891 6892 6893 6894 6895 6896 6897
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
6898
          ;
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
6899

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6900
grant_options:
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6901
	/* empty */ {}
6902
	| WITH grant_option_list;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6903

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6904 6905
grant_option_list:
	grant_option_list grant_option {}
6906 6907
	| grant_option {}
        ;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6908 6909 6910

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
6911
        | MAX_QUERIES_PER_HOUR ULONG_NUM
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
6912
        {
6913
	  Lex->mqh.questions=$2;
6914
	  Lex->mqh.bits |= 1;
6915
	}
6916
        | MAX_UPDATES_PER_HOUR ULONG_NUM
6917
        {
6918
	  Lex->mqh.updates=$2;
6919
	  Lex->mqh.bits |= 2;
6920
	}
6921
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
6922
        {
6923
	  Lex->mqh.connections=$2;
6924
	  Lex->mqh.bits |= 4;
6925 6926
	}
        ;
6927

bk@work.mysql.com's avatar
bk@work.mysql.com committed
6928
begin:
6929 6930
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6931 6932 6933

opt_work:
	/* empty */ {}
6934 6935
	| WORK_SYM {;}
        ;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6936 6937

commit:
6938
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
bk@work.mysql.com's avatar
bk@work.mysql.com committed
6939 6940

rollback:
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
6941
	ROLLBACK_SYM
6942 6943 6944 6945 6946
	{
	  Lex->sql_command = SQLCOM_ROLLBACK;
	}
	| ROLLBACK_SYM TO_SYM SAVEPOINT_SYM ident
	{
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
6947
	  Lex->sql_command = SQLCOM_ROLLBACK_TO_SAVEPOINT;
6948 6949 6950 6951 6952 6953 6954 6955
	  Lex->savepoint_name = $4.str;
	};
savepoint:
	SAVEPOINT_SYM ident
	{
	  Lex->sql_command = SQLCOM_SAVEPOINT;
	  Lex->savepoint_name = $2.str;
	};
6956 6957

/*
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
6958
   UNIONS : glue selects together
6959 6960 6961
*/


6962
union_clause:
6963
	/* empty */ {}
6964 6965
	| union_list
	;
6966 6967

union_list:
6968
	UNION_SYM union_option
6969 6970 6971 6972 6973
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
6974
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
6975
	    YYABORT;
6976
	  }
6977
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
6978
	  {
6979
            yyerror(ER(ER_SYNTAX_ERROR));
6980 6981
	    YYABORT;
	  }
6982
	  if (mysql_new_select(lex, 0))
6983
	    YYABORT;
6984
          mysql_init_select(lex);
6985
	  lex->current_select->linkage=UNION_TYPE;
6986 6987 6988
          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
6989
	}
6990
	select_init {}
6991
	;
6992 6993

union_opt:
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
6994
	union_list {}
6995 6996
	| optional_order_or_limit {}
	;
6997 6998

optional_order_or_limit:
6999
	/* Empty */ {}
7000 7001
	|
	  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7002
	    THD *thd= YYTHD;
7003
	    LEX *lex= thd->lex;
7004
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7005
	    SELECT_LEX *sel= lex->current_select;
7006
	    SELECT_LEX_UNIT *unit= sel->master_unit();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7007
	    SELECT_LEX *fake= unit->fake_select_lex;
7008 7009 7010 7011 7012 7013
	    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
7014
	    thd->where= "global ORDER clause";
7015
	  }
7016
	order_or_limit
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7017 7018
          {
	    THD *thd= YYTHD;
7019
	    thd->lex->current_select->no_table_names_allowed= 0;
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7020 7021
	    thd->where= "";
          }
7022 7023 7024
	;

order_or_limit:
7025 7026
	order_clause opt_limit_clause_init
	| limit_clause
7027
	;
7028 7029

union_option:
7030 7031 7032 7033
	/* empty */ { $$=1; }
	| DISTINCT  { $$=1; }
	| ALL       { $$=0; }
        ;
7034

7035 7036
singlerow_subselect:
	subselect_start singlerow_subselect_init
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7037 7038 7039 7040
	subselect_end
	{
	  $$= $2;
	};
7041

7042
singlerow_subselect_init:
7043
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7044
	{
7045 7046
	  $$= new Item_singlerow_subselect(Lex->current_select->
					   master_unit()->first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7047
	};
7048 7049

exists_subselect:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7050 7051 7052 7053 7054
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
7055 7056

exists_subselect_init:
7057
	select_init2
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7058
	{
7059 7060
	  $$= new Item_exists_subselect(Lex->current_select->master_unit()->
					first_select());
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7061
	};
7062

bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7063 7064 7065 7066 7067 7068 7069 7070
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
7071
  select_init2
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7072
  {
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7073
    $$= Lex->current_select->master_unit()->first_select();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
7074 7075
  };

7076
subselect_start:
7077
	'(' SELECT_SYM
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7078
	{
7079
	  LEX *lex=Lex;
7080
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
7081 7082
	       lex->sql_command <= (int)SQLCOM_HA_READ) ||
	       lex->sql_command == (int)SQLCOM_KILL)
7083 7084
	  {
            yyerror(ER(ER_SYNTAX_ERROR));
7085 7086
	    YYABORT;
	  }
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7087 7088 7089
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
7090 7091

subselect_end:
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
7092 7093 7094
	')'
	{
	  LEX *lex=Lex;
7095
	  lex->current_select = lex->current_select->return_after_parsing();
Sinisa@sinisa.nasamreza.org's avatar
Sinisa@sinisa.nasamreza.org committed
7096
	};
serg@serg.mylan's avatar
serg@serg.mylan committed
7097