17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
21
#define DRIZZLE_SERVER_SQL_LEX_H
20
#ifndef DRIZZLED_SQL_LEX_H
21
#define DRIZZLED_SQL_LEX_H
24
24
@defgroup Semantic_Analysis Semantic Analysis
26
#include <drizzled/message/table.pb.h>
28
#include "drizzled/slot/function.h"
29
#include "drizzled/name_resolution_context.h"
30
#include "drizzled/item/subselect.h"
31
#include "drizzled/item/param.h"
32
#include "drizzled/item/outer_ref.h"
33
#include "drizzled/table_list.h"
34
#include "drizzled/function/math/real.h"
35
#include "drizzled/alter_drop.h"
36
#include "drizzled/alter_column.h"
37
#include "drizzled/key.h"
38
#include "drizzled/foreign_key.h"
39
#include "drizzled/item/param.h"
40
#include "drizzled/index_hint.h"
41
#include "drizzled/statement.h"
45
class select_result_interceptor;
29
47
/* YACC and LEX Definitions */
31
49
/* These may not be declared yet */
38
56
The following hack is needed because mysql_yacc.cc does not define
39
57
YYSTYPE before including this file
45
#define LEX_YYSTYPE void *
47
#if defined(DRIZZLE_LEX)
48
#include "lex_symbol.h"
50
#define LEX_YYSTYPE YYSTYPE *
52
#define LEX_YYSTYPE void *
58
When a command is added here, be sure it's also added in mysqld.cc
59
in "struct show_var_st status_vars[]= {" ...
61
If the command returns a result set or is not allowed in stored
62
functions or triggers, please also make sure that
63
sp_get_flags_for_command (sp_head.cc) returns proper flags for the
67
enum enum_sql_command {
68
SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_ALTER_TABLE,
69
SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
70
SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
71
SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
72
SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
73
SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
74
SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
75
SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS,
76
SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS,
77
SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
78
SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
79
SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
80
SQLCOM_OPTIMIZE, SQLCOM_CHECK,
81
SQLCOM_ASSIGN_TO_KEYCACHE,
82
SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
83
SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
84
SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT,
85
SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
86
SQLCOM_BEGIN, SQLCOM_CHANGE_MASTER,
88
SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
89
SQLCOM_SHOW_OPEN_TABLES,
90
SQLCOM_SHOW_SLAVE_HOSTS, SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
91
SQLCOM_SHOW_BINLOG_EVENTS,
92
SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
94
SQLCOM_BINLOG_BASE64_EVENT,
97
When a command is added here, be sure it's also added in mysqld.cc
98
in "struct show_var_st status_vars[]= {" ...
100
/* This should be the last !!! */
61
# include <drizzled/set_var.h>
62
# include <drizzled/item/func.h>
64
# define LEX_YYSTYPE void *
66
# if defined(DRIZZLE_LEX)
67
# include <drizzled/lex_symbol.h>
68
# include <drizzled/sql_yacc.h>
69
# define LEX_YYSTYPE YYSTYPE *
71
# define LEX_YYSTYPE void *
72
# endif /* defined(DRIZZLE_LEX) */
73
# endif /* DRIZZLE_YACC */
74
#endif /* DRIZZLE_SERVER */
104
76
// describe/explain types
105
77
#define DESCRIBE_NORMAL 1
113
85
typedef List<Item> List_item;
115
/* SERVERS CACHE CHANGES */
116
typedef struct st_lex_server_options
119
uint32_t server_name_length;
120
char *server_name, *host, *db, *username, *password, *scheme, *owner;
121
} LEX_SERVER_OPTIONS;
123
typedef struct st_lex_master_info
125
char *host, *user, *password, *log_file_name;
126
uint32_t port, connect_retry;
127
float heartbeat_period;
131
Enum is used for making it possible to detect if the user
132
changed variable or if it should be left at old value
134
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
135
ssl, ssl_verify_server_cert, heartbeat_opt;
136
char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
137
char *relay_log_name;
138
uint32_t relay_log_pos;
142
87
enum sub_select_type
144
UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
145
EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
150
UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
100
UNSPECIFIED_OLAP_TYPE,
153
105
enum tablespace_op_type
155
NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
159
String names used to print a statement with index hints.
160
Keep in sync with index_hint_type.
162
extern const char * index_hint_type_name[];
163
typedef unsigned char index_clause_map;
166
Bits in index_clause_map : one for each possible FOR clause in
167
USE/FORCE/IGNORE INDEX index hint specification
169
#define INDEX_HINT_MASK_JOIN (1)
170
#define INDEX_HINT_MASK_GROUP (1 << 1)
171
#define INDEX_HINT_MASK_ORDER (1 << 2)
173
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
174
INDEX_HINT_MASK_ORDER)
176
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint */
177
class Index_hint : public Sql_alloc
180
/* The type of the hint : USE/FORCE/IGNORE */
181
enum index_hint_type type;
182
/* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
183
index_clause_map clause;
185
The index name. Empty (str=NULL) name represents an empty list
190
Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
191
char *str, uint32_t length) :
192
type(type_arg), clause(clause_arg)
195
key_name.length= length;
198
void print(THD *thd, String *str);
202
The state of the lex parsing for selects
113
The state of the lex parsing for selects
204
115
master and slaves are pointers to select_lex.
205
116
master is pointer to upper level node.
206
117
slave is pointer to lower level node
348
259
static void *operator new(size_t size, MEM_ROOT *mem_root)
349
260
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
350
static void operator delete(void *ptr __attribute__((unused)),
351
size_t size __attribute__((unused)))
261
static void operator delete(void *, size_t)
352
262
{ TRASH(ptr, size); }
353
static void operator delete(void *ptr __attribute__((unused)),
354
MEM_ROOT *mem_root __attribute__((unused)))
263
static void operator delete(void *, MEM_ROOT *)
356
st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
357
virtual ~st_select_lex_node() {}
358
inline st_select_lex_node* get_master() { return master; }
265
Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
266
virtual ~Select_Lex_Node() {}
267
inline Select_Lex_Node* get_master() { return master; }
359
268
virtual void init_query();
360
269
virtual void init_select();
361
void include_down(st_select_lex_node *upper);
362
void include_neighbour(st_select_lex_node *before);
363
void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
364
void include_global(st_select_lex_node **plink);
270
void include_down(Select_Lex_Node *upper);
271
void include_neighbour(Select_Lex_Node *before);
272
void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
273
void include_global(Select_Lex_Node **plink);
367
virtual st_select_lex_unit* master_unit()= 0;
368
virtual st_select_lex* outer_select()= 0;
369
virtual st_select_lex* return_after_parsing()= 0;
276
virtual Select_Lex_Unit* master_unit()= 0;
277
virtual Select_Lex* outer_select()= 0;
278
virtual Select_Lex* return_after_parsing()= 0;
371
280
virtual bool set_braces(bool value);
372
281
virtual bool inc_in_sum_expr();
432
340
Pointer to 'last' select or pointer to unit where stored
433
341
global parameters for union
435
st_select_lex *global_parameters;
343
Select_Lex *global_parameters;
436
344
//node on wich we should return current_select pointer after parsing subquery
437
st_select_lex *return_to;
345
Select_Lex *return_to;
438
346
/* LIMIT clause runtime counters */
439
347
ha_rows select_limit_cnt, offset_limit_cnt;
440
348
/* not NULL if unit used in subselect, point to subselect item */
441
349
Item_subselect *item;
442
350
/* thread handler */
445
SELECT_LEX for hidden SELECT in onion which process global
353
Select_Lex for hidden SELECT in onion which process global
446
354
ORDER BY and LIMIT
448
st_select_lex *fake_select_lex;
356
Select_Lex *fake_select_lex;
450
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
358
Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
451
359
bool describe; /* union exec() called for EXPLAIN */
453
361
void init_query();
454
st_select_lex_unit* master_unit();
455
st_select_lex* outer_select();
456
st_select_lex* first_select()
458
return reinterpret_cast<st_select_lex*>(slave);
460
st_select_lex_unit* next_unit()
462
return reinterpret_cast<st_select_lex_unit*>(next);
464
st_select_lex* return_after_parsing() { return return_to; }
362
Select_Lex_Unit* master_unit();
363
Select_Lex* outer_select();
364
Select_Lex* first_select()
366
return reinterpret_cast<Select_Lex*>(slave);
368
Select_Lex_Unit* next_unit()
370
return reinterpret_cast<Select_Lex_Unit*>(next);
372
Select_Lex* return_after_parsing() { return return_to; }
465
373
void exclude_level();
466
374
void exclude_tree();
468
376
/* UNION methods */
469
bool prepare(THD *thd, select_result *result, uint32_t additional_options);
377
bool prepare(Session *session, select_result *result,
378
uint64_t additional_options);
472
381
inline void unclean() { cleaned= 0; }
475
384
void print(String *str, enum_query_type query_type);
477
bool add_fake_select_lex(THD *thd);
478
void init_prepare_fake_select_lex(THD *thd);
386
bool add_fake_select_lex(Session *session);
387
void init_prepare_fake_select_lex(Session *session);
479
388
bool change_result(select_result_interceptor *result,
480
389
select_result_interceptor *old_result);
481
void set_limit(st_select_lex *values);
482
void set_thd(THD *thd_arg) { thd= thd_arg; }
483
inline bool is_union ();
390
void set_limit(Select_Lex *values);
391
void set_session(Session *session_arg) { session= session_arg; }
392
inline bool is_union ();
485
friend void lex_start(THD *thd);
394
friend void lex_start(Session *session);
486
395
friend int subselect_union_engine::exec();
488
397
List<Item> *get_unit_column_types();
491
typedef class st_select_lex_unit SELECT_LEX_UNIT;
494
SELECT_LEX - store information of parsed SELECT statment
401
Select_Lex - store information of parsed SELECT statment
496
class st_select_lex: public st_select_lex_node
403
class Select_Lex: public Select_Lex_Node
499
406
Name_resolution_context context;
501
Item *where, *having; /* WHERE & HAVING clauses */
408
/* An Item representing the WHERE clause */
410
/* An Item representing the HAVING clause */
502
412
/* Saved values of the WHERE and HAVING clauses*/
503
Item::cond_result cond_value, having_value;
413
Item::cond_result cond_value;
414
Item::cond_result having_value;
504
415
/* point on lex in which it was created, used in view subquery detection */
506
417
enum olap_type olap;
507
418
/* FROM clause - points to the beginning of the TableList::next_local list. */
509
SQL_LIST group_list; /* GROUP BY clause. */
510
List<Item> item_list; /* list of fields & expressions */
511
List<String> interval_list;
512
bool is_item_list_lookup;
514
Despite their names, the following are used in unions. This should
517
List<Item_real_func> *ftfunc_list;
518
List<Item_real_func> ftfunc_list_alloc;
420
SQL_LIST group_list; /* GROUP BY clause. */
421
List<Item> item_list; /* list of fields & expressions */
422
List<String> interval_list;
423
bool is_item_list_lookup;
519
424
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
520
425
List<TableList> top_join_list; /* join list of the top level */
521
426
List<TableList> *join_list; /* list for the currently parsed join */
613
512
1 - aggregate functions are used in this select,
614
513
defined as SUM_FUNC_USED.
616
uint8_t full_group_by_flag;
515
std::bitset<2> full_group_by_flag;
617
516
void init_query();
618
517
void init_select();
619
st_select_lex_unit* master_unit();
620
st_select_lex_unit* first_inner_unit()
622
return (st_select_lex_unit*) slave;
624
st_select_lex* outer_select();
625
st_select_lex* next_select() { return (st_select_lex*) next; }
626
st_select_lex* next_select_in_list()
628
return (st_select_lex*) link_next;
630
st_select_lex_node** next_select_in_list_addr()
518
Select_Lex_Unit* master_unit();
519
Select_Lex_Unit* first_inner_unit()
521
return (Select_Lex_Unit*) slave;
523
Select_Lex* outer_select();
524
Select_Lex* next_select()
526
return (Select_Lex*) next;
528
Select_Lex* next_select_in_list()
530
return (Select_Lex*) link_next;
532
Select_Lex_Node** next_select_in_list_addr()
632
534
return &link_next;
634
st_select_lex* return_after_parsing()
536
Select_Lex* return_after_parsing()
636
538
return master_unit()->return_after_parsing();
639
void mark_as_dependent(st_select_lex *last);
541
void mark_as_dependent(Select_Lex *last);
641
543
bool set_braces(bool value);
642
544
bool inc_in_sum_expr();
643
545
uint32_t get_in_sum_expr();
645
bool add_item_to_list(THD *thd, Item *item);
646
bool add_group_to_list(THD *thd, Item *item, bool asc);
647
bool add_order_to_list(THD *thd, Item *item, bool asc);
648
TableList* add_table_to_list(THD *thd, Table_ident *table,
650
uint32_t table_options,
651
thr_lock_type flags= TL_UNLOCK,
652
List<Index_hint> *hints= 0,
653
LEX_STRING *option= 0);
547
bool add_item_to_list(Session *session, Item *item);
548
bool add_group_to_list(Session *session, Item *item, bool asc);
549
bool add_order_to_list(Session *session, Item *item, bool asc);
550
TableList* add_table_to_list(Session *session,
553
uint32_t table_options,
554
thr_lock_type flags= TL_UNLOCK,
555
List<Index_hint> *hints= 0,
556
LEX_STRING *option= 0);
654
557
TableList* get_table_list();
655
bool init_nested_join(THD *thd);
656
TableList *end_nested_join(THD *thd);
657
TableList *nest_last_join(THD *thd);
558
bool init_nested_join(Session *session);
559
TableList *end_nested_join(Session *session);
560
TableList *nest_last_join(Session *session);
658
561
void add_joined_table(TableList *table);
659
562
TableList *convert_right_join();
660
563
List<Item>* get_item_list();
988
@brief This class represents the character input stream consumed during
991
In addition to consuming the input stream, this class performs some
992
comment pre processing, by filtering out out of bound special text
993
from the query input stream.
994
Two buffers, with pointers inside each buffers, are maintained in
995
parallel. The 'raw' buffer is the original query text, which may
996
contain out-of-bound comments. The 'cpp' (for comments pre processor)
997
is the pre-processed buffer that contains only the query text that
998
should be seen once out-of-bound data is removed.
1001
class Lex_input_stream
1004
Lex_input_stream(THD *thd, const char* buff, unsigned int length);
1005
~Lex_input_stream();
1010
When echo is true, characters parsed from the raw input stream are
1011
preserved. When false, characters parsed are silently ignored.
1012
@param echo the echo mode.
1014
void set_echo(bool echo)
1020
Skip binary from the input stream.
1021
@param n number of bytes to accept.
1023
void skip_binary(int n)
1027
memcpy(m_cpp_ptr, m_ptr, n);
1034
Get a character, and advance in the stream.
1035
@return the next character to parse.
1046
Get the last character accepted.
1047
@return the last character accepted.
1055
Look at the next character to parse, but do not accept it.
1063
Look ahead at some character to parse.
1064
@param n offset of the character to look up
1072
Cancel the effect of the last yyGet() or yySkip().
1073
Note that the echo mode should not change between calls to yyGet / yySkip
1074
and yyUnget. The caller is responsible for ensuring that.
1084
Accept a character, by advancing the input stream.
1089
*m_cpp_ptr++ = *m_ptr++;
1095
Accept multiple characters at once.
1096
@param n the number of characters to accept.
1102
memcpy(m_cpp_ptr, m_ptr, n);
1109
End of file indicator for the query text to parse.
1110
@return true if there are no more characters to parse
1114
return (m_ptr >= m_end_of_query);
1118
End of file indicator for the query text to parse.
1119
@param n number of characters expected
1120
@return true if there are less than n characters to parse
1124
return ((m_ptr + n) >= m_end_of_query);
1127
/** Get the raw query buffer. */
1128
const char *get_buf()
1133
/** Get the pre-processed query buffer. */
1134
const char *get_cpp_buf()
1139
/** Get the end of the raw query buffer. */
1140
const char *get_end_of_query()
1142
return m_end_of_query;
1145
/** Mark the stream position as the start of a new token. */
1148
m_tok_start_prev= m_tok_start;
1152
m_cpp_tok_start_prev= m_cpp_tok_start;
1153
m_cpp_tok_start= m_cpp_ptr;
1154
m_cpp_tok_end= m_cpp_ptr;
1158
Adjust the starting position of the current token.
1159
This is used to compensate for starting whitespace.
1161
void restart_token()
1164
m_cpp_tok_start= m_cpp_ptr;
1167
/** Get the token start position, in the raw buffer. */
1168
const char *get_tok_start()
1173
/** Get the token start position, in the pre-processed buffer. */
1174
const char *get_cpp_tok_start()
1176
return m_cpp_tok_start;
1179
/** Get the token end position, in the raw buffer. */
1180
const char *get_tok_end()
1185
/** Get the token end position, in the pre-processed buffer. */
1186
const char *get_cpp_tok_end()
1188
return m_cpp_tok_end;
1191
/** Get the previous token start position, in the raw buffer. */
1192
const char *get_tok_start_prev()
1194
return m_tok_start_prev;
1197
/** Get the current stream pointer, in the raw buffer. */
1198
const char *get_ptr()
1203
/** Get the current stream pointer, in the pre-processed buffer. */
1204
const char *get_cpp_ptr()
1209
/** Get the length of the current token, in the raw buffer. */
1213
The assumption is that the lexical analyser is always 1 character ahead,
1214
which the -1 account for.
1216
assert(m_ptr > m_tok_start);
1217
return (uint32_t) ((m_ptr - m_tok_start) - 1);
1220
/** Get the utf8-body string. */
1221
const char *get_body_utf8_str()
1226
/** Get the utf8-body length. */
1227
uint32_t get_body_utf8_length()
1229
return m_body_utf8_ptr - m_body_utf8;
1232
void body_utf8_start(THD *thd, const char *begin_ptr);
1233
void body_utf8_append(const char *ptr);
1234
void body_utf8_append(const char *ptr, const char *end_ptr);
1235
void body_utf8_append_literal(THD *thd,
1236
const LEX_STRING *txt,
1237
const CHARSET_INFO * const txt_cs,
1238
const char *end_ptr);
1240
/** Current thread. */
1243
/** Current line number. */
1246
/** Length of the last token parsed. */
1249
/** Interface with bison, value of the last token parsed. */
1252
/** LALR(2) resolution, look ahead token.*/
1253
int lookahead_token;
1255
/** LALR(2) resolution, value of the look ahead token.*/
1256
LEX_YYSTYPE lookahead_yylval;
1259
/** Pointer to the current position in the raw input stream. */
1262
/** Starting position of the last token parsed, in the raw buffer. */
1263
const char *m_tok_start;
1265
/** Ending position of the previous token parsed, in the raw buffer. */
1266
const char *m_tok_end;
1268
/** End of the query text in the input stream, in the raw buffer. */
1269
const char *m_end_of_query;
1271
/** Starting position of the previous token parsed, in the raw buffer. */
1272
const char *m_tok_start_prev;
1274
/** Begining of the query text in the input stream, in the raw buffer. */
1277
/** Length of the raw buffer. */
1278
uint32_t m_buf_length;
1280
/** Echo the parsed stream to the pre-processed buffer. */
1283
/** Pre-processed buffer. */
1286
/** Pointer to the current position in the pre-processed input stream. */
1290
Starting position of the last token parsed,
1291
in the pre-processed buffer.
1293
const char *m_cpp_tok_start;
1296
Starting position of the previous token parsed,
1297
in the pre-procedded buffer.
1299
const char *m_cpp_tok_start_prev;
1302
Ending position of the previous token parsed,
1303
in the pre-processed buffer.
1305
const char *m_cpp_tok_end;
1307
/** UTF8-body buffer created during parsing. */
1310
/** Pointer to the current position in the UTF8-body buffer. */
1311
char *m_body_utf8_ptr;
1314
Position in the pre-processed buffer. The query from m_cpp_buf to
1315
m_cpp_utf_processed_ptr is converted to UTF8-body.
1317
const char *m_cpp_utf8_processed_ptr;
1321
/** Current state of the lexical analyser. */
1322
enum my_lex_states next_state;
1325
Position of ';' in the stream, to delimit multiple queries.
1326
This delimiter is in the raw buffer.
1328
const char *found_semicolon;
1330
/** Token character bitmaps, to detect 7bit strings. */
1331
unsigned char tok_bitmap;
1333
/** SQL_MODE = IGNORE_SPACE. */
1336
/** State of the lexical analyser for comments. */
1337
enum_comment_state in_comment;
1340
Starting position of the TEXT_STRING or IDENT in the pre-processed
1343
NOTE: this member must be used within MYSQLlex() function only.
1345
const char *m_cpp_text_start;
1348
Ending position of the TEXT_STRING or IDENT in the pre-processed
1351
NOTE: this member must be used within MYSQLlex() function only.
1353
const char *m_cpp_text_end;
1356
Character set specified by the character-set-introducer.
1358
NOTE: this member must be used within MYSQLlex() function only.
1360
const CHARSET_INFO *m_underscore_cs;
1364
/* The state of the lex parsing. This is saved in the THD struct */
1366
typedef struct st_lex : public Query_tables_list
1368
SELECT_LEX_UNIT unit; /* most upper unit */
1369
SELECT_LEX select_lex; /* first SELECT_LEX */
1370
/* current SELECT_LEX in parsing */
1371
SELECT_LEX *current_select;
1372
/* list of all SELECT_LEX */
1373
SELECT_LEX *all_selects_list;
1375
char *length,*dec,*change;
815
#include "drizzled/lex_input_stream.h"
817
/* The state of the lex parsing. This is saved in the Session struct */
818
class LEX : public Query_tables_list
821
Select_Lex_Unit unit; /* most upper unit */
822
Select_Lex select_lex; /* first Select_Lex */
823
/* current Select_Lex in parsing */
824
Select_Lex *current_select;
825
/* list of all Select_Lex */
826
Select_Lex *all_selects_list;
828
/* This is the "scale" for DECIMAL (S,P) notation */
830
/* This is the decimal precision in DECIMAL(S,P) notation */
832
/* The text in a CHANGE COLUMN clause in ALTER TABLE */
836
* This is used kind of like the "ident" member variable below, as
837
* a place to store certain names of identifiers. Unfortunately, it
838
* is used differently depending on the Command (SELECT on a derived
1376
841
LEX_STRING name;
1378
char* to_log; /* For PURGE MASTER LOGS TO */
1379
char* x509_subject,*x509_issuer,*ssl_cipher;
842
/* The string literal used in a LIKE expression */
1381
sql_exchange *exchange;
844
file_exchange *exchange;
1382
845
select_result *result;
1383
Item *default_value, *on_update_value;
1384
LEX_STRING comment, ident;
847
/* An item representing the DEFAULT clause in CREATE/ALTER TABLE */
849
/* An item representing the ON UPDATE clause in CREATE/ALTER TABLE */
850
Item *on_update_value;
851
/* Not really sure what exactly goes in here... Comment text at beginning of statement? */
855
* This is current used to store the name of a named key cache
856
* or a named savepoint. It should probably be refactored out into
857
* the eventual Command class built for the Keycache and Savepoint
1386
862
unsigned char* yacc_yyss, *yacc_yyvs;
1389
/* maintain a list of used plugins for this LEX */
1390
DYNAMIC_ARRAY plugins;
1391
plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
863
/* The owning Session of this LEX */
1393
865
const CHARSET_INFO *charset;
1394
866
bool text_string_is_7bit;
1395
867
/* store original leaf_tables for INSERT SELECT and PS/SP */
1456
929
enum ha_rkey_function ha_rkey_mode;
1457
930
enum xa_option_words xa_opt;
1458
bool lock_transactional; /* For LOCK Table ... IN ... MODE */
1460
932
enum enum_var_type option_type;
1462
uint32_t profile_query_id;
1463
uint32_t profile_options;
1464
934
enum column_format_type column_format;
1465
uint32_t which_columns;
1466
935
enum Foreign_key::fk_match_opt fk_match_option;
1467
936
enum Foreign_key::fk_option fk_update_opt;
1468
937
enum Foreign_key::fk_option fk_delete_opt;
1469
uint32_t slave_thd_opt, start_transaction_opt;
938
/* Options used in START TRANSACTION statement */
939
uint32_t start_transaction_opt;
1472
In LEX representing update which were transformed to multi-update
1473
stores total number of tables. For LEX representing multi-delete
1474
holds number of tables from which we will delete records.
1476
uint32_t table_count;
1477
941
uint8_t describe;
1479
943
A flag that indicates what kinds of derived tables are present in the
1480
944
query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
1482
946
uint8_t derived_tables;
1483
bool drop_if_exists, drop_temporary, local_file, one_shot_set;
948
/* True if "IF EXISTS" used in DROP statement */
950
/* True if "TEMPORARY" used in DROP/CREATE statement */
954
/* Only true when FULL symbol is found (e.g. SHOW FULL PROCESSLIST) */
1487
bool tx_chain, tx_release;
1488
bool subqueries, ignore;
1489
st_parsing_options parsing_options;
957
/* Was the CHAIN option using in COMMIT/ROLLBACK? */
959
/* Was the RELEASE option used in COMMIT/ROLLBACK? */
961
/* Was the IGNORE symbol found in statement */
1490
963
Alter_info alter_info;
1493
field_list was created for view and should be removed before PS/SP
1496
bool empty_field_list_on_rset;
1499
966
Pointers to part of LOAD DATA statement that should be rewritten
1500
967
during replication ("LOCAL 'filename' REPLACE INTO" part).
1502
969
const char *fname_start;
1503
970
const char *fname_end;
1506
During name resolution search only in the table list given by
973
During name resolution search only in the table list given by
1507
974
Name_resolution_context::first_name_resolution_table and
1508
975
Name_resolution_context::last_name_resolution_table
1509
(see Item_field::fix_fields()).
976
(see Item_field::fix_fields()).
1511
978
bool use_only_table_context;
980
/* Was the ESCAPE keyword used? */
1513
981
bool escape_used;
1514
982
bool is_lex_started; /* If lex_start() did run. For debugging. */
986
/* Note that init and de-init mostly happen in lex_start and lex_end
987
and not here. This is because LEX isn't delete/new for each new
988
statement in a session. It's re-used by doing lex_end, lex_start
1520
destroy_query_tables_list();
1521
plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements);
1522
delete_dynamic(&plugins);
1525
995
TableList *unlink_first_table(bool *link_to_local);
1526
996
void link_first_table_back(TableList *first, bool link_to_local);
1527
997
void first_lists_tables_same();
1529
bool can_be_merged();
1530
bool can_use_merged();
1531
bool can_not_use_merged();
1532
999
bool only_view_structure();
1533
1000
bool need_correct_ident();
1551
1018
return context_stack.head();
1554
Restore the LEX and THD in case of a parse error.
1021
Restore the LEX and Session in case of a parse error.
1556
static void cleanup_lex_after_parse_error(THD *thd);
1558
void reset_n_backup_query_tables_list(Query_tables_list *backup);
1559
void restore_backup_query_tables_list(Query_tables_list *backup);
1561
bool table_or_sp_used();
1023
static void cleanup_lex_after_parse_error(Session *session);
1564
1026
@brief check if the statement is a single-level join
1565
1027
@return result of the check
1566
@retval true The statement doesn't contain subqueries, unions and
1028
@retval true The statement doesn't contain subqueries, unions and
1567
1029
stored procedure calls.
1568
1030
@retval false There are subqueries, UNIONs or stored procedure calls.
1570
bool is_single_level_stmt()
1032
bool is_single_level_stmt()
1573
1035
This check exploits the fact that the last added to all_select_list is
1574
on its top. So select_lex (as the first added) will be at the tail
1036
on its top. So select_lex (as the first added) will be at the tail
1577
if (&select_lex == all_selects_list && !sroutines.records)
1039
if (&select_lex == all_selects_list)
1579
1041
assert(!all_selects_list->next_select_in_list());
1586
struct st_lex_local: public st_lex
1588
static void *operator new(size_t size) throw()
1590
return sql_alloc(size);
1592
static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1594
return (void*) alloc_root(mem_root, (uint32_t) size);
1596
static void operator delete(void *ptr __attribute__((unused)),
1597
size_t size __attribute__((unused)))
1598
{ TRASH(ptr, size); }
1599
static void operator delete(void *ptr __attribute__((unused)),
1600
MEM_ROOT *mem_root __attribute__((unused)))
1601
{ /* Never called */ }
1604
extern void lex_init(void);
1605
extern void lex_free(void);
1606
extern void lex_start(THD *thd);
1048
extern void lex_start(Session *session);
1607
1049
extern void lex_end(LEX *lex);
1609
1050
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1611
1051
extern bool is_lex_native_function(const LEX_STRING *name);