17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_SQL_LEX_H
21
#define DRIZZLED_SQL_LEX_H
20
#ifndef DRIZZLE_SERVER_SQL_LEX_H
21
#define DRIZZLE_SERVER_SQL_LEX_H
24
24
@defgroup Semantic_Analysis Semantic Analysis
26
#include <drizzled/message/table.pb.h>
28
#include "drizzled/plugin/function.h"
29
#include "drizzled/name_resolution_context.h"
30
#include "drizzled/item/subselect.h"
31
#include "drizzled/table_list.h"
32
#include "drizzled/function/math/real.h"
33
#include "drizzled/alter_drop.h"
34
#include "drizzled/alter_column.h"
35
#include "drizzled/alter_info.h"
36
#include "drizzled/key_part_spec.h"
37
#include "drizzled/index_hint.h"
38
#include "drizzled/statement.h"
39
#include "drizzled/optimizer/explain_plan.h"
47
class select_result_interceptor;
49
29
/* YACC and LEX Definitions */
51
31
/* These may not be declared yet */
57
} /* namespace drizzled */
60
38
The following hack is needed because mysql_yacc.cc does not define
61
39
YYSTYPE before including this file
65
# include <drizzled/set_var.h>
66
# include <drizzled/item/func.h>
68
# define LEX_YYSTYPE void *
70
# if defined(DRIZZLE_LEX)
71
# include <drizzled/foreign_key.h>
72
# include <drizzled/lex_symbol.h>
73
# include <drizzled/sql_yacc.h>
74
# define LEX_YYSTYPE YYSTYPE *
76
# define LEX_YYSTYPE void *
77
# endif /* defined(DRIZZLE_LEX) */
78
# endif /* DRIZZLE_YACC */
79
#endif /* DRIZZLE_SERVER */
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_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 !!! */
81
104
// describe/explain types
82
105
#define DESCRIBE_NORMAL 1
87
110
#define DERIVED_NONE 0
88
111
#define DERIVED_SUBQUERY 1
93
113
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} heartbeat_opt;
135
char *relay_log_name;
136
uint32_t relay_log_pos;
95
140
enum sub_select_type
108
UNSPECIFIED_OLAP_TYPE,
142
UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
143
EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
148
UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
151
enum tablespace_op_type
153
NO_TABLESPACE_OP, DISCARD_TABLESPACE, IMPORT_TABLESPACE
157
String names used to print a statement with index hints.
158
Keep in sync with index_hint_type.
160
extern const char * index_hint_type_name[];
161
typedef unsigned char index_clause_map;
114
The state of the lex parsing for selects
164
Bits in index_clause_map : one for each possible FOR clause in
165
USE/FORCE/IGNORE INDEX index hint specification
167
#define INDEX_HINT_MASK_JOIN (1)
168
#define INDEX_HINT_MASK_GROUP (1 << 1)
169
#define INDEX_HINT_MASK_ORDER (1 << 2)
171
#define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
172
INDEX_HINT_MASK_ORDER)
174
/* Single element of an USE/FORCE/IGNORE INDEX list specified as a SQL hint */
175
class Index_hint : public Sql_alloc
178
/* The type of the hint : USE/FORCE/IGNORE */
179
enum index_hint_type type;
180
/* Where the hit applies to. A bitmask of INDEX_HINT_MASK_<place> values */
181
index_clause_map clause;
183
The index name. Empty (str=NULL) name represents an empty list
188
Index_hint (enum index_hint_type type_arg, index_clause_map clause_arg,
189
char *str, uint32_t length) :
190
type(type_arg), clause(clause_arg)
193
key_name.length= length;
196
void print(THD *thd, String *str);
200
The state of the lex parsing for selects
116
202
master and slaves are pointers to select_lex.
117
203
master is pointer to upper level node.
118
204
slave is pointer to lower level node
256
342
static void *operator new(size_t size)
258
return memory::sql_alloc(size);
344
return sql_alloc(size);
260
static void *operator new(size_t size, memory::Root *mem_root)
346
static void *operator new(size_t size, MEM_ROOT *mem_root)
261
347
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
262
static void operator delete(void *, size_t)
264
static void operator delete(void *, memory::Root *)
348
static void operator delete(void *ptr __attribute__((unused)),
349
size_t size __attribute__((unused)))
350
{ TRASH(ptr, size); }
351
static void operator delete(void *ptr __attribute__((unused)),
352
MEM_ROOT *mem_root __attribute__((unused)))
266
Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
267
virtual ~Select_Lex_Node() {}
268
inline Select_Lex_Node* get_master() { return master; }
354
st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
355
virtual ~st_select_lex_node() {}
356
inline st_select_lex_node* get_master() { return master; }
269
357
virtual void init_query();
270
358
virtual void init_select();
271
void include_down(Select_Lex_Node *upper);
272
void include_neighbour(Select_Lex_Node *before);
273
void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
274
void include_global(Select_Lex_Node **plink);
359
void include_down(st_select_lex_node *upper);
360
void include_neighbour(st_select_lex_node *before);
361
void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
362
void include_global(st_select_lex_node **plink);
277
virtual Select_Lex_Unit* master_unit()= 0;
278
virtual Select_Lex* outer_select()= 0;
279
virtual Select_Lex* return_after_parsing()= 0;
365
virtual st_select_lex_unit* master_unit()= 0;
366
virtual st_select_lex* outer_select()= 0;
367
virtual st_select_lex* return_after_parsing()= 0;
281
369
virtual bool set_braces(bool value);
282
370
virtual bool inc_in_sum_expr();
341
430
Pointer to 'last' select or pointer to unit where stored
342
431
global parameters for union
344
Select_Lex *global_parameters;
433
st_select_lex *global_parameters;
345
434
//node on wich we should return current_select pointer after parsing subquery
346
Select_Lex *return_to;
435
st_select_lex *return_to;
347
436
/* LIMIT clause runtime counters */
348
437
ha_rows select_limit_cnt, offset_limit_cnt;
349
438
/* not NULL if unit used in subselect, point to subselect item */
350
439
Item_subselect *item;
351
440
/* thread handler */
354
Select_Lex for hidden SELECT in onion which process global
443
SELECT_LEX for hidden SELECT in onion which process global
355
444
ORDER BY and LIMIT
357
Select_Lex *fake_select_lex;
446
st_select_lex *fake_select_lex;
359
Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
448
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
360
449
bool describe; /* union exec() called for EXPLAIN */
362
451
void init_query();
363
Select_Lex_Unit* master_unit();
364
Select_Lex* outer_select();
365
Select_Lex* first_select()
367
return reinterpret_cast<Select_Lex*>(slave);
369
Select_Lex_Unit* next_unit()
371
return reinterpret_cast<Select_Lex_Unit*>(next);
373
Select_Lex* return_after_parsing() { return return_to; }
452
st_select_lex_unit* master_unit();
453
st_select_lex* outer_select();
454
st_select_lex* first_select()
456
return reinterpret_cast<st_select_lex*>(slave);
458
st_select_lex_unit* next_unit()
460
return reinterpret_cast<st_select_lex_unit*>(next);
462
st_select_lex* return_after_parsing() { return return_to; }
374
463
void exclude_level();
375
464
void exclude_tree();
377
466
/* UNION methods */
378
bool prepare(Session *session, select_result *result,
379
uint64_t additional_options);
467
bool prepare(THD *thd, select_result *result, uint32_t additional_options);
382
470
inline void unclean() { cleaned= 0; }
385
473
void print(String *str, enum_query_type query_type);
387
bool add_fake_select_lex(Session *session);
388
void init_prepare_fake_select_lex(Session *session);
475
bool add_fake_select_lex(THD *thd);
476
void init_prepare_fake_select_lex(THD *thd);
389
477
bool change_result(select_result_interceptor *result,
390
478
select_result_interceptor *old_result);
391
void set_limit(Select_Lex *values);
392
void set_session(Session *session_arg) { session= session_arg; }
393
inline bool is_union ();
479
void set_limit(st_select_lex *values);
480
void set_thd(THD *thd_arg) { thd= thd_arg; }
481
inline bool is_union ();
395
friend void lex_start(Session *session);
483
friend void lex_start(THD *thd);
396
484
friend int subselect_union_engine::exec();
398
486
List<Item> *get_unit_column_types();
489
typedef class st_select_lex_unit SELECT_LEX_UNIT;
402
Select_Lex - store information of parsed SELECT statment
492
SELECT_LEX - store information of parsed SELECT statment
404
class Select_Lex: public Select_Lex_Node
494
class st_select_lex: public st_select_lex_node
407
497
Name_resolution_context context;
409
/* An Item representing the WHERE clause */
411
/* An Item representing the HAVING clause */
499
Item *where, *having; /* WHERE & HAVING clauses */
413
500
/* Saved values of the WHERE and HAVING clauses*/
414
Item::cond_result cond_value;
415
Item::cond_result having_value;
501
Item::cond_result cond_value, having_value;
416
502
/* point on lex in which it was created, used in view subquery detection */
418
504
enum olap_type olap;
419
505
/* FROM clause - points to the beginning of the TableList::next_local list. */
421
SQL_LIST group_list; /* GROUP BY clause. */
422
List<Item> item_list; /* list of fields & expressions */
423
List<String> interval_list;
424
bool is_item_list_lookup;
507
SQL_LIST group_list; /* GROUP BY clause. */
508
List<Item> item_list; /* list of fields & expressions */
509
List<String> interval_list;
510
bool is_item_list_lookup;
512
Despite their names, the following are used in unions. This should
515
List<Item_real_func> *ftfunc_list;
516
List<Item_real_func> ftfunc_list_alloc;
425
517
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
426
518
List<TableList> top_join_list; /* join list of the top level */
427
519
List<TableList> *join_list; /* list for the currently parsed join */
513
611
1 - aggregate functions are used in this select,
514
612
defined as SUM_FUNC_USED.
516
std::bitset<2> full_group_by_flag;
614
uint8_t full_group_by_flag;
517
615
void init_query();
518
616
void init_select();
519
Select_Lex_Unit* master_unit();
520
Select_Lex_Unit* first_inner_unit()
522
return (Select_Lex_Unit*) slave;
524
Select_Lex* outer_select();
525
Select_Lex* next_select()
527
return (Select_Lex*) next;
529
Select_Lex* next_select_in_list()
531
return (Select_Lex*) link_next;
533
Select_Lex_Node** next_select_in_list_addr()
617
st_select_lex_unit* master_unit();
618
st_select_lex_unit* first_inner_unit()
620
return (st_select_lex_unit*) slave;
622
st_select_lex* outer_select();
623
st_select_lex* next_select() { return (st_select_lex*) next; }
624
st_select_lex* next_select_in_list()
626
return (st_select_lex*) link_next;
628
st_select_lex_node** next_select_in_list_addr()
535
630
return &link_next;
537
Select_Lex* return_after_parsing()
632
st_select_lex* return_after_parsing()
539
634
return master_unit()->return_after_parsing();
542
void mark_as_dependent(Select_Lex *last);
637
void mark_as_dependent(st_select_lex *last);
544
639
bool set_braces(bool value);
545
640
bool inc_in_sum_expr();
546
641
uint32_t get_in_sum_expr();
548
bool add_item_to_list(Session *session, Item *item);
549
bool add_group_to_list(Session *session, Item *item, bool asc);
550
bool add_order_to_list(Session *session, Item *item, bool asc);
551
TableList* add_table_to_list(Session *session,
554
uint32_t table_options,
555
thr_lock_type flags= TL_UNLOCK,
556
List<Index_hint> *hints= 0,
557
LEX_STRING *option= 0);
643
bool add_item_to_list(THD *thd, Item *item);
644
bool add_group_to_list(THD *thd, Item *item, bool asc);
645
bool add_order_to_list(THD *thd, Item *item, bool asc);
646
TableList* add_table_to_list(THD *thd, Table_ident *table,
648
uint32_t table_options,
649
thr_lock_type flags= TL_UNLOCK,
650
List<Index_hint> *hints= 0,
651
LEX_STRING *option= 0);
558
652
TableList* get_table_list();
559
bool init_nested_join(Session *session);
560
TableList *end_nested_join(Session *session);
561
TableList *nest_last_join(Session *session);
653
bool init_nested_join(THD *thd);
654
TableList *end_nested_join(THD *thd);
655
TableList *nest_last_join(THD *thd);
562
656
void add_joined_table(TableList *table);
563
657
TableList *convert_right_join();
564
658
List<Item>* get_item_list();
628
719
void clear_index_hints(void) { index_hints= NULL; }
631
722
/* current index hint kind. used in filling up index_hints */
632
723
enum index_hint_type current_index_hint_type;
633
724
index_clause_map current_index_hint_clause;
634
725
/* a list of USE/FORCE/IGNORE INDEX */
635
726
List<Index_hint> *index_hints;
728
typedef class st_select_lex SELECT_LEX;
638
inline bool Select_Lex_Unit::is_union ()
640
return first_select()->next_select() &&
730
inline bool st_select_lex_unit::is_union ()
732
return first_select()->next_select() &&
641
733
first_select()->next_select()->linkage == UNION_TYPE;
736
#define ALTER_ADD_COLUMN (1L << 0)
737
#define ALTER_DROP_COLUMN (1L << 1)
738
#define ALTER_CHANGE_COLUMN (1L << 2)
739
#define ALTER_COLUMN_STORAGE (1L << 3)
740
#define ALTER_COLUMN_FORMAT (1L << 4)
741
#define ALTER_COLUMN_ORDER (1L << 5)
742
#define ALTER_ADD_INDEX (1L << 6)
743
#define ALTER_DROP_INDEX (1L << 7)
744
#define ALTER_RENAME (1L << 8)
745
#define ALTER_ORDER (1L << 9)
746
#define ALTER_OPTIONS (1L << 10)
747
#define ALTER_COLUMN_DEFAULT (1L << 11)
748
#define ALTER_KEYS_ONOFF (1L << 12)
749
#define ALTER_STORAGE (1L << 13)
750
#define ALTER_ROW_FORMAT (1L << 14)
751
#define ALTER_CONVERT (1L << 15)
752
#define ALTER_FORCE (1L << 16)
753
#define ALTER_RECREATE (1L << 17)
754
#define ALTER_TABLE_REORG (1L << 24)
755
#define ALTER_FOREIGN_KEY (1L << 31)
758
@brief Parsing data for CREATE or ALTER Table.
760
This structure contains a list of columns or indexes to be created,
767
List<Alter_drop> drop_list;
768
List<Alter_column> alter_list;
770
List<Create_field> create_list;
772
enum enum_enable_or_disable keys_onoff;
773
enum tablespace_op_type tablespace_op;
775
enum ha_build_method build_method;
776
Create_field *datetime_field;
777
bool error_if_not_empty;
782
keys_onoff(LEAVE_AS_IS),
783
tablespace_op(NO_TABLESPACE_OP),
785
build_method(HA_BUILD_DEFAULT),
786
datetime_field(NULL),
787
error_if_not_empty(false)
797
keys_onoff= LEAVE_AS_IS;
798
tablespace_op= NO_TABLESPACE_OP;
800
build_method= HA_BUILD_DEFAULT;
802
error_if_not_empty= false;
804
Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
806
Alter_info &operator=(const Alter_info &rhs); // not implemented
807
Alter_info(const Alter_info &rhs); // not implemented
810
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
811
XA_SUSPEND, XA_FOR_MIGRATE};
654
813
extern const LEX_STRING null_lex_str;
657
817
Class representing list of all tables used by statement.
658
818
It also contains information about stored functions used by statement
740
} /* namespace drizzled */
742
#include "drizzled/lex_input_stream.h"
747
/* The state of the lex parsing. This is saved in the Session struct */
748
class LEX : public Query_tables_list
751
Select_Lex_Unit unit; /* most upper unit */
752
Select_Lex select_lex; /* first Select_Lex */
753
/* current Select_Lex in parsing */
754
Select_Lex *current_select;
755
/* list of all Select_Lex */
756
Select_Lex *all_selects_list;
758
/* This is the "scale" for DECIMAL (S,P) notation */
760
/* This is the decimal precision in DECIMAL(S,P) notation */
764
* This is used kind of like the "ident" member variable below, as
765
* a place to store certain names of identifiers. Unfortunately, it
766
* is used differently depending on the Command (SELECT on a derived
986
@brief This class represents the character input stream consumed during
989
In addition to consuming the input stream, this class performs some
990
comment pre processing, by filtering out out of bound special text
991
from the query input stream.
992
Two buffers, with pointers inside each buffers, are maintained in
993
parallel. The 'raw' buffer is the original query text, which may
994
contain out-of-bound comments. The 'cpp' (for comments pre processor)
995
is the pre-processed buffer that contains only the query text that
996
should be seen once out-of-bound data is removed.
999
class Lex_input_stream
1002
Lex_input_stream(THD *thd, const char* buff, unsigned int length);
1003
~Lex_input_stream();
1008
When echo is true, characters parsed from the raw input stream are
1009
preserved. When false, characters parsed are silently ignored.
1010
@param echo the echo mode.
1012
void set_echo(bool echo)
1018
Skip binary from the input stream.
1019
@param n number of bytes to accept.
1021
void skip_binary(int n)
1025
memcpy(m_cpp_ptr, m_ptr, n);
1032
Get a character, and advance in the stream.
1033
@return the next character to parse.
1044
Get the last character accepted.
1045
@return the last character accepted.
1053
Look at the next character to parse, but do not accept it.
1061
Look ahead at some character to parse.
1062
@param n offset of the character to look up
1070
Cancel the effect of the last yyGet() or yySkip().
1071
Note that the echo mode should not change between calls to yyGet / yySkip
1072
and yyUnget. The caller is responsible for ensuring that.
1082
Accept a character, by advancing the input stream.
1087
*m_cpp_ptr++ = *m_ptr++;
1093
Accept multiple characters at once.
1094
@param n the number of characters to accept.
1100
memcpy(m_cpp_ptr, m_ptr, n);
1107
End of file indicator for the query text to parse.
1108
@return true if there are no more characters to parse
1112
return (m_ptr >= m_end_of_query);
1116
End of file indicator for the query text to parse.
1117
@param n number of characters expected
1118
@return true if there are less than n characters to parse
1122
return ((m_ptr + n) >= m_end_of_query);
1125
/** Get the raw query buffer. */
1126
const char *get_buf()
1131
/** Get the pre-processed query buffer. */
1132
const char *get_cpp_buf()
1137
/** Get the end of the raw query buffer. */
1138
const char *get_end_of_query()
1140
return m_end_of_query;
1143
/** Mark the stream position as the start of a new token. */
1146
m_tok_start_prev= m_tok_start;
1150
m_cpp_tok_start_prev= m_cpp_tok_start;
1151
m_cpp_tok_start= m_cpp_ptr;
1152
m_cpp_tok_end= m_cpp_ptr;
1156
Adjust the starting position of the current token.
1157
This is used to compensate for starting whitespace.
1159
void restart_token()
1162
m_cpp_tok_start= m_cpp_ptr;
1165
/** Get the token start position, in the raw buffer. */
1166
const char *get_tok_start()
1171
/** Get the token start position, in the pre-processed buffer. */
1172
const char *get_cpp_tok_start()
1174
return m_cpp_tok_start;
1177
/** Get the token end position, in the raw buffer. */
1178
const char *get_tok_end()
1183
/** Get the token end position, in the pre-processed buffer. */
1184
const char *get_cpp_tok_end()
1186
return m_cpp_tok_end;
1189
/** Get the previous token start position, in the raw buffer. */
1190
const char *get_tok_start_prev()
1192
return m_tok_start_prev;
1195
/** Get the current stream pointer, in the raw buffer. */
1196
const char *get_ptr()
1201
/** Get the current stream pointer, in the pre-processed buffer. */
1202
const char *get_cpp_ptr()
1207
/** Get the length of the current token, in the raw buffer. */
1211
The assumption is that the lexical analyser is always 1 character ahead,
1212
which the -1 account for.
1214
assert(m_ptr > m_tok_start);
1215
return (uint32_t) ((m_ptr - m_tok_start) - 1);
1218
/** Get the utf8-body string. */
1219
const char *get_body_utf8_str()
1224
/** Get the utf8-body length. */
1225
uint32_t get_body_utf8_length()
1227
return m_body_utf8_ptr - m_body_utf8;
1230
void body_utf8_start(THD *thd, const char *begin_ptr);
1231
void body_utf8_append(const char *ptr);
1232
void body_utf8_append(const char *ptr, const char *end_ptr);
1233
void body_utf8_append_literal(THD *thd,
1234
const LEX_STRING *txt,
1235
const CHARSET_INFO * const txt_cs,
1236
const char *end_ptr);
1238
/** Current thread. */
1241
/** Current line number. */
1244
/** Length of the last token parsed. */
1247
/** Interface with bison, value of the last token parsed. */
1250
/** LALR(2) resolution, look ahead token.*/
1251
int lookahead_token;
1253
/** LALR(2) resolution, value of the look ahead token.*/
1254
LEX_YYSTYPE lookahead_yylval;
1257
/** Pointer to the current position in the raw input stream. */
1260
/** Starting position of the last token parsed, in the raw buffer. */
1261
const char *m_tok_start;
1263
/** Ending position of the previous token parsed, in the raw buffer. */
1264
const char *m_tok_end;
1266
/** End of the query text in the input stream, in the raw buffer. */
1267
const char *m_end_of_query;
1269
/** Starting position of the previous token parsed, in the raw buffer. */
1270
const char *m_tok_start_prev;
1272
/** Begining of the query text in the input stream, in the raw buffer. */
1275
/** Length of the raw buffer. */
1276
uint32_t m_buf_length;
1278
/** Echo the parsed stream to the pre-processed buffer. */
1281
/** Pre-processed buffer. */
1284
/** Pointer to the current position in the pre-processed input stream. */
1288
Starting position of the last token parsed,
1289
in the pre-processed buffer.
1291
const char *m_cpp_tok_start;
1294
Starting position of the previous token parsed,
1295
in the pre-procedded buffer.
1297
const char *m_cpp_tok_start_prev;
1300
Ending position of the previous token parsed,
1301
in the pre-processed buffer.
1303
const char *m_cpp_tok_end;
1305
/** UTF8-body buffer created during parsing. */
1308
/** Pointer to the current position in the UTF8-body buffer. */
1309
char *m_body_utf8_ptr;
1312
Position in the pre-processed buffer. The query from m_cpp_buf to
1313
m_cpp_utf_processed_ptr is converted to UTF8-body.
1315
const char *m_cpp_utf8_processed_ptr;
1319
/** Current state of the lexical analyser. */
1320
enum my_lex_states next_state;
1323
Position of ';' in the stream, to delimit multiple queries.
1324
This delimiter is in the raw buffer.
1326
const char *found_semicolon;
1328
/** Token character bitmaps, to detect 7bit strings. */
1329
unsigned char tok_bitmap;
1331
/** SQL_MODE = IGNORE_SPACE. */
1334
/** State of the lexical analyser for comments. */
1335
enum_comment_state in_comment;
1338
Starting position of the TEXT_STRING or IDENT in the pre-processed
1341
NOTE: this member must be used within MYSQLlex() function only.
1343
const char *m_cpp_text_start;
1346
Ending position of the TEXT_STRING or IDENT in the pre-processed
1349
NOTE: this member must be used within MYSQLlex() function only.
1351
const char *m_cpp_text_end;
1354
Character set specified by the character-set-introducer.
1356
NOTE: this member must be used within MYSQLlex() function only.
1358
const CHARSET_INFO *m_underscore_cs;
1362
/* The state of the lex parsing. This is saved in the THD struct */
1364
typedef struct st_lex : public Query_tables_list
1366
SELECT_LEX_UNIT unit; /* most upper unit */
1367
SELECT_LEX select_lex; /* first SELECT_LEX */
1368
/* current SELECT_LEX in parsing */
1369
SELECT_LEX *current_select;
1370
/* list of all SELECT_LEX */
1371
SELECT_LEX *all_selects_list;
1373
char *length,*dec,*change;
769
1374
LEX_STRING name;
770
/* The string literal used in a LIKE expression */
1376
char* to_log; /* For PURGE MASTER LOGS TO */
772
file_exchange *exchange;
1378
sql_exchange *exchange;
773
1379
select_result *result;
776
* This is current used to store the name of a named key cache
777
* or a named savepoint. It should probably be refactored out into
778
* the eventual Command class built for the Keycache and Savepoint
1380
Item *default_value, *on_update_value;
1381
LEX_STRING comment, ident;
783
1383
unsigned char* yacc_yyss, *yacc_yyvs;
784
/* The owning Session of this LEX */
1386
/* maintain a list of used plugins for this LEX */
1387
DYNAMIC_ARRAY plugins;
1388
plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
786
1390
const CHARSET_INFO *charset;
787
1391
bool text_string_is_7bit;
788
1392
/* store original leaf_tables for INSERT SELECT and PS/SP */
839
1448
thr_lock_type lock_option;
840
1449
enum enum_duplicates duplicates;
1450
enum enum_tx_isolation tx_isolation;
1451
enum enum_ha_read_modes ha_read_mode;
842
1453
enum ha_rkey_function ha_rkey_mode;
843
1454
enum xa_option_words xa_opt;
1455
bool lock_transactional; /* For LOCK Table ... IN ... MODE */
845
sql_var_t option_type;
1457
enum enum_var_type option_type;
1459
uint32_t profile_query_id;
1460
uint32_t profile_options;
1461
enum column_format_type column_format;
1462
uint32_t which_columns;
1463
enum Foreign_key::fk_match_opt fk_match_option;
1464
enum Foreign_key::fk_option fk_update_opt;
1465
enum Foreign_key::fk_option fk_delete_opt;
1466
uint32_t slave_thd_opt, start_transaction_opt;
1469
In LEX representing update which were transformed to multi-update
1470
stores total number of tables. For LEX representing multi-delete
1471
holds number of tables from which we will delete records.
1473
uint32_t table_count;
848
1474
uint8_t describe;
850
1476
A flag that indicates what kinds of derived tables are present in the
851
1477
query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
853
1479
uint8_t derived_tables;
855
/* Was the IGNORE symbol found in statement */
1480
bool drop_if_exists, drop_temporary, local_file, one_shot_set;
1484
bool tx_chain, tx_release;
1485
bool subqueries, ignore;
1486
st_parsing_options parsing_options;
1487
Alter_info alter_info;
1490
field_list was created for view and should be removed before PS/SP
1493
bool empty_field_list_on_rset;
1496
Pointers to part of LOAD DATA statement that should be rewritten
1497
during replication ("LOCAL 'filename' REPLACE INTO" part).
1499
const char *fname_start;
1500
const char *fname_end;
859
During name resolution search only in the table list given by
1503
During name resolution search only in the table list given by
860
1504
Name_resolution_context::first_name_resolution_table and
861
1505
Name_resolution_context::last_name_resolution_table
862
(see Item_field::fix_fields()).
1506
(see Item_field::fix_fields()).
864
1508
bool use_only_table_context;
866
/* Was the ESCAPE keyword used? */
867
1510
bool escape_used;
868
1511
bool is_lex_started; /* If lex_start() did run. For debugging. */
872
/* Note that init and de-init mostly happen in lex_start and lex_end
873
and not here. This is because LEX isn't delete/new for each new
874
statement in a session. It's re-used by doing lex_end, lex_start
1517
destroy_query_tables_list();
1518
plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements);
1519
delete_dynamic(&plugins);
881
1522
TableList *unlink_first_table(bool *link_to_local);
882
1523
void link_first_table_back(TableList *first, bool link_to_local);
883
1524
void first_lists_tables_same();
1526
bool can_be_merged();
1527
bool can_use_merged();
1528
bool can_not_use_merged();
885
1529
bool only_view_structure();
886
1530
bool need_correct_ident();
904
1548
return context_stack.head();
907
Restore the LEX and Session in case of a parse error.
1551
Restore the LEX and THD in case of a parse error.
909
static void cleanup_lex_after_parse_error(Session *session);
1553
static void cleanup_lex_after_parse_error(THD *thd);
1555
void reset_n_backup_query_tables_list(Query_tables_list *backup);
1556
void restore_backup_query_tables_list(Query_tables_list *backup);
1558
bool table_or_sp_used();
912
1561
@brief check if the statement is a single-level join
913
1562
@return result of the check
914
@retval true The statement doesn't contain subqueries, unions and
1563
@retval true The statement doesn't contain subqueries, unions and
915
1564
stored procedure calls.
916
1565
@retval false There are subqueries, UNIONs or stored procedure calls.
918
bool is_single_level_stmt()
1567
bool is_single_level_stmt()
921
1570
This check exploits the fact that the last added to all_select_list is
922
on its top. So select_lex (as the first added) will be at the tail
1571
on its top. So select_lex (as the first added) will be at the tail
925
if (&select_lex == all_selects_list)
1574
if (&select_lex == all_selects_list && !sroutines.records)
927
1576
assert(!all_selects_list->next_select_in_list());
1583
struct st_lex_local: public st_lex
1585
static void *operator new(size_t size) throw()
1587
return sql_alloc(size);
1589
static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1591
return (void*) alloc_root(mem_root, (uint32_t) size);
1593
static void operator delete(void *ptr __attribute__((unused)),
1594
size_t size __attribute__((unused)))
1595
{ TRASH(ptr, size); }
1596
static void operator delete(void *ptr __attribute__((unused)),
1597
MEM_ROOT *mem_root __attribute__((unused)))
1598
{ /* Never called */ }
934
extern void lex_start(Session *session);
1601
extern void lex_init(void);
1602
extern void lex_free(void);
1603
extern void lex_start(THD *thd);
935
1604
extern void lex_end(LEX *lex);
936
1606
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
937
1608
extern bool is_lex_native_function(const LEX_STRING *name);
940
1611
@} (End of group Semantic_Analysis)
943
} /* namespace drizzled */
945
1614
#endif /* DRIZZLE_SERVER */
946
#endif /* DRIZZLED_SQL_LEX_H */
1615
#endif /* DRIZZLE_SERVER_SQL_LEX_H */