sql_yacc.yy 108 KB
Newer Older
unknown's avatar
unknown committed
1
/* Copyright (C) 2000-2001 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 23

%{
#define MYSQL_YACC
#define YYINITDEPTH 100
#define YYMAXDEPTH 3200				/* Because of 64K stack */
#define Lex current_lex
24
#define Select Lex->current_select
unknown's avatar
unknown committed
25
#include "mysql_priv.h"
unknown's avatar
unknown committed
26
#include "slave.h"
unknown's avatar
unknown committed
27 28
#include "sql_acl.h"
#include "lex_symbol.h"
29
#include "item_create.h"
unknown's avatar
unknown committed
30
#include <myisam.h>
31
#include <myisammrg.h>
32

unknown's avatar
unknown committed
33 34 35
extern void yyerror(const char*);
int yylex(void *yylval);

unknown's avatar
unknown committed
36
#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
37 38 39

inline Item *or_or_concat(Item* A, Item* B)
{
40
  return (current_thd->sql_mode & MODE_PIPES_AS_CONCAT ?
unknown's avatar
unknown committed
41 42 43 44 45 46 47
          (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
48
  ulonglong ulonglong_number;
unknown's avatar
unknown committed
49 50 51 52 53 54 55 56
  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
57 58 59 60 61 62
  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
63
  Key::Keytype key_type;
unknown's avatar
unknown committed
64
  enum ha_key_alg  key_alg;
unknown's avatar
unknown committed
65 66
  enum db_type db_type;
  enum row_type row_type;
unknown's avatar
unknown committed
67
  enum ha_rkey_function ha_rkey_mode;
unknown's avatar
unknown committed
68
  enum enum_tx_isolation tx_isolation;
unknown's avatar
unknown committed
69
  enum Item_cast cast_type;
unknown's avatar
unknown committed
70
  enum Item_udftype udf_type;
71
  CHARSET_INFO *charset;
unknown's avatar
unknown committed
72
  interval_type interval;
unknown's avatar
unknown committed
73 74 75 76 77 78 79 80 81 82
}

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

%pure_parser					/* We have threads */

%token	END_OF_INPUT

83 84 85 86 87 88
%token CLOSE_SYM
%token HANDLER_SYM
%token LAST_SYM
%token NEXT_SYM
%token PREV_SYM

89
%token	DIV_SYM
unknown's avatar
unknown committed
90 91 92 93 94 95 96 97
%token	EQ
%token	EQUAL_SYM
%token	GE
%token	GT_SYM
%token	LE
%token	LT
%token	NE
%token	IS
98
%token	MOD_SYM
unknown's avatar
unknown committed
99 100 101 102
%token	SHIFT_LEFT
%token	SHIFT_RIGHT
%token  SET_VAR

unknown's avatar
unknown committed
103
%token	ABORT_SYM
unknown's avatar
unknown committed
104 105
%token	ADD
%token	AFTER_SYM
unknown's avatar
unknown committed
106 107 108 109 110
%token	ALTER
%token	ANALYZE_SYM
%token	AVG_SYM
%token	BEGIN_SYM
%token	BINLOG_SYM
unknown's avatar
unknown committed
111
%token	CHANGE
unknown's avatar
unknown committed
112 113 114 115
%token	CLIENT_SYM
%token	COMMENT_SYM
%token	COMMIT_SYM
%token	COUNT_SYM
unknown's avatar
unknown committed
116 117
%token	CREATE
%token	CROSS
118
%token  CUBE_SYM
unknown's avatar
unknown committed
119
%token	DELETE_SYM
120
%token	DUAL_SYM
unknown's avatar
unknown committed
121
%token	DO_SYM
unknown's avatar
unknown committed
122
%token	DROP
unknown's avatar
unknown committed
123 124
%token	EVENTS_SYM
%token	EXECUTE_SYM
unknown's avatar
unknown committed
125
%token	FLUSH_SYM
unknown's avatar
unknown committed
126 127
%token	INSERT
%token	IO_THREAD
unknown's avatar
unknown committed
128 129
%token	KILL_SYM
%token	LOAD
unknown's avatar
unknown committed
130
%token	LOCKS_SYM
unknown's avatar
unknown committed
131 132 133 134
%token	LOCK_SYM
%token	MASTER_SYM
%token	MAX_SYM
%token	MIN_SYM
135
%token	NONE_SYM
unknown's avatar
unknown committed
136 137 138 139 140 141
%token	OPTIMIZE
%token	PURGE
%token	REPAIR
%token	REPLICATION
%token	RESET_SYM
%token	ROLLBACK_SYM
142
%token  ROLLUP_SYM
unknown's avatar
unknown committed
143 144 145 146 147 148 149 150 151 152
%token	SELECT_SYM
%token	SHOW
%token	SLAVE
%token	SQL_THREAD
%token	START_SYM
%token	STD_SYM
%token	STOP_SYM
%token	SUM_SYM
%token	SUPER_SYM
%token	TRUNCATE_SYM
unknown's avatar
unknown committed
153
%token	UNLOCK_SYM
unknown's avatar
unknown committed
154
%token	UPDATE_SYM
unknown's avatar
unknown committed
155 156 157 158 159 160 161

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

unknown's avatar
unknown committed
369 370 371
%token  ERRORS
%token  WARNINGS

unknown's avatar
unknown committed
372 373 374
%token	BIGINT
%token	BLOB_SYM
%token	CHAR_SYM
unknown's avatar
unknown committed
375
%token	CHANGED
unknown's avatar
unknown committed
376 377 378 379 380 381
%token	COALESCE
%token	DATETIME
%token	DATE_SYM
%token	DECIMAL_SYM
%token	DOUBLE_SYM
%token	ENUM
382
%token	FAST_SYM
unknown's avatar
unknown committed
383
%token	FLOAT_SYM
unknown's avatar
unknown committed
384
%token  GEOMETRY_SYM
unknown's avatar
unknown committed
385 386 387 388 389 390 391 392 393
%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
394
%token	QUICK
unknown's avatar
unknown committed
395
%token	REAL
unknown's avatar
unknown committed
396
%token	SIGNED_SYM
unknown's avatar
unknown committed
397 398 399 400 401 402 403 404
%token	SMALLINT
%token	STRING_SYM
%token	TEXT_SYM
%token	TIMESTAMP
%token	TIME_SYM
%token	TINYBLOB
%token	TINYINT
%token	TINYTEXT
unknown's avatar
unknown committed
405
%token	ULONGLONG_NUM
unknown's avatar
unknown committed
406
%token	UNSIGNED
407 408 409
%token	VARBINARY
%token	VARCHAR
%token	VARYING
unknown's avatar
unknown committed
410 411
%token	ZEROFILL

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

unknown's avatar
unknown committed
505 506 507 508
%token	SQL_BIG_RESULT
%token	SQL_CACHE_SYM
%token	SQL_CALC_FOUND_ROWS
%token	SQL_NO_CACHE_SYM
unknown's avatar
unknown committed
509
%token	SQL_SMALL_RESULT
unknown's avatar
unknown committed
510
%token  SQL_BUFFER_RESULT
unknown's avatar
unknown committed
511

unknown's avatar
unknown committed
512 513
%token  ISSUER_SYM
%token  SUBJECT_SYM
514
%token  CIPHER_SYM
unknown's avatar
unknown committed
515

unknown's avatar
unknown committed
516 517
%token  HELP

unknown's avatar
unknown committed
518 519 520 521 522 523 524 525 526
%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	'-' '+'
527
%left	'*' '/' '%' DIV_SYM MOD_SYM
unknown's avatar
unknown committed
528
%left	NEG '~'
unknown's avatar
unknown committed
529 530
%left   XOR
%left   '^'
unknown's avatar
unknown committed
531
%right	NOT
unknown's avatar
unknown committed
532
%right	BINARY COLLATE_SYM
533 534 535 536 537 538
/* 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
539 540
%type <lex_str>
	IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
unknown's avatar
unknown committed
541
	ULONGLONG_NUM field_ident select_alias ident ident_or_text  UNDERSCORE_CHARSET
unknown's avatar
unknown committed
542 543 544 545 546

%type <lex_str_ptr>
	opt_table_alias

%type <table>
547
	table_ident references
unknown's avatar
unknown committed
548 549

%type <simple_string>
550
	remember_name remember_end opt_ident opt_db text_or_password
unknown's avatar
unknown committed
551 552 553
	opt_escape

%type <string>
unknown's avatar
unknown committed
554
	text_string 
unknown's avatar
unknown committed
555 556

%type <num>
unknown's avatar
unknown committed
557
	type int_type real_type order_dir opt_field_spec lock_option
unknown's avatar
unknown committed
558
	udf_type if_exists opt_local opt_table_options table_options
unknown's avatar
unknown committed
559
	table_option opt_if_not_exists opt_var_type opt_var_ident_type
unknown's avatar
unknown committed
560
	delete_option opt_with_if_not_exists
unknown's avatar
unknown committed
561 562

%type <ulong_num>
563
	ULONG_NUM raid_types merge_insert_types
unknown's avatar
unknown committed
564

unknown's avatar
unknown committed
565 566
%type <ulonglong_number>
	ulonglong_num
unknown's avatar
unknown committed
567 568

%type <item>
unknown's avatar
unknown committed
569
	literal text_literal insert_ident order_ident
unknown's avatar
unknown committed
570 571
	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
unknown's avatar
unknown committed
572
	using_list expr_or_default set_expr_or_default
unknown's avatar
unknown committed
573
	param_marker singleval_subselect singleval_subselect_init
unknown's avatar
unknown committed
574
	exists_subselect exists_subselect_init
unknown's avatar
unknown committed
575 576

%type <item_list>
unknown's avatar
unknown committed
577
	expr_list udf_expr_list when_list ident_list ident_list_arg
unknown's avatar
unknown committed
578 579

%type <key_type>
580
	key_type opt_unique_or_fulltext
unknown's avatar
unknown committed
581

unknown's avatar
unknown committed
582 583 584
%type <key_alg>
	key_alg opt_btree_or_rtree

unknown's avatar
unknown committed
585 586 587 588 589 590 591
%type <string_list>
	key_usage_list

%type <key_part>
	key_part

%type <table_list>
592
	join_table_list  join_table
unknown's avatar
unknown committed
593 594 595 596 597 598 599 600 601 602 603

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

unknown's avatar
unknown committed
606 607
%type <ha_rkey_mode> handler_rkey_mode

unknown's avatar
unknown committed
608 609
%type <cast_type> cast_type

unknown's avatar
unknown committed
610 611 612 613 614 615
%type <udf_type> udf_func_type

%type <symbol> FUNC_ARG0 FUNC_ARG1 FUNC_ARG2 FUNC_ARG3 keyword

%type <lex_user> user grant_user

616 617 618 619 620
%type <charset> 
	charset_name
	charset_name_or_default
	opt_db_default_character_set

unknown's avatar
unknown committed
621 622
%type <variable> internal_variable_name

unknown's avatar
unknown committed
623
%type <NONE>
unknown's avatar
unknown committed
624
	query verb_clause create change select do drop insert replace insert2
625 626
	insert_values update delete truncate rename
	show describe load alter optimize flush
unknown's avatar
unknown committed
627
	reset purge begin commit rollback slave master_def master_defs
628
	repair restore backup analyze check 
629
	field_list field_list_item field_spec kill
unknown's avatar
unknown committed
630 631 632
	select_item_list select_item values_list no_braces
	limit_clause delete_limit_clause fields opt_values values
	procedure_list procedure_list2 procedure_item
633
	when_list2 expr_list2  handler
unknown's avatar
unknown committed
634 635 636
	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
637
	ref_list opt_on_delete opt_on_delete_list opt_on_delete_item use
638
	opt_delete_options opt_delete_option
639
	opt_outer table_list table_name opt_option opt_place opt_low_priority
unknown's avatar
unknown committed
640 641
	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
642
	grant_privilege grant_privilege_list
unknown's avatar
unknown committed
643 644 645
	flush_options flush_option insert_lock_option replace_lock_option
	equal optional_braces opt_key_definition key_usage_list2
	opt_mi_check_type opt_to mi_check_types normal_join
646
	table_to_table_list table_to_table opt_table_list opt_as
unknown's avatar
unknown committed
647
	handler_rkey_function handler_read_or_scan
unknown's avatar
unknown committed
648
	single_multi table_wild_list table_wild_one opt_wild union union_list
unknown's avatar
unknown committed
649
	precision union_option opt_on_delete_item subselect_start opt_and
650
	subselect_end select_var_list select_var_list_init help opt_len
651
END_OF_INPUT
unknown's avatar
unknown committed
652 653 654

%type <NONE>
	'-' '+' '*' '/' '%' '(' ')'
655 656
	',' '!' '{' '}' '&' '|' AND OR OR_OR_CONCAT BETWEEN_SYM CASE_SYM
	THEN_SYM WHEN_SYM DIV_SYM MOD_SYM
unknown's avatar
unknown committed
657 658 659 660 661
%%


query:
	END_OF_INPUT
unknown's avatar
unknown committed
662
	{
663 664
	   THD *thd=current_thd;
	   if (!thd->bootstrap &&
unknown's avatar
unknown committed
665
	      (!(thd->lex.select_lex.options & OPTION_FOUND_COMMENT)))
666
	   {
667
	     send_error(current_thd,ER_EMPTY_QUERY);
668 669 670 671 672 673
	     YYABORT;
 	   }
	   else
	   {
	     thd->lex.sql_command = SQLCOM_EMPTY_QUERY;
	   }
unknown's avatar
unknown committed
674
	}
unknown's avatar
unknown committed
675
	| verb_clause END_OF_INPUT {};
unknown's avatar
unknown committed
676 677 678 679

verb_clause:
	  alter
	| analyze
680
	| backup
unknown's avatar
unknown committed
681 682 683 684 685 686 687
	| begin
	| change
	| check
	| commit
	| create
	| delete
	| describe
unknown's avatar
unknown committed
688
	| do
unknown's avatar
unknown committed
689 690 691 692 693 694 695 696
	| drop
	| grant
	| insert
	| flush
	| load
	| lock
	| kill
	| optimize
unknown's avatar
unknown committed
697
	| purge  
698
	| rename
unknown's avatar
unknown committed
699 700
        | repair
	| replace
unknown's avatar
unknown committed
701
	| reset
702
	| restore
unknown's avatar
unknown committed
703 704 705 706
	| revoke
	| rollback
	| select
	| set
unknown's avatar
unknown committed
707
	| slave
unknown's avatar
unknown committed
708
	| show
709
	| truncate
710
	| handler
unknown's avatar
unknown committed
711 712
	| unlock
	| update
unknown's avatar
unknown committed
713 714 715 716 717 718 719 720 721 722 723
	| use
	| help;
	
/* help */

help: 
       HELP TEXT_STRING
       {
       LEX *lex= Lex;
       lex->sql_command= SQLCOM_HELP;
       lex->help_arg= $2.str;
724
       };
unknown's avatar
unknown committed
725 726 727 728

/* change master */

change:
unknown's avatar
unknown committed
729
       CHANGE MASTER_SYM TO_SYM
unknown's avatar
unknown committed
730 731 732 733
        {
	  LEX *lex = Lex;
	  lex->sql_command = SQLCOM_CHANGE_MASTER;
	  memset(&lex->mi, 0, sizeof(lex->mi));
unknown's avatar
unknown committed
734
        } master_defs;
unknown's avatar
unknown committed
735 736 737

master_defs:
       master_def
unknown's avatar
unknown committed
738
       | master_defs ',' master_def;
unknown's avatar
unknown committed
739

unknown's avatar
unknown committed
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
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
761
       MASTER_PORT_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
762 763 764 765
       {
	 Lex->mi.port = $3;
       }
       |
unknown's avatar
unknown committed
766
       MASTER_LOG_POS_SYM EQ ulonglong_num
unknown's avatar
unknown committed
767 768 769 770
       {
	 Lex->mi.pos = $3;
       }
       |
unknown's avatar
unknown committed
771
       MASTER_CONNECT_RETRY_SYM EQ ULONG_NUM
unknown's avatar
unknown committed
772 773 774
       {
	 Lex->mi.connect_retry = $3;
       }
775 776 777 778 779 780 781 782 783
       |
       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;
784 785
       }
       ;
unknown's avatar
unknown committed
786

unknown's avatar
unknown committed
787

unknown's avatar
unknown committed
788 789 790 791 792
/* create a table */

create:
	CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
	{
793
	  THD *thd=current_thd;
unknown's avatar
unknown committed
794 795
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_CREATE_TABLE;
796 797 798 799 800
	  if (!lex->select_lex.add_table_to_list($5,
			 			 ($2 &
						  HA_LEX_CREATE_TMP_TABLE ?
						  &tmp_table_alias :
						  (LEX_STRING*) 0),1))
unknown's avatar
unknown committed
801 802 803 804 805 806 807
	    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
808
	  lex->create_info.db_type= (enum db_type) lex->thd->variables.table_type;
809
	  lex->create_info.table_charset=thd->db_charset?thd->db_charset:default_charset_info;
unknown's avatar
unknown committed
810 811 812
	}
	create2

unknown's avatar
unknown committed
813
	| CREATE opt_unique_or_fulltext INDEX ident key_alg ON table_ident
unknown's avatar
unknown committed
814
	  {
unknown's avatar
unknown committed
815 816
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_CREATE_INDEX;
817
	    if (!lex->current_select->add_table_to_list($7,NULL,1))
unknown's avatar
unknown committed
818
	      YYABORT;
unknown's avatar
unknown committed
819 820 821 822
	    lex->create_list.empty();
	    lex->key_list.empty();
	    lex->col_list.empty();
	    lex->change=NullS;
unknown's avatar
unknown committed
823
	  }
unknown's avatar
unknown committed
824
	   '(' key_list ')' 
unknown's avatar
unknown committed
825
	  {
unknown's avatar
unknown committed
826
	    LEX *lex=Lex;
unknown's avatar
unknown committed
827

828
	    lex->key_list.push_back(new Key($2,$4.str, $5, lex->col_list));
unknown's avatar
unknown committed
829
	    lex->col_list.empty();
unknown's avatar
unknown committed
830
	  }
831
	| CREATE DATABASE opt_if_not_exists ident opt_db_default_character_set
unknown's avatar
unknown committed
832
	  {
unknown's avatar
unknown committed
833 834 835 836
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_CREATE_DB;
	    lex->name=$4.str;
            lex->create_info.options=$3;
837
	    lex->create_info.table_charset=$5;
unknown's avatar
unknown committed
838 839 840
	  }
	| CREATE udf_func_type UDF_SYM ident
	  {
unknown's avatar
unknown committed
841 842 843 844 845
	    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
846 847 848
	  }
	  UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
	  {
unknown's avatar
unknown committed
849 850 851
	    LEX *lex=Lex;
	    lex->udf.returns=(Item_result) $7;
	    lex->udf.dl=$9.str;
852 853
	  }
          ;
unknown's avatar
unknown committed
854 855

create2:
unknown's avatar
unknown committed
856
	'(' field_list ')' opt_create_table_options create3 {}
857 858
	| opt_create_table_options create3 {}
        ;
unknown's avatar
unknown committed
859 860

create3:
861 862
	/* empty */ {}
	| opt_duplicate opt_as SELECT_SYM
unknown's avatar
unknown committed
863
          {
unknown's avatar
unknown committed
864 865 866
	    LEX *lex=Lex;
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
	    mysql_init_select(lex);
unknown's avatar
unknown committed
867
          }
868 869
          select_options select_item_list opt_select_from union {}
          ;
unknown's avatar
unknown committed
870

871 872
opt_as:
	/* empty */ {}
unknown's avatar
unknown committed
873
	| AS	    {};
874

unknown's avatar
unknown committed
875
opt_table_options:
unknown's avatar
unknown committed
876
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
877
	| table_options  { $$= $1;};
unknown's avatar
unknown committed
878 879 880

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

unknown's avatar
unknown committed
883
table_option:
unknown's avatar
unknown committed
884
	TEMPORARY	{ $$=HA_LEX_CREATE_TMP_TABLE; };
unknown's avatar
unknown committed
885 886

opt_if_not_exists:
unknown's avatar
unknown committed
887
	/* empty */	 { $$= 0; }
unknown's avatar
unknown committed
888
	| IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };
unknown's avatar
unknown committed
889

unknown's avatar
unknown committed
890 891 892 893
opt_with_if_not_exists:
	/* empty */	 { $$= 0; }
	| WITH IF NOT EXISTS	 { $$=HA_LEX_CREATE_IF_NOT_EXISTS; };

unknown's avatar
unknown committed
894 895
opt_create_table_options:
	/* empty */
unknown's avatar
unknown committed
896
	| create_table_options;
unknown's avatar
unknown committed
897

unknown's avatar
unknown committed
898 899 900 901
create_table_options_space_separated:
	create_table_option
	| create_table_option create_table_options_space_separated;

unknown's avatar
unknown committed
902 903
create_table_options:
	create_table_option
unknown's avatar
unknown committed
904 905
	| create_table_option     create_table_options;
	| create_table_option ',' create_table_options;
unknown's avatar
unknown committed
906

unknown's avatar
unknown committed
907 908 909 910
o_eq:
	/* empty */
	| EQ		{};

unknown's avatar
unknown committed
911
create_table_option:
unknown's avatar
unknown committed
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
	TYPE_SYM o_eq table_types	{ Lex->create_info.db_type= $3; }
	| MAX_ROWS o_eq ulonglong_num	{ Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;}
	| MIN_ROWS o_eq ulonglong_num	{ Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;}
	| AVG_ROW_LENGTH o_eq ULONG_NUM	{ Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;}
	| PASSWORD o_eq TEXT_STRING	{ Lex->create_info.password=$3.str; }
	| COMMENT_SYM o_eq TEXT_STRING	{ Lex->create_info.comment=$3.str; }
	| AUTO_INC o_eq ulonglong_num	{ Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;}
	| PACK_KEYS_SYM o_eq 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 o_eq 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 o_eq ULONG_NUM	{ Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; }
	| DELAY_KEY_WRITE_SYM o_eq ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; }
	| ROW_FORMAT_SYM o_eq row_types	{ Lex->create_info.row_type= $3; }
	| RAID_TYPE o_eq raid_types	{ Lex->create_info.raid_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKS o_eq ULONG_NUM	{ Lex->create_info.raid_chunks= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| RAID_CHUNKSIZE o_eq ULONG_NUM	{ Lex->create_info.raid_chunksize= $3*RAID_BLOCK_SIZE; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;}
	| UNION_SYM o_eq '(' table_list ')'
928 929 930
	  {
	    /* Move the union list to the merge_list */
	    LEX *lex=Lex;
931 932
	    TABLE_LIST *table_list= lex->select_lex.get_table_list();
	    lex->create_info.merge_list= lex->select_lex.table_list;
933 934
	    lex->create_info.merge_list.elements--;
	    lex->create_info.merge_list.first= (byte*) (table_list->next);
935 936
	    lex->select_lex.table_list.elements=1;
	    lex->select_lex.table_list.next= (byte**) &(table_list->next);
937
	    table_list->next=0;
938
	    lex->create_info.used_fields|= HA_CREATE_USED_UNION;
939
	  }
940
	| opt_default CHARSET o_eq charset_name_or_default
941
	  { 
942 943 944 945 946 947
	    Lex->create_info.table_charset= $4;
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
	| opt_default CHAR_SYM SET o_eq charset_name_or_default
	  { 
	    Lex->create_info.table_charset= $5;
948 949
	    Lex->create_info.used_fields|= HA_CREATE_USED_CHARSET;
	  }
unknown's avatar
unknown committed
950 951 952
	| INSERT_METHOD o_eq merge_insert_types   { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;}
	| DATA_SYM DIRECTORY_SYM o_eq TEXT_STRING { Lex->create_info.data_file_name= $4.str; }
	| INDEX DIRECTORY_SYM o_eq TEXT_STRING	  { Lex->create_info.index_file_name= $4.str; };
unknown's avatar
unknown committed
953 954 955 956 957 958 959

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
960
	| INNOBASE_SYM  { $$= DB_TYPE_INNODB; };
unknown's avatar
unknown committed
961 962 963 964 965

row_types:
	DEFAULT		{ $$= ROW_TYPE_DEFAULT; }
	| FIXED_SYM	{ $$= ROW_TYPE_FIXED; }
	| DYNAMIC_SYM	{ $$= ROW_TYPE_DYNAMIC; }
unknown's avatar
unknown committed
966
	| COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; };
unknown's avatar
unknown committed
967 968 969 970

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

973 974 975
merge_insert_types:
       NO_SYM            { $$= MERGE_INSERT_DISABLED; }
       | FIRST_SYM       { $$= MERGE_INSERT_TO_FIRST; }
unknown's avatar
unknown committed
976
       | LAST_SYM        { $$= MERGE_INSERT_TO_LAST; };
977

unknown's avatar
unknown committed
978 979
opt_select_from:
	/* empty */
unknown's avatar
unknown committed
980
	| select_from select_lock_type;
unknown's avatar
unknown committed
981 982 983

udf_func_type:
	/* empty */ 	{ $$ = UDFTYPE_FUNCTION; }
unknown's avatar
unknown committed
984
	| AGGREGATE_SYM { $$ = UDFTYPE_AGGREGATE; };
unknown's avatar
unknown committed
985 986 987 988

udf_type:
	STRING_SYM {$$ = (int) STRING_RESULT; }
	| REAL {$$ = (int) REAL_RESULT; }
unknown's avatar
unknown committed
989
	| INT_SYM {$$ = (int) INT_RESULT; };
unknown's avatar
unknown committed
990 991 992

field_list:
	  field_list_item
unknown's avatar
unknown committed
993
	| field_list ',' field_list_item;
unknown's avatar
unknown committed
994 995 996 997 998 999 1000 1001


field_list_item:
	  field_spec
	| field_spec references
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
	  }
unknown's avatar
unknown committed
1002
	| key_type opt_ident key_alg '(' key_list ')'
unknown's avatar
unknown committed
1003
	  {
unknown's avatar
unknown committed
1004
	    LEX *lex=Lex;
1005
	    lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
unknown's avatar
unknown committed
1006
	    lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1007
	  }
1008
	| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
unknown's avatar
unknown committed
1009
	  {
1010 1011 1012 1013 1014 1015 1016 1017
	    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
1018 1019 1020 1021
	  }
	| opt_constraint CHECK_SYM '(' expr ')'
	  {
	    Lex->col_list.empty();		/* Alloced by sql_alloc */
unknown's avatar
unknown committed
1022
	  };
unknown's avatar
unknown committed
1023 1024 1025

opt_constraint:
	/* empty */
unknown's avatar
unknown committed
1026
	| CONSTRAINT opt_ident;
unknown's avatar
unknown committed
1027 1028 1029 1030

field_spec:
	field_ident
	 {
unknown's avatar
unknown committed
1031 1032
	   LEX *lex=Lex;
	   lex->length=lex->dec=0; lex->type=0; lex->interval=0;
1033
	   lex->default_value=lex->comment=0;
1034
	   lex->charset=NULL;
unknown's avatar
unknown committed
1035 1036 1037
	 }
	type opt_attribute
	{
unknown's avatar
unknown committed
1038
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1039 1040
	  if (add_field_to_list($1.str,
				(enum enum_field_types) $3,
unknown's avatar
unknown committed
1041
				lex->length,lex->dec,lex->type,
1042
				lex->default_value, lex->comment,
1043
				lex->change,lex->interval,lex->charset))
unknown's avatar
unknown committed
1044
	    YYABORT;
unknown's avatar
unknown committed
1045
	};
unknown's avatar
unknown committed
1046 1047

type:
1048
	int_type opt_len field_options	{ $$=$1; }
unknown's avatar
unknown committed
1049 1050 1051 1052 1053 1054
	| 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; }
1055
	| char '(' NUM ')' opt_binary	{ Lex->length=$3.str;
unknown's avatar
unknown committed
1056 1057 1058 1059
					  $$=FIELD_TYPE_STRING; }
	| char opt_binary		{ Lex->length=(char*) "1";
					  $$=FIELD_TYPE_STRING; }
	| BINARY '(' NUM ')' 		{ Lex->length=$3.str;
1060
					  Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1061 1062 1063 1064
					  $$=FIELD_TYPE_STRING; }
	| varchar '(' NUM ')' opt_binary { Lex->length=$3.str;
					  $$=FIELD_TYPE_VAR_STRING; }
	| VARBINARY '(' NUM ')' 	{ Lex->length=$3.str;
1065
					  Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1066
					  $$=FIELD_TYPE_VAR_STRING; }
1067
	| YEAR_SYM opt_len field_options { $$=FIELD_TYPE_YEAR; }
unknown's avatar
unknown committed
1068 1069
	| DATE_SYM			{ $$=FIELD_TYPE_DATE; }
	| TIME_SYM			{ $$=FIELD_TYPE_TIME; }
1070 1071 1072 1073 1074 1075 1076
	| TIMESTAMP
	  {
	    if (current_thd->sql_mode & MODE_SAPDB)
	      $$=FIELD_TYPE_DATETIME;
	    else
	      $$=FIELD_TYPE_TIMESTAMP;	
	   }
unknown's avatar
unknown committed
1077 1078 1079
	| TIMESTAMP '(' NUM ')'		{ Lex->length=$3.str;
					  $$=FIELD_TYPE_TIMESTAMP; }
	| DATETIME			{ $$=FIELD_TYPE_DATETIME; }
1080
	| TINYBLOB			{ Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1081
					  $$=FIELD_TYPE_TINY_BLOB; }
1082
	| BLOB_SYM opt_len		{ Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1083
					  $$=FIELD_TYPE_BLOB; }
1084
	| GEOMETRY_SYM			{ Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1085
					  $$=FIELD_TYPE_GEOMETRY; }
1086
	| MEDIUMBLOB			{ Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1087
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1088
	| LONGBLOB			{ Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1089
					  $$=FIELD_TYPE_LONG_BLOB; }
1090
	| LONG_SYM VARBINARY		{ Lex->charset=my_charset_bin;
unknown's avatar
unknown committed
1091
					  $$=FIELD_TYPE_MEDIUM_BLOB; }
1092 1093
	| LONG_SYM varchar opt_binary	{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| TINYTEXT opt_binary		{ $$=FIELD_TYPE_TINY_BLOB; }
1094
	| TEXT_SYM opt_len opt_binary	{ $$=FIELD_TYPE_BLOB; }
1095 1096
	| MEDIUMTEXT opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
	| LONGTEXT opt_binary		{ $$=FIELD_TYPE_LONG_BLOB; }
unknown's avatar
unknown committed
1097 1098 1099 1100
	| DECIMAL_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
	| NUMERIC_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1101 1102
	| FIXED_SYM float_options field_options
					{ $$=FIELD_TYPE_DECIMAL;}
1103
	| ENUM {Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1104
	  {
unknown's avatar
unknown committed
1105 1106
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1107 1108
	    $$=FIELD_TYPE_ENUM;
	  }
1109
	| SET { Lex->interval_list.empty();} '(' string_list ')' opt_binary
unknown's avatar
unknown committed
1110
	  {
unknown's avatar
unknown committed
1111 1112
	    LEX *lex=Lex;
	    lex->interval=typelib(lex->interval_list);
unknown's avatar
unknown committed
1113
	    $$=FIELD_TYPE_SET;
1114
	  }
1115
	| LONG_SYM opt_binary		{ $$=FIELD_TYPE_MEDIUM_BLOB; }
1116
	;
unknown's avatar
unknown committed
1117 1118 1119 1120

char:
	CHAR_SYM {}
	| NCHAR_SYM {}
unknown's avatar
unknown committed
1121
	| NATIONAL_SYM CHAR_SYM {};
unknown's avatar
unknown committed
1122

unknown's avatar
unknown committed
1123 1124 1125 1126
varchar:
	char VARYING {}
	| VARCHAR {}
	| NATIONAL_SYM VARCHAR {}
unknown's avatar
unknown committed
1127
	| NCHAR_SYM VARCHAR {};
unknown's avatar
unknown committed
1128 1129 1130 1131 1132 1133

int_type:
	INT_SYM		{ $$=FIELD_TYPE_LONG; }
	| TINYINT	{ $$=FIELD_TYPE_TINY; }
	| SMALLINT	{ $$=FIELD_TYPE_SHORT; }
	| MEDIUMINT	{ $$=FIELD_TYPE_INT24; }
unknown's avatar
unknown committed
1134
	| BIGINT	{ $$=FIELD_TYPE_LONGLONG; };
unknown's avatar
unknown committed
1135 1136

real_type:
1137
	REAL		{ $$= current_thd->sql_mode & MODE_REAL_AS_FLOAT ?
unknown's avatar
unknown committed
1138 1139
			      FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
	| DOUBLE_SYM	{ $$=FIELD_TYPE_DOUBLE; }
unknown's avatar
unknown committed
1140
	| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; };
unknown's avatar
unknown committed
1141 1142 1143 1144 1145


float_options:
	/* empty */		{}
	| '(' NUM ')'		{ Lex->length=$2.str; }
unknown's avatar
unknown committed
1146
	| precision		{};
unknown's avatar
unknown committed
1147 1148 1149 1150 1151 1152

precision:
	'(' NUM ',' NUM ')'
	{
	  LEX *lex=Lex;
	  lex->length=$2.str; lex->dec=$4.str;
unknown's avatar
unknown committed
1153
	};
unknown's avatar
unknown committed
1154 1155 1156

field_options:
	/* empty */		{}
unknown's avatar
unknown committed
1157
	| field_opt_list	{};
unknown's avatar
unknown committed
1158 1159 1160

field_opt_list:
	field_opt_list field_option {}
unknown's avatar
unknown committed
1161
	| field_option {};
unknown's avatar
unknown committed
1162 1163

field_option:
unknown's avatar
unknown committed
1164
	SIGNED_SYM	{}
1165
	| UNSIGNED	{ Lex->type|= UNSIGNED_FLAG;}
unknown's avatar
unknown committed
1166
	| ZEROFILL	{ Lex->type|= UNSIGNED_FLAG | ZEROFILL_FLAG; };
unknown's avatar
unknown committed
1167 1168

opt_len:
1169 1170
	/* empty */	{ Lex->length=(char*) 0; } /* use default length */
	| '(' NUM ')'	{ Lex->length= $2.str; };
unknown's avatar
unknown committed
1171 1172 1173

opt_precision:
	/* empty */	{}
unknown's avatar
unknown committed
1174
	| precision	{};
unknown's avatar
unknown committed
1175 1176 1177

opt_attribute:
	/* empty */ {}
unknown's avatar
unknown committed
1178
	| opt_attribute_list {};
unknown's avatar
unknown committed
1179 1180 1181

opt_attribute_list:
	opt_attribute_list attribute {}
unknown's avatar
unknown committed
1182
	| attribute;
unknown's avatar
unknown committed
1183 1184 1185 1186 1187 1188

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; }
1189 1190
	| SERIAL_SYM DEFAULT VALUE_SYM
	  { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
unknown's avatar
unknown committed
1191 1192
	| PRIMARY_SYM KEY_SYM { Lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG; }
	| UNIQUE_SYM	  { Lex->type|= UNIQUE_FLAG; }
1193
	| UNIQUE_SYM KEY_SYM { Lex->type|= UNIQUE_KEY_FLAG; }
unknown's avatar
unknown committed
1194
	| COMMENT_SYM text_literal { Lex->comment= $2; };
unknown's avatar
unknown committed
1195

1196
charset_name:
unknown's avatar
unknown committed
1197 1198 1199 1200 1201 1202 1203 1204 1205
	BINARY
	{ 
	  if (!($$=get_charset_by_name("binary",MYF(0))))
	  {
	    net_printf(current_thd,ER_UNKNOWN_CHARACTER_SET,"binary");
	    YYABORT;
	  }
	}
	| ident	
1206
	{ 
1207
	  if (!($$=get_charset_by_name($1.str,MYF(0))))
1208
	  {
1209
	    net_printf(current_thd,ER_UNKNOWN_CHARACTER_SET,$1.str);
1210 1211 1212 1213
	    YYABORT;
	  }
	};

1214 1215 1216
charset_name_or_default:
	charset_name { $$=$1;   }
	| DEFAULT    { $$=NULL; } ;
unknown's avatar
unknown committed
1217

1218 1219 1220 1221
opt_default:
	/* empty */	{}
	| DEFAULT	{};

1222
opt_db_default_character_set:
1223 1224 1225
	/* empty */	{ $$=default_charset_info; }
	| opt_default CHAR_SYM SET charset_name_or_default	{ $$=$4; }
	| opt_default CHARSET charset_name_or_default		{ $$=$3; };
unknown's avatar
unknown committed
1226 1227

opt_binary:
1228
	/* empty */			{ Lex->charset=NULL; }
1229
	| BYTE_SYM			{ Lex->charset=my_charset_bin; }
1230
	| BINARY			{ Lex->charset=my_charset_bin; }
1231
	| CHAR_SYM SET charset_name	{ Lex->charset=$3; } ;
unknown's avatar
unknown committed
1232 1233

references:
1234 1235 1236 1237 1238 1239 1240 1241 1242
	REFERENCES table_ident
	{
	  LEX *lex=Lex;	
	  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
1243
	};
1244 1245
	
opt_ref_list:
unknown's avatar
unknown committed
1246
	/* empty */ opt_on_delete {}
unknown's avatar
unknown committed
1247
	| '(' ref_list ')' opt_on_delete {};
1248 1249 1250

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

unknown's avatar
unknown committed
1253 1254 1255

opt_on_delete:
	/* empty */ {}
unknown's avatar
unknown committed
1256
	| opt_on_delete_list {};
unknown's avatar
unknown committed
1257 1258 1259

opt_on_delete_list:
	opt_on_delete_list opt_on_delete_item {}
unknown's avatar
unknown committed
1260
	| opt_on_delete_item {};
unknown's avatar
unknown committed
1261 1262

opt_on_delete_item:
1263 1264 1265 1266
	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
1267
	| MATCH SIMPLE_SYM { Lex->fk_match_option= foreign_key::FK_MATCH_SIMPLE; };
unknown's avatar
unknown committed
1268 1269

delete_option:
1270 1271 1272 1273
	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
1274
	| SET DEFAULT    { $$= (int) foreign_key::FK_OPTION_DEFAULT;  };
unknown's avatar
unknown committed
1275 1276 1277 1278

key_type:
	opt_constraint PRIMARY_SYM KEY_SYM  { $$= Key::PRIMARY; }
	| key_or_index			    { $$= Key::MULTIPLE; }
1279 1280
	| FULLTEXT_SYM			    { $$= Key::FULLTEXT; }
	| FULLTEXT_SYM key_or_index	    { $$= Key::FULLTEXT; }
unknown's avatar
unknown committed
1281 1282
	| SPATIAL_SYM			    { $$= Key::SPATIAL; }
	| SPATIAL_SYM key_or_index	    { $$= Key::SPATIAL; }
unknown's avatar
unknown committed
1283
	| opt_constraint UNIQUE_SYM	    { $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1284
	| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
unknown's avatar
unknown committed
1285 1286 1287

key_or_index:
	KEY_SYM {}
unknown's avatar
unknown committed
1288
	| INDEX {};
unknown's avatar
unknown committed
1289 1290 1291 1292

keys_or_index:
	KEYS {}
	| INDEX {}
unknown's avatar
unknown committed
1293
	| INDEXES {};
unknown's avatar
unknown committed
1294

1295
opt_unique_or_fulltext:
unknown's avatar
unknown committed
1296 1297
	/* empty */	{ $$= Key::MULTIPLE; }
	| UNIQUE_SYM	{ $$= Key::UNIQUE; }
unknown's avatar
unknown committed
1298
	| SPATIAL_SYM	{ $$= Key::SPATIAL; };
unknown's avatar
unknown committed
1299 1300

key_alg:
1301
	/* empty */		   { $$= HA_KEY_ALG_UNDEF; }
unknown's avatar
unknown committed
1302
	| USING opt_btree_or_rtree { $$= $2; };
unknown's avatar
unknown committed
1303 1304 1305 1306

opt_btree_or_rtree:
	BTREE_SYM	{ $$= HA_KEY_ALG_BTREE; }
	| RTREE_SYM	{ $$= HA_KEY_ALG_RTREE; }
unknown's avatar
unknown committed
1307
	| HASH_SYM	{ $$= HA_KEY_ALG_HASH; };
unknown's avatar
unknown committed
1308 1309 1310

key_list:
	key_list ',' key_part order_dir { Lex->col_list.push_back($3); }
unknown's avatar
unknown committed
1311
	| key_part order_dir		{ Lex->col_list.push_back($1); };
unknown's avatar
unknown committed
1312 1313 1314

key_part:
	ident			{ $$=new key_part_spec($1.str); }
unknown's avatar
unknown committed
1315
	| ident '(' NUM ')'	{ $$=new key_part_spec($1.str,(uint) atoi($3.str)); };
unknown's avatar
unknown committed
1316 1317 1318

opt_ident:
	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
unknown's avatar
unknown committed
1319
	| field_ident	{ $$=$1.str; };
unknown's avatar
unknown committed
1320 1321 1322

string_list:
	text_string			{ Lex->interval_list.push_back($1); }
unknown's avatar
unknown committed
1323
	| string_list ',' text_string	{ Lex->interval_list.push_back($3); };
unknown's avatar
unknown committed
1324 1325 1326 1327 1328 1329 1330 1331

/*
** Alter table
*/

alter:
	ALTER opt_ignore TABLE_SYM table_ident
	{
1332
	  THD *thd=current_thd;
1333
	  LEX *lex=&thd->lex;
unknown's avatar
unknown committed
1334 1335
	  lex->sql_command = SQLCOM_ALTER_TABLE;
	  lex->name=0;
1336
	  if (!lex->select_lex.add_table_to_list($4, NULL,1))
unknown's avatar
unknown committed
1337 1338 1339 1340 1341 1342 1343
	    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();
1344
          lex->select_lex.init_order();
1345
	  lex->select_lex.db=lex->name=0;
unknown's avatar
unknown committed
1346 1347
    	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	  lex->create_info.db_type= DB_TYPE_DEFAULT;
1348
	  lex->create_info.table_charset=thd->db_charset?thd->db_charset:default_charset_info;
1349
	  lex->create_info.row_type= ROW_TYPE_NOT_USED;
1350 1351
          lex->alter_keys_onoff=LEAVE_AS_IS;
          lex->simple_alter=1;
unknown's avatar
unknown committed
1352
	}
unknown's avatar
unknown committed
1353
	alter_list;
1354

1355
	| ALTER DATABASE ident opt_db_default_character_set
1356 1357 1358 1359
	  {
	    LEX *lex=Lex;
	    lex->sql_command=SQLCOM_ALTER_DB;
	    lex->name=$3.str;
1360 1361
	    lex->create_info.table_charset=$4;
	  };
1362 1363


unknown's avatar
unknown committed
1364
alter_list:
unknown's avatar
unknown committed
1365
        | alter_list_item
unknown's avatar
unknown committed
1366
	| alter_list ',' alter_list_item;
unknown's avatar
unknown committed
1367 1368

add_column:
unknown's avatar
unknown committed
1369
	ADD opt_column { Lex->change=0; };
unknown's avatar
unknown committed
1370 1371

alter_list_item:
1372 1373
	add_column field_list_item opt_place { Lex->simple_alter=0; }
	| add_column '(' field_list ')'      { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1374 1375 1376 1377 1378
	| CHANGE opt_column field_ident
	  {
	     LEX *lex=Lex;
	     lex->change= $3.str; lex->simple_alter=0;
	  }
1379
          field_spec opt_place
unknown's avatar
unknown committed
1380 1381 1382 1383 1384
        | 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
1385
            lex->simple_alter=0;
unknown's avatar
unknown committed
1386 1387 1388 1389 1390 1391 1392 1393
          }
          type opt_attribute
          {
            LEX *lex=Lex;
            if (add_field_to_list($3.str,
                                  (enum enum_field_types) $5,
                                  lex->length,lex->dec,lex->type,
                                  lex->default_value, lex->comment,
1394
				  $3.str, lex->interval, lex->charset))
unknown's avatar
unknown committed
1395 1396 1397
	       YYABORT;
          }
          opt_place
unknown's avatar
unknown committed
1398
	| DROP opt_column field_ident opt_restrict
unknown's avatar
unknown committed
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
	  {
	    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;
	  }
1409
	| DROP FOREIGN KEY_SYM opt_ident { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1410
	| DROP key_or_index field_ident
unknown's avatar
unknown committed
1411 1412 1413 1414 1415 1416
	  {
	    LEX *lex=Lex;
	    lex->drop_list.push_back(new Alter_drop(Alter_drop::KEY,
						    $3.str));
	    lex->simple_alter=0;
	  }
1417 1418
	| DISABLE_SYM KEYS { Lex->alter_keys_onoff=DISABLE; }
	| ENABLE_SYM KEYS  { Lex->alter_keys_onoff=ENABLE; }
unknown's avatar
unknown committed
1419
	| ALTER opt_column field_ident SET DEFAULT literal
unknown's avatar
unknown committed
1420 1421 1422 1423 1424
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,$6));
	    lex->simple_alter=0;
	  }
unknown's avatar
unknown committed
1425
	| ALTER opt_column field_ident DROP DEFAULT
unknown's avatar
unknown committed
1426 1427 1428 1429 1430
	  {
	    LEX *lex=Lex;
	    lex->alter_list.push_back(new Alter_column($3.str,(Item*) 0));
	    lex->simple_alter=0;
	  }
1431
	| RENAME opt_to table_ident
1432 1433
	  { 
	    LEX *lex=Lex;
1434
	    lex->select_lex.db=$3->db.str;
1435
	    lex->name= $3->table.str;
1436
	  }
unknown's avatar
unknown committed
1437
        | create_table_options_space_separated { Lex->simple_alter=0; }
unknown's avatar
unknown committed
1438
	| order_clause         { Lex->simple_alter=0; };
unknown's avatar
unknown committed
1439 1440 1441

opt_column:
	/* empty */	{}
unknown's avatar
unknown committed
1442
	| COLUMN_SYM	{};
unknown's avatar
unknown committed
1443 1444 1445

opt_ignore:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
unknown's avatar
unknown committed
1446
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
1447 1448 1449 1450

opt_restrict:
	/* empty */	{}
	| RESTRICT	{}
unknown's avatar
unknown committed
1451
	| CASCADE	{};
unknown's avatar
unknown committed
1452 1453 1454 1455

opt_place:
	/* empty */	{}
	| AFTER_SYM ident { store_position_for_column($2.str); }
unknown's avatar
unknown committed
1456
	| FIRST_SYM	  { store_position_for_column(first_keyword); };
unknown's avatar
unknown committed
1457 1458 1459 1460

opt_to:
	/* empty */	{}
	| TO_SYM	{}
1461
	| EQ		{}
unknown's avatar
unknown committed
1462
	| AS		{};
unknown's avatar
unknown committed
1463 1464

slave:
1465
	START_SYM SLAVE slave_thread_opts
unknown's avatar
unknown committed
1466
         {
unknown's avatar
unknown committed
1467 1468 1469
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_START;
	   lex->type = 0;
unknown's avatar
unknown committed
1470 1471
         }
         |
1472
	STOP_SYM SLAVE slave_thread_opts
unknown's avatar
unknown committed
1473
         {
unknown's avatar
unknown committed
1474 1475 1476
	   LEX *lex=Lex;
           lex->sql_command = SQLCOM_SLAVE_STOP;
	   lex->type = 0;
unknown's avatar
unknown committed
1477
         };
unknown's avatar
unknown committed
1478

unknown's avatar
unknown committed
1479 1480 1481
slave_thread_opts:
	slave_thread_opt
	| slave_thread_opts ',' slave_thread_opt;
1482 1483

slave_thread_opt:
unknown's avatar
unknown committed
1484 1485 1486 1487
	/*empty*/	{} 
	| SQL_THREAD	{ Lex->slave_thd_opt|=SLAVE_SQL; }
	| IO_THREAD   	{ Lex->slave_thd_opt|=SLAVE_IO; }
	;
1488
  
unknown's avatar
unknown committed
1489 1490 1491 1492 1493 1494 1495 1496
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
1497
        };
unknown's avatar
unknown committed
1498

unknown's avatar
unknown committed
1499 1500 1501 1502 1503 1504 1505 1506
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
1507
        };
unknown's avatar
unknown committed
1508

unknown's avatar
unknown committed
1509 1510 1511
repair:
	REPAIR table_or_tables
	{
unknown's avatar
unknown committed
1512 1513 1514
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_REPAIR;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1515
	}
unknown's avatar
unknown committed
1516
	table_list opt_mi_repair_type;
unknown's avatar
unknown committed
1517

unknown's avatar
unknown committed
1518
opt_mi_repair_type:
unknown's avatar
unknown committed
1519
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1520
	| mi_repair_types {};
unknown's avatar
unknown committed
1521

unknown's avatar
unknown committed
1522 1523
mi_repair_types:
	mi_repair_type {}
unknown's avatar
unknown committed
1524
	| mi_repair_type mi_repair_types {};
1525

unknown's avatar
unknown committed
1526
mi_repair_type:
unknown's avatar
unknown committed
1527
	QUICK          { Lex->check_opt.flags|= T_QUICK; }
1528
	| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
unknown's avatar
unknown committed
1529
        | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; };
unknown's avatar
unknown committed
1530 1531

analyze:
1532
	ANALYZE_SYM table_or_tables
unknown's avatar
unknown committed
1533
	{
unknown's avatar
unknown committed
1534 1535 1536
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_ANALYZE;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1537
	}
unknown's avatar
unknown committed
1538
	table_list opt_mi_check_type;
unknown's avatar
unknown committed
1539 1540

check:
unknown's avatar
unknown committed
1541
	CHECK_SYM table_or_tables
unknown's avatar
unknown committed
1542
	{
unknown's avatar
unknown committed
1543 1544 1545
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_CHECK;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1546
	}
unknown's avatar
unknown committed
1547
	table_list opt_mi_check_type;
unknown's avatar
unknown committed
1548

unknown's avatar
unknown committed
1549 1550
opt_mi_check_type:
	/* empty */ { Lex->check_opt.flags = T_MEDIUM; }
unknown's avatar
unknown committed
1551
	| mi_check_types {};
unknown's avatar
unknown committed
1552 1553 1554

mi_check_types:
	mi_check_type {}
unknown's avatar
unknown committed
1555
	| mi_check_type mi_check_types {};
unknown's avatar
unknown committed
1556 1557 1558 1559 1560 1561

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

unknown's avatar
unknown committed
1564
optimize:
1565
	OPTIMIZE table_or_tables
unknown's avatar
unknown committed
1566
	{
unknown's avatar
unknown committed
1567 1568 1569
	   LEX *lex=Lex;
	   lex->sql_command = SQLCOM_OPTIMIZE;
	   lex->check_opt.init();
unknown's avatar
unknown committed
1570
	}
unknown's avatar
unknown committed
1571
	table_list opt_mi_check_type;
unknown's avatar
unknown committed
1572

1573 1574 1575 1576 1577
rename:
	RENAME table_or_tables
	{
	   Lex->sql_command=SQLCOM_RENAME_TABLE;
	}
unknown's avatar
unknown committed
1578
	table_to_table_list;
1579 1580 1581

table_to_table_list:
	table_to_table
unknown's avatar
unknown committed
1582
	| table_to_table_list ',' table_to_table;
1583 1584 1585

table_to_table:
	table_ident TO_SYM table_ident
1586 1587 1588 1589 1590
	{ 
	  SELECT_LEX_NODE *sl= Lex->current_select;
	  if (!sl->add_table_to_list($1,NULL,1,TL_IGNORE) ||
	      !sl->add_table_to_list($3,NULL,1,TL_IGNORE))
	    YYABORT;
unknown's avatar
unknown committed
1591
 	};
1592

unknown's avatar
unknown committed
1593
/*
unknown's avatar
unknown committed
1594
  Select : retrieve data from table
unknown's avatar
unknown committed
1595 1596 1597 1598
*/


select:
unknown's avatar
unknown committed
1599
	select_init { Lex->sql_command=SQLCOM_SELECT; };
unknown's avatar
unknown committed
1600 1601

select_init:
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
	SELECT_SYM select_part2 
        { 
	  LEX *lex= Lex;
          if (lex->current_select->set_braces(false))
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;
	  }
	}
	union
1612
	|
1613 1614
	'(' SELECT_SYM 	select_part2 ')' 
	  { 
1615 1616 1617 1618 1619 1620 1621
	    LEX *lex= Lex;
            SELECT_LEX_NODE * sel= lex->current_select;
	    if (sel->set_braces(true))
	    {
	      send_error(lex->thd, ER_SYNTAX_ERROR);
	      YYABORT;
	    }
1622
            /* select in braces, can't contain global parameters */
1623 1624
            sel->master_unit()->global_parameters=
              	sel->master_unit();
unknown's avatar
unknown committed
1625
          } union_opt;
1626 1627

select_part2:
unknown's avatar
unknown committed
1628 1629
	{
	  LEX *lex=Lex;
unknown's avatar
unknown committed
1630
	  lex->lock_option=TL_READ;
1631
	   mysql_init_select(lex);
unknown's avatar
unknown committed
1632
	}
unknown's avatar
unknown committed
1633
	select_options select_item_list select_into select_lock_type;
1634

unknown's avatar
unknown committed
1635
select_into:
1636
	limit_clause {}
unknown's avatar
unknown committed
1637
	| select_from
1638
	| FROM DUAL_SYM
unknown's avatar
unknown committed
1639
        | opt_into
unknown's avatar
unknown committed
1640
	| opt_into select_from
unknown's avatar
unknown committed
1641
	| select_from opt_into;
unknown's avatar
unknown committed
1642 1643

select_from:
unknown's avatar
unknown committed
1644
	FROM join_table_list where_clause group_clause having_clause opt_order_clause limit_clause procedure_clause;
unknown's avatar
unknown committed
1645 1646 1647 1648


select_options:
	/* empty*/
unknown's avatar
unknown committed
1649
	| select_option_list;
unknown's avatar
unknown committed
1650 1651 1652

select_option_list:
	select_option_list select_option
unknown's avatar
unknown committed
1653
	| select_option;
unknown's avatar
unknown committed
1654 1655

select_option:
1656
	STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
1657 1658 1659 1660 1661 1662
	| HIGH_PRIORITY
	  {
	    if (check_simple_select())
	      YYABORT;
	    Lex->lock_option= TL_READ_HIGH_PRIORITY;
	  }
1663 1664 1665
	| DISTINCT	{ Select->options|= SELECT_DISTINCT; }
	| SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
	| SQL_BIG_RESULT { Select->options|= SELECT_BIG_RESULT; }
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
	| 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;
	  }
	| SQL_NO_CACHE_SYM { current_thd->safe_to_cache_query=0; }
	| SQL_CACHE_SYM    { Select->options|= OPTION_TO_QUERY_CACHE; }
	| ALL		{}
	;
unknown's avatar
unknown committed
1682

unknown's avatar
unknown committed
1683 1684 1685
select_lock_type:
	/* empty */
	| FOR_SYM UPDATE_SYM
1686 1687 1688 1689 1690 1691 1692
	  {
	    LEX *lex=Lex;
	    if (check_simple_select())
	      YYABORT;	
	    lex->lock_option= TL_WRITE;
	    lex->thd->safe_to_cache_query=0;
	  }
unknown's avatar
unknown committed
1693
	| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
1694 1695 1696 1697 1698 1699 1700 1701
	  {
	    LEX *lex=Lex;
	    if (check_simple_select())
	      YYABORT;	
	    lex->lock_option= TL_READ_WITH_SHARED_LOCKS;
	    lex->thd->safe_to_cache_query=0;
	  }
	;
unknown's avatar
unknown committed
1702

unknown's avatar
unknown committed
1703 1704 1705 1706 1707 1708 1709
select_item_list:
	  select_item_list ',' select_item
	| select_item
	| '*'
	  {
	    if (add_item_to_list(new Item_field(NULL,NULL,"*")))
	      YYABORT;
unknown's avatar
unknown committed
1710
	  };
unknown's avatar
unknown committed
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721


select_item:
	  remember_name select_item2 remember_end select_alias
	  {
	    if (add_item_to_list($2))
	      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
1722
	  };
unknown's avatar
unknown committed
1723 1724

remember_name:
unknown's avatar
unknown committed
1725
	{ $$=(char*) Lex->tok_start; };
unknown's avatar
unknown committed
1726 1727

remember_end:
unknown's avatar
unknown committed
1728
	{ $$=(char*) Lex->tok_end; };
unknown's avatar
unknown committed
1729 1730 1731

select_item2:
	table_wild	{ $$=$1; } /* table.* */
unknown's avatar
unknown committed
1732
	| expr		{ $$=$1; };
unknown's avatar
unknown committed
1733 1734 1735 1736 1737 1738

select_alias:
	{ $$.str=0;}
	| AS ident { $$=$2; }
	| AS TEXT_STRING  { $$=$2; }
	| ident { $$=$1; }
unknown's avatar
unknown committed
1739
	| TEXT_STRING  { $$=$1; };
unknown's avatar
unknown committed
1740 1741 1742

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

unknown's avatar
unknown committed
1745
/* all possible expressions */
1746
expr:	expr_expr	{ $$= $1; }
unknown's avatar
unknown committed
1747
	| simple_expr	{ $$= $1; };
unknown's avatar
unknown committed
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760

/* expressions that begin with 'expr' */
expr_expr:
	expr IN_SYM '(' expr_list ')'
	  { $$= new Item_func_in($1,*$4); }
	| expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
	| 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)); }
	| expr OR_OR_CONCAT expr { $$= or_or_concat($1,$3); }
	| expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
1761
        | expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
	| expr AND expr		{ $$= new Item_cond_and($1,$3); }
	| 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 EQ expr		{ $$= new Item_func_eq($1,$3); }
	| expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
	| expr GE expr		{ $$= new Item_func_ge($1,$3); }
	| expr GT_SYM expr	{ $$= new Item_func_gt($1,$3); }
	| expr LE expr		{ $$= new Item_func_le($1,$3); }
	| expr LT expr		{ $$= new Item_func_lt($1,$3); }
	| expr NE expr		{ $$= new Item_func_ne($1,$3); }
	| 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); }
1782 1783
	| 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
1784
	| expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
1785
        | expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }	
unknown's avatar
unknown committed
1786 1787 1788 1789 1790
	| expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| expr '%' expr		{ $$= new Item_func_mod($1,$3); }
	| expr '+' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,0); }
	| expr '-' INTERVAL_SYM expr interval
unknown's avatar
unknown committed
1791
	  { $$= new Item_date_add_interval($1,$4,$5,1); }
1792 1793
	| expr COLLATE_SYM charset_name
	  { $$= new Item_func_set_collation($1,$3); };
unknown's avatar
unknown committed
1794 1795 1796 1797 1798 1799 1800 1801 1802

/* 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)); }
	| no_in_expr OR_OR_CONCAT expr	{ $$= or_or_concat($1,$3); }
	| no_in_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
1803
        | no_in_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
	| no_in_expr AND expr		{ $$= new Item_cond_and($1,$3); }
	| 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 EQ expr		{ $$= new Item_func_eq($1,$3); }
	| no_in_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
	| no_in_expr GE expr		{ $$= new Item_func_ge($1,$3); }
	| no_in_expr GT_SYM expr	{ $$= new Item_func_gt($1,$3); }
	| no_in_expr LE expr		{ $$= new Item_func_le($1,$3); }
	| no_in_expr LT expr		{ $$= new Item_func_lt($1,$3); }
	| no_in_expr NE expr		{ $$= new Item_func_ne($1,$3); }
	| 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); }
1824
	| no_in_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
1825
	| no_in_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
1826
        | no_in_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
1827 1828
	| no_in_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_in_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
1829
	| no_in_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
unknown's avatar
unknown committed
1830 1831 1832 1833
	| no_in_expr '+' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,0); }
	| no_in_expr '-' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,1); }
unknown's avatar
unknown committed
1834
	| simple_expr;
unknown's avatar
unknown committed
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847

/* expressions that begin with 'expr' that does NOT follow AND */
no_and_expr:
	no_and_expr IN_SYM '(' expr_list ')'
	{ $$= new Item_func_in($1,*$4); }
	| no_and_expr NOT IN_SYM '(' expr_list ')'
	  { $$= new Item_func_not(new Item_func_in($1,*$5)); }
	| 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)); }
	| no_and_expr OR_OR_CONCAT expr	{ $$= or_or_concat($1,$3); }
	| no_and_expr OR expr		{ $$= new Item_cond_or($1,$3); }
unknown's avatar
unknown committed
1848
        | no_and_expr XOR expr		{ $$= new Item_cond_xor($1,$3); }
unknown's avatar
unknown committed
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
	| 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 EQ expr		{ $$= new Item_func_eq($1,$3); }
	| no_and_expr EQUAL_SYM expr	{ $$= new Item_func_equal($1,$3); }
	| no_and_expr GE expr		{ $$= new Item_func_ge($1,$3); }
	| no_and_expr GT_SYM expr	{ $$= new Item_func_gt($1,$3); }
	| no_and_expr LE expr		{ $$= new Item_func_le($1,$3); }
	| no_and_expr LT expr		{ $$= new Item_func_lt($1,$3); }
	| no_and_expr NE expr		{ $$= new Item_func_ne($1,$3); }
	| 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); }
1868
	| no_and_expr DIV_SYM expr	{ $$= new Item_func_int_div($1,$3); }
unknown's avatar
unknown committed
1869
	| no_and_expr '|' expr		{ $$= new Item_func_bit_or($1,$3); }
unknown's avatar
unknown committed
1870
        | no_and_expr '^' expr		{ $$= new Item_func_bit_xor($1,$3); }
unknown's avatar
unknown committed
1871 1872
	| no_and_expr '&' expr		{ $$= new Item_func_bit_and($1,$3); }
	| no_and_expr '%' expr		{ $$= new Item_func_mod($1,$3); }
1873
	| no_and_expr MOD_SYM expr	{ $$= new Item_func_mod($1,$3); }
unknown's avatar
unknown committed
1874 1875 1876 1877
	| no_and_expr '+' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,0); }
	| no_and_expr '-' INTERVAL_SYM expr interval
	  { $$= new Item_date_add_interval($1,$4,$5,1); }
unknown's avatar
unknown committed
1878
	| simple_expr;
unknown's avatar
unknown committed
1879 1880 1881 1882

simple_expr:
	simple_ident
	| literal
unknown's avatar
unknown committed
1883
	| param_marker
unknown's avatar
unknown committed
1884
	| '@' ident_or_text SET_VAR expr
unknown's avatar
unknown committed
1885 1886
	  {
	    $$= new Item_func_set_user_var($2,$4);
unknown's avatar
unknown committed
1887 1888 1889
	    current_thd->safe_to_cache_query=0;
	  }
	| '@' ident_or_text	 
unknown's avatar
unknown committed
1890 1891
	  {
	    $$= new Item_func_get_user_var($2);
unknown's avatar
unknown committed
1892 1893
	    current_thd->safe_to_cache_query=0;
	  }
unknown's avatar
unknown committed
1894 1895 1896 1897
	| '@' '@' opt_var_ident_type ident_or_text
	  {
	    if (!($$= get_system_var((enum_var_type) $3, $4)))
	      YYABORT;
unknown's avatar
unknown committed
1898
	  }
unknown's avatar
unknown committed
1899 1900 1901 1902 1903 1904
	| 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; }
unknown's avatar
unknown committed
1905 1906
	| EXISTS exists_subselect { $$= $2; }
	| singleval_subselect   { $$= $1; }
unknown's avatar
unknown committed
1907
	| '{' ident expr '}'	{ $$= $3; }
unknown's avatar
unknown committed
1908
        | MATCH ident_list_arg AGAINST '(' expr ')'
1909
          { Select->add_ftfunc_to_list((Item_func_match *)
1910
                   ($$=new Item_func_match_nl(*$2,$5))); }
unknown's avatar
unknown committed
1911
        | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')'
1912
          { Select->add_ftfunc_to_list((Item_func_match *)
1913
                   ($$=new Item_func_match_bool(*$2,$5))); }
1914
	| BINARY expr %prec NEG { $$= new Item_func_set_collation($2,my_charset_bin); }
unknown's avatar
unknown committed
1915
	| CAST_SYM '(' expr AS cast_type ')'  { $$= create_func_cast($3, $5); }
unknown's avatar
unknown committed
1916
	| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
1917
	  { $$= new Item_func_case(* $4, $2, $5 ); }
unknown's avatar
unknown committed
1918
	| CONVERT_SYM '(' expr ',' cast_type ')'  { $$= create_func_cast($3, $5); }
1919 1920
	| CONVERT_SYM '(' expr USING charset_name ')'
	  { $$= new Item_func_conv_charset($3,$5); }
1921
	| CONVERT_SYM '(' expr ',' expr ',' expr ')'
1922
	  { $$= new Item_func_conv_charset3($3,$7,$5); }
unknown's avatar
unknown committed
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
	| 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
1937 1938
	| CHARSET '(' expr ')'
	  { $$= new Item_func_charset($3); }
unknown's avatar
unknown committed
1939 1940 1941 1942 1943 1944 1945
	| 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
unknown's avatar
unknown committed
1946
	  { $$= new Item_func_curdate(); current_thd->safe_to_cache_query=0; }
unknown's avatar
unknown committed
1947
	| CURTIME optional_braces
unknown's avatar
unknown committed
1948
	  { $$= new Item_func_curtime(); current_thd->safe_to_cache_query=0; }
unknown's avatar
unknown committed
1949
	| CURTIME '(' expr ')'
unknown's avatar
unknown committed
1950 1951 1952 1953
	  { 
	    $$= new Item_func_curtime($3); 
	    current_thd->safe_to_cache_query=0;
	  }
unknown's avatar
unknown committed
1954 1955 1956 1957 1958
	| DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3,$6,$7,0); }
	| DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
	  { $$= new Item_date_add_interval($3,$6,$7,1); }
	| DATABASE '(' ')'
unknown's avatar
unknown committed
1959 1960 1961 1962
	  { 
	    $$= new Item_func_database();
            current_thd->safe_to_cache_query=0; 
	  }
unknown's avatar
unknown committed
1963 1964 1965 1966
	| 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
1967 1968 1969 1970 1971
	| ENCRYPT '(' expr ')'
	  {
	    $$= new Item_func_encrypt($3);
	    current_thd->safe_to_cache_query=0; 
	  }
unknown's avatar
unknown committed
1972 1973 1974 1975 1976
	| 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
1977
	| DES_DECRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
1978
        { $$= new Item_func_des_decrypt($3); }
unknown's avatar
unknown committed
1979
	| DES_DECRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
1980
        { $$= new Item_func_des_decrypt($3,$5); }
unknown's avatar
unknown committed
1981
	| DES_ENCRYPT_SYM '(' expr ')'
unknown's avatar
unknown committed
1982
        { $$= new Item_func_des_encrypt($3); }
unknown's avatar
unknown committed
1983
	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
1984
        { $$= new Item_func_des_encrypt($3,$5); }
unknown's avatar
unknown committed
1985 1986 1987 1988 1989 1990
	| 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); }
1991 1992
	| FALSE_SYM
	  { $$= new Item_int((char*) "FALSE",0,1); }
unknown's avatar
unknown committed
1993 1994 1995 1996 1997 1998
	| 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
1999
	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
unknown's avatar
unknown committed
2000 2001 2002
	  }
	| FIELD_FUNC '(' expr ',' expr_list ')'
	  { $$= new Item_func_field($3, *$5); }
unknown's avatar
unknown committed
2003
	| GEOMFROMTEXT '(' expr ')'
2004
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2005
	| GEOMFROMTEXT '(' expr ',' expr ')'
2006
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2007 2008 2009 2010
	| GEOMETRYCOLLECTION '(' expr_list ')'
	  { $$= new Item_func_spatial_collection(* $3, 
                       Geometry::wkbGeometryCollection, 
                       Geometry::wkbPoint); }
unknown's avatar
unknown committed
2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
	| 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); }
	| INTERVAL_SYM expr interval '+' expr
	  /* we cannot put interval before - */
	  { $$= new Item_date_add_interval($5,$2,$3,0); }
	| INTERVAL_SYM '(' expr ',' expr_list ')'
	  { $$= new Item_func_interval($3,* $5); }
	| LAST_INSERT_ID '(' ')'
	  {
2024 2025
    	    $$= get_system_var(OPT_SESSION, "last_insert_id", 14,
			      "last_insert_id()");
unknown's avatar
unknown committed
2026 2027 2028 2029
	  }
	| LAST_INSERT_ID '(' expr ')'
	  {
	    $$= new Item_func_set_last_insert_id($3);
unknown's avatar
unknown committed
2030
	    current_thd->safe_to_cache_query=0;
unknown's avatar
unknown committed
2031 2032 2033
	  }
	| LEFT '(' expr ',' expr ')'
	  { $$= new Item_func_left($3,$5); }
unknown's avatar
unknown committed
2034 2035 2036
	| LINESTRING '(' expr_list ')'
	  { $$= new Item_func_spatial_collection(* $3, 
               Geometry::wkbLineString, Geometry::wkbPoint); }
unknown's avatar
unknown committed
2037 2038 2039 2040
	| 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
2041
 	| GEOMCOLLFROMTEXT '(' expr ')'
2042
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2043
	| GEOMCOLLFROMTEXT '(' expr ',' expr ')'
2044
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2045
	| GREATEST_SYM '(' expr ',' expr_list ')'
unknown's avatar
unknown committed
2046 2047 2048
	  { $5->push_front($3); $$= new Item_func_max(*$5); }
	| LEAST_SYM '(' expr ',' expr_list ')'
	  { $5->push_front($3); $$= new Item_func_min(*$5); }
2049
	| LOG_SYM '(' expr ')'
unknown's avatar
unknown committed
2050
	  { $$= new Item_func_log($3); }
2051
	| LOG_SYM '(' expr ',' expr ')'
unknown's avatar
unknown committed
2052
	  { $$= new Item_func_log($3, $5); }
unknown's avatar
unknown committed
2053
 	| LINEFROMTEXT '(' expr ')'
2054
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2055
	| LINEFROMTEXT '(' expr ',' expr ')'
2056
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2057 2058
	| MINUTE_SYM '(' expr ')'
	  { $$= new Item_func_minute($3); }
2059 2060
	| MOD_SYM '(' expr ',' expr ')'
	  { $$ = new Item_func_mod( $3, $5); }
unknown's avatar
unknown committed
2061 2062
	| MONTH_SYM '(' expr ')'
	  { $$= new Item_func_month($3); }
unknown's avatar
unknown committed
2063 2064 2065
 	| MULTILINESTRING '(' expr_list ')'
 	  { $$= new Item_func_spatial_collection(* $3, 
                    Geometry::wkbMultiLineString, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2066
 	| MLINEFROMTEXT '(' expr ')'
2067
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2068
	| MLINEFROMTEXT '(' expr ',' expr ')'
2069
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2070
	| MPOINTFROMTEXT '(' expr ')'
2071
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2072
	| MPOINTFROMTEXT '(' expr ',' expr ')'
2073
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2074
	| MPOLYFROMTEXT '(' expr ')'
2075
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2076
	| MPOLYFROMTEXT '(' expr ',' expr ')'
2077
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2078
	| MULTIPOINT '(' expr_list ')'
unknown's avatar
unknown committed
2079 2080 2081 2082 2083
 	  { $$= new Item_func_spatial_collection(* $3, 
                    Geometry::wkbMultiPoint, Geometry::wkbPoint); }
 	| MULTIPOLYGON '(' expr_list ')'
 	  { $$= new Item_func_spatial_collection(* $3, 
                       Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
unknown's avatar
unknown committed
2084
	| NOW_SYM optional_braces
unknown's avatar
unknown committed
2085
	  { $$= new Item_func_now(); current_thd->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2086
	| NOW_SYM '(' expr ')'
unknown's avatar
unknown committed
2087 2088 2089 2090 2091
	  { $$= new Item_func_now($3); current_thd->safe_to_cache_query=0;}
	| PASSWORD '(' expr ')'
	  {
	    $$= new Item_func_password($3);
	   }
unknown's avatar
unknown committed
2092
 	| POINTFROMTEXT '(' expr ')'
2093
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2094
	| POINTFROMTEXT '(' expr ',' expr ')'
2095
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2096
	| POLYFROMTEXT '(' expr ')'
2097
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2098
	| POLYFROMTEXT '(' expr ',' expr ')'
2099
	  { $$= new Item_func_geometry_from_text($3); }
unknown's avatar
unknown committed
2100
	| POLYGON '(' expr_list ')'
unknown's avatar
unknown committed
2101 2102
 	  { $$= new Item_func_spatial_collection(* $3, 
			Geometry::wkbPolygon, Geometry::wkbLineString); }
unknown's avatar
unknown committed
2103 2104
	| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
	  { $$ = new Item_func_locate($5,$3); }
unknown's avatar
unknown committed
2105 2106 2107 2108
	| RAND '(' expr ')'
	  { $$= new Item_func_rand($3); current_thd->safe_to_cache_query=0;}
	| RAND '(' ')'
	  { $$= new Item_func_rand(); current_thd->safe_to_cache_query=0;}
unknown's avatar
unknown committed
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
	| 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 ')'
2129
	  { $$= new Item_func_trim($3,new Item_string(" ",1,default_charset_info)); }
unknown's avatar
unknown committed
2130 2131 2132 2133 2134 2135 2136 2137
	| 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); }
2138 2139
	| TRUNCATE_SYM '(' expr ',' expr ')'
	  { $$= new Item_func_round($3,$5,1); }
2140 2141
	| TRUE_SYM
	  { $$= new Item_int((char*) "TRUE",1,1); }
unknown's avatar
unknown committed
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184
	| 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 ')'
unknown's avatar
unknown committed
2185 2186 2187
	  { 
            $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
	  }
unknown's avatar
unknown committed
2188
	| UNIX_TIMESTAMP '(' ')'
unknown's avatar
unknown committed
2189 2190 2191 2192
	  {
	    $$= new Item_func_unix_timestamp();
	    current_thd->safe_to_cache_query=0;
	  }
unknown's avatar
unknown committed
2193 2194 2195
	| UNIX_TIMESTAMP '(' expr ')'
	  { $$= new Item_func_unix_timestamp($3); }
	| USER '(' ')'
unknown's avatar
unknown committed
2196
	  { $$= new Item_func_user(); current_thd->safe_to_cache_query=0; }
unknown's avatar
unknown committed
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207
	| 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 ')'
unknown's avatar
unknown committed
2208 2209 2210 2211
	  { 
	    $$=new Item_func_benchmark($3,$5);
	    current_thd->safe_to_cache_query=0;
	  }
unknown's avatar
unknown committed
2212
	| EXTRACT_SYM '(' interval FROM expr ')'
unknown's avatar
unknown committed
2213
	{ $$=new Item_extract( $3, $5); };
unknown's avatar
unknown committed
2214 2215 2216

udf_expr_list:
	/* empty */	{ $$= NULL; }
unknown's avatar
unknown committed
2217
	| expr_list	{ $$= $1;};
unknown's avatar
unknown committed
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240

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); }
	| SUM_SYM '(' in_sum_expr ')'
unknown's avatar
unknown committed
2241
	  { $$=new Item_sum_sum($3); };
unknown's avatar
unknown committed
2242 2243

in_sum_expr:
2244 2245 2246 2247 2248 2249 2250 2251
	{
	  LEX *lex= Lex;
	  if (lex->current_select->inc_in_sum_expr())
	  {
	    send_error(lex->thd, ER_SYNTAX_ERROR);
	    YYABORT;	    
	  }
	}
unknown's avatar
unknown committed
2252 2253
	expr
	{
unknown's avatar
unknown committed
2254
	  Select->select_lex()->in_sum_expr--;
unknown's avatar
unknown committed
2255
	  $$=$2;
unknown's avatar
unknown committed
2256
	};
unknown's avatar
unknown committed
2257

unknown's avatar
unknown committed
2258 2259 2260 2261 2262 2263 2264 2265
cast_type:
	BINARY 			{ $$=ITEM_CAST_BINARY; }
	| 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; }
unknown's avatar
unknown committed
2266
	| DATETIME		{ $$=ITEM_CAST_DATETIME; };
unknown's avatar
unknown committed
2267

unknown's avatar
unknown committed
2268
expr_list:
2269
	{ Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2270
	expr_list2
unknown's avatar
unknown committed
2271
	{ $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2272 2273

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

unknown's avatar
unknown committed
2277 2278
ident_list_arg:
          ident_list          { $$= $1; }
unknown's avatar
unknown committed
2279
        | '(' ident_list ')'  { $$= $2; };
unknown's avatar
unknown committed
2280

unknown's avatar
unknown committed
2281
ident_list:
2282
        { Select->expr_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2283
        ident_list2
unknown's avatar
unknown committed
2284
        { $$= Select->expr_list.pop(); };
unknown's avatar
unknown committed
2285 2286

ident_list2:
2287
        simple_ident { Select->expr_list.head()->push_back($1); }
unknown's avatar
unknown committed
2288
        | ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
unknown's avatar
unknown committed
2289 2290 2291

opt_expr:
	/* empty */      { $$= NULL; }
unknown's avatar
unknown committed
2292
	| expr         	 { $$= $1; };
unknown's avatar
unknown committed
2293 2294 2295

opt_else:
	/* empty */    { $$= NULL; }
unknown's avatar
unknown committed
2296
	| ELSE expr    { $$= $2; };
unknown's avatar
unknown committed
2297 2298

when_list:
unknown's avatar
unknown committed
2299
        { Select->when_list.push_front(new List<Item>); }
unknown's avatar
unknown committed
2300
	when_list2
unknown's avatar
unknown committed
2301
	{ $$= Select->when_list.pop(); };
unknown's avatar
unknown committed
2302 2303

when_list2:
unknown's avatar
unknown committed
2304
	expr THEN_SYM expr
unknown's avatar
unknown committed
2305
	  {
2306
	    SELECT_LEX_NODE *sel=Select;	    
unknown's avatar
unknown committed
2307 2308
	    sel->when_list.head()->push_back($1);
	    sel->when_list.head()->push_back($3);
unknown's avatar
unknown committed
2309
	}
unknown's avatar
unknown committed
2310
	| when_list2 WHEN_SYM expr THEN_SYM expr
unknown's avatar
unknown committed
2311
	  {
2312
	    SELECT_LEX_NODE *sel=Select;
unknown's avatar
unknown committed
2313 2314
	    sel->when_list.head()->push_back($3);
	    sel->when_list.head()->push_back($5);
unknown's avatar
unknown committed
2315
	  };
unknown's avatar
unknown committed
2316 2317

opt_pad:
2318
	/* empty */ { $$=new Item_string(" ",1,default_charset_info); }
unknown's avatar
unknown committed
2319
	| expr	    { $$=$1; };
unknown's avatar
unknown committed
2320 2321 2322 2323

join_table_list:
	'(' join_table_list ')'	{ $$=$2; }
	| join_table		{ $$=$1; }
2324
	| join_table_list normal_join join_table_list { $$=$3; }
2325 2326 2327
	| 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
2328
	  { add_join_on($4,$6); $$=$4; }
2329
	| join_table_list INNER_SYM JOIN_SYM join_table_list
unknown's avatar
unknown committed
2330
	  {
unknown's avatar
unknown committed
2331
	    SELECT_LEX *sel= Select->select_lex();
2332 2333
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$4->db; sel->table2=$4->alias;
unknown's avatar
unknown committed
2334
	  }
unknown's avatar
unknown committed
2335 2336
	  USING '(' using_list ')'
	  { add_join_on($4,$8); $$=$4; }
2337
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr
2338
	  { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2339
	| join_table_list LEFT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2340
	  {
unknown's avatar
unknown committed
2341
	    SELECT_LEX *sel= Select->select_lex();
2342 2343
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2344
	  }
unknown's avatar
unknown committed
2345
	  USING '(' using_list ')'
2346
	  { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
2347
	| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
2348
	  { add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
2349
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
2350
	  { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2351
	| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
unknown's avatar
unknown committed
2352
	  {
unknown's avatar
unknown committed
2353
	    SELECT_LEX *sel= Select->select_lex();
2354 2355
	    sel->db1=$1->db; sel->table1=$1->alias;
	    sel->db2=$5->db; sel->table2=$5->alias;
unknown's avatar
unknown committed
2356
	  }
2357 2358
	  USING '(' using_list ')'
	  { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2359
	| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
2360
	  { add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
2361
	| join_table_list NATURAL JOIN_SYM join_table_list
unknown's avatar
unknown committed
2362
	  { add_join_natural($1,$4); $$=$4; };
unknown's avatar
unknown committed
2363 2364 2365 2366

normal_join:
	',' {}
	| JOIN_SYM {}
unknown's avatar
unknown committed
2367
	| CROSS JOIN_SYM {};
unknown's avatar
unknown committed
2368 2369

join_table:
unknown's avatar
unknown committed
2370
	{
unknown's avatar
unknown committed
2371
	  SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2372 2373
	  sel->use_index_ptr=sel->ignore_index_ptr=0;
	}
unknown's avatar
unknown committed
2374
        table_ident opt_table_alias opt_key_definition
unknown's avatar
unknown committed
2375
	{
2376 2377 2378 2379
	  SELECT_LEX_NODE *sel=Select;
	  if (!($$= sel->add_table_to_list($2, $3, 0, TL_UNLOCK,
					   sel->get_use_index(),
					   sel->get_ignore_index())))
2380
	    YYABORT;
unknown's avatar
unknown committed
2381
	}
unknown's avatar
unknown committed
2382
	| '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}'
2383
	  { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
unknown's avatar
unknown committed
2384 2385 2386
        | '(' SELECT_SYM select_part3 ')' opt_table_alias 
	{
	  LEX *lex=Lex;
2387 2388 2389 2390
	  SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
	  lex->current_select= unit->outer_select();
	  if (!($$= lex->current_select->
                add_table_to_list(new Table_ident(unit), $5, 0, TL_UNLOCK)))
unknown's avatar
unknown committed
2391
	    YYABORT;
unknown's avatar
unknown committed
2392
	};
unknown's avatar
unknown committed
2393 2394 2395

select_part3:
        {
unknown's avatar
unknown committed
2396 2397
	  LEX *lex= Lex;
	  lex->derived_tables= true;
2398
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || 
unknown's avatar
unknown committed
2399
              mysql_new_select(lex, 1))
unknown's avatar
unknown committed
2400 2401
	    YYABORT;
	  mysql_init_select(lex);
2402
	  lex->current_select->linkage= DERIVED_TABLE_TYPE;
unknown's avatar
unknown committed
2403
	}
unknown's avatar
unknown committed
2404
        select_options select_item_list select_intoto;
unknown's avatar
unknown committed
2405 2406 2407

select_intoto:
	limit_clause {}
unknown's avatar
unknown committed
2408
	| select_from;
unknown's avatar
unknown committed
2409 2410 2411

opt_outer:
	/* empty */	{}
unknown's avatar
unknown committed
2412
	| OUTER		{};
unknown's avatar
unknown committed
2413 2414 2415 2416

opt_key_definition:
	/* empty */	{}
	| USE_SYM    key_usage_list
unknown's avatar
unknown committed
2417
          {
unknown's avatar
unknown committed
2418
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2419 2420 2421
	    sel->use_index= *$2;
	    sel->use_index_ptr= &sel->use_index;
	  }
unknown's avatar
unknown committed
2422
	| IGNORE_SYM key_usage_list
unknown's avatar
unknown committed
2423
	  {
unknown's avatar
unknown committed
2424
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2425 2426
	    sel->ignore_index= *$2;
	    sel->ignore_index_ptr= &sel->ignore_index;
unknown's avatar
unknown committed
2427
	  };
unknown's avatar
unknown committed
2428 2429

key_usage_list:
unknown's avatar
unknown committed
2430
	key_or_index { Select->select_lex()->interval_list.empty(); }
2431
        '(' key_usage_list2 ')'
unknown's avatar
unknown committed
2432
        { $$= &Select->select_lex()->interval_list; };
unknown's avatar
unknown committed
2433 2434 2435

key_usage_list2:
	key_usage_list2 ',' ident
unknown's avatar
unknown committed
2436
        { Select->select_lex()->
2437 2438
	    interval_list.push_back(new String((const char*) $3.str, $3.length,
				    default_charset_info)); }
unknown's avatar
unknown committed
2439
	| ident
unknown's avatar
unknown committed
2440
        { Select->select_lex()->
2441 2442
	    interval_list.push_back(new String((const char*) $1.str, $1.length,
				    default_charset_info)); }
unknown's avatar
unknown committed
2443
	| PRIMARY_SYM
unknown's avatar
unknown committed
2444
        { Select->select_lex()->
2445 2446
	    interval_list.push_back(new String("PRIMARY", 7,
				    default_charset_info)); };
unknown's avatar
unknown committed
2447 2448 2449

using_list:
	ident
unknown's avatar
unknown committed
2450
	  {
unknown's avatar
unknown committed
2451
	    SELECT_LEX *sel= Select->select_lex();
2452 2453 2454 2455
	    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
2456 2457 2458 2459
	      YYABORT;
	  }
	| using_list ',' ident
	  {
unknown's avatar
unknown committed
2460
	    SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2461
	    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
2462
	      YYABORT;
unknown's avatar
unknown committed
2463
	  };
unknown's avatar
unknown committed
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477

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
2478
	| YEAR_SYM		{ $$=INTERVAL_YEAR; };
unknown's avatar
unknown committed
2479 2480 2481 2482

table_alias:
	/* empty */
	| AS
unknown's avatar
unknown committed
2483
	| EQ;
unknown's avatar
unknown committed
2484 2485 2486 2487

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


where_clause:
unknown's avatar
unknown committed
2492 2493
	/* empty */  { Select->select_lex()->where= 0; }  
	| WHERE expr { Select->select_lex()->where= $2; };
unknown's avatar
unknown committed
2494 2495 2496

having_clause:
	/* empty */
unknown's avatar
unknown committed
2497
	| HAVING { Select->select_lex()->create_refs= 1; } expr
unknown's avatar
unknown committed
2498
	{
unknown's avatar
unknown committed
2499
	  SELECT_LEX *sel= Select->select_lex();
unknown's avatar
unknown committed
2500
	  sel->having= $3; sel->create_refs=0;
unknown's avatar
unknown committed
2501
	};
unknown's avatar
unknown committed
2502 2503 2504

opt_escape:
	ESCAPE_SYM TEXT_STRING	{ $$= $2.str; }
unknown's avatar
unknown committed
2505
	| /* empty */		{ $$= (char*) "\\"; };
unknown's avatar
unknown committed
2506 2507 2508


/*
unknown's avatar
unknown committed
2509
   group by statement in select
unknown's avatar
unknown committed
2510 2511 2512 2513
*/

group_clause:
	/* empty */
2514
	| GROUP BY group_list olap_opt;
unknown's avatar
unknown committed
2515 2516

group_list:
unknown's avatar
unknown committed
2517 2518 2519
	group_list ',' order_ident order_dir
	  { if (add_group_to_list($3,(bool) $4)) YYABORT; }
	| order_ident order_dir
unknown's avatar
unknown committed
2520
	  { if (add_group_to_list($1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
2521

2522 2523
olap_opt:
	/* empty */ {}
2524
	| WITH CUBE_SYM
2525
          {
2526 2527
	    LEX *lex=Lex;
	    lex->olap = true;
2528 2529 2530 2531 2532 2533
	    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
2534
	    lex->current_select->select_lex()->olap= CUBE_TYPE;
2535
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
2536
	    YYABORT;	/* To be deleted in 4.1 */
2537
	  }
2538
	| WITH ROLLUP_SYM
2539
          {
2540 2541 2542 2543 2544 2545 2546 2547
	    LEX *lex= Lex;
	    lex->olap= true;
	    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
2548
	    lex->current_select->select_lex()->olap= ROLLUP_TYPE;
2549
	    net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "ROLLUP");
2550
	    YYABORT;	/* To be deleted in 4.1 */
2551
	  }
2552
	;
2553

unknown's avatar
unknown committed
2554
/*
unknown's avatar
unknown committed
2555
   Order by statement in select
unknown's avatar
unknown committed
2556 2557
*/

2558
opt_order_clause:
unknown's avatar
unknown committed
2559
	/* empty */
unknown's avatar
unknown committed
2560
	| order_clause;
2561 2562

order_clause:
2563 2564
	ORDER_SYM BY 
        { 
unknown's avatar
unknown committed
2565
	  LEX *lex=Lex;
2566
	  if (lex->sql_command == SQLCOM_MULTI_UPDATE)
2567
	  {
2568
	    net_printf(lex->thd, ER_WRONG_USAGE, "UPDATE", "ORDER BY");
2569
	    YYABORT;
2570
	  }	
2571
	  if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
2572
	      lex->current_select->select_lex()->olap !=
2573
	      UNSPECIFIED_OLAP_TYPE)
2574
	  {
2575
	    net_printf(lex->thd, ER_WRONG_USAGE,
2576 2577 2578 2579
		       "CUBE/ROLLUP",
		       "ORDER BY");
	    YYABORT;
	  }
unknown's avatar
unknown committed
2580
	} order_list;
unknown's avatar
unknown committed
2581 2582 2583 2584 2585

order_list:
	order_list ',' order_ident order_dir
	  { if (add_order_to_list($3,(bool) $4)) YYABORT; }
	| order_ident order_dir
unknown's avatar
unknown committed
2586
	  { if (add_order_to_list($1,(bool) $2)) YYABORT; };
unknown's avatar
unknown committed
2587 2588 2589

order_dir:
	/* empty */ { $$ =  1; }
unknown's avatar
unknown committed
2590
	| ASC  { $$ =1; }
unknown's avatar
unknown committed
2591
	| DESC { $$ =0; };
unknown's avatar
unknown committed
2592 2593 2594


limit_clause:
unknown's avatar
unknown committed
2595
	/* empty */ {}
unknown's avatar
unknown committed
2596
	| LIMIT ULONG_NUM
unknown's avatar
unknown committed
2597
	  {
2598 2599
	    LEX *lex= Lex;
	    if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
2600
	        lex->current_select->select_lex()->olap !=
2601
		UNSPECIFIED_OLAP_TYPE)
2602
	    {
2603
	      net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
2604
		        "LIMIT");
2605
	      YYABORT;
2606
	    }
2607
	    SELECT_LEX_NODE *sel= Select;
unknown's avatar
unknown committed
2608
	    sel->select_limit= $2;
unknown's avatar
unknown committed
2609
	    sel->offset_limit= 0L;
unknown's avatar
unknown committed
2610
	  }
unknown's avatar
unknown committed
2611
	| LIMIT ULONG_NUM ',' ULONG_NUM
unknown's avatar
unknown committed
2612
	  {
2613
	    LEX *lex=Lex;
2614
	    if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
unknown's avatar
unknown committed
2615
                lex->current_select->select_lex()->olap !=
2616
		UNSPECIFIED_OLAP_TYPE)
2617
	    {
2618
	      net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
2619
		        "LIMIT");
2620
	      YYABORT;
2621
	    }	      
2622
	    SELECT_LEX_NODE *sel= lex->current_select;
unknown's avatar
unknown committed
2623 2624
	    sel->select_limit= $4;
	    sel->offset_limit= $2;
unknown's avatar
unknown committed
2625
	  };
unknown's avatar
unknown committed
2626 2627 2628 2629

delete_limit_clause:
	/* empty */
	{
unknown's avatar
unknown committed
2630 2631
	  LEX *lex=Lex;
	  if (lex->sql_command == SQLCOM_MULTI_UPDATE)
2632
	  {
2633
	    net_printf(lex->thd, ER_WRONG_USAGE, "DELETE", "LIMIT");
2634
	    YYABORT;
2635
	  }
2636
	  lex->current_select->select_limit= HA_POS_ERROR;
unknown's avatar
unknown committed
2637
	}
unknown's avatar
unknown committed
2638
	| LIMIT ulonglong_num
unknown's avatar
unknown committed
2639
	{ Select->select_limit= (ha_rows) $2; };
unknown's avatar
unknown committed
2640 2641

ULONG_NUM:
unknown's avatar
unknown committed
2642
	NUM	    { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2643
	| ULONGLONG_NUM { $$= (ulong) strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
2644
	| REAL_NUM  { $$= strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2645
	| FLOAT_NUM { $$= strtoul($1.str,NULL,10); };
unknown's avatar
unknown committed
2646

unknown's avatar
unknown committed
2647
ulonglong_num:
unknown's avatar
unknown committed
2648
	NUM	    { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2649 2650
	| ULONGLONG_NUM { $$= strtoull($1.str,NULL,10); }
	| LONG_NUM  { $$= (ulonglong) strtoul($1.str,NULL,10); }
unknown's avatar
unknown committed
2651
	| REAL_NUM  { $$= strtoull($1.str,NULL,10); }
unknown's avatar
unknown committed
2652
	| FLOAT_NUM { $$= strtoull($1.str,NULL,10); };
unknown's avatar
unknown committed
2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663

procedure_clause:
	/* empty */
	| PROCEDURE ident			/* Procedure name */
	  {
	    LEX *lex=Lex;
	    lex->proc_list.elements=0;
	    lex->proc_list.first=0;
	    lex->proc_list.next= (byte**) &lex->proc_list.first;
	    if (add_proc_to_list(new Item_field(NULL,NULL,$2.str)))
	      YYABORT;
unknown's avatar
unknown committed
2664
	    current_thd->safe_to_cache_query=0;
unknown's avatar
unknown committed
2665
	  }
unknown's avatar
unknown committed
2666
	  '(' procedure_list ')';
unknown's avatar
unknown committed
2667 2668 2669 2670


procedure_list:
	/* empty */ {}
unknown's avatar
unknown committed
2671
	| procedure_list2 {};
unknown's avatar
unknown committed
2672 2673 2674

procedure_list2:
	procedure_list2 ',' procedure_item
unknown's avatar
unknown committed
2675
	| procedure_item;
unknown's avatar
unknown committed
2676 2677 2678 2679 2680 2681 2682 2683

procedure_item:
	  remember_name expr
	  {
	    if (add_proc_to_list($2))
	      YYABORT;
	    if (!$2->name)
	      $2->set_name($1,(uint) ((char*) Lex->tok_end - $1));
2684 2685 2686 2687 2688 2689
	  }
          ;


select_var_list_init:
	   {
unknown's avatar
unknown committed
2690 2691
             LEX *lex=Lex;
	     if (!lex->describe && (!(lex->result= new select_dumpvar())))
2692 2693 2694 2695
	        YYABORT;
	   }
	   select_var_list 
           ;
unknown's avatar
unknown committed
2696

unknown's avatar
unknown committed
2697
select_var_list:
2698 2699 2700 2701 2702
	   select_var_list ',' select_var_ident
	   | select_var_ident {}
           ;

select_var_ident:  '@' ident_or_text
unknown's avatar
unknown committed
2703
           {
2704
             LEX *lex=Lex;
unknown's avatar
unknown committed
2705
	     if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
unknown's avatar
unknown committed
2706 2707
	       YYABORT;
	   }
unknown's avatar
unknown committed
2708
           ;
unknown's avatar
unknown committed
2709 2710

opt_into:
unknown's avatar
unknown committed
2711
        INTO OUTFILE TEXT_STRING
unknown's avatar
unknown committed
2712
	{
2713
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2714 2715 2716 2717 2718 2719 2720
	  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
2721 2722 2723 2724
	}
	opt_field_term opt_line_term
	| INTO DUMPFILE TEXT_STRING
	{
2725
	  LEX *lex=Lex;
unknown's avatar
unknown committed
2726 2727 2728 2729 2730 2731 2732
	  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
2733
	}
2734
        | INTO select_var_list_init
unknown's avatar
unknown committed
2735 2736
	{
	  current_thd->safe_to_cache_query=0;
2737 2738
	}
        ;
unknown's avatar
unknown committed
2739

unknown's avatar
unknown committed
2740 2741 2742
/*
  DO statement
*/
unknown's avatar
unknown committed
2743

unknown's avatar
unknown committed
2744 2745 2746 2747 2748 2749 2750
do:	DO_SYM 
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DO;
	  if (!(lex->insert_list = new List_item))
	    YYABORT;
	}
unknown's avatar
unknown committed
2751
	values;
unknown's avatar
unknown committed
2752
/*
unknown's avatar
unknown committed
2753
  Drop : delete tables or index
unknown's avatar
unknown committed
2754 2755 2756
*/

drop:
2757
	DROP TABLE_SYM if_exists table_list opt_restrict
unknown's avatar
unknown committed
2758
	{
unknown's avatar
unknown committed
2759 2760 2761
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_DROP_TABLE;
	  lex->drop_if_exists = $3;
unknown's avatar
unknown committed
2762 2763 2764
	}
	| DROP INDEX ident ON table_ident {}
	  {
unknown's avatar
unknown committed
2765 2766 2767 2768
	     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
2769
						     $3.str));
2770
	     if (!lex->current_select->add_table_to_list($5,NULL, 1))
unknown's avatar
unknown committed
2771 2772 2773 2774
	      YYABORT;
	  }
	| DROP DATABASE if_exists ident
	  {
unknown's avatar
unknown committed
2775 2776 2777 2778
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_DROP_DB;
	    lex->drop_if_exists=$3;
	    lex->name=$4.str;
unknown's avatar
unknown committed
2779 2780 2781
	 }
	| DROP UDF_SYM ident
	  {
unknown's avatar
unknown committed
2782 2783 2784
	    LEX *lex=Lex;
	    lex->sql_command = SQLCOM_DROP_FUNCTION;
	    lex->udf.name=$3.str;
unknown's avatar
unknown committed
2785
	  };
unknown's avatar
unknown committed
2786 2787 2788


table_list:
2789
	table_name
unknown's avatar
unknown committed
2790
	| table_list ',' table_name;
unknown's avatar
unknown committed
2791

2792
table_name:
unknown's avatar
unknown committed
2793
	table_ident
2794
	{ if (!Select->add_table_to_list($1, NULL, 1)) YYABORT; };
unknown's avatar
unknown committed
2795 2796 2797

if_exists:
	/* empty */ { $$=0; }
unknown's avatar
unknown committed
2798
	| IF EXISTS { $$= 1; };
unknown's avatar
unknown committed
2799 2800 2801 2802 2803 2804

/*
** Insert : add new data to table
*/

insert:
unknown's avatar
unknown committed
2805
	INSERT { Lex->sql_command = SQLCOM_INSERT; } insert_lock_option opt_ignore insert2 insert_field_spec;
unknown's avatar
unknown committed
2806 2807

replace:
2808 2809 2810 2811 2812 2813
	REPLACE
	{
	  LEX *lex=Lex;	
	  lex->sql_command = SQLCOM_REPLACE;
	  lex->duplicates= DUP_REPLACE;
	}
unknown's avatar
unknown committed
2814
	replace_lock_option insert2 insert_field_spec;
unknown's avatar
unknown committed
2815 2816 2817 2818 2819

insert_lock_option:
	/* empty */	{ Lex->lock_option= TL_WRITE_CONCURRENT_INSERT; }
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; }
	| DELAYED_SYM	{ Lex->lock_option= TL_WRITE_DELAYED; }
unknown's avatar
unknown committed
2820
	| HIGH_PRIORITY { Lex->lock_option= TL_WRITE; };
unknown's avatar
unknown committed
2821 2822 2823

replace_lock_option:
	opt_low_priority {}
unknown's avatar
unknown committed
2824
	| DELAYED_SYM	{ Lex->lock_option= TL_WRITE_DELAYED; };
unknown's avatar
unknown committed
2825 2826 2827

insert2:
	INTO insert_table {}
unknown's avatar
unknown committed
2828
	| insert_table {};
unknown's avatar
unknown committed
2829 2830

insert_table:
2831
	table_name
unknown's avatar
unknown committed
2832
	{
unknown's avatar
unknown committed
2833 2834 2835 2836
	  LEX *lex=Lex;
	  lex->field_list.empty();
	  lex->many_values.empty();
	  lex->insert_list=0;
unknown's avatar
unknown committed
2837
	};
unknown's avatar
unknown committed
2838 2839 2840 2841 2842

insert_field_spec:
	opt_field_spec insert_values {}
	| SET
	  {
unknown's avatar
unknown committed
2843 2844 2845
	    LEX *lex=Lex;
	    if (!(lex->insert_list = new List_item) ||
		lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
2846 2847
	      YYABORT;
	   }
unknown's avatar
unknown committed
2848
	   ident_eq_list;
unknown's avatar
unknown committed
2849 2850 2851 2852

opt_field_spec:
	/* empty */	  { }
	| '(' fields ')'  { }
unknown's avatar
unknown committed
2853
	| '(' ')'	  { };
unknown's avatar
unknown committed
2854 2855 2856

fields:
	fields ',' insert_ident { Lex->field_list.push_back($3); }
unknown's avatar
unknown committed
2857
	| insert_ident		{ Lex->field_list.push_back($1); };
unknown's avatar
unknown committed
2858 2859 2860 2861 2862 2863 2864 2865

insert_values:
	VALUES	values_list  {}
	| SELECT_SYM
	  {
	    LEX *lex=Lex;
	    lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
				SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
unknown's avatar
unknown committed
2866
	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
2867
	    mysql_init_select(lex);
unknown's avatar
unknown committed
2868
	  }
unknown's avatar
unknown committed
2869 2870
	  select_options select_item_list select_from select_lock_type
          union {};
unknown's avatar
unknown committed
2871 2872 2873

values_list:
	values_list ','  no_braces
unknown's avatar
unknown committed
2874
	| no_braces;
unknown's avatar
unknown committed
2875 2876 2877 2878

ident_eq_list:
	ident_eq_list ',' ident_eq_value
	|
unknown's avatar
unknown committed
2879
	ident_eq_value;
unknown's avatar
unknown committed
2880 2881

ident_eq_value:
unknown's avatar
unknown committed
2882
	simple_ident equal expr_or_default
unknown's avatar
unknown committed
2883
	 {
unknown's avatar
unknown committed
2884 2885 2886
	  LEX *lex=Lex;
	  if (lex->field_list.push_back($1) ||
	      lex->insert_list->push_back($3))
unknown's avatar
unknown committed
2887
	    YYABORT;
unknown's avatar
unknown committed
2888
	 };
unknown's avatar
unknown committed
2889 2890

equal:	EQ		{}
unknown's avatar
unknown committed
2891 2892 2893 2894 2895 2896 2897
	| SET_VAR	{}
	;

opt_equal:
	/* empty */	{}
	| equal		{}
	;
unknown's avatar
unknown committed
2898 2899 2900 2901 2902 2903 2904 2905 2906

no_braces:
	 '('
	 {
	    if (!(Lex->insert_list = new List_item))
	      YYABORT;
	 }
	 opt_values ')'
	 {
unknown's avatar
unknown committed
2907 2908
	  LEX *lex=Lex;
	  if (lex->many_values.push_back(lex->insert_list))
unknown's avatar
unknown committed
2909
	    YYABORT;
unknown's avatar
unknown committed
2910
	 };
unknown's avatar
unknown committed
2911 2912 2913

opt_values:
	/* empty */ {}
unknown's avatar
unknown committed
2914
	| values;
unknown's avatar
unknown committed
2915 2916

values:
unknown's avatar
unknown committed
2917
	values ','  expr_or_default
unknown's avatar
unknown committed
2918 2919 2920 2921
	{
	  if (Lex->insert_list->push_back($3))
	    YYABORT;
	}
unknown's avatar
unknown committed
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932
	| expr_or_default
	  {
	    if (Lex->insert_list->push_back($1))
	      YYABORT;
	  }
	;

expr_or_default:
	expr 	  { $$= $1;}
	| DEFAULT {$$= new Item_default(); }
	;
unknown's avatar
unknown committed
2933 2934 2935 2936

/* Update rows in a table */

update:
2937
        UPDATE_SYM 
2938
	{ 
2939 2940
	  LEX *lex= Lex;
          lex->sql_command= SQLCOM_UPDATE;
2941
          lex->select_lex.init_order();
2942
        }
unknown's avatar
unknown committed
2943
        opt_low_priority opt_ignore join_table_list SET update_list where_clause opt_order_clause delete_limit_clause;
unknown's avatar
unknown committed
2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954

update_list:
	update_list ',' simple_ident equal expr
	{
	  if (add_item_to_list($3) || add_value_to_list($5))
	    YYABORT;
	}
	| simple_ident equal expr
	  {
	    if (add_item_to_list($1) || add_value_to_list($3))
	      YYABORT;
unknown's avatar
unknown committed
2955
	  };
unknown's avatar
unknown committed
2956 2957 2958

opt_low_priority:
	/* empty */	{ Lex->lock_option= current_thd->update_lock_default; }
unknown's avatar
unknown committed
2959
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
2960 2961 2962 2963

/* Delete rows from a table */

delete:
2964
	DELETE_SYM
2965
	{ 
2966 2967 2968
	  LEX *lex= Lex;
	  lex->sql_command= SQLCOM_DELETE;
	  lex->select_lex.options= 0;
unknown's avatar
unknown committed
2969
	  lex->lock_option= lex->thd->update_lock_default;
2970
	  lex->select_lex.init_order();
unknown's avatar
unknown committed
2971
	}
unknown's avatar
unknown committed
2972
	opt_delete_options single_multi	{};
2973 2974

single_multi:
unknown's avatar
unknown committed
2975 2976
 	FROM table_name where_clause opt_order_clause delete_limit_clause {}
	| table_wild_list
unknown's avatar
unknown committed
2977 2978 2979 2980
	  { mysql_init_multi_delete(Lex); }
	   FROM join_table_list where_clause
	| FROM table_wild_list
	  { mysql_init_multi_delete(Lex); }
unknown's avatar
unknown committed
2981
	  USING join_table_list where_clause;
unknown's avatar
unknown committed
2982 2983 2984

table_wild_list:
	  table_wild_one {}
unknown's avatar
unknown committed
2985
	  | table_wild_list ',' table_wild_one {};
unknown's avatar
unknown committed
2986 2987 2988 2989

table_wild_one:
	 ident opt_wild
	 {
2990 2991
	    if (!Select->add_table_to_list(new Table_ident($1), NULL, 1,
					   TL_WRITE))
unknown's avatar
unknown committed
2992 2993 2994 2995
	      YYABORT;
         }
	 | ident '.' ident opt_wild
	   {
2996 2997
	     if (!Select->add_table_to_list(new Table_ident($1, $3, 0), NULL,
					    1, TL_WRITE))
unknown's avatar
unknown committed
2998
	      YYABORT;
unknown's avatar
unknown committed
2999
	   };
unknown's avatar
unknown committed
3000 3001 3002

opt_wild:
	/* empty */	{} 
unknown's avatar
unknown committed
3003
	| '.' '*'	{};
unknown's avatar
unknown committed
3004 3005


3006
opt_delete_options:
unknown's avatar
unknown committed
3007
	/* empty */	{}
unknown's avatar
unknown committed
3008
	| opt_delete_option opt_delete_options {};
3009 3010

opt_delete_option:
3011
	QUICK		{ Select->options|= OPTION_QUICK; }
unknown's avatar
unknown committed
3012
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
3013

3014
truncate:
unknown's avatar
unknown committed
3015
	TRUNCATE_SYM opt_table_sym table_name
3016
	{
3017
	  LEX* lex= Lex;
3018
	  lex->sql_command= SQLCOM_TRUNCATE;
3019
	  lex->select_lex.options= 0;
3020 3021
	  lex->select_lex.init_order();
	  lex->lock_option= lex->thd->update_lock_default; };
3022

unknown's avatar
unknown committed
3023 3024
opt_table_sym:
	/* empty */
unknown's avatar
unknown committed
3025
	| TABLE_SYM;
3026
 
unknown's avatar
unknown committed
3027 3028
/* Show things */

unknown's avatar
unknown committed
3029 3030 3031 3032 3033 3034 3035
show:	SHOW 
	{ 
	  LEX *lex=Lex;
	  lex->wild=0;
	  bzero((char*) &lex->create_info,sizeof(lex->create_info));
	}
	show_param;
unknown's avatar
unknown committed
3036 3037 3038 3039 3040

show_param:
	DATABASES wild
	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
	| TABLES opt_db wild
unknown's avatar
unknown committed
3041
	  {
3042
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3043
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3044 3045
	    lex->select_lex.db= $2;
	    lex->select_lex.options= 0;
unknown's avatar
unknown committed
3046
	   }
unknown's avatar
unknown committed
3047
	| TABLE_SYM STATUS_SYM opt_db wild
unknown's avatar
unknown committed
3048
	  {
3049
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3050
	    lex->sql_command= SQLCOM_SHOW_TABLES;
3051 3052
	    lex->select_lex.options|= SELECT_DESCRIBE;
	    lex->select_lex.db= $3;
unknown's avatar
unknown committed
3053
	  }
3054
	| OPEN_SYM TABLES opt_db wild
unknown's avatar
unknown committed
3055
	  {
3056
	    LEX *lex= Lex;
unknown's avatar
unknown committed
3057
	    lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
3058 3059
	    lex->select_lex.db= $3;
	    lex->select_lex.options= 0;
3060
	  }
unknown's avatar
unknown committed
3061
	| opt_full COLUMNS from_or_in table_ident opt_db wild
unknown's avatar
unknown committed
3062 3063
	  {
	    Lex->sql_command= SQLCOM_SHOW_FIELDS;
unknown's avatar
unknown committed
3064 3065
	    if ($5)
	      $4->change_db($5);
3066
	    if (!Select->add_table_to_list($4, NULL, 0))
unknown's avatar
unknown committed
3067 3068
	      YYABORT;
	  }
unknown's avatar
unknown committed
3069
        | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ 
3070 3071
	  TEXT_STRING AND MASTER_LOG_POS_SYM EQ ulonglong_num
	  AND MASTER_SERVER_ID_SYM EQ
unknown's avatar
unknown committed
3072 3073 3074 3075 3076
	ULONG_NUM
          {
	    Lex->sql_command = SQLCOM_SHOW_NEW_MASTER;
	    Lex->mi.log_file_name = $8.str;
	    Lex->mi.pos = $12;
3077
	    Lex->mi.server_id = $16;
unknown's avatar
unknown committed
3078
          }
3079
        | BINARY LOGS_SYM
unknown's avatar
unknown committed
3080 3081
          {
	    Lex->sql_command = SQLCOM_SHOW_BINLOGS;
3082 3083 3084 3085 3086
          }
        | SLAVE HOSTS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_HOSTS;
          }
unknown's avatar
unknown committed
3087
        | BINLOG_SYM EVENTS_SYM binlog_in binlog_from
unknown's avatar
unknown committed
3088
          {
3089 3090 3091 3092
	    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;
unknown's avatar
unknown committed
3093
          } limit_clause
unknown's avatar
unknown committed
3094 3095 3096 3097 3098
	| keys_or_index FROM table_ident opt_db
	  {
	    Lex->sql_command= SQLCOM_SHOW_KEYS;
	    if ($4)
	      $3->change_db($4);
3099
	    if (!Select->add_table_to_list($3, NULL, 0))
unknown's avatar
unknown committed
3100 3101
	      YYABORT;
	  }
unknown's avatar
unknown committed
3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117
	| 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;
	  }
        | COUNT_SYM '(' '*' ')' WARNINGS 
3118
          { (void) create_select_for_variable("warning_count"); }
unknown's avatar
unknown committed
3119
        | COUNT_SYM '(' '*' ')' ERRORS 
3120
	  { (void) create_select_for_variable("error_count"); }
unknown's avatar
unknown committed
3121 3122 3123 3124
        | WARNINGS {Select->offset_limit=0L;} limit_clause
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
        | ERRORS {Select->offset_limit=0L;} limit_clause
          { Lex->sql_command = SQLCOM_SHOW_ERRORS;}  
unknown's avatar
unknown committed
3125 3126
	| STATUS_SYM wild
	  { Lex->sql_command= SQLCOM_SHOW_STATUS; }
unknown's avatar
unknown committed
3127 3128
        | INNOBASE_SYM STATUS_SYM
          { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS;}
unknown's avatar
unknown committed
3129 3130
	| opt_full PROCESSLIST_SYM
	  { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;}
3131
	| opt_var_type VARIABLES wild
unknown's avatar
unknown committed
3132
	  {
3133 3134
	    THD *thd= current_thd;
	    thd->lex.sql_command= SQLCOM_SHOW_VARIABLES;
unknown's avatar
unknown committed
3135
	    thd->lex.option_type= (enum_var_type) $1;
3136
	  }
3137 3138
	| CHAR_SYM SET wild
	  { Lex->sql_command= SQLCOM_SHOW_CHARSETS; }
unknown's avatar
unknown committed
3139 3140
	| LOGS_SYM
	  { Lex->sql_command= SQLCOM_SHOW_LOGS; }
unknown's avatar
unknown committed
3141
	| GRANTS FOR_SYM user
unknown's avatar
unknown committed
3142 3143 3144 3145 3146 3147
	  {
	    LEX *lex=Lex;
	    lex->sql_command= SQLCOM_SHOW_GRANTS;
	    lex->grant_user=$3;
	    lex->grant_user->password.str=NullS;
	  }
unknown's avatar
unknown committed
3148
	| CREATE DATABASE opt_with_if_not_exists ident
unknown's avatar
unknown committed
3149 3150
	  {
	    Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
unknown's avatar
unknown committed
3151 3152
	    Lex->create_info.options=$3;
	    Lex->name=$4.str;
unknown's avatar
unknown committed
3153
	  }
unknown's avatar
unknown committed
3154 3155 3156
        | CREATE TABLE_SYM table_ident
          {
	    Lex->sql_command = SQLCOM_SHOW_CREATE;
3157
	    if(!Select->add_table_to_list($3, NULL,0))
unknown's avatar
unknown committed
3158 3159 3160 3161 3162
	      YYABORT;
	  }
        | MASTER_SYM STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_MASTER_STAT;
unknown's avatar
unknown committed
3163
          }
unknown's avatar
unknown committed
3164 3165 3166
        | SLAVE STATUS_SYM
          {
	    Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
unknown's avatar
unknown committed
3167
          };
unknown's avatar
unknown committed
3168 3169 3170

opt_db:
	/* empty */  { $$= 0; }
unknown's avatar
unknown committed
3171
	| from_or_in ident { $$= $2.str; };
unknown's avatar
unknown committed
3172 3173 3174

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

unknown's avatar
unknown committed
3177 3178
opt_full:
	/* empty */ { Lex->verbose=0; }
unknown's avatar
unknown committed
3179
	| FULL	    { Lex->verbose=1; };
unknown's avatar
unknown committed
3180

unknown's avatar
unknown committed
3181 3182
from_or_in:
	FROM
unknown's avatar
unknown committed
3183
	| IN_SYM;
unknown's avatar
unknown committed
3184

unknown's avatar
unknown committed
3185 3186
binlog_in:
	/* empty */ { Lex->mi.log_file_name = 0; }
unknown's avatar
unknown committed
3187
        | IN_SYM TEXT_STRING { Lex->mi.log_file_name = $2.str; };
unknown's avatar
unknown committed
3188 3189 3190

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


unknown's avatar
unknown committed
3194 3195 3196 3197
/* A Oracle compatible synonym for show */
describe:
	describe_command table_ident
	{
unknown's avatar
unknown committed
3198 3199 3200 3201
	  LEX *lex=Lex;
	  lex->wild=0;
	  lex->verbose=0;
	  lex->sql_command=SQLCOM_SHOW_FIELDS;
3202
	  if (!Select->add_table_to_list($2, NULL,0))
unknown's avatar
unknown committed
3203 3204 3205
	    YYABORT;
	}
	opt_describe_column
unknown's avatar
unknown committed
3206
	| describe_command select
unknown's avatar
unknown committed
3207 3208 3209 3210 3211
          { 
	    LEX *lex=Lex;
	    lex->select_lex.options|= SELECT_DESCRIBE; 
	    lex->describe=1;
	  };
unknown's avatar
unknown committed
3212 3213 3214 3215


describe_command:
	DESC
unknown's avatar
unknown committed
3216
	| DESCRIBE;
unknown's avatar
unknown committed
3217 3218 3219 3220

opt_describe_column:
	/* empty */	{}
	| text_string	{ Lex->wild= $1; }
unknown's avatar
unknown committed
3221
	| ident
unknown's avatar
unknown committed
3222
	  { Lex->wild= new String((const char*) $1.str,$1.length,default_charset_info); };
unknown's avatar
unknown committed
3223 3224 3225 3226 3227


/* flush things */

flush:
unknown's avatar
unknown committed
3228 3229 3230 3231 3232
	FLUSH_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_FLUSH; lex->type=0;
	}
unknown's avatar
unknown committed
3233
	flush_options;
unknown's avatar
unknown committed
3234 3235 3236

flush_options:
	flush_options ',' flush_option
unknown's avatar
unknown committed
3237
	| flush_option;
unknown's avatar
unknown committed
3238 3239

flush_option:
3240
	table_or_tables	{ Lex->type|= REFRESH_TABLES; } opt_table_list
unknown's avatar
unknown committed
3241
	| TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; }
unknown's avatar
unknown committed
3242
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; }
unknown's avatar
unknown committed
3243 3244 3245 3246
	| 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
3247 3248
        | SLAVE         { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
3249 3250
	| DES_KEY_FILE	{ Lex->type|= REFRESH_DES_KEY_FILE; }
 	| RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
unknown's avatar
unknown committed
3251

unknown's avatar
unknown committed
3252
opt_table_list:
3253 3254
	/* empty */  {;}
	| table_list {;};
unknown's avatar
unknown committed
3255

unknown's avatar
unknown committed
3256
reset:
unknown's avatar
unknown committed
3257 3258 3259 3260
	RESET_SYM
	{
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_RESET; lex->type=0;
unknown's avatar
unknown committed
3261
	} reset_options;
unknown's avatar
unknown committed
3262 3263
reset_options:
	reset_options ',' reset_option
unknown's avatar
unknown committed
3264
	| reset_option;
unknown's avatar
unknown committed
3265 3266

reset_option:
unknown's avatar
unknown committed
3267 3268
        SLAVE                 { Lex->type|= REFRESH_SLAVE; }
        | MASTER_SYM          { Lex->type|= REFRESH_MASTER; }
unknown's avatar
unknown committed
3269
	| QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE;};
unknown's avatar
unknown committed
3270

unknown's avatar
unknown committed
3271
purge:
unknown's avatar
unknown committed
3272 3273 3274 3275 3276 3277
	PURGE
	{
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_PURGE;
	  lex->type=0;
	}
unknown's avatar
unknown committed
3278 3279 3280
        MASTER_SYM LOGS_SYM TO_SYM TEXT_STRING
         {
	   Lex->to_log = $6.str;
unknown's avatar
unknown committed
3281
         } ;
unknown's avatar
unknown committed
3282

unknown's avatar
unknown committed
3283 3284 3285
/* kill threads */

kill:
3286
	KILL_SYM expr
unknown's avatar
unknown committed
3287
	{
unknown's avatar
unknown committed
3288
	  LEX *lex=Lex;
unknown's avatar
unknown committed
3289
	  if ($2->fix_fields(lex->thd, 0, &$2))
unknown's avatar
unknown committed
3290
	  { 
3291
	    send_error(lex->thd, ER_SET_CONSTANTS_ONLY);
unknown's avatar
unknown committed
3292 3293 3294 3295
	    YYABORT;
	  }
          lex->sql_command=SQLCOM_KILL;
	  lex->thread_id= (ulong) $2->val_int();
unknown's avatar
unknown committed
3296
	};
unknown's avatar
unknown committed
3297 3298 3299 3300

/* change database */

use:	USE_SYM ident
unknown's avatar
unknown committed
3301 3302
	{
	  LEX *lex=Lex;
3303 3304
	  lex->sql_command=SQLCOM_CHANGE_DB;
	  lex->select_lex.db= $2.str;
unknown's avatar
unknown committed
3305
	};
unknown's avatar
unknown committed
3306 3307 3308

/* import, export of files */

3309
load:	LOAD DATA_SYM load_data_lock opt_local INFILE TEXT_STRING
unknown's avatar
unknown committed
3310
	{
unknown's avatar
unknown committed
3311 3312 3313 3314
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_LOAD;
	  lex->local_file= $4;
	  if (!(lex->exchange= new sql_exchange($6.str,0)))
unknown's avatar
unknown committed
3315
	    YYABORT;
unknown's avatar
unknown committed
3316
	  lex->field_list.empty();
unknown's avatar
unknown committed
3317 3318 3319 3320
	}
	opt_duplicate INTO TABLE_SYM table_ident opt_field_term opt_line_term
	opt_ignore_lines opt_field_spec
	{
3321
	  if (!Select->add_table_to_list($11, NULL, 1))
unknown's avatar
unknown committed
3322 3323 3324
	    YYABORT;
	}
        |
unknown's avatar
unknown committed
3325
	LOAD TABLE_SYM table_ident FROM MASTER_SYM
unknown's avatar
unknown committed
3326 3327
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_TABLE;
3328
	  if (!Select->add_table_to_list($3, NULL, 1))
unknown's avatar
unknown committed
3329
	    YYABORT;
unknown's avatar
unknown committed
3330 3331

        }
3332 3333 3334 3335
        |
	LOAD DATA_SYM FROM MASTER_SYM
        {
	  Lex->sql_command = SQLCOM_LOAD_MASTER_DATA;
unknown's avatar
unknown committed
3336
        };
unknown's avatar
unknown committed
3337 3338 3339

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

unknown's avatar
unknown committed
3342 3343 3344
load_data_lock:
	/* empty */	{ Lex->lock_option= current_thd->update_lock_default; }
	| CONCURRENT	{ Lex->lock_option= TL_WRITE_CONCURRENT_INSERT ; }
unknown's avatar
unknown committed
3345
	| LOW_PRIORITY	{ Lex->lock_option= TL_WRITE_LOW_PRIORITY; };
unknown's avatar
unknown committed
3346 3347


unknown's avatar
unknown committed
3348 3349 3350
opt_duplicate:
	/* empty */	{ Lex->duplicates=DUP_ERROR; }
	| REPLACE	{ Lex->duplicates=DUP_REPLACE; }
unknown's avatar
unknown committed
3351
	| IGNORE_SYM	{ Lex->duplicates=DUP_IGNORE; };
unknown's avatar
unknown committed
3352 3353 3354

opt_field_term:
	/* empty */
unknown's avatar
unknown committed
3355
	| COLUMNS field_term_list;
unknown's avatar
unknown committed
3356 3357 3358

field_term_list:
	field_term_list field_term
unknown's avatar
unknown committed
3359
	| field_term;
unknown's avatar
unknown committed
3360 3361 3362 3363

field_term:
	TERMINATED BY text_string { Lex->exchange->field_term= $3;}
	| OPTIONALLY ENCLOSED BY text_string
unknown's avatar
unknown committed
3364 3365 3366 3367 3368
	  {
	    LEX *lex=Lex;
	    lex->exchange->enclosed= $4;
	    lex->exchange->opt_enclosed=1;
	  }
unknown's avatar
unknown committed
3369
	| ENCLOSED BY text_string { Lex->exchange->enclosed= $3;}
unknown's avatar
unknown committed
3370
	| ESCAPED BY text_string  { Lex->exchange->escaped= $3;};
unknown's avatar
unknown committed
3371 3372 3373

opt_line_term:
	/* empty */
unknown's avatar
unknown committed
3374
	| LINES line_term_list;
unknown's avatar
unknown committed
3375 3376 3377

line_term_list:
	line_term_list line_term
unknown's avatar
unknown committed
3378
	| line_term;
unknown's avatar
unknown committed
3379 3380 3381

line_term:
	TERMINATED BY text_string { Lex->exchange->line_term= $3;}
unknown's avatar
unknown committed
3382
	| STARTING BY text_string { Lex->exchange->line_start= $3;};
unknown's avatar
unknown committed
3383 3384 3385 3386

opt_ignore_lines:
	/* empty */
	| IGNORE_SYM NUM LINES
unknown's avatar
unknown committed
3387
	  { Lex->exchange->skip_lines=atol($2.str); };
unknown's avatar
unknown committed
3388 3389 3390 3391

/* Common definitions */

text_literal:
3392
	TEXT_STRING { $$ = new Item_string($1.str,$1.length,current_thd->thd_charset); }
3393
	| UNDERSCORE_CHARSET TEXT_STRING { $$ = new Item_string($2.str,$2.length,Lex->charset); }
unknown's avatar
unknown committed
3394
	| text_literal TEXT_STRING
unknown's avatar
unknown committed
3395
	{ ((Item_string*) $1)->append($2.str,$2.length); };
unknown's avatar
unknown committed
3396 3397

text_string:
3398
	TEXT_STRING	{ $$=  new String($1.str,$1.length,current_thd->thd_charset); }
unknown's avatar
unknown committed
3399 3400
	| HEX_NUM
	  {
3401
	    Item *tmp = new Item_varbinary($1.str,$1.length);
unknown's avatar
unknown committed
3402
	    $$= tmp ? tmp->val_str((String*) 0) : (String*) 0;
unknown's avatar
unknown committed
3403
	  };
unknown's avatar
unknown committed
3404 3405 3406
param_marker:
        '?' 
        {
3407 3408
	  LEX *lex=Lex;
          if (current_thd->prepare_command)
unknown's avatar
unknown committed
3409
          {     
3410 3411
            lex->param_list.push_back($$=new Item_param());      
            lex->param_count++;
unknown's avatar
unknown committed
3412 3413 3414 3415 3416 3417
          }
          else 
          {
            yyerror("You have an error in your SQL syntax");
            YYABORT;
          }
unknown's avatar
unknown committed
3418
        };
unknown's avatar
unknown committed
3419 3420 3421 3422
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
3423
	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
unknown's avatar
unknown committed
3424 3425 3426 3427
	| 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;}
3428
	| HEX_NUM	{ $$ =	new Item_varbinary($1.str,$1.length);}
unknown's avatar
unknown committed
3429 3430
	| DATE_SYM text_literal { $$ = $2; }
	| TIME_SYM text_literal { $$ = $2; }
unknown's avatar
unknown committed
3431
	| TIMESTAMP text_literal { $$ = $2; };
unknown's avatar
unknown committed
3432 3433 3434 3435 3436 3437 3438

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

insert_ident:
	simple_ident	 { $$=$1; }
unknown's avatar
unknown committed
3439
	| table_wild	 { $$=$1; };
unknown's avatar
unknown committed
3440 3441 3442 3443

table_wild:
	ident '.' '*' { $$ = new Item_field(NullS,$1.str,"*"); }
	| ident '.' ident '.' '*'
unknown's avatar
unknown committed
3444 3445
	{ $$ = new Item_field((current_thd->client_capabilities &
   CLIENT_NO_SCHEMA ? NullS : $1.str),$3.str,"*"); };
unknown's avatar
unknown committed
3446 3447

order_ident:
unknown's avatar
unknown committed
3448
	expr { $$=$1; };
unknown's avatar
unknown committed
3449 3450 3451

simple_ident:
	ident
unknown's avatar
unknown committed
3452
	{
3453 3454
	  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
3455
	}
unknown's avatar
unknown committed
3456
	| ident '.' ident
unknown's avatar
unknown committed
3457
	{
3458 3459
	  SELECT_LEX_NODE *sel=Select;
	  $$ = !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
3460
	}
unknown's avatar
unknown committed
3461
	| '.' ident '.' ident
unknown's avatar
unknown committed
3462
	{
3463 3464
	  SELECT_LEX_NODE *sel=Select;
	  $$ = !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
3465
	}
unknown's avatar
unknown committed
3466
	| ident '.' ident '.' ident
unknown's avatar
unknown committed
3467
	{
3468 3469
	  SELECT_LEX_NODE *sel=Select;
	  $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((current_thd->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str);
unknown's avatar
unknown committed
3470
	};
unknown's avatar
unknown committed
3471 3472 3473 3474 3475


field_ident:
	ident			{ $$=$1;}
	| ident '.' ident	{ $$=$3;}	/* Skipp schema name in create*/
unknown's avatar
unknown committed
3476
	| '.' ident		{ $$=$2;}	/* For Delphi */;
unknown's avatar
unknown committed
3477 3478 3479 3480

table_ident:
	ident			{ $$=new Table_ident($1); }
	| ident '.' ident	{ $$=new Table_ident($1,$3,0);}
unknown's avatar
unknown committed
3481 3482
	| '.' ident		{ $$=new Table_ident($2);}
   /* For Delphi */;
unknown's avatar
unknown committed
3483 3484 3485 3486 3487

ident:
	IDENT	    { $$=$1; }
	| keyword
	{
unknown's avatar
unknown committed
3488
	  LEX *lex;
unknown's avatar
unknown committed
3489 3490
	  $$.str=sql_strmake($1.str,$1.length);
	  $$.length=$1.length;
unknown's avatar
unknown committed
3491 3492
	  if ((lex=Lex)->next_state != STATE_END)
	    lex->next_state=STATE_OPERATOR_OR_IDENT;
unknown's avatar
unknown committed
3493
	};
unknown's avatar
unknown committed
3494 3495 3496

ident_or_text:
	ident 		{ $$=$1;}
unknown's avatar
unknown committed
3497
	| TEXT_STRING	{ $$=$1;}
unknown's avatar
unknown committed
3498
	| LEX_HOSTNAME	{ $$=$1;};
unknown's avatar
unknown committed
3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511

user:
	ident_or_text
	{
	  if (!($$=(LEX_USER*) sql_alloc(sizeof(st_lex_user))))
	    YYABORT;
	  $$->user = $1; $$->host.str=NullS;
	  }
	| ident_or_text '@' ident_or_text
	  {
	  if (!($$=(LEX_USER*) sql_alloc(sizeof(st_lex_user))))
	      YYABORT;
	    $$->user = $1; $$->host=$3;
unknown's avatar
unknown committed
3512
	  };
unknown's avatar
unknown committed
3513 3514 3515 3516 3517 3518

/* Keyword that we allow for identifiers */

keyword:
	ACTION			{}
	| AFTER_SYM		{}
3519
	| AGAINST		{}
unknown's avatar
unknown committed
3520
	| AGGREGATE_SYM		{}
unknown's avatar
unknown committed
3521
	| AUTO_INC		{}
unknown's avatar
unknown committed
3522 3523
	| AVG_ROW_LENGTH	{}
	| AVG_SYM		{}
unknown's avatar
unknown committed
3524
	| BACKUP_SYM		{}
unknown's avatar
unknown committed
3525
	| BEGIN_SYM		{}
unknown's avatar
unknown committed
3526
	| BERKELEY_DB_SYM	{}
unknown's avatar
unknown committed
3527
	| BINLOG_SYM		{}
unknown's avatar
unknown committed
3528 3529
	| BIT_SYM		{}
	| BOOL_SYM		{}
unknown's avatar
unknown committed
3530
	| BOOLEAN_SYM		{}
3531
	| BYTE_SYM		{}
unknown's avatar
unknown committed
3532
	| CACHE_SYM		{}
3533
	| CHANGED		{}
3534
	| CHARSET		{}
unknown's avatar
unknown committed
3535 3536
	| CHECKSUM_SYM		{}
	| CHECK_SYM		{}
3537
	| CIPHER_SYM		{}
unknown's avatar
unknown committed
3538
	| CLIENT_SYM		{}
3539
	| CLOSE_SYM		{}
unknown's avatar
unknown committed
3540
	| COMMENT_SYM		{}
unknown's avatar
unknown committed
3541
	| COMMITTED_SYM		{}
unknown's avatar
unknown committed
3542
	| COMMIT_SYM		{}
unknown's avatar
unknown committed
3543
	| COMPRESSED_SYM	{}
unknown's avatar
unknown committed
3544
	| CONCURRENT		{}
3545
	| CUBE_SYM		{}
unknown's avatar
unknown committed
3546 3547 3548 3549 3550
	| DATA_SYM		{}
	| DATETIME		{}
	| DATE_SYM		{}
	| DAY_SYM		{}
	| DELAY_KEY_WRITE_SYM	{}
unknown's avatar
unknown committed
3551 3552
	| DES_KEY_FILE		{}
	| DIRECTORY_SYM		{}
unknown's avatar
unknown committed
3553
	| DO_SYM		{}
unknown's avatar
unknown committed
3554
	| DUMPFILE		{}
3555
	| DUAL_SYM		{}
unknown's avatar
unknown committed
3556 3557 3558 3559
	| DYNAMIC_SYM		{}
	| END			{}
	| ENUM			{}
	| ESCAPE_SYM		{}
unknown's avatar
unknown committed
3560
	| EVENTS_SYM		{}
unknown's avatar
unknown committed
3561
	| EXECUTE_SYM		{}
unknown's avatar
unknown committed
3562
	| EXTENDED_SYM		{}
3563
	| FAST_SYM		{}
unknown's avatar
unknown committed
3564 3565
	| DISABLE_SYM		{}
	| ENABLE_SYM		{}
unknown's avatar
unknown committed
3566
	| FULL			{}
unknown's avatar
unknown committed
3567 3568 3569 3570
	| FILE_SYM		{}
	| FIRST_SYM		{}
	| FIXED_SYM		{}
	| FLUSH_SYM		{}
unknown's avatar
unknown committed
3571
	| GRANTS		{}
unknown's avatar
unknown committed
3572
	| GLOBAL_SYM		{}
unknown's avatar
unknown committed
3573
	| HEAP_SYM		{}
3574
	| HANDLER_SYM		{}
unknown's avatar
unknown committed
3575 3576 3577
	| HOSTS_SYM		{}
	| HOUR_SYM		{}
	| IDENTIFIED_SYM	{}
unknown's avatar
unknown committed
3578
	| INDEXES		{}
unknown's avatar
unknown committed
3579
	| ISOLATION		{}
unknown's avatar
unknown committed
3580
	| ISAM_SYM		{}
unknown's avatar
unknown committed
3581
	| ISSUER_SYM		{}
unknown's avatar
unknown committed
3582
	| INNOBASE_SYM		{}
3583
	| INSERT_METHOD		{}
unknown's avatar
unknown committed
3584
	| IO_THREAD		{}
3585
	| LAST_SYM		{}
unknown's avatar
unknown committed
3586
	| LEVEL_SYM		{}
unknown's avatar
unknown committed
3587
	| LOCAL_SYM		{}
unknown's avatar
unknown committed
3588
	| LOCKS_SYM		{}
unknown's avatar
unknown committed
3589 3590 3591 3592 3593 3594 3595 3596 3597 3598
	| 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
3599 3600 3601
	| MAX_CONNECTIONS_PER_HOUR	 {}
	| MAX_QUERIES_PER_HOUR	{}
	| MAX_UPDATES_PER_HOUR	{}
3602
	| MEDIUM_SYM		{}
unknown's avatar
unknown committed
3603 3604 3605 3606
	| MERGE_SYM		{}
	| MINUTE_SYM		{}
	| MIN_ROWS		{}
	| MODIFY_SYM		{}
unknown's avatar
unknown committed
3607
	| MODE_SYM		{}
unknown's avatar
unknown committed
3608 3609 3610 3611
	| MONTH_SYM		{}
	| MYISAM_SYM		{}
	| NATIONAL_SYM		{}
	| NCHAR_SYM		{}
3612
	| NEXT_SYM		{}
unknown's avatar
unknown committed
3613
	| NEW_SYM		{}
unknown's avatar
unknown committed
3614
	| NO_SYM		{}
3615
	| NONE_SYM		{}
3616
	| OPEN_SYM		{}
unknown's avatar
unknown committed
3617
	| PACK_KEYS_SYM		{}
3618
	| PARTIAL		{}
unknown's avatar
unknown committed
3619
	| PASSWORD		{}
3620
	| PREV_SYM		{}
unknown's avatar
unknown committed
3621 3622
	| PROCESS		{}
	| PROCESSLIST_SYM	{}
unknown's avatar
unknown committed
3623
	| QUERY_SYM		{}
3624
	| QUICK			{}
unknown's avatar
unknown committed
3625
	| RAID_0_SYM		{}
unknown's avatar
unknown committed
3626 3627
	| RAID_CHUNKS		{}
	| RAID_CHUNKSIZE	{}
unknown's avatar
unknown committed
3628
	| RAID_STRIPED_SYM	{}
unknown's avatar
unknown committed
3629
	| RAID_TYPE		{}
unknown's avatar
unknown committed
3630 3631
	| RELAY_LOG_FILE_SYM	{}
	| RELAY_LOG_POS_SYM	{}
unknown's avatar
unknown committed
3632 3633
	| RELOAD		{}
	| REPAIR		{}
unknown's avatar
unknown committed
3634
	| REPEATABLE_SYM	{}
unknown's avatar
unknown committed
3635
	| REPLICATION		{}
unknown's avatar
unknown committed
3636
	| RESET_SYM		{}
3637
	| RESOURCES		{}
unknown's avatar
unknown committed
3638
	| RESTORE_SYM		{}
unknown's avatar
unknown committed
3639
	| ROLLBACK_SYM		{}
3640
	| ROLLUP_SYM		{}
unknown's avatar
unknown committed
3641 3642 3643 3644
	| ROWS_SYM		{}
	| ROW_FORMAT_SYM	{}
	| ROW_SYM		{}
	| SECOND_SYM		{}
3645
	| SERIAL_SYM		{}
unknown's avatar
unknown committed
3646 3647
	| SERIALIZABLE_SYM	{}
	| SESSION_SYM		{}
unknown's avatar
unknown committed
3648
	| SIGNED_SYM		{}
3649
	| SIMPLE_SYM		{}
unknown's avatar
unknown committed
3650
	| SHARE_SYM		{}
unknown's avatar
unknown committed
3651
	| SHUTDOWN		{}
unknown's avatar
unknown committed
3652
	| SLAVE			{}
unknown's avatar
unknown committed
3653
	| SQL_CACHE_SYM		{}
unknown's avatar
unknown committed
3654
	| SQL_BUFFER_RESULT	{}
unknown's avatar
unknown committed
3655
	| SQL_NO_CACHE_SYM	{}
unknown's avatar
unknown committed
3656
	| SQL_THREAD		{}
unknown's avatar
unknown committed
3657 3658 3659 3660
	| START_SYM		{}
	| STATUS_SYM		{}
	| STOP_SYM		{}
	| STRING_SYM		{}
unknown's avatar
unknown committed
3661
	| SUBJECT_SYM		{}
unknown's avatar
unknown committed
3662
	| SUPER_SYM		{}
unknown's avatar
unknown committed
3663 3664
	| TEMPORARY		{}
	| TEXT_SYM		{}
unknown's avatar
unknown committed
3665
	| TRANSACTION_SYM	{}
3666
	| TRUNCATE_SYM		{}
unknown's avatar
unknown committed
3667 3668 3669 3670
	| TIMESTAMP		{}
	| TIME_SYM		{}
	| TYPE_SYM		{}
	| UDF_SYM		{}
unknown's avatar
unknown committed
3671
	| UNCOMMITTED_SYM	{}
unknown's avatar
unknown committed
3672
	| USE_FRM		{}
unknown's avatar
unknown committed
3673
	| VARIABLES		{}
3674
	| VALUE_SYM		{}
unknown's avatar
unknown committed
3675
	| WORK_SYM		{}
unknown's avatar
unknown committed
3676 3677
	| YEAR_SYM		{}
	;
unknown's avatar
unknown committed
3678 3679 3680 3681 3682 3683

/* Option functions */

set:
	SET opt_option
	{
unknown's avatar
unknown committed
3684 3685
	  LEX *lex=Lex;
	  lex->sql_command= SQLCOM_SET_OPTION;
unknown's avatar
unknown committed
3686 3687
	  lex->option_type=OPT_DEFAULT;
	  lex->var_list.empty();
unknown's avatar
unknown committed
3688
	}
unknown's avatar
unknown committed
3689
	option_value_list;
unknown's avatar
unknown committed
3690 3691 3692

opt_option:
	/* empty */ {}
unknown's avatar
unknown committed
3693
	| OPTION {};
unknown's avatar
unknown committed
3694 3695

option_value_list:
unknown's avatar
unknown committed
3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707
	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
3708
	| GLOBAL_SYM	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
3709 3710 3711 3712 3713 3714
	| LOCAL_SYM	{ $$=OPT_SESSION; }
	| SESSION_SYM	{ $$=OPT_SESSION; }
	;

opt_var_ident_type:
	/* empty */		{ $$=OPT_DEFAULT; }
unknown's avatar
unknown committed
3715
	| GLOBAL_SYM '.'	{ $$=OPT_GLOBAL; }
unknown's avatar
unknown committed
3716 3717 3718
	| LOCAL_SYM '.'		{ $$=OPT_SESSION; }
	| SESSION_SYM '.'	{ $$=OPT_SESSION; }
	;
unknown's avatar
unknown committed
3719 3720

option_value:
unknown's avatar
unknown committed
3721
	'@' ident_or_text equal expr
unknown's avatar
unknown committed
3722
	{
unknown's avatar
unknown committed
3723
	  Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
unknown's avatar
unknown committed
3724
	}
unknown's avatar
unknown committed
3725
	| internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
3726
	  {
unknown's avatar
unknown committed
3727 3728
	    LEX *lex=Lex;
	    lex->var_list.push_back(new set_var(lex->option_type, $1, $3));
unknown's avatar
unknown committed
3729
	  }
unknown's avatar
unknown committed
3730
	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
unknown's avatar
unknown committed
3731 3732 3733 3734 3735 3736 3737 3738
	  {
	    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
3739
						find_sys_var("tx_isolation"),
unknown's avatar
unknown committed
3740
						new Item_int((int32) $4)));
unknown's avatar
unknown committed
3741
	  }
unknown's avatar
unknown committed
3742
	| CHAR_SYM SET opt_equal set_expr_or_default
unknown's avatar
unknown committed
3743
	{
unknown's avatar
unknown committed
3744 3745 3746 3747
	  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
3748 3749
	}
	| PASSWORD equal text_or_password
unknown's avatar
unknown committed
3750
	  {
unknown's avatar
unknown committed
3751 3752 3753 3754 3755 3756 3757 3758 3759
	    THD *thd=current_thd;
	    LEX_USER *user;
	    if (!(user=(LEX_USER*) sql_alloc(sizeof(LEX_USER))))
	      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
3760
	  {
unknown's avatar
unknown committed
3761 3762
	    Lex->var_list.push_back(new set_var_password($3,$5));
	  }
3763
	;
unknown's avatar
unknown committed
3764

unknown's avatar
unknown committed
3765 3766 3767 3768 3769 3770 3771 3772
internal_variable_name:
	ident
	{
	  sys_var *tmp=find_sys_var($1.str, $1.length);
	  if (!tmp)
	    YYABORT;
	  $$=tmp;
	}
3773
        ;
unknown's avatar
unknown committed
3774 3775 3776 3777 3778 3779 3780

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; }
	;
unknown's avatar
unknown committed
3781
  
unknown's avatar
unknown committed
3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793
text_or_password:
	TEXT_STRING { $$=$1.str;}
	| PASSWORD '(' TEXT_STRING ')'
	  {
	    if (!$3.length)
	      $$=$3.str;
	    else
	    {
	      char *buff=(char*) sql_alloc(HASH_PASSWORD_LENGTH+1);
	      make_scrambled_password(buff,$3.str);
	      $$=buff;
	    }
3794 3795
	  }
          ;
unknown's avatar
unknown committed
3796

unknown's avatar
unknown committed
3797

unknown's avatar
unknown committed
3798
set_expr_or_default:
unknown's avatar
unknown committed
3799 3800
	expr      { $$=$1; }
	| DEFAULT { $$=0; }
3801 3802
	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
unknown's avatar
unknown committed
3803
	;
unknown's avatar
unknown committed
3804 3805


unknown's avatar
unknown committed
3806 3807 3808 3809 3810 3811 3812
/* Lock function */

lock:
	LOCK_SYM table_or_tables
	{
	  Lex->sql_command=SQLCOM_LOCK_TABLES;
	}
unknown's avatar
unknown committed
3813
	table_lock_list;
unknown's avatar
unknown committed
3814 3815 3816

table_or_tables:
	TABLE_SYM
unknown's avatar
unknown committed
3817
	| TABLES;
unknown's avatar
unknown committed
3818 3819 3820

table_lock_list:
	table_lock
unknown's avatar
unknown committed
3821
	| table_lock_list ',' table_lock;
unknown's avatar
unknown committed
3822 3823 3824

table_lock:
	table_ident opt_table_alias lock_option
3825 3826 3827 3828
	{
	  if (!Select->add_table_to_list($1, $2, 0, (thr_lock_type) $3))
	   YYABORT;
	}
3829
        ;
unknown's avatar
unknown committed
3830 3831 3832 3833 3834

lock_option:
	READ_SYM	{ $$=TL_READ_NO_INSERT; }
	| WRITE_SYM     { $$=current_thd->update_lock_default; }
	| LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; }
3835 3836
	| READ_SYM LOCAL_SYM { $$= TL_READ; }
        ;
unknown's avatar
unknown committed
3837 3838

unlock:
3839 3840
	UNLOCK_SYM table_or_tables { Lex->sql_command=SQLCOM_UNLOCK_TABLES; }
        ;
unknown's avatar
unknown committed
3841 3842


3843
/*
unknown's avatar
unknown committed
3844
** Handler: direct access to ISAM functions
3845 3846 3847 3848 3849
*/

handler:
	HANDLER_SYM table_ident OPEN_SYM opt_table_alias
	{
3850 3851 3852
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_OPEN;
	  if (!lex->current_select->add_table_to_list($2, $4, 0))
3853 3854 3855 3856
	    YYABORT;
	}
	| HANDLER_SYM table_ident CLOSE_SYM
	{
3857 3858 3859
	  LEX *lex= Lex;
	  lex->sql_command = SQLCOM_HA_CLOSE;
	  if (!lex->current_select->add_table_to_list($2, 0, 0))
3860 3861
	    YYABORT;
	}
unknown's avatar
unknown committed
3862
	| HANDLER_SYM table_ident READ_SYM
3863
	{
unknown's avatar
unknown committed
3864 3865 3866
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_HA_READ;
	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
3867 3868 3869
	  lex->current_select->select_limit= 1;
	  lex->current_select->offset_limit= 0L;
	  if (!lex->current_select->add_table_to_list($2, 0, 0))
3870
	    YYABORT;
unknown's avatar
unknown committed
3871
        }
3872 3873
        handler_read_or_scan where_clause limit_clause { }
        ;
3874

unknown's avatar
unknown committed
3875 3876
handler_read_or_scan:
	handler_scan_function         { Lex->backup_dir= 0; }
3877 3878
        | ident handler_rkey_function { Lex->backup_dir= $1.str; }
        ;
unknown's avatar
unknown committed
3879 3880 3881

handler_scan_function:
	FIRST_SYM  { Lex->ha_read_mode = RFIRST; }
3882 3883
	| NEXT_SYM { Lex->ha_read_mode = RNEXT;  }
        ;
unknown's avatar
unknown committed
3884 3885 3886 3887 3888 3889

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;  }
3890 3891
	| handler_rkey_mode
	{
unknown's avatar
unknown committed
3892 3893
	  LEX *lex=Lex;
	  lex->ha_read_mode = RKEY;
unknown's avatar
unknown committed
3894
	  lex->ha_rkey_mode=$1;
unknown's avatar
unknown committed
3895
	  if (!(lex->insert_list = new List_item))
3896
	    YYABORT;
3897 3898
	} '(' values ')' { }
        ;
3899 3900

handler_rkey_mode:
unknown's avatar
unknown committed
3901 3902 3903 3904
	  EQ     { $$=HA_READ_KEY_EXACT;   }
	| GE     { $$=HA_READ_KEY_OR_NEXT; }
	| LE     { $$=HA_READ_KEY_OR_PREV; }
	| GT_SYM { $$=HA_READ_AFTER_KEY;   }
3905 3906
	| LT     { $$=HA_READ_BEFORE_KEY;  }
        ;
3907

unknown's avatar
unknown committed
3908 3909 3910 3911 3912
/* GRANT / REVOKE */

revoke:
	REVOKE
	{
unknown's avatar
unknown committed
3913 3914 3915 3916 3917
	  LEX *lex=Lex;
	  lex->sql_command = SQLCOM_REVOKE;
	  lex->users_list.empty();
	  lex->columns.empty();
	  lex->grant= lex->grant_tot_col=0;
3918
	  lex->select_lex.db=0;
3919 3920
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
3921
	  bzero((char*) &lex->mqh, sizeof(lex->mqh));
unknown's avatar
unknown committed
3922
	}
unknown's avatar
unknown committed
3923
	grant_privileges ON opt_table FROM user_list;
unknown's avatar
unknown committed
3924 3925 3926 3927

grant:
	GRANT
	{
unknown's avatar
unknown committed
3928 3929 3930
	  LEX *lex=Lex;
	  lex->users_list.empty();
	  lex->columns.empty();
3931 3932
	  lex->sql_command = SQLCOM_GRANT;
	  lex->grant= lex->grant_tot_col= 0;
3933
	  lex->select_lex.db= 0;
3934 3935
	  lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
	  lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
3936
	  bzero(&(lex->mqh),sizeof(lex->mqh));
unknown's avatar
unknown committed
3937 3938
	}
	grant_privileges ON opt_table TO_SYM user_list
unknown's avatar
unknown committed
3939
	require_clause grant_options;
unknown's avatar
unknown committed
3940 3941 3942

grant_privileges:
	grant_privilege_list {}
unknown's avatar
unknown committed
3943
	| ALL PRIVILEGES	{ Lex->grant = GLOBAL_ACLS;}
3944 3945
	| ALL			{ Lex->grant = GLOBAL_ACLS;}
        ;
unknown's avatar
unknown committed
3946 3947 3948

grant_privilege_list:
	grant_privilege
unknown's avatar
unknown committed
3949
	| grant_privilege_list ',' grant_privilege;
unknown's avatar
unknown committed
3950 3951

grant_privilege:
unknown's avatar
unknown committed
3952 3953 3954 3955 3956 3957
	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
	| DELETE_SYM	{ Lex->grant |= DELETE_ACL;}
	| USAGE		{}
unknown's avatar
unknown committed
3958 3959 3960 3961
	| 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
3962
	| EXECUTE_SYM	{ Lex->grant |= EXECUTE_ACL;}
unknown's avatar
unknown committed
3963 3964 3965 3966
	| 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
3967 3968 3969 3970 3971 3972 3973 3974
	| 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
3975

unknown's avatar
unknown committed
3976

3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988
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
3989 3990 3991 3992
	{
	  LEX *lex=Lex;
	  if (lex->x509_subject)
	  {
3993
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT");
unknown's avatar
unknown committed
3994 3995 3996 3997 3998 3999 4000 4001 4002
	    YYABORT;
	  }
	  lex->x509_subject=$2.str;
	}
	| ISSUER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->x509_issuer)
	  {
4003
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER");
unknown's avatar
unknown committed
4004 4005 4006 4007 4008 4009 4010 4011 4012
	    YYABORT;
	  }
	  lex->x509_issuer=$2.str;
	}
	| CIPHER_SYM TEXT_STRING
	{
	  LEX *lex=Lex;
	  if (lex->ssl_cipher)
	  {
4013
	    net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER");
unknown's avatar
unknown committed
4014 4015 4016 4017 4018
	    YYABORT;
	  }
	  lex->ssl_cipher=$2.str;
	}
	;
unknown's avatar
unknown committed
4019
 
unknown's avatar
unknown committed
4020 4021 4022
opt_table:
	'*'
	  {
4023
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4024
	    lex->current_select->select_lex()->db= lex->thd->db;
unknown's avatar
unknown committed
4025
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4026 4027
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4028
	    {
4029
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
4030
	      YYABORT;
unknown's avatar
unknown committed
4031
	    }
unknown's avatar
unknown committed
4032 4033 4034
	  }
	| ident '.' '*'
	  {
4035
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4036
	    lex->current_select->select_lex()->db = $1.str;
unknown's avatar
unknown committed
4037
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4038 4039
	      lex->grant = DB_ACLS & ~GRANT_ACL;
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4040
	    {
4041
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4042 4043 4044 4045 4046
	      YYABORT;
	    }
	  }
	| '*' '.' '*'
	  {
4047
	    LEX *lex= Lex;
unknown's avatar
unknown committed
4048
	    lex->current_select->select_lex()->db = NULL;
unknown's avatar
unknown committed
4049 4050
	    if (lex->grant == GLOBAL_ACLS)
	      lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
unknown's avatar
unknown committed
4051
	    else if (lex->columns.elements)
unknown's avatar
unknown committed
4052
	    {
4053
	      send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE);
unknown's avatar
unknown committed
4054 4055 4056 4057 4058
	      YYABORT;
	    }
	  }
	| table_ident
	  {
unknown's avatar
unknown committed
4059
	    LEX *lex=Lex;
4060
	    if (!lex->current_select->add_table_to_list($1,NULL,0))
unknown's avatar
unknown committed
4061
	      YYABORT;
unknown's avatar
unknown committed
4062
	    if (lex->grant == GLOBAL_ACLS)
unknown's avatar
unknown committed
4063
	      lex->grant =  TABLE_ACLS & ~GRANT_ACL;
4064 4065
	  }
          ;
unknown's avatar
unknown committed
4066 4067 4068


user_list:
4069 4070 4071 4072 4073 4074 4075
	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
4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095


grant_user:
	user IDENTIFIED_SYM BY TEXT_STRING
	{
	   $$=$1; $1->password=$4;
	   if ($4.length)
	   {
	     char *buff=(char*) sql_alloc(HASH_PASSWORD_LENGTH+1);
	     if (buff)
	     {
	       make_scrambled_password(buff,$4.str);
	       $1->password.str=buff;
	       $1->password.length=HASH_PASSWORD_LENGTH;
	     }
	  }
	}
	| user IDENTIFIED_SYM BY PASSWORD TEXT_STRING
	  { $$=$1; $1->password=$5 ; }
	| user
4096 4097
	  { $$=$1; $1->password.str=NullS; }
        ;
unknown's avatar
unknown committed
4098 4099 4100


opt_column_list:
unknown's avatar
unknown committed
4101 4102 4103 4104 4105
	/* empty */
	{
	  LEX *lex=Lex;
	  lex->grant |= lex->which_columns;
	}
unknown's avatar
unknown committed
4106
	| '(' column_list ')';
unknown's avatar
unknown committed
4107 4108 4109

column_list:
	column_list ',' column_list_id
unknown's avatar
unknown committed
4110
	| column_list_id;
unknown's avatar
unknown committed
4111 4112 4113 4114

column_list_id:
	ident
	{
4115
	  String *new_str = new String((const char*) $1.str,$1.length,default_charset_info);
unknown's avatar
unknown committed
4116 4117
	  List_iterator <LEX_COLUMN> iter(Lex->columns);
	  class LEX_COLUMN *point;
unknown's avatar
unknown committed
4118
	  LEX *lex=Lex;
unknown's avatar
unknown committed
4119 4120
	  while ((point=iter++))
	  {
4121 4122
	    if (!my_strcasecmp(system_charset_info,
                               point->column.ptr(), new_str->ptr()))
unknown's avatar
unknown committed
4123 4124
		break;
	  }
unknown's avatar
unknown committed
4125
	  lex->grant_tot_col|= lex->which_columns;
unknown's avatar
unknown committed
4126
	  if (point)
unknown's avatar
unknown committed
4127
	    point->rights |= lex->which_columns;
unknown's avatar
unknown committed
4128
	  else
unknown's avatar
unknown committed
4129
	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
4130 4131
	}
        ;
unknown's avatar
unknown committed
4132

unknown's avatar
unknown committed
4133 4134

require_clause: /* empty */
4135
        | REQUIRE_SYM require_list 
4136 4137 4138
          {
            Lex->ssl_type=SSL_TYPE_SPECIFIED;
          }
4139
        | REQUIRE_SYM SSL_SYM
4140 4141 4142
          {
            Lex->ssl_type=SSL_TYPE_ANY;
          }
4143
        | REQUIRE_SYM X509_SYM
4144 4145 4146 4147 4148 4149 4150
          {
            Lex->ssl_type=SSL_TYPE_X509;
          }
	| REQUIRE_SYM NONE_SYM
	  {
	    Lex->ssl_type=SSL_TYPE_NONE;
	  }
4151
          ;
unknown's avatar
unknown committed
4152

unknown's avatar
unknown committed
4153
grant_options:
unknown's avatar
unknown committed
4154
	/* empty */ {}
unknown's avatar
unknown committed
4155
	| WITH grant_option_list;
unknown's avatar
unknown committed
4156

unknown's avatar
unknown committed
4157 4158
grant_option_list:
	grant_option_list grant_option {}
4159 4160
	| grant_option {}
        ;
unknown's avatar
unknown committed
4161 4162 4163

grant_option:
	GRANT OPTION { Lex->grant |= GRANT_ACL;}
4164
        | MAX_QUERIES_PER_HOUR ULONG_NUM
unknown's avatar
unknown committed
4165
        {
4166
	  Lex->mqh.questions=$2;
4167
	  Lex->mqh.bits |= 1;
4168
	}
4169
        | MAX_UPDATES_PER_HOUR ULONG_NUM
4170
        {
4171
	  Lex->mqh.updates=$2;
4172
	  Lex->mqh.bits |= 2;
4173
	}
4174
        | MAX_CONNECTIONS_PER_HOUR ULONG_NUM
4175
        {
4176
	  Lex->mqh.connections=$2;
4177
	  Lex->mqh.bits |= 4;
4178 4179
	}
        ;
4180

unknown's avatar
unknown committed
4181
begin:
unknown's avatar
unknown committed
4182
	BEGIN_SYM   { Lex->sql_command = SQLCOM_BEGIN;} opt_work;
unknown's avatar
unknown committed
4183 4184 4185

opt_work:
	/* empty */ {}
4186 4187
	| WORK_SYM {;}
        ;
unknown's avatar
unknown committed
4188 4189

commit:
unknown's avatar
unknown committed
4190
	COMMIT_SYM   { Lex->sql_command = SQLCOM_COMMIT;};
unknown's avatar
unknown committed
4191 4192

rollback:
unknown's avatar
unknown committed
4193
	ROLLBACK_SYM { Lex->sql_command = SQLCOM_ROLLBACK;};
4194 4195 4196


/*
unknown's avatar
unknown committed
4197
   UNIONS : glue selects together
4198 4199 4200 4201
*/


union:	
4202 4203
	/* empty */ {}
	| union_list;
4204 4205

union_list:
unknown's avatar
unknown committed
4206
	UNION_SYM    union_option
4207 4208 4209 4210 4211
	{
	  LEX *lex=Lex;
	  if (lex->exchange)
	  {
	    /* Only the last SELECT can have  INTO...... */
4212
	    net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO");
4213
	    YYABORT;
unknown's avatar
unknown committed
4214
	  } 
4215
	  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4216
	  {
4217
	    send_error(lex->thd, ER_SYNTAX_ERROR);
4218 4219
	    YYABORT;
	  }
4220
	  if (mysql_new_select(lex, 0))
4221
	    YYABORT;
4222
	  lex->current_select->linkage=UNION_TYPE;
unknown's avatar
unknown committed
4223
	}
4224 4225
	select_init
	;
4226 4227

union_opt:
4228 4229
	union {}
	| optional_order_or_limit {};
4230 4231

optional_order_or_limit:
4232 4233 4234
	/* empty */ {}
	|
	  {
unknown's avatar
unknown committed
4235
	    LEX *lex=Lex;
4236
	    if (!lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
4237
	    {
4238
	      send_error(lex->thd, ER_SYNTAX_ERROR);
4239 4240
	      YYABORT;
	    }
unknown's avatar
unknown committed
4241
	    SELECT_LEX *sel= lex->current_select->select_lex();
4242 4243 4244 4245 4246
	    sel->master_unit()->global_parameters= 
	      sel->master_unit();
	    lex->current_select= sel->master_unit();
	    lex->current_select->select_limit=
	      lex->thd->variables.select_limit;
4247
	  }
unknown's avatar
unknown committed
4248
	opt_order_clause limit_clause
4249
	;
unknown's avatar
unknown committed
4250 4251

union_option:
4252
	/* empty */ {}
unknown's avatar
unknown committed
4253
	| ALL {Select->master_unit()->union_option= 1;};
4254

unknown's avatar
unknown committed
4255
singleval_subselect:
unknown's avatar
unknown committed
4256 4257 4258 4259 4260
	subselect_start singleval_subselect_init
	subselect_end
	{
	  $$= $2;
	};
4261

unknown's avatar
unknown committed
4262
singleval_subselect_init:
unknown's avatar
unknown committed
4263 4264
	select_init
	{
unknown's avatar
unknown committed
4265
	  $$= new Item_singleval_subselect(current_thd,
4266 4267
					   Lex->current_select->master_unit()->
                                             first_select());
unknown's avatar
unknown committed
4268
	};
unknown's avatar
unknown committed
4269 4270

exists_subselect:
unknown's avatar
unknown committed
4271 4272 4273 4274 4275
	subselect_start exists_subselect_init
	subselect_end
	{
	  $$= $2;
	};
unknown's avatar
unknown committed
4276 4277

exists_subselect_init:
unknown's avatar
unknown committed
4278 4279
	select_init
	{
unknown's avatar
unknown committed
4280
	  $$= new Item_exists_subselect(current_thd,
4281 4282
					Lex->current_select->master_unit()->
					  first_select());
unknown's avatar
unknown committed
4283
	};
4284 4285

subselect_start:
unknown's avatar
unknown committed
4286 4287 4288 4289 4290
	'('
	{
	  if (mysql_new_select(Lex, 1))
	    YYABORT;
	};
4291 4292

subselect_end:
unknown's avatar
unknown committed
4293 4294 4295
	')'
	{
	  LEX *lex=Lex;
4296
	  lex->current_select = lex->current_select->outer_select();
unknown's avatar
unknown committed
4297
	};