34
44
const LEX_STRING null_lex_str= {NULL, 0};
36
/* Longest standard keyword name */
38
#define TOCK_NAME_LENGTH 24
41
The following data is based on the latin1 character set, and is only
42
used when comparing keywords
45
static uchar to_upper_lex[]=
47
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
48
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
49
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
50
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
51
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
52
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
53
96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
54
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
55
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
56
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
57
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
58
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
59
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
60
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
61
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
62
208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
66
Names of the index hints (for error messages). Keep in sync with
70
const char * index_hint_type_name[] =
77
inline int lex_casecmp(const char *s, const char *t, uint len)
80
to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
90
for (i=0 ; i < array_elements(symbols) ; i++)
91
symbols[i].length=(uchar) strlen(symbols[i].name);
92
for (i=0 ; i < array_elements(sql_functions) ; i++)
93
sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
100
{ // Call this when daemon ends
106
st_parsing_options::reset()
108
allows_variable= true;
109
allows_select_into= true;
110
allows_select_procedure= true;
111
allows_derived= true;
114
Lex_input_stream::Lex_input_stream(THD *thd,
46
Lex_input_stream::Lex_input_stream(Session *session,
115
47
const char* buffer,
116
48
unsigned int length)
233
161
The operation converts the specified text literal to the utf8 and appends
234
162
the result to the utf8-body.
236
@param thd Thread context.
164
@param session Thread context.
237
165
@param txt Text literal.
238
166
@param txt_cs Character set of the text literal.
239
167
@param end_ptr Pointer in the pre-processed buffer, to which
240
168
m_cpp_utf8_processed_ptr will be set in the end of the
244
void Lex_input_stream::body_utf8_append_literal(THD *thd,
245
const LEX_STRING *txt,
246
const CHARSET_INFO * const txt_cs,
171
void Lex_input_stream::body_utf8_append_literal(const LEX_STRING *txt,
247
172
const char *end_ptr)
249
174
if (!m_cpp_utf8_processed_ptr)
254
if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
256
thd->convert_string(&utf_txt,
257
&my_charset_utf8_general_ci,
258
txt->str, txt->length,
263
utf_txt.str= txt->str;
264
utf_txt.length= txt->length;
267
177
/* NOTE: utf_txt.length is in bytes, not in symbols. */
269
memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
270
m_body_utf8_ptr += utf_txt.length;
179
memcpy(m_body_utf8_ptr, txt->str, txt->length);
180
m_body_utf8_ptr += txt->length;
271
181
*m_body_utf8_ptr= 0;
273
183
m_cpp_utf8_processed_ptr= end_ptr;
278
187
This is called before every query that is to be parsed.
279
188
Because of this, it's critical to not do too much things here.
280
189
(We already do too much here)
283
void lex_start(THD *thd)
191
void lex_start(Session *session)
193
LEX *lex= session->lex;
287
lex->thd= lex->unit.thd= thd;
195
lex->session= lex->unit.session= session;
289
197
lex->context_stack.empty();
290
198
lex->unit.init_query();
337
239
lex->nest_level=0 ;
338
240
lex->allow_sum_func= 0;
339
241
lex->in_sum_func= NULL;
341
ok, there must be a better solution for this, long-term
342
I tried "memset" in the sql_yacc.yy code, but that for
343
some reason made the values zero, even if they were set
345
lex->server_options.server_name= 0;
346
lex->server_options.server_name_length= 0;
347
lex->server_options.host= 0;
348
lex->server_options.db= 0;
349
lex->server_options.username= 0;
350
lex->server_options.password= 0;
351
lex->server_options.scheme= 0;
352
lex->server_options.owner= 0;
353
lex->server_options.port= -1;
355
243
lex->is_lex_started= true;
244
lex->create_table_proto= NULL;
359
247
void lex_end(LEX *lex)
361
249
if (lex->yacc_yyss)
363
my_free(lex->yacc_yyss, MYF(0));
364
my_free(lex->yacc_yyvs, MYF(0));
251
free(lex->yacc_yyss);
252
free(lex->yacc_yyvs);
365
253
lex->yacc_yyss= 0;
366
254
lex->yacc_yyvs= 0;
369
/* release used plugins */
370
plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer,
371
lex->plugins.elements);
372
reset_dynamic(&lex->plugins);
259
if(lex->create_table_proto)
260
delete lex->create_table_proto;
378
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
264
static int find_keyword(Lex_input_stream *lip, uint32_t len, bool function)
266
/* Plenty of memory for the largest lex symbol we have */
380
268
const char *tok= lip->get_tok_start();
270
for (;tok_pos<len && tok_pos<63;tok_pos++)
271
tok_upper[tok_pos]=my_toupper(system_charset_info, tok[tok_pos]);
272
tok_upper[tok_pos]=0;
382
SYMBOL *symbol= get_hash_symbol(tok, len, function);
274
const SYMBOL *symbol= lookup_symbol(tok_upper, len, function);
385
277
lip->yylval->symbol.symbol=symbol;
521
393
str= lip->get_tok_start();
522
394
end= lip->get_ptr();
523
395
/* Extract the text from the token */
526
398
assert(end >= str);
528
if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
529
return (char*) ""; // Sql_alloc has set error flag
400
if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
401
return (char*) ""; // Sql_alloc has set error flag
531
403
lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
532
404
lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
536
lip->yytoklen=(uint) (end-str);
537
memcpy(start,str,lip->yytoklen);
538
start[lip->yytoklen]=0;
408
lip->yytoklen= (uint32_t) (end-str);
409
memcpy(start, str, lip->yytoklen);
410
start[lip->yytoklen]= 0;
544
for (to=start ; str != end ; str++)
416
for (to= start; str != end; str++)
549
(l = my_ismbchar(cs, str, end))) {
421
int l= my_ismbchar(cs, str, end);
556
if (!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
557
*str == '\\' && str+1 != end)
573
*to++= 0; // Ascii null
575
case 'Z': // ^Z must be escaped on Win32
580
*to++= '\\'; // remember prefix for wildcard
431
if (*str == '\\' && (str + 1) != end)
447
*to++= 0; // Ascii null
449
case 'Z': // ^Z must be escaped on Win32
454
*to++= '\\'; // remember prefix for wildcard
587
else if (*str == sep)
588
*to++= *str++; // Two ' or "
593
lip->yytoklen=(uint) (to-start);
461
else if (*str == sep)
462
*to++= *str++; // Two ' or "
467
lip->yytoklen= (uint32_t) (to - start);
603
477
** Calc type of integer; long integer, int64_t integer or real.
604
478
** Returns smallest type that match the string.
605
** When using unsigned long long values the result is converted to a real
479
** When using uint64_t values the result is converted to a real
606
480
** because else they will be unexpected sign changes because all calculation
607
481
** is done with int64_t or double.
610
static const char *long_str="2147483647";
611
static const uint long_len=10;
612
static const char *signed_long_str="-2147483648";
613
static const char *int64_t_str="9223372036854775807";
614
static const uint int64_t_len=19;
615
static const char *signed_int64_t_str="-9223372036854775808";
616
static const uint signed_int64_t_len=19;
617
static const char *unsigned_int64_t_str="18446744073709551615";
618
static const uint unsigned_int64_t_len=20;
484
static const char *long_str= "2147483647";
485
static const uint32_t long_len= 10;
486
static const char *signed_long_str= "-2147483648";
487
static const char *int64_t_str= "9223372036854775807";
488
static const uint32_t int64_t_len= 19;
489
static const char *signed_int64_t_str= "-9223372036854775808";
490
static const uint32_t signed_int64_t_len= 19;
491
static const char *unsigned_int64_t_str= "18446744073709551615";
492
static const uint32_t unsigned_int64_t_len= 20;
620
static inline uint int_token(const char *str,uint length)
494
static inline uint32_t int_token(const char *str,uint32_t length)
622
496
if (length < long_len) // quick normal case
887
756
for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
889
758
if (start == lip->get_ptr() && c == '.' && ident_map[(uint8_t)lip->yyPeek()])
890
lip->next_state=MY_LEX_IDENT_SEP;
759
lip->next_state=MY_LEX_IDENT_SEP;
892
761
{ // '(' must follow directly if function
894
if ((tokval = find_keyword(lip, length, c == '(')))
896
lip->next_state= MY_LEX_START; // Allow signed numbers
897
return(tokval); // Was keyword
763
if ((tokval = find_keyword(lip, length, c == '(')))
765
lip->next_state= MY_LEX_START; // Allow signed numbers
766
return(tokval); // Was keyword
899
768
lip->yySkip(); // next state does a unget
901
770
yylval->lex_str=get_token(lip, 0, length);
904
Note: "SELECT _bla AS 'alias'"
905
_bla should be considered as a IDENT if charset haven't been found.
906
So we don't use MYF(MY_WME) with get_charset_by_csname to avoid
910
if (yylval->lex_str.str[0] == '_')
912
const CHARSET_INFO * const cs= get_charset_by_csname(yylval->lex_str.str + 1,
913
MY_CS_PRIMARY, MYF(0));
917
lip->m_underscore_cs= cs;
919
lip->body_utf8_append(lip->m_cpp_text_start,
920
lip->get_cpp_tok_start() + length);
921
return(UNDERSCORE_CHARSET);
925
772
lip->body_utf8_append(lip->m_cpp_text_start);
927
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
928
lip->m_cpp_text_end);
774
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
930
776
return(result_state); // IDENT or IDENT_QUOTED
1021
865
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1023
867
if (c == '.' && ident_map[(uint8_t)lip->yyPeek()])
1024
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
868
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
1026
870
yylval->lex_str= get_token(lip, 0, lip->yyLength());
1028
872
lip->body_utf8_append(lip->m_cpp_text_start);
1030
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1031
lip->m_cpp_text_end);
874
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1033
876
return(result_state);
1035
878
case MY_LEX_USER_VARIABLE_DELIMITER: // Found quote char
1037
uint double_quotes= 0;
880
uint32_t double_quotes= 0;
1038
881
char quote_char= c; // Used char
1039
882
while ((c=lip->yyGet()))
1042
if ((var_length= my_mbcharlen(cs, c)) == 1)
1044
if (c == quote_char)
1046
if (lip->yyPeek() != quote_char)
885
if ((var_length= my_mbcharlen(cs, c)) == 1)
889
if (lip->yyPeek() != quote_char)
1054
else if (var_length < 1)
897
else if (var_length < 1)
1056
899
lip->skip_binary(var_length-1);
1059
902
if (double_quotes)
1060
yylval->lex_str=get_quoted_token(lip, 1,
1061
lip->yyLength() - double_quotes -1,
903
yylval->lex_str=get_quoted_token(lip, 1, lip->yyLength() - double_quotes -1, quote_char);
1064
905
yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
1065
906
if (c == quote_char)
1066
907
lip->yySkip(); // Skip end `
1067
908
lip->next_state= MY_LEX_START;
1069
909
lip->body_utf8_append(lip->m_cpp_text_start);
1071
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1072
lip->m_cpp_text_end);
910
lip->body_utf8_append_literal(&yylval->lex_str, lip->m_cpp_text_end);
1074
911
return(IDENT_QUOTED);
1076
913
case MY_LEX_INT_OR_REAL: // Complete int or incomplete real
1078
915
{ // Found complete integer number.
1079
916
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1080
return int_token(yylval->lex_str.str,yylval->lex_str.length);
917
return int_token(yylval->lex_str.str,yylval->lex_str.length);
1083
920
case MY_LEX_REAL: // Incomplete real number
1220
1053
The special comment format is very strict:
1221
'/' '*' '!', followed by exactly
1222
1 digit (major), 2 digits (minor), then 2 digits (dot).
1054
'/' '*' '!', followed by digits ended by a non-digit.
1055
There must be at least 5 digits for it to count
1227
char version_str[6];
1228
version_str[0]= lip->yyPeekn(0);
1229
version_str[1]= lip->yyPeekn(1);
1230
version_str[2]= lip->yyPeekn(2);
1231
version_str[3]= lip->yyPeekn(3);
1232
version_str[4]= lip->yyPeekn(4);
1234
if ( my_isdigit(cs, version_str[0])
1235
&& my_isdigit(cs, version_str[1])
1236
&& my_isdigit(cs, version_str[2])
1237
&& my_isdigit(cs, version_str[3])
1238
&& my_isdigit(cs, version_str[4])
1242
version=strtol(version_str, NULL, 10);
1057
const int MAX_VERSION_SIZE= 16;
1058
char version_str[MAX_VERSION_SIZE];
1063
version_str[pos]= lip->yyPeekn(pos);
1065
} while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
1066
version_str[pos]= 0;
1068
/* To keep some semblance of compatibility, we impose a 5 digit floor */
1072
version=strtoll(version_str, NULL, 10);
1244
1074
/* Accept 'M' 'm' 'm' 'd' 'd' */
1075
lip->yySkipn(pos-1);
1247
1077
if (version <= DRIZZLE_VERSION_ID)
1814
bool st_select_lex_node::set_braces(bool value __attribute__((unused)))
1816
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1817
uint st_select_lex_node::get_in_sum_expr() { return 0; }
1818
TABLE_LIST* st_select_lex_node::get_table_list() { return 0; }
1819
List<Item>* st_select_lex_node::get_item_list() { return 0; }
1820
TABLE_LIST *st_select_lex_node::add_table_to_list (THD *thd __attribute__((unused)),
1821
Table_ident *table __attribute__((unused)),
1822
LEX_STRING *alias __attribute__((unused)),
1823
uint32_t table_join_options __attribute__((unused)),
1824
thr_lock_type flags __attribute__((unused)),
1825
List<Index_hint> *hints __attribute__((unused)),
1826
LEX_STRING *option __attribute__((unused)))
1621
bool Select_Lex_Node::set_braces(bool)
1624
bool Select_Lex_Node::inc_in_sum_expr()
1627
uint32_t Select_Lex_Node::get_in_sum_expr()
1630
TableList* Select_Lex_Node::get_table_list()
1633
List<Item>* Select_Lex_Node::get_item_list()
1636
TableList *Select_Lex_Node::add_table_to_list (Session *, Table_ident *, LEX_STRING *, uint32_t,
1637
thr_lock_type, List<Index_hint> *, LEX_STRING *)
1830
uint32_t st_select_lex_node::get_table_join_options()
1642
uint32_t Select_Lex_Node::get_table_join_options()
1836
1648
prohibit using LIMIT clause
1838
bool st_select_lex::test_limit()
1650
bool Select_Lex::test_limit()
1840
1652
if (select_limit != 0)
1842
1654
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1843
1655
"LIMIT & IN/ALL/ANY/SOME subquery");
1850
st_select_lex_unit* st_select_lex_unit::master_unit()
1856
st_select_lex* st_select_lex_unit::outer_select()
1858
return (st_select_lex*) master;
1862
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1864
return add_to_list(thd, order_list, item, asc);
1868
bool st_select_lex::add_item_to_list(THD *thd __attribute__((unused)),
1661
Select_Lex_Unit* Select_Lex_Unit::master_unit()
1666
Select_Lex* Select_Lex_Unit::outer_select()
1668
return (Select_Lex*) master;
1671
bool Select_Lex::add_order_to_list(Session *session, Item *item, bool asc)
1673
return add_to_list(session, order_list, item, asc);
1676
bool Select_Lex::add_item_to_list(Session *, Item *item)
1871
1678
return(item_list.push_back(item));
1875
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1877
return add_to_list(thd, group_list, item, asc);
1881
st_select_lex_unit* st_select_lex::master_unit()
1883
return (st_select_lex_unit*) master;
1887
st_select_lex* st_select_lex::outer_select()
1889
return (st_select_lex*) master->get_master();
1893
bool st_select_lex::set_braces(bool value)
1681
bool Select_Lex::add_group_to_list(Session *session, Item *item, bool asc)
1683
return add_to_list(session, group_list, item, asc);
1686
Select_Lex_Unit* Select_Lex::master_unit()
1688
return (Select_Lex_Unit*) master;
1691
Select_Lex* Select_Lex::outer_select()
1693
return (Select_Lex*) master->get_master();
1696
bool Select_Lex::set_braces(bool value)
1900
bool st_select_lex::inc_in_sum_expr()
1702
bool Select_Lex::inc_in_sum_expr()
1907
uint st_select_lex::get_in_sum_expr()
1708
uint32_t Select_Lex::get_in_sum_expr()
1909
1710
return in_sum_expr;
1913
TABLE_LIST* st_select_lex::get_table_list()
1713
TableList* Select_Lex::get_table_list()
1915
return (TABLE_LIST*) table_list.first;
1715
return (TableList*) table_list.first;
1918
List<Item>* st_select_lex::get_item_list()
1718
List<Item>* Select_Lex::get_item_list()
1920
1720
return &item_list;
1923
uint32_t st_select_lex::get_table_join_options()
1723
uint32_t Select_Lex::get_table_join_options()
1925
1725
return table_join_options;
1929
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
1728
bool Select_Lex::setup_ref_array(Session *session, uint32_t order_group_num)
1931
1730
if (ref_pointer_array)
1935
We have to create array in prepared statement memory if it is
1938
Query_arena *arena= thd->stmt_arena;
1939
1733
return (ref_pointer_array=
1940
(Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
1734
(Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
1941
1735
item_list.elements +
1942
1736
select_n_having_items +
1943
1737
select_n_where_fields +
1944
1738
order_group_num)*5)) == 0;
1948
void st_select_lex_unit::print(String *str, enum_query_type query_type)
1741
void Select_Lex_Unit::print(String *str, enum_query_type query_type)
1950
1743
bool union_all= !union_distinct;
1951
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1744
for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1953
1746
if (sl != first_select())
2090
1878
query_tables= 0;
2091
1879
query_tables_last= &query_tables;
2092
1880
query_tables_own_last= 0;
2096
We delay real initialization of hash (and therefore related
2097
memory allocation) until first insertion into this hash.
2099
hash_clear(&sroutines);
2101
else if (sroutines.records)
2103
/* Non-zero sroutines.records means that hash was initialized. */
2104
my_hash_reset(&sroutines);
2106
sroutines_list.empty();
2107
sroutines_list_own_last= sroutines_list.next;
2108
sroutines_list_own_elements= 0;
2109
binlog_stmt_flags= 0;
2114
Destroy Query_tables_list object with freeing all resources used by it.
2117
destroy_query_tables_list()
2120
void Query_tables_list::destroy_query_tables_list()
2122
hash_free(&sroutines);
2127
1884
Initialize LEX object.
2133
1890
LEX object initialized with this constructor can be used as part of
2134
THD object for which one can safely call open_tables(), lock_tables()
1891
Session object for which one can safely call open_tables(), lock_tables()
2135
1892
and close_thread_tables() functions. But it is not yet ready for
2136
1893
statement parsing. On should use lex_start() function to prepare LEX
2141
1897
:result(0), yacc_yyss(0), yacc_yyvs(0),
2142
1898
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
2145
my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2146
plugins_static_buffer,
2147
INITIAL_LEX_PLUGIN_LIST_SIZE,
2148
INITIAL_LEX_PLUGIN_LIST_SIZE);
2149
1900
reset_query_tables_list(true);
2154
Check whether the merging algorithm can be used on this VIEW
2157
st_lex::can_be_merged()
2160
We can apply merge algorithm if it is single SELECT view with
2161
subqueries only in WHERE clause (we do not count SELECTs of underlying
2162
views, and second level subqueries) and we have not grpouping, ordering,
2163
HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2164
several underlying tables.
2167
false - only temporary table algorithm can be used
2168
true - merge algorithm can be used
2171
bool st_lex::can_be_merged()
2173
// TODO: do not forget implement case when select_lex.table_list.elements==0
2175
/* find non VIEW subqueries/unions */
2176
bool selects_allow_merge= select_lex.next_select() == 0;
2177
if (selects_allow_merge)
2179
for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2181
tmp_unit= tmp_unit->next_unit())
2183
if (tmp_unit->first_select()->parent_lex == this &&
2184
(tmp_unit->item == 0 ||
2185
(tmp_unit->item->place() != IN_WHERE &&
2186
tmp_unit->item->place() != IN_ON)))
2188
selects_allow_merge= 0;
2194
return (selects_allow_merge &&
2195
select_lex.group_list.elements == 0 &&
2196
select_lex.having == 0 &&
2197
select_lex.with_sum_func == 0 &&
2198
select_lex.table_list.elements >= 1 &&
2199
!(select_lex.options & SELECT_DISTINCT) &&
2200
select_lex.select_limit == 0);
2205
check if command can use VIEW with MERGE algorithm (for top VIEWs)
2208
st_lex::can_use_merged()
2211
Only listed here commands can use merge algorithm in top level
2212
SELECT_LEX (for subqueries will be used merge algorithm if
2213
st_lex::can_not_use_merged() is not true).
2216
false - command can't use merged VIEWs
2217
true - VIEWs with MERGE algorithms can be used
2220
bool st_lex::can_use_merged()
2222
switch (sql_command)
2225
case SQLCOM_CREATE_TABLE:
2227
case SQLCOM_UPDATE_MULTI:
2229
case SQLCOM_DELETE_MULTI:
2231
case SQLCOM_INSERT_SELECT:
2232
case SQLCOM_REPLACE:
2233
case SQLCOM_REPLACE_SELECT:
2242
Check if command can't use merged views in any part of command
2245
st_lex::can_not_use_merged()
2248
Temporary table algorithm will be used on all SELECT levels for queries
2249
listed here (see also st_lex::can_use_merged()).
2252
false - command can't use merged VIEWs
2253
true - VIEWs with MERGE algorithms can be used
2256
bool st_lex::can_not_use_merged()
2258
switch (sql_command)
2261
SQLCOM_SHOW_FIELDS is necessary to make
2262
information schema tables working correctly with views.
2263
see get_schema_tables_result function
2265
case SQLCOM_SHOW_FIELDS:
1901
create_table_proto= NULL;
2336
1963
@return true in case of error (parsing should be aborted, false in
2337
1964
case of success
2341
st_lex::copy_db_to(char **p_db, size_t *p_db_length) const
1966
bool LEX::copy_db_to(char **p_db, size_t *p_db_length) const
2343
return thd->copy_db_to(p_db, p_db_length);
1968
return session->copy_db_to(p_db, p_db_length);
2347
1972
initialize limit counters
2350
st_select_lex_unit::set_limit()
2351
values - SELECT_LEX with initial values for counters
1975
Select_Lex_Unit::set_limit()
1976
values - Select_Lex with initial values for counters
2354
void st_select_lex_unit::set_limit(st_select_lex *sl)
1978
void Select_Lex_Unit::set_limit(Select_Lex *sl)
2356
1980
ha_rows select_limit_val;
2359
1983
val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
2360
1984
select_limit_val= (ha_rows)val;
2363
1986
Check for overflow : ha_rows can be smaller then uint64_t if
2364
1987
BIG_TABLES is off.
2366
1989
if (val != (uint64_t)select_limit_val)
2367
1990
select_limit_val= HA_POS_ERROR;
2369
1991
offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
2371
1993
select_limit_cnt= select_limit_val + offset_limit_cnt;
2372
1994
if (select_limit_cnt < select_limit_val)
2373
1995
select_limit_cnt= HA_POS_ERROR; // no limit
2378
1999
Unlink the first table from the global table list and the first table from
2379
2000
outer select (lex->select_lex) local list
2493
2109
if (link_to_local)
2495
first->next_local= (TABLE_LIST*) select_lex.table_list.first;
2111
first->next_local= (TableList*) select_lex.table_list.first;
2496
2112
select_lex.context.table_list= first;
2497
select_lex.table_list.first= (uchar*) first;
2113
select_lex.table_list.first= (unsigned char*) first;
2498
2114
select_lex.table_list.elements++; //safety
2506
2120
cleanup lex for case when we open table by table for processing
2509
st_lex::cleanup_after_one_table_open()
2123
LEX::cleanup_after_one_table_open()
2512
2126
This method is mostly responsible for cleaning up of selects lists and
2513
2127
derived tables state. To rollback changes in Query_tables_list one has
2514
2128
to call Query_tables_list::reset_query_tables_list(false).
2517
void st_lex::cleanup_after_one_table_open()
2130
void LEX::cleanup_after_one_table_open()
2520
thd->lex->derived_tables & additional units may be set if we open
2521
a view. It is necessary to clear thd->lex->derived_tables flag
2133
session->lex->derived_tables & additional units may be set if we open
2134
a view. It is necessary to clear session->lex->derived_tables flag
2522
2135
to prevent processing of derived tables during next open_and_lock_tables
2523
2136
if next table is a real table and cleanup & remove underlying units
2524
NOTE: all units will be connected to thd->lex->select_lex, because we
2137
NOTE: all units will be connected to session->lex->select_lex, because we
2525
2138
have not UNION on most upper level.
2527
2140
if (all_selects_list != &select_lex)
2529
2142
derived_tables= 0;
2530
2143
/* cleunup underlying units (units of VIEW) */
2531
for (SELECT_LEX_UNIT *un= select_lex.first_inner_unit();
2144
for (Select_Lex_Unit *un= select_lex.first_inner_unit();
2533
2146
un= un->next_unit())
2544
Save current state of Query_tables_list for this LEX, and prepare it
2545
for processing of new statemnt.
2548
reset_n_backup_query_tables_list()
2549
backup Pointer to Query_tables_list instance to be used for backup
2552
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2558
Restore state of Query_tables_list for this LEX from backup.
2561
restore_backup_query_tables_list()
2562
backup Pointer to Query_tables_list instance used for backup
2565
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup __attribute__((unused)))
2571
Checks for usage of routines and/or tables in a parsed statement
2574
st_lex:table_or_sp_used()
2577
false No routines and tables used
2578
true Either or both routines and tables are used.
2581
bool st_lex::table_or_sp_used()
2583
if (sroutines.records || query_tables)
2591
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2594
fix_prepare_info_in_table_list()
2596
tbl List of tables to process
2599
Perform end-end-of prepare fixup for list of tables, if any of the tables
2600
is a merge-algorithm VIEW, recursively fix up its underlying tables as
2605
static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl)
2607
for (; tbl; tbl= tbl->next_local)
2611
tbl->prep_on_expr= tbl->on_expr;
2612
tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2614
fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2620
There are st_select_lex::add_table_to_list &
2621
st_select_lex::set_lock_for_tables are in sql_parse.cc
2623
st_select_lex::print is in sql_select.cc
2625
st_select_lex_unit::prepare, st_select_lex_unit::exec,
2626
st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
2627
st_select_lex_unit::change_result
2156
There are Select_Lex::add_table_to_list &
2157
Select_Lex::set_lock_for_tables are in sql_parse.cc
2159
Select_Lex::print is in sql_select.cc
2161
Select_Lex_Unit::prepare, Select_Lex_Unit::exec,
2162
Select_Lex_Unit::cleanup, Select_Lex_Unit::reinit_exec_mechanism,
2163
Select_Lex_Unit::change_result
2628
2164
are in sql_union.cc
2640
2176
Used in filling up the tagged hints list.
2641
This list is filled by first setting the kind of the hint as a
2177
This list is filled by first setting the kind of the hint as a
2642
2178
context variable and then adding hints of the current kind.
2643
2179
Then the context variable index_hint_type can be reset to the
2644
2180
next hint type.
2646
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
2647
index_clause_map clause)
2182
void Select_Lex::set_index_hint_type(enum index_hint_type type_arg, index_clause_map clause)
2649
2184
current_index_hint_type= type_arg;
2650
2185
current_index_hint_clause= clause;
2655
2189
Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2658
2192
alloc_index_hints()
2193
session current thread.
2662
void st_select_lex::alloc_index_hints (THD *thd)
2664
index_hints= new (thd->mem_root) List<Index_hint>();
2195
void Select_Lex::alloc_index_hints (Session *session)
2197
index_hints= new (session->mem_root) List<Index_hint>();
2670
adds an element to the array storing index usage hints
2201
adds an element to the array storing index usage hints
2671
2202
(ADD/FORCE/IGNORE INDEX).
2674
2205
add_index_hint()
2206
session current thread.
2676
2207
str name of the index.
2677
2208
length number of characters in str.
2680
2211
0 on success, non-zero otherwise
2682
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2213
bool Select_Lex::add_index_hint (Session *session, char *str, uint32_t length)
2684
return index_hints->push_front (new (thd->mem_root)
2215
return index_hints->push_front (new (session->mem_root)
2685
2216
Index_hint(current_index_hint_type,
2686
2217
current_index_hint_clause,