sql_yacc.yy 116 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
unknown's avatar
unknown committed
139 140
%token	INSERT
%token	IO_THREAD
unknown's avatar
unknown committed
141 142
%token	KILL_SYM
%token	LOAD
unknown's avatar
unknown committed
143
%token	LOCKS_SYM
unknown's avatar
unknown committed
144 145 146 147
%token	LOCK_SYM
%token	MASTER_SYM
%token	MAX_SYM
%token	MIN_SYM
148
%token	NONE_SYM
unknown's avatar
unknown committed
149 150 151 152 153 154
%token	OPTIMIZE
%token	PURGE
%token	REPAIR
%token	REPLICATION
%token	RESET_SYM
%token	ROLLBACK_SYM
155
%token  ROLLUP_SYM
unknown's avatar
unknown committed
156 157 158 159 160 161
%token	SELECT_SYM
%token	SHOW
%token	SLAVE
%token	SQL_THREAD
%token	START_SYM
%token	STD_SYM
unknown's avatar
unknown committed
162
%token  VARIANCE_SYM
unknown's avatar
unknown committed
163 164 165 166
%token	STOP_SYM
%token	SUM_SYM
%token	SUPER_SYM
%token	TRUNCATE_SYM
unknown's avatar
unknown committed
167
%token	UNLOCK_SYM
unknown's avatar
unknown committed
168
%token	UPDATE_SYM
unknown's avatar
unknown committed
169 170 171 172 173 174 175

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

unknown's avatar
unknown committed
382 383 384
%token  ERRORS
%token  WARNINGS

unknown's avatar
unknown committed
385
%token	ASCII_SYM
unknown's avatar
unknown committed
386 387 388
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
unknown's avatar
unknown committed
389
%token	CHANGED
unknown's avatar
unknown committed
390 391 392 393 394 395
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
396
%token	FAST_SYM
unknown's avatar
unknown committed
397
%token	FLOAT_SYM
unknown's avatar
unknown committed
398
%token  GEOMETRY_SYM
unknown's avatar
unknown committed
399 400 401 402 403 404 405 406 407
%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
408
%token	QUICK
unknown's avatar
unknown committed
409
%token	REAL
unknown's avatar
unknown committed
410
%token	SIGNED_SYM
unknown's avatar
unknown committed
411 412 413 414 415 416 417 418
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
unknown's avatar
unknown committed
419
%token	ULONGLONG_NUM
unknown's avatar
unknown committed
420
%token	UNSIGNED
421 422 423
%token	VARBINARY
%token	VARCHAR
%token	VARYING
unknown's avatar
unknown committed
424 425
%token	ZEROFILL

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

unknown's avatar
unknown committed
519 520 521 522
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
523
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
524
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
525

unknown's avatar
unknown committed
526 527
%token  ISSUER_SYM
%token  SUBJECT_SYM
528
%token  CIPHER_SYM
unknown's avatar
unknown committed
529

unknown's avatar
unknown committed
530 531
%token  HELP

unknown's avatar
unknown committed
532 533 534 535 536 537 538 539 540
%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	'-' '+'
541
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
542
%left	NEG '~'
unknown's avatar
unknown committed
543 544
%left   XOR
%left   '^'
unknown's avatar
unknown committed
545
%right	NOT
unknown's avatar
unknown committed
546
%right	BINARY COLLATE_SYM
547 548 549 550 551 552
/* These don't actually affect the way the query is really evaluated, but
   they silence a few warnings for shift/reduce conflicts. */
%left	','
%left	STRAIGHT_JOIN JOIN_SYM
%nonassoc	CROSS INNER_SYM NATURAL LEFT RIGHT

unknown's avatar
unknown committed
553 554
%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
555
	ULONGLONG_NUM field_ident select_alias ident ident_or_text
unknown's avatar
unknown committed
556
        UNDERSCORE_CHARSET
unknown's avatar
unknown committed
557 558 559 560 561

%type <lex_str_ptr>
	opt_table_alias

%type <table>
562
	table_ident references
unknown's avatar
unknown committed
563 564

%type <simple_string>
565
	remember_name remember_end opt_ident opt_db text_or_password
unknown's avatar
unknown committed
566 567 568
	opt_escape

%type <string>
569
	text_string
unknown's avatar
unknown committed
570 571

%type <num>
unknown's avatar
unknown committed
572
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
573
	udf_type if_exists opt_local opt_table_options table_options
unknown's avatar
unknown committed
574
	table_option opt_if_not_exists opt_var_type opt_var_ident_type
unknown's avatar
unknown committed
575
	delete_option opt_temporary all_or_any
unknown's avatar
unknown committed
576 577

%type <ulong_num>
578
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
579

unknown's avatar
unknown committed
580 581
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
582

unknown's avatar
unknown committed
583 584 585
%type <lock_type>
	replace_lock_option opt_low_priority insert_lock_option load_data_lock

unknown's avatar
unknown committed
586
%type <item>
unknown's avatar
unknown committed
587
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
588 589
	simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr
	table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr
590
	using_list expr_or_default set_expr_or_default interval_expr
unknown's avatar
unknown committed
591
	param_marker singlerow_subselect singlerow_subselect_init
unknown's avatar
unknown committed
592
	exists_subselect exists_subselect_init
unknown's avatar
unknown committed
593 594

%type <item_list>
unknown's avatar
unknown committed
595
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
596 597

%type <key_type>
598
	key_type opt_unique_or_fulltext
unknown's avatar
unknown committed
599

unknown's avatar
unknown committed
600 601 602
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
603 604 605 606 607 608 609
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
610
	join_table_list  join_table
unknown's avatar
unknown committed
611 612 613 614 615 616 617 618 619 620 621

%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
622
%type <tx_isolation> isolation_types
unknown's avatar
unknown committed
623

unknown's avatar
unknown committed
624 625
%type <ha_rkey_mode> handler_rkey_mode

unknown's avatar
unknown committed
626 627
%type <cast_type> cast_type

unknown's avatar
unknown committed
628 629 630 631 632 633
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

634
%type <charset>
635 636
	charset_name
	charset_name_or_default
637 638
	collation_name
	collation_name_or_default
639

unknown's avatar
unknown committed
640 641
%type <variable> internal_variable_name

unknown's avatar
unknown committed
642 643
%type <select_lex> in_subselect in_subselect_init

unknown's avatar
unknown committed
644 645
%type <boolfunc2creator> comp_op

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

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
679 680
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
unknown's avatar
unknown committed
681 682 683 684 685
%%


query:
	END_OF_INPUT
unknown's avatar
unknown committed
686
	{
687
	   THD *thd= YYTHD;
688
	   if (!thd->bootstrap &&
unknown's avatar
unknown committed
689
	      (!(thd->lex.select_lex.options & OPTION_FOUND_COMMENT)))
690
	   {
691
	     send_error(thd,ER_EMPTY_QUERY);
692
	     YYABORT;
693
	   }
694 695 696 697
	   else
	   {
	     thd->lex.sql_command = SQLCOM_EMPTY_QUERY;
	   }
unknown's avatar
unknown committed
698
	}
unknown's avatar
unknown committed
699
	| verb_clause END_OF_INPUT {};
unknown's avatar
unknown committed
700 701 702 703

verb_clause:
	  alter
	| analyze
704
	| backup
unknown's avatar
unknown committed
705 706 707 708 709 710 711
	| begin
	| change
	| check
	| commit
	| create
	| delete
	| describe
unknown's avatar
unknown committed
712
	| do
unknown's avatar
unknown committed
713 714 715 716 717 718 719 720
	| drop
	| grant
	| insert
	| flush
	| load
	| lock
	| kill
	| optimize
721
	| purge
722
	| rename
unknown's avatar
unknown committed
723 724
        | repair
	| replace
unknown's avatar
unknown committed
725
	| reset
726
	| restore
unknown's avatar
unknown committed
727 728 729 730
	| revoke
	| rollback
	| select
	| set
unknown's avatar
unknown committed
731
	| slave
unknown's avatar
unknown committed
732
	| show
733
	| truncate
734
	| handler
unknown's avatar
unknown committed
735 736
	| unlock
	| update
unknown's avatar
unknown committed
737 738
	| use
	| help;
739

unknown's avatar
unknown committed
740 741
/* help */

742
help:
unknown's avatar
unknown committed
743 744 745 746 747
       HELP TEXT_STRING
       {
       LEX *lex= Lex;
       lex->sql_command= SQLCOM_HELP;
       lex->help_arg= $2.str;
748
       };
unknown's avatar
unknown committed
749 750 751 752

/* change master */

change:
unknown's avatar
unknown committed
753
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
754 755 756
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
unknown's avatar
unknown committed
757
	  bzero((char*) &lex->mi, sizeof(lex->mi));
758 759 760 761
        }
       master_defs
	{}
       ;
unknown's avatar
unknown committed
762 763 764

master_defs:
       master_def
unknown's avatar
unknown committed
765
       | master_defs ',' master_def;
unknown's avatar
unknown committed
766

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

unknown's avatar
unknown committed
814

unknown's avatar
unknown committed
815 816 817 818 819
/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
820
	  THD *thd= YYTHD;
unknown's avatar
unknown committed
821 822
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
unknown's avatar
unknown committed
823
	  if (!lex->select_lex.add_table_to_list(thd,$5,
824
						 ($2 &
825 826
						  HA_LEX_CREATE_TMP_TABLE ?
						  &tmp_table_alias :
unknown's avatar
unknown committed
827 828
						  (LEX_STRING*) 0),
						 TL_OPTION_UPDATING,
unknown's avatar
unknown committed
829 830 831
						 ((using_update_log)?
						  TL_READ_NO_INSERT:
						  TL_READ)))
unknown's avatar
unknown committed
832 833 834 835 836 837 838
	    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
839
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
840
	  lex->create_info.table_charset=thd->db_charset?thd->db_charset:default_charset_info;
unknown's avatar
unknown committed
841
	  lex->name=0;
unknown's avatar
unknown committed
842 843
	}
	create2
unknown's avatar
unknown committed
844
	{}
unknown's avatar
unknown committed
845
	| CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
unknown's avatar
unknown committed
846
	  {
unknown's avatar
unknown committed
847 848
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
unknown's avatar
unknown committed
849 850
	    if (!lex->current_select->add_table_to_list(lex->thd, $7, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
851
	      YYABORT;
unknown's avatar
unknown committed
852 853 854 855
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
unknown's avatar
unknown committed
856
	  }
857
	   '(' key_list ')'
unknown's avatar
unknown committed
858
	  {
unknown's avatar
unknown committed
859
	    LEX *lex=Lex;
unknown's avatar
unknown committed
860

861
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
unknown's avatar
unknown committed
862
	    lex->col_list.empty();
unknown's avatar
unknown committed
863
	  }
864 865 866
	| CREATE DATABASE opt_if_not_exists ident 
	  { Lex->create_info.table_charset=NULL; }
	  opt_create_database_options
unknown's avatar
unknown committed
867
	  {
unknown's avatar
unknown committed
868 869 870 871
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
unknown's avatar
unknown committed
872 873 874
	  }
	| CREATE udf_func_type UDF_SYM ident
	  {
unknown's avatar
unknown committed
875 876 877 878 879
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_CREATE_FUNCTION;
	    lex->udf.name=$4.str;
	    lex->udf.name_length=$4.length;
	    lex->udf.type= $2;
unknown's avatar
unknown committed
880 881 882
	  }
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
	  {
unknown's avatar
unknown committed
883 884 885
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
886 887
	  }
          ;
unknown's avatar
unknown committed
888 889

create2:
unknown's avatar
unknown committed
890
	'(' field_list ')' opt_create_table_options create3 {}
891
	| opt_create_table_options create3 {}
unknown's avatar
unknown committed
892 893 894 895 896 897 898
	| LIKE table_ident
      	  {
      	    LEX *lex=Lex;
     	    if (!(lex->name= (char *)$2))
              YYABORT;
    	  }
  	  ;
unknown's avatar
unknown committed
899 900

create3:
901 902
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
unknown's avatar
unknown committed
903
          {
unknown's avatar
unknown committed
904 905 906
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	    mysql_init_select(lex);
unknown's avatar
unknown committed
907
          }
908
          select_options select_item_list opt_select_from union_clause {}
909
          ;
unknown's avatar
unknown committed
910

911 912
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
913
	| AS	    {};
914

915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
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; }
	| opt_default CHAR_SYM SET charset_name_or_default
	  { Lex->create_info.table_charset=$4; }
	| opt_default CHARSET charset_name_or_default
	  { Lex->create_info.table_charset=$3; };

unknown's avatar
unknown committed
931
opt_table_options:
unknown's avatar
unknown committed
932
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
933
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
934 935 936

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

unknown's avatar
unknown committed
939
table_option:
unknown's avatar
unknown committed
940
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
941 942

opt_if_not_exists:
unknown's avatar
unknown committed
943
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
944
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
945 946 947

opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
948
	| create_table_options;
unknown's avatar
unknown committed
949

unknown's avatar
unknown committed
950 951 952 953
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
954 955
create_table_options:
	create_table_option
956
	| create_table_option     create_table_options
unknown's avatar
unknown committed
957
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
958 959

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

table_types:
	ISAM_SYM	{ $$= DB_TYPE_ISAM; }
	| MYISAM_SYM	{ $$= DB_TYPE_MYISAM; }
	| MERGE_SYM	{ $$= DB_TYPE_MRG_MYISAM; }
	| HEAP_SYM	{ $$= DB_TYPE_HEAP; }
	| BERKELEY_DB_SYM { $$= DB_TYPE_BERKELEY_DB; }
unknown's avatar
unknown committed
1013
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
unknown's avatar
unknown committed
1014 1015 1016 1017 1018

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
1019
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
1020 1021 1022 1023

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

1026 1027 1028
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
1029
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
1030

unknown's avatar
unknown committed
1031
opt_select_from:
1032
	opt_limit_clause {}
unknown's avatar
unknown committed
1033
	| FROM DUAL_SYM {}
unknown's avatar
unknown committed
1034
	| select_from select_lock_type;
unknown's avatar
unknown committed
1035 1036 1037

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
1038
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
1039 1040 1041 1042

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
1043
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
1044 1045 1046

field_list:
	  field_list_item
unknown's avatar
unknown committed
1047
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
1048 1049 1050


field_list_item:
1051
	  field_spec check_constraint
unknown's avatar
unknown committed
1052 1053 1054 1055
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1056
	| key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1057
	  {
unknown's avatar
unknown committed
1058
	    LEX *lex=Lex;
1059
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
unknown's avatar
unknown committed
1060
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1061
	  }
1062
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1063
	  {
1064 1065 1066 1067 1068 1069 1070 1071
	    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
1072
	  }
1073
	| opt_constraint check_constraint
unknown's avatar
unknown committed
1074 1075
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
1076 1077 1078 1079 1080 1081 1082
	  }
	;

check_constraint:
	/* empty */
	| CHECK_SYM expr
	;
unknown's avatar
unknown committed
1083 1084 1085

opt_constraint:
	/* empty */
unknown's avatar
unknown committed
1086
	| CONSTRAINT opt_ident;
unknown's avatar
unknown committed
1087 1088 1089 1090

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1091 1092
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
1093
	   lex->default_value=lex->comment=0;
1094
	   lex->charset=NULL;
unknown's avatar
unknown committed
1095 1096 1097
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1098
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1099
	  if (add_field_to_list(lex->thd, $1.str,
unknown's avatar
unknown committed
1100
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1101
				lex->length,lex->dec,lex->type,
1102
				lex->default_value, lex->comment,
1103
				lex->change,lex->interval,lex->charset))
unknown's avatar
unknown committed
1104
	    YYABORT;
unknown's avatar
unknown committed
1105
	};
unknown's avatar
unknown committed
1106 1107

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

char:
	CHAR_SYM {}
	| NCHAR_SYM {}
unknown's avatar
unknown committed
1189
	| NATIONAL_SYM CHAR_SYM {};
unknown's avatar
unknown committed
1190

unknown's avatar
unknown committed
1191 1192 1193 1194
varchar:
	char VARYING {}
	| VARCHAR {}
	| NATIONAL_SYM VARCHAR {}
unknown's avatar
unknown committed
1195
	| NCHAR_SYM VARCHAR {};
unknown's avatar
unknown committed
1196 1197 1198 1199 1200 1201

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1202
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1203 1204

real_type:
1205
	REAL		{ $$= YYTHD->variables.sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1206 1207
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1208
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1209 1210 1211 1212 1213


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1214
	| precision		{};
unknown's avatar
unknown committed
1215 1216 1217 1218 1219 1220

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1221
	};
unknown's avatar
unknown committed
1222 1223 1224

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1225
	| field_opt_list	{};
unknown's avatar
unknown committed
1226 1227 1228

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1229
	| field_option {};
unknown's avatar
unknown committed
1230 1231

field_option:
unknown's avatar
unknown committed
1232
	SIGNED_SYM	{}
1233
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1234
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1235 1236

opt_len:
1237 1238
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1239 1240 1241

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1242
	| precision	{};
unknown's avatar
unknown committed
1243 1244 1245

opt_attribute:
	/* empty */ {}
unknown's avatar
unknown committed
1246
	| opt_attribute_list {};
unknown's avatar
unknown committed
1247 1248 1249

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1250
	| attribute;
unknown's avatar
unknown committed
1251 1252 1253 1254 1255 1256

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; }
1257
	| SERIAL_SYM DEFAULT VALUE_SYM
unknown's avatar
unknown committed
1258 1259
	  { 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
1260
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1261
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
1262
	| COMMENT_SYM text_literal { Lex->comment= $2; }
1263
	| COLLATE_SYM collation_name { Lex->charset=$2; };
unknown's avatar
unknown committed
1264

unknown's avatar
unknown committed
1265

1266
charset_name:
unknown's avatar
unknown committed
1267
	ident
1268
	{
1269
	  if (!($$=get_charset_by_csname($1.str,MYF(0))))
1270
	  {
1271
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
1272 1273 1274 1275
	    YYABORT;
	  }
	};

1276 1277 1278
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1279

1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
collation_name:
	ident
	{
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str);
	    YYABORT;
	  }
	};

collation_name_or_default:
	collation_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;

1294 1295 1296 1297
opt_default:
	/* empty */	{}
	| DEFAULT	{};

unknown's avatar
unknown committed
1298
opt_binary:
1299
	/* empty */			{ Lex->charset=NULL; }
unknown's avatar
unknown committed
1300
	| ASCII_SYM			{ Lex->charset=my_charset_latin1; }
1301
	| BYTE_SYM			{ Lex->charset=my_charset_bin; }
1302
	| BINARY			{ Lex->charset=my_charset_bin; }
unknown's avatar
unknown committed
1303 1304 1305 1306 1307 1308 1309 1310
	| UNICODE_SYM
	{
	  if (!(Lex->charset=get_charset_by_name("ucs2",MYF(0))))
	  {
	    net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2");
	    YYABORT;
	  }
	}
1311
	| CHAR_SYM SET charset_name	{ Lex->charset=$3; } ;
unknown's avatar
unknown committed
1312

unknown's avatar
unknown committed
1313 1314 1315
opt_primary:
	/* empty */
	| PRIMARY_SYM
1316
	;
unknown's avatar
unknown committed
1317

unknown's avatar
unknown committed
1318
references:
1319 1320
	REFERENCES table_ident
	{
1321
	  LEX *lex=Lex;
1322 1323 1324 1325 1326 1327
	  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
1328
	};
1329

1330
opt_ref_list:
unknown's avatar
unknown committed
1331
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1332
	| '(' ref_list ')' opt_on_delete {};
1333 1334 1335

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

unknown's avatar
unknown committed
1338 1339 1340

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1341
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1342 1343 1344

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1345
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1346 1347

opt_on_delete_item:
1348 1349 1350 1351
	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
1352
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1353 1354

delete_option:
1355 1356 1357 1358
	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
1359
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1360 1361 1362 1363

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1364 1365
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
unknown's avatar
unknown committed
1366 1367
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; }
unknown's avatar
unknown committed
1368
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1369
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1370 1371 1372

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1373
	| INDEX {};
unknown's avatar
unknown committed
1374 1375 1376 1377

keys_or_index:
	KEYS {}
	| INDEX {}
unknown's avatar
unknown committed
1378
	| INDEXES {};
unknown's avatar
unknown committed
1379

1380
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1381 1382
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1383
	| SPATIAL_SYM	{ $$= Key::SPATIAL; };
unknown's avatar
unknown committed
1384 1385

key_alg:
1386
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
1387
	| USING opt_btree_or_rtree { $$= $2; }
unknown's avatar
unknown committed
1388
	| TYPE_SYM opt_btree_or_rtree  { $$= $2; };
unknown's avatar
unknown committed
1389 1390 1391 1392

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
	| RTREE_SYM	{ $$= HA_KEY_ALG_RTREE; }
unknown's avatar
unknown committed
1393
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1394 1395 1396

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1397
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1398 1399 1400

key_part:
	ident			{ $$=new key_part_spec($1.str); }
unknown's avatar
unknown committed
1401
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
unknown's avatar
unknown committed
1402 1403 1404

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
unknown's avatar
unknown committed
1405
	| field_ident	{ $$=$1.str; };
unknown's avatar
unknown committed
1406 1407 1408

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1409
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1410 1411 1412 1413 1414 1415 1416 1417

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1418
	  THD *thd= YYTHD;
1419
	  LEX *lex=&thd->lex;
unknown's avatar
unknown committed
1420 1421
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
unknown's avatar
unknown committed
1422 1423
	  if (!lex->select_lex.add_table_to_list(thd, $4, NULL,
						 TL_OPTION_UPDATING))
unknown's avatar
unknown committed
1424 1425 1426 1427 1428 1429 1430
	    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();
1431
          lex->select_lex.init_order();
1432
	  lex->select_lex.db=lex->name=0;
1433
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
unknown's avatar
unknown committed
1434
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1435
	  lex->create_info.table_charset=thd->db_charset?thd->db_charset:default_charset_info;
1436
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1437 1438
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
unknown's avatar
unknown committed
1439
	}
1440 1441
	alter_list
	{}
1442
	| ALTER DATABASE ident opt_create_database_options
1443 1444 1445 1446
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1447
	  };
1448 1449


unknown's avatar
unknown committed
1450
alter_list:
unknown's avatar
unknown committed
1451
        | alter_list_item
unknown's avatar
unknown committed
1452
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1453 1454

add_column:
unknown's avatar
unknown committed
1455
	ADD opt_column { Lex->change=0; };
unknown's avatar
unknown committed
1456 1457

alter_list_item:
1458 1459
	add_column field_list_item opt_place { Lex->simple_alter=0; }
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1460 1461 1462 1463 1464
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1465
          field_spec opt_place
unknown's avatar
unknown committed
1466 1467 1468 1469 1470
        | 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;
unknown's avatar
unknown committed
1471
            lex->simple_alter=0;
unknown's avatar
unknown committed
1472 1473 1474 1475
          }
          type opt_attribute
          {
            LEX *lex=Lex;
unknown's avatar
unknown committed
1476
            if (add_field_to_list(lex->thd,$3.str,
unknown's avatar
unknown committed
1477 1478 1479
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
1480
				  $3.str, lex->interval, lex->charset))
unknown's avatar
unknown committed
1481 1482 1483
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1484
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
	  {
	    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;
	  }
1495
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1496
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1497 1498 1499 1500 1501 1502
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1503 1504
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
unknown's avatar
unknown committed
1505
	| ALTER opt_column field_ident SET DEFAULT literal
unknown's avatar
unknown committed
1506 1507 1508 1509 1510
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
unknown's avatar
unknown committed
1511
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1512 1513 1514 1515 1516
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1517
	| RENAME opt_to table_ident
1518
	  {
1519
	    LEX *lex=Lex;
1520
	    lex->select_lex.db=$3->db.str;
1521
	    lex->name= $3->table.str;
1522
	  }
unknown's avatar
unknown committed
1523
        | create_table_options_space_separated { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1524
	| order_clause         { Lex->simple_alter=0; };
unknown's avatar
unknown committed
1525 1526 1527

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
1528
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
1529 1530 1531

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
unknown's avatar
unknown committed
1532
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
1533 1534 1535 1536

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
1537
	| CASCADE	{};
unknown's avatar
unknown committed
1538 1539 1540 1541

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
1542
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
1543 1544 1545 1546

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1547
	| EQ		{}
unknown's avatar
unknown committed
1548
	| AS		{};
unknown's avatar
unknown committed
1549

unknown's avatar
unknown committed
1550
/*
unknown's avatar
unknown committed
1551 1552 1553
  The first two deprecate the last two--delete the last two for 4.1 release
*/

unknown's avatar
unknown committed
1554
slave:
1555
	START_SYM SLAVE slave_thread_opts
unknown's avatar
unknown committed
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
        {
	  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
1568

unknown's avatar
unknown committed
1569 1570 1571
slave_thread_opts:
	slave_thread_opt
	| slave_thread_opts ',' slave_thread_opt;
1572 1573

slave_thread_opt:
1574
	/*empty*/	{}
unknown's avatar
unknown committed
1575 1576 1577
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
	| IO_THREAD   	{ Lex->slave_thd_opt|=SLAVE_IO; }
	;
1578

unknown's avatar
unknown committed
1579 1580 1581 1582 1583 1584 1585 1586
restore:
	RESTORE_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_RESTORE_TABLE;
	}
	table_list FROM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1587
        };
unknown's avatar
unknown committed
1588

unknown's avatar
unknown committed
1589 1590 1591 1592 1593 1594 1595 1596
backup:
	BACKUP_SYM table_or_tables
	{
	   Lex->sql_command = SQLCOM_BACKUP_TABLE;
	}
	table_list TO_SYM TEXT_STRING
        {
	  Lex->backup_dir = $6.str;
unknown's avatar
unknown committed
1597
        };
unknown's avatar
unknown committed
1598

unknown's avatar
unknown committed
1599 1600 1601
repair:
	REPAIR table_or_tables
	{
unknown's avatar
unknown committed
1602 1603 1604
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1605
	}
1606 1607 1608
	table_list opt_mi_repair_type
	{}
	;
unknown's avatar
unknown committed
1609

unknown's avatar
unknown committed
1610
opt_mi_repair_type:
unknown's avatar
unknown committed
1611
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1612
	| mi_repair_types {};
unknown's avatar
unknown committed
1613

unknown's avatar
unknown committed
1614 1615
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
1616
	| mi_repair_type mi_repair_types {};
1617

unknown's avatar
unknown committed
1618
mi_repair_type:
unknown's avatar
unknown committed
1619
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1620
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1621
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
1622 1623

analyze:
1624
	ANALYZE_SYM table_or_tables
unknown's avatar
unknown committed
1625
	{
unknown's avatar
unknown committed
1626 1627 1628
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1629
	}
1630 1631 1632
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1633 1634

check:
unknown's avatar
unknown committed
1635
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
1636
	{
unknown's avatar
unknown committed
1637 1638 1639
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1640
	}
1641 1642 1643
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1644

unknown's avatar
unknown committed
1645 1646
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1647
	| mi_check_types {};
unknown's avatar
unknown committed
1648 1649 1650

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
1651
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
1652 1653 1654 1655 1656 1657

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

unknown's avatar
unknown committed
1660
optimize:
1661
	OPTIMIZE table_or_tables
unknown's avatar
unknown committed
1662
	{
unknown's avatar
unknown committed
1663 1664 1665
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1666
	}
1667 1668 1669
	table_list opt_mi_check_type
	{}
	;
unknown's avatar
unknown committed
1670

1671 1672 1673 1674 1675
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
1676 1677 1678
	table_to_table_list
	{}
	;
1679 1680 1681

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
1682
	| table_to_table_list ',' table_to_table;
1683 1684 1685

table_to_table:
	table_ident TO_SYM table_ident
1686
	{
unknown's avatar
unknown committed
1687 1688
	  LEX *lex=Lex;	  
	  SELECT_LEX_NODE *sl= lex->current_select;
unknown's avatar
unknown committed
1689 1690 1691 1692
	  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))
1693
	    YYABORT;
1694
	};
1695

unknown's avatar
unknown committed
1696
/*
unknown's avatar
unknown committed
1697
  Select : retrieve data from table
unknown's avatar
unknown committed
1698 1699 1700 1701
*/


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

1704
/* Need select_init2 for subselects. */
unknown's avatar
unknown committed
1705
select_init:
1706
	SELECT_SYM select_init2
1707
	|
1708 1709
	'(' SELECT_SYM select_part2 ')'
	  {
1710
	    LEX *lex= Lex;
unknown's avatar
unknown committed
1711
            SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1712
	    if (sel->set_braces(1))
1713 1714 1715 1716
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
unknown's avatar
unknown committed
1717 1718 1719 1720 1721
	  if (sel->linkage == UNION_TYPE && !sel->master_unit()->first_select()->braces)
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1722
            /* select in braces, can't contain global parameters */
1723
            sel->master_unit()->global_parameters=
1724
               sel->master_unit();
unknown's avatar
unknown committed
1725
          } union_opt;
1726

1727 1728
select_init2:
	select_part2
1729
        {
1730
	  LEX *lex= Lex;
unknown's avatar
unknown committed
1731
          SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1732
          if (lex->current_select->set_braces(0))
1733 1734 1735 1736
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
unknown's avatar
unknown committed
1737 1738 1739 1740 1741
	  if (sel->linkage == UNION_TYPE && sel->master_unit()->first_select()->braces)
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
1742
	}
1743
	union_clause
1744 1745
	;

1746
select_part2:
unknown's avatar
unknown committed
1747 1748
	{
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1749
	  SELECT_LEX * sel= lex->current_select->select_lex();
unknown's avatar
unknown committed
1750
	  if (lex->current_select == &lex->select_lex)
1751 1752
	    lex->lock_option= TL_READ; /* Only for global SELECT */
	  mysql_init_select(lex);
unknown's avatar
unknown committed
1753
	}
unknown's avatar
unknown committed
1754
	select_options select_item_list select_into select_lock_type;
1755

unknown's avatar
unknown committed
1756
select_into:
1757 1758 1759 1760 1761 1762
	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
1763
	| select_from
1764 1765
	| into select_from
	| select_from into;
unknown's avatar
unknown committed
1766 1767

select_from:
1768
	FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause;
unknown's avatar
unknown committed
1769 1770 1771

select_options:
	/* empty*/
unknown's avatar
unknown committed
1772
	| select_option_list;
unknown's avatar
unknown committed
1773 1774 1775

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
1776
	| select_option;
unknown's avatar
unknown committed
1777 1778

select_option:
1779
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1780 1781 1782 1783 1784 1785
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1786 1787 1788
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
	| 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;
	  }
1801
	| SQL_NO_CACHE_SYM { Lex->uncacheable();; }
1802 1803 1804
	| SQL_CACHE_SYM    { Select->options|= OPTION_TO_QUERY_CACHE; }
	| ALL		{}
	;
unknown's avatar
unknown committed
1805

unknown's avatar
unknown committed
1806 1807 1808
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1809 1810
	  {
	    LEX *lex=Lex;
1811
	    lex->current_select->set_lock_for_tables(TL_WRITE);
1812
	    lex->safe_to_cache_query=0;
1813
	  }
unknown's avatar
unknown committed
1814
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1815 1816
	  {
	    LEX *lex=Lex;
1817 1818
	    lex->current_select->
	      set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
1819
	    lex->safe_to_cache_query=0;
1820 1821
	  }
	;
unknown's avatar
unknown committed
1822

unknown's avatar
unknown committed
1823 1824 1825 1826 1827
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
1828 1829
	    THD *thd= YYTHD;
	    if (add_item_to_list(thd, new Item_field(NULL, NULL, "*")))
unknown's avatar
unknown committed
1830
	      YYABORT;
1831
	    (thd->lex.current_select->select_lex()->with_wild)++;
unknown's avatar
unknown committed
1832
	  };
unknown's avatar
unknown committed
1833 1834 1835 1836 1837


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
unknown's avatar
unknown committed
1838
	    if (add_item_to_list(YYTHD, $2))
unknown's avatar
unknown committed
1839 1840 1841 1842 1843
	      YYABORT;
	    if ($4.str)
	      $2->set_name($4.str);
	    else if (!$2->name)
	      $2->set_name($1,(uint) ($3 - $1));
unknown's avatar
unknown committed
1844
	  };
unknown's avatar
unknown committed
1845 1846

remember_name:
unknown's avatar
unknown committed
1847
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
1848 1849

remember_end:
unknown's avatar
unknown committed
1850
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
1851 1852 1853

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
1854
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
1855 1856 1857 1858 1859 1860

select_alias:
	{ $$.str=0;}
	| AS ident { $$=$2; }
	| AS TEXT_STRING  { $$=$2; }
	| ident { $$=$1; }
unknown's avatar
unknown committed
1861
	| TEXT_STRING  { $$=$1; };
unknown's avatar
unknown committed
1862 1863 1864

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

unknown's avatar
unknown committed
1867
/* all possible expressions */
unknown's avatar
SCRUM  
unknown committed
1868 1869 1870 1871
expr:	
	expr_expr	{ $$= $1; }
	| simple_expr	{ $$= $1; }
	;
unknown's avatar
unknown committed
1872

unknown's avatar
unknown committed
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
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
1885 1886
/* expressions that begin with 'expr' */
expr_expr:
unknown's avatar
SCRUM  
unknown committed
1887
	 expr IN_SYM '(' expr_list ')'
unknown's avatar
unknown committed
1888 1889 1890
	  { $$= 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
1891
        | expr IN_SYM in_subselect
unknown's avatar
unknown committed
1892
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
unknown's avatar
unknown committed
1893
	| expr NOT IN_SYM in_subselect
1894
          {
unknown's avatar
unknown committed
1895
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
unknown's avatar
unknown committed
1896
          }
unknown's avatar
unknown committed
1897 1898 1899 1900
	| 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)); }
1901
	| expr OR_OR_CONCAT expr { $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
1902
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
1903
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
1904
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
1905
	| 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
1906 1907 1908 1909 1910 1911 1912
	| 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
1913 1914 1915
	| expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| expr comp_op all_or_any in_subselect %prec EQ
	{
1916
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
1917
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
1918 1919 1920 1921 1922
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
1923 1924 1925 1926 1927 1928
	| 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); }
1929 1930
	| 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
1931
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
1932
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
1933 1934
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
1935 1936 1937 1938
	| 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); }
1939
	| expr COLLATE_SYM collation_name
1940
	  { $$= new Item_func_set_collation($1,$3); };
unknown's avatar
unknown committed
1941 1942 1943 1944 1945 1946 1947

/* 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)); }
1948
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
1949
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
1950
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
1951
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
unknown's avatar
unknown committed
1952
	| 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
1953 1954 1955 1956 1957 1958 1959
	| 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
1960 1961 1962
	| no_in_expr comp_op expr %prec EQ	{ $$= (*((*$2)(0)))($1,$3); }
	| no_in_expr comp_op all_or_any in_subselect %prec EQ
	{
1963
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
1964
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
1965 1966 1967 1968 1969
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
1970 1971 1972 1973 1974 1975
	| 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); }
1976
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
1977
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
1978
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
1979 1980
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
1981
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
1982 1983 1984 1985
	| 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
1986
	| simple_expr;
unknown's avatar
unknown committed
1987 1988 1989

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
unknown's avatar
unknown committed
1990 1991
	  no_and_expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
unknown's avatar
unknown committed
1992 1993
	| no_and_expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
unknown's avatar
unknown committed
1994
        | no_and_expr IN_SYM in_subselect
unknown's avatar
unknown committed
1995
          { $$= new Item_in_subselect(YYTHD, $1, $3); }
unknown's avatar
unknown committed
1996
	| no_and_expr NOT IN_SYM in_subselect
1997
          {
unknown's avatar
unknown committed
1998
            $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4));
unknown's avatar
unknown committed
1999
          }
unknown's avatar
unknown committed
2000 2001 2002 2003
	| 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)); }
2004
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat(YYTHD, $1,$3); }
unknown's avatar
unknown committed
2005
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
2006
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
2007
	| 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
2008 2009 2010 2011 2012 2013 2014
	| 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
2015 2016 2017
	| no_and_expr comp_op expr %prec EQ { $$= (*((*$2)(0)))($1,$3); }
	| no_and_expr comp_op all_or_any in_subselect %prec EQ
	{
2018
	  Item_allany_subselect *it=
unknown's avatar
unknown committed
2019
	    new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4);
unknown's avatar
unknown committed
2020 2021 2022 2023 2024
	  if ($3)
	    $$ = new Item_func_not(it);	/* ALL */
	  else
	    $$ = it;			/* ANY/SOME */
	}
unknown's avatar
unknown committed
2025 2026 2027 2028 2029 2030
	| 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); }
2031
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
2032
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
2033
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
2034 2035
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
2036
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
2037 2038 2039 2040
	| 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
2041
	| simple_expr;
unknown's avatar
unknown committed
2042

2043
interval_expr:
unknown's avatar
unknown committed
2044
         INTERVAL_SYM expr { $$=$2; }
2045 2046
        ;

unknown's avatar
unknown committed
2047 2048 2049
simple_expr:
	simple_ident
	| literal
unknown's avatar
unknown committed
2050
	| param_marker
unknown's avatar
unknown committed
2051
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
2052 2053
	  {
	    $$= new Item_func_set_user_var($2,$4);
2054
	    Lex->uncacheable();;
unknown's avatar
unknown committed
2055
	  }
2056
	| '@' ident_or_text
unknown's avatar
unknown committed
2057 2058
	  {
	    $$= new Item_func_get_user_var($2);
2059
	    Lex->uncacheable();;
unknown's avatar
unknown committed
2060
	  }
unknown's avatar
unknown committed
2061 2062 2063 2064
	| '@' '@' opt_var_ident_type ident_or_text
	  {
	    if (!($$= get_system_var((enum_var_type) $3, $4)))
	      YYABORT;
unknown's avatar
unknown committed
2065
	  }
unknown's avatar
unknown committed
2066 2067 2068 2069 2070 2071
	| 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; }
2072 2073 2074 2075 2076
	| '(' expr ',' expr_list ')'
	  {
	    $4->push_front($2);
	    $$= new Item_row(*$4);
	  }
2077
	| ROW_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2078
	  {
2079 2080
	    $5->push_front($3);
	    $$= new Item_row(*$5);
unknown's avatar
unknown committed
2081
	  }
unknown's avatar
unknown committed
2082
	| EXISTS exists_subselect { $$= $2; }
unknown's avatar
unknown committed
2083
	| singlerow_subselect   { $$= $1; }
unknown's avatar
unknown committed
2084
	| '{' ident expr '}'	{ $$= $3; }
unknown's avatar
unknown committed
2085
        | MATCH ident_list_arg AGAINST '(' expr ')'
2086
          { Select->add_ftfunc_to_list((Item_func_match *)
2087
                   ($$=new Item_func_match_nl(*$2,$5))); }
unknown's avatar
unknown committed
2088
        | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
2089
          { Select->add_ftfunc_to_list((Item_func_match *)
2090
                   ($$=new Item_func_match_bool(*$2,$5))); }
unknown's avatar
unknown committed
2091
	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
2092
	| BINARY expr %prec NEG { $$= new Item_func_set_collation($2,my_charset_bin); }
unknown's avatar
unknown committed
2093
	| CAST_SYM '(' expr AS cast_type ')'  { $$= create_func_cast($3, $5); }
unknown's avatar
unknown committed
2094
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
2095
	  { $$= new Item_func_case(* $4, $2, $5 ); }
unknown's avatar
unknown committed
2096
	| CONVERT_SYM '(' expr ',' cast_type ')'  { $$= create_func_cast($3, $5); }
2097 2098
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
2099
	| CONVERT_SYM '(' expr ',' expr ',' expr ')'
2100
	  { $$= new Item_func_conv_charset3($3,$7,$5); }
unknown's avatar
SCRUM  
unknown committed
2101 2102
	| DEFAULT '(' simple_ident ')'
	  { $$= new Item_default_value($3); }
unknown's avatar
unknown committed
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
	| 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
2117 2118
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
2119 2120 2121 2122 2123 2124 2125
	| COALESCE '(' expr_list ')'
	  { $$= new Item_func_coalesce(* $3); }
	| CONCAT '(' expr_list ')'
	  { $$= new Item_func_concat(* $3); }
	| CONCAT_WS '(' expr ',' expr_list ')'
	  { $$= new Item_func_concat_ws($3, *$5); }
	| CURDATE optional_braces
2126
	  { $$= new Item_func_curdate(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2127
	| CURTIME optional_braces
2128
	  { $$= new Item_func_curtime(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2129
	| CURTIME '(' expr ')'
2130 2131
	  {
	    $$= new Item_func_curtime($3);
2132
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2133
	  }
2134 2135 2136 2137
	| 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
2138
	| DATABASE '(' ')'
2139
	  {
unknown's avatar
unknown committed
2140
	    $$= new Item_func_database();
2141
            Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2142
	  }
unknown's avatar
unknown committed
2143 2144 2145 2146
	| 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
2147 2148 2149
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
2150
	    Lex->uncacheable();;
unknown's avatar
unknown committed
2151
	  }
unknown's avatar
unknown committed
2152 2153 2154 2155 2156
	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
	| DECODE_SYM '(' expr ',' TEXT_STRING ')'
	  { $$= new Item_func_decode($3,$5.str); }
	| ENCODE_SYM '(' expr ',' TEXT_STRING ')'
	 { $$= new Item_func_encode($3,$5.str); }
unknown's avatar
unknown committed
2157
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2158
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
2159
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2160
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
2161
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
2162
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
2163
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2164
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
2165 2166 2167 2168 2169 2170
	| 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); }
2171 2172
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
2173 2174 2175 2176 2177 2178
	| 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
2179
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2180 2181 2182
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_field($3, *$5); }
unknown's avatar
unknown committed
2183
	| GEOMFROMTEXT '(' expr ')'
2184
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2185
	| GEOMFROMTEXT '(' expr ',' expr ')'
2186
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2187
	| GEOMETRYCOLLECTION '(' expr_list ')'
2188 2189
	  { $$= new Item_func_spatial_collection(* $3,
                       Geometry::wkbGeometryCollection,
unknown's avatar
unknown committed
2190
                       Geometry::wkbPoint); }
unknown's avatar
unknown committed
2191 2192 2193 2194 2195 2196
	| 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); }
2197
	| interval_expr interval '+' expr
unknown's avatar
unknown committed
2198
	  /* we cannot put interval before - */
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208
	  { $$= 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
2209 2210
	| LAST_INSERT_ID '(' ')'
	  {
2211
	    $$= get_system_var(OPT_SESSION, "last_insert_id", 14,
2212
			      "last_insert_id()");
2213
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2214 2215 2216 2217
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
2218
	    Lex->safe_to_cache_query= 0;
unknown's avatar
unknown committed
2219 2220 2221
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
unknown's avatar
unknown committed
2222
	| LINESTRING '(' expr_list ')'
2223
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2224
               Geometry::wkbLineString, Geometry::wkbPoint); }
unknown's avatar
unknown committed
2225 2226 2227 2228
	| 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
2229
 	| GEOMCOLLFROMTEXT '(' expr ')'
2230
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2231
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
2232
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2233
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2234 2235 2236
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
2237
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
2238
	  { $$= new Item_func_log($3); }
2239
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2240
	  { $$= new Item_func_log($3, $5); }
unknown's avatar
unknown committed
2241
 	| LINEFROMTEXT '(' expr ')'
2242
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2243
	| LINEFROMTEXT '(' expr ',' expr ')'
2244
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2245 2246
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
2247 2248
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
2249 2250
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
unknown's avatar
unknown committed
2251
 	| MULTILINESTRING '(' expr_list ')'
2252
 	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2253
                    Geometry::wkbMultiLineString, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2254
 	| MLINEFROMTEXT '(' expr ')'
2255
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2256
	| MLINEFROMTEXT '(' expr ',' expr ')'
2257
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2258
	| MPOINTFROMTEXT '(' expr ')'
2259
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2260
	| MPOINTFROMTEXT '(' expr ',' expr ')'
2261
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2262
	| MPOLYFROMTEXT '(' expr ')'
2263
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2264
	| MPOLYFROMTEXT '(' expr ',' expr ')'
2265
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2266
	| MULTIPOINT '(' expr_list ')'
2267
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2268 2269
                    Geometry::wkbMultiPoint, Geometry::wkbPoint); }
 	| MULTIPOLYGON '(' expr_list ')'
2270
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2271
                       Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
unknown's avatar
unknown committed
2272
	| NOW_SYM optional_braces
2273
	  { $$= new Item_func_now(); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2274
	| NOW_SYM '(' expr ')'
2275
	  { $$= new Item_func_now($3); Lex->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2276
	| PASSWORD '(' expr ')'
unknown's avatar
SCRUM  
unknown committed
2277 2278 2279
	  { $$= new Item_func_password($3); }
        | PASSWORD '(' expr ',' expr ')'
          { $$= new Item_func_password($3,$5); }
unknown's avatar
unknown committed
2280
 	| POINTFROMTEXT '(' expr ')'
2281
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2282
	| POINTFROMTEXT '(' expr ',' expr ')'
2283
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2284
	| POLYFROMTEXT '(' expr ')'
2285
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2286
	| POLYFROMTEXT '(' expr ',' expr ')'
2287
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2288
	| POLYGON '(' expr_list ')'
2289
	  { $$= new Item_func_spatial_collection(* $3,
unknown's avatar
unknown committed
2290
			Geometry::wkbPolygon, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2291 2292
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
2293
	| RAND '(' expr ')'
2294
	  { $$= new Item_func_rand($3); Lex->uncacheable();}
unknown's avatar
unknown committed
2295
	| RAND '(' ')'
2296
	  { $$= new Item_func_rand(); Lex->uncacheable();}
unknown's avatar
unknown committed
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316
	| 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 ')'
2317
	  { $$= new Item_func_trim($3,new Item_string(" ",1,default_charset_info)); }
unknown's avatar
unknown committed
2318 2319 2320 2321 2322 2323 2324 2325
	| TRIM '(' LEADING opt_pad FROM expr ')'
	  { $$= new Item_func_ltrim($6,$4); }
	| TRIM '(' TRAILING opt_pad FROM expr ')'
	  { $$= new Item_func_rtrim($6,$4); }
	| TRIM '(' BOTH opt_pad FROM expr ')'
	  { $$= new Item_func_trim($6,$4); }
	| TRIM '(' expr FROM expr ')'
	  { $$= new Item_func_trim($5,$3); }
2326 2327
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
2328 2329
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372
	| 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 ')'
2373
	  {
unknown's avatar
unknown committed
2374 2375
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
2376
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
2377 2378
	  {
	    $$= new Item_func_unix_timestamp();
2379
	    Lex->safe_to_cache_query=0;
unknown's avatar
unknown committed
2380
	  }
unknown's avatar
unknown committed
2381 2382 2383
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
2384
	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395
	| WEEK_SYM '(' expr ')'
	  { $$= new Item_func_week($3,new Item_int((char*) "0",0,1)); }
	| 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 ')'
2396
	  {
unknown's avatar
unknown committed
2397
	    $$=new Item_func_benchmark($3,$5);
2398
	    Lex->uncacheable();
unknown's avatar
unknown committed
2399
	  }
unknown's avatar
unknown committed
2400
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
2401
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
2402 2403 2404

udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
2405
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427

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); }
	| COUNT_SYM '(' '*' ')'
	  { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
	| COUNT_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_count($3); }
	| COUNT_SYM '(' DISTINCT expr_list ')'
	  { $$=new Item_sum_count_distinct(* $4); }
	| GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
	  { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
	| MIN_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_min($3); }
	| MAX_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_max($3); }
	| STD_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_std($3); }
unknown's avatar
unknown committed
2428 2429
	| VARIANCE_SYM '(' in_sum_expr ')'
	  { $$=new Item_sum_variance($3); }
unknown's avatar
unknown committed
2430
	| SUM_SYM '(' in_sum_expr ')'
unknown's avatar
unknown committed
2431
	  { $$=new Item_sum_sum($3); };
unknown's avatar
unknown committed
2432 2433

in_sum_expr:
2434 2435 2436 2437 2438
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
2439
	    YYABORT;
2440 2441
	  }
	}
unknown's avatar
unknown committed
2442 2443
	expr
	{
unknown's avatar
unknown committed
2444
	  Select->select_lex()->in_sum_expr--;
unknown's avatar
unknown committed
2445
	  $$=$2;
unknown's avatar
unknown committed
2446
	};
unknown's avatar
unknown committed
2447

unknown's avatar
unknown committed
2448
cast_type:
2449
	BINARY			{ $$=ITEM_CAST_BINARY; }
2450
	| CHAR_SYM		{ $$=ITEM_CAST_CHAR; }
unknown's avatar
unknown committed
2451 2452 2453 2454 2455 2456
	| SIGNED_SYM		{ $$=ITEM_CAST_SIGNED_INT; }
	| SIGNED_SYM INT_SYM	{ $$=ITEM_CAST_SIGNED_INT; }
	| UNSIGNED		{ $$=ITEM_CAST_UNSIGNED_INT; }
	| UNSIGNED INT_SYM	{ $$=ITEM_CAST_UNSIGNED_INT; }
	| DATE_SYM		{ $$=ITEM_CAST_DATE; }
	| TIME_SYM		{ $$=ITEM_CAST_TIME; }
2457 2458
	| DATETIME		{ $$=ITEM_CAST_DATETIME; }
	;
unknown's avatar
unknown committed
2459

unknown's avatar
unknown committed
2460
expr_list:
2461
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2462
	expr_list2
unknown's avatar
unknown committed
2463
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2464 2465

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

unknown's avatar
unknown committed
2469 2470
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
2471
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
2472

unknown's avatar
unknown committed
2473
ident_list:
2474
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2475
        ident_list2
unknown's avatar
unknown committed
2476
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2477 2478

ident_list2:
2479
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
2480
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
2481 2482 2483

opt_expr:
	/* empty */      { $$= NULL; }
unknown's avatar
unknown committed
2484
	| expr         	 { $$= $1; };
unknown's avatar
unknown committed
2485 2486 2487

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
2488
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
2489 2490

when_list:
unknown's avatar
unknown committed
2491
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2492
	when_list2
unknown's avatar
unknown committed
2493
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
2494 2495

when_list2:
unknown's avatar
unknown committed
2496
	expr THEN_SYM expr
unknown's avatar
unknown committed
2497
	  {
2498
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2499 2500
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
2501
	}
unknown's avatar
unknown committed
2502
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
2503
	  {
2504
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2505 2506
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
2507
	  };
unknown's avatar
unknown committed
2508 2509

opt_pad:
2510
	/* empty */ { $$=new Item_string(" ",1,default_charset_info); }
unknown's avatar
unknown committed
2511
	| expr	    { $$=$1; };
unknown's avatar
unknown committed
2512 2513 2514 2515

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
2516
	| join_table_list normal_join join_table_list { $$=$3; }
2517 2518 2519
	| join_table_list STRAIGHT_JOIN join_table_list
	  { $$=$3 ; $$->straight=1; }
	| join_table_list INNER_SYM JOIN_SYM join_table_list ON expr
unknown's avatar
unknown committed
2520
	  { add_join_on($4,$6); $$=$4; }
2521
	| join_table_list INNER_SYM JOIN_SYM join_table_list
unknown's avatar
unknown committed
2522
	  {
unknown's avatar
unknown committed
2523
	    SELECT_LEX *sel= Select->select_lex();
2524 2525
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$4->db; sel->table2=$4->alias;
unknown's avatar
unknown committed
2526
	  }
unknown's avatar
unknown committed
2527 2528
	  USING '(' using_list ')'
	  { add_join_on($4,$8); $$=$4; }
2529
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2530
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2531
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2532
	  {
unknown's avatar
unknown committed
2533
	    SELECT_LEX *sel= Select->select_lex();
2534 2535
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2536
	  }
unknown's avatar
unknown committed
2537
	  USING '(' using_list ')'
2538
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2539
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2540
	  { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
2541
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2542
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2543
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2544
	  {
unknown's avatar
unknown committed
2545
	    SELECT_LEX *sel= Select->select_lex();
2546 2547
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2548
	  }
2549 2550
	  USING '(' using_list ')'
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2551
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2552
	  { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2553
	| join_table_list NATURAL JOIN_SYM join_table_list
unknown's avatar
unknown committed
2554
	  { add_join_natural($1,$4); $$=$4; };
unknown's avatar
unknown committed
2555 2556 2557 2558

normal_join:
	',' {}
	| JOIN_SYM {}
unknown's avatar
unknown committed
2559
	| CROSS JOIN_SYM {};
unknown's avatar
unknown committed
2560 2561

join_table:
unknown's avatar
unknown committed
2562
	{
unknown's avatar
unknown committed
2563
	  SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2564
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
unknown's avatar
unknown committed
2565
	  sel->table_join_options= 0;
unknown's avatar
unknown committed
2566
	}
unknown's avatar
unknown committed
2567
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
2568
	{
unknown's avatar
unknown committed
2569 2570
	  LEX *lex= Lex;
	  SELECT_LEX_NODE *sel= lex->current_select;
unknown's avatar
unknown committed
2571
	  if (!($$= sel->add_table_to_list(lex->thd, $2, $3,
unknown's avatar
unknown committed
2572
					   sel->get_table_join_options(),
unknown's avatar
unknown committed
2573
					   lex->lock_option,
2574 2575
					   sel->get_use_index(),
					   sel->get_ignore_index())))
2576
	    YYABORT;
unknown's avatar
unknown committed
2577
	}
unknown's avatar
unknown committed
2578
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2579
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
2580
        | '(' SELECT_SYM select_derived ')' opt_table_alias
unknown's avatar
unknown committed
2581 2582
	{
	  LEX *lex=Lex;
2583 2584 2585
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
unknown's avatar
unknown committed
2586
                add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
2587
				  TL_READ,(List<String> *)0,
unknown's avatar
unknown committed
2588 2589
	                          (List<String> *)0)))

unknown's avatar
unknown committed
2590
	    YYABORT;
unknown's avatar
unknown committed
2591
	};
unknown's avatar
unknown committed
2592

2593
select_derived:
unknown's avatar
unknown committed
2594
        {
unknown's avatar
unknown committed
2595
	  LEX *lex= Lex;
unknown's avatar
unknown committed
2596
	  lex->derived_tables= 1;
2597 2598 2599 2600 2601 2602
	  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;
	  }
2603
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
unknown's avatar
unknown committed
2604
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
2605 2606
	    YYABORT;
	  mysql_init_select(lex);
2607
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
unknown's avatar
unknown committed
2608
	}
2609
        select_options select_item_list opt_select_from union_opt
2610
        ;
unknown's avatar
unknown committed
2611 2612 2613

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
2614
	| OUTER		{};
unknown's avatar
unknown committed
2615 2616 2617 2618

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
2619
          {
unknown's avatar
unknown committed
2620
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2621 2622 2623
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2624 2625 2626 2627 2628 2629 2630
	| 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
2631
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
2632
	  {
unknown's avatar
unknown committed
2633
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2634 2635
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
2636
	  };
unknown's avatar
unknown committed
2637 2638

key_usage_list:
unknown's avatar
unknown committed
2639
	key_or_index { Select->select_lex()->interval_list.empty(); }
unknown's avatar
unknown committed
2640 2641 2642 2643 2644 2645 2646 2647
        '(' key_list_or_empty ')'
        { $$= &Select->select_lex()->interval_list; }
	;

key_list_or_empty:
	/* empty */ 		{}
	| key_usage_list2	{}
	;
unknown's avatar
unknown committed
2648 2649 2650

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
2651
        { Select->select_lex()->
2652 2653
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
				    default_charset_info)); }
unknown's avatar
unknown committed
2654
	| ident
unknown's avatar
unknown committed
2655
        { Select->select_lex()->
2656 2657
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
				    default_charset_info)); }
unknown's avatar
unknown committed
2658
	| PRIMARY_SYM
unknown's avatar
unknown committed
2659
        { Select->select_lex()->
2660 2661
	    interval_list.push_back(new String("PRIMARY", 7,
				    default_charset_info)); };
unknown's avatar
unknown committed
2662 2663 2664

using_list:
	ident
unknown's avatar
unknown committed
2665
	  {
unknown's avatar
unknown committed
2666
	    SELECT_LEX *sel= Select->select_lex();
2667 2668 2669 2670
	    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
2671 2672 2673 2674
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
2675
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2676
	    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
2677
	      YYABORT;
unknown's avatar
unknown committed
2678
	  };
unknown's avatar
unknown committed
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692

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
2693
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
unknown's avatar
unknown committed
2694 2695 2696 2697

table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
2698
	| EQ;
unknown's avatar
unknown committed
2699 2700 2701 2702

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


where_clause:
2707
	/* empty */  { Select->select_lex()->where= 0; }
2708 2709
	| WHERE expr
	  {
unknown's avatar
unknown committed
2710
	    Select->select_lex()->where= $2;
2711 2712 2713
	    if ($2)
	      $2->top_level_item();
	  }
unknown's avatar
unknown committed
2714
 	;
unknown's avatar
unknown committed
2715 2716 2717

having_clause:
	/* empty */
unknown's avatar
unknown committed
2718
	| HAVING { Select->select_lex()->create_refs= 1; } expr
unknown's avatar
unknown committed
2719 2720 2721 2722 2723 2724
	  {
	    SELECT_LEX *sel= Select->select_lex();
	    sel->having= $3; sel->create_refs=0;
	    if ($3)
	      $3->top_level_item();
	  }
2725
	;
unknown's avatar
unknown committed
2726 2727 2728

opt_escape:
	ESCAPE_SYM TEXT_STRING	{ $$= $2.str; }
unknown's avatar
unknown committed
2729
	| /* empty */		{ $$= (char*) "\\"; };
unknown's avatar
unknown committed
2730 2731 2732


/*
unknown's avatar
unknown committed
2733
   group by statement in select
unknown's avatar
unknown committed
2734 2735 2736 2737
*/

group_clause:
	/* empty */
2738
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
2739 2740

group_list:
unknown's avatar
unknown committed
2741
	group_list ',' order_ident order_dir
unknown's avatar
unknown committed
2742
	  { if (add_group_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
2743
	| order_ident order_dir
unknown's avatar
unknown committed
2744
	  { if (add_group_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
2745

2746 2747
olap_opt:
	/* empty */ {}
2748
	| WITH CUBE_SYM
2749
          {
2750
	    LEX *lex=Lex;
unknown's avatar
unknown committed
2751
	    lex->olap= 1;
2752 2753 2754 2755 2756 2757
	    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
2758
	    lex->current_select->select_lex()->olap= CUBE_TYPE;
2759
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
2760
	    YYABORT;	/* To be deleted in 4.1 */
2761
	  }
2762
	| WITH ROLLUP_SYM
2763
          {
2764
	    LEX *lex= Lex;
unknown's avatar
unknown committed
2765
	    lex->olap= 1;
2766 2767 2768 2769 2770 2771
	    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
2772
	    lex->current_select->select_lex()->olap= ROLLUP_TYPE;
2773
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "ROLLUP");
2774
	    YYABORT;	/* To be deleted in 4.1 */
2775
	  }
2776
	;
2777

unknown's avatar
unknown committed
2778
/*
unknown's avatar
unknown committed
2779
   Order by statement in select
unknown's avatar
unknown committed
2780 2781
*/

2782
opt_order_clause:
unknown's avatar
unknown committed
2783
	/* empty */
unknown's avatar
unknown committed
2784
	| order_clause;
2785 2786

order_clause:
2787 2788
	ORDER_SYM BY
        {
unknown's avatar
unknown committed
2789
	  LEX *lex=Lex;
2790
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
2791
	      lex->current_select->select_lex()->olap !=
2792
	      UNSPECIFIED_OLAP_TYPE)
2793
	  {
2794
	    net_printf(lex->thd, ER_WRONG_USAGE,
2795 2796 2797 2798
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
2799
	} order_list;
unknown's avatar
unknown committed
2800 2801 2802

order_list:
	order_list ',' order_ident order_dir
unknown's avatar
unknown committed
2803
	  { if (add_order_to_list(YYTHD, $3,(bool) $4)) YYABORT; }
unknown's avatar
unknown committed
2804
	| order_ident order_dir
unknown's avatar
unknown committed
2805
	  { if (add_order_to_list(YYTHD, $1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
2806 2807 2808

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
2809
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
2810
	| DESC { $$ =0; };
unknown's avatar
unknown committed
2811 2812


2813
opt_limit_clause:
unknown's avatar
unknown committed
2814
	/* empty */ {}
2815 2816 2817 2818
	| limit_clause {}
	;

limit_clause:
2819
	LIMIT
unknown's avatar
unknown committed
2820
	  {
2821 2822
	    LEX *lex= Lex;
	    if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
2823
	        lex->current_select->select_lex()->olap !=
2824
		UNSPECIFIED_OLAP_TYPE)
2825
	    {
2826
	      net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
2827
		        "LIMIT");
2828
	      YYABORT;
2829
	    }
unknown's avatar
unknown committed
2830
	  }
unknown's avatar
unknown committed
2831
	  limit_options
2832
	  {}
unknown's avatar
unknown committed
2833
	;
unknown's avatar
unknown committed
2834 2835 2836

limit_options:
	ULONG_NUM
unknown's avatar
unknown committed
2837
	  {
unknown's avatar
unknown committed
2838
            SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
2839 2840 2841 2842 2843
            sel->select_limit= $1;
            sel->offset_limit= 0L;
	  }
	| ULONG_NUM ',' ULONG_NUM
	  {
2844
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
2845 2846
	    sel->select_limit= $3;
	    sel->offset_limit= $1;
unknown's avatar
unknown committed
2847
	  }
unknown's avatar
unknown committed
2848
	| ULONG_NUM OFFSET_SYM ULONG_NUM
unknown's avatar
unknown committed
2849
	  {
unknown's avatar
unknown committed
2850
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
2851 2852 2853 2854
	    sel->select_limit= $1;
	    sel->offset_limit= $3;
	  }
	;
unknown's avatar
unknown committed
2855 2856 2857 2858 2859


delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
2860
	  LEX *lex=Lex;
2861
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
2862
	}
unknown's avatar
unknown committed
2863
	| LIMIT ulonglong_num
unknown's avatar
unknown committed
2864
	{ Select->select_limit= (ha_rows) $2; };
unknown's avatar
unknown committed
2865 2866

ULONG_NUM:
unknown's avatar
unknown committed
2867
	NUM	    { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2868
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
2869
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2870
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
unknown's avatar
unknown committed
2871

unknown's avatar
unknown committed
2872
ulonglong_num:
unknown's avatar
unknown committed
2873
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2874 2875
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
	| LONG_NUM  { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2876
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
2877
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
unknown's avatar
unknown committed
2878 2879 2880 2881 2882 2883

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
2884 2885 2886 2887 2888 2889 2890
	    if (&lex->select_lex != lex->current_select)
	    {
	      net_printf(lex->thd, ER_WRONG_USAGE,
			  "PROCEDURE",
			  "subquery");
	      YYABORT;
	    }
unknown's avatar
unknown committed
2891 2892 2893
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
unknown's avatar
unknown committed
2894
	    if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
unknown's avatar
unknown committed
2895
	      YYABORT;
2896
	    Lex->uncacheable();
unknown's avatar
unknown committed
2897
	  }
unknown's avatar
unknown committed
2898
	  '(' procedure_list ')';
unknown's avatar
unknown committed
2899 2900 2901 2902


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
2903
	| procedure_list2 {};
unknown's avatar
unknown committed
2904 2905 2906

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
2907
	| procedure_item;
unknown's avatar
unknown committed
2908 2909 2910 2911

procedure_item:
	  remember_name expr
	  {
unknown's avatar
unknown committed
2912 2913
	    LEX *lex= Lex;
	    if (add_proc_to_list(lex->thd, $2))
unknown's avatar
unknown committed
2914 2915
	      YYABORT;
	    if (!$2->name)
unknown's avatar
unknown committed
2916
	      $2->set_name($1,(uint) ((char*) lex->tok_end - $1));
2917 2918 2919 2920 2921 2922
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
2923 2924
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
2925 2926
	        YYABORT;
	   }
2927
	   select_var_list
2928
	   {}
2929
           ;
unknown's avatar
unknown committed
2930

unknown's avatar
unknown committed
2931
select_var_list:
2932 2933 2934 2935 2936
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
2937
           {
2938
             LEX *lex=Lex;
unknown's avatar
unknown committed
2939
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
2940 2941
	       YYABORT;
	   }
unknown's avatar
unknown committed
2942
           ;
unknown's avatar
unknown committed
2943

2944
into:
unknown's avatar
unknown committed
2945
        INTO OUTFILE TEXT_STRING
unknown's avatar
unknown committed
2946
	{
2947
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2948 2949 2950 2951 2952 2953 2954
	  if (!lex->describe)
	  {
	    if (!(lex->exchange= new sql_exchange($3.str,0)))
	      YYABORT;
	    if (!(lex->result= new select_export(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
2955 2956 2957 2958
	}
	opt_field_term opt_line_term
	| INTO DUMPFILE TEXT_STRING
	{
2959
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2960 2961 2962 2963 2964 2965 2966
	  if (!lex->describe)
	  {
	    if (!(lex->exchange= new sql_exchange($3.str,1)))
	      YYABORT;
	    if (!(lex->result= new select_dump(lex->exchange)))
	      YYABORT;
	  }
unknown's avatar
unknown committed
2967
	}
2968
        | INTO select_var_list_init
unknown's avatar
unknown committed
2969
	{
2970
	  Lex->uncacheable();
2971 2972
	}
        ;
unknown's avatar
unknown committed
2973

unknown's avatar
unknown committed
2974 2975 2976
/*
  DO statement
*/
unknown's avatar
unknown committed
2977

2978
do:	DO_SYM
unknown's avatar
unknown committed
2979 2980 2981 2982 2983 2984
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
2985 2986 2987 2988
	values
	{}
	;

unknown's avatar
unknown committed
2989
/*
unknown's avatar
unknown committed
2990
  Drop : delete tables or index
unknown's avatar
unknown committed
2991 2992 2993
*/

drop:
2994
	DROP opt_temporary TABLE_SYM if_exists table_list opt_restrict
unknown's avatar
unknown committed
2995
	{
unknown's avatar
unknown committed
2996 2997
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
2998 2999
	  lex->drop_temporary= $2;
	  lex->drop_if_exists= $4;
unknown's avatar
unknown committed
3000 3001 3002
	}
	| DROP INDEX ident ON table_ident {}
	  {
unknown's avatar
unknown committed
3003 3004 3005 3006
	     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
3007
						     $3.str));
unknown's avatar
unknown committed
3008 3009
	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
							TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3010 3011 3012 3013
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
3014 3015 3016 3017
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
3018 3019 3020
	 }
	| DROP UDF_SYM ident
	  {
unknown's avatar
unknown committed
3021 3022 3023
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
	    lex->udf.name=$3.str;
unknown's avatar
unknown committed
3024
	  };
unknown's avatar
unknown committed
3025 3026 3027


table_list:
3028
	table_name
unknown's avatar
unknown committed
3029
	| table_list ',' table_name;
unknown's avatar
unknown committed
3030

3031
table_name:
unknown's avatar
unknown committed
3032
	table_ident
unknown's avatar
unknown committed
3033 3034 3035 3036 3037
	{
	  if (!Select->add_table_to_list(YYTHD, $1, NULL, TL_OPTION_UPDATING))
	    YYABORT;
	}
	;
unknown's avatar
unknown committed
3038 3039

if_exists:
3040
	/* empty */ { $$= 0; }
3041 3042
	| IF EXISTS { $$= 1; }
	;
unknown's avatar
unknown committed
3043

3044 3045 3046 3047
opt_temporary:
	/* empty */ { $$= 0; }
	| TEMPORARY { $$= 1; }
	;
unknown's avatar
unknown committed
3048 3049 3050 3051 3052
/*
** Insert : add new data to table
*/

insert:
3053 3054 3055 3056 3057 3058 3059
	INSERT
	{
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_INSERT;
	  /* for subselects */
          lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	} insert_lock_option
3060
	opt_ignore insert2
unknown's avatar
unknown committed
3061
	{
unknown's avatar
unknown committed
3062
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3063
	}
3064
	insert_field_spec opt_insert_update
3065
	{}
unknown's avatar
unknown committed
3066
	;
unknown's avatar
unknown committed
3067 3068

replace:
3069 3070
	REPLACE
	{
3071
	  LEX *lex=Lex;
3072 3073 3074
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
unknown's avatar
unknown committed
3075 3076
	replace_lock_option insert2
	{
unknown's avatar
unknown committed
3077
	  Select->set_lock_for_tables($3);
unknown's avatar
unknown committed
3078 3079
	}
	insert_field_spec
3080
	{}
unknown's avatar
unknown committed
3081
	{}
unknown's avatar
unknown committed
3082
	;
unknown's avatar
unknown committed
3083 3084

insert_lock_option:
unknown's avatar
unknown committed
3085 3086 3087 3088
	/* empty */	{ $$= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ $$= TL_WRITE_DELAYED; }
	| HIGH_PRIORITY { $$= TL_WRITE; }
3089
	;
unknown's avatar
unknown committed
3090 3091

replace_lock_option:
unknown's avatar
unknown committed
3092 3093
	opt_low_priority { $$= $1; }
	| DELAYED_SYM	 { $$= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
3094 3095 3096

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
3097
	| insert_table {};
unknown's avatar
unknown committed
3098 3099

insert_table:
3100
	table_name
unknown's avatar
unknown committed
3101
	{
unknown's avatar
unknown committed
3102 3103 3104 3105
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
3106
	};
unknown's avatar
unknown committed
3107 3108 3109 3110 3111

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
unknown's avatar
unknown committed
3112 3113 3114
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3115 3116
	      YYABORT;
	   }
unknown's avatar
unknown committed
3117
	   ident_eq_list;
unknown's avatar
unknown committed
3118 3119 3120 3121

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
3122
	| '(' ')'	  { };
unknown's avatar
unknown committed
3123 3124 3125

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
3126
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
3127 3128 3129

insert_values:
	VALUES	values_list  {}
unknown's avatar
unknown committed
3130
	| VALUE_SYM values_list  {}
unknown's avatar
unknown committed
3131 3132 3133 3134 3135
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
unknown's avatar
unknown committed
3136
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
3137
	    mysql_init_select(lex);
unknown's avatar
unknown committed
3138
	  }
unknown's avatar
unknown committed
3139
	  select_options select_item_list opt_select_from select_lock_type
3140
          union_clause {}
unknown's avatar
unknown committed
3141
	;
unknown's avatar
unknown committed
3142 3143 3144

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
3145
	| no_braces;
unknown's avatar
unknown committed
3146 3147 3148 3149

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
3150
	ident_eq_value;
unknown's avatar
unknown committed
3151 3152

ident_eq_value:
unknown's avatar
unknown committed
3153
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
3154
	 {
unknown's avatar
unknown committed
3155 3156 3157
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
3158
	    YYABORT;
unknown's avatar
unknown committed
3159
	 };
unknown's avatar
unknown committed
3160 3161

equal:	EQ		{}
unknown's avatar
unknown committed
3162 3163 3164 3165 3166 3167 3168
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
3169 3170 3171 3172 3173 3174 3175 3176 3177

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
3178 3179
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
3180
	    YYABORT;
unknown's avatar
unknown committed
3181
	 };
unknown's avatar
unknown committed
3182 3183 3184

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
3185
	| values;
unknown's avatar
unknown committed
3186 3187

values:
unknown's avatar
unknown committed
3188
	values ','  expr_or_default
unknown's avatar
unknown committed
3189 3190 3191 3192
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
3193 3194 3195 3196 3197 3198 3199 3200
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
3201
	expr	  { $$= $1;}
unknown's avatar
SCRUM  
unknown committed
3202
	| DEFAULT {$$= new Item_default_value(); }
unknown's avatar
unknown committed
3203
	;
unknown's avatar
unknown committed
3204

3205 3206
opt_insert_update:
        /* empty */
unknown's avatar
unknown committed
3207
        | ON DUPLICATE_SYM
3208 3209 3210 3211 3212 3213 3214 3215 3216
          { /* 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;
            }
          }
3217
          KEY_SYM UPDATE_SYM update_list
3218 3219
        ;

unknown's avatar
unknown committed
3220 3221 3222
/* Update rows in a table */

update:
3223 3224
	UPDATE_SYM
	{
3225 3226
	  LEX *lex= Lex;
          lex->sql_command= SQLCOM_UPDATE;
3227
          lex->select_lex.init_order();
3228
        }
unknown's avatar
unknown committed
3229 3230 3231
        opt_low_priority opt_ignore join_table_list
	SET update_list where_clause opt_order_clause delete_limit_clause
	{
3232
	  LEX *lex= Lex;
unknown's avatar
unknown committed
3233
	  Select->set_lock_for_tables($3);
3234
          if (lex->select_lex.table_list.elements > 1)
3235
            lex->sql_command=SQLCOM_UPDATE_MULTI;
unknown's avatar
unknown committed
3236 3237
	}
	;
unknown's avatar
unknown committed
3238 3239

update_list:
unknown's avatar
SCRUM  
unknown committed
3240
	update_list ',' simple_ident equal expr_or_default
unknown's avatar
unknown committed
3241
	{
unknown's avatar
unknown committed
3242
	  if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5))
unknown's avatar
unknown committed
3243 3244
	    YYABORT;
	}
unknown's avatar
SCRUM  
unknown committed
3245
	| simple_ident equal expr_or_default
unknown's avatar
unknown committed
3246
	  {
unknown's avatar
unknown committed
3247
	    if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3))
unknown's avatar
unknown committed
3248
	      YYABORT;
unknown's avatar
unknown committed
3249
	  };
unknown's avatar
unknown committed
3250 3251

opt_low_priority:
3252
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3253
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3254 3255 3256 3257

/* Delete rows from a table */

delete:
3258
	DELETE_SYM
3259
	{
3260 3261 3262
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
	  lex->select_lex.options= 0;
unknown's avatar
unknown committed
3263
	  lex->lock_option= lex->thd->update_lock_default;
3264
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3265
	}
unknown's avatar
unknown committed
3266 3267
	opt_delete_options single_multi {}
	;
3268 3269

single_multi:
unknown's avatar
unknown committed
3270 3271
 	FROM table_ident
	{
unknown's avatar
unknown committed
3272 3273
	  if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
					 Lex->lock_option))
unknown's avatar
unknown committed
3274 3275 3276
	    YYABORT;
	}
	where_clause opt_order_clause
3277
	delete_limit_clause {}
unknown's avatar
unknown committed
3278
	| table_wild_list
unknown's avatar
unknown committed
3279
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
3280
          FROM join_table_list where_clause
unknown's avatar
unknown committed
3281 3282
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
3283 3284 3285
	  USING join_table_list where_clause
	  {}
	;
unknown's avatar
unknown committed
3286 3287 3288

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
3289
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
3290 3291

table_wild_one:
unknown's avatar
unknown committed
3292
	ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3293
	{
unknown's avatar
unknown committed
3294 3295
	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
					 TL_OPTION_UPDATING, Lex->lock_option))
unknown's avatar
unknown committed
3296 3297
	    YYABORT;
        }
unknown's avatar
unknown committed
3298
	| ident '.' ident opt_wild opt_table_alias
unknown's avatar
unknown committed
3299
	  {
unknown's avatar
unknown committed
3300
	    if (!Select->add_table_to_list(YYTHD, new Table_ident($1, $3, 0),
unknown's avatar
unknown committed
3301 3302
					   $5, TL_OPTION_UPDATING,
					   Lex->lock_option))
unknown's avatar
unknown committed
3303
	      YYABORT;
unknown's avatar
unknown committed
3304
	  }
unknown's avatar
unknown committed
3305
	;
unknown's avatar
unknown committed
3306 3307

opt_wild:
3308
	/* empty */	{}
unknown's avatar
unknown committed
3309
	| '.' '*'	{};
unknown's avatar
unknown committed
3310 3311


3312
opt_delete_options:
unknown's avatar
unknown committed
3313
	/* empty */	{}
unknown's avatar
unknown committed
3314
	| opt_delete_option opt_delete_options {};
3315 3316

opt_delete_option:
3317
	QUICK		{ Select->options|= OPTION_QUICK; }
unknown's avatar
unknown committed
3318
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
3319

3320
truncate:
unknown's avatar
unknown committed
3321
	TRUNCATE_SYM opt_table_sym table_name
3322
	{
3323
	  LEX* lex= Lex;
3324
	  lex->sql_command= SQLCOM_TRUNCATE;
3325
	  lex->select_lex.options= 0;
3326
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
3327 3328
	}
	;
3329

unknown's avatar
unknown committed
3330 3331
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
3332
	| TABLE_SYM;
3333

unknown's avatar
unknown committed
3334 3335
/* Show things */

3336 3337
show:	SHOW
	{
unknown's avatar
unknown committed
3338 3339 3340 3341
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
unknown's avatar
unknown committed
3342
	show_param
3343 3344
	{}
	;
unknown's avatar
unknown committed
3345 3346 3347 3348 3349

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
3350
	  {
3351
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3352
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3353 3354
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
unknown's avatar
unknown committed
3355
	   }
unknown's avatar
unknown committed
3356
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
3357
	  {
3358
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3359
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3360 3361
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
3362
	  }
3363
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
3364
	  {
3365
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3366
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
3367 3368
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
3369
	  }
unknown's avatar
unknown committed
3370
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
3371 3372
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3373 3374
	    if ($5)
	      $4->change_db($5);
unknown's avatar
unknown committed
3375
	    if (!Select->add_table_to_list(YYTHD, $4, NULL, 0))
unknown's avatar
unknown committed
3376 3377
	      YYABORT;
	  }
3378
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ
3379 3380
	  TEXT_STRING AND MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
3381 3382 3383 3384 3385
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
3386
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
3387
          }
3388
        | BINARY LOGS_SYM
unknown's avatar
unknown committed
3389 3390
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
3391 3392 3393 3394 3395
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
3396
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
3397
          {
3398 3399 3400 3401
	    LEX *lex= Lex;
	    lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
	    lex->select_lex.select_limit= lex->thd->variables.select_limit;
	    lex->select_lex.offset_limit= 0L;
3402
          } opt_limit_clause
unknown's avatar
unknown committed
3403 3404 3405 3406 3407
	| 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
3408
	    if (!Select->add_table_to_list(YYTHD, $3, NULL, 0))
unknown's avatar
unknown committed
3409 3410
	      YYABORT;
	  }
unknown's avatar
unknown committed
3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425
	| 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;
	  }
3426
        | COUNT_SYM '(' '*' ')' WARNINGS
3427
          { (void) create_select_for_variable("warning_count"); }
3428
        | COUNT_SYM '(' '*' ')' ERRORS
3429
	  { (void) create_select_for_variable("error_count"); }
3430
        | WARNINGS {Select->offset_limit=0L;} opt_limit_clause
unknown's avatar
unknown committed
3431
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
3432
        | ERRORS {Select->offset_limit=0L;} opt_limit_clause
3433
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}
unknown's avatar
unknown committed
3434 3435
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
3436 3437
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
unknown's avatar
unknown committed
3438 3439
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
3440
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
3441
	  {
3442
	    THD *thd= YYTHD;
3443
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
unknown's avatar
unknown committed
3444
	    thd->lex.option_type= (enum_var_type) $1;
3445
	  }
3446 3447
	| CHAR_SYM SET wild
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
unknown's avatar
unknown committed
3448 3449
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
unknown's avatar
unknown committed
3450
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
3451 3452 3453 3454 3455 3456
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
3457
	| CREATE DATABASE opt_if_not_exists ident
unknown's avatar
unknown committed
3458 3459
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
3460 3461
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
3462
	  }
unknown's avatar
unknown committed
3463 3464 3465
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
unknown's avatar
unknown committed
3466
	    if (!Select->add_table_to_list(YYTHD, $3, NULL,0))
unknown's avatar
unknown committed
3467 3468 3469 3470 3471
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
3472
          }
unknown's avatar
unknown committed
3473 3474 3475
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
3476
          };
unknown's avatar
unknown committed
3477 3478 3479

opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
3480
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
3481 3482 3483

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

unknown's avatar
unknown committed
3486 3487
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
3488
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
3489

unknown's avatar
unknown committed
3490 3491
from_or_in:
	FROM
unknown's avatar
unknown committed
3492
	| IN_SYM;
unknown's avatar
unknown committed
3493

unknown's avatar
unknown committed
3494 3495
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
3496
        | IN_SYM TEXT_STRING { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
3497 3498 3499

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


unknown's avatar
unknown committed
3503 3504 3505 3506
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
3507 3508 3509 3510
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3511
	  if (!Select->add_table_to_list(lex->thd, $2, NULL,0))
unknown's avatar
unknown committed
3512 3513
	    YYABORT;
	}
3514
	opt_describe_column {}
unknown's avatar
unknown committed
3515
	| describe_command { Lex->describe=1; } select
3516
          {
unknown's avatar
unknown committed
3517
	    LEX *lex=Lex;
3518
	    lex->select_lex.options|= SELECT_DESCRIBE;
unknown's avatar
unknown committed
3519 3520
	  }
	;
unknown's avatar
unknown committed
3521 3522 3523

describe_command:
	DESC
unknown's avatar
unknown committed
3524
	| DESCRIBE;
unknown's avatar
unknown committed
3525 3526 3527 3528

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
3529
	| ident
unknown's avatar
unknown committed
3530
	  { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); };
unknown's avatar
unknown committed
3531 3532 3533 3534 3535


/* flush things */

flush:
unknown's avatar
unknown committed
3536 3537 3538 3539 3540
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
3541 3542 3543
	flush_options
	{}
	;
unknown's avatar
unknown committed
3544 3545 3546

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
3547
	| flush_option;
unknown's avatar
unknown committed
3548 3549

flush_option:
3550
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list {}
unknown's avatar
unknown committed
3551
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
3552
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
3553 3554 3555 3556
	| 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
3557 3558
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3559 3560
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
3561

unknown's avatar
unknown committed
3562
opt_table_list:
3563 3564
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
3565

unknown's avatar
unknown committed
3566
reset:
unknown's avatar
unknown committed
3567 3568 3569 3570
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
3571 3572 3573 3574
	} reset_options
	{}
	;

unknown's avatar
unknown committed
3575 3576
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
3577
	| reset_option;
unknown's avatar
unknown committed
3578 3579

reset_option:
unknown's avatar
unknown committed
3580 3581
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
3582
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
3583

unknown's avatar
unknown committed
3584
purge:
unknown's avatar
unknown committed
3585 3586 3587 3588 3589 3590
	PURGE
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_PURGE;
	  lex->type=0;
	}
unknown's avatar
unknown committed
3591 3592 3593
        MASTER_SYM LOGS_SYM TO_SYM TEXT_STRING
         {
	   Lex->to_log = $6.str;
unknown's avatar
unknown committed
3594
         } ;
unknown's avatar
unknown committed
3595

unknown's avatar
unknown committed
3596 3597 3598
/* kill threads */

kill:
3599
	KILL_SYM expr
unknown's avatar
unknown committed
3600
	{
unknown's avatar
unknown committed
3601
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3602
	  if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1))
3603
	  {
3604
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
3605 3606 3607 3608
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
3609
	};
unknown's avatar
unknown committed
3610 3611 3612 3613

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
3614 3615
	{
	  LEX *lex=Lex;
3616 3617
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
3618
	};
unknown's avatar
unknown committed
3619 3620 3621

/* import, export of files */

3622
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING
unknown's avatar
unknown committed
3623
	{
unknown's avatar
unknown committed
3624 3625
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
unknown's avatar
unknown committed
3626 3627
	  lex->lock_option= $3;
	  lex->local_file=  $4;
unknown's avatar
unknown committed
3628
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
3629
	    YYABORT;
unknown's avatar
unknown committed
3630
	  lex->field_list.empty();
unknown's avatar
unknown committed
3631 3632 3633 3634
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
unknown's avatar
unknown committed
3635
	  if (!Select->add_table_to_list(YYTHD, $11, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3636 3637 3638
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
3639
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
3640 3641
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
unknown's avatar
unknown committed
3642
	  if (!Select->add_table_to_list(YYTHD, $3, NULL, TL_OPTION_UPDATING))
unknown's avatar
unknown committed
3643
	    YYABORT;
unknown's avatar
unknown committed
3644 3645

        }
3646 3647 3648 3649
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
3650
        };
unknown's avatar
unknown committed
3651 3652 3653

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

unknown's avatar
unknown committed
3656
load_data_lock:
3657
	/* empty */	{ $$= YYTHD->update_lock_default; }
unknown's avatar
unknown committed
3658 3659
	| CONCURRENT	{ $$= TL_WRITE_CONCURRENT_INSERT ; }
	| LOW_PRIORITY	{ $$= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3660 3661


unknown's avatar
unknown committed
3662 3663 3664
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
unknown's avatar
unknown committed
3665
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
3666 3667 3668

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
3669
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
3670 3671 3672

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
3673
	| field_term;
unknown's avatar
unknown committed
3674 3675 3676 3677

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
3678 3679 3680 3681 3682
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
unknown's avatar
unknown committed
3683
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
unknown's avatar
unknown committed
3684
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
unknown's avatar
unknown committed
3685 3686 3687

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
3688
	| LINES line_term_list;
unknown's avatar
unknown committed
3689 3690 3691

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
3692
	| line_term;
unknown's avatar
unknown committed
3693 3694 3695

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
unknown's avatar
unknown committed
3696
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
unknown's avatar
unknown committed
3697 3698 3699 3700

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
unknown's avatar
unknown committed
3701
	  { Lex->exchange->skip_lines=atol($2.str); };
unknown's avatar
unknown committed
3702 3703 3704 3705

/* Common definitions */

text_literal:
3706
	TEXT_STRING { $$ = new Item_string($1.str,$1.length,YYTHD->variables.thd_charset); }
3707
	| UNDERSCORE_CHARSET TEXT_STRING { $$ = new Item_string($2.str,$2.length,Lex->charset); }
unknown's avatar
unknown committed
3708
	| text_literal TEXT_STRING
unknown's avatar
unknown committed
3709
	{ ((Item_string*) $1)->append($2.str,$2.length); };
unknown's avatar
unknown committed
3710 3711

text_string:
3712
	TEXT_STRING	{ $$=  new String($1.str,$1.length,YYTHD->variables.thd_charset); }
unknown's avatar
unknown committed
3713 3714
	| HEX_NUM
	  {
3715
	    Item *tmp = new Item_varbinary($1.str,$1.length);
unknown's avatar
unknown committed
3716
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
unknown's avatar
unknown committed
3717
	  };
unknown's avatar
unknown committed
3718
param_marker:
3719
        '?'
unknown's avatar
unknown committed
3720
        {
3721
	  LEX *lex=Lex;
3722
          if (YYTHD->prepare_command)
3723 3724
          {
            lex->param_list.push_back($$=new Item_param());
3725
            lex->param_count++;
unknown's avatar
unknown committed
3726
          }
3727
          else
unknown's avatar
unknown committed
3728 3729 3730 3731
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
unknown's avatar
unknown committed
3732
        };
unknown's avatar
unknown committed
3733 3734 3735 3736
literal:
	text_literal	{ $$ =	$1; }
	| NUM		{ $$ =	new Item_int($1.str, (longlong) atol($1.str),$1.length); }
	| LONG_NUM	{ $$ =	new Item_int($1.str); }
unknown's avatar
unknown committed
3737
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
unknown's avatar
unknown committed
3738 3739 3740 3741
	| REAL_NUM	{ $$ =	new Item_real($1.str, $1.length); }
	| FLOAT_NUM	{ $$ =	new Item_float($1.str, $1.length); }
	| NULL_SYM	{ $$ =	new Item_null();
			  Lex->next_state=STATE_OPERATOR_OR_IDENT;}
3742
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
unknown's avatar
unknown committed
3743 3744
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
3745
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
3746 3747 3748 3749 3750 3751 3752

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

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
3753
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
3754 3755

table_wild:
3756 3757 3758 3759 3760
	ident '.' '*' 
	{
	  $$ = new Item_field(NullS,$1.str,"*");
	  Lex->current_select->select_lex()->with_wild++;
	}
unknown's avatar
unknown committed
3761
	| ident '.' ident '.' '*'
3762 3763 3764 3765 3766 3767 3768
	{
	  $$ = 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
3769 3770

order_ident:
unknown's avatar
unknown committed
3771
	expr { $$=$1; };
unknown's avatar
unknown committed
3772 3773 3774

simple_ident:
	ident
unknown's avatar
unknown committed
3775
	{
3776 3777
	  SELECT_LEX_NODE *sel=Select;
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,NullS,$1.str) : (Item*) new Item_ref(NullS,NullS,$1.str);
unknown's avatar
unknown committed
3778
	}
unknown's avatar
unknown committed
3779
	| ident '.' ident
unknown's avatar
unknown committed
3780
	{
unknown's avatar
unknown committed
3781 3782 3783 3784 3785 3786 3787 3788 3789
	  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);
	  }
3790
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str);
unknown's avatar
unknown committed
3791
	}
unknown's avatar
unknown committed
3792
	| '.' ident '.' ident
unknown's avatar
unknown committed
3793
	{
unknown's avatar
unknown committed
3794 3795 3796 3797 3798 3799 3800 3801 3802
	  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);
	  }
3803
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str);
unknown's avatar
unknown committed
3804
	}
unknown's avatar
unknown committed
3805
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
3806
	{
unknown's avatar
unknown committed
3807 3808 3809 3810 3811 3812 3813 3814 3815
	  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);
	  }
3816
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str);
unknown's avatar
unknown committed
3817
	};
unknown's avatar
unknown committed
3818 3819 3820 3821 3822


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
unknown's avatar
unknown committed
3823
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
3824 3825 3826 3827

table_ident:
	ident			{ $$=new Table_ident($1); }
	| ident '.' ident	{ $$=new Table_ident($1,$3,0);}
unknown's avatar
unknown committed
3828 3829
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
unknown's avatar
unknown committed
3830 3831 3832 3833 3834

ident:
	IDENT	    { $$=$1; }
	| keyword
	{
3835 3836
	  LEX *lex= Lex;
	  $$.str= lex->thd->strmake($1.str,$1.length);
unknown's avatar
unknown committed
3837
	  $$.length=$1.length;
3838
	  if (lex->next_state != STATE_END)
unknown's avatar
unknown committed
3839
	    lex->next_state=STATE_OPERATOR_OR_IDENT;
3840 3841
	}
	;
unknown's avatar
unknown committed
3842 3843 3844

ident_or_text:
	ident 		{ $$=$1;}
unknown's avatar
unknown committed
3845
	| TEXT_STRING	{ $$=$1;}
unknown's avatar
unknown committed
3846
	| LEX_HOSTNAME	{ $$=$1;};
unknown's avatar
unknown committed
3847 3848 3849 3850

user:
	ident_or_text
	{
unknown's avatar
unknown committed
3851 3852
	  THD *thd= YYTHD;
	  if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
3853 3854 3855 3856 3857
	    YYABORT;
	  $$->user = $1; $$->host.str=NullS;
	  }
	| ident_or_text '@' ident_or_text
	  {
unknown's avatar
unknown committed
3858 3859
	    THD *thd= YYTHD;
	    if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
unknown's avatar
unknown committed
3860 3861
	      YYABORT;
	    $$->user = $1; $$->host=$3;
unknown's avatar
unknown committed
3862
	  };
unknown's avatar
unknown committed
3863 3864 3865 3866 3867 3868

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
3869
	| AGAINST		{}
unknown's avatar
unknown committed
3870
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
3871
	| ANY_SYM		{}
unknown's avatar
unknown committed
3872
	| ASCII_SYM		{}
unknown's avatar
unknown committed
3873
	| AUTO_INC		{}
unknown's avatar
unknown committed
3874 3875
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
3876
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
3877
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
3878
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
3879
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
3880 3881
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
3882
	| BOOLEAN_SYM		{}
3883
	| BYTE_SYM		{}
unknown's avatar
unknown committed
3884
	| CACHE_SYM		{}
3885
	| CHANGED		{}
3886
	| CHARSET		{}
unknown's avatar
unknown committed
3887
	| CHECKSUM_SYM		{}
3888
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
3889
	| CLIENT_SYM		{}
3890
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
3891
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
3892
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
3893
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
3894
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
3895
	| CONCURRENT		{}
3896
	| CUBE_SYM		{}
unknown's avatar
unknown committed
3897 3898 3899 3900 3901
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
3902 3903
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
3904
	| DO_SYM		{}
3905
	| DUAL_SYM		{}
unknown's avatar
unknown committed
3906 3907
	| DUMPFILE		{}
	| DUPLICATE_SYM		{}
unknown's avatar
unknown committed
3908 3909 3910 3911
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
3912
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
3913
	| EXECUTE_SYM		{}
unknown's avatar
unknown committed
3914
	| EXTENDED_SYM		{}
3915
	| FAST_SYM		{}
unknown's avatar
unknown committed
3916 3917
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
3918
	| FULL			{}
unknown's avatar
unknown committed
3919 3920 3921 3922
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
unknown's avatar
unknown committed
3923
	| GRANTS		{}
unknown's avatar
unknown committed
3924
	| GLOBAL_SYM		{}
unknown's avatar
unknown committed
3925
	| HEAP_SYM		{}
3926
	| HANDLER_SYM		{}
unknown's avatar
unknown committed
3927 3928 3929
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
3930
	| INDEXES		{}
unknown's avatar
unknown committed
3931
	| ISOLATION		{}
unknown's avatar
unknown committed
3932
	| ISAM_SYM		{}
unknown's avatar
unknown committed
3933
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
3934
	| INNOBASE_SYM		{}
3935
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
3936
	| IO_THREAD		{}
3937
	| LAST_SYM		{}
unknown's avatar
unknown committed
3938
	| LEVEL_SYM		{}
unknown's avatar
unknown committed
3939
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
3940
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
3941 3942 3943 3944 3945 3946 3947 3948 3949 3950
	| 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
3951 3952 3953
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
3954
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
3955 3956 3957 3958
	| MERGE_SYM		{}
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
3959
	| MODE_SYM		{}
unknown's avatar
unknown committed
3960 3961 3962 3963
	| MONTH_SYM		{}
	| MYISAM_SYM		{}
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
3964
	| NEXT_SYM		{}
unknown's avatar
unknown committed
3965
	| NEW_SYM		{}
unknown's avatar
unknown committed
3966
	| NO_SYM		{}
3967
	| NONE_SYM		{}
unknown's avatar
unknown committed
3968
	| OFFSET_SYM		{}
3969
	| OPEN_SYM		{}
unknown's avatar
unknown committed
3970
	| PACK_KEYS_SYM		{}
3971
	| PARTIAL		{}
unknown's avatar
unknown committed
3972
	| PASSWORD		{}
3973
	| PREV_SYM		{}
unknown's avatar
unknown committed
3974 3975
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
3976
	| QUERY_SYM		{}
3977
	| QUICK			{}
unknown's avatar
unknown committed
3978
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
3979 3980
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
3981
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
3982
	| RAID_TYPE		{}
unknown's avatar
unknown committed
3983 3984
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
3985 3986
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
3987
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
3988
	| REPLICATION		{}
unknown's avatar
unknown committed
3989
	| RESET_SYM		{}
3990
	| RESOURCES		{}
unknown's avatar
unknown committed
3991
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
3992
	| ROLLBACK_SYM		{}
3993
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
3994 3995 3996 3997
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
	| SECOND_SYM		{}
3998
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
3999 4000
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
4001
	| SIGNED_SYM		{}
4002
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
4003
	| SHARE_SYM		{}
unknown's avatar
unknown committed
4004
	| SHUTDOWN		{}
unknown's avatar
unknown committed
4005
	| SLAVE			{}
unknown's avatar
unknown committed
4006
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
4007
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
4008
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
4009
	| SQL_THREAD		{}
unknown's avatar
unknown committed
4010 4011 4012 4013
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
unknown's avatar
unknown committed
4014
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
4015
	| SUPER_SYM		{}
unknown's avatar
unknown committed
4016 4017
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
4018
	| TRANSACTION_SYM	{}
4019
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
4020 4021 4022 4023
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
unknown's avatar
unknown committed
4024
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
4025
	| UNICODE_SYM		{}
unknown's avatar
unknown committed
4026
	| USE_FRM		{}
unknown's avatar
unknown committed
4027
	| VARIABLES		{}
4028
	| VALUE_SYM		{}
unknown's avatar
unknown committed
4029
	| WORK_SYM		{}
unknown's avatar
unknown committed
4030
	| YEAR_SYM		{}
unknown's avatar
unknown committed
4031
	| SOUNDS_SYM            {}
unknown's avatar
unknown committed
4032
	;
unknown's avatar
unknown committed
4033 4034 4035 4036 4037 4038

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
4039 4040
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
unknown's avatar
unknown committed
4041 4042
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
unknown's avatar
unknown committed
4043
	}
4044 4045 4046
	option_value_list
	{}
	;
unknown's avatar
unknown committed
4047 4048 4049

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
4050
	| OPTION {};
unknown's avatar
unknown committed
4051 4052

option_value_list:
unknown's avatar
unknown committed
4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064
	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
4065
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4066 4067 4068 4069 4070 4071
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
4072
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
4073 4074 4075
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
4076 4077

option_value:
unknown's avatar
unknown committed
4078
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
4079
	{
unknown's avatar
unknown committed
4080
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
4081
	}
unknown's avatar
unknown committed
4082
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4083
	  {
unknown's avatar
unknown committed
4084 4085
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
unknown's avatar
unknown committed
4086
	  }
unknown's avatar
unknown committed
4087
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
4088 4089 4090 4091 4092 4093 4094 4095
	  {
	    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
4096
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
4097
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
4098
	  }
unknown's avatar
unknown committed
4099
	| CHAR_SYM SET opt_equal set_expr_or_default
unknown's avatar
unknown committed
4100
	{
unknown's avatar
unknown committed
4101 4102 4103 4104
	  LEX *lex=Lex;
	  lex->var_list.push_back(new set_var(lex->option_type,
					      find_sys_var("convert_character_set"),
					      $4));
unknown's avatar
unknown committed
4105 4106
	}
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
4107
	  {
4108
	    THD *thd=YYTHD;
unknown's avatar
unknown committed
4109
	    LEX_USER *user;
unknown's avatar
unknown committed
4110
	    if (!(user=(LEX_USER*) thd->alloc(sizeof(LEX_USER))))
unknown's avatar
unknown committed
4111 4112 4113 4114 4115 4116
	      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
4117
	  {
unknown's avatar
unknown committed
4118 4119
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
4120
	;
unknown's avatar
unknown committed
4121

unknown's avatar
unknown committed
4122 4123 4124 4125 4126 4127 4128 4129
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
4130
        ;
unknown's avatar
unknown committed
4131 4132 4133 4134 4135 4136 4137

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

unknown's avatar
unknown committed
4139 4140 4141 4142 4143 4144 4145 4146
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
	    if (!$3.length)
	      $$=$3.str;
	    else
	    {
unknown's avatar
unknown committed
4147
	      char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
4148 4149
	      make_scrambled_password(buff,$3.str,use_old_passwords,
				      &YYTHD->rand);
unknown's avatar
unknown committed
4150 4151
	      $$=buff;
	    }
4152 4153
	  }
          ;
unknown's avatar
unknown committed
4154

unknown's avatar
unknown committed
4155

unknown's avatar
unknown committed
4156
set_expr_or_default:
unknown's avatar
unknown committed
4157 4158
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
4159 4160
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
4161
	;
unknown's avatar
unknown committed
4162 4163


unknown's avatar
unknown committed
4164 4165 4166 4167 4168 4169 4170
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
4171 4172 4173
	table_lock_list
	{}
	;
unknown's avatar
unknown committed
4174 4175 4176

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
4177
	| TABLES;
unknown's avatar
unknown committed
4178 4179 4180

table_lock_list:
	table_lock
unknown's avatar
unknown committed
4181
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
4182 4183 4184

table_lock:
	table_ident opt_table_alias lock_option
4185
	{
unknown's avatar
unknown committed
4186
	  if (!Select->add_table_to_list(YYTHD, $1, $2, 0, (thr_lock_type) $3))
4187 4188
	   YYABORT;
	}
4189
        ;
unknown's avatar
unknown committed
4190 4191 4192

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
4193
	| WRITE_SYM     { $$=YYTHD->update_lock_default; }
unknown's avatar
unknown committed
4194
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
4195 4196
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
4197 4198

unlock:
4199 4200
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
4201 4202


4203
/*
unknown's avatar
unknown committed
4204
** Handler: direct access to ISAM functions
4205 4206 4207 4208 4209
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
4210 4211
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
unknown's avatar
unknown committed
4212
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, $4, 0))
4213 4214 4215 4216
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
4217 4218
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
unknown's avatar
unknown committed
4219
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4220 4221
	    YYABORT;
	}
unknown's avatar
unknown committed
4222
	| HANDLER_SYM table_ident READ_SYM
4223
	{
unknown's avatar
unknown committed
4224 4225 4226
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
4227 4228
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
unknown's avatar
unknown committed
4229
	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
4230
	    YYABORT;
unknown's avatar
unknown committed
4231
        }
4232
        handler_read_or_scan where_clause opt_limit_clause { }
4233
        ;
4234

unknown's avatar
unknown committed
4235 4236
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
4237 4238
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
4239 4240 4241

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
4242 4243
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
4244 4245 4246 4247 4248 4249

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;  }
4250 4251
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
4252 4253
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
4254
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
4255
	  if (!(lex->insert_list = new List_item))
4256
	    YYABORT;
4257 4258
	} '(' values ')' { }
        ;
4259 4260

handler_rkey_mode:
unknown's avatar
unknown committed
4261 4262 4263 4264
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
4265 4266
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
4267

unknown's avatar
unknown committed
4268 4269 4270 4271 4272
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
4273 4274 4275 4276 4277
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
4278
	  lex->select_lex.db=0;
4279 4280
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4281
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
4282
	}
4283 4284 4285
	grant_privileges ON opt_table FROM user_list
	{}
	;
unknown's avatar
unknown committed
4286 4287 4288 4289

grant:
	GRANT
	{
unknown's avatar
unknown committed
4290 4291 4292
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
4293 4294
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
4295
	  lex->select_lex.db= 0;
4296 4297
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
4298
	  bzero(&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
4299 4300
	}
	grant_privileges ON opt_table TO_SYM user_list
4301 4302 4303
	require_clause grant_options
	{}
	;
unknown's avatar
unknown committed
4304 4305 4306

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
4307
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
4308 4309
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
unknown's avatar
unknown committed
4310 4311 4312

grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
4313
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
4314 4315

grant_privilege:
4316 4317 4318 4319
	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
4320 4321
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
4322 4323 4324 4325
	| 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
4326
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
4327 4328 4329 4330
	| 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
4331 4332 4333 4334 4335 4336 4337 4338
	| 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
4339

unknown's avatar
unknown committed
4340

4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352
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
4353 4354 4355 4356
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
4357
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
4358 4359 4360 4361 4362 4363 4364 4365 4366
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
4367
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
4368 4369 4370 4371 4372 4373 4374 4375 4376
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
4377
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
4378 4379 4380 4381 4382
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
4383

unknown's avatar
unknown committed
4384 4385 4386
opt_table:
	'*'
	  {
4387
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4388
	    lex->current_select->select_lex()->db= lex->thd->db;
unknown's avatar
unknown committed
4389
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4390 4391
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4392
	    {
4393
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
4394
	      YYABORT;
unknown's avatar
unknown committed
4395
	    }
unknown's avatar
unknown committed
4396 4397 4398
	  }
	| ident '.' '*'
	  {
4399
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4400
	    lex->current_select->select_lex()->db = $1.str;
unknown's avatar
unknown committed
4401
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4402 4403
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4404
	    {
4405
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4406 4407 4408 4409 4410
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
4411
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4412
	    lex->current_select->select_lex()->db = NULL;
unknown's avatar
unknown committed
4413 4414
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
4415
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4416
	    {
4417
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4418 4419 4420 4421 4422
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
4423
	    LEX *lex=Lex;
unknown's avatar
unknown committed
4424
	    if (!lex->current_select->add_table_to_list(lex->thd, $1,NULL,0))
unknown's avatar
unknown committed
4425
	      YYABORT;
unknown's avatar
unknown committed
4426
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4427
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
4428 4429
	  }
          ;
unknown's avatar
unknown committed
4430 4431 4432


user_list:
4433 4434 4435 4436 4437 4438 4439
	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
4440 4441 4442 4443 4444 4445 4446 4447


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
unknown's avatar
unknown committed
4448
	     char *buff=(char*) YYTHD->alloc(HASH_PASSWORD_LENGTH+1);
unknown's avatar
unknown committed
4449 4450
	     if (buff)
	     {
4451 4452
	       make_scrambled_password(buff,$4.str,use_old_passwords,
				       &YYTHD->rand);
unknown's avatar
unknown committed
4453 4454 4455 4456 4457 4458 4459 4460
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
4461 4462
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
4463 4464 4465


opt_column_list:
unknown's avatar
unknown committed
4466 4467 4468 4469 4470
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
4471
	| '(' column_list ')';
unknown's avatar
unknown committed
4472 4473 4474

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
4475
	| column_list_id;
unknown's avatar
unknown committed
4476 4477 4478 4479

column_list_id:
	ident
	{
4480
	  String *new_str = new String((const char*) $1.str,$1.length,default_charset_info);
unknown's avatar
unknown committed
4481 4482
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
4483
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4484 4485
	  while ((point=iter++))
	  {
4486 4487
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
4488 4489
		break;
	  }
unknown's avatar
unknown committed
4490
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
4491
	  if (point)
unknown's avatar
unknown committed
4492
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
4493
	  else
unknown's avatar
unknown committed
4494
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
4495 4496
	}
        ;
unknown's avatar
unknown committed
4497

unknown's avatar
unknown committed
4498 4499

require_clause: /* empty */
4500
        | REQUIRE_SYM require_list
4501 4502 4503
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
4504
        | REQUIRE_SYM SSL_SYM
4505 4506 4507
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
4508
        | REQUIRE_SYM X509_SYM
4509 4510 4511 4512 4513 4514 4515
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
4516
          ;
unknown's avatar
unknown committed
4517

unknown's avatar
unknown committed
4518
grant_options:
unknown's avatar
unknown committed
4519
	/* empty */ {}
unknown's avatar
unknown committed
4520
	| WITH grant_option_list;
unknown's avatar
unknown committed
4521

unknown's avatar
unknown committed
4522 4523
grant_option_list:
	grant_option_list grant_option {}
4524 4525
	| grant_option {}
        ;
unknown's avatar
unknown committed
4526 4527 4528

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
4529
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
4530
        {
4531
	  Lex->mqh.questions=$2;
4532
	  Lex->mqh.bits |= 1;
4533
	}
4534
        | MAX_UPDATES_PER_HOUR ULONG_NUM
4535
        {
4536
	  Lex->mqh.updates=$2;
4537
	  Lex->mqh.bits |= 2;
4538
	}
4539
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
4540
        {
4541
	  Lex->mqh.connections=$2;
4542
	  Lex->mqh.bits |= 4;
4543 4544
	}
        ;
4545

unknown's avatar
unknown committed
4546
begin:
4547 4548
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work {}
	;
unknown's avatar
unknown committed
4549 4550 4551

opt_work:
	/* empty */ {}
4552 4553
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
4554 4555

commit:
unknown's avatar
unknown committed
4556
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
4557 4558

rollback:
unknown's avatar
unknown committed
4559
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
4560 4561 4562


/*
unknown's avatar
unknown committed
4563
   UNIONS : glue selects together
4564 4565 4566
*/


4567
union_clause:
4568
	/* empty */ {}
unknown's avatar
unknown committed
4569 4570
	| union_list
	;
4571 4572

union_list:
unknown's avatar
unknown committed
4573
	UNION_SYM    union_option
4574 4575 4576 4577 4578
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
4579
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
4580
	    YYABORT;
4581
	  }
4582
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4583
	  {
4584
	    send_error(lex->thd, ER_SYNTAX_ERROR);
4585 4586
	    YYABORT;
	  }
4587
	  if (mysql_new_select(lex, 0))
4588
	    YYABORT;
4589
	  lex->current_select->linkage=UNION_TYPE;
unknown's avatar
unknown committed
4590
	}
4591
	select_init {}
4592
	;
4593 4594

union_opt:
unknown's avatar
unknown committed
4595
	union_list {}
unknown's avatar
unknown committed
4596 4597
	| optional_order_or_limit {}
	;
4598 4599

optional_order_or_limit:
4600
      	/* Empty */ {}
4601 4602
	|
	  {
unknown's avatar
unknown committed
4603 4604
	    THD *thd= YYTHD;
	    LEX *lex= &thd->lex;
unknown's avatar
unknown committed
4605
	    DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
unknown's avatar
unknown committed
4606
	    SELECT_LEX *sel= lex->current_select->select_lex();
4607
	    sel->master_unit()->global_parameters=
4608 4609 4610 4611
	      sel->master_unit();
	    lex->current_select= sel->master_unit();
	    lex->current_select->select_limit=
	      lex->thd->variables.select_limit;
unknown's avatar
unknown committed
4612 4613
	    lex->current_select->no_table_names_allowed= 1;
	    thd->where= "global ORDER clause";
4614
	  }
4615
	order_or_limit
unknown's avatar
unknown committed
4616 4617 4618 4619 4620
          {
	    THD *thd= YYTHD;
	    thd->lex.current_select->no_table_names_allowed= 0;
	    thd->where= "";
          }
4621 4622 4623 4624 4625 4626
	;

order_or_limit:
	order_clause opt_limit_clause
	|
	limit_clause
4627
	;
unknown's avatar
unknown committed
4628 4629

union_option:
4630
	/* empty */ {}
unknown's avatar
unknown committed
4631
	| ALL {Select->master_unit()->union_option= 1;};
4632

unknown's avatar
unknown committed
4633 4634
singlerow_subselect:
	subselect_start singlerow_subselect_init
unknown's avatar
unknown committed
4635 4636 4637 4638
	subselect_end
	{
	  $$= $2;
	};
4639

unknown's avatar
unknown committed
4640
singlerow_subselect_init:
4641
	select_init2
unknown's avatar
unknown committed
4642
	{
unknown's avatar
unknown committed
4643
	  $$= new Item_singlerow_subselect(YYTHD,
4644 4645
					   Lex->current_select->master_unit()->
                                             first_select());
unknown's avatar
unknown committed
4646
	};
unknown's avatar
unknown committed
4647 4648

exists_subselect:
unknown's avatar
unknown committed
4649 4650 4651 4652 4653
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
4654 4655

exists_subselect_init:
4656
	select_init2
unknown's avatar
unknown committed
4657
	{
4658
	  $$= new Item_exists_subselect(YYTHD,
4659 4660
					Lex->current_select->master_unit()->
					  first_select());
unknown's avatar
unknown committed
4661
	};
4662

unknown's avatar
unknown committed
4663 4664 4665 4666 4667 4668 4669 4670
in_subselect:
  subselect_start in_subselect_init
  subselect_end
  {
    $$= $2;
  };

in_subselect_init:
4671
  select_init2
unknown's avatar
unknown committed
4672
  {
unknown's avatar
unknown committed
4673
    $$= Lex->current_select->master_unit()->first_select();
unknown's avatar
unknown committed
4674 4675
  };

4676
subselect_start:
4677
	'(' SELECT_SYM
unknown's avatar
unknown committed
4678
	{
4679
	  LEX *lex=Lex;
4680
	  if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN &&
4681 4682 4683 4684
	       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
4685 4686 4687
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
4688 4689

subselect_end:
unknown's avatar
unknown committed
4690 4691 4692
	')'
	{
	  LEX *lex=Lex;
4693
	  lex->current_select = lex->current_select->outer_select();
unknown's avatar
unknown committed
4694
	};