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

unknown's avatar
unknown 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

unknown's avatar
unknown 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

unknown's avatar
unknown 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 */

unknown's avatar
unknown committed
17
/* sql_yacc.yy */
unknown's avatar
unknown 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)

unknown's avatar
unknown 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
unknown's avatar
unknown committed
33
#include "mysql_priv.h"
unknown's avatar
unknown committed
34
#include "slave.h"
unknown's avatar
unknown committed
35 36
#include "sql_acl.h"
#include "lex_symbol.h"
37
#include "item_create.h"
unknown's avatar
unknown committed
38
#include <myisam.h>
39
#include <myisammrg.h>
40

unknown's avatar
unknown committed
41
extern void yyerror(const char*);
42
int yylex(void *yylval, void *yythd);
unknown's avatar
unknown committed
43

unknown's avatar
unknown committed
44
#define yyoverflow(A,B,C,D,E,F) if (my_yyoverflow((B),(D),(int*) (F))) { yyerror((char*) (A)); return 2; }
unknown's avatar
unknown committed
45

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

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

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

%pure_parser					/* We have threads */

%token	END_OF_INPUT

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

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

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

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

unknown's avatar
unknown committed
390 391 392
%token  ERRORS
%token  WARNINGS

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

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

unknown's avatar
unknown committed
531 532 533 534
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
535
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
536
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
537

unknown's avatar
unknown committed
538 539
%token  ISSUER_SYM
%token  SUBJECT_SYM
540
%token  CIPHER_SYM
unknown's avatar
unknown committed
541

unknown's avatar
unknown committed
542
%token  HELP
543
%token  BEFORE_SYM
unknown's avatar
unknown committed
544 545 546 547 548 549 550 551 552
%left   SET_VAR
%left	OR_OR_CONCAT OR
%left	AND
%left	BETWEEN_SYM CASE_SYM WHEN_SYM THEN_SYM ELSE
%left	EQ EQUAL_SYM GE GT_SYM LE LT NE IS LIKE REGEXP IN_SYM
%left	'|'
%left	'&'
%left	SHIFT_LEFT SHIFT_RIGHT
%left	'-' '+'
553
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
554
%left	NEG '~'
unknown's avatar
unknown committed
555 556
%left   XOR
%left   '^'
unknown's avatar
unknown committed
557
%right	NOT
unknown's avatar
unknown committed
558
%right	BINARY COLLATE_SYM
559

unknown's avatar
unknown committed
560 561
%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
562
	ULONGLONG_NUM field_ident select_alias ident ident_or_text
563
        UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
unknown's avatar
unknown committed
564
	NCHAR_STRING
unknown's avatar
unknown committed
565 566 567 568 569

%type <lex_str_ptr>
	opt_table_alias

%type <table>
570
	table_ident references
unknown's avatar
unknown committed
571 572

%type <simple_string>
573
	remember_name remember_end opt_ident opt_db text_or_password
unknown's avatar
unknown committed
574 575 576
	opt_escape

%type <string>
577
	text_string opt_gconcat_separator
unknown's avatar
unknown committed
578 579

%type <num>
unknown's avatar
unknown committed
580
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
581
	udf_type if_exists opt_local opt_table_options table_options
582
	table_option opt_if_not_exists opt_no_write_to_binlog opt_var_type opt_var_ident_type
unknown's avatar
unknown committed
583
	delete_option opt_temporary all_or_any opt_distinct opt_ignore_leaves
unknown's avatar
unknown committed
584 585

%type <ulong_num>
586
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
587

unknown's avatar
unknown committed
588 589
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
590

unknown's avatar
unknown committed
591 592 593
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

unknown's avatar
unknown committed
594
%type <item>
unknown's avatar
unknown committed
595
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
596
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
597
	table_wild no_in_expr expr_expr simple_expr no_and_expr
598
	using_list expr_or_default set_expr_or_default interval_expr
unknown's avatar
unknown committed
599
	param_marker singlerow_subselect singlerow_subselect_init
unknown's avatar
unknown committed
600
	exists_subselect exists_subselect_init
unknown's avatar
unknown committed
601 602

%type <item_list>
unknown's avatar
unknown committed
603
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
604 605

%type <key_type>
606
	key_type opt_unique_or_fulltext
unknown's avatar
unknown committed
607

unknown's avatar
unknown committed
608 609 610
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
611
%type <string_list>
unknown's avatar
unknown committed
612
	key_usage_list 
unknown's avatar
unknown committed
613 614 615 616 617

%type <key_part>
	key_part

%type <table_list>
618
	join_table_list  join_table
unknown's avatar
unknown committed
619 620 621 622 623 624 625 626 627 628 629

%type <udf>
	UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
	UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM

%type <interval> interval

%type <db_type> table_types

%type <row_type> row_types

unknown's avatar
unknown committed
630
%type <tx_isolation> isolation_types
unknown's avatar
unknown committed
631

unknown's avatar
unknown committed
632 633
%type <ha_rkey_mode> handler_rkey_mode

unknown's avatar
unknown committed
634 635
%type <cast_type> cast_type

unknown's avatar
unknown committed
636 637 638 639 640 641
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

642
%type <charset>
643
	opt_collate
644 645
	charset_name
	charset_name_or_default
unknown's avatar
unknown committed
646 647
	old_or_new_charset_name
	old_or_new_charset_name_or_default
648 649
	collation_name
	collation_name_or_default
650

unknown's avatar
unknown committed
651 652
%type <variable> internal_variable_name

unknown's avatar
unknown committed
653 654
%type <select_lex> in_subselect in_subselect_init

unknown's avatar
unknown committed
655 656
%type <boolfunc2creator> comp_op

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

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


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

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

unknown's avatar
unknown committed
754 755
/* help */

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

/* change master */

change:
unknown's avatar
unknown committed
767
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
768 769 770
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
unknown's avatar
unknown committed
771
	  bzero((char*) &lex->mi, sizeof(lex->mi));
772 773 774 775
        }
       master_defs
	{}
       ;
unknown's avatar
unknown committed
776 777 778

master_defs:
       master_def
unknown's avatar
unknown committed
779
       | master_defs ',' master_def;
unknown's avatar
unknown committed
780

unknown's avatar
unknown committed
781
master_def:
unknown's avatar
unknown committed
782
       MASTER_HOST_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
783 784 785 786
       {
	 Lex->mi.host = $3.str;
       }
       |
unknown's avatar
unknown committed
787
       MASTER_USER_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
788 789 790 791
       {
	 Lex->mi.user = $3.str;
       }
       |
unknown's avatar
unknown committed
792
       MASTER_PASSWORD_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
793 794 795 796
       {
	 Lex->mi.password = $3.str;
       }
       |
unknown's avatar
unknown committed
797
       MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
unknown's avatar
unknown committed
798 799 800 801
       {
	 Lex->mi.log_file_name = $3.str;
       }
       |
unknown's avatar
unknown committed
802
       MASTER_PORT_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
803 804 805 806
       {
	 Lex->mi.port = $3;
       }
       |
unknown's avatar
unknown committed
807
       MASTER_LOG_POS_SYM EQ ulonglong_num
unknown's avatar
unknown committed
808 809
       {
	 Lex->mi.pos = $3;
810 811 812 813 814 815 816 817 818 819 820 821
         /* 
            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);
unknown's avatar
unknown committed
822 823
       }
       |
unknown's avatar
unknown committed
824
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
825 826 827
       {
	 Lex->mi.connect_retry = $3;
       }
828
       |
unknown's avatar
unknown committed
829
       RELAY_LOG_FILE_SYM EQ TEXT_STRING_sys
830 831 832 833 834 835 836
       {
	 Lex->mi.relay_log_name = $3.str;
       }
       |
       RELAY_LOG_POS_SYM EQ ULONG_NUM
       {
	 Lex->mi.relay_log_pos = $3;
837 838
         /* 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);
839 840
       }
       ;
unknown's avatar
unknown committed
841

unknown's avatar
unknown committed
842

unknown's avatar
unknown committed
843 844 845 846 847
/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
848
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
849 850
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
unknown's avatar
unknown committed
851
	  if (!lex->select_lex.add_table_to_list(thd,$5,
852
						 ($2 &
853 854
						  HA_LEX_CREATE_TMP_TABLE ?
						  &tmp_table_alias :
unknown's avatar
unknown committed
855 856
						  (LEX_STRING*) 0),
						 TL_OPTION_UPDATING,
unknown's avatar
unknown committed
857 858 859
						 ((using_update_log)?
						  TL_READ_NO_INSERT:
						  TL_READ)))
unknown's avatar
unknown committed
860 861 862 863 864 865 866
	    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;
unknown's avatar
unknown committed
867
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
868
	  lex->create_info.table_charset= thd->variables.character_set_database;
unknown's avatar
unknown committed
869
	  lex->name=0;
unknown's avatar
unknown committed
870 871
	}
	create2
unknown's avatar
unknown committed
872
	{}
unknown's avatar
unknown committed
873
	| CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
unknown's avatar
unknown committed
874
	  {
unknown's avatar
unknown committed
875 876
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
unknown's avatar
unknown committed
877 878
	    if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
879
	      YYABORT;
unknown's avatar
unknown committed
880 881 882 883
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
unknown's avatar
unknown committed
884
	  }
885
	   '(' key_list ')'
unknown's avatar
unknown committed
886
	  {
unknown's avatar
unknown committed
887
	    LEX *lex=Lex;
unknown's avatar
unknown committed
888

889
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
unknown's avatar
unknown committed
890
	    lex->col_list.empty();
unknown's avatar
unknown committed
891
	  }
892 893 894
	| CREATE DATABASE opt_if_not_exists ident 
	  { Lex->create_info.table_charset=NULL; }
	  opt_create_database_options
unknown's avatar
unknown committed
895
	  {
unknown's avatar
unknown committed
896 897 898 899
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
unknown's avatar
unknown committed
900
	  }
unknown's avatar
unknown committed
901
	| CREATE udf_func_type UDF_SYM IDENT_sys
unknown's avatar
unknown committed
902
	  {
unknown's avatar
unknown committed
903 904
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
905
	    lex->udf.name = $4;
unknown's avatar
unknown committed
906
	    lex->udf.type= $2;
unknown's avatar
unknown committed
907
	  }
unknown's avatar
unknown committed
908
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
909
	  {
unknown's avatar
unknown committed
910 911 912
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
913 914
	  }
          ;
unknown's avatar
unknown committed
915 916

create2:
unknown's avatar
unknown committed
917
	'(' field_list ')' opt_create_table_options create3 {}
918
	| opt_create_table_options create3 {}
unknown's avatar
unknown committed
919 920 921 922 923 924
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
925 926 927 928 929 930 931
	| '(' LIKE table_ident ')'
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$3))
              YYABORT;
    	  }
          ;
unknown's avatar
unknown committed
932 933

create3:
934 935
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
unknown's avatar
unknown committed
936
          {
unknown's avatar
unknown committed
937 938 939
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	    mysql_init_select(lex);
unknown's avatar
unknown committed
940
	    lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
unknown's avatar
unknown committed
941
          }
unknown's avatar
unknown committed
942 943 944 945 946
          select_options select_item_list
	  {
	    Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
	  }
	  opt_select_from union_clause {}
947
          ;
unknown's avatar
unknown committed
948

949 950
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
951
	| AS	    {};
952

953 954 955 956 957 958 959 960 961 962 963
opt_create_database_options:
	/* empty */			{}
	| create_database_options	{};

create_database_options:
	create_database_option					{}
	| create_database_options create_database_option	{};

create_database_option:
	  COLLATE_SYM collation_name_or_default	
	  { Lex->create_info.table_charset=$2; }
964 965 966
	| opt_default charset charset_name_or_default
	  { Lex->create_info.table_charset=$3; }
	;
967

unknown's avatar
unknown committed
968
opt_table_options:
unknown's avatar
unknown committed
969
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
970
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
971 972 973

table_options:
	table_option	{ $$=$1; }
unknown's avatar
unknown committed
974
	| table_option table_options { $$= $1 | $2; };
unknown's avatar
unknown committed
975

unknown's avatar
unknown committed
976
table_option:
unknown's avatar
unknown committed
977
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
978 979

opt_if_not_exists:
unknown's avatar
unknown committed
980
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
981
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
982 983 984

opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
985
	| create_table_options;
unknown's avatar
unknown committed
986

unknown's avatar
unknown committed
987 988 989 990
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
991 992
create_table_options:
	create_table_option
993
	| create_table_option     create_table_options
unknown's avatar
unknown committed
994
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
995 996

create_table_option:
997 998 999 1000
	TYPE_SYM opt_equal table_types          { Lex->create_info.db_type= $3; }
	| MAX_ROWS opt_equal ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS opt_equal ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH opt_equal ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
unknown's avatar
unknown committed
1001 1002
	| 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; }
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
	| 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 ')'
1013 1014 1015
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
1016 1017
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
1018 1019
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
1020 1021
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
1022
	    table_list->next=0;
1023
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
1024
	  }
1025
	| opt_default charset opt_equal charset_name_or_default
1026
	  {
1027 1028 1029
	    Lex->create_info.table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1030 1031 1032 1033 1034
	| COLLATE_SYM opt_equal collation_name_or_default
	  {
	    Lex->create_info.table_charset= $3;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
1035
	| INSERT_METHOD opt_equal merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
unknown's avatar
unknown committed
1036 1037 1038
	| 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; };
unknown's avatar
unknown committed
1039 1040 1041 1042 1043 1044

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
1045
	| MEMORY_SYM	{ $$= DB_TYPE_HEAP; }
unknown's avatar
unknown committed
1046
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
unknown's avatar
unknown committed
1047
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
unknown's avatar
unknown committed
1048 1049 1050 1051 1052

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
1053
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
1054 1055 1056 1057

raid_types:
	RAID_STRIPED_SYM { $$= RAID_TYPE_0; }
	| RAID_0_SYM	 { $$= RAID_TYPE_0; }
unknown's avatar
unknown committed
1058
	| ULONG_NUM	 { $$=$1;};
unknown's avatar
unknown committed
1059

1060 1061 1062
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
1063
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1064

unknown's avatar
unknown committed
1065
opt_select_from:
1066
	opt_limit_clause {}
unknown's avatar
unknown committed
1067
	| FROM DUAL_SYM {}
unknown's avatar
unknown committed
1068
	| select_from select_lock_type;
unknown's avatar
unknown committed
1069 1070 1071

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
1072
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
1073 1074 1075 1076

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
1077
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
1078 1079 1080

field_list:
	  field_list_item
unknown's avatar
unknown committed
1081
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
1082 1083 1084


field_list_item:
unknown's avatar
unknown committed
1085
	   column_def
1086 1087 1088 1089
         | key_def
         ;

column_def:
1090
	  field_spec check_constraint
unknown's avatar
unknown committed
1091 1092 1093 1094
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1095
	;
1096 1097

key_def:
unknown's avatar
unknown committed
1098
	key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1099
	  {
unknown's avatar
unknown committed
1100
	    LEX *lex=Lex;
1101
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
unknown's avatar
unknown committed
1102
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1103
	  }
1104
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1105
	  {
1106 1107 1108 1109 1110 1111 1112 1113
	    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 */
unknown's avatar
unknown committed
1114
	  }
1115
	| opt_constraint check_constraint
unknown's avatar
unknown committed
1116 1117
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1118 1119 1120 1121 1122 1123 1124
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
unknown's avatar
unknown committed
1125 1126 1127

opt_constraint:
	/* empty */
unknown's avatar
unknown committed
1128
	| CONSTRAINT opt_ident;
unknown's avatar
unknown committed
1129 1130 1131 1132

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1133 1134
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
1135
	   lex->default_value=lex->comment=0;
1136
	   lex->charset=NULL;
unknown's avatar
unknown committed
1137 1138 1139
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1140
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1141
	  if (add_field_to_list(lex->thd, $1.str,
unknown's avatar
unknown committed
1142
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1143
				lex->length,lex->dec,lex->type,
1144
				lex->default_value, lex->comment,
unknown's avatar
unknown committed
1145 1146
				lex->change,lex->interval,lex->charset,
				lex->uint_geom_type))
unknown's avatar
unknown committed
1147
	    YYABORT;
unknown's avatar
unknown committed
1148
	};
unknown's avatar
unknown committed
1149 1150

type:
1151
	int_type opt_len field_options	{ $$=$1; }
unknown's avatar
unknown committed
1152 1153 1154 1155 1156 1157
	| 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; }
1158 1159
	| BOOLEAN_SYM			{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_TINY; }
1160
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1161 1162 1163
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
unknown's avatar
unknown committed
1164 1165
	| nchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_STRING; 
1166
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1167 1168
	| nchar				{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; 
1169
					  Lex->charset=national_charset_info; }
1170
	| BINARY '(' NUM ')'		{ Lex->length=$3.str;
unknown's avatar
unknown committed
1171
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1172 1173 1174
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
unknown's avatar
unknown committed
1175 1176
	| nvarchar '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING;
1177
					  Lex->charset=national_charset_info; }
unknown's avatar
unknown committed
1178
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1179
					  Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1180
					  $$=FIELD_TYPE_VAR_STRING; }
1181
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
unknown's avatar
unknown committed
1182 1183
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1184 1185
	| TIMESTAMP
	  {
1186
	    if (YYTHD->variables.sql_mode & MODE_SAPDB)
1187 1188
	      $$=FIELD_TYPE_DATETIME;
	    else
1189
	      $$=FIELD_TYPE_TIMESTAMP;
1190
	   }
unknown's avatar
unknown committed
1191 1192 1193
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
unknown's avatar
unknown committed
1194
	| TINYBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1195
					  $$=FIELD_TYPE_TINY_BLOB; }
unknown's avatar
unknown committed
1196
	| BLOB_SYM opt_len		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1197
					  $$=FIELD_TYPE_BLOB; }
unknown's avatar
unknown committed
1198
	| GEOMETRY_SYM			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1199
					  Lex->uint_geom_type= (uint) Field::GEOM_GEOMETRY;
unknown's avatar
unknown committed
1200
					  $$=FIELD_TYPE_GEOMETRY; }
1201
	| GEOMETRYCOLLECTION		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1202
					  Lex->uint_geom_type= (uint) Field::GEOM_GEOMETRYCOLLECTION;
1203
					  $$=FIELD_TYPE_GEOMETRY; }
1204
	| POINT_SYM			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1205
					  Lex->uint_geom_type= (uint) Field::GEOM_POINT;
1206 1207
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOINT			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1208
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTIPOINT;
1209 1210
					  $$=FIELD_TYPE_GEOMETRY; }
	| LINESTRING			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1211
					  Lex->uint_geom_type= (uint) Field::GEOM_LINESTRING;
1212 1213
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTILINESTRING		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1214
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTILINESTRING;
1215 1216
					  $$=FIELD_TYPE_GEOMETRY; }
	| POLYGON			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1217
					  Lex->uint_geom_type= (uint) Field::GEOM_POLYGON;
1218 1219
					  $$=FIELD_TYPE_GEOMETRY; }
	| MULTIPOLYGON			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1220
					  Lex->uint_geom_type= (uint) Field::GEOM_MULTIPOLYGON;
1221
					  $$=FIELD_TYPE_GEOMETRY; }
unknown's avatar
unknown committed
1222
	| MEDIUMBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1223
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1224
	| LONGBLOB			{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1225
					  $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1226
	| LONG_SYM VARBINARY		{ Lex->charset=&my_charset_bin;
unknown's avatar
unknown committed
1227
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1228 1229
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1230
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1231 1232
	| MEDIUMTEXT opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT opt_binary		{ $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1233 1234 1235 1236
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1237 1238
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1239
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1240
	  {
unknown's avatar
unknown committed
1241 1242
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1243 1244
	    $$=FIELD_TYPE_ENUM;
	  }
1245
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1246
	  {
unknown's avatar
unknown committed
1247 1248
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1249
	    $$=FIELD_TYPE_SET;
1250
	  }
1251
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
unknown's avatar
unknown committed
1252 1253 1254 1255 1256 1257
	| SERIAL_SYM
	  {
	    $$=FIELD_TYPE_LONGLONG;
	    Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNSIGNED_FLAG |
		         UNIQUE_FLAG);
	  }
1258
	;
unknown's avatar
unknown committed
1259 1260 1261

char:
	CHAR_SYM {}
unknown's avatar
unknown committed
1262 1263 1264 1265 1266 1267
	;

nchar:
	NCHAR_SYM {}
	| NATIONAL_SYM CHAR_SYM {}
	;
unknown's avatar
unknown committed
1268

unknown's avatar
unknown committed
1269 1270 1271
varchar:
	char VARYING {}
	| VARCHAR {}
unknown's avatar
unknown committed
1272 1273 1274 1275 1276 1277 1278 1279
	;

nvarchar:
	NATIONAL_SYM VARCHAR {}
	| NCHAR_SYM VARCHAR {}
	| NATIONAL_SYM CHAR_SYM VARYING {}
	| NCHAR_SYM VARYING {}
	;
unknown's avatar
unknown committed
1280 1281 1282 1283 1284 1285

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1286
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1287 1288

real_type:
1289
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1290 1291
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1292
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1293 1294 1295 1296 1297


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1298
	| precision		{};
unknown's avatar
unknown committed
1299 1300 1301 1302 1303 1304

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1305
	};
unknown's avatar
unknown committed
1306 1307 1308

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1309
	| field_opt_list	{};
unknown's avatar
unknown committed
1310 1311 1312

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1313
	| field_option {};
unknown's avatar
unknown committed
1314 1315

field_option:
unknown's avatar
unknown committed
1316
	SIGNED_SYM	{}
1317
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1318
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1319 1320

opt_len:
1321 1322
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1323 1324 1325

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1326
	| precision	{};
unknown's avatar
unknown committed
1327 1328 1329

opt_attribute:
	/* empty */ {}
unknown's avatar
unknown committed
1330
	| opt_attribute_list {};
unknown's avatar
unknown committed
1331 1332 1333

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1334
	| attribute;
unknown's avatar
unknown committed
1335 1336 1337 1338 1339 1340

attribute:
	NULL_SYM	  { Lex->type&= ~ NOT_NULL_FLAG; }
	| NOT NULL_SYM	  { Lex->type|= NOT_NULL_FLAG; }
	| DEFAULT literal { Lex->default_value=$2; }
	| AUTO_INC	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
1341
	| SERIAL_SYM DEFAULT VALUE_SYM
unknown's avatar
unknown committed
1342 1343
	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG; }
	| opt_primary KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
unknown's avatar
unknown committed
1344
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1345
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
1346
	| COMMENT_SYM text_literal { Lex->comment= $2; }
unknown's avatar
unknown committed
1347 1348
	| COLLATE_SYM collation_name 
	  { 
unknown's avatar
unknown committed
1349
	    if (Lex->charset && !my_charset_same(Lex->charset,$2))
unknown's avatar
unknown committed
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
	    {
	      net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH,
			 $2->name,Lex->charset->csname);
	      YYABORT;
	    }
	    else
	    {
	      Lex->charset=$2;
	    }
	  }
	;
unknown's avatar
unknown committed
1361

1362 1363 1364 1365
charset:
	CHAR_SYM SET	{}
	| CHARSET	{}
	;
unknown's avatar
unknown committed
1366

1367
charset_name:
1368
	ident_or_text
1369
	{
unknown's avatar
unknown committed
1370
	  if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))))
1371
	  {
1372
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1373 1374
	    YYABORT;
	  }
unknown's avatar
unknown committed
1375 1376 1377
	}
	| BINARY { $$= &my_charset_bin; }
	;
1378

1379 1380 1381
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1382

unknown's avatar
unknown committed
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400

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

1401
collation_name:
1402
	ident_or_text
1403 1404 1405 1406 1407 1408 1409 1410
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	};

1411 1412
opt_collate:
	/* empty */	{ $$=NULL; }
unknown's avatar
unknown committed
1413
	| COLLATE_SYM collation_name_or_default { $$=$2; }
1414 1415
	;

1416 1417 1418 1419
collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1420 1421 1422 1423
opt_default:
	/* empty */	{}
	| DEFAULT	{};

unknown's avatar
unknown committed
1424
opt_binary:
1425
	/* empty */			{ Lex->charset=NULL; }
unknown's avatar
unknown committed
1426 1427 1428
	| ASCII_SYM			{ Lex->charset=&my_charset_latin1; }
	| BYTE_SYM			{ Lex->charset=&my_charset_bin; }
	| BINARY			{ Lex->charset=&my_charset_bin; }
unknown's avatar
unknown committed
1429 1430
	| UNICODE_SYM
	{
1431
	  if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0))))
unknown's avatar
unknown committed
1432 1433 1434 1435 1436
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1437
	| charset charset_name	{ Lex->charset=$2; } ;
unknown's avatar
unknown committed
1438

unknown's avatar
unknown committed
1439 1440 1441
opt_primary:
	/* empty */
	| PRIMARY_SYM
1442
	;
unknown's avatar
unknown committed
1443

unknown's avatar
unknown committed
1444
references:
1445 1446
	REFERENCES table_ident
	{
1447
	  LEX *lex=Lex;
1448 1449 1450 1451 1452 1453
	  lex->fk_delete_opt= lex->fk_update_opt= lex->fk_match_option= 0;
	  lex->ref_list.empty();
	}
	opt_ref_list
	{
	  $$=$2;
unknown's avatar
unknown committed
1454
	};
1455

1456
opt_ref_list:
unknown's avatar
unknown committed
1457
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1458
	| '(' ref_list ')' opt_on_delete {};
1459 1460 1461

ref_list:
	ref_list ',' ident	{ Lex->ref_list.push_back(new key_part_spec($3.str)); }
unknown's avatar
unknown committed
1462
	| ident			{ Lex->ref_list.push_back(new key_part_spec($1.str)); };
1463

unknown's avatar
unknown committed
1464 1465 1466

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1467
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1468 1469 1470

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1471
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1472 1473

opt_on_delete_item:
1474 1475 1476 1477
	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; }
unknown's avatar
unknown committed
1478
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1479 1480

delete_option:
1481 1482 1483 1484
	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; }
unknown's avatar
unknown committed
1485
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1486 1487 1488 1489

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1490 1491
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
unknown's avatar
unknown committed
1492 1493
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; }
unknown's avatar
unknown committed
1494
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1495
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1496 1497 1498

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1499
	| INDEX {};
unknown's avatar
unknown committed
1500 1501 1502 1503

keys_or_index:
	KEYS {}
	| INDEX {}
unknown's avatar
unknown committed
1504
	| INDEXES {};
unknown's avatar
unknown committed
1505

1506
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1507 1508
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1509 1510 1511
	| FULLTEXT_SYM	{ $$= Key::FULLTEXT;}
	| SPATIAL_SYM	{ $$= Key::SPATIAL; }
        ;
unknown's avatar
unknown committed
1512 1513

key_alg:
1514
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1515
	| USING opt_btree_or_rtree { $$= $2; }
unknown's avatar
unknown committed
1516
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
unknown's avatar
unknown committed
1517 1518 1519 1520

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
	| RTREE_SYM	{ $$= HA_KEY_ALG_RTREE; }
unknown's avatar
unknown committed
1521
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1522 1523 1524

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1525
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1526 1527 1528

key_part:
	ident			{ $$=new key_part_spec($1.str); }
unknown's avatar
unknown committed
1529
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
unknown's avatar
unknown committed
1530 1531 1532

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
unknown's avatar
unknown committed
1533
	| field_ident	{ $$=$1.str; };
unknown's avatar
unknown committed
1534 1535 1536

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1537
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1538 1539 1540 1541 1542 1543 1544 1545

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1546
	  THD *thd= YYTHD;
1547
	  LEX *lex=&thd->lex;
unknown's avatar
unknown committed
1548 1549
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
unknown's avatar
unknown committed
1550 1551
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1552 1553 1554 1555 1556 1557 1558
	    YYABORT;
	  lex->drop_primary=0;
	  lex->create_list.empty();
	  lex->key_list.empty();
	  lex->col_list.empty();
	  lex->drop_list.empty();
	  lex->alter_list.empty();
1559
          lex->select_lex.init_order();
1560
	  lex->select_lex.db=lex->name=0;
1561
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
unknown's avatar
unknown committed
1562
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1563
	  lex->create_info.table_charset= thd->variables.character_set_database;
1564
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1565 1566
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
unknown's avatar
unknown committed
1567
	}
1568 1569
	alter_list
	{}
1570
	| ALTER DATABASE ident opt_create_database_options
1571 1572 1573 1574
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1575
	  };
1576 1577


unknown's avatar
unknown committed
1578
alter_list:
unknown's avatar
unknown committed
1579
        | alter_list_item
unknown's avatar
unknown committed
1580
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1581 1582

add_column:
unknown's avatar
unknown committed
1583
	ADD opt_column { Lex->change=0; };
unknown's avatar
unknown committed
1584 1585

alter_list_item:
1586 1587
	add_column column_def opt_place { Lex->simple_alter=0; }
	| ADD key_def { Lex->simple_alter=0; }
1588
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1589 1590 1591 1592 1593
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1594
          field_spec opt_place
unknown's avatar
unknown committed
1595 1596 1597 1598 1599
        | MODIFY_SYM opt_column field_ident
          {
            LEX *lex=Lex;
            lex->length=lex->dec=0; lex->type=0; lex->interval=0;
            lex->default_value=lex->comment=0;
1600
	    lex->charset= NULL;
unknown's avatar
unknown committed
1601
            lex->simple_alter=0;
unknown's avatar
unknown committed
1602 1603 1604 1605
          }
          type opt_attribute
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
1606
            if (add_field_to_list(lex->thd,$3.str,
unknown's avatar
unknown committed
1607 1608 1609
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
unknown's avatar
unknown committed
1610 1611
				  $3.str, lex->interval, lex->charset,
				  lex->uint_geom_type))
unknown's avatar
unknown committed
1612 1613 1614
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1615
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
					    $3.str)); lex->simple_alter=0;
	  }
	| DROP PRIMARY_SYM KEY_SYM
	  {
	    LEX *lex=Lex;
	    lex->drop_primary=1; lex->simple_alter=0;
	  }
1626
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1627
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1628 1629 1630 1631 1632 1633
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1634 1635
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
unknown's avatar
unknown committed
1636
	| ALTER opt_column field_ident SET DEFAULT literal
unknown's avatar
unknown committed
1637 1638 1639 1640 1641
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
unknown's avatar
unknown committed
1642
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1643 1644 1645 1646 1647
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1648
	| RENAME opt_to table_ident
1649
	  {
1650
	    LEX *lex=Lex;
1651
	    lex->select_lex.db=$3->db.str;
1652
	    lex->name= $3->table.str;
1653
	  }
unknown's avatar
unknown committed
1654
        | create_table_options_space_separated { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1655
	| order_clause         { Lex->simple_alter=0; };
unknown's avatar
unknown committed
1656 1657 1658

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
1659
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
1660 1661 1662

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
unknown's avatar
unknown committed
1663
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
1664 1665 1666 1667

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
1668
	| CASCADE	{};
unknown's avatar
unknown committed
1669 1670 1671 1672

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
1673
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
1674 1675 1676 1677

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1678
	| EQ		{}
unknown's avatar
unknown committed
1679
	| AS		{};
unknown's avatar
unknown committed
1680

unknown's avatar
unknown committed
1681
/*
unknown's avatar
unknown committed
1682 1683 1684
  The first two deprecate the last two--delete the last two for 4.1 release
*/

unknown's avatar
unknown committed
1685
slave:
1686
	START_SYM SLAVE slave_thread_opts
unknown's avatar
unknown committed
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
        {
	  LEX *lex=Lex;
          lex->sql_command = SQLCOM_SLAVE_START;
	  lex->type = 0;
        }
        | STOP_SYM SLAVE slave_thread_opts
          {
	    LEX *lex=Lex;
            lex->sql_command = SQLCOM_SLAVE_STOP;
	    lex->type = 0;
          }
	;
unknown's avatar
unknown committed
1699

unknown's avatar
unknown committed
1700 1701 1702 1703 1704
start:
	START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;}
	{}
	;

unknown's avatar
unknown committed
1705
slave_thread_opts:
1706 1707
	{ Lex->slave_thd_opt= 0; }
	slave_thread_opt_list
unknown's avatar
unknown committed
1708
	;
1709 1710

slave_thread_opt_list:
unknown's avatar
unknown committed
1711
	slave_thread_opt
1712 1713
	| slave_thread_opt_list ',' slave_thread_opt
	;
1714 1715

slave_thread_opt:
1716
	/*empty*/	{}
unknown's avatar
unknown committed
1717
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
unknown's avatar
unknown committed
1718
	| RELAY_THREAD 	{ Lex->slave_thd_opt|=SLAVE_IO; }
unknown's avatar
unknown committed
1719
	;
1720

unknown's avatar
unknown committed
1721 1722 1723 1724 1725
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
unknown's avatar
unknown committed
1726
	table_list FROM TEXT_STRING_sys
unknown's avatar
unknown committed
1727 1728
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1729
        };
unknown's avatar
unknown committed
1730

unknown's avatar
unknown committed
1731 1732 1733 1734 1735
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
unknown's avatar
unknown committed
1736
	table_list TO_SYM TEXT_STRING_sys
unknown's avatar
unknown committed
1737 1738
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1739
        };
unknown's avatar
unknown committed
1740

unknown's avatar
unknown committed
1741
repair:
1742
	REPAIR opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1743
	{
unknown's avatar
unknown committed
1744 1745
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
1746
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1747
	   lex->check_opt.init();
unknown's avatar
unknown committed
1748
	}
1749 1750 1751
	table_list opt_mi_repair_type
	{}
	;
unknown's avatar
unknown committed
1752

unknown's avatar
unknown committed
1753
opt_mi_repair_type:
unknown's avatar
unknown committed
1754
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1755
	| mi_repair_types {};
unknown's avatar
unknown committed
1756

unknown's avatar
unknown committed
1757 1758
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
1759
	| mi_repair_type mi_repair_types {};
1760

unknown's avatar
unknown committed
1761
mi_repair_type:
unknown's avatar
unknown committed
1762
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1763
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1764
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
1765 1766

analyze:
1767
	ANALYZE_SYM opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1768
	{
unknown's avatar
unknown committed
1769 1770
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
1771
           lex->no_write_to_binlog= $2;
unknown's avatar
unknown committed
1772
	   lex->check_opt.init();
unknown's avatar
unknown committed
1773
	}
1774 1775 1776
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1777 1778

check:
unknown's avatar
unknown committed
1779
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
1780
	{
unknown's avatar
unknown committed
1781 1782 1783
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1784
	}
1785 1786 1787
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1788

unknown's avatar
unknown committed
1789 1790
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1791
	| mi_check_types {};
unknown's avatar
unknown committed
1792 1793 1794

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
1795
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
1796 1797 1798 1799 1800 1801

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; }
unknown's avatar
unknown committed
1802
	| CHANGED  { Lex->check_opt.flags|= T_CHECK_ONLY_CHANGED; };
unknown's avatar
unknown committed
1803

unknown's avatar
unknown committed
1804
optimize:
1805
	OPTIMIZE opt_no_write_to_binlog table_or_tables
unknown's avatar
unknown committed
1806
	{
unknown's avatar
unknown committed
1807 1808
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
1809
           lex->no_write_to_binlog= $2;        
unknown's avatar
unknown committed
1810
	   lex->check_opt.init();
unknown's avatar
unknown committed
1811
	}
1812 1813 1814
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1815

1816 1817 1818
opt_no_write_to_binlog:
	/* empty */        { $$= 0; }
	| NO_WRITE_TO_BINLOG  { $$= 1; }
1819
	| LOCAL_SYM  { $$= 1; }
1820 1821
	;

1822 1823 1824 1825 1826
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1827 1828 1829
	table_to_table_list
	{}
	;
1830 1831 1832

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
1833
	| table_to_table_list ',' table_to_table;
1834 1835 1836

table_to_table:
	table_ident TO_SYM table_ident
1837
	{
unknown's avatar
unknown committed
1838 1839
	  LEX *lex=Lex;	  
	  SELECT_LEX_NODE *sl= lex->current_select;
unknown's avatar
unknown committed
1840 1841 1842 1843
	  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))
1844
	    YYABORT;
1845
	};
1846

unknown's avatar
unknown committed
1847
preload:
unknown's avatar
unknown committed
1848
	LOAD INDEX INTO CACHE_SYM
unknown's avatar
unknown committed
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861
	{
	  LEX *lex=Lex;
	  lex->sql_command=SQLCOM_PRELOAD_KEYS;
	}
	preload_list
	{}
	;

preload_list:
	preload_keys
	| preload_list ',' preload_keys;

preload_keys:
unknown's avatar
unknown committed
1862
	table_ident preload_keys_spec opt_ignore_leaves
unknown's avatar
unknown committed
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
	  if (!sel->add_table_to_list(lex->thd, $1, NULL, $3, 
                                      TL_READ, 
                                      sel->get_use_index(),
                                      (List<String> *)0))
            YYABORT;
	}
	;

preload_keys_spec:
	keys_or_index { Select->select_lex()->interval_list.empty(); }
	preload_key_list_or_empty 
	{
	  LEX *lex=Lex;
	  SELECT_LEX *sel= &lex->select_lex;
	  sel->use_index= sel->interval_list;
	  sel->use_index_ptr= &sel->use_index;
	}          
	;

preload_key_list_or_empty:
	/* empty */
	| '(' key_usage_list2 ')' {}
	;

unknown's avatar
unknown committed
1890
opt_ignore_leaves:
unknown's avatar
unknown committed
1891 1892 1893 1894 1895
	/* empty */
	{ $$= 0; }
	| IGNORE_SYM LEAVES { $$= TL_OPTION_IGNORE_LEAVES; }
	;

unknown's avatar
unknown committed
1896
/*
unknown's avatar
unknown committed
1897
  Select : retrieve data from table
unknown's avatar
unknown committed
1898 1899 1900 1901
*/


select:
unknown's avatar
unknown committed
1902
	select_init { Lex->sql_command=SQLCOM_SELECT; };
unknown's avatar
unknown committed
1903

1904
/* Need select_init2 for subselects. */
unknown's avatar
unknown committed
1905
select_init:
1906
	SELECT_SYM select_init2
1907
	|
1908 1909
	'(' SELECT_SYM select_part2 ')'
	  {
1910
	    LEX *lex= Lex;
unknown's avatar
unknown committed
1911
            SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1912
	    if (sel->set_braces(1))
1913 1914 1915 1916
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
1917 1918
	  if (sel->linkage == UNION_TYPE &&
	      !sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
1919 1920 1921 1922
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1923
            /* select in braces, can't contain global parameters */
1924
            sel->master_unit()->global_parameters=
1925
               sel->master_unit();
unknown's avatar
unknown committed
1926
          } union_opt;
1927

1928 1929
select_init2:
	select_part2
1930
        {
1931
	  LEX *lex= Lex;
unknown's avatar
unknown committed
1932
          SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1933
          if (lex->current_select->set_braces(0))
1934 1935 1936 1937
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1938 1939
	  if (sel->linkage == UNION_TYPE &&
	      sel->master_unit()->first_select()->braces)
unknown's avatar
unknown committed
1940 1941 1942 1943
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1944
	}
1945
	union_clause
1946 1947
	;

1948
select_part2:
unknown's avatar
unknown committed
1949 1950
	{
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1951
	  SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1952
	  if (lex->current_select == &lex->select_lex)
1953
	    lex->lock_option= TL_READ; /* Only for global SELECT */
unknown's avatar
unknown committed
1954 1955
	  if (sel->linkage != UNION_TYPE)
	    mysql_init_select(lex);
unknown's avatar
unknown committed
1956 1957 1958 1959 1960
	  lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
	}
	select_options select_item_list
	{
	  Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
unknown's avatar
unknown committed
1961
	}
unknown's avatar
unknown committed
1962
	select_into select_lock_type;
1963

unknown's avatar
unknown committed
1964
select_into:
1965 1966 1967 1968 1969 1970
	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
unknown's avatar
unknown committed
1971
	| select_from
1972 1973
	| into select_from
	| select_from into;
unknown's avatar
unknown committed
1974 1975

select_from:
1976
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
unknown's avatar
unknown committed
1977 1978 1979

select_options:
	/* empty*/
unknown's avatar
unknown committed
1980
	| select_option_list;
unknown's avatar
unknown committed
1981 1982 1983

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
1984
	| select_option;
unknown's avatar
unknown committed
1985 1986

select_option:
1987
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1988 1989 1990 1991 1992 1993
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1994 1995 1996
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
	| 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;
	  }
unknown's avatar
unknown committed
2009
	| SQL_NO_CACHE_SYM { Lex->uncacheable(); }
2010 2011 2012 2013
	| SQL_CACHE_SYM
	  {
	    Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
	  }
2014 2015
	| ALL		{}
	;
unknown's avatar
unknown committed
2016

unknown's avatar
unknown committed
2017 2018 2019
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
2020 2021
	  {
	    LEX *lex=Lex;
2022
	    lex->current_select->set_lock_for_tables(TL_WRITE);
2023
	    lex->safe_to_cache_query=0;
2024
	  }
unknown's avatar
unknown committed
2025
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
2026 2027
	  {
	    LEX *lex=Lex;
2028 2029
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
2030
	    lex->safe_to_cache_query=0;
2031 2032
	  }
	;
unknown's avatar
unknown committed
2033

unknown's avatar
unknown committed
2034 2035 2036 2037 2038
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
2039 2040
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
unknown's avatar
unknown committed
2041
	      YYABORT;
2042
	    (thd->lex.current_select->select_lex()->with_wild)++;
unknown's avatar
unknown committed
2043
	  };
unknown's avatar
unknown committed
2044 2045 2046 2047 2048


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
unknown's avatar
unknown committed
2049
	    if (add_item_to_list(YYTHD, $2))
unknown's avatar
unknown committed
2050 2051
	      YYABORT;
	    if ($4.str)
unknown's avatar
unknown committed
2052
	      $2->set_name($4.str,$4.length,system_charset_info);
unknown's avatar
unknown committed
2053
	    else if (!$2->name)
unknown's avatar
unknown committed
2054
	      $2->set_name($1,(uint) ($3 - $1), YYTHD->charset());
unknown's avatar
unknown committed
2055
	  };
unknown's avatar
unknown committed
2056 2057

remember_name:
unknown's avatar
unknown committed
2058
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
2059 2060

remember_end:
unknown's avatar
unknown committed
2061
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
2062 2063 2064

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
2065
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
2066 2067

select_alias:
unknown's avatar
unknown committed
2068 2069 2070 2071 2072 2073
	/* empty */		{ $$.str=0;}
	| AS ident		{ $$=$2; }
	| AS TEXT_STRING_sys	{ $$=$2; }
	| ident			{ $$=$1; }
	| TEXT_STRING_sys	{ $$=$1; }
	;
unknown's avatar
unknown committed
2074 2075 2076

optional_braces:
	/* empty */ {}
unknown's avatar
unknown committed
2077
	| '(' ')' {};
unknown's avatar
unknown committed
2078

unknown's avatar
unknown committed
2079
/* all possible expressions */
unknown's avatar
SCRUM  
unknown committed
2080 2081 2082 2083
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
unknown's avatar
unknown committed
2084

unknown's avatar
unknown committed
2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
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; }
        ;

unknown's avatar
unknown committed
2097 2098
/* expressions that begin with 'expr' */
expr_expr:
unknown's avatar
SCRUM  
unknown committed
2099
	 expr IN_SYM '(' expr_list ')'
unknown's avatar
unknown committed
2100 2101 2102
	  { $$= new Item_func_in($1,*$4); }
	| expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
unknown's avatar
unknown committed
2103
        | expr IN_SYM in_subselect
unknown's avatar
unknown committed
2104
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
unknown's avatar
unknown committed
2105
	| expr NOT IN_SYM in_subselect
2106
          {
unknown's avatar
unknown committed
2107
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
unknown's avatar
unknown committed
2108
          }
unknown's avatar
unknown committed
2109 2110 2111 2112
	| 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)); }
2113
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2114
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2115
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2116
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2117
	| expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
unknown's avatar
unknown committed
2118 2119 2120 2121 2122 2123 2124
	| expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
	| expr NOT LIKE simple_expr opt_escape	{ $$= new Item_func_not(new Item_func_like($1,$4,$5));}
	| expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
unknown's avatar
unknown committed
2125 2126 2127
	| expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| expr comp_op all_or_any in_subselect %prec EQ
	{
2128
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2129
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2130 2131 2132 2133 2134
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2135 2136 2137 2138 2139 2140
	| 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); }
2141 2142
	| expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
	| expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
unknown's avatar
unknown committed
2143
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
2144
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2145 2146
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2147 2148 2149 2150
	| 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); }
unknown's avatar
unknown committed
2151
	;
unknown's avatar
unknown committed
2152 2153 2154 2155 2156 2157 2158

/* 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)); }
2159
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2160
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2161
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2162
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
2163
	| no_in_expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
unknown's avatar
unknown committed
2164 2165 2166 2167 2168 2169 2170
	| no_in_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
	| no_in_expr NOT LIKE simple_expr opt_escape { $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
	| no_in_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| no_in_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| no_in_expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| no_in_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| no_in_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
unknown's avatar
unknown committed
2171 2172 2173
	| no_in_expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
2174
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2175
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2176 2177 2178 2179 2180
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2181 2182 2183 2184 2185 2186
	| 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); }
2187
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2188
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2189
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2190 2191
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2192
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2193 2194 2195 2196
	| 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); }
unknown's avatar
unknown committed
2197
	| simple_expr;
unknown's avatar
unknown committed
2198 2199 2200

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
unknown's avatar
unknown committed
2201 2202
	  no_and_expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
unknown's avatar
unknown committed
2203 2204
	| no_and_expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
unknown's avatar
unknown committed
2205
        | no_and_expr IN_SYM in_subselect
unknown's avatar
unknown committed
2206
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
unknown's avatar
unknown committed
2207
	| no_and_expr NOT IN_SYM in_subselect
2208
          {
unknown's avatar
unknown committed
2209
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
unknown's avatar
unknown committed
2210
          }
unknown's avatar
unknown committed
2211 2212 2213 2214
	| 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)); }
2215
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2216
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2217
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2218
	| no_and_expr SOUNDS_SYM LIKE expr { $$= Item_bool_func2::eq_creator(new Item_func_soundex($1), new Item_func_soundex($4));}
unknown's avatar
unknown committed
2219 2220 2221 2222 2223 2224 2225
	| no_and_expr LIKE simple_expr opt_escape { $$= new Item_func_like($1,$3,$4); }
	| no_and_expr NOT LIKE simple_expr opt_escape	{ $$= new Item_func_not(new Item_func_like($1,$4,$5)); }
	| no_and_expr REGEXP expr { $$= new Item_func_regex($1,$3); }
	| no_and_expr NOT REGEXP expr { $$= new Item_func_not(new Item_func_regex($1,$4)); }
	| no_and_expr IS NULL_SYM	{ $$= new Item_func_isnull($1); }
	| no_and_expr IS NOT NULL_SYM { $$= new Item_func_isnotnull($1); }
	| no_and_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
unknown's avatar
unknown committed
2226 2227 2228
	| no_and_expr comp_op expr %prec EQ { $$= (*((*$2)(0)))($1,$3); }
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
2229
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2230
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2231 2232 2233 2234 2235
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2236 2237 2238 2239 2240 2241
	| 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); }
2242
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2243
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2244
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2245 2246
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2247
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2248 2249 2250 2251
	| 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); }
unknown's avatar
unknown committed
2252
	| simple_expr;
unknown's avatar
unknown committed
2253

2254
interval_expr:
unknown's avatar
unknown committed
2255
         INTERVAL_SYM expr { $$=$2; }
2256 2257
        ;

unknown's avatar
unknown committed
2258 2259
simple_expr:
	simple_ident
2260 2261
 	| simple_expr COLLATE_SYM ident_or_text %prec NEG
	  { 
unknown's avatar
unknown committed
2262 2263 2264 2265
	    $$= new Item_func_set_collation($1,
					    new Item_string($3.str,
							    $3.length,
					    		    YYTHD->charset()));
2266
	  }
unknown's avatar
unknown committed
2267
	| literal
unknown's avatar
unknown committed
2268
	| param_marker
unknown's avatar
unknown committed
2269
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
2270 2271
	  {
	    $$= new Item_func_set_user_var($2,$4);
unknown's avatar
unknown committed
2272
	    Lex->uncacheable();
unknown's avatar
unknown committed
2273
	  }
2274
	| '@' ident_or_text
unknown's avatar
unknown committed
2275 2276
	  {
	    $$= new Item_func_get_user_var($2);
unknown's avatar
unknown committed
2277
	    Lex->uncacheable();
unknown's avatar
unknown committed
2278
	  }
unknown's avatar
unknown committed
2279 2280 2281 2282
	| '@' '@' opt_var_ident_type ident_or_text
	  {
	    if (!($$= get_system_var((enum_var_type) $3, $4)))
	      YYABORT;
unknown's avatar
unknown committed
2283
	  }
unknown's avatar
unknown committed
2284 2285 2286 2287 2288 2289
	| sum_expr
	| '-' expr %prec NEG	{ $$= new Item_func_neg($2); }
	| '~' expr %prec NEG	{ $$= new Item_func_bit_neg($2); }
	| NOT expr %prec NEG	{ $$= new Item_func_not($2); }
	| '!' expr %prec NEG	{ $$= new Item_func_not($2); }
	| '(' expr ')'		{ $$= $2; }
2290 2291 2292 2293 2294
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
2295
	| ROW_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2296
	  {
2297 2298
	    $5->push_front($3);
	    $$= new Item_row(*$5);
unknown's avatar
unknown committed
2299
	  }
unknown's avatar
unknown committed
2300
	| EXISTS exists_subselect { $$= $2; }
unknown's avatar
unknown committed
2301
	| singlerow_subselect   { $$= $1; }
unknown's avatar
unknown committed
2302
	| '{' ident expr '}'	{ $$= $3; }
unknown's avatar
unknown committed
2303
        | MATCH ident_list_arg AGAINST '(' expr ')'
2304
          { Select->add_ftfunc_to_list((Item_func_match *)
2305
                   ($$=new Item_func_match_nl(*$2,$5))); }
unknown's avatar
unknown committed
2306
        | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
2307
          { Select->add_ftfunc_to_list((Item_func_match *)
2308
                   ($$=new Item_func_match_bool(*$2,$5))); }
unknown's avatar
unknown committed
2309
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
unknown's avatar
unknown committed
2310 2311
	| BINARY expr %prec NEG 
	  {
unknown's avatar
unknown committed
2312 2313
	    $$= new Item_func_set_collation($2,new Item_string(binary_keyword,
					    6, &my_charset_latin1));
unknown's avatar
unknown committed
2314
	  }
2315 2316
	| CAST_SYM '(' expr AS cast_type ')'
	  { $$= create_func_cast($3, $5, Lex->charset); }
unknown's avatar
unknown committed
2317
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
2318
	  { $$= new Item_func_case(* $4, $2, $5 ); }
2319 2320
	| CONVERT_SYM '(' expr ',' cast_type ')'
	  { $$= create_func_cast($3, $5, Lex->charset); }
2321 2322
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
2323
	| CONVERT_SYM '(' expr ',' expr ',' expr ')'
2324
	  { $$= new Item_func_conv_charset3($3,$7,$5); }
unknown's avatar
SCRUM  
unknown committed
2325 2326
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
unknown's avatar
unknown committed
2327 2328
	| VALUES '(' simple_ident ')'
	  { $$= new Item_insert_value($3); }
unknown's avatar
unknown committed
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342
	| FUNC_ARG0 '(' ')'
	  { $$= ((Item*(*)(void))($1.symbol->create_func))();}
	| FUNC_ARG1 '(' expr ')'
	  { $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);}
	| FUNC_ARG2 '(' expr ',' expr ')'
	  { $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);}
	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
	  { $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);}
	| ATAN	'(' expr ')'
	  { $$= new Item_func_atan($3); }
	| ATAN	'(' expr ',' expr ')'
	  { $$= new Item_func_atan($3,$5); }
	| CHAR_SYM '(' expr_list ')'
	  { $$= new Item_func_char(*$3); }
unknown's avatar
unknown committed
2343 2344
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
2345 2346
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
unknown's avatar
unknown committed
2347 2348
	| COLLATION_SYM '(' expr ')'
	  { $$= new Item_func_collation($3); }
unknown's avatar
unknown committed
2349 2350 2351 2352 2353
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
2354
	  { $$= new Item_func_curdate(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2355
	| CURTIME optional_braces
2356
	  { $$= new Item_func_curtime(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2357
	| CURTIME '(' expr ')'
2358 2359
	  {
	    $$= new Item_func_curtime($3);
2360
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2361
	  }
2362 2363 2364 2365
	| 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); }
unknown's avatar
unknown committed
2366
	| DATABASE '(' ')'
2367
	  {
unknown's avatar
unknown committed
2368
	    $$= new Item_func_database();
2369
            Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2370
	  }
unknown's avatar
unknown committed
2371 2372 2373 2374
	| ELT_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_elt($3, *$5); }
	| MAKE_SET_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_make_set($3, *$5); }
unknown's avatar
unknown committed
2375 2376 2377
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
unknown's avatar
unknown committed
2378
	    Lex->uncacheable();
unknown's avatar
unknown committed
2379
	  }
unknown's avatar
unknown committed
2380
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
2381
	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2382
	  { $$= new Item_func_decode($3,$5.str); }
2383
	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
unknown's avatar
unknown committed
2384
	 { $$= new Item_func_encode($3,$5.str); }
unknown's avatar
unknown committed
2385
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2386
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
2387
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2388
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
2389
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2390
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
2391
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2392
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
2393 2394 2395 2396 2397 2398
	| 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); }
2399 2400
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
2401 2402 2403 2404 2405 2406
	| 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 ')'
	  {
unknown's avatar
unknown committed
2407
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2408 2409 2410
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_field($3, *$5); }
unknown's avatar
unknown committed
2411
	| GEOMFROMTEXT '(' expr ')'
2412
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2413
	| GEOMFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2414 2415 2416 2417 2418
	  { $$= new Item_func_geometry_from_text($3, $5); }
	| GEOMFROMWKB '(' expr ')'
	  { $$= new Item_func_geometry_from_wkb($3); }
	| GEOMFROMWKB '(' expr ',' expr ')'
	  { $$= new Item_func_geometry_from_wkb($3, $5); }
unknown's avatar
unknown committed
2419
	| GEOMETRYCOLLECTION '(' expr_list ')'
2420 2421
	  { $$= new Item_func_spatial_collection(* $3,
                       Geometry::wkbGeometryCollection,
unknown's avatar
unknown committed
2422
                       Geometry::wkbPoint); }
unknown's avatar
unknown committed
2423 2424 2425 2426 2427 2428
	| 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); }
2429
	| interval_expr interval '+' expr
unknown's avatar
unknown committed
2430
	  /* we cannot put interval before - */
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440
	  { $$= new Item_date_add_interval($4,$1,$2,0); }
	| interval_expr
	  {
            if ($1->type() != Item::ROW_ITEM)
            {
              send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
            $$= new Item_func_interval((Item_row *)$1);
          }
unknown's avatar
unknown committed
2441 2442
	| LAST_INSERT_ID '(' ')'
	  {
2443
	    $$= get_system_var(OPT_SESSION, "last_insert_id", 14,
2444
			      "last_insert_id()");
2445
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2446 2447 2448 2449
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
2450
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2451 2452 2453
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
unknown's avatar
unknown committed
2454
	| LINESTRING '(' expr_list ')'
2455
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2456
               Geometry::wkbLineString, Geometry::wkbPoint); }
unknown's avatar
unknown committed
2457 2458 2459 2460
	| LOCATE '(' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3); }
	| LOCATE '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_locate($5,$3,$7); }
unknown's avatar
unknown committed
2461
 	| GEOMCOLLFROMTEXT '(' expr ')'
2462
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2463
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2464
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2465
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2466 2467 2468
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
2469
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
2470
	  { $$= new Item_func_log($3); }
2471
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2472
	  { $$= new Item_func_log($3, $5); }
unknown's avatar
unknown committed
2473
 	| LINEFROMTEXT '(' expr ')'
2474
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2475
	| LINEFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2476
	  { $$= new Item_func_geometry_from_text($3, $5); }
2477 2478 2479
	| MASTER_POS_WAIT '(' expr ',' expr ')'
	  { 
	    $$= new Item_master_pos_wait($3, $5);
unknown's avatar
unknown committed
2480 2481
	    Lex->safe_to_cache_query=0; 
		  }
2482 2483 2484
	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
	  { 
	    $$= new Item_master_pos_wait($3, $5, $7);
unknown's avatar
unknown committed
2485
	    Lex->safe_to_cache_query=0; 
2486
	  }
unknown's avatar
unknown committed
2487 2488
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
2489 2490
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
2491 2492
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
unknown's avatar
unknown committed
2493
 	| MULTILINESTRING '(' expr_list ')'
2494
 	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2495
                    Geometry::wkbMultiLineString, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2496
 	| MLINEFROMTEXT '(' expr ')'
2497
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2498
	| MLINEFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2499
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2500
	| MPOINTFROMTEXT '(' expr ')'
2501
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2502
	| MPOINTFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2503
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2504
	| MPOLYFROMTEXT '(' expr ')'
2505
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2506
	| MPOLYFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2507
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2508
	| MULTIPOINT '(' expr_list ')'
2509
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2510 2511
                    Geometry::wkbMultiPoint, Geometry::wkbPoint); }
 	| MULTIPOLYGON '(' expr_list ')'
2512
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2513
                       Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
unknown's avatar
unknown committed
2514
	| NOW_SYM optional_braces
2515
	  { $$= new Item_func_now(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2516
	| NOW_SYM '(' expr ')'
2517
	  { $$= new Item_func_now($3); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2518
	| PASSWORD '(' expr ')'
unknown's avatar
SCRUM  
unknown committed
2519 2520 2521
	  { $$= new Item_func_password($3); }
        | PASSWORD '(' expr ',' expr ')'
          { $$= new Item_func_password($3,$5); }
2522
	| POINT_SYM '(' expr ',' expr ')'
2523
	  { $$= new Item_func_point($3,$5); }
unknown's avatar
unknown committed
2524
 	| POINTFROMTEXT '(' expr ')'
2525
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2526
	| POINTFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2527
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2528
	| POLYFROMTEXT '(' expr ')'
2529
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2530
	| POLYFROMTEXT '(' expr ',' expr ')'
unknown's avatar
unknown committed
2531
	  { $$= new Item_func_geometry_from_text($3, $5); }
unknown's avatar
unknown committed
2532
	| POLYGON '(' expr_list ')'
2533
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2534
			Geometry::wkbPolygon, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2535 2536
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
2537
	| RAND '(' expr ')'
2538
	  { $$= new Item_func_rand($3); Lex->uncacheable();}
unknown's avatar
unknown committed
2539
	| RAND '(' ')'
2540
	  { $$= new Item_func_rand(); Lex->uncacheable();}
unknown's avatar
unknown committed
2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560
	| REPLACE '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_replace($3,$5,$7); }
	| RIGHT '(' expr ',' expr ')'
	  { $$= new Item_func_right($3,$5); }
	| ROUND '(' expr ')'
	  { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
	| ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
	| SECOND_SYM '(' expr ')'
	  { $$= new Item_func_second($3); }
	| SUBSTRING '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_substr($3,$5,$7); }
	| SUBSTRING '(' expr ',' expr ')'
	  { $$= new Item_func_substr($3,$5); }
	| SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
	  { $$= new Item_func_substr($3,$5,$7); }
	| SUBSTRING '(' expr FROM expr ')'
	  { $$= new Item_func_substr($3,$5); }
	| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
	  { $$= new Item_func_substr_index($3,$5,$7); }
	| TRIM '(' expr ')'
2561 2562
	  { $$= new Item_func_trim($3); }
	| TRIM '(' LEADING expr FROM expr ')'
unknown's avatar
unknown committed
2563
	  { $$= new Item_func_ltrim($6,$4); }
2564
	| TRIM '(' TRAILING expr FROM expr ')'
unknown's avatar
unknown committed
2565
	  { $$= new Item_func_rtrim($6,$4); }
2566
	| TRIM '(' BOTH expr FROM expr ')'
unknown's avatar
unknown committed
2567
	  { $$= new Item_func_trim($6,$4); }
2568 2569 2570 2571 2572 2573
	| 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); }
unknown's avatar
unknown committed
2574 2575
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
2576 2577
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
2578 2579
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622
	| UDA_CHAR_SUM '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_sum_udf_str($1, *$3);
	    else
	      $$ = new Item_sum_udf_str($1);
	  }
	| UDA_FLOAT_SUM '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_sum_udf_float($1, *$3);
	    else
	      $$ = new Item_sum_udf_float($1);
	  }
	| UDA_INT_SUM '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_sum_udf_int($1, *$3);
	    else
	      $$ = new Item_sum_udf_int($1);
	  }
	| UDF_CHAR_FUNC '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_func_udf_str($1, *$3);
	    else
	      $$ = new Item_func_udf_str($1);
	  }
	| UDF_FLOAT_FUNC '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_func_udf_float($1, *$3);
	    else
	      $$ = new Item_func_udf_float($1);
	  }
	| UDF_INT_FUNC '(' udf_expr_list ')'
	  {
	    if ($3 != NULL)
	      $$ = new Item_func_udf_int($1, *$3);
	    else
	      $$ = new Item_func_udf_int($1);
	  }
	| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
2623
	  {
unknown's avatar
unknown committed
2624 2625
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
2626
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
2627 2628
	  {
	    $$= new Item_func_unix_timestamp();
2629
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2630
	  }
unknown's avatar
unknown committed
2631 2632 2633
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
2634
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2635
	| WEEK_SYM '(' expr ')'
2636 2637 2638 2639
	  { 
            $$= new Item_func_week($3,new Item_int((char*) "0",
				   YYTHD->variables.default_week_format,1)); 
          }
unknown's avatar
unknown committed
2640 2641 2642 2643 2644 2645 2646 2647 2648
	| 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 ')'
2649
	  {
unknown's avatar
unknown committed
2650
	    $$=new Item_func_benchmark($3,$5);
2651
	    Lex->uncacheable();
unknown's avatar
unknown committed
2652
	  }
unknown's avatar
unknown committed
2653
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
2654
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
2655 2656 2657

udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
2658
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
2659 2660 2661 2662 2663 2664 2665 2666

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); }
unknown's avatar
unknown committed
2667
	| COUNT_SYM '(' opt_all '*' ')'
unknown's avatar
unknown committed
2668 2669 2670
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
2671
	| COUNT_SYM '(' DISTINCT
unknown's avatar
unknown committed
2672
	  { Select->select_lex()->in_sum_expr++; }
2673
	   expr_list
unknown's avatar
unknown committed
2674
	  { Select->select_lex()->in_sum_expr--; }
2675 2676
	  ')'
	  { $$=new Item_sum_count_distinct(* $5); }
unknown's avatar
unknown committed
2677 2678 2679 2680 2681 2682 2683 2684
	| GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
	  { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
	| MIN_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_min($3); }
	| MAX_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_max($3); }
	| STD_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_std($3); }
unknown's avatar
unknown committed
2685 2686
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
unknown's avatar
unknown committed
2687
	| SUM_SYM '(' in_sum_expr ')'
2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699
	  { $$=new Item_sum_sum($3); }
	| GROUP_CONCAT_SYM '(' opt_distinct expr_list opt_gorder_clause opt_gconcat_separator ')'
	  { 
	    $$=new Item_func_group_concat($3,$4,Lex->gorder_list,$6); 
	    $4->empty();
	  };

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

opt_gconcat_separator:
2700
    /* empty */        { $$ = new String(",",1,default_charset_info); }
2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
    |SEPARATOR_SYM text_string  { $$ = $2; };
   

opt_gorder_clause:
    /* empty */ 
      {
        LEX *lex=Lex;
        lex->gorder_list = NULL;
      }
    | order_clause
      {
        LEX *lex=Lex;
        lex->gorder_list= (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,sizeof(st_sql_list));
        lex->current_select->order_list.empty();
      };
	  
unknown's avatar
unknown committed
2717 2718

in_sum_expr:
unknown's avatar
unknown committed
2719
	opt_all
2720 2721 2722 2723 2724
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
2725
	    YYABORT;
2726 2727
	  }
	}
unknown's avatar
unknown committed
2728 2729
	expr
	{
unknown's avatar
unknown committed
2730
	  Select->select_lex()->in_sum_expr--;
2731
	  $$= $3;
unknown's avatar
unknown committed
2732
	};
unknown's avatar
unknown committed
2733

unknown's avatar
unknown committed
2734
cast_type:
2735 2736 2737 2738 2739 2740 2741 2742 2743
	BINARY			{ $$=ITEM_CAST_BINARY; Lex->charset= NULL; }
	| CHAR_SYM opt_binary	{ $$=ITEM_CAST_CHAR; }
	| SIGNED_SYM		{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; }
	| SIGNED_SYM INT_SYM	{ $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; }
	| UNSIGNED		{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; }
	| UNSIGNED INT_SYM	{ $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; }
	| DATE_SYM		{ $$=ITEM_CAST_DATE; Lex->charset= NULL; }
	| TIME_SYM		{ $$=ITEM_CAST_TIME; Lex->charset= NULL; }
	| DATETIME		{ $$=ITEM_CAST_DATETIME; Lex->charset= NULL; }
2744
	;
unknown's avatar
unknown committed
2745

unknown's avatar
unknown committed
2746
expr_list:
2747
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2748
	expr_list2
unknown's avatar
unknown committed
2749
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2750 2751

expr_list2:
2752
	expr { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
2753
	| expr_list2 ',' expr { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
2754

unknown's avatar
unknown committed
2755 2756
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
2757
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
2758

unknown's avatar
unknown committed
2759
ident_list:
2760
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2761
        ident_list2
unknown's avatar
unknown committed
2762
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2763 2764

ident_list2:
2765
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
2766
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
2767 2768 2769

opt_expr:
	/* empty */      { $$= NULL; }
unknown's avatar
unknown committed
2770
	| expr         	 { $$= $1; };
unknown's avatar
unknown committed
2771 2772 2773

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
2774
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
2775 2776

when_list:
unknown's avatar
unknown committed
2777
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2778
	when_list2
unknown's avatar
unknown committed
2779
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
2780 2781

when_list2:
unknown's avatar
unknown committed
2782
	expr THEN_SYM expr
unknown's avatar
unknown committed
2783
	  {
2784
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2785 2786
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
2787
	}
unknown's avatar
unknown committed
2788
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
2789
	  {
2790
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2791 2792
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
2793
	  };
unknown's avatar
unknown committed
2794 2795 2796 2797

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
unknown's avatar
unknown committed
2798
	| join_table_list ',' join_table_list { $$=$3; }
2799
	| join_table_list normal_join join_table_list { $$=$3; }
2800
	| join_table_list STRAIGHT_JOIN join_table_list
2801
	  { $$=$3 ; $1->next->straight=1; }
unknown's avatar
unknown committed
2802 2803 2804 2805
	| join_table_list normal_join join_table_list ON expr
	  { add_join_on($3,$5); $$=$3; }
	| join_table_list normal_join join_table_list
	  USING 
unknown's avatar
unknown committed
2806
	  {
unknown's avatar
unknown committed
2807
	    SELECT_LEX *sel= Select->select_lex();
2808
	    sel->db1=$1->db; sel->table1=$1->alias;
unknown's avatar
unknown committed
2809
	    sel->db2=$3->db; sel->table2=$3->alias;
unknown's avatar
unknown committed
2810
	  }
unknown's avatar
unknown committed
2811 2812 2813
	  '(' using_list ')'
	  { add_join_on($3,$7); $$=$3; }

2814
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2815
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2816
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2817
	  {
unknown's avatar
unknown committed
2818
	    SELECT_LEX *sel= Select->select_lex();
2819 2820
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2821
	  }
unknown's avatar
unknown committed
2822
	  USING '(' using_list ')'
2823
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2824
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2825 2826 2827 2828 2829
	  {
	    add_join_natural($1,$1->next);
	    $1->next->outer_join|=JOIN_TYPE_LEFT;
	    $$=$6;
	  }
2830
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2831
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
2832
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2833
	  {
unknown's avatar
unknown committed
2834
	    SELECT_LEX *sel= Select->select_lex();
2835 2836
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2837
	  }
2838
	  USING '(' using_list ')'
2839
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
2840
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2841 2842 2843 2844 2845
	  {
	    add_join_natural($1->next,$1);
	    $1->outer_join|=JOIN_TYPE_RIGHT;
	    $$=$6;
	  }
2846
	| join_table_list NATURAL JOIN_SYM join_table_list
2847
	  { add_join_natural($1,$1->next); $$=$4; };
unknown's avatar
unknown committed
2848 2849

normal_join:
unknown's avatar
unknown committed
2850 2851 2852 2853
	JOIN_SYM		{}
	| INNER_SYM JOIN_SYM	{}
	| CROSS JOIN_SYM	{}
	;
unknown's avatar
unknown committed
2854 2855

join_table:
unknown's avatar
unknown committed
2856
	{
unknown's avatar
unknown committed
2857
	  SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2858
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
unknown's avatar
unknown committed
2859
	  sel->table_join_options= 0;
unknown's avatar
unknown committed
2860
	}
unknown's avatar
unknown committed
2861
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
2862
	{
unknown's avatar
unknown committed
2863 2864
	  LEX *lex= Lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
unknown's avatar
unknown committed
2865
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
unknown's avatar
unknown committed
2866
					   sel->get_table_join_options(),
unknown's avatar
unknown committed
2867
					   lex->lock_option,
2868 2869
					   sel->get_use_index(),
					   sel->get_ignore_index())))
2870
	    YYABORT;
unknown's avatar
unknown committed
2871
	}
unknown's avatar
unknown committed
2872
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2873
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
2874
        | '(' SELECT_SYM select_derived ')' opt_table_alias
unknown's avatar
unknown committed
2875 2876
	{
	  LEX *lex=Lex;
2877 2878 2879
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
unknown's avatar
unknown committed
2880
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
2881
				  TL_READ,(List<String> *)0,
unknown's avatar
unknown committed
2882 2883
	                          (List<String> *)0)))

unknown's avatar
unknown committed
2884
	    YYABORT;
unknown's avatar
unknown committed
2885
	};
unknown's avatar
unknown committed
2886

2887
select_derived:
unknown's avatar
unknown committed
2888
        {
unknown's avatar
unknown committed
2889
	  LEX *lex= Lex;
unknown's avatar
unknown committed
2890
	  lex->derived_tables= 1;
2891 2892 2893 2894 2895 2896
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN && 
	       lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)
	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
2897
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
unknown's avatar
unknown committed
2898
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
2899 2900
	    YYABORT;
	  mysql_init_select(lex);
2901
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
unknown's avatar
unknown committed
2902
	}
2903
        select_options select_item_list opt_select_from union_opt
2904
        ;
unknown's avatar
unknown committed
2905 2906 2907

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
2908
	| OUTER		{};
unknown's avatar
unknown committed
2909 2910 2911 2912

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
2913
          {
unknown's avatar
unknown committed
2914
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2915 2916 2917
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2918 2919 2920 2921 2922 2923 2924
	| FORCE_SYM key_usage_list
          {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	    sel->table_join_options|= TL_OPTION_FORCE_INDEX;
	  }
unknown's avatar
unknown committed
2925
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
2926
	  {
unknown's avatar
unknown committed
2927
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2928 2929
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
2930
	  };
unknown's avatar
unknown committed
2931 2932

key_usage_list:
unknown's avatar
unknown committed
2933
	key_or_index { Select->select_lex()->interval_list.empty(); }
unknown's avatar
unknown committed
2934 2935 2936 2937 2938 2939 2940 2941
        '(' key_list_or_empty ')'
        { $$= &Select->select_lex()->interval_list; }
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
unknown's avatar
unknown committed
2942 2943 2944

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
2945
        { Select->select_lex()->
2946
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
2947
				    system_charset_info)); }
unknown's avatar
unknown committed
2948
	| ident
unknown's avatar
unknown committed
2949
        { Select->select_lex()->
2950
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
2951
				    system_charset_info)); }
unknown's avatar
unknown committed
2952
	| PRIMARY_SYM
unknown's avatar
unknown committed
2953
        { Select->select_lex()->
2954
	    interval_list.push_back(new String("PRIMARY", 7,
2955
				    system_charset_info)); };
unknown's avatar
unknown committed
2956 2957 2958

using_list:
	ident
unknown's avatar
unknown committed
2959
	  {
unknown's avatar
unknown committed
2960
	    SELECT_LEX *sel= Select->select_lex();
2961 2962 2963 2964
	    if (!($$= new Item_func_eq(new Item_field(sel->db1, sel->table1,
						      $1.str),
				       new Item_field(sel->db2, sel->table2,
						      $1.str))))
unknown's avatar
unknown committed
2965 2966 2967 2968
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
2969
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2970
	    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)))
unknown's avatar
unknown committed
2971
	      YYABORT;
unknown's avatar
unknown committed
2972
	  };
unknown's avatar
unknown committed
2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986

interval:
	 DAY_HOUR_SYM		{ $$=INTERVAL_DAY_HOUR; }
	| DAY_MINUTE_SYM	{ $$=INTERVAL_DAY_MINUTE; }
	| DAY_SECOND_SYM	{ $$=INTERVAL_DAY_SECOND; }
	| DAY_SYM		{ $$=INTERVAL_DAY; }
	| HOUR_MINUTE_SYM	{ $$=INTERVAL_HOUR_MINUTE; }
	| HOUR_SECOND_SYM	{ $$=INTERVAL_HOUR_SECOND; }
	| HOUR_SYM		{ $$=INTERVAL_HOUR; }
	| MINUTE_SECOND_SYM	{ $$=INTERVAL_MINUTE_SECOND; }
	| MINUTE_SYM		{ $$=INTERVAL_MINUTE; }
	| MONTH_SYM		{ $$=INTERVAL_MONTH; }
	| SECOND_SYM		{ $$=INTERVAL_SECOND; }
	| YEAR_MONTH_SYM	{ $$=INTERVAL_YEAR_MONTH; }
unknown's avatar
unknown committed
2987
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
unknown's avatar
unknown committed
2988 2989 2990 2991

table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
2992
	| EQ;
unknown's avatar
unknown committed
2993 2994 2995 2996

opt_table_alias:
	/* empty */		{ $$=0; }
	| table_alias ident
unknown's avatar
unknown committed
2997
	  { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); };
unknown's avatar
unknown committed
2998

unknown's avatar
unknown committed
2999 3000 3001 3002
opt_all:
	/* empty */
	| ALL
	;
unknown's avatar
unknown committed
3003 3004

where_clause:
3005
	/* empty */  { Select->select_lex()->where= 0; }
3006 3007
	| WHERE expr
	  {
unknown's avatar
unknown committed
3008
	    Select->select_lex()->where= $2;
3009 3010 3011
	    if ($2)
	      $2->top_level_item();
	  }
unknown's avatar
unknown committed
3012
 	;
unknown's avatar
unknown committed
3013 3014 3015

having_clause:
	/* empty */
unknown's avatar
unknown committed
3016 3017 3018 3019 3020
	| HAVING
	  {
	    Select->select_lex()->parsing_place= SELECT_LEX_NODE::IN_HAVING;
          }
	  expr
unknown's avatar
unknown committed
3021 3022
	  {
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
3023 3024
	    sel->having= $3;
	    sel->parsing_place= SELECT_LEX_NODE::NO_MATTER;
unknown's avatar
unknown committed
3025 3026 3027
	    if ($3)
	      $3->top_level_item();
	  }
3028
	;
unknown's avatar
unknown committed
3029 3030

opt_escape:
3031
	ESCAPE_SYM TEXT_STRING_literal	{ $$= $2.str; }
unknown's avatar
unknown committed
3032
	| /* empty */			{ $$= (char*) "\\"; };
unknown's avatar
unknown committed
3033 3034 3035


/*
unknown's avatar
unknown committed
3036
   group by statement in select
unknown's avatar
unknown committed
3037 3038 3039 3040
*/

group_clause:
	/* empty */
3041
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
3042 3043

group_list:
unknown's avatar
unknown committed
3044
	group_list ',' order_ident order_dir
unknown's avatar
unknown committed
3045
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3046
	| order_ident order_dir
unknown's avatar
unknown committed
3047
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3048

3049 3050
olap_opt:
	/* empty */ {}
3051
	| WITH CUBE_SYM
3052
          {
3053
	    LEX *lex=Lex;
3054 3055 3056 3057 3058 3059
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE",
		       "global union parameters");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3060
	    lex->current_select->select_lex()->olap= CUBE_TYPE;
3061
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
3062
	    YYABORT;	/* To be deleted in 5.1 */
3063
	  }
3064
	| WITH ROLLUP_SYM
3065
          {
3066 3067 3068 3069 3070 3071 3072
	    LEX *lex= Lex;
	    if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP",
		       "global union parameters");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3073
	    lex->current_select->select_lex()->olap= ROLLUP_TYPE;
3074
	  }
3075
	;
3076

unknown's avatar
unknown committed
3077
/*
unknown's avatar
unknown committed
3078
   Order by statement in select
unknown's avatar
unknown committed
3079 3080
*/

3081
opt_order_clause:
unknown's avatar
unknown committed
3082
	/* empty */
unknown's avatar
unknown committed
3083
	| order_clause;
3084 3085

order_clause:
3086 3087
	ORDER_SYM BY
        {
unknown's avatar
unknown committed
3088
	  LEX *lex=Lex;
3089
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
3090
	      lex->current_select->select_lex()->olap !=
3091
	      UNSPECIFIED_OLAP_TYPE)
3092
	  {
3093
	    net_printf(lex->thd, ER_WRONG_USAGE,
3094 3095 3096 3097
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
3098
	} order_list;
unknown's avatar
unknown committed
3099 3100 3101

order_list:
	order_list ',' order_ident order_dir
unknown's avatar
unknown committed
3102
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
3103
	| order_ident order_dir
unknown's avatar
unknown committed
3104
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
3105 3106 3107

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
3108
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
3109
	| DESC { $$ =0; };
unknown's avatar
unknown committed
3110 3111


3112 3113 3114 3115 3116 3117 3118
opt_limit_clause_init:
	/* empty */
	{
	  SELECT_LEX_NODE *sel= Select;
          sel->offset_limit= 0L;
          sel->select_limit= Lex->thd->variables.select_limit;
	}
3119 3120 3121
	| limit_clause {}
	;

3122 3123 3124 3125 3126
opt_limit_clause:
	/* empty */	{}
	| limit_clause	{}
	;

3127
limit_clause:
3128
	LIMIT limit_options {}
unknown's avatar
unknown committed
3129
	;
unknown's avatar
unknown committed
3130 3131 3132

limit_options:
	ULONG_NUM
unknown's avatar
unknown committed
3133
	  {
unknown's avatar
unknown committed
3134
            SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
3135 3136 3137 3138 3139
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
3140
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
3141 3142
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
unknown's avatar
unknown committed
3143
	  }
unknown's avatar
unknown committed
3144
	| ULONG_NUM OFFSET_SYM ULONG_NUM
unknown's avatar
unknown committed
3145
	  {
unknown's avatar
unknown committed
3146
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
3147 3148 3149 3150
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
unknown's avatar
unknown committed
3151 3152 3153 3154 3155


delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
3156
	  LEX *lex=Lex;
3157
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
3158
	}
unknown's avatar
unknown committed
3159
	| LIMIT ulonglong_num
unknown's avatar
unknown committed
3160
	{ Select->select_limit= (ha_rows) $2; };
unknown's avatar
unknown committed
3161 3162

ULONG_NUM:
unknown's avatar
unknown committed
3163
	NUM	    { $$= strtoul($1.str,NULL,10); }
3164
	| LONG_NUM  { $$= (ulong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3165
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3166
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3167
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
unknown's avatar
unknown committed
3168

unknown's avatar
unknown committed
3169
ulonglong_num:
unknown's avatar
unknown committed
3170
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
3171
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
3172
	| LONG_NUM  { $$= (ulonglong) strtoll($1.str,NULL,10); }
unknown's avatar
unknown committed
3173
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
3174
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
unknown's avatar
unknown committed
3175 3176 3177 3178 3179 3180

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
3181 3182 3183 3184 3185 3186 3187
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
unknown's avatar
unknown committed
3188 3189 3190
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
unknown's avatar
unknown committed
3191
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
unknown's avatar
unknown committed
3192
	      YYABORT;
3193
	    Lex->uncacheable();
unknown's avatar
unknown committed
3194
	  }
unknown's avatar
unknown committed
3195
	  '(' procedure_list ')';
unknown's avatar
unknown committed
3196 3197 3198 3199


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
3200
	| procedure_list2 {};
unknown's avatar
unknown committed
3201 3202 3203

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
3204
	| procedure_item;
unknown's avatar
unknown committed
3205 3206 3207 3208

procedure_item:
	  remember_name expr
	  {
unknown's avatar
unknown committed
3209 3210
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
unknown's avatar
unknown committed
3211 3212
	      YYABORT;
	    if (!$2->name)
unknown's avatar
unknown committed
3213
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1), YYTHD->charset());
3214 3215 3216 3217 3218 3219
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
3220 3221
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
3222 3223
	        YYABORT;
	   }
3224
	   select_var_list
3225
	   {}
3226
           ;
unknown's avatar
unknown committed
3227

unknown's avatar
unknown committed
3228
select_var_list:
3229 3230 3231 3232 3233
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
3234
           {
3235
             LEX *lex=Lex;
unknown's avatar
unknown committed
3236
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
3237 3238
	       YYABORT;
	   }
unknown's avatar
unknown committed
3239
           ;
unknown's avatar
unknown committed
3240

3241
into:
unknown's avatar
unknown committed
3242
        INTO OUTFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3243
	{
3244
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3245 3246
	  if (!lex->describe)
	  {
unknown's avatar
unknown committed
3247
	    lex->uncacheable();
unknown's avatar
unknown committed
3248 3249 3250 3251 3252
	    if (!(lex->exchange= new sql_exchange($3.str,0)))
	      YYABORT;
	    if (!(lex->result= new select_export(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3253 3254
	}
	opt_field_term opt_line_term
unknown's avatar
unknown committed
3255
	| INTO DUMPFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3256
	{
3257
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3258 3259
	  if (!lex->describe)
	  {
unknown's avatar
unknown committed
3260
	    lex->uncacheable();
unknown's avatar
unknown committed
3261 3262 3263 3264 3265
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
3266
	}
3267
        | INTO select_var_list_init
unknown's avatar
unknown committed
3268
	{
3269
	  Lex->uncacheable();
3270 3271
	}
        ;
unknown's avatar
unknown committed
3272

unknown's avatar
unknown committed
3273 3274 3275
/*
  DO statement
*/
unknown's avatar
unknown committed
3276

3277
do:	DO_SYM
unknown's avatar
unknown committed
3278 3279 3280 3281 3282 3283
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
3284 3285 3286 3287
	values
	{}
	;

unknown's avatar
unknown committed
3288
/*
3289
  Drop : delete tables or index or user
unknown's avatar
unknown committed
3290 3291 3292
*/

drop:
3293
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
unknown's avatar
unknown committed
3294
	{
unknown's avatar
unknown committed
3295 3296
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
3297 3298
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
unknown's avatar
unknown committed
3299 3300 3301
	}
	| DROP INDEX ident ON table_ident {}
	  {
unknown's avatar
unknown committed
3302 3303 3304 3305
	     LEX *lex=Lex;
	     lex->sql_command= SQLCOM_DROP_INDEX;
	     lex->drop_list.empty();
	     lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
unknown's avatar
unknown committed
3306
						     $3.str));
unknown's avatar
unknown committed
3307 3308
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3309 3310 3311 3312
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
3313 3314 3315 3316
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
3317
	 }
unknown's avatar
unknown committed
3318
	| DROP UDF_SYM IDENT_sys
unknown's avatar
unknown committed
3319
	  {
unknown's avatar
unknown committed
3320 3321
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
3322
	    lex->udf.name = $3;
3323 3324 3325 3326 3327 3328 3329 3330 3331 3332
	  }
	| DROP USER
	  {
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_USER;
	    lex->users_list.empty();
	  } 
	  user_list
	  {}
	  ;
unknown's avatar
unknown committed
3333 3334 3335


table_list:
3336
	table_name
unknown's avatar
unknown committed
3337
	| table_list ',' table_name;
unknown's avatar
unknown committed
3338

3339
table_name:
unknown's avatar
unknown committed
3340
	table_ident
unknown's avatar
unknown committed
3341 3342 3343 3344 3345
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
unknown's avatar
unknown committed
3346 3347

if_exists:
3348
	/* empty */ { $$= 0; }
3349 3350
	| IF EXISTS { $$= 1; }
	;
unknown's avatar
unknown committed
3351

3352 3353 3354 3355
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
unknown's avatar
unknown committed
3356 3357 3358 3359 3360
/*
** Insert : add new data to table
*/

insert:
3361 3362 3363 3364 3365 3366
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3367
	  lex->select_lex.insert_select= 1;
3368
	} insert_lock_option
3369
	opt_ignore insert2
unknown's avatar
unknown committed
3370
	{
unknown's avatar
unknown committed
3371
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3372
	}
3373
	insert_field_spec opt_insert_update
3374
	{}
unknown's avatar
unknown committed
3375
	;
unknown's avatar
unknown committed
3376 3377

replace:
3378 3379
	REPLACE
	{
3380
	  LEX *lex=Lex;
3381 3382
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
3383
	  lex->select_lex.insert_select= 1;
3384
	}
unknown's avatar
unknown committed
3385 3386
	replace_lock_option insert2
	{
unknown's avatar
unknown committed
3387
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3388 3389
	}
	insert_field_spec
3390
	{}
unknown's avatar
unknown committed
3391
	{}
unknown's avatar
unknown committed
3392
	;
unknown's avatar
unknown committed
3393 3394

insert_lock_option:
unknown's avatar
unknown committed
3395 3396 3397 3398
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3399
	;
unknown's avatar
unknown committed
3400 3401

replace_lock_option:
unknown's avatar
unknown committed
3402 3403
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
3404 3405 3406

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
3407
	| insert_table {};
unknown's avatar
unknown committed
3408 3409

insert_table:
3410
	table_name
unknown's avatar
unknown committed
3411
	{
unknown's avatar
unknown committed
3412 3413 3414 3415
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
3416
	};
unknown's avatar
unknown committed
3417 3418 3419 3420 3421

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
unknown's avatar
unknown committed
3422 3423 3424
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3425 3426
	      YYABORT;
	   }
unknown's avatar
unknown committed
3427
	   ident_eq_list;
unknown's avatar
unknown committed
3428 3429 3430 3431

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
3432
	| '(' ')'	  { };
unknown's avatar
unknown committed
3433 3434 3435

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
3436
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
3437 3438 3439

insert_values:
	VALUES	values_list  {}
unknown's avatar
unknown committed
3440
	| VALUE_SYM values_list  {}
unknown's avatar
unknown committed
3441 3442 3443 3444 3445
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
unknown's avatar
unknown committed
3446
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3447
	    mysql_init_select(lex);
3448 3449 3450 3451 3452
	    /*
	      it is not simple select => table list will be
              preprocessed before passing to handle_select
	    */
	    lex->select_lex.insert_select= 0;
unknown's avatar
unknown committed
3453
	    lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
unknown's avatar
unknown committed
3454
	  }
unknown's avatar
unknown committed
3455 3456 3457
	  select_options select_item_list
	  {
	    Select->parsing_place= SELECT_LEX_NODE::NO_MATTER;
unknown's avatar
unknown committed
3458
	  }
unknown's avatar
unknown committed
3459
	  opt_select_from select_lock_type
3460
          union_clause {}
unknown's avatar
unknown committed
3461
	;
unknown's avatar
unknown committed
3462 3463 3464

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
3465
	| no_braces;
unknown's avatar
unknown committed
3466 3467 3468 3469

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
3470
	ident_eq_value;
unknown's avatar
unknown committed
3471 3472

ident_eq_value:
unknown's avatar
unknown committed
3473
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
3474
	 {
unknown's avatar
unknown committed
3475 3476 3477
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
3478
	    YYABORT;
unknown's avatar
unknown committed
3479
	 };
unknown's avatar
unknown committed
3480 3481

equal:	EQ		{}
unknown's avatar
unknown committed
3482 3483 3484 3485 3486 3487 3488
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
3489 3490 3491 3492 3493 3494 3495 3496 3497

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
3498 3499
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3500
	    YYABORT;
unknown's avatar
unknown committed
3501
	 };
unknown's avatar
unknown committed
3502 3503 3504

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
3505
	| values;
unknown's avatar
unknown committed
3506 3507

values:
unknown's avatar
unknown committed
3508
	values ','  expr_or_default
unknown's avatar
unknown committed
3509 3510 3511 3512
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
3513 3514 3515 3516 3517 3518 3519 3520
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3521
	expr	  { $$= $1;}
unknown's avatar
SCRUM  
unknown committed
3522
	| DEFAULT {$$= new Item_default_value(); }
unknown's avatar
unknown committed
3523
	;
unknown's avatar
unknown committed
3524

3525 3526
opt_insert_update:
        /* empty */
unknown's avatar
unknown committed
3527
        | ON DUPLICATE_SYM
3528 3529 3530 3531 3532 3533 3534 3535 3536
          { /* for simplisity, let's forget about
               INSERT ... SELECT ... UPDATE
               for a moment */
	    if (Lex->sql_command != SQLCOM_INSERT)
            {
	      send_error(Lex->thd, ER_SYNTAX_ERROR);
              YYABORT;
            }
          }
3537
          KEY_SYM UPDATE_SYM update_list
3538 3539
        ;

unknown's avatar
unknown committed
3540 3541 3542
/* Update rows in a table */

update:
3543 3544
	UPDATE_SYM
	{
3545
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3546
	  mysql_init_select(lex);
3547
          lex->sql_command= SQLCOM_UPDATE;
3548
        }
unknown's avatar
unknown committed
3549 3550 3551
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3552
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3553
	  Select->set_lock_for_tables($3);
3554
          if (lex->select_lex.table_list.elements > 1)
unknown's avatar
unknown committed
3555
            lex->sql_command= SQLCOM_UPDATE_MULTI;
unknown's avatar
unknown committed
3556 3557
	}
	;
unknown's avatar
unknown committed
3558 3559

update_list:
unknown's avatar
SCRUM  
unknown committed
3560
	update_list ',' simple_ident equal expr_or_default
unknown's avatar
unknown committed
3561
	{
unknown's avatar
unknown committed
3562
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
unknown's avatar
unknown committed
3563 3564
	    YYABORT;
	}
unknown's avatar
SCRUM  
unknown committed
3565
	| simple_ident equal expr_or_default
unknown's avatar
unknown committed
3566
	  {
unknown's avatar
unknown committed
3567
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
unknown's avatar
unknown committed
3568
	      YYABORT;
unknown's avatar
unknown committed
3569
	  };
unknown's avatar
unknown committed
3570 3571

opt_low_priority:
3572
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3573
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3574 3575 3576 3577

/* Delete rows from a table */

delete:
3578
	DELETE_SYM
3579
	{
3580 3581
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
unknown's avatar
unknown committed
3582
	  lex->lock_option= lex->thd->update_lock_default;
3583
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3584
	}
unknown's avatar
unknown committed
3585 3586
	opt_delete_options single_multi {}
	;
3587 3588

single_multi:
unknown's avatar
unknown committed
3589 3590
 	FROM table_ident
	{
unknown's avatar
unknown committed
3591 3592
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
unknown's avatar
unknown committed
3593 3594 3595
	    YYABORT;
	}
	where_clause opt_order_clause
3596
	delete_limit_clause {}
unknown's avatar
unknown committed
3597
	| table_wild_list
unknown's avatar
unknown committed
3598
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
3599
          FROM join_table_list where_clause
unknown's avatar
unknown committed
3600 3601
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3602 3603 3604
	  USING join_table_list where_clause
	  {}
	;
unknown's avatar
unknown committed
3605 3606 3607

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
3608
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
3609 3610

table_wild_one:
unknown's avatar
unknown committed
3611
	ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3612
	{
unknown's avatar
unknown committed
3613 3614
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
unknown's avatar
unknown committed
3615 3616
	    YYABORT;
        }
unknown's avatar
unknown committed
3617
	| ident '.' ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3618
	  {
unknown's avatar
unknown committed
3619 3620
	    if (!Select->add_table_to_list(YYTHD,
					   new Table_ident(YYTHD, $1, $3, 0),
unknown's avatar
unknown committed
3621 3622
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
unknown's avatar
unknown committed
3623
	      YYABORT;
unknown's avatar
unknown committed
3624
	  }
unknown's avatar
unknown committed
3625
	;
unknown's avatar
unknown committed
3626 3627

opt_wild:
3628
	/* empty */	{}
unknown's avatar
unknown committed
3629
	| '.' '*'	{};
unknown's avatar
unknown committed
3630 3631


3632
opt_delete_options:
unknown's avatar
unknown committed
3633
	/* empty */	{}
unknown's avatar
unknown committed
3634
	| opt_delete_option opt_delete_options {};
3635 3636

opt_delete_option:
3637
	QUICK		{ Select->options|= OPTION_QUICK; }
unknown's avatar
unknown committed
3638
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
3639

3640
truncate:
unknown's avatar
unknown committed
3641
	TRUNCATE_SYM opt_table_sym table_name
3642
	{
3643
	  LEX* lex= Lex;
3644
	  lex->sql_command= SQLCOM_TRUNCATE;
3645
	  lex->select_lex.options= 0;
3646
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3647 3648
	}
	;
3649

unknown's avatar
unknown committed
3650 3651
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
3652
	| TABLE_SYM;
3653

unknown's avatar
unknown committed
3654 3655
/* Show things */

3656 3657
show:	SHOW
	{
unknown's avatar
unknown committed
3658 3659 3660 3661
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
unknown's avatar
unknown committed
3662
	show_param
3663 3664
	{}
	;
unknown's avatar
unknown committed
3665 3666 3667 3668 3669

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
3670
	  {
3671
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3672
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3673 3674
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
unknown's avatar
unknown committed
3675
	   }
unknown's avatar
unknown committed
3676
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
3677
	  {
3678
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3679
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3680 3681
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
3682
	  }
3683
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
3684
	  {
3685
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3686
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
3687 3688
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
3689
	  }
unknown's avatar
unknown committed
3690
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
3691 3692
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3693 3694
	    if ($5)
	      $4->change_db($5);
unknown's avatar
unknown committed
3695
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
unknown's avatar
unknown committed
3696 3697
	      YYABORT;
	  }
3698
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
unknown's avatar
unknown committed
3699
	  TEXT_STRING_sys AND MASTER_LOG_POS_SYM EQ ulonglong_num
3700
	  AND MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
3701 3702 3703 3704 3705
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
3706
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
3707
          }
3708
        | BINARY LOGS_SYM
unknown's avatar
unknown committed
3709 3710
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
3711 3712 3713 3714 3715
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
3716
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
3717
          {
3718 3719
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
3720
          } opt_limit_clause_init
unknown's avatar
unknown committed
3721 3722 3723 3724 3725
	| keys_or_index FROM table_ident opt_db
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
unknown's avatar
unknown committed
3726
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
unknown's avatar
unknown committed
3727 3728
	      YYABORT;
	  }
unknown's avatar
unknown committed
3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743
	| COLUMN_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_COLUMN_TYPES;
	  }
	| TABLE_SYM TYPES_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_TABLE_TYPES;
	  }
	| PRIVILEGES
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_PRIVILEGES;
	  }
3744
        | COUNT_SYM '(' '*' ')' WARNINGS
3745
          { (void) create_select_for_variable("warning_count"); }
3746
        | COUNT_SYM '(' '*' ')' ERRORS
3747
	  { (void) create_select_for_variable("error_count"); }
3748
        | WARNINGS opt_limit_clause_init
unknown's avatar
unknown committed
3749
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
3750
        | ERRORS opt_limit_clause_init
3751
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
unknown's avatar
unknown committed
3752 3753
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
3754 3755
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
unknown's avatar
unknown committed
3756 3757
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
3758
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
3759
	  {
3760
	    THD *thd= YYTHD;
3761
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
unknown's avatar
unknown committed
3762
	    thd->lex.option_type= (enum_var_type) $1;
3763
	  }
3764
	| charset wild
3765
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
3766 3767
	| COLLATION_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; }
unknown's avatar
unknown committed
3768 3769
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
unknown's avatar
unknown committed
3770
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
3771 3772 3773 3774 3775 3776
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
3777
	| CREATE DATABASE opt_if_not_exists ident
unknown's avatar
unknown committed
3778 3779
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
3780 3781
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
3782
	  }
unknown's avatar
unknown committed
3783 3784 3785
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
unknown's avatar
unknown committed
3786
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
unknown's avatar
unknown committed
3787 3788 3789 3790 3791
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
3792
          }
unknown's avatar
unknown committed
3793 3794 3795
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
3796
          };
unknown's avatar
unknown committed
3797 3798 3799

opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
3800
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
3801 3802 3803

wild:
	/* empty */
unknown's avatar
unknown committed
3804
	| LIKE text_string { Lex->wild= $2; };
unknown's avatar
unknown committed
3805

unknown's avatar
unknown committed
3806 3807
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
3808
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
3809

unknown's avatar
unknown committed
3810 3811
from_or_in:
	FROM
unknown's avatar
unknown committed
3812
	| IN_SYM;
unknown's avatar
unknown committed
3813

unknown's avatar
unknown committed
3814 3815
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
3816
        | IN_SYM TEXT_STRING_sys { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
3817 3818 3819

binlog_from:
	/* empty */ { Lex->mi.pos = 4; /* skip magic number */ }
unknown's avatar
unknown committed
3820
        | FROM ulonglong_num { Lex->mi.pos = $2; };
unknown's avatar
unknown committed
3821 3822


unknown's avatar
unknown committed
3823 3824 3825 3826
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
3827 3828 3829 3830
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3831
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
unknown's avatar
unknown committed
3832 3833
	    YYABORT;
	}
3834
	opt_describe_column {}
unknown's avatar
unknown committed
3835
	| describe_command { Lex->describe=1; } select
3836
          {
unknown's avatar
unknown committed
3837
	    LEX *lex=Lex;
3838
	    lex->select_lex.options|= SELECT_DESCRIBE;
unknown's avatar
unknown committed
3839 3840
	  }
	;
unknown's avatar
unknown committed
3841 3842 3843

describe_command:
	DESC
unknown's avatar
unknown committed
3844
	| DESCRIBE;
unknown's avatar
unknown committed
3845 3846 3847 3848

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
3849
	| ident
3850
	  { Lex->wild= new String((const char*) $1.str,$1.length,system_charset_info); };
unknown's avatar
unknown committed
3851 3852 3853 3854 3855


/* flush things */

flush:
3856
	FLUSH_SYM opt_no_write_to_binlog
unknown's avatar
unknown committed
3857 3858 3859
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
3860
          lex->no_write_to_binlog= $2; 
unknown's avatar
unknown committed
3861
	}
3862 3863 3864
	flush_options
	{}
	;
unknown's avatar
unknown committed
3865 3866 3867

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
3868
	| flush_option;
unknown's avatar
unknown committed
3869 3870

flush_option:
3871
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
unknown's avatar
unknown committed
3872
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
3873
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
3874 3875 3876 3877
	| HOSTS_SYM	{ Lex->type|= REFRESH_HOSTS; }
	| PRIVILEGES	{ Lex->type|= REFRESH_GRANT; }
	| LOGS_SYM	{ Lex->type|= REFRESH_LOG; }
	| STATUS_SYM	{ Lex->type|= REFRESH_STATUS; }
unknown's avatar
unknown committed
3878 3879
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3880 3881
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
3882

unknown's avatar
unknown committed
3883
opt_table_list:
3884 3885
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
3886

unknown's avatar
unknown committed
3887
reset:
unknown's avatar
unknown committed
3888 3889 3890 3891
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
3892 3893 3894 3895
	} reset_options
	{}
	;

unknown's avatar
unknown committed
3896 3897
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
3898
	| reset_option;
unknown's avatar
unknown committed
3899 3900

reset_option:
unknown's avatar
unknown committed
3901 3902
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
3903
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
3904

unknown's avatar
unknown committed
3905
purge:
unknown's avatar
unknown committed
3906 3907 3908 3909
	PURGE
	{
	  LEX *lex=Lex;
	  lex->type=0;
3910 3911 3912 3913 3914
	} purge_options
	{}
	;

purge_options:
unknown's avatar
unknown committed
3915 3916 3917
	LOGS_SYM purge_option
	| MASTER_SYM LOGS_SYM purge_option
	;
3918 3919

purge_option:
unknown's avatar
unknown committed
3920
        TO_SYM TEXT_STRING_sys
3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933
        {
	   Lex->sql_command = SQLCOM_PURGE;
	   Lex->to_log = $2.str;
        }
	| BEFORE_SYM expr
	{
	  if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2))
	  {
	    net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE");
	    YYABORT;	  
	  }
	  Item *tmp= new Item_func_unix_timestamp($2);
	  Lex->sql_command = SQLCOM_PURGE_BEFORE;
3934
	  Lex->purge_time= (ulong) tmp->val_int();
unknown's avatar
unknown committed
3935
	}
unknown's avatar
unknown committed
3936
	;
unknown's avatar
unknown committed
3937

unknown's avatar
unknown committed
3938 3939 3940
/* kill threads */

kill:
3941
	KILL_SYM expr
unknown's avatar
unknown committed
3942
	{
unknown's avatar
unknown committed
3943
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3944
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
3945
	  {
3946
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
3947 3948 3949 3950
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
3951
	};
unknown's avatar
unknown committed
3952 3953 3954 3955

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
3956 3957
	{
	  LEX *lex=Lex;
3958 3959
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
3960
	};
unknown's avatar
unknown committed
3961 3962 3963

/* import, export of files */

unknown's avatar
unknown committed
3964
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING_sys
unknown's avatar
unknown committed
3965
	{
unknown's avatar
unknown committed
3966 3967
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
unknown's avatar
unknown committed
3968 3969
	  lex->lock_option= $3;
	  lex->local_file=  $4;
unknown's avatar
unknown committed
3970
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
3971
	    YYABORT;
unknown's avatar
unknown committed
3972
	  lex->field_list.empty();
unknown's avatar
unknown committed
3973 3974 3975 3976
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
unknown's avatar
unknown committed
3977
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3978 3979 3980
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
3981
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
3982 3983
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
unknown's avatar
unknown committed
3984
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3985
	    YYABORT;
unknown's avatar
unknown committed
3986 3987

        }
3988 3989 3990 3991
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
3992
        };
unknown's avatar
unknown committed
3993 3994 3995

opt_local:
	/* empty */	{ $$=0;}
unknown's avatar
unknown committed
3996
	| LOCAL_SYM	{ $$=1;};
unknown's avatar
unknown committed
3997

unknown's avatar
unknown committed
3998
load_data_lock:
3999
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4000 4001
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
4002 4003


unknown's avatar
unknown committed
4004 4005 4006
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
unknown's avatar
unknown committed
4007
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
4008 4009 4010

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
4011
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
4012 4013 4014

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
4015
	| field_term;
unknown's avatar
unknown committed
4016 4017 4018 4019

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
4020 4021 4022 4023 4024
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
unknown's avatar
unknown committed
4025
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
unknown's avatar
unknown committed
4026
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
unknown's avatar
unknown committed
4027 4028 4029

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
4030
	| LINES line_term_list;
unknown's avatar
unknown committed
4031 4032 4033

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
4034
	| line_term;
unknown's avatar
unknown committed
4035 4036 4037

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
unknown's avatar
unknown committed
4038
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
unknown's avatar
unknown committed
4039 4040 4041 4042

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
unknown's avatar
unknown committed
4043
	  { Lex->exchange->skip_lines=atol($2.str); };
unknown's avatar
unknown committed
4044 4045 4046 4047

/* Common definitions */

text_literal:
4048
	TEXT_STRING_literal
unknown's avatar
unknown committed
4049 4050
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4051
	  $$ = new Item_string($1.str,$1.length,thd->variables.collation_connection);
unknown's avatar
unknown committed
4052
	}
unknown's avatar
unknown committed
4053
	| NCHAR_STRING
4054
	{ $$=  new Item_string($1.str,$1.length,national_charset_info); }
4055
	| UNDERSCORE_CHARSET TEXT_STRING
4056
	  { $$ = new Item_string($2.str,$2.length,Lex->charset); }
4057
	| text_literal TEXT_STRING_literal
unknown's avatar
unknown committed
4058 4059
	  { ((Item_string*) $1)->append($2.str,$2.length); }
	;
unknown's avatar
unknown committed
4060 4061

text_string:
4062
	TEXT_STRING_literal
unknown's avatar
unknown committed
4063
	{ $$=  new String($1.str,$1.length,YYTHD->variables.collation_connection); }
unknown's avatar
unknown committed
4064 4065
	| HEX_NUM
	  {
4066
	    Item *tmp = new Item_varbinary($1.str,$1.length);
unknown's avatar
unknown committed
4067
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
4068 4069 4070
	  }
	;

unknown's avatar
unknown committed
4071
param_marker:
4072
        '?'
unknown's avatar
unknown committed
4073
        {
4074
	  LEX *lex=Lex;
4075
          if (YYTHD->prepare_command)
4076
          {
4077
            lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query)));
4078
            lex->param_count++;
unknown's avatar
unknown committed
4079
          }
4080
          else
unknown's avatar
unknown committed
4081 4082 4083 4084
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
4085 4086 4087
        }
	;

unknown's avatar
unknown committed
4088 4089
literal:
	text_literal	{ $$ =	$1; }
4090 4091
	| 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); }
unknown's avatar
unknown committed
4092
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
unknown's avatar
unknown committed
4093 4094 4095
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
4096
			  Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
4097
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
4098 4099 4100 4101
	| UNDERSCORE_CHARSET HEX_NUM
	  { 
	    Item *tmp= new Item_varbinary($2.str,$2.length);
	    String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0;
4102 4103
	    $$ = new Item_string(str ? str->ptr() : "", str ? str->length() : 0, 
				 Lex->charset);
4104
	  }
unknown's avatar
unknown committed
4105 4106
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
4107
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
4108 4109 4110 4111 4112 4113 4114

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

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
4115
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
4116 4117

table_wild:
4118 4119 4120 4121 4122
	ident '.' '*' 
	{
	  $$ = new Item_field(NullS,$1.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
unknown's avatar
unknown committed
4123
	| ident '.' ident '.' '*'
4124 4125 4126 4127 4128 4129 4130
	{
	  $$ = new Item_field((YYTHD->client_capabilities &
   			     CLIENT_NO_SCHEMA ? NullS : $1.str),
			     $3.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
	;
unknown's avatar
unknown committed
4131 4132

order_ident:
unknown's avatar
unknown committed
4133
	expr { $$=$1; };
unknown's avatar
unknown committed
4134 4135 4136

simple_ident:
	ident
unknown's avatar
unknown committed
4137
	{
4138
	  SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
4139 4140 4141 4142
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
              (Item*) new Item_field(NullS,NullS,$1.str) :
	      (Item*) new Item_ref(NullS,NullS,$1.str);
unknown's avatar
unknown committed
4143
	}
unknown's avatar
unknown committed
4144
	| ident '.' ident
unknown's avatar
unknown committed
4145
	{
unknown's avatar
unknown committed
4146 4147 4148 4149 4150 4151 4152 4153 4154
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $1.str, thd->where);
	  }
unknown's avatar
unknown committed
4155 4156 4157 4158
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$1.str,$3.str) :
	      (Item*) new Item_ref(NullS,$1.str,$3.str);
unknown's avatar
unknown committed
4159
	}
unknown's avatar
unknown committed
4160
	| '.' ident '.' ident
unknown's avatar
unknown committed
4161
	{
unknown's avatar
unknown committed
4162 4163 4164 4165 4166 4167 4168 4169 4170
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $2.str, thd->where);
	  }
unknown's avatar
unknown committed
4171 4172 4173 4174
	  $$= (sel->parsing_place != SELECT_LEX_NODE::IN_HAVING ||
	       sel->get_in_sum_expr() > 0) ?
	      (Item*) new Item_field(NullS,$2.str,$4.str) :
              (Item*) new Item_ref(NullS,$2.str,$4.str);
unknown's avatar
unknown committed
4175
	}
unknown's avatar
unknown committed
4176
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
4177
	{
unknown's avatar
unknown committed
4178 4179 4180 4181 4182 4183 4184 4185 4186
	  THD *thd= YYTHD;
	  LEX *lex= &thd->lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
	  if (sel->no_table_names_allowed)
	  {
	    my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, 
			    ER(ER_TABLENAME_NOT_ALLOWED_HERE),
			    MYF(0), $3.str, thd->where);
	  }
unknown's avatar
unknown committed
4187 4188 4189 4190 4191 4192 4193 4194
	  $$= (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) :
	      (Item*) new Item_ref((YYTHD->client_capabilities &
				    CLIENT_NO_SCHEMA ? NullS : $1.str),
                                   $3.str, $5.str);
unknown's avatar
unknown committed
4195
	};
unknown's avatar
unknown committed
4196 4197 4198 4199 4200


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
unknown's avatar
unknown committed
4201
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
4202 4203 4204

table_ident:
	ident			{ $$=new Table_ident($1); }
unknown's avatar
unknown committed
4205
	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
unknown's avatar
unknown committed
4206 4207
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
unknown's avatar
unknown committed
4208

unknown's avatar
unknown committed
4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244
IDENT_sys:
	IDENT
	{
	  THD *thd= YYTHD;
	  if (my_charset_same(thd->charset(),system_charset_info))
	  {
	    $$=$1;
	  }
	  else
	  {
	    String ident;
	    ident.copy($1.str,$1.length,thd->charset(),system_charset_info);
	    $$.str= thd->strmake(ident.ptr(),ident.length());
	    $$.length= ident.length();
	  }
	}
	;

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

4245
TEXT_STRING_literal:
unknown's avatar
unknown committed
4246 4247 4248
	TEXT_STRING
	{
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4249
	  if (my_charset_same(thd->charset(),thd->variables.collation_connection))
unknown's avatar
unknown committed
4250 4251 4252 4253 4254 4255
	  {
	    $$=$1;
	  }
	  else
	  {
	    String ident;
unknown's avatar
unknown committed
4256
	    ident.copy($1.str,$1.length,thd->charset(),thd->variables.collation_connection);
unknown's avatar
unknown committed
4257 4258 4259 4260 4261 4262 4263
	    $$.str= thd->strmake(ident.ptr(),ident.length());
	    $$.length= ident.length();
	  }
	}
	;


unknown's avatar
unknown committed
4264
ident:
unknown's avatar
unknown committed
4265
	IDENT_sys	    { $$=$1; }
unknown's avatar
unknown committed
4266 4267
	| keyword
	{
4268 4269
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
unknown's avatar
unknown committed
4270
	  $$.length=$1.length;
4271 4272
	  if (lex->next_state != MY_LEX_END)
	    lex->next_state= MY_LEX_OPERATOR_OR_IDENT;
4273 4274
	}
	;
unknown's avatar
unknown committed
4275 4276

ident_or_text:
unknown's avatar
unknown committed
4277 4278 4279
	ident 			{ $$=$1;}
	| TEXT_STRING_sys	{ $$=$1;}
	| LEX_HOSTNAME		{ $$=$1;};
unknown's avatar
unknown committed
4280 4281 4282 4283

user:
	ident_or_text
	{
unknown's avatar
unknown committed
4284 4285
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4286
	    YYABORT;
4287 4288 4289 4290
	  $$->user = $1;
	  $$->host.str= (char *) "%";
	  $$->host.length= 1;
	}
unknown's avatar
unknown committed
4291 4292
	| ident_or_text '@' ident_or_text
	  {
unknown's avatar
unknown committed
4293 4294
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
4295 4296
	      YYABORT;
	    $$->user = $1; $$->host=$3;
unknown's avatar
unknown committed
4297
	  };
unknown's avatar
unknown committed
4298 4299 4300 4301 4302 4303

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
4304
	| AGAINST		{}
unknown's avatar
unknown committed
4305
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
4306
	| ANY_SYM		{}
unknown's avatar
unknown committed
4307
	| ASCII_SYM		{}
unknown's avatar
unknown committed
4308
	| AUTO_INC		{}
unknown's avatar
unknown committed
4309 4310
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
4311
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
4312
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
4313
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
4314
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
4315 4316
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
4317
	| BOOLEAN_SYM		{}
4318
	| BYTE_SYM		{}
unknown's avatar
unknown committed
4319
	| CACHE_SYM		{}
4320
	| CHANGED		{}
4321
	| CHARSET		{}
unknown's avatar
unknown committed
4322
	| CHECKSUM_SYM		{}
4323
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
4324
	| CLIENT_SYM		{}
4325
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
4326
	| COLLATION_SYM		{}
unknown's avatar
unknown committed
4327
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
4328
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
4329
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
4330
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
4331
	| CONCURRENT		{}
4332
	| CUBE_SYM		{}
unknown's avatar
unknown committed
4333 4334 4335 4336 4337
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
4338 4339
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
4340
	| DO_SYM		{}
4341
	| DUAL_SYM		{}
unknown's avatar
unknown committed
4342 4343
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
unknown's avatar
unknown committed
4344 4345 4346 4347
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
4348
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
4349
	| EXECUTE_SYM		{}
unknown's avatar
unknown committed
4350
	| EXTENDED_SYM		{}
4351
	| FAST_SYM		{}
unknown's avatar
unknown committed
4352 4353
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
4354
	| FULL			{}
unknown's avatar
unknown committed
4355 4356 4357 4358
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
4359
	| GEOMETRY_SYM		{}
4360
	| GEOMETRYCOLLECTION	{}
unknown's avatar
unknown committed
4361
	| GRANTS		{}
unknown's avatar
unknown committed
4362
	| GLOBAL_SYM		{}
4363
	| HANDLER_SYM		{}
4364 4365
	| HEAP_SYM		{}
	| HELP_SYM		{}
unknown's avatar
unknown committed
4366 4367 4368
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
4369
	| INDEXES		{}
unknown's avatar
unknown committed
4370
	| ISOLATION		{}
unknown's avatar
unknown committed
4371
	| ISAM_SYM		{}
unknown's avatar
unknown committed
4372
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
4373
	| INNOBASE_SYM		{}
4374
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
4375
	| RELAY_THREAD		{}
4376
	| LAST_SYM		{}
unknown's avatar
unknown committed
4377
	| LEAVES                {}
unknown's avatar
unknown committed
4378
	| LEVEL_SYM		{}
4379
	| LINESTRING		{}
unknown's avatar
unknown committed
4380
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
4381
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
4382 4383 4384 4385 4386 4387 4388 4389 4390 4391
	| LOGS_SYM		{}
	| MAX_ROWS		{}
	| MASTER_SYM		{}
	| MASTER_HOST_SYM	{}
	| MASTER_PORT_SYM	{}
	| MASTER_LOG_FILE_SYM	{}
	| MASTER_LOG_POS_SYM	{}
	| MASTER_USER_SYM	{}
	| MASTER_PASSWORD_SYM	{}
	| MASTER_CONNECT_RETRY_SYM	{}
unknown's avatar
unknown committed
4392 4393 4394
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
4395
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
4396
	| MERGE_SYM		{}
4397
	| MEMORY_SYM		{}
unknown's avatar
unknown committed
4398 4399 4400
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
4401
	| MODE_SYM		{}
unknown's avatar
unknown committed
4402
	| MONTH_SYM		{}
4403 4404 4405
	| MULTILINESTRING	{}
	| MULTIPOINT		{}
	| MULTIPOLYGON		{}
unknown's avatar
unknown committed
4406
	| MYISAM_SYM		{}
unknown's avatar
unknown committed
4407
	| NAMES_SYM		{}
unknown's avatar
unknown committed
4408 4409
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
4410
	| NEXT_SYM		{}
unknown's avatar
unknown committed
4411
	| NEW_SYM		{}
unknown's avatar
unknown committed
4412
	| NO_SYM		{}
4413
	| NONE_SYM		{}
unknown's avatar
unknown committed
4414
	| OFFSET_SYM		{}
4415
	| OPEN_SYM		{}
unknown's avatar
unknown committed
4416
	| PACK_KEYS_SYM		{}
4417
	| PARTIAL		{}
unknown's avatar
unknown committed
4418
	| PASSWORD		{}
4419
	| POINT_SYM		{}
4420
	| POLYGON		{}
4421
	| PREV_SYM		{}
unknown's avatar
unknown committed
4422 4423
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
4424
	| QUERY_SYM		{}
4425
	| QUICK			{}
unknown's avatar
unknown committed
4426
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
4427 4428
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
4429
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
4430
	| RAID_TYPE		{}
unknown's avatar
unknown committed
4431 4432
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
4433 4434
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
4435
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
4436
	| REPLICATION		{}
unknown's avatar
unknown committed
4437
	| RESET_SYM		{}
4438
	| RESOURCES		{}
unknown's avatar
unknown committed
4439
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
4440
	| ROLLBACK_SYM		{}
4441
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
4442 4443 4444 4445
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
	| SECOND_SYM		{}
4446
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
4447 4448
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
4449
	| SIGNED_SYM		{}
4450
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
4451
	| SHARE_SYM		{}
unknown's avatar
unknown committed
4452
	| SHUTDOWN		{}
unknown's avatar
unknown committed
4453
	| SLAVE			{}
unknown's avatar
unknown committed
4454
	| SOUNDS_SYM		{}
unknown's avatar
unknown committed
4455
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
4456
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
4457
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
4458
	| SQL_THREAD		{}
unknown's avatar
unknown committed
4459 4460 4461 4462
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
unknown's avatar
unknown committed
4463
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
4464
	| SUPER_SYM		{}
unknown's avatar
unknown committed
4465 4466
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
4467
	| TRANSACTION_SYM	{}
4468
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
4469 4470 4471 4472
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
unknown's avatar
unknown committed
4473
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
4474
	| UNICODE_SYM		{}
4475
	| USER			{}
unknown's avatar
unknown committed
4476
	| USE_FRM		{}
unknown's avatar
unknown committed
4477
	| VARIABLES		{}
4478
	| VALUE_SYM		{}
unknown's avatar
unknown committed
4479
	| WORK_SYM		{}
4480
	| X509_SYM		{}
unknown's avatar
unknown committed
4481 4482
	| YEAR_SYM		{}
	;
unknown's avatar
unknown committed
4483 4484 4485 4486 4487 4488

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
4489 4490
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
unknown's avatar
unknown committed
4491 4492
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
unknown's avatar
unknown committed
4493
	}
4494 4495 4496
	option_value_list
	{}
	;
unknown's avatar
unknown committed
4497 4498 4499

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
4500
	| OPTION {};
unknown's avatar
unknown committed
4501 4502

option_value_list:
unknown's avatar
unknown committed
4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514
	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; }
unknown's avatar
unknown committed
4515
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4516 4517 4518 4519 4520 4521
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
4522
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4523 4524 4525
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
4526 4527

option_value:
unknown's avatar
unknown committed
4528
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
4529
	{
unknown's avatar
unknown committed
4530
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
4531
	}
unknown's avatar
unknown committed
4532
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4533
	  {
unknown's avatar
unknown committed
4534 4535
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
unknown's avatar
unknown committed
4536
	  }
unknown's avatar
unknown committed
4537
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4538 4539 4540 4541 4542 4543 4544 4545
	  {
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var((enum_var_type) $3, $4, $6));
	  }
	| TRANSACTION_SYM ISOLATION LEVEL_SYM isolation_types
	  {
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type,
unknown's avatar
unknown committed
4546
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
4547
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
4548
	  }
4549
	| charset old_or_new_charset_name_or_default
unknown's avatar
unknown committed
4550
	{
unknown's avatar
unknown committed
4551
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4552
	  LEX *lex= Lex;
4553
	  $2= $2 ? $2: global_system_variables.character_set_client;
4554
	  lex->var_list.push_back(new set_var_collation_client($2,thd->variables.character_set_database,$2));
unknown's avatar
unknown committed
4555
	}
4556
	| NAMES_SYM charset_name_or_default opt_collate
4557
	{
unknown's avatar
unknown committed
4558
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
4559
	  LEX *lex= Lex;
4560
	  $2= $2 ? $2 : global_system_variables.character_set_client;
4561 4562
	  $3= $3 ? $3 : $2;
	  if (!my_charset_same($2,$3))
4563
	  {
unknown's avatar
unknown committed
4564 4565
	    net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname);
	    YYABORT;
4566
	  }
4567
	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
4568
	}
unknown's avatar
unknown committed
4569
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
4570
	  {
4571
	    THD *thd=YYTHD;
unknown's avatar
unknown committed
4572
	    LEX_USER *user;
unknown's avatar
unknown committed
4573
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
unknown's avatar
unknown committed
4574 4575 4576 4577 4578 4579
	      YYABORT;
	    user->host.str=0;
	    user->user.str=thd->priv_user;
	    thd->lex.var_list.push_back(new set_var_password(user, $3));
	  }
	| PASSWORD FOR_SYM user equal text_or_password
unknown's avatar
unknown committed
4580
	  {
unknown's avatar
unknown committed
4581 4582
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
4583
	;
unknown's avatar
unknown committed
4584

unknown's avatar
unknown committed
4585 4586 4587 4588 4589 4590 4591 4592
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
4593
        ;
unknown's avatar
unknown committed
4594 4595 4596 4597 4598 4599 4600

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

unknown's avatar
unknown committed
4602 4603 4604 4605 4606 4607 4608 4609
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
	    if (!$3.length)
	      $$=$3.str;
	    else
	    {
unknown's avatar
unknown committed
4610
	      char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
4611 4612
	      make_scrambled_password(buff,$3.str,use_old_passwords,
				      &YYTHD->rand);
unknown's avatar
unknown committed
4613 4614
	      $$=buff;
	    }
4615 4616
	  }
          ;
unknown's avatar
unknown committed
4617

unknown's avatar
unknown committed
4618

unknown's avatar
unknown committed
4619
set_expr_or_default:
unknown's avatar
unknown committed
4620 4621
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
4622 4623
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
4624
	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
unknown's avatar
unknown committed
4625
	;
unknown's avatar
unknown committed
4626 4627


unknown's avatar
unknown committed
4628 4629 4630 4631 4632 4633 4634
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
4635 4636 4637
	table_lock_list
	{}
	;
unknown's avatar
unknown committed
4638 4639 4640

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
4641
	| TABLES;
unknown's avatar
unknown committed
4642 4643 4644

table_lock_list:
	table_lock
unknown's avatar
unknown committed
4645
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
4646 4647 4648

table_lock:
	table_ident opt_table_alias lock_option
4649
	{
unknown's avatar
unknown committed
4650
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
4651 4652
	   YYABORT;
	}
4653
        ;
unknown's avatar
unknown committed
4654 4655 4656

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
4657
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4658
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
4659 4660
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
4661 4662

unlock:
4663 4664
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
4665 4666


4667
/*
unknown's avatar
unknown committed
4668
** Handler: direct access to ISAM functions
4669 4670 4671 4672 4673
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
4674 4675
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
unknown's avatar
unknown committed
4676
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
4677 4678 4679 4680
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
4681 4682
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
unknown's avatar
unknown committed
4683
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4684 4685
	    YYABORT;
	}
unknown's avatar
unknown committed
4686
	| HANDLER_SYM table_ident READ_SYM
4687
	{
unknown's avatar
unknown committed
4688 4689 4690
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
4691 4692
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
unknown's avatar
unknown committed
4693
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4694
	    YYABORT;
unknown's avatar
unknown committed
4695
        }
4696
        handler_read_or_scan where_clause opt_limit_clause {}
4697
        ;
4698

unknown's avatar
unknown committed
4699 4700
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
4701 4702
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
4703 4704 4705

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
4706 4707
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
4708 4709 4710 4711 4712 4713

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;  }
4714 4715
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
4716 4717
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
4718
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
4719
	  if (!(lex->insert_list = new List_item))
4720
	    YYABORT;
4721 4722
	} '(' values ')' { }
        ;
4723 4724

handler_rkey_mode:
unknown's avatar
unknown committed
4725 4726 4727 4728
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
4729 4730
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
4731

unknown's avatar
unknown committed
4732 4733 4734 4735 4736
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
4737 4738 4739 4740 4741
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
4742
	  lex->select_lex.db=0;
4743 4744
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4745
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
4746
	}
4747 4748 4749 4750 4751
	revoke_command
	{}
        ;

revoke_command:
4752 4753
	grant_privileges ON opt_table FROM user_list
	{}
4754 4755 4756 4757 4758
	|
	ALL PRIVILEGES ',' GRANT FROM user_list
	{
	  Lex->sql_command = SQLCOM_REVOKE_ALL;
	}
4759
	;
unknown's avatar
unknown committed
4760 4761 4762 4763

grant:
	GRANT
	{
unknown's avatar
unknown committed
4764 4765 4766
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
4767 4768
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
4769
	  lex->select_lex.db= 0;
4770 4771
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4772
	  bzero(&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
4773 4774
	}
	grant_privileges ON opt_table TO_SYM user_list
4775 4776 4777
	require_clause grant_options
	{}
	;
unknown's avatar
unknown committed
4778 4779 4780

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
4781
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
4782 4783
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
unknown's avatar
unknown committed
4784 4785 4786

grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
4787
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
4788 4789

grant_privilege:
4790 4791 4792 4793
	SELECT_SYM 	{ Lex->which_columns = SELECT_ACL;} opt_column_list {}
	| INSERT	{ Lex->which_columns = INSERT_ACL;} opt_column_list {}
	| UPDATE_SYM	{ Lex->which_columns = UPDATE_ACL; } opt_column_list {}
	| REFERENCES	{ Lex->which_columns = REFERENCES_ACL;} opt_column_list {}
unknown's avatar
unknown committed
4794 4795
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
4796 4797 4798 4799
	| INDEX		{ Lex->grant |= INDEX_ACL;}
	| ALTER		{ Lex->grant |= ALTER_ACL;}
	| CREATE	{ Lex->grant |= CREATE_ACL;}
	| DROP		{ Lex->grant |= DROP_ACL;}
unknown's avatar
unknown committed
4800
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
4801 4802 4803 4804
	| RELOAD	{ Lex->grant |= RELOAD_ACL;}
	| SHUTDOWN	{ Lex->grant |= SHUTDOWN_ACL;}
	| PROCESS	{ Lex->grant |= PROCESS_ACL;}
	| FILE_SYM	{ Lex->grant |= FILE_ACL;}
unknown's avatar
unknown committed
4805 4806 4807 4808 4809 4810 4811 4812
	| 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;}
	;
unknown's avatar
unknown committed
4813

unknown's avatar
unknown committed
4814

4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826
opt_and:
	/* empty */	{}
	| AND		{}
	;

require_list:
	 require_list_element opt_and require_list
	 | require_list_element
	 ;

require_list_element:
	SUBJECT_SYM TEXT_STRING
unknown's avatar
unknown committed
4827 4828 4829 4830
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
4831
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
4832 4833 4834 4835 4836 4837 4838 4839 4840
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
4841
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
4842 4843 4844 4845 4846 4847 4848 4849 4850
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
4851
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
4852 4853 4854 4855 4856
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
4857

unknown's avatar
unknown committed
4858 4859 4860
opt_table:
	'*'
	  {
4861
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4862
	    lex->current_select->select_lex()->db= lex->thd->db;
unknown's avatar
unknown committed
4863
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4864 4865
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4866
	    {
4867
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
4868
	      YYABORT;
unknown's avatar
unknown committed
4869
	    }
unknown's avatar
unknown committed
4870 4871 4872
	  }
	| ident '.' '*'
	  {
4873
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4874
	    lex->current_select->select_lex()->db = $1.str;
unknown's avatar
unknown committed
4875
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4876 4877
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4878
	    {
4879
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4880 4881 4882 4883 4884
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
4885
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4886
	    lex->current_select->select_lex()->db = NULL;
unknown's avatar
unknown committed
4887 4888
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
4889
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4890
	    {
4891
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4892 4893 4894 4895 4896
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
4897
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4898
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
unknown's avatar
unknown committed
4899
	      YYABORT;
unknown's avatar
unknown committed
4900
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4901
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
4902 4903
	  }
          ;
unknown's avatar
unknown committed
4904 4905 4906


user_list:
4907 4908 4909 4910 4911 4912 4913
	grant_user  { if (Lex->users_list.push_back($1)) YYABORT;}
	| user_list ',' grant_user
	  {
	    if (Lex->users_list.push_back($3))
	      YYABORT;
	  }
	;
unknown's avatar
unknown committed
4914 4915 4916 4917 4918 4919 4920 4921


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
unknown's avatar
unknown committed
4922
	     char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
unknown's avatar
unknown committed
4923 4924
	     if (buff)
	     {
4925 4926
	       make_scrambled_password(buff,$4.str,use_old_passwords,
				       &YYTHD->rand);
unknown's avatar
unknown committed
4927 4928 4929 4930 4931 4932 4933 4934
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
4935 4936
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
4937 4938 4939


opt_column_list:
unknown's avatar
unknown committed
4940 4941 4942 4943 4944
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
4945
	| '(' column_list ')';
unknown's avatar
unknown committed
4946 4947 4948

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
4949
	| column_list_id;
unknown's avatar
unknown committed
4950 4951 4952 4953

column_list_id:
	ident
	{
4954
	  String *new_str = new String((const char*) $1.str,$1.length,system_charset_info);
unknown's avatar
unknown committed
4955 4956
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
4957
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4958 4959
	  while ((point=iter++))
	  {
4960 4961
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
4962 4963
		break;
	  }
unknown's avatar
unknown committed
4964
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
4965
	  if (point)
unknown's avatar
unknown committed
4966
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
4967
	  else
unknown's avatar
unknown committed
4968
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
4969 4970
	}
        ;
unknown's avatar
unknown committed
4971

unknown's avatar
unknown committed
4972 4973

require_clause: /* empty */
4974
        | REQUIRE_SYM require_list
4975 4976 4977
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
4978
        | REQUIRE_SYM SSL_SYM
4979 4980 4981
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
4982
        | REQUIRE_SYM X509_SYM
4983 4984 4985 4986 4987 4988 4989
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
4990
          ;
unknown's avatar
unknown committed
4991

unknown's avatar
unknown committed
4992
grant_options:
unknown's avatar
unknown committed
4993
	/* empty */ {}
unknown's avatar
unknown committed
4994
	| WITH grant_option_list;
unknown's avatar
unknown committed
4995

unknown's avatar
unknown committed
4996 4997
grant_option_list:
	grant_option_list grant_option {}
4998 4999
	| grant_option {}
        ;
unknown's avatar
unknown committed
5000 5001 5002

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
5003
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
5004
        {
5005
	  Lex->mqh.questions=$2;
5006
	  Lex->mqh.bits |= 1;
5007
	}
5008
        | MAX_UPDATES_PER_HOUR ULONG_NUM
5009
        {
5010
	  Lex->mqh.updates=$2;
5011
	  Lex->mqh.bits |= 2;
5012
	}
5013
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
5014
        {
5015
	  Lex->mqh.connections=$2;
5016
	  Lex->mqh.bits |= 4;
5017 5018
	}
        ;
5019

unknown's avatar
unknown committed
5020
begin:
5021 5022
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
unknown's avatar
unknown committed
5023 5024 5025

opt_work:
	/* empty */ {}
5026 5027
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
5028 5029

commit:
unknown's avatar
unknown committed
5030
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
5031 5032

rollback:
unknown's avatar
unknown committed
5033
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
5034 5035 5036


/*
unknown's avatar
unknown committed
5037
   UNIONS : glue selects together
5038 5039 5040
*/


5041
union_clause:
5042
	/* empty */ {}
unknown's avatar
unknown committed
5043 5044
	| union_list
	;
5045 5046

union_list:
unknown's avatar
unknown committed
5047
	UNION_SYM    union_option
5048 5049 5050 5051 5052
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
5053
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
5054
	    YYABORT;
5055
	  }
5056
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
5057
	  {
5058
	    send_error(lex->thd, ER_SYNTAX_ERROR);
5059 5060
	    YYABORT;
	  }
5061
	  if (mysql_new_select(lex, 0))
5062
	    YYABORT;
unknown's avatar
unknown committed
5063
          mysql_init_select(lex);
5064
	  lex->current_select->linkage=UNION_TYPE;
unknown's avatar
unknown committed
5065
	}
5066
	select_init {}
5067
	;
5068 5069

union_opt:
unknown's avatar
unknown committed
5070
	union_list {}
unknown's avatar
unknown committed
5071 5072
	| optional_order_or_limit {}
	;
5073 5074

optional_order_or_limit:
5075
      	/* Empty */ {}
5076 5077
	|
	  {
unknown's avatar
unknown committed
5078 5079
	    THD *thd= YYTHD;
	    LEX *lex= &thd->lex;
unknown's avatar
unknown committed
5080
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
unknown's avatar
unknown committed
5081
	    SELECT_LEX *sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
5082 5083 5084 5085
	    SELECT_LEX_UNIT *unit= sel->master_unit();
	    unit->global_parameters= unit;
	    unit->no_table_names_allowed= 1;
	    lex->current_select= unit;
unknown's avatar
unknown committed
5086
	    thd->where= "global ORDER clause";
5087
	  }
5088
	order_or_limit
unknown's avatar
unknown committed
5089 5090 5091 5092 5093
          {
	    THD *thd= YYTHD;
	    thd->lex.current_select->no_table_names_allowed= 0;
	    thd->where= "";
          }
5094 5095 5096
	;

order_or_limit:
5097 5098
	order_clause opt_limit_clause_init
	| limit_clause
5099
	;
unknown's avatar
unknown committed
5100 5101

union_option:
5102
	/* empty */ {}
unknown's avatar
unknown committed
5103
	| ALL {Select->master_unit()->union_option= 1;};
5104

unknown's avatar
unknown committed
5105 5106
singlerow_subselect:
	subselect_start singlerow_subselect_init
unknown's avatar
unknown committed
5107 5108 5109 5110
	subselect_end
	{
	  $$= $2;
	};
5111

unknown's avatar
unknown committed
5112
singlerow_subselect_init:
5113
	select_init2
unknown's avatar
unknown committed
5114
	{
unknown's avatar
unknown committed
5115
	  $$= new Item_singlerow_subselect(YYTHD,
5116 5117
					   Lex->current_select->master_unit()->
                                             first_select());
unknown's avatar
unknown committed
5118
	};
unknown's avatar
unknown committed
5119 5120

exists_subselect:
unknown's avatar
unknown committed
5121 5122 5123 5124 5125
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
5126 5127

exists_subselect_init:
5128
	select_init2
unknown's avatar
unknown committed
5129
	{
5130
	  $$= new Item_exists_subselect(YYTHD,
5131 5132
					Lex->current_select->master_unit()->
					  first_select());
unknown's avatar
unknown committed
5133
	};
5134

unknown's avatar
unknown committed
5135 5136 5137 5138 5139 5140 5141 5142
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
5143
  select_init2
unknown's avatar
unknown committed
5144
  {
unknown's avatar
unknown committed
5145
    $$= Lex->current_select->master_unit()->first_select();
unknown's avatar
unknown committed
5146 5147
  };

5148
subselect_start:
5149
	'(' SELECT_SYM
unknown's avatar
unknown committed
5150
	{
5151
	  LEX *lex=Lex;
5152
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
5153 5154 5155 5156
	       lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL)	  {	
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
unknown's avatar
unknown committed
5157 5158 5159
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
5160 5161

subselect_end:
unknown's avatar
unknown committed
5162 5163 5164
	')'
	{
	  LEX *lex=Lex;
5165
	  lex->current_select = lex->current_select->return_after_parsing();
unknown's avatar
unknown committed
5166
	};