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>
48
class select_result_interceptor;
50
29
/* YACC and LEX Definitions */
52
31
/* These may not be declared yet */
58
} /* namespace drizzled */
61
38
The following hack is needed because mysql_yacc.cc does not define
62
39
YYSTYPE before including this file
66
/* set_var should change to set_var here ... */
67
# include <drizzled/sys_var.h>
68
# include <drizzled/item/func.h>
70
# define LEX_YYSTYPE void *
72
# if defined(DRIZZLE_LEX)
73
# include <drizzled/foreign_key.h>
74
# include <drizzled/lex_symbol.h>
75
# include <drizzled/sql_yacc.h>
76
# define LEX_YYSTYPE YYSTYPE *
78
# define LEX_YYSTYPE void *
79
# endif /* defined(DRIZZLE_LEX) */
80
# endif /* DRIZZLE_YACC */
81
#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,
76
SQLCOM_SHOW_CREATE_DB,
77
SQLCOM_SHOW_TABLE_STATUS,
78
SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES,
79
SQLCOM_CHANGE_DB, SQLCOM_CREATE_DB, SQLCOM_DROP_DB, SQLCOM_ALTER_DB,
80
SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT,
81
SQLCOM_OPTIMIZE, SQLCOM_CHECK,
82
SQLCOM_ASSIGN_TO_KEYCACHE,
83
SQLCOM_FLUSH, SQLCOM_KILL, SQLCOM_ANALYZE,
84
SQLCOM_ROLLBACK, SQLCOM_ROLLBACK_TO_SAVEPOINT,
85
SQLCOM_COMMIT, SQLCOM_SAVEPOINT, SQLCOM_RELEASE_SAVEPOINT,
86
SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
87
SQLCOM_BEGIN, SQLCOM_CHANGE_MASTER,
89
SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_PURGE_BEFORE, SQLCOM_SHOW_BINLOGS,
90
SQLCOM_SHOW_OPEN_TABLES,
91
SQLCOM_DELETE_MULTI, SQLCOM_UPDATE_MULTI,
96
SQLCOM_BINLOG_BASE64_EVENT,
99
When a command is added here, be sure it's also added in mysqld.cc
100
in "struct show_var_st status_vars[]= {" ...
102
/* This should be the last !!! */
83
106
// describe/explain types
84
107
#define DESCRIBE_NORMAL 1
89
112
#define DERIVED_NONE 0
90
113
#define DERIVED_SUBQUERY 1
95
115
typedef List<Item> List_item;
117
/* SERVERS CACHE CHANGES */
118
typedef struct st_lex_server_options
121
uint32_t server_name_length;
122
char *server_name, *host, *db, *username, *password, *scheme, *owner;
123
} LEX_SERVER_OPTIONS;
125
typedef struct st_lex_master_info
127
char *host, *user, *password, *log_file_name;
128
uint32_t port, connect_retry;
129
float heartbeat_period;
133
Enum is used for making it possible to detect if the user
134
changed variable or if it should be left at old value
136
enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE} heartbeat_opt;
137
char *relay_log_name;
138
uint32_t relay_log_pos;
97
142
enum sub_select_type
110
UNSPECIFIED_OLAP_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
153
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;
116
The state of the lex parsing for selects
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
118
204
master and slaves are pointers to select_lex.
119
205
master is pointer to upper level node.
120
206
slave is pointer to lower level node
250
336
UNCACHEABLE_EXPLAIN
251
337
UNCACHEABLE_PREPARE
253
std::bitset<8> uncacheable;
254
340
enum sub_select_type linkage;
255
341
bool no_table_names_allowed; /* used for global order by */
256
342
bool no_error; /* suppress error message (convert it to warnings) */
258
344
static void *operator new(size_t size)
260
return memory::sql_alloc(size);
346
return sql_alloc(size);
262
static void *operator new(size_t size, memory::Root *mem_root)
263
{ return (void*) mem_root->alloc_root((uint32_t) size); }
264
static void operator delete(void *, size_t)
266
static void operator delete(void *, memory::Root *)
348
static void *operator new(size_t size, MEM_ROOT *mem_root)
349
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
350
static void operator delete(void *ptr __attribute__((unused)),
351
size_t size __attribute__((unused)))
352
{ TRASH(ptr, size); }
353
static void operator delete(void *ptr __attribute__((unused)),
354
MEM_ROOT *mem_root __attribute__((unused)))
268
Select_Lex_Node(): linkage(UNSPECIFIED_TYPE) {}
269
virtual ~Select_Lex_Node() {}
270
inline Select_Lex_Node* get_master() { return master; }
356
st_select_lex_node(): linkage(UNSPECIFIED_TYPE) {}
357
virtual ~st_select_lex_node() {}
358
inline st_select_lex_node* get_master() { return master; }
271
359
virtual void init_query();
272
360
virtual void init_select();
273
void include_down(Select_Lex_Node *upper);
274
void include_neighbour(Select_Lex_Node *before);
275
void include_standalone(Select_Lex_Node *sel, Select_Lex_Node **ref);
276
void include_global(Select_Lex_Node **plink);
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);
279
virtual Select_Lex_Unit* master_unit()= 0;
280
virtual Select_Lex* outer_select()= 0;
281
virtual Select_Lex* return_after_parsing()= 0;
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;
283
371
virtual bool set_braces(bool value);
284
372
virtual bool inc_in_sum_expr();
285
373
virtual uint32_t get_in_sum_expr();
286
374
virtual TableList* get_table_list();
287
375
virtual List<Item>* get_item_list();
288
virtual TableList *add_table_to_list(Session *session, Table_ident *table,
290
const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
291
thr_lock_type flags= TL_UNLOCK,
292
List<Index_hint> *hints= 0,
293
LEX_STRING *option= 0);
294
virtual void set_lock_for_tables(thr_lock_type)
376
virtual uint32_t get_table_join_options();
377
virtual TableList *add_table_to_list(THD *thd, Table_ident *table,
379
uint32_t table_options,
380
thr_lock_type flags= TL_UNLOCK,
381
List<Index_hint> *hints= 0,
382
LEX_STRING *option= 0);
383
virtual void set_lock_for_tables(thr_lock_type lock_type __attribute__((unused)))
297
friend class Select_Lex_Unit;
298
friend bool new_select(LEX *lex, bool move_down);
386
friend class st_select_lex_unit;
387
friend bool mysql_new_select(struct st_lex *lex, bool move_down);
300
389
void fast_exclude();
391
typedef class st_select_lex_node SELECT_LEX_NODE;
304
Select_Lex_Unit - unit of selects (UNION, INTERSECT, ...) group
394
SELECT_LEX_UNIT - unit of selects (UNION, INTERSECT, ...) group
308
398
class select_result;
310
400
class select_union;
311
class Select_Lex_Unit: public Select_Lex_Node {
401
class st_select_lex_unit: public st_select_lex_node {
313
403
TableList result_table_list;
314
404
select_union *union_result;
342
432
Pointer to 'last' select or pointer to unit where stored
343
433
global parameters for union
345
Select_Lex *global_parameters;
435
st_select_lex *global_parameters;
346
436
//node on wich we should return current_select pointer after parsing subquery
347
Select_Lex *return_to;
437
st_select_lex *return_to;
348
438
/* LIMIT clause runtime counters */
349
439
ha_rows select_limit_cnt, offset_limit_cnt;
350
440
/* not NULL if unit used in subselect, point to subselect item */
351
441
Item_subselect *item;
352
442
/* thread handler */
355
Select_Lex for hidden SELECT in onion which process global
445
SELECT_LEX for hidden SELECT in onion which process global
356
446
ORDER BY and LIMIT
358
Select_Lex *fake_select_lex;
448
st_select_lex *fake_select_lex;
360
Select_Lex *union_distinct; /* pointer to the last UNION DISTINCT */
450
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
361
451
bool describe; /* union exec() called for EXPLAIN */
363
453
void init_query();
364
Select_Lex_Unit* master_unit();
365
Select_Lex* outer_select();
366
Select_Lex* first_select()
368
return reinterpret_cast<Select_Lex*>(slave);
370
Select_Lex_Unit* next_unit()
372
return reinterpret_cast<Select_Lex_Unit*>(next);
374
Select_Lex* return_after_parsing() { return return_to; }
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; }
375
465
void exclude_level();
376
466
void exclude_tree();
378
468
/* UNION methods */
379
bool prepare(Session *session, select_result *result,
380
uint64_t additional_options);
469
bool prepare(THD *thd, select_result *result, uint32_t additional_options);
383
472
inline void unclean() { cleaned= 0; }
386
475
void print(String *str, enum_query_type query_type);
388
bool add_fake_select_lex(Session *session);
389
void init_prepare_fake_select_lex(Session *session);
477
bool add_fake_select_lex(THD *thd);
478
void init_prepare_fake_select_lex(THD *thd);
390
479
bool change_result(select_result_interceptor *result,
391
480
select_result_interceptor *old_result);
392
void set_limit(Select_Lex *values);
393
void set_session(Session *session_arg) { session= session_arg; }
394
inline bool is_union ();
481
void set_limit(st_select_lex *values);
482
void set_thd(THD *thd_arg) { thd= thd_arg; }
483
inline bool is_union ();
396
friend void lex_start(Session *session);
485
friend void lex_start(THD *thd);
397
486
friend int subselect_union_engine::exec();
399
488
List<Item> *get_unit_column_types();
491
typedef class st_select_lex_unit SELECT_LEX_UNIT;
403
Select_Lex - store information of parsed SELECT statment
494
SELECT_LEX - store information of parsed SELECT statment
405
class Select_Lex: public Select_Lex_Node
496
class st_select_lex: public st_select_lex_node
417
olap(UNSPECIFIED_OLAP_TYPE),
422
is_item_list_lookup(false),
429
type(optimizer::ST_PRIMARY),
434
ref_pointer_array(0),
435
select_n_having_items(0),
439
select_n_where_fields(0),
440
parsing_place(NO_MATTER),
445
inner_sum_func_list(0),
451
n_child_sum_items(0),
454
subquery_in_having(0),
456
exclude_from_table_unique_test(0),
458
cur_pos_in_select_list(0),
460
full_group_by_flag(),
461
current_index_hint_type(INDEX_HINT_IGNORE),
462
current_index_hint_clause(),
467
499
Name_resolution_context context;
469
/* An Item representing the WHERE clause */
471
/* An Item representing the HAVING clause */
501
Item *where, *having; /* WHERE & HAVING clauses */
473
502
/* Saved values of the WHERE and HAVING clauses*/
474
Item::cond_result cond_value;
475
Item::cond_result having_value;
503
Item::cond_result cond_value, having_value;
476
504
/* point on lex in which it was created, used in view subquery detection */
478
506
enum olap_type olap;
479
507
/* FROM clause - points to the beginning of the TableList::next_local list. */
481
SQL_LIST group_list; /* GROUP BY clause. */
482
List<Item> item_list; /* list of fields & expressions */
483
List<String> interval_list;
484
bool is_item_list_lookup;
485
Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
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;
519
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
486
520
List<TableList> top_join_list; /* join list of the top level */
487
521
List<TableList> *join_list; /* list for the currently parsed join */
488
522
TableList *embedding; /* table embedding to the above list */
576
613
1 - aggregate functions are used in this select,
577
614
defined as SUM_FUNC_USED.
579
std::bitset<2> full_group_by_flag;
616
uint8_t full_group_by_flag;
581
617
void init_query();
582
618
void init_select();
583
Select_Lex_Unit* master_unit();
584
Select_Lex_Unit* first_inner_unit()
586
return (Select_Lex_Unit*) slave;
588
Select_Lex* outer_select();
589
Select_Lex* next_select()
591
return (Select_Lex*) next;
593
Select_Lex* next_select_in_list()
595
return (Select_Lex*) link_next;
597
Select_Lex_Node** next_select_in_list_addr()
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()
599
632
return &link_next;
601
Select_Lex* return_after_parsing()
634
st_select_lex* return_after_parsing()
603
636
return master_unit()->return_after_parsing();
606
void mark_as_dependent(Select_Lex *last);
639
void mark_as_dependent(st_select_lex *last);
608
641
bool set_braces(bool value);
609
642
bool inc_in_sum_expr();
610
643
uint32_t get_in_sum_expr();
612
bool add_item_to_list(Session *session, Item *item);
613
bool add_group_to_list(Session *session, Item *item, bool asc);
614
bool add_order_to_list(Session *session, Item *item, bool asc);
615
TableList* add_table_to_list(Session *session,
618
const std::bitset<NUM_OF_TABLE_OPTIONS>& table_options,
619
thr_lock_type flags= TL_UNLOCK,
620
List<Index_hint> *hints= 0,
621
LEX_STRING *option= 0);
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);
622
654
TableList* get_table_list();
623
bool init_nested_join(Session *session);
624
TableList *end_nested_join(Session *session);
625
TableList *nest_last_join(Session *session);
655
bool init_nested_join(THD *thd);
656
TableList *end_nested_join(THD *thd);
657
TableList *nest_last_join(THD *thd);
626
658
void add_joined_table(TableList *table);
627
659
TableList *convert_right_join();
628
660
List<Item>* get_item_list();
661
uint32_t get_table_join_options();
629
662
void set_lock_for_tables(thr_lock_type lock_type);
630
663
inline void init_order()
690
721
void clear_index_hints(void) { index_hints= NULL; }
693
724
/* current index hint kind. used in filling up index_hints */
694
725
enum index_hint_type current_index_hint_type;
695
726
index_clause_map current_index_hint_clause;
696
727
/* a list of USE/FORCE/IGNORE INDEX */
697
728
List<Index_hint> *index_hints;
730
typedef class st_select_lex SELECT_LEX;
700
inline bool Select_Lex_Unit::is_union ()
702
return first_select()->next_select() &&
732
inline bool st_select_lex_unit::is_union ()
734
return first_select()->next_select() &&
703
735
first_select()->next_select()->linkage == UNION_TYPE;
738
#define ALTER_ADD_COLUMN (1L << 0)
739
#define ALTER_DROP_COLUMN (1L << 1)
740
#define ALTER_CHANGE_COLUMN (1L << 2)
741
#define ALTER_COLUMN_STORAGE (1L << 3)
742
#define ALTER_COLUMN_FORMAT (1L << 4)
743
#define ALTER_COLUMN_ORDER (1L << 5)
744
#define ALTER_ADD_INDEX (1L << 6)
745
#define ALTER_DROP_INDEX (1L << 7)
746
#define ALTER_RENAME (1L << 8)
747
#define ALTER_ORDER (1L << 9)
748
#define ALTER_OPTIONS (1L << 10)
749
#define ALTER_COLUMN_DEFAULT (1L << 11)
750
#define ALTER_KEYS_ONOFF (1L << 12)
751
#define ALTER_STORAGE (1L << 13)
752
#define ALTER_ROW_FORMAT (1L << 14)
753
#define ALTER_CONVERT (1L << 15)
754
#define ALTER_FORCE (1L << 16)
755
#define ALTER_RECREATE (1L << 17)
756
#define ALTER_TABLE_REORG (1L << 24)
757
#define ALTER_FOREIGN_KEY (1L << 31)
760
@brief Parsing data for CREATE or ALTER Table.
762
This structure contains a list of columns or indexes to be created,
769
List<Alter_drop> drop_list;
770
List<Alter_column> alter_list;
772
List<Create_field> create_list;
774
enum enum_enable_or_disable keys_onoff;
775
enum tablespace_op_type tablespace_op;
777
enum ha_build_method build_method;
778
Create_field *datetime_field;
779
bool error_if_not_empty;
784
keys_onoff(LEAVE_AS_IS),
785
tablespace_op(NO_TABLESPACE_OP),
787
build_method(HA_BUILD_DEFAULT),
788
datetime_field(NULL),
789
error_if_not_empty(false)
799
keys_onoff= LEAVE_AS_IS;
800
tablespace_op= NO_TABLESPACE_OP;
802
build_method= HA_BUILD_DEFAULT;
804
error_if_not_empty= false;
806
Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
808
Alter_info &operator=(const Alter_info &rhs); // not implemented
809
Alter_info(const Alter_info &rhs); // not implemented
812
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
813
XA_SUSPEND, XA_FOR_MIGRATE};
716
815
extern const LEX_STRING null_lex_str;
719
819
Class representing list of all tables used by statement.
720
820
It also contains information about stored functions used by statement
802
} /* namespace drizzled */
804
#include <drizzled/lex_input_stream.h>
809
/* The state of the lex parsing. This is saved in the Session struct */
810
class LEX : public Query_tables_list
813
Select_Lex_Unit unit; /* most upper unit */
814
Select_Lex select_lex; /* first Select_Lex */
815
/* current Select_Lex in parsing */
816
Select_Lex *current_select;
817
/* list of all Select_Lex */
818
Select_Lex *all_selects_list;
820
/* This is the "scale" for DECIMAL (S,P) notation */
822
/* This is the decimal precision in DECIMAL(S,P) notation */
826
* This is used kind of like the "ident" member variable below, as
827
* a place to store certain names of identifiers. Unfortunately, it
828
* is used differently depending on the Command (SELECT on a derived
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;
831
1376
LEX_STRING name;
832
/* The string literal used in a LIKE expression */
1378
char* to_log; /* For PURGE MASTER LOGS TO */
834
file_exchange *exchange;
1380
sql_exchange *exchange;
835
1381
select_result *result;
838
* This is current used to store the name of a named key cache
839
* or a named savepoint. It should probably be refactored out into
840
* the eventual Command class built for the Keycache and Savepoint
1382
Item *default_value, *on_update_value;
1383
LEX_STRING comment, ident;
845
1385
unsigned char* yacc_yyss, *yacc_yyvs;
846
/* The owning Session of this LEX */
1387
virtual_column_info *vcol_info;
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];
848
1393
const CHARSET_INFO *charset;
849
1394
bool text_string_is_7bit;
850
1395
/* store original leaf_tables for INSERT SELECT and PS/SP */
897
1447
syntax error back.
899
1449
bool expr_allows_subselect;
1451
A special command "PARSE_VCOL_EXPR" is defined for the parser
1452
to translate an expression statement of a virtual column \
1453
(stored in the *.frm file as a string) into an Item object.
1454
The following flag is used to prevent other applications to use
1457
bool parse_vcol_expr;
901
1459
thr_lock_type lock_option;
902
1460
enum enum_duplicates duplicates;
1461
enum enum_tx_isolation tx_isolation;
1462
enum enum_ha_read_modes ha_read_mode;
904
1464
enum ha_rkey_function ha_rkey_mode;
905
1465
enum xa_option_words xa_opt;
1466
bool lock_transactional; /* For LOCK Table ... IN ... MODE */
907
sql_var_t option_type;
1468
enum enum_var_type option_type;
1470
uint32_t profile_query_id;
1471
uint32_t profile_options;
1472
enum column_format_type column_format;
1473
uint32_t which_columns;
1474
enum Foreign_key::fk_match_opt fk_match_option;
1475
enum Foreign_key::fk_option fk_update_opt;
1476
enum Foreign_key::fk_option fk_delete_opt;
1477
uint32_t slave_thd_opt, start_transaction_opt;
1480
In LEX representing update which were transformed to multi-update
1481
stores total number of tables. For LEX representing multi-delete
1482
holds number of tables from which we will delete records.
1484
uint32_t table_count;
910
1485
uint8_t describe;
912
1487
A flag that indicates what kinds of derived tables are present in the
913
1488
query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
915
1490
uint8_t derived_tables;
917
/* Was the IGNORE symbol found in statement */
1491
bool drop_if_exists, drop_temporary, local_file, one_shot_set;
1495
bool tx_chain, tx_release;
1496
bool subqueries, ignore;
1497
st_parsing_options parsing_options;
1498
Alter_info alter_info;
1501
field_list was created for view and should be removed before PS/SP
1504
bool empty_field_list_on_rset;
1507
Pointers to part of LOAD DATA statement that should be rewritten
1508
during replication ("LOCAL 'filename' REPLACE INTO" part).
1510
const char *fname_start;
1511
const char *fname_end;
921
During name resolution search only in the table list given by
1514
During name resolution search only in the table list given by
922
1515
Name_resolution_context::first_name_resolution_table and
923
1516
Name_resolution_context::last_name_resolution_table
924
(see Item_field::fix_fields()).
1517
(see Item_field::fix_fields()).
926
1519
bool use_only_table_context;
928
/* Was the ESCAPE keyword used? */
929
1521
bool escape_used;
930
1522
bool is_lex_started; /* If lex_start() did run. For debugging. */
934
/* Note that init and de-init mostly happen in lex_start and lex_end
935
and not here. This is because LEX isn't delete/new for each new
936
statement in a session. It's re-used by doing lex_end, lex_start
1528
destroy_query_tables_list();
1529
plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements);
1530
delete_dynamic(&plugins);
941
1533
TableList *unlink_first_table(bool *link_to_local);
942
1534
void link_first_table_back(TableList *first, bool link_to_local);
943
1535
void first_lists_tables_same();
1537
bool can_be_merged();
1538
bool can_use_merged();
1539
bool can_not_use_merged();
1540
bool only_view_structure();
1541
bool need_correct_ident();
945
1543
void cleanup_after_one_table_open();
947
1545
bool push_context(Name_resolution_context *context)
961
1559
return context_stack.head();
1562
Restore the LEX and THD in case of a parse error.
1564
static void cleanup_lex_after_parse_error(THD *thd);
1566
void reset_n_backup_query_tables_list(Query_tables_list *backup);
1567
void restore_backup_query_tables_list(Query_tables_list *backup);
1569
bool table_or_sp_used();
965
1572
@brief check if the statement is a single-level join
966
1573
@return result of the check
967
@retval true The statement doesn't contain subqueries, unions and
1574
@retval true The statement doesn't contain subqueries, unions and
968
1575
stored procedure calls.
969
1576
@retval false There are subqueries, UNIONs or stored procedure calls.
971
bool is_single_level_stmt()
1578
bool is_single_level_stmt()
974
1581
This check exploits the fact that the last added to all_select_list is
975
on its top. So select_lex (as the first added) will be at the tail
1582
on its top. So select_lex (as the first added) will be at the tail
978
if (&select_lex == all_selects_list)
1585
if (&select_lex == all_selects_list && !sroutines.records)
980
1587
assert(!all_selects_list->next_select_in_list());
985
bool is_cross; // CROSS keyword was used
990
void setCacheable(bool val)
997
sum_expr_used= false;
1001
void setSumExprUsed()
1003
sum_expr_used= true;
1006
bool isSumExprUsed()
1008
return sum_expr_used;
1011
void start(Session *session);
1014
message::Table *table()
1016
if (not _create_table)
1017
_create_table= new message::Table;
1019
return _create_table;
1022
message::Table::Field *field()
1024
return _create_field;
1027
void setField(message::Table::Field *arg)
1045
message::Table *_create_table;
1046
message::Table::Field *_create_field;
1594
struct st_lex_local: public st_lex
1596
static void *operator new(size_t size) throw()
1598
return sql_alloc(size);
1600
static void *operator new(size_t size, MEM_ROOT *mem_root) throw()
1602
return (void*) alloc_root(mem_root, (uint32_t) size);
1604
static void operator delete(void *ptr __attribute__((unused)),
1605
size_t size __attribute__((unused)))
1606
{ TRASH(ptr, size); }
1607
static void operator delete(void *ptr __attribute__((unused)),
1608
MEM_ROOT *mem_root __attribute__((unused)))
1609
{ /* Never called */ }
1050
extern void lex_start(Session *session);
1612
extern void lex_init(void);
1613
extern void lex_free(void);
1614
extern void lex_start(THD *thd);
1615
extern void lex_end(LEX *lex);
1051
1617
extern void trim_whitespace(const CHARSET_INFO * const cs, LEX_STRING *str);
1052
1619
extern bool is_lex_native_function(const LEX_STRING *name);
1054
bool check_for_sql_keyword(drizzled::st_lex_symbol const&);
1055
bool check_for_sql_keyword(drizzled::lex_string_t const&);
1058
1622
@} (End of group Semantic_Analysis)
1061
} /* namespace drizzled */
1063
1625
#endif /* DRIZZLE_SERVER */
1064
#endif /* DRIZZLED_SQL_LEX_H */
1626
#endif /* DRIZZLE_SERVER_SQL_LEX_H */