21 #ifndef SQL_LEX_INCLUDED
22 #define SQL_LEX_INCLUDED
25 #include "sql_trigger.h"
28 #include "sql_array.h"
29 #include "mem_root_array.h"
30 #include "sql_alter.h"
90 extern uint binlog_unsafe_map[256];
95 void binlog_unsafe_map_init();
113 #define LEX_YYSTYPE void *
115 #include "lex_symbol.h"
117 #include "item_func.h"
118 #include "sql_get_diagnostics.h"
119 #include "sql_yacc.h"
120 #define LEX_YYSTYPE YYSTYPE *
122 #define LEX_YYSTYPE void *
130 #define DESCRIBE_NONE 0 // Not explain query
131 #define DESCRIBE_NORMAL 1
132 #define DESCRIBE_EXTENDED 2
137 #define DESCRIBE_PARTITIONS 4
141 enum enum_sp_suid_behaviour
143 SP_IS_DEFAULT_SUID= 0,
148 enum enum_sp_data_access
150 SP_DEFAULT_ACCESS= 0,
183 #define TYPE_ENUM_FUNCTION 1
184 #define TYPE_ENUM_PROCEDURE 2
185 #define TYPE_ENUM_TRIGGER 3
186 #define TYPE_ENUM_PROXY 4
190 { C_STRING_WITH_LEN(
"") },
191 { C_STRING_WITH_LEN(
"CONTAINS SQL") },
192 { C_STRING_WITH_LEN(
"NO SQL") },
193 { C_STRING_WITH_LEN(
"READS SQL DATA") },
194 { C_STRING_WITH_LEN(
"MODIFIES SQL DATA") }
197 #define DERIVED_SUBQUERY 1
198 #define DERIVED_VIEW 2
200 enum enum_view_create_mode
204 VIEW_CREATE_OR_REPLACE
215 #define TL_OPTION_UPDATING 1
216 #define TL_OPTION_FORCE_INDEX 2
217 #define TL_OPTION_IGNORE_LEAVES 4
218 #define TL_OPTION_ALIAS 8
224 typedef struct st_lex_server_options
227 uint server_name_length;
228 char *server_name, *host, *db, *username, *password, *scheme, *socket, *owner;
229 } LEX_SERVER_OPTIONS;
239 typedef struct st_lex_master_info
241 char *host, *user, *password, *log_file_name, *bind_addr;
242 uint port, connect_retry;
243 float heartbeat_period;
246 ulong server_id, retry_count;
248 enum {UNTIL_SQL_BEFORE_GTIDS= 0, UNTIL_SQL_AFTER_GTIDS} gtid_until_condition;
249 bool until_after_gaps;
255 enum {LEX_MI_UNCHANGED= 0, LEX_MI_DISABLE, LEX_MI_ENABLE}
256 ssl, ssl_verify_server_cert, heartbeat_opt, repl_ignore_server_ids_opt,
257 retry_count_opt, auto_position;
258 char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
259 char *ssl_crl, *ssl_crlpath;
260 char *relay_log_name;
263 ulong server_ids_buffer[2];
264 void set_unspecified();
267 typedef struct st_lex_reset_slave
274 UNSPECIFIED_TYPE,UNION_TYPE, INTERSECT_TYPE,
275 EXCEPT_TYPE, GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
280 UNSPECIFIED_OLAP_TYPE, CUBE_TYPE, ROLLUP_TYPE
287 extern const char * index_hint_type_name[];
288 typedef uchar index_clause_map;
294 #define INDEX_HINT_MASK_JOIN (1)
295 #define INDEX_HINT_MASK_GROUP (1 << 1)
296 #define INDEX_HINT_MASK_ORDER (1 << 2)
298 #define INDEX_HINT_MASK_ALL (INDEX_HINT_MASK_JOIN | INDEX_HINT_MASK_GROUP | \
299 INDEX_HINT_MASK_ORDER)
306 enum index_hint_type
type;
308 index_clause_map clause;
315 Index_hint (
enum index_hint_type type_arg, index_clause_map clause_arg,
316 char *str, uint length) :
317 type(type_arg), clause(clause_arg)
320 key_name.length= length;
323 void print(THD *thd,
String *str);
446 class st_select_lex_unit;
449 class st_select_lex_node {
451 st_select_lex_node *next, **prev,
453 *link_next, **link_prev;
462 enum e_sql_cache { SQL_CACHE_UNSPECIFIED, SQL_NO_CACHE, SQL_CACHE };
463 e_sql_cache sql_cache;
474 enum sub_select_type linkage;
475 bool no_table_names_allowed;
478 static void *
operator new(
size_t size)
throw ()
480 return sql_alloc(
size);
482 static void *
operator new(
size_t size,
MEM_ROOT *mem_root)
throw ()
483 {
return (
void*) alloc_root(mem_root, (uint)
size); }
484 static void operator delete(
void *ptr,
size_t size) { TRASH(ptr,
size); }
485 static void operator delete(
void *ptr,
MEM_ROOT *mem_root) {}
489 : next(NULL), prev(NULL),
490 master(NULL), slave(NULL),
491 link_next(NULL), link_prev(NULL),
492 linkage(UNSPECIFIED_TYPE)
495 virtual ~st_select_lex_node() {}
497 inline st_select_lex_node* get_master() {
return master; }
498 virtual void init_query();
499 virtual void init_select();
500 void include_down(st_select_lex_node *upper);
501 void include_neighbour(st_select_lex_node *before);
502 void include_standalone(st_select_lex_node *sel, st_select_lex_node **ref);
503 void include_global(st_select_lex_node **plink);
506 virtual st_select_lex_unit* master_unit()= 0;
507 virtual st_select_lex* outer_select()= 0;
509 virtual bool set_braces(
bool value);
510 virtual bool inc_in_sum_expr();
511 virtual uint get_in_sum_expr();
514 virtual ulong get_table_join_options();
518 thr_lock_type
flags= TL_UNLOCK,
519 enum_mdl_type mdl_type= MDL_SHARED_READ,
523 virtual void set_lock_for_tables(thr_lock_type lock_type) {}
525 friend class st_select_lex_unit;
528 bool open_view_no_parse);
532 typedef class st_select_lex_node SELECT_LEX_NODE;
544 class st_select_lex_unit:
public st_select_lex_node {
547 select_union *union_result;
550 select_result *result;
551 ulonglong found_rows_for_union;
557 : union_result(NULL),
table(NULL), result(NULL),
559 fake_select_lex(NULL),
587 st_select_lex *global_parameters;
589 ha_rows select_limit_cnt, offset_limit_cnt;
598 st_select_lex *fake_select_lex;
600 st_select_lex *union_distinct;
615 st_select_lex_unit* master_unit();
616 st_select_lex* outer_select();
617 st_select_lex* first_select()
619 return reinterpret_cast<st_select_lex*
>(slave);
621 st_select_lex_unit* next_unit()
623 return reinterpret_cast<st_select_lex_unit*
>(next);
625 void exclude_level();
627 inline select_result *get_result() {
return result; }
630 bool prepare(THD *thd, select_result *result, ulong additional_options);
635 bool cleanup_level();
636 inline void unclean() { cleaned= 0; }
637 void reinit_exec_mechanism();
639 void print(
String *str, enum_query_type query_type);
641 bool add_fake_select_lex(THD *thd);
642 bool init_prepare_fake_select_lex(THD *thd,
bool no_const_tables);
643 inline bool is_prepared() {
return prepared; }
644 bool change_result(select_result_interceptor *result,
645 select_result_interceptor *old_result);
646 void set_limit(st_select_lex *values);
647 void set_thd(THD *thd_arg) { thd= thd_arg; }
648 inline bool is_union ();
650 friend void lex_start(THD *thd);
651 friend bool subselect_union_engine::exec();
659 typedef class st_select_lex_unit SELECT_LEX_UNIT;
665 class st_select_lex:
public st_select_lex_node
673 enum Resolve_place { RESOLVE_NONE, RESOLVE_JOIN_NEST, RESOLVE_CONDITION,
675 Resolve_place resolve_place;
678 Item *where, *having;
689 Item::cond_result cond_value, having_value;
703 Group_list_ptrs *group_list_ptrs;
713 bool is_item_list_lookup;
757 Group_list_ptrs *order_list_ptrs;
760 Item *select_limit, *offset_limit;
763 Ref_ptr_array ref_pointer_array;
766 uint derived_table_count;
768 uint materialized_table_count;
770 uint partitioned_table_count;
776 uint select_n_having_items;
779 uint max_equal_elems;
784 uint select_n_where_fields;
785 enum_parsing_place parsing_place;
788 ulong table_join_options;
801 bool having_fix_field;
803 bool group_fix_field;
809 uint n_child_sum_items;
817 bool subquery_in_having;
830 bool first_execution;
831 bool first_natural_join_processing;
832 bool first_cond_optimization;
834 bool no_wrap_view_item;
836 bool exclude_from_table_unique_test;
841 static const int ALL_FIELDS_UNDEF_POS= INT_MIN;
853 int cur_pos_in_all_fields;
875 table_map select_list_tables;
877 st_select_lex *removed_select;
881 st_select_lex_unit* master_unit();
882 st_select_lex_unit* first_inner_unit()
884 return (st_select_lex_unit*) slave;
886 st_select_lex* outer_select();
887 st_select_lex* next_select() {
return (st_select_lex*) next; }
889 st_select_lex* last_select()
891 st_select_lex* mylast=
this;
892 for (; mylast->next_select(); mylast= mylast->next_select())
897 st_select_lex* next_select_in_list()
899 return (st_select_lex*) link_next;
901 st_select_lex_node** next_select_in_list_addr()
906 void mark_as_dependent(st_select_lex *last);
908 bool set_braces(
bool value);
909 bool inc_in_sum_expr();
910 uint get_in_sum_expr();
912 bool add_item_to_list(THD *thd,
Item *item);
913 bool add_group_to_list(THD *thd,
Item *item,
bool asc);
915 bool add_order_to_list(THD *thd,
Item *item,
bool asc);
916 bool add_gorder_to_list(THD *thd,
Item *item,
bool asc);
920 thr_lock_type
flags= TL_UNLOCK,
921 enum_mdl_type mdl_type= MDL_SHARED_READ,
926 bool init_nested_join(THD *thd);
932 ulong get_table_join_options();
933 void set_lock_for_tables(thr_lock_type lock_type);
934 inline void init_order()
936 order_list.elements= 0;
938 order_list.next= &order_list.first;
946 void cut_subtree() { slave= 0; }
949 friend void lex_start(THD *thd);
950 st_select_lex() : group_list_ptrs(NULL), order_list_ptrs(NULL),
951 n_sum_items(0), n_child_sum_items(0),
952 cur_pos_in_all_fields(ALL_FIELDS_UNDEF_POS)
954 void make_empty_select()
959 bool setup_ref_array(THD *thd, uint order_group_num);
960 void print(THD *thd,
String *str, enum_query_type query_type);
961 static void print_order(
String *str,
963 enum_query_type query_type);
964 void print_limit(THD *thd,
String *str, enum_query_type query_type);
965 void fix_prepare_information(THD *thd,
Item **conds,
Item **having_conds);
971 bool cleanup_level();
976 void cleanup_all_joins(
bool full);
978 void set_index_hint_type(
enum index_hint_type
type, index_clause_map clause);
984 bool add_index_hint (THD *thd,
char *str, uint length);
987 void alloc_index_hints (THD *thd);
996 void clear_index_hints(
void) { index_hints= NULL; }
997 bool handle_derived(LEX *lex,
bool (*processor)(THD*, LEX*,
TABLE_LIST*));
998 bool is_part_of_union() {
return master_unit()->is_union(); }
1006 bool non_agg_field_used()
const {
return m_non_agg_field_used; }
1007 bool agg_func_used()
const {
return m_agg_func_used; }
1009 void set_non_agg_field_used(
bool val) { m_non_agg_field_used= val; }
1010 void set_agg_func_used(
bool val) { m_agg_func_used= val; }
1013 type_enum
type(
const THD *thd);
1016 const char *get_type_str(
const THD *thd) {
return type_str[
type(thd)]; }
1017 static const char *get_type_str(type_enum
type) {
return type_str[
type]; }
1019 bool is_dependent()
const {
return uncacheable & UNCACHEABLE_DEPENDENT; }
1020 bool is_cacheable()
const
1027 bool m_non_agg_field_used;
1028 bool m_agg_func_used;
1031 enum index_hint_type current_index_hint_type;
1032 index_clause_map current_index_hint_clause;
1036 static const char *type_str[SLT_total];
1038 typedef class st_select_lex SELECT_LEX;
1040 inline bool st_select_lex_unit::is_union ()
1042 return first_select()->next_select() &&
1043 first_select()->next_select()->linkage == UNION_TYPE;
1047 class Switch_resolve_place
1050 Switch_resolve_place(SELECT_LEX::Resolve_place *rp_ptr,
1051 SELECT_LEX::Resolve_place new_rp,
1053 : rp(NULL), saved_rp()
1062 ~Switch_resolve_place()
1068 SELECT_LEX::Resolve_place *rp;
1069 SELECT_LEX::Resolve_place saved_rp;
1073 typedef struct struct_slave_connection
1081 } LEX_SLAVE_CONNECTION;
1083 struct st_sp_chistics
1086 enum enum_sp_suid_behaviour suid;
1088 enum enum_sp_data_access daccess;
1094 struct st_trg_chistics
1096 enum trg_action_time_type action_time;
1097 enum trg_event_type
event;
1100 extern sys_var *trg_new_row_fake_var;
1102 enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
1103 XA_SUSPEND, XA_FOR_MIGRATE};
1123 class Query_tables_list
1132 enum_sql_command sql_command;
1148 enum { START_SROUTINES_HASH_SIZE= 16 };
1161 uint sroutines_list_own_elements;
1175 enum enum_lock_tables_state {
1179 enum_lock_tables_state lock_tables_state;
1180 bool is_query_tables_locked()
1182 return (lock_tables_state == LTS_LOCKED);
1198 Query_tables_list() {}
1199 ~Query_tables_list() {}
1202 void reset_query_tables_list(
bool init);
1203 void destroy_query_tables_list();
1204 void set_query_tables_list(Query_tables_list *state)
1216 *(table->prev_global= query_tables_last)= table;
1217 query_tables_last= &table->next_global;
1219 bool requires_prelocking()
1221 return test(query_tables_own_last);
1223 void mark_as_requiring_prelocking(
TABLE_LIST **tables_own_last)
1225 query_tables_own_last= tables_own_last;
1230 return ( query_tables_own_last ? *query_tables_own_last : 0);
1232 void chop_off_not_own_tables()
1234 if (query_tables_own_last)
1236 *query_tables_own_last= 0;
1237 query_tables_last= query_tables_own_last;
1238 query_tables_own_last= 0;
1246 return query_tables ?
1248 ((
char*) &(query_tables->next_global) -
1249 (
char*) query_tables)) :
1260 enum enum_binlog_stmt_unsafe {
1265 BINLOG_STMT_UNSAFE_LIMIT= 0,
1270 BINLOG_STMT_UNSAFE_INSERT_DELAYED,
1275 BINLOG_STMT_UNSAFE_SYSTEM_TABLE,
1285 BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS,
1289 BINLOG_STMT_UNSAFE_UDF,
1294 BINLOG_STMT_UNSAFE_SYSTEM_VARIABLE,
1298 BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION,
1305 BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS,
1311 BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE,
1317 BINLOG_STMT_UNSAFE_MIXED_STATEMENT,
1324 BINLOG_STMT_UNSAFE_INSERT_IGNORE_SELECT,
1331 BINLOG_STMT_UNSAFE_INSERT_SELECT_UPDATE,
1338 BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT,
1345 BINLOG_STMT_UNSAFE_REPLACE_SELECT,
1352 BINLOG_STMT_UNSAFE_CREATE_IGNORE_SELECT,
1359 BINLOG_STMT_UNSAFE_CREATE_REPLACE_SELECT,
1367 BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC,
1374 BINLOG_STMT_UNSAFE_UPDATE_IGNORE,
1380 BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS,
1386 BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST,
1389 BINLOG_STMT_UNSAFE_COUNT
1395 static const int BINLOG_STMT_UNSAFE_ALL_FLAGS=
1396 ((1 << BINLOG_STMT_UNSAFE_COUNT) - 1);
1401 static const int binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT];
1409 inline bool is_stmt_unsafe()
const {
1410 return get_stmt_unsafe_flags() != 0;
1420 inline void set_stmt_unsafe(enum_binlog_stmt_unsafe unsafe_type) {
1421 DBUG_ENTER(
"set_stmt_unsafe");
1422 DBUG_ASSERT(unsafe_type >= 0 && unsafe_type < BINLOG_STMT_UNSAFE_COUNT);
1423 binlog_stmt_flags|= (1
U << unsafe_type);
1435 inline void set_stmt_unsafe_flags(uint32
flags) {
1436 DBUG_ENTER(
"set_stmt_unsafe_flags");
1437 DBUG_ASSERT((flags & ~BINLOG_STMT_UNSAFE_ALL_FLAGS) == 0);
1438 binlog_stmt_flags|=
flags;
1448 inline uint32 get_stmt_unsafe_flags()
const {
1449 DBUG_ENTER(
"get_stmt_unsafe_flags");
1450 DBUG_RETURN(binlog_stmt_flags & BINLOG_STMT_UNSAFE_ALL_FLAGS);
1458 inline void clear_stmt_unsafe() {
1459 DBUG_ENTER(
"clear_stmt_unsafe");
1460 binlog_stmt_flags&= ~BINLOG_STMT_UNSAFE_ALL_FLAGS;
1470 inline bool is_stmt_row_injection()
const {
1471 return binlog_stmt_flags &
1472 (1
U << (BINLOG_STMT_UNSAFE_COUNT + BINLOG_STMT_TYPE_ROW_INJECTION));
1480 inline void set_stmt_row_injection() {
1481 DBUG_ENTER(
"set_stmt_row_injection");
1483 (1
U << (BINLOG_STMT_UNSAFE_COUNT + BINLOG_STMT_TYPE_ROW_INJECTION));
1487 enum enum_stmt_accessed_table
1493 STMT_READS_TRANS_TABLE= 0,
1498 STMT_READS_NON_TRANS_TABLE,
1503 STMT_READS_TEMP_TRANS_TABLE,
1508 STMT_READS_TEMP_NON_TRANS_TABLE,
1512 STMT_WRITES_TRANS_TABLE,
1516 STMT_WRITES_NON_TRANS_TABLE,
1520 STMT_WRITES_TEMP_TRANS_TABLE,
1524 STMT_WRITES_TEMP_NON_TRANS_TABLE,
1529 STMT_ACCESS_TABLE_COUNT
1533 static inline const char *stmt_accessed_table_string(enum_stmt_accessed_table accessed_table)
1535 switch (accessed_table)
1537 case STMT_READS_TRANS_TABLE:
1538 return "STMT_READS_TRANS_TABLE";
1540 case STMT_READS_NON_TRANS_TABLE:
1541 return "STMT_READS_NON_TRANS_TABLE";
1543 case STMT_READS_TEMP_TRANS_TABLE:
1544 return "STMT_READS_TEMP_TRANS_TABLE";
1546 case STMT_READS_TEMP_NON_TRANS_TABLE:
1547 return "STMT_READS_TEMP_NON_TRANS_TABLE";
1549 case STMT_WRITES_TRANS_TABLE:
1550 return "STMT_WRITES_TRANS_TABLE";
1552 case STMT_WRITES_NON_TRANS_TABLE:
1553 return "STMT_WRITES_NON_TRANS_TABLE";
1555 case STMT_WRITES_TEMP_TRANS_TABLE:
1556 return "STMT_WRITES_TEMP_TRANS_TABLE";
1558 case STMT_WRITES_TEMP_NON_TRANS_TABLE:
1559 return "STMT_WRITES_TEMP_NON_TRANS_TABLE";
1561 case STMT_ACCESS_TABLE_COUNT:
1566 MY_ASSERT_UNREACHABLE();
1571 #define BINLOG_DIRECT_ON 0xF0
1575 #define BINLOG_DIRECT_OFF 0xF
1579 #define TRX_CACHE_EMPTY 0x33
1581 #define TRX_CACHE_NOT_EMPTY 0xCC
1583 #define IL_LT_REPEATABLE 0xAA
1585 #define IL_GTE_REPEATABLE 0x55
1594 inline void set_stmt_accessed_table(enum_stmt_accessed_table accessed_table)
1596 DBUG_ENTER(
"LEX::set_stmt_accessed_table");
1598 DBUG_ASSERT(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
1599 stmt_accessed_table_flag |= (1
U << accessed_table);
1615 inline bool stmt_accessed_table(enum_stmt_accessed_table accessed_table)
1617 DBUG_ENTER(
"LEX::stmt_accessed_table");
1619 DBUG_ASSERT(accessed_table >= 0 && accessed_table < STMT_ACCESS_TABLE_COUNT);
1621 DBUG_RETURN((stmt_accessed_table_flag & (1
U << accessed_table)) != 0);
1639 inline bool is_mixed_stmt_unsafe(
bool in_multi_stmt_transaction_mode,
1641 bool trx_cache_is_not_empty,
1646 if (in_multi_stmt_transaction_mode)
1649 (binlog_direct ? BINLOG_DIRECT_ON : BINLOG_DIRECT_OFF) &
1650 (trx_cache_is_not_empty ? TRX_CACHE_NOT_EMPTY : TRX_CACHE_EMPTY) &
1651 (tx_isolation >= ISO_REPEATABLE_READ ? IL_GTE_REPEATABLE : IL_LT_REPEATABLE);
1653 unsafe= (binlog_unsafe_map[stmt_accessed_table_flag] & condition);
1655 #if !defined(DBUG_OFF)
1656 DBUG_PRINT(
"LEX::is_mixed_stmt_unsafe", (
"RESULT %02X %02X %02X\n", condition,
1657 binlog_unsafe_map[stmt_accessed_table_flag],
1658 (binlog_unsafe_map[stmt_accessed_table_flag] & condition)));
1661 for (; type_in < STMT_ACCESS_TABLE_COUNT; type_in++)
1663 if (stmt_accessed_table((enum_stmt_accessed_table) type_in))
1664 DBUG_PRINT(
"LEX::is_mixed_stmt_unsafe", (
"ACCESSED %s ",
1665 stmt_accessed_table_string((enum_stmt_accessed_table) type_in)));
1670 if (stmt_accessed_table(STMT_WRITES_NON_TRANS_TABLE) &&
1671 stmt_accessed_table(STMT_READS_TRANS_TABLE) &&
1672 tx_isolation < ISO_REPEATABLE_READ)
1674 else if (stmt_accessed_table(STMT_WRITES_TEMP_NON_TRANS_TABLE) &&
1675 stmt_accessed_table(STMT_READS_TRANS_TABLE) &&
1676 tx_isolation < ISO_REPEATABLE_READ)
1686 bool uses_stored_routines()
const
1687 {
return sroutines_list.elements != 0; }
1696 enum enum_binlog_stmt_type {
1701 BINLOG_STMT_TYPE_ROW_INJECTION = 0,
1704 BINLOG_STMT_TYPE_COUNT
1722 uint32 binlog_stmt_flags;
1728 uint32 stmt_accessed_table_flag;
1737 struct st_parsing_options
1739 bool allows_variable;
1740 bool allows_select_into;
1741 bool allows_select_procedure;
1742 bool allows_derived;
1744 st_parsing_options() { reset(); }
1752 enum enum_comment_state
1787 class Lex_input_stream
1804 bool init(THD *thd,
char *buff,
unsigned int length);
1806 void reset(
char *buff,
unsigned int length);
1815 void set_echo(
bool echo)
1820 void save_in_comment_state()
1822 m_echo_saved= m_echo;
1823 in_comment_saved= in_comment;
1826 void restore_in_comment_state()
1828 m_echo= m_echo_saved;
1829 in_comment= in_comment_saved;
1836 void skip_binary(
int n)
1840 memcpy(m_cpp_ptr, m_ptr, n);
1850 unsigned char yyGet()
1862 unsigned char yyGetLast()
1870 unsigned char yyPeek()
1879 unsigned char yyPeekn(
int n)
1902 *m_cpp_ptr++ = *m_ptr++;
1915 memcpy(m_cpp_ptr, m_ptr, n);
1927 char *yyUnput(
char ch)
1942 char *cpp_inject(
char ch)
1954 return (m_ptr >= m_end_of_query);
1964 return ((m_ptr + n) >= m_end_of_query);
1968 const char *get_buf()
1974 const char *get_cpp_buf()
1980 const char *get_end_of_query()
1982 return m_end_of_query;
1988 m_tok_start_prev= m_tok_start;
1992 m_cpp_tok_start_prev= m_cpp_tok_start;
1993 m_cpp_tok_start= m_cpp_ptr;
1994 m_cpp_tok_end= m_cpp_ptr;
2001 void restart_token()
2004 m_cpp_tok_start= m_cpp_ptr;
2008 const char *get_tok_start()
2014 const char *get_cpp_tok_start()
2016 return m_cpp_tok_start;
2020 const char *get_tok_end()
2026 const char *get_cpp_tok_end()
2028 return m_cpp_tok_end;
2032 const char *get_tok_start_prev()
2034 return m_tok_start_prev;
2038 const char *get_ptr()
2044 const char *get_cpp_ptr()
2056 DBUG_ASSERT(m_ptr > m_tok_start);
2057 return (uint) ((m_ptr - m_tok_start) - 1);
2061 const char *get_body_utf8_str()
2067 uint get_body_utf8_length()
2069 return (uint) (m_body_utf8_ptr - m_body_utf8);
2072 void body_utf8_start(THD *thd,
const char *begin_ptr);
2073 void body_utf8_append(
const char *ptr);
2074 void body_utf8_append(
const char *ptr,
const char *end_ptr);
2075 void body_utf8_append_literal(THD *thd,
2078 const char *end_ptr);
2098 int lookahead_token;
2101 LEX_YYSTYPE lookahead_yylval;
2108 const char *m_tok_start;
2111 const char *m_tok_end;
2114 const char *m_end_of_query;
2117 const char *m_tok_start_prev;
2139 const char *m_cpp_tok_start;
2145 const char *m_cpp_tok_start_prev;
2151 const char *m_cpp_tok_end;
2157 char *m_body_utf8_ptr;
2163 const char *m_cpp_utf8_processed_ptr;
2168 enum my_lex_states next_state;
2174 const char *found_semicolon;
2186 bool stmt_prepare_mode;
2190 bool multi_statements;
2193 enum_comment_state in_comment;
2194 enum_comment_state in_comment_saved;
2202 const char *m_cpp_text_start;
2210 const char *m_cpp_text_end;
2222 PSI_digest_locker* m_digest_psi;
2230 struct Proc_analyse_params:
public Sql_alloc
2232 uint max_tree_elements;
2235 Proc_analyse_params()
2236 : max_tree_elements(256),
2244 struct LEX:
public Query_tables_list
2246 SELECT_LEX_UNIT unit;
2247 SELECT_LEX select_lex;
2249 SELECT_LEX *current_select;
2251 SELECT_LEX *all_selects_list;
2253 char *length,*dec,*change;
2257 char* x509_subject,*x509_issuer,*ssl_cipher;
2259 sql_exchange *exchange;
2260 select_result *result;
2261 Item *default_value, *on_update_value;
2269 plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
2272 bool text_string_is_7bit;
2280 const char* raw_trg_on_table_name_begin;
2282 const char* raw_trg_on_table_name_end;
2305 List<Item> *insert_list,field_list,value_list,update_list;
2329 Proc_analyse_params *proc_analyse;
2338 LEX_SLAVE_CONNECTION slave_connection;
2339 LEX_SERVER_OPTIONS server_options;
2341 LEX_RESET_SLAVE reset_slave_info;
2352 nesting_map allow_sum_func;
2362 bool expr_allows_subselect;
2364 enum SSL_type ssl_type;
2365 enum enum_duplicates duplicates;
2366 enum enum_tx_isolation tx_isolation;
2367 enum xa_option_words xa_opt;
2368 enum enum_var_type option_type;
2369 enum enum_view_create_mode create_view_mode;
2370 enum enum_drop_mode drop_mode;
2372 uint profile_query_id;
2373 uint profile_options;
2374 uint uint_geom_type;
2375 uint grant, grant_tot_col, which_columns;
2376 enum Foreign_key::fk_match_opt fk_match_option;
2377 enum Foreign_key::fk_option fk_update_opt;
2378 enum Foreign_key::fk_option fk_delete_opt;
2379 uint slave_thd_opt, start_transaction_opt;
2387 uint8 derived_tables;
2388 uint8 create_view_algorithm;
2389 uint8 create_view_check;
2390 uint8 context_analysis_only;
2391 bool drop_if_exists, drop_temporary, local_file, one_shot_set;
2393 bool verbose, no_write_to_binlog;
2395 enum enum_yes_no_unknown tx_chain, tx_release;
2396 bool safe_to_cache_query;
2397 bool subqueries, ignore;
2398 st_parsing_options parsing_options;
2414 bool prepared_stmt_code_is_varref;
2420 bool all_privileges;
2422 bool is_change_password;
2428 bool is_set_password_sql;
2429 bool contains_plaintext_password;
2439 bool is_broken()
const {
return m_broken; }
2448 void mark_broken(
bool broken=
true)
2459 if (is_metadata_used())
2467 {
return sp_current_parsing_ctx; }
2470 { sp_current_parsing_ctx= ctx; }
2474 bool is_metadata_used()
const
2475 {
return query_tables != NULL || sroutines.records > 0; }
2478 st_sp_chistics sp_chistics;
2487 bool empty_field_list_on_rset;
2491 uint8 create_view_suid;
2509 const char *stmt_definition_begin;
2510 uint keyword_delayed_begin_offset;
2514 const char *stmt_definition_end;
2515 uint keyword_delayed_end_offset;
2524 bool use_only_table_context;
2533 bool is_lex_started;
2543 table_map used_tables;
2551 destroy_query_tables_list();
2552 plugin_unlock_list(NULL, (
plugin_ref *)plugins.buffer, plugins.elements);
2553 delete_dynamic(&plugins);
2556 inline bool is_ps_or_view_context_analysis()
2558 return (context_analysis_only &
2559 (CONTEXT_ANALYSIS_ONLY_PREPARE |
2560 CONTEXT_ANALYSIS_ONLY_VIEW));
2563 inline void uncacheable(uint8 cause)
2565 safe_to_cache_query= 0;
2573 SELECT_LEX_UNIT *un;
2574 for (sl= current_select, un= sl->master_unit();
2576 sl= sl->outer_select(), un= sl->master_unit())
2578 sl->uncacheable|= cause;
2579 un->uncacheable|= cause;
2582 void set_trg_event_type_for_tables();
2584 TABLE_LIST *unlink_first_table(
bool *link_to_local);
2585 void link_first_table_back(
TABLE_LIST *first,
bool link_to_local);
2586 void first_lists_tables_same();
2588 bool can_be_merged();
2589 bool can_use_merged();
2590 bool can_not_use_merged();
2591 bool only_view_structure();
2592 bool need_correct_ident();
2604 inline bool which_check_option_applicable()
2606 switch (sql_command) {
2608 case SQLCOM_UPDATE_MULTI:
2610 case SQLCOM_INSERT_SELECT:
2611 case SQLCOM_REPLACE:
2612 case SQLCOM_REPLACE_SELECT:
2620 void cleanup_after_one_table_open();
2624 return context_stack.push_front(context);
2629 context_stack.pop();
2632 bool copy_db_to(
char **p_db,
size_t *p_db_length)
const;
2636 return context_stack.head();
2641 static void cleanup_lex_after_parse_error(THD *thd);
2643 void reset_n_backup_query_tables_list(Query_tables_list *backup);
2644 void restore_backup_query_tables_list(Query_tables_list *backup);
2646 bool table_or_sp_used();
2647 bool is_partition_management()
const;
2656 bool is_single_level_stmt()
2663 if (&select_lex == all_selects_list && !sroutines.records)
2665 DBUG_ASSERT(!all_selects_list->next_select_in_list());
2678 class Set_signal_information
2682 Set_signal_information() {}
2685 Set_signal_information(
const Set_signal_information&
set);
2688 ~Set_signal_information()
2699 Item *m_item[LAST_DIAG_SET_PROPERTY+1];
2720 m_set_signal_info.clear();
2721 m_lock_type= TL_READ_DEFAULT;
2722 m_mdl_type= MDL_SHARED_READ;
2723 m_ha_rkey_mode= HA_READ_KEY_EXACT;
2732 void reset_before_substatement()
2734 m_lock_type= TL_READ_DEFAULT;
2735 m_mdl_type= MDL_SHARED_READ;
2736 m_ha_rkey_mode= HA_READ_KEY_EXACT;
2755 Set_signal_information m_set_signal_info;
2774 thr_lock_type m_lock_type;
2780 enum_mdl_type m_mdl_type;
2783 enum ha_rkey_function m_ha_rkey_mode;
2809 bool init(THD *thd,
char *buff,
unsigned int length)
2811 return m_lip.init(thd, buff, length);
2817 Lex_input_stream m_lip;
2820 void reset(
char *found_semicolon,
unsigned int length)
2822 m_lip.reset(found_semicolon, length);
2828 struct st_lex_local:
public LEX
2830 static void *
operator new(
size_t size)
throw()
2832 return sql_alloc(
size);
2834 static void *
operator new(
size_t size,
MEM_ROOT *mem_root)
throw()
2836 return (
void*) alloc_root(mem_root, (uint)
size);
2838 static void operator delete(
void *ptr,
size_t size)
2839 { TRASH(ptr,
size); }
2840 static void operator delete(
void *ptr,
MEM_ROOT *mem_root)
2844 extern void lex_init(
void);
2845 extern void lex_free(
void);
2846 extern void lex_start(THD *thd);
2847 extern void lex_end(LEX *lex);
2848 extern int MYSQLlex(
void *arg,
void *yythd);
2858 void my_missing_function_error(
const LEX_STRING &token,
const char *
name);
2859 bool is_keyword(
const char *
name, uint len);
2860 bool db_is_default_db(
const char *db,
size_t db_len,
const THD *thd);