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"
26
#include "drizzled/sql_udf.h"
29
27
#include "drizzled/name_resolution_context.h"
30
28
#include "drizzled/item/subselect.h"
29
#include "drizzled/item/param.h"
30
#include "drizzled/item/outer_ref.h"
31
31
#include "drizzled/table_list.h"
32
32
#include "drizzled/function/math/real.h"
33
33
#include "drizzled/alter_drop.h"
34
34
#include "drizzled/alter_column.h"
35
#include "drizzled/alter_info.h"
36
#include "drizzled/key_part_spec.h"
35
#include "drizzled/key.h"
36
#include "drizzled/foreign_key.h"
37
#include "drizzled/item/param.h"
37
38
#include "drizzled/index_hint.h"
38
#include "drizzled/statement.h"
39
#include "drizzled/optimizer/explain_plan.h"
47
40
class select_result_interceptor;
41
class virtual_column_info;
49
43
/* YACC and LEX Definitions */
404
399
class Select_Lex: public Select_Lex_Node
416
olap(UNSPECIFIED_OLAP_TYPE),
421
is_item_list_lookup(false),
428
type(optimizer::ST_PRIMARY),
433
ref_pointer_array(0),
434
select_n_having_items(0),
438
select_n_where_fields(0),
439
parsing_place(NO_MATTER),
444
inner_sum_func_list(0),
450
n_child_sum_items(0),
452
subquery_in_having(0),
454
exclude_from_table_unique_test(0),
456
cur_pos_in_select_list(0),
458
full_group_by_flag(),
459
current_index_hint_type(INDEX_HINT_IGNORE),
460
current_index_hint_clause(),
465
402
Name_resolution_context context;
467
/* An Item representing the WHERE clause */
469
/* An Item representing the HAVING clause */
404
Item *where, *having; /* WHERE & HAVING clauses */
471
405
/* Saved values of the WHERE and HAVING clauses*/
472
Item::cond_result cond_value;
473
Item::cond_result having_value;
406
Item::cond_result cond_value, having_value;
474
407
/* point on lex in which it was created, used in view subquery detection */
476
409
enum olap_type olap;
477
410
/* FROM clause - points to the beginning of the TableList::next_local list. */
479
SQL_LIST group_list; /* GROUP BY clause. */
480
List<Item> item_list; /* list of fields & expressions */
481
List<String> interval_list;
482
bool is_item_list_lookup;
483
Join *join; /* after Join::prepare it is pointer to corresponding JOIN */
412
SQL_LIST group_list; /* GROUP BY clause. */
413
List<Item> item_list; /* list of fields & expressions */
414
List<String> interval_list;
415
bool is_item_list_lookup;
417
Despite their names, the following are used in unions. This should
420
List<Item_real_func> *ftfunc_list;
421
List<Item_real_func> ftfunc_list_alloc;
422
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
484
423
List<TableList> top_join_list; /* join list of the top level */
485
424
List<TableList> *join_list; /* list for the currently parsed join */
486
425
TableList *embedding; /* table embedding to the above list */
697
632
first_select()->next_select()->linkage == UNION_TYPE;
635
#define ALTER_ADD_COLUMN (1L << 0)
636
#define ALTER_DROP_COLUMN (1L << 1)
637
#define ALTER_CHANGE_COLUMN (1L << 2)
638
#define ALTER_COLUMN_STORAGE (1L << 3)
639
#define ALTER_COLUMN_FORMAT (1L << 4)
640
#define ALTER_COLUMN_ORDER (1L << 5)
641
#define ALTER_ADD_INDEX (1L << 6)
642
#define ALTER_DROP_INDEX (1L << 7)
643
#define ALTER_RENAME (1L << 8)
644
#define ALTER_ORDER (1L << 9)
645
#define ALTER_OPTIONS (1L << 10)
646
#define ALTER_COLUMN_DEFAULT (1L << 11)
647
#define ALTER_KEYS_ONOFF (1L << 12)
648
#define ALTER_STORAGE (1L << 13)
649
#define ALTER_ROW_FORMAT (1L << 14)
650
#define ALTER_CONVERT (1L << 15)
651
#define ALTER_FORCE (1L << 16)
652
#define ALTER_RECREATE (1L << 17)
653
#define ALTER_TABLE_REORG (1L << 24)
654
#define ALTER_FOREIGN_KEY (1L << 31)
657
@brief Parsing data for CREATE or ALTER Table.
659
This structure contains a list of columns or indexes to be created,
666
List<Alter_drop> drop_list;
667
List<Alter_column> alter_list;
669
List<Create_field> create_list;
671
enum enum_enable_or_disable keys_onoff;
672
enum tablespace_op_type tablespace_op;
674
enum ha_build_method build_method;
675
Create_field *datetime_field;
676
bool error_if_not_empty;
681
keys_onoff(LEAVE_AS_IS),
682
tablespace_op(NO_TABLESPACE_OP),
684
build_method(HA_BUILD_DEFAULT),
685
datetime_field(NULL),
686
error_if_not_empty(false)
696
keys_onoff= LEAVE_AS_IS;
697
tablespace_op= NO_TABLESPACE_OP;
699
build_method= HA_BUILD_DEFAULT;
701
error_if_not_empty= false;
703
Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root);
705
Alter_info &operator=(const Alter_info &rhs); // not implemented
706
Alter_info(const Alter_info &rhs); // not implemented
709
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
710
XA_SUSPEND, XA_FOR_MIGRATE};
710
712
extern const LEX_STRING null_lex_str;
713
716
Class representing list of all tables used by statement.
714
717
It also contains information about stored functions used by statement
796
} /* namespace drizzled */
798
#include "drizzled/lex_input_stream.h"
822
@brief This class represents the character input stream consumed during
825
In addition to consuming the input stream, this class performs some
826
comment pre processing, by filtering out out of bound special text
827
from the query input stream.
828
Two buffers, with pointers inside each buffers, are maintained in
829
parallel. The 'raw' buffer is the original query text, which may
830
contain out-of-bound comments. The 'cpp' (for comments pre processor)
831
is the pre-processed buffer that contains only the query text that
832
should be seen once out-of-bound data is removed.
835
class Lex_input_stream
838
Lex_input_stream(Session *session, const char* buff, unsigned int length);
844
When echo is true, characters parsed from the raw input stream are
845
preserved. When false, characters parsed are silently ignored.
846
@param echo the echo mode.
848
void set_echo(bool echo)
854
Skip binary from the input stream.
855
@param n number of bytes to accept.
857
void skip_binary(int n)
861
memcpy(m_cpp_ptr, m_ptr, n);
868
Get a character, and advance in the stream.
869
@return the next character to parse.
880
Get the last character accepted.
881
@return the last character accepted.
889
Look at the next character to parse, but do not accept it.
897
Look ahead at some character to parse.
898
@param n offset of the character to look up
906
Cancel the effect of the last yyGet() or yySkip().
907
Note that the echo mode should not change between calls to yyGet / yySkip
908
and yyUnget. The caller is responsible for ensuring that.
918
Accept a character, by advancing the input stream.
923
*m_cpp_ptr++ = *m_ptr++;
929
Accept multiple characters at once.
930
@param n the number of characters to accept.
936
memcpy(m_cpp_ptr, m_ptr, n);
943
End of file indicator for the query text to parse.
944
@return true if there are no more characters to parse
948
return (m_ptr >= m_end_of_query);
952
End of file indicator for the query text to parse.
953
@param n number of characters expected
954
@return true if there are less than n characters to parse
958
return ((m_ptr + n) >= m_end_of_query);
961
/** Get the raw query buffer. */
962
const char *get_buf()
967
/** Get the pre-processed query buffer. */
968
const char *get_cpp_buf()
973
/** Get the end of the raw query buffer. */
974
const char *get_end_of_query()
976
return m_end_of_query;
979
/** Mark the stream position as the start of a new token. */
982
m_tok_start_prev= m_tok_start;
986
m_cpp_tok_start_prev= m_cpp_tok_start;
987
m_cpp_tok_start= m_cpp_ptr;
988
m_cpp_tok_end= m_cpp_ptr;
992
Adjust the starting position of the current token.
993
This is used to compensate for starting whitespace.
998
m_cpp_tok_start= m_cpp_ptr;
1001
/** Get the token start position, in the raw buffer. */
1002
const char *get_tok_start()
1007
/** Get the token start position, in the pre-processed buffer. */
1008
const char *get_cpp_tok_start()
1010
return m_cpp_tok_start;
1013
/** Get the token end position, in the raw buffer. */
1014
const char *get_tok_end()
1019
/** Get the token end position, in the pre-processed buffer. */
1020
const char *get_cpp_tok_end()
1022
return m_cpp_tok_end;
1025
/** Get the previous token start position, in the raw buffer. */
1026
const char *get_tok_start_prev()
1028
return m_tok_start_prev;
1031
/** Get the current stream pointer, in the raw buffer. */
1032
const char *get_ptr()
1037
/** Get the current stream pointer, in the pre-processed buffer. */
1038
const char *get_cpp_ptr()
1043
/** Get the length of the current token, in the raw buffer. */
1047
The assumption is that the lexical analyser is always 1 character ahead,
1048
which the -1 account for.
1050
assert(m_ptr > m_tok_start);
1051
return (uint32_t) ((m_ptr - m_tok_start) - 1);
1054
/** Get the utf8-body string. */
1055
const char *get_body_utf8_str()
1060
/** Get the utf8-body length. */
1061
uint32_t get_body_utf8_length()
1063
return m_body_utf8_ptr - m_body_utf8;
1066
void body_utf8_start(Session *session, const char *begin_ptr);
1067
void body_utf8_append(const char *ptr);
1068
void body_utf8_append(const char *ptr, const char *end_ptr);
1069
void body_utf8_append_literal(Session *session,
1070
const LEX_STRING *txt,
1071
const CHARSET_INFO * const txt_cs,
1072
const char *end_ptr);
1074
/** Current thread. */
1077
/** Current line number. */
1080
/** Length of the last token parsed. */
1083
/** Interface with bison, value of the last token parsed. */
1086
/** LALR(2) resolution, look ahead token.*/
1087
int lookahead_token;
1089
/** LALR(2) resolution, value of the look ahead token.*/
1090
LEX_YYSTYPE lookahead_yylval;
1093
/** Pointer to the current position in the raw input stream. */
1096
/** Starting position of the last token parsed, in the raw buffer. */
1097
const char *m_tok_start;
1099
/** Ending position of the previous token parsed, in the raw buffer. */
1100
const char *m_tok_end;
1102
/** End of the query text in the input stream, in the raw buffer. */
1103
const char *m_end_of_query;
1105
/** Starting position of the previous token parsed, in the raw buffer. */
1106
const char *m_tok_start_prev;
1108
/** Begining of the query text in the input stream, in the raw buffer. */
1111
/** Length of the raw buffer. */
1112
uint32_t m_buf_length;
1114
/** Echo the parsed stream to the pre-processed buffer. */
1117
/** Pre-processed buffer. */
1120
/** Pointer to the current position in the pre-processed input stream. */
1124
Starting position of the last token parsed,
1125
in the pre-processed buffer.
1127
const char *m_cpp_tok_start;
1130
Starting position of the previous token parsed,
1131
in the pre-procedded buffer.
1133
const char *m_cpp_tok_start_prev;
1136
Ending position of the previous token parsed,
1137
in the pre-processed buffer.
1139
const char *m_cpp_tok_end;
1141
/** UTF8-body buffer created during parsing. */
1144
/** Pointer to the current position in the UTF8-body buffer. */
1145
char *m_body_utf8_ptr;
1148
Position in the pre-processed buffer. The query from m_cpp_buf to
1149
m_cpp_utf_processed_ptr is converted to UTF8-body.
1151
const char *m_cpp_utf8_processed_ptr;
1155
/** Current state of the lexical analyser. */
1156
enum my_lex_states next_state;
1159
Position of ';' in the stream, to delimit multiple queries.
1160
This delimiter is in the raw buffer.
1162
const char *found_semicolon;
1164
/** Token character bitmaps, to detect 7bit strings. */
1165
unsigned char tok_bitmap;
1167
/** SQL_MODE = IGNORE_SPACE. */
1170
/** State of the lexical analyser for comments. */
1171
enum_comment_state in_comment;
1174
Starting position of the TEXT_STRING or IDENT in the pre-processed
1177
NOTE: this member must be used within DRIZZLElex() function only.
1179
const char *m_cpp_text_start;
1182
Ending position of the TEXT_STRING or IDENT in the pre-processed
1185
NOTE: this member must be used within DRIZZLElex() function only.
1187
const char *m_cpp_text_end;
1190
Character set specified by the character-set-introducer.
1192
NOTE: this member must be used within DRIZZLElex() function only.
1194
const CHARSET_INFO *m_underscore_cs;
803
1198
/* The state of the lex parsing. This is saved in the Session struct */
804
1200
class LEX : public Query_tables_list
891
1274
syntax error back.
893
1276
bool expr_allows_subselect;
1278
A special command "PARSE_VCOL_EXPR" is defined for the parser
1279
to translate an expression statement of a virtual column \
1280
(stored in the *.frm file as a string) into an Item object.
1281
The following flag is used to prevent other applications to use
1284
bool parse_vcol_expr;
895
1286
thr_lock_type lock_option;
896
1287
enum enum_duplicates duplicates;
1288
enum enum_tx_isolation tx_isolation;
1289
enum enum_ha_read_modes ha_read_mode;
898
1291
enum ha_rkey_function ha_rkey_mode;
899
1292
enum xa_option_words xa_opt;
1293
bool lock_transactional; /* For LOCK Table ... IN ... MODE */
901
sql_var_t option_type;
1295
enum enum_var_type option_type;
1297
uint32_t profile_query_id;
1298
uint32_t profile_options;
1299
enum column_format_type column_format;
1300
uint32_t which_columns;
1301
enum Foreign_key::fk_match_opt fk_match_option;
1302
enum Foreign_key::fk_option fk_update_opt;
1303
enum Foreign_key::fk_option fk_delete_opt;
1304
uint32_t slave_session_opt, start_transaction_opt;
1307
In LEX representing update which were transformed to multi-update
1308
stores total number of tables. For LEX representing multi-delete
1309
holds number of tables from which we will delete records.
1311
uint32_t table_count;
904
1312
uint8_t describe;
906
1314
A flag that indicates what kinds of derived tables are present in the
907
1315
query (0 if no derived tables, otherwise DERIVED_SUBQUERY).
909
1317
uint8_t derived_tables;
911
/* Was the IGNORE symbol found in statement */
1318
bool drop_if_exists, drop_temporary, one_shot_set;
1322
bool tx_chain, tx_release;
1323
bool subqueries, ignore;
1324
st_parsing_options parsing_options;
1325
Alter_info alter_info;
1328
Pointers to part of LOAD DATA statement that should be rewritten
1329
during replication ("LOCAL 'filename' REPLACE INTO" part).
1331
const char *fname_start;
1332
const char *fname_end;
915
1335
During name resolution search only in the table list given by