1
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
/* A lexical scanner on a temporary buffer with a yacc interface */
20
#include "mysql_priv.h"
21
#include "item_create.h"
28
We are using pointer to this variable for distinguishing between assignment
29
to NEW row field (when parsing trigger definition) and structured variable.
32
sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
34
/* Longest standard keyword name */
35
#define TOCK_NAME_LENGTH 24
38
The following data is based on the latin1 character set, and is only
39
used when comparing keywords
42
static uchar to_upper_lex[]=
44
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
45
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
46
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
47
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
48
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
49
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
50
96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
51
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
52
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
53
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
54
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
55
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
56
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
57
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
58
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
59
208,209,210,211,212,213,214,247,216,217,218,219,220,221,222,255
63
Names of the index hints (for error messages). Keep in sync with
67
const char * index_hint_type_name[] =
74
inline int lex_casecmp(const char *s, const char *t, uint len)
77
to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
87
DBUG_ENTER("lex_init");
88
for (i=0 ; i < array_elements(symbols) ; i++)
89
symbols[i].length=(uchar) strlen(symbols[i].name);
90
for (i=0 ; i < array_elements(sql_functions) ; i++)
91
sql_functions[i].length=(uchar) strlen(sql_functions[i].name);
98
{ // Call this when daemon ends
99
DBUG_ENTER("lex_free");
105
st_parsing_options::reset()
107
allows_variable= TRUE;
108
allows_select_into= TRUE;
109
allows_select_procedure= TRUE;
110
allows_derived= TRUE;
113
Lex_input_stream::Lex_input_stream(THD *thd,
123
m_end_of_query(buffer + length),
124
m_tok_start_prev(NULL),
126
m_buf_length(length),
128
m_cpp_tok_start(NULL),
129
m_cpp_tok_start_prev(NULL),
132
m_cpp_utf8_processed_ptr(NULL),
133
next_state(MY_LEX_START),
134
found_semicolon(NULL),
135
ignore_space(test(thd->variables.sql_mode & MODE_IGNORE_SPACE)),
136
stmt_prepare_mode(FALSE),
137
in_comment(NO_COMMENT),
138
m_underscore_cs(NULL)
140
m_cpp_buf= (char*) thd->alloc(length + 1);
141
m_cpp_ptr= m_cpp_buf;
144
Lex_input_stream::~Lex_input_stream()
148
The operation is called from the parser in order to
149
1) designate the intention to have utf8 body;
150
1) Indicate to the lexer that we will need a utf8 representation of this
152
2) Determine the beginning of the body.
154
@param thd Thread context.
155
@param begin_ptr Pointer to the start of the body in the pre-processed
159
void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr)
161
DBUG_ASSERT(begin_ptr);
162
DBUG_ASSERT(m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length);
164
uint body_utf8_length=
165
(m_buf_length / thd->variables.character_set_client->mbminlen) *
166
my_charset_utf8_bin.mbmaxlen;
168
m_body_utf8= (char *) thd->alloc(body_utf8_length + 1);
169
m_body_utf8_ptr= m_body_utf8;
172
m_cpp_utf8_processed_ptr= begin_ptr;
176
@brief The operation appends unprocessed part of pre-processed buffer till
177
the given pointer (ptr) and sets m_cpp_utf8_processed_ptr to end_ptr.
179
The idea is that some tokens in the pre-processed buffer (like character
180
set introducers) should be skipped.
183
CPP buffer: SELECT 'str1', _latin1 'str2';
184
m_cpp_utf8_processed_ptr -- points at the "SELECT ...";
185
In order to skip "_latin1", the following call should be made:
186
body_utf8_append(<pointer to "_latin1 ...">, <pointer to " 'str2'...">)
188
@param ptr Pointer in the pre-processed buffer, which specifies the
189
end of the chunk, which should be appended to the utf8
191
@param end_ptr Pointer in the pre-processed buffer, to which
192
m_cpp_utf8_processed_ptr will be set in the end of the
196
void Lex_input_stream::body_utf8_append(const char *ptr,
199
DBUG_ASSERT(m_cpp_buf <= ptr && ptr <= m_cpp_buf + m_buf_length);
200
DBUG_ASSERT(m_cpp_buf <= end_ptr && end_ptr <= m_cpp_buf + m_buf_length);
205
if (m_cpp_utf8_processed_ptr >= ptr)
208
int bytes_to_copy= ptr - m_cpp_utf8_processed_ptr;
210
memcpy(m_body_utf8_ptr, m_cpp_utf8_processed_ptr, bytes_to_copy);
211
m_body_utf8_ptr += bytes_to_copy;
214
m_cpp_utf8_processed_ptr= end_ptr;
218
The operation appends unprocessed part of the pre-processed buffer till
219
the given pointer (ptr) and sets m_cpp_utf8_processed_ptr to ptr.
221
@param ptr Pointer in the pre-processed buffer, which specifies the end
222
of the chunk, which should be appended to the utf8 body.
225
void Lex_input_stream::body_utf8_append(const char *ptr)
227
body_utf8_append(ptr, ptr);
231
The operation converts the specified text literal to the utf8 and appends
232
the result to the utf8-body.
234
@param thd Thread context.
235
@param txt Text literal.
236
@param txt_cs Character set of the text literal.
237
@param end_ptr Pointer in the pre-processed buffer, to which
238
m_cpp_utf8_processed_ptr will be set in the end of the
242
void Lex_input_stream::body_utf8_append_literal(THD *thd,
243
const LEX_STRING *txt,
244
CHARSET_INFO *txt_cs,
247
if (!m_cpp_utf8_processed_ptr)
252
if (!my_charset_same(txt_cs, &my_charset_utf8_general_ci))
254
thd->convert_string(&utf_txt,
255
&my_charset_utf8_general_ci,
256
txt->str, (uint) txt->length,
261
utf_txt.str= txt->str;
262
utf_txt.length= txt->length;
265
/* NOTE: utf_txt.length is in bytes, not in symbols. */
267
memcpy(m_body_utf8_ptr, utf_txt.str, utf_txt.length);
268
m_body_utf8_ptr += utf_txt.length;
271
m_cpp_utf8_processed_ptr= end_ptr;
276
This is called before every query that is to be parsed.
277
Because of this, it's critical to not do too much things here.
278
(We already do too much here)
281
void lex_start(THD *thd)
284
DBUG_ENTER("lex_start");
286
lex->thd= lex->unit.thd= thd;
288
lex->context_stack.empty();
289
lex->unit.init_query();
290
lex->unit.init_select();
291
/* 'parent_lex' is used in init_query() so it must be before it. */
292
lex->select_lex.parent_lex= lex;
293
lex->select_lex.init_query();
294
lex->value_list.empty();
295
lex->update_list.empty();
296
lex->set_var_list.empty();
297
lex->param_list.empty();
298
lex->view_list.empty();
299
lex->prepared_stmt_params.empty();
300
lex->auxiliary_table_list.empty();
301
lex->unit.next= lex->unit.master=
302
lex->unit.link_next= lex->unit.return_to= 0;
303
lex->unit.prev= lex->unit.link_prev= 0;
304
lex->unit.slave= lex->unit.global_parameters= lex->current_select=
305
lex->all_selects_list= &lex->select_lex;
306
lex->select_lex.master= &lex->unit;
307
lex->select_lex.prev= &lex->unit.slave;
308
lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
309
lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
310
lex->select_lex.options= 0;
311
lex->select_lex.sql_cache= SELECT_LEX::SQL_CACHE_UNSPECIFIED;
312
lex->select_lex.init_order();
313
lex->select_lex.group_list.empty();
315
lex->subqueries= FALSE;
316
lex->view_prepare_mode= FALSE;
317
lex->derived_tables= 0;
318
lex->lock_option= TL_READ;
319
lex->safe_to_cache_query= 1;
320
lex->leaf_tables_insert= 0;
321
lex->parsing_options.reset();
322
lex->empty_field_list_on_rset= 0;
323
lex->select_lex.select_number= 1;
326
lex->select_lex.in_sum_expr=0;
327
lex->select_lex.ftfunc_list_alloc.empty();
328
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
329
lex->select_lex.group_list.empty();
330
lex->select_lex.order_list.empty();
331
lex->sql_command= SQLCOM_END;
332
lex->duplicates= DUP_ERROR;
337
lex->proc_list.first= 0;
338
lex->escape_used= FALSE;
339
lex->query_tables= 0;
340
lex->reset_query_tables_list(FALSE);
341
lex->expr_allows_subselect= TRUE;
342
lex->use_only_table_context= FALSE;
346
lex->event_parse_data= NULL;
347
lex->profile_options= PROFILE_NONE;
349
lex->allow_sum_func= 0;
350
lex->in_sum_func= NULL;
351
lex->protect_against_global_read_lock= FALSE;
353
ok, there must be a better solution for this, long-term
354
I tried "bzero" in the sql_yacc.yy code, but that for
355
some reason made the values zero, even if they were set
357
lex->server_options.server_name= 0;
358
lex->server_options.server_name_length= 0;
359
lex->server_options.host= 0;
360
lex->server_options.db= 0;
361
lex->server_options.username= 0;
362
lex->server_options.password= 0;
363
lex->server_options.scheme= 0;
364
lex->server_options.socket= 0;
365
lex->server_options.owner= 0;
366
lex->server_options.port= -1;
368
lex->is_lex_started= TRUE;
372
void lex_end(LEX *lex)
374
DBUG_ENTER("lex_end");
375
DBUG_PRINT("enter", ("lex: 0x%lx", (long) lex));
377
/* release used plugins */
378
plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer,
379
lex->plugins.elements);
380
reset_dynamic(&lex->plugins);
385
Yacc_state::~Yacc_state()
389
my_free(yacc_yyss, MYF(0));
390
my_free(yacc_yyvs, MYF(0));
394
static int find_keyword(Lex_input_stream *lip, uint len, bool function)
396
const char *tok= lip->get_tok_start();
398
SYMBOL *symbol= get_hash_symbol(tok, len, function);
401
lip->yylval->symbol.symbol=symbol;
402
lip->yylval->symbol.str= (char*) tok;
403
lip->yylval->symbol.length=len;
405
if ((symbol->tok == NOT_SYM) &&
406
(lip->m_thd->variables.sql_mode & MODE_HIGH_NOT_PRECEDENCE))
408
if ((symbol->tok == OR_OR_SYM) &&
409
!(lip->m_thd->variables.sql_mode & MODE_PIPES_AS_CONCAT))
418
Check if name is a keyword
422
name checked name (must not be empty)
423
len length of checked name
427
1 name isn't a keyword
430
bool is_keyword(const char *name, uint len)
432
DBUG_ASSERT(len != 0);
433
return get_hash_symbol(name,len,0)!=0;
437
Check if name is a sql function
439
@param name checked name
441
@return is this a native function or not
442
@retval 0 name is a function
443
@retval 1 name isn't a function
446
bool is_lex_native_function(const LEX_STRING *name)
448
DBUG_ASSERT(name != NULL);
449
return (get_hash_symbol(name->str, (uint) name->length, 1) != 0);
452
/* make a copy of token before ptr and set yytoklen */
454
static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
457
lip->yyUnget(); // ptr points now after last token char
458
tmp.length=lip->yytoklen=length;
459
tmp.str= lip->m_thd->strmake(lip->get_tok_start() + skip, tmp.length);
461
lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
462
lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.length;
469
There are no dangerous charsets in mysql for function
470
get_quoted_token yet. But it should be fixed in the
471
future to operate multichar strings (like ucs2)
474
static LEX_STRING get_quoted_token(Lex_input_stream *lip,
476
uint length, char quote)
479
const char *from, *end;
481
lip->yyUnget(); // ptr points now after last token char
482
tmp.length= lip->yytoklen=length;
483
tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
484
from= lip->get_tok_start() + skip;
488
lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
489
lip->m_cpp_text_end= lip->m_cpp_text_start + length;
493
if ((*to++= *from++) == quote)
495
from++; // Skip double quotes
496
lip->m_cpp_text_start++;
499
*to= 0; // End null for safety
505
Return an unescaped text literal without quotes
506
Fix sometimes to do only one scan of the string
509
static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
513
CHARSET_INFO *cs= lip->m_thd->charset();
516
sep= lip->yyGetLast(); // String should end with this
527
lip->get_end_of_query()))) {
528
lip->skip_binary(l-1);
534
!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
535
{ // Escaped character
543
if (c == lip->yyGet()) // Check if two separators in a row
545
found_escape=1; // duplicate. Remember for delete
551
/* Found end. Unescape and return string */
552
const char *str, *end;
555
str= lip->get_tok_start();
557
/* Extract the text from the token */
560
DBUG_ASSERT(end >= str);
562
if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
563
return (char*) ""; // Sql_alloc has set error flag
565
lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
566
lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
570
lip->yytoklen=(uint) (end-str);
571
memcpy(start,str,lip->yytoklen);
572
start[lip->yytoklen]=0;
578
for (to=start ; str != end ; str++)
583
(l = my_ismbchar(cs, str, end))) {
590
if (!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
591
*str == '\\' && str+1 != end)
607
*to++= 0; // Ascii null
609
case 'Z': // ^Z must be escaped on Win32
614
*to++= '\\'; // remember prefix for wildcard
621
else if (*str == sep)
622
*to++= *str++; // Two ' or "
627
lip->yytoklen=(uint) (to-start);
632
return 0; // unexpected end of query
637
** Calc type of integer; long integer, longlong integer or real.
638
** Returns smallest type that match the string.
639
** When using unsigned long long values the result is converted to a real
640
** because else they will be unexpected sign changes because all calculation
641
** is done with longlong or double.
644
static const char *long_str="2147483647";
645
static const uint long_len=10;
646
static const char *signed_long_str="-2147483648";
647
static const char *longlong_str="9223372036854775807";
648
static const uint longlong_len=19;
649
static const char *signed_longlong_str="-9223372036854775808";
650
static const uint signed_longlong_len=19;
651
static const char *unsigned_longlong_str="18446744073709551615";
652
static const uint unsigned_longlong_len=20;
654
static inline uint int_token(const char *str,uint length)
656
if (length < long_len) // quick normal case
660
if (*str == '+') // Remove sign and pre-zeros
664
else if (*str == '-')
669
while (*str == '0' && length)
673
if (length < long_len)
680
if (length == long_len)
682
cmp= signed_long_str+1;
683
smaller=NUM; // If <= signed_long_str
684
bigger=LONG_NUM; // If >= signed_long_str
686
else if (length < signed_longlong_len)
688
else if (length > signed_longlong_len)
692
cmp=signed_longlong_str+1;
693
smaller=LONG_NUM; // If <= signed_longlong_str
699
if (length == long_len)
705
else if (length < longlong_len)
707
else if (length > longlong_len)
709
if (length > unsigned_longlong_len)
711
cmp=unsigned_longlong_str;
712
smaller=ULONGLONG_NUM;
719
bigger= ULONGLONG_NUM;
722
while (*cmp && *cmp++ == *str++) ;
723
return ((uchar) str[-1] <= (uchar) cmp[-1]) ? smaller : bigger;
728
Given a stream that is advanced to the first contained character in
729
an open comment, consume the comment. Optionally, if we are allowed,
730
recurse so that we understand comments within this current comment.
732
At this level, we do not support version-condition comments. We might
733
have been called with having just passed one in the stream, though. In
734
that case, we probably want to tolerate mundane comments inside. Thus,
735
the case for recursion.
737
@retval Whether EOF reached before comment is closed.
739
bool consume_comment(Lex_input_stream *lip, int remaining_recursions_permitted)
746
if (remaining_recursions_permitted > 0)
748
if ((c == '/') && (lip->yyPeek() == '*'))
750
lip->yySkip(); /* Eat asterisk */
751
consume_comment(lip, remaining_recursions_permitted-1);
758
if (lip->yyPeek() == '/')
760
lip->yySkip(); /* Eat slash */
774
MYSQLlex remember the following states from the following MYSQLlex()
776
- MY_LEX_EOQ Found end of query
777
- MY_LEX_OPERATOR_OR_IDENT Last state was an ident, text or number
778
(which can't be followed by a signed number)
781
int MYSQLlex(void *arg, void *yythd)
785
int tokval, result_state;
787
enum my_lex_states state;
788
THD *thd= (THD *)yythd;
789
Lex_input_stream *lip= & thd->m_parser_state->m_lip;
791
YYSTYPE *yylval=(YYSTYPE*) arg;
792
CHARSET_INFO *cs= thd->charset();
793
uchar *state_map= cs->state_map;
794
uchar *ident_map= cs->ident_map;
796
lip->yylval=yylval; // The global state
799
state=lip->next_state;
800
lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
804
case MY_LEX_OPERATOR_OR_IDENT: // Next is operator or keyword
805
case MY_LEX_START: // Start of token
806
// Skip starting whitespace
807
while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
815
/* Start of real token */
816
lip->restart_token();
818
state= (enum my_lex_states) state_map[c];
821
if (lip->yyGet() == 'N')
822
{ // Allow \N as shortcut for NULL
823
yylval->lex_str.str=(char*) "\\N";
824
yylval->lex_str.length=2;
827
case MY_LEX_CHAR: // Unknown or single char token
828
case MY_LEX_SKIP: // This should not happen
829
if (c == '-' && lip->yyPeek() == '-' &&
830
(my_isspace(cs,lip->yyPeekn(1)) ||
831
my_iscntrl(cs,lip->yyPeekn(1))))
833
state=MY_LEX_COMMENT;
838
lip->next_state= MY_LEX_START; // Allow signed numbers
844
This is a work around, to make the "remember_name" rule in
845
sql/sql_yacc.yy work properly.
846
The problem is that, when parsing "select expr1, expr2",
847
the code generated by bison executes the *pre* action
848
remember_name (see select_item) *before* actually parsing the
849
first token of expr2.
851
lip->restart_token();
856
Check for a placeholder: it should not precede a possible identifier
857
because of binlogging: when a placeholder is replaced with
858
its value in a query for the binlog, the query must stay
859
grammatically correct.
861
if (c == '?' && lip->stmt_prepare_mode && !ident_map[lip->yyPeek()])
862
return(PARAM_MARKER);
867
case MY_LEX_IDENT_OR_NCHAR:
868
if (lip->yyPeek() != '\'')
873
/* Found N'string' */
874
lip->yySkip(); // Skip '
875
if (!(yylval->lex_str.str = get_text(lip, 2, 1)))
877
state= MY_LEX_CHAR; // Read char by char
880
yylval->lex_str.length= lip->yytoklen;
881
lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
882
return(NCHAR_STRING);
884
case MY_LEX_IDENT_OR_HEX:
885
if (lip->yyPeek() == '\'')
886
{ // Found x'hex-number'
887
state= MY_LEX_HEX_NUMBER;
890
case MY_LEX_IDENT_OR_BIN:
891
if (lip->yyPeek() == '\'')
892
{ // Found b'bin-number'
893
state= MY_LEX_BIN_NUMBER;
898
#if defined(USE_MB) && defined(USE_MB_IDENT)
901
result_state= IDENT_QUOTED;
902
if (my_mbcharlen(cs, lip->yyGetLast()) > 1)
904
int l = my_ismbchar(cs,
906
lip->get_end_of_query());
911
lip->skip_binary(l - 1);
913
while (ident_map[c=lip->yyGet()])
915
if (my_mbcharlen(cs, c) > 1)
918
if ((l = my_ismbchar(cs,
920
lip->get_end_of_query())) == 0)
922
lip->skip_binary(l-1);
929
for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) ;
930
/* If there were non-ASCII characters, mark that we must convert */
931
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
933
length= lip->yyLength();
934
start= lip->get_ptr();
935
if (lip->ignore_space)
938
If we find a space then this can't be an identifier. We notice this
939
below by checking start != lex->ptr.
941
for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) ;
943
if (start == lip->get_ptr() && c == '.' && ident_map[lip->yyPeek()])
944
lip->next_state=MY_LEX_IDENT_SEP;
946
{ // '(' must follow directly if function
948
if ((tokval = find_keyword(lip, length, c == '(')))
950
lip->next_state= MY_LEX_START; // Allow signed numbers
951
return(tokval); // Was keyword
953
lip->yySkip(); // next state does a unget
955
yylval->lex_str=get_token(lip, 0, length);
958
Note: "SELECT _bla AS 'alias'"
959
_bla should be considered as a IDENT if charset haven't been found.
960
So we don't use MYF(MY_WME) with get_charset_by_csname to avoid
964
if (yylval->lex_str.str[0] == '_')
966
CHARSET_INFO *cs= get_charset_by_csname(yylval->lex_str.str + 1,
967
MY_CS_PRIMARY, MYF(0));
971
lip->m_underscore_cs= cs;
973
lip->body_utf8_append(lip->m_cpp_text_start,
974
lip->get_cpp_tok_start() + length);
975
return(UNDERSCORE_CHARSET);
979
lip->body_utf8_append(lip->m_cpp_text_start);
981
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
982
lip->m_cpp_text_end);
984
return(result_state); // IDENT or IDENT_QUOTED
986
case MY_LEX_IDENT_SEP: // Found ident and now '.'
987
yylval->lex_str.str= (char*) lip->get_ptr();
988
yylval->lex_str.length= 1;
989
c= lip->yyGet(); // should be '.'
990
lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
991
if (!ident_map[lip->yyPeek()]) // Probably ` or "
992
lip->next_state= MY_LEX_START;
995
case MY_LEX_NUMBER_IDENT: // number or ident which num-start
996
if (lip->yyGetLast() == '0')
1001
while (my_isxdigit(cs,(c = lip->yyGet()))) ;
1002
if ((lip->yyLength() >= 3) && !ident_map[c])
1005
yylval->lex_str=get_token(lip, 2, lip->yyLength()-2);
1009
state= MY_LEX_IDENT_START;
1014
while ((c= lip->yyGet()) == '0' || c == '1') ;
1015
if ((lip->yyLength() >= 3) && !ident_map[c])
1018
yylval->lex_str= get_token(lip, 2, lip->yyLength()-2);
1022
state= MY_LEX_IDENT_START;
1028
while (my_isdigit(cs, (c = lip->yyGet()))) ;
1030
{ // Can't be identifier
1031
state=MY_LEX_INT_OR_REAL;
1034
if (c == 'e' || c == 'E')
1036
// The following test is written this way to allow numbers of type 1e1
1037
if (my_isdigit(cs,lip->yyPeek()) ||
1038
(c=(lip->yyGet())) == '+' || c == '-')
1040
if (my_isdigit(cs,lip->yyPeek())) // Number must have digit after sign
1043
while (my_isdigit(cs,lip->yyGet())) ;
1044
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1051
case MY_LEX_IDENT_START: // We come here after '.'
1052
result_state= IDENT;
1053
#if defined(USE_MB) && defined(USE_MB_IDENT)
1056
result_state= IDENT_QUOTED;
1057
while (ident_map[c=lip->yyGet()])
1059
if (my_mbcharlen(cs, c) > 1)
1062
if ((l = my_ismbchar(cs,
1064
lip->get_end_of_query())) == 0)
1066
lip->skip_binary(l-1);
1073
for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) ;
1074
/* If there were non-ASCII characters, mark that we must convert */
1075
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1077
if (c == '.' && ident_map[lip->yyPeek()])
1078
lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
1080
yylval->lex_str= get_token(lip, 0, lip->yyLength());
1082
lip->body_utf8_append(lip->m_cpp_text_start);
1084
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1085
lip->m_cpp_text_end);
1087
return(result_state);
1089
case MY_LEX_USER_VARIABLE_DELIMITER: // Found quote char
1091
uint double_quotes= 0;
1092
char quote_char= c; // Used char
1093
while ((c=lip->yyGet()))
1096
if ((var_length= my_mbcharlen(cs, c)) == 1)
1098
if (c == quote_char)
1100
if (lip->yyPeek() != quote_char)
1108
else if (use_mb(cs))
1110
if ((var_length= my_ismbchar(cs, lip->get_ptr() - 1,
1111
lip->get_end_of_query())))
1112
lip->skip_binary(var_length-1);
1117
yylval->lex_str=get_quoted_token(lip, 1,
1118
lip->yyLength() - double_quotes -1,
1121
yylval->lex_str=get_token(lip, 1, lip->yyLength() -1);
1122
if (c == quote_char)
1123
lip->yySkip(); // Skip end `
1124
lip->next_state= MY_LEX_START;
1126
lip->body_utf8_append(lip->m_cpp_text_start);
1128
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1129
lip->m_cpp_text_end);
1131
return(IDENT_QUOTED);
1133
case MY_LEX_INT_OR_REAL: // Complete int or incomplete real
1135
{ // Found complete integer number.
1136
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1137
return int_token(yylval->lex_str.str, (uint) yylval->lex_str.length);
1140
case MY_LEX_REAL: // Incomplete real number
1141
while (my_isdigit(cs,c = lip->yyGet())) ;
1143
if (c == 'e' || c == 'E')
1146
if (c == '-' || c == '+')
1147
c = lip->yyGet(); // Skip sign
1148
if (!my_isdigit(cs,c))
1149
{ // No digit after sign
1153
while (my_isdigit(cs,lip->yyGet())) ;
1154
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1157
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1158
return(DECIMAL_NUM);
1160
case MY_LEX_HEX_NUMBER: // Found x'hexstring'
1161
lip->yySkip(); // Accept opening '
1162
while (my_isxdigit(cs, (c= lip->yyGet()))) ;
1164
return(ABORT_SYM); // Illegal hex constant
1165
lip->yySkip(); // Accept closing '
1166
length= lip->yyLength(); // Length of hexnum+3
1167
if ((length % 2) == 0)
1168
return(ABORT_SYM); // odd number of hex digits
1169
yylval->lex_str=get_token(lip,
1171
length-3); // don't count x' and last '
1174
case MY_LEX_BIN_NUMBER: // Found b'bin-string'
1175
lip->yySkip(); // Accept opening '
1176
while ((c= lip->yyGet()) == '0' || c == '1') ;
1178
return(ABORT_SYM); // Illegal hex constant
1179
lip->yySkip(); // Accept closing '
1180
length= lip->yyLength(); // Length of bin-num + 3
1181
yylval->lex_str= get_token(lip,
1183
length-3); // don't count b' and last '
1186
case MY_LEX_CMP_OP: // Incomplete comparison operator
1187
if (state_map[lip->yyPeek()] == MY_LEX_CMP_OP ||
1188
state_map[lip->yyPeek()] == MY_LEX_LONG_CMP_OP)
1190
if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1192
lip->next_state= MY_LEX_START; // Allow signed numbers
1195
state = MY_LEX_CHAR; // Something fishy found
1198
case MY_LEX_LONG_CMP_OP: // Incomplete comparison operator
1199
if (state_map[lip->yyPeek()] == MY_LEX_CMP_OP ||
1200
state_map[lip->yyPeek()] == MY_LEX_LONG_CMP_OP)
1203
if (state_map[lip->yyPeek()] == MY_LEX_CMP_OP)
1206
if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
1208
lip->next_state= MY_LEX_START; // Found long op
1211
state = MY_LEX_CHAR; // Something fishy found
1215
if (c != lip->yyPeek())
1221
tokval = find_keyword(lip,2,0); // Is a bool operator
1222
lip->next_state= MY_LEX_START; // Allow signed numbers
1225
case MY_LEX_STRING_OR_DELIMITER:
1226
if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
1228
state= MY_LEX_USER_VARIABLE_DELIMITER;
1231
/* " used for strings */
1232
case MY_LEX_STRING: // Incomplete text string
1233
if (!(yylval->lex_str.str = get_text(lip, 1, 1)))
1235
state= MY_LEX_CHAR; // Read char by char
1238
yylval->lex_str.length=lip->yytoklen;
1240
lip->body_utf8_append(lip->m_cpp_text_start);
1242
lip->body_utf8_append_literal(thd, &yylval->lex_str,
1243
lip->m_underscore_cs ? lip->m_underscore_cs : cs,
1244
lip->m_cpp_text_end);
1246
lip->m_underscore_cs= NULL;
1248
lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1249
return(TEXT_STRING);
1251
case MY_LEX_COMMENT: // Comment
1252
lex->select_lex.options|= OPTION_FOUND_COMMENT;
1253
while ((c = lip->yyGet()) != '\n' && c) ;
1254
lip->yyUnget(); // Safety against eof
1255
state = MY_LEX_START; // Try again
1257
case MY_LEX_LONG_COMMENT: /* Long C comment? */
1258
if (lip->yyPeek() != '*')
1260
state=MY_LEX_CHAR; // Probable division
1263
lex->select_lex.options|= OPTION_FOUND_COMMENT;
1264
/* Reject '/' '*', since we might need to turn off the echo */
1267
lip->save_in_comment_state();
1269
if (lip->yyPeekn(2) == '!')
1271
lip->in_comment= DISCARD_COMMENT;
1272
/* Accept '/' '*' '!', but do not keep this marker. */
1273
lip->set_echo(FALSE);
1279
The special comment format is very strict:
1280
'/' '*' '!', followed by exactly
1281
1 digit (major), 2 digits (minor), then 2 digits (dot).
1286
char version_str[6];
1287
version_str[0]= lip->yyPeekn(0);
1288
version_str[1]= lip->yyPeekn(1);
1289
version_str[2]= lip->yyPeekn(2);
1290
version_str[3]= lip->yyPeekn(3);
1291
version_str[4]= lip->yyPeekn(4);
1293
if ( my_isdigit(cs, version_str[0])
1294
&& my_isdigit(cs, version_str[1])
1295
&& my_isdigit(cs, version_str[2])
1296
&& my_isdigit(cs, version_str[3])
1297
&& my_isdigit(cs, version_str[4])
1301
version=strtol(version_str, NULL, 10);
1303
/* Accept 'M' 'm' 'm' 'd' 'd' */
1306
if (version <= MYSQL_VERSION_ID)
1308
/* Expand the content of the special comment as real code */
1309
lip->set_echo(TRUE);
1311
break; /* Do not treat contents as a comment. */
1315
comment_closed= ! consume_comment(lip, 1);
1316
/* version allowed to have one level of comment inside. */
1321
/* Not a version comment. */
1323
lip->set_echo(TRUE);
1329
lip->in_comment= PRESERVE_COMMENT;
1330
lip->yySkip(); // Accept /
1331
lip->yySkip(); // Accept *
1332
comment_closed= ! consume_comment(lip, 0);
1333
/* regular comments can have zero comments inside. */
1337
- regular '/' '*' comments,
1338
- special comments '/' '*' '!' for a future version,
1339
by scanning until we find a closing '*' '/' marker.
1341
Nesting regular comments isn't allowed. The first
1342
'*' '/' returns the parser to the previous state.
1344
/#!VERSI oned containing /# regular #/ is allowed #/
1346
Inside one versioned comment, another versioned comment
1347
is treated as a regular discardable comment. It gets
1351
/* Unbalanced comments with a missing '*' '/' are a syntax error */
1352
if (! comment_closed)
1354
state = MY_LEX_START; // Try again
1355
lip->restore_in_comment_state();
1357
case MY_LEX_END_LONG_COMMENT:
1358
if ((lip->in_comment != NO_COMMENT) && lip->yyPeek() == '/')
1360
/* Reject '*' '/' */
1362
/* Accept '*' '/', with the proper echo */
1363
lip->set_echo(lip->in_comment == PRESERVE_COMMENT);
1365
/* And start recording the tokens again */
1366
lip->set_echo(TRUE);
1367
lip->in_comment=NO_COMMENT;
1371
state=MY_LEX_CHAR; // Return '*'
1373
case MY_LEX_SET_VAR: // Check if ':='
1374
if (lip->yyPeek() != '=')
1376
state=MY_LEX_CHAR; // Return ':'
1381
case MY_LEX_SEMICOLON: // optional line terminator
1382
state= MY_LEX_CHAR; // Return ';'
1387
lip->yyUnget(); // Reject the last '\0'
1388
lip->set_echo(FALSE);
1390
lip->set_echo(TRUE);
1391
/* Unbalanced comments with a missing '*' '/' are a syntax error */
1392
if (lip->in_comment != NO_COMMENT)
1394
lip->next_state=MY_LEX_END; // Mark for next loop
1395
return(END_OF_INPUT);
1400
lip->next_state=MY_LEX_END;
1401
return(0); // We found end of input last time
1403
/* Actually real shouldn't start with . but allow them anyhow */
1404
case MY_LEX_REAL_OR_POINT:
1405
if (my_isdigit(cs,lip->yyPeek()))
1406
state = MY_LEX_REAL; // Real
1409
state= MY_LEX_IDENT_SEP; // return '.'
1410
lip->yyUnget(); // Put back '.'
1413
case MY_LEX_USER_END: // end '@' of user@hostname
1414
switch (state_map[lip->yyPeek()]) {
1416
case MY_LEX_USER_VARIABLE_DELIMITER:
1417
case MY_LEX_STRING_OR_DELIMITER:
1419
case MY_LEX_USER_END:
1420
lip->next_state=MY_LEX_SYSTEM_VAR;
1423
lip->next_state=MY_LEX_HOSTNAME;
1426
yylval->lex_str.str=(char*) lip->get_ptr();
1427
yylval->lex_str.length=1;
1429
case MY_LEX_HOSTNAME: // end '@' of user@hostname
1430
for (c=lip->yyGet() ;
1431
my_isalnum(cs,c) || c == '.' || c == '_' || c == '$';
1433
yylval->lex_str=get_token(lip, 0, lip->yyLength());
1434
return(LEX_HOSTNAME);
1435
case MY_LEX_SYSTEM_VAR:
1436
yylval->lex_str.str=(char*) lip->get_ptr();
1437
yylval->lex_str.length=1;
1438
lip->yySkip(); // Skip '@'
1439
lip->next_state= (state_map[lip->yyPeek()] ==
1440
MY_LEX_USER_VARIABLE_DELIMITER ?
1441
MY_LEX_OPERATOR_OR_IDENT :
1442
MY_LEX_IDENT_OR_KEYWORD);
1444
case MY_LEX_IDENT_OR_KEYWORD:
1446
We come here when we have found two '@' in a row.
1447
We should now be able to handle:
1448
[(global | local | session) .]variable_name
1451
for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) ;
1452
/* If there were non-ASCII characters, mark that we must convert */
1453
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1456
lip->next_state=MY_LEX_IDENT_SEP;
1457
length= lip->yyLength();
1459
return(ABORT_SYM); // Names must be nonempty.
1460
if ((tokval= find_keyword(lip, length,0)))
1462
lip->yyUnget(); // Put back 'c'
1463
return(tokval); // Was keyword
1465
yylval->lex_str=get_token(lip, 0, length);
1467
lip->body_utf8_append(lip->m_cpp_text_start);
1469
lip->body_utf8_append_literal(thd, &yylval->lex_str, cs,
1470
lip->m_cpp_text_end);
1472
return(result_state);
1479
Construct a copy of this object to be used for mysql_alter_table
1480
and mysql_create_table.
1482
Historically, these two functions modify their Alter_info
1483
arguments. This behaviour breaks re-execution of prepared
1484
statements and stored procedures and is compensated by always
1485
supplying a copy of Alter_info to these functions.
1487
@return You need to use check the error in THD for out
1488
of memory condition after calling this function.
1491
Alter_info::Alter_info(const Alter_info &rhs, MEM_ROOT *mem_root)
1492
:drop_list(rhs.drop_list, mem_root),
1493
alter_list(rhs.alter_list, mem_root),
1494
key_list(rhs.key_list, mem_root),
1495
create_list(rhs.create_list, mem_root),
1497
keys_onoff(rhs.keys_onoff),
1498
tablespace_op(rhs.tablespace_op),
1499
partition_names(rhs.partition_names, mem_root),
1500
no_parts(rhs.no_parts),
1501
change_level(rhs.change_level),
1502
datetime_field(rhs.datetime_field),
1503
error_if_not_empty(rhs.error_if_not_empty)
1506
Make deep copies of used objects.
1507
This is not a fully deep copy - clone() implementations
1508
of Alter_drop, Alter_column, Key, foreign_key, Key_part_spec
1509
do not copy string constants. At the same length the only
1510
reason we make a copy currently is that ALTER/CREATE TABLE
1511
code changes input Alter_info definitions, but string
1512
constants never change.
1514
list_copy_and_replace_each_value(drop_list, mem_root);
1515
list_copy_and_replace_each_value(alter_list, mem_root);
1516
list_copy_and_replace_each_value(key_list, mem_root);
1517
list_copy_and_replace_each_value(create_list, mem_root);
1518
/* partition_names are not deeply copied currently */
1522
void trim_whitespace(CHARSET_INFO *cs, LEX_STRING *str)
1526
This code assumes that there are no multi-bytes characters
1527
that can be considered white-space.
1530
while ((str->length > 0) && (my_isspace(cs, str->str[0])))
1538
Also, parsing backward is not safe with multi bytes characters
1540
while ((str->length > 0) && (my_isspace(cs, str->str[str->length-1])))
1548
st_select_lex structures initialisations
1551
void st_select_lex_node::init_query()
1554
sql_cache= SQL_CACHE_UNSPECIFIED;
1555
linkage= UNSPECIFIED_TYPE;
1556
no_error= no_table_names_allowed= 0;
1560
void st_select_lex_node::init_select()
1564
void st_select_lex_unit::init_query()
1566
st_select_lex_node::init_query();
1567
linkage= GLOBAL_OPTIONS_TYPE;
1568
global_parameters= first_select();
1569
select_limit_cnt= HA_POS_ERROR;
1570
offset_limit_cnt= 0;
1572
prepared= optimized= executed= 0;
1580
found_rows_for_union= 0;
1583
void st_select_lex::init_query()
1585
st_select_lex_node::init_query();
1587
top_join_list.empty();
1588
join_list= &top_join_list;
1589
embedding= leaf_tables= 0;
1592
having= prep_having= where= prep_where= 0;
1593
olap= UNSPECIFIED_OLAP_TYPE;
1594
having_fix_field= 0;
1596
context.select_lex= this;
1599
Add the name resolution context of the current (sub)query to the
1600
stack of contexts for the whole query.
1602
push_context may return an error if there is no memory for a new
1603
element in the stack, however this method has no return value,
1604
thus push_context should be moved to a place where query
1605
initialization is checked for failure.
1607
parent_lex->push_context(&context);
1608
cond_count= between_count= with_wild= 0;
1610
conds_processed_with_permanent_arena= 0;
1611
ref_pointer_array= 0;
1612
select_n_where_fields= 0;
1613
select_n_having_items= 0;
1614
subquery_in_having= explicit_limit= 0;
1615
is_item_list_lookup= 0;
1617
first_natural_join_processing= 1;
1618
first_cond_optimization= 1;
1619
parsing_place= NO_MATTER;
1620
exclude_from_table_unique_test= no_wrap_view_item= FALSE;
1623
lock_option= TL_READ_DEFAULT;
1626
void st_select_lex::init_select()
1628
st_select_lex_node::init_select();
1632
table_join_options= 0;
1633
in_sum_expr= with_wild= 0;
1635
sql_cache= SQL_CACHE_UNSPECIFIED;
1637
interval_list.empty();
1638
ftfunc_list_alloc.empty();
1639
inner_sum_func_list= 0;
1640
ftfunc_list= &ftfunc_list_alloc;
1641
linkage= UNSPECIFIED_TYPE;
1642
order_list.elements= 0;
1643
order_list.first= 0;
1644
order_list.next= (uchar**) &order_list.first;
1645
/* Set limit and offset to default values */
1646
select_limit= 0; /* denotes the default limit = HA_POS_ERROR */
1647
offset_limit= 0; /* denotes the default offset = 0 */
1650
cur_pos_in_select_list= UNDEF_POS;
1651
non_agg_fields.empty();
1652
cond_value= having_value= Item::COND_UNDEF;
1653
inner_refs_list.empty();
1654
full_group_by_flag= 0;
1658
st_select_lex structures linking
1661
/* include on level down */
1662
void st_select_lex_node::include_down(st_select_lex_node *upper)
1664
if ((next= upper->slave))
1666
prev= &upper->slave;
1673
include on level down (but do not link)
1676
st_select_lex_node::include_standalone()
1677
upper - reference on node underr which this node should be included
1678
ref - references on reference on this node
1680
void st_select_lex_node::include_standalone(st_select_lex_node *upper,
1681
st_select_lex_node **ref)
1689
/* include neighbour (on same level) */
1690
void st_select_lex_node::include_neighbour(st_select_lex_node *before)
1692
if ((next= before->next))
1694
prev= &before->next;
1696
master= before->master;
1700
/* including in global SELECT_LEX list */
1701
void st_select_lex_node::include_global(st_select_lex_node **plink)
1703
if ((link_next= *plink))
1704
link_next->link_prev= &link_next;
1709
//excluding from global list (internal function)
1710
void st_select_lex_node::fast_exclude()
1714
if ((*link_prev= link_next))
1715
link_next->link_prev= link_prev;
1717
// Remove slave structure
1718
for (; slave; slave= slave->next)
1719
slave->fast_exclude();
1724
excluding select_lex structure (except first (first select can't be
1725
deleted, because it is most upper select))
1727
void st_select_lex_node::exclude()
1729
//exclude from global list
1731
//exclude from other structures
1735
We do not need following statements, because prev pointer of first
1736
list element point to master->slave
1737
if (master->slave == this)
1738
master->slave= next;
1744
Exclude level of current unit from tree of SELECTs
1747
st_select_lex_unit::exclude_level()
1749
NOTE: units which belong to current will be brought up on level of
1752
void st_select_lex_unit::exclude_level()
1754
SELECT_LEX_UNIT *units= 0, **units_last= &units;
1755
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1757
// unlink current level from global SELECTs list
1758
if (sl->link_prev && (*sl->link_prev= sl->link_next))
1759
sl->link_next->link_prev= sl->link_prev;
1761
// bring up underlay levels
1762
SELECT_LEX_UNIT **last= 0;
1763
for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1766
last= (SELECT_LEX_UNIT**)&(u->next);
1770
(*units_last)= sl->first_inner_unit();
1776
// include brought up levels in place of current
1778
(*units_last)= (SELECT_LEX_UNIT*)next;
1780
next->prev= (SELECT_LEX_NODE**)units_last;
1785
// exclude currect unit from list of nodes
1794
Exclude subtree of current unit from tree of SELECTs
1797
st_select_lex_unit::exclude_tree()
1799
void st_select_lex_unit::exclude_tree()
1801
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
1803
// unlink current level from global SELECTs list
1804
if (sl->link_prev && (*sl->link_prev= sl->link_next))
1805
sl->link_next->link_prev= sl->link_prev;
1807
// unlink underlay levels
1808
for (SELECT_LEX_UNIT *u= sl->first_inner_unit(); u; u= u->next_unit())
1813
// exclude currect unit from list of nodes
1821
st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
1822
this to 'last' as dependent
1825
last - pointer to last st_select_lex struct, before wich all
1826
st_select_lex have to be marked as dependent
1829
'last' should be reachable from this st_select_lex_node
1832
void st_select_lex::mark_as_dependent(st_select_lex *last)
1835
Mark all selects from resolved to 1 before select where was
1836
found table as depended (of select where was found table)
1838
for (SELECT_LEX *s= this;
1840
s= s->outer_select())
1841
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
1843
// Select is dependent of outer select
1844
s->uncacheable= (s->uncacheable & ~UNCACHEABLE_UNITED) |
1845
UNCACHEABLE_DEPENDENT;
1846
SELECT_LEX_UNIT *munit= s->master_unit();
1847
munit->uncacheable= (munit->uncacheable & ~UNCACHEABLE_UNITED) |
1848
UNCACHEABLE_DEPENDENT;
1849
for (SELECT_LEX *sl= munit->first_select(); sl ; sl= sl->next_select())
1852
!(sl->uncacheable & (UNCACHEABLE_DEPENDENT | UNCACHEABLE_UNITED)))
1853
sl->uncacheable|= UNCACHEABLE_UNITED;
1856
is_correlated= TRUE;
1857
this->master_unit()->item->is_correlated= TRUE;
1860
bool st_select_lex_node::set_braces(bool value) { return 1; }
1861
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
1862
uint st_select_lex_node::get_in_sum_expr() { return 0; }
1863
TABLE_LIST* st_select_lex_node::get_table_list() { return 0; }
1864
List<Item>* st_select_lex_node::get_item_list() { return 0; }
1865
TABLE_LIST *st_select_lex_node::add_table_to_list (THD *thd, Table_ident *table,
1867
ulong table_join_options,
1868
thr_lock_type flags,
1869
List<Index_hint> *hints,
1874
ulong st_select_lex_node::get_table_join_options()
1880
prohibit using LIMIT clause
1882
bool st_select_lex::test_limit()
1884
if (select_limit != 0)
1886
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1887
"LIMIT & IN/ALL/ANY/SOME subquery");
1894
st_select_lex_unit* st_select_lex_unit::master_unit()
1900
st_select_lex* st_select_lex_unit::outer_select()
1902
return (st_select_lex*) master;
1906
bool st_select_lex::add_order_to_list(THD *thd, Item *item, bool asc)
1908
return add_to_list(thd, order_list, item, asc);
1912
bool st_select_lex::add_item_to_list(THD *thd, Item *item)
1914
DBUG_ENTER("st_select_lex::add_item_to_list");
1915
DBUG_PRINT("info", ("Item: 0x%lx", (long) item));
1916
DBUG_RETURN(item_list.push_back(item));
1920
bool st_select_lex::add_group_to_list(THD *thd, Item *item, bool asc)
1922
return add_to_list(thd, group_list, item, asc);
1926
bool st_select_lex::add_ftfunc_to_list(Item_func_match *func)
1928
return !func || ftfunc_list->push_back(func); // end of memory?
1932
st_select_lex_unit* st_select_lex::master_unit()
1934
return (st_select_lex_unit*) master;
1938
st_select_lex* st_select_lex::outer_select()
1940
return (st_select_lex*) master->get_master();
1944
bool st_select_lex::set_braces(bool value)
1951
bool st_select_lex::inc_in_sum_expr()
1958
uint st_select_lex::get_in_sum_expr()
1964
TABLE_LIST* st_select_lex::get_table_list()
1966
return (TABLE_LIST*) table_list.first;
1969
List<Item>* st_select_lex::get_item_list()
1974
ulong st_select_lex::get_table_join_options()
1976
return table_join_options;
1980
bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
1982
if (ref_pointer_array)
1986
We have to create array in prepared statement memory if it is
1989
Query_arena *arena= thd->stmt_arena;
1990
return (ref_pointer_array=
1991
(Item **)arena->alloc(sizeof(Item*) * (n_child_sum_items +
1992
item_list.elements +
1993
select_n_having_items +
1994
select_n_where_fields +
1995
order_group_num)*5)) == 0;
1999
void st_select_lex_unit::print(String *str, enum_query_type query_type)
2001
bool union_all= !union_distinct;
2002
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
2004
if (sl != first_select())
2006
str->append(STRING_WITH_LEN(" union "));
2008
str->append(STRING_WITH_LEN("all "));
2009
else if (union_distinct == sl)
2014
sl->print(thd, str, query_type);
2018
if (fake_select_lex == global_parameters)
2020
if (fake_select_lex->order_list.elements)
2022
str->append(STRING_WITH_LEN(" order by "));
2023
fake_select_lex->print_order(
2025
(ORDER *) fake_select_lex->order_list.first,
2028
fake_select_lex->print_limit(thd, str, query_type);
2033
void st_select_lex::print_order(String *str,
2035
enum_query_type query_type)
2037
for (; order; order= order->next)
2039
if (order->counter_used)
2042
size_t length= my_snprintf(buffer, 20, "%d", order->counter);
2043
str->append(buffer, (uint) length);
2046
(*order->item)->print(str, query_type);
2048
str->append(STRING_WITH_LEN(" desc"));
2055
void st_select_lex::print_limit(THD *thd,
2057
enum_query_type query_type)
2059
SELECT_LEX_UNIT *unit= master_unit();
2060
Item_subselect *item= unit->item;
2061
if (item && unit->global_parameters == this &&
2062
(item->substype() == Item_subselect::EXISTS_SUBS ||
2063
item->substype() == Item_subselect::IN_SUBS ||
2064
item->substype() == Item_subselect::ALL_SUBS))
2066
DBUG_ASSERT(!item->fixed ||
2067
(select_limit->val_int() == LL(1) && offset_limit == 0));
2073
str->append(STRING_WITH_LEN(" limit "));
2076
offset_limit->print(str, query_type);
2079
select_limit->print(str, query_type);
2084
@brief Restore the LEX and THD in case of a parse error.
2086
This is a clean up call that is invoked by the Bison generated
2087
parser before returning an error from MYSQLparse. If your
2088
semantic actions manipulate with the global thread state (which
2089
is a very bad practice and should not normally be employed) and
2090
need a clean-up in case of error, and you can not use %destructor
2091
rule in the grammar file itself, this function should be used
2092
to implement the clean up.
2095
void st_lex::cleanup_lex_after_parse_error(THD *thd)
2098
Delete sphead for the side effect of restoring of the original
2099
LEX state, thd->lex, thd->mem_root and thd->free_list if they
2100
were replaced when parsing stored procedure statements. We
2101
will never use sphead object after a parse error, so it's okay
2102
to delete it only for the sake of the side effect.
2103
TODO: make this functionality explicit in sp_head class.
2104
Sic: we must nullify the member of the main lex, not the
2105
current one that will be thrown away
2107
if (thd->lex->sphead)
2109
delete thd->lex->sphead;
2110
thd->lex->sphead= NULL;
2115
Initialize (or reset) Query_tables_list object.
2118
reset_query_tables_list()
2119
init TRUE - we should perform full initialization of object with
2120
allocating needed memory
2121
FALSE - object is already initialized so we should only reset
2122
its state so it can be used for parsing/processing
2126
This method initializes Query_tables_list so it can be used as part
2127
of LEX object for parsing/processing of statement. One can also use
2128
this method to reset state of already initialized Query_tables_list
2129
so it can be used for processing of new statement.
2132
void Query_tables_list::reset_query_tables_list(bool init)
2134
if (!init && query_tables)
2136
TABLE_LIST *table= query_tables;
2140
if (query_tables_last == &table->next_global ||
2141
!(table= table->next_global))
2146
query_tables_last= &query_tables;
2147
query_tables_own_last= 0;
2151
We delay real initialization of hash (and therefore related
2152
memory allocation) until first insertion into this hash.
2154
hash_clear(&sroutines);
2156
else if (sroutines.records)
2158
/* Non-zero sroutines.records means that hash was initialized. */
2159
my_hash_reset(&sroutines);
2161
sroutines_list.empty();
2162
sroutines_list_own_last= sroutines_list.next;
2163
sroutines_list_own_elements= 0;
2164
binlog_stmt_flags= 0;
2169
Destroy Query_tables_list object with freeing all resources used by it.
2172
destroy_query_tables_list()
2175
void Query_tables_list::destroy_query_tables_list()
2177
hash_free(&sroutines);
2182
Initialize LEX object.
2188
LEX object initialized with this constructor can be used as part of
2189
THD object for which one can safely call open_tables(), lock_tables()
2190
and close_thread_tables() functions. But it is not yet ready for
2191
statement parsing. On should use lex_start() function to prepare LEX
2197
sql_command(SQLCOM_END), option_type(OPT_DEFAULT), is_lex_started(0)
2200
my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
2201
plugins_static_buffer,
2202
INITIAL_LEX_PLUGIN_LIST_SIZE,
2203
INITIAL_LEX_PLUGIN_LIST_SIZE);
2204
reset_query_tables_list(TRUE);
2209
Check whether the merging algorithm can be used on this VIEW
2212
st_lex::can_be_merged()
2215
We can apply merge algorithm if it is single SELECT view with
2216
subqueries only in WHERE clause (we do not count SELECTs of underlying
2217
views, and second level subqueries) and we have not grpouping, ordering,
2218
HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2219
several underlying tables.
2222
FALSE - only temporary table algorithm can be used
2223
TRUE - merge algorithm can be used
2226
bool st_lex::can_be_merged()
2228
// TODO: do not forget implement case when select_lex.table_list.elements==0
2230
/* find non VIEW subqueries/unions */
2231
bool selects_allow_merge= select_lex.next_select() == 0;
2232
if (selects_allow_merge)
2234
for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2236
tmp_unit= tmp_unit->next_unit())
2238
if (tmp_unit->first_select()->parent_lex == this &&
2239
(tmp_unit->item == 0 ||
2240
(tmp_unit->item->place() != IN_WHERE &&
2241
tmp_unit->item->place() != IN_ON)))
2243
selects_allow_merge= 0;
2249
return (selects_allow_merge &&
2250
select_lex.group_list.elements == 0 &&
2251
select_lex.having == 0 &&
2252
select_lex.with_sum_func == 0 &&
2253
select_lex.table_list.elements >= 1 &&
2254
!(select_lex.options & SELECT_DISTINCT) &&
2255
select_lex.select_limit == 0);
2260
check if command can use VIEW with MERGE algorithm (for top VIEWs)
2263
st_lex::can_use_merged()
2266
Only listed here commands can use merge algorithm in top level
2267
SELECT_LEX (for subqueries will be used merge algorithm if
2268
st_lex::can_not_use_merged() is not TRUE).
2271
FALSE - command can't use merged VIEWs
2272
TRUE - VIEWs with MERGE algorithms can be used
2275
bool st_lex::can_use_merged()
2277
switch (sql_command)
2280
case SQLCOM_CREATE_TABLE:
2282
case SQLCOM_UPDATE_MULTI:
2284
case SQLCOM_DELETE_MULTI:
2286
case SQLCOM_INSERT_SELECT:
2287
case SQLCOM_REPLACE:
2288
case SQLCOM_REPLACE_SELECT:
2297
Check if command can't use merged views in any part of command
2300
st_lex::can_not_use_merged()
2303
Temporary table algorithm will be used on all SELECT levels for queries
2304
listed here (see also st_lex::can_use_merged()).
2307
FALSE - command can't use merged VIEWs
2308
TRUE - VIEWs with MERGE algorithms can be used
2311
bool st_lex::can_not_use_merged()
2313
switch (sql_command)
2315
case SQLCOM_CREATE_VIEW:
2316
case SQLCOM_SHOW_CREATE:
2318
SQLCOM_SHOW_FIELDS is necessary to make
2319
information schema tables working correctly with views.
2320
see get_schema_tables_result function
2322
case SQLCOM_SHOW_FIELDS:
2330
Detect that we need only table structure of derived table/view
2333
only_view_structure()
2336
TRUE yes, we need only structure
2337
FALSE no, we need data
2340
bool st_lex::only_view_structure()
2342
switch (sql_command) {
2343
case SQLCOM_SHOW_CREATE:
2344
case SQLCOM_SHOW_TABLES:
2345
case SQLCOM_SHOW_FIELDS:
2346
case SQLCOM_REVOKE_ALL:
2349
case SQLCOM_CREATE_VIEW:
2358
Should Items_ident be printed correctly
2361
need_correct_ident()
2364
TRUE yes, we need only structure
2365
FALSE no, we need data
2369
bool st_lex::need_correct_ident()
2373
case SQLCOM_SHOW_CREATE:
2374
case SQLCOM_SHOW_TABLES:
2375
case SQLCOM_CREATE_VIEW:
2383
Get effective type of CHECK OPTION for given view
2386
get_effective_with_check()
2390
It have not sense to set CHECK OPTION for SELECT satement or subqueries,
2394
VIEW_CHECK_NONE no need CHECK OPTION
2395
VIEW_CHECK_LOCAL CHECK OPTION LOCAL
2396
VIEW_CHECK_CASCADED CHECK OPTION CASCADED
2399
uint8 st_lex::get_effective_with_check(TABLE_LIST *view)
2401
if (view->select_lex->master_unit() == &unit &&
2402
which_check_option_applicable())
2403
return (uint8)view->with_check;
2404
return VIEW_CHECK_NONE;
2409
This method should be called only during parsing.
2410
It is aware of compound statements (stored routine bodies)
2411
and will initialize the destination with the default
2412
database of the stored routine, rather than the default
2413
database of the connection it is parsed in.
2414
E.g. if one has no current database selected, or current database
2415
set to 'bar' and then issues:
2417
CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//
2419
t1 is meant to refer to foo.t1, not to bar.t1.
2421
This method is needed to support this rule.
2423
@return TRUE in case of error (parsing should be aborted, FALSE in
2428
st_lex::copy_db_to(char **p_db, size_t *p_db_length) const
2432
DBUG_ASSERT(sphead->m_db.str && sphead->m_db.length);
2434
It is safe to assign the string by-pointer, both sphead and
2435
its statements reside in the same memory root.
2437
*p_db= sphead->m_db.str;
2439
*p_db_length= sphead->m_db.length;
2442
return thd->copy_db_to(p_db, p_db_length);
2446
initialize limit counters
2449
st_select_lex_unit::set_limit()
2450
values - SELECT_LEX with initial values for counters
2453
void st_select_lex_unit::set_limit(st_select_lex *sl)
2455
ha_rows select_limit_val;
2458
DBUG_ASSERT(! thd->stmt_arena->is_stmt_prepare());
2459
val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
2460
select_limit_val= (ha_rows)val;
2463
Check for overflow : ha_rows can be smaller then ulonglong if
2466
if (val != (ulonglong)select_limit_val)
2467
select_limit_val= HA_POS_ERROR;
2469
val= sl->offset_limit ? sl->offset_limit->val_uint() : ULL(0);
2470
offset_limit_cnt= (ha_rows)val;
2472
/* Check for truncation. */
2473
if (val != (ulonglong)offset_limit_cnt)
2474
offset_limit_cnt= HA_POS_ERROR;
2476
select_limit_cnt= select_limit_val + offset_limit_cnt;
2477
if (select_limit_cnt < select_limit_val)
2478
select_limit_cnt= HA_POS_ERROR; // no limit
2483
@brief Set the initial purpose of this TABLE_LIST object in the list of used
2486
We need to track this information on table-by-table basis, since when this
2487
table becomes an element of the pre-locked list, it's impossible to identify
2488
which SQL sub-statement it has been originally used in.
2492
User request: SELECT * FROM t1 WHERE f1();
2493
FUNCTION f1(): DELETE FROM t2; RETURN 1;
2494
BEFORE DELETE trigger on t2: INSERT INTO t3 VALUES (old.a);
2496
For this user request, the pre-locked list will contain t1, t2, t3
2497
table elements, each needed for different DML.
2499
The trigger event map is updated to reflect INSERT, UPDATE, DELETE,
2500
REPLACE, LOAD DATA, CREATE TABLE .. SELECT, CREATE TABLE ..
2501
REPLACE SELECT statements, and additionally ON DUPLICATE KEY UPDATE
2505
void st_lex::set_trg_event_type_for_tables()
2507
uint8 new_trg_event_map= 0;
2510
Some auxiliary operations
2511
(e.g. GRANT processing) create TABLE_LIST instances outside
2512
the parser. Additionally, some commands (e.g. OPTIMIZE) change
2513
the lock type for a table only after parsing is done. Luckily,
2514
these do not fire triggers and do not need to pre-load them.
2515
For these TABLE_LISTs set_trg_event_type is never called, and
2516
trg_event_map is always empty. That means that the pre-locking
2517
algorithm will ignore triggers defined on these tables, if
2518
any, and the execution will either fail with an assert in
2519
sql_trigger.cc or with an error that a used table was not
2520
pre-locked, in case of a production build.
2522
TODO: this usage pattern creates unnecessary module dependencies
2523
and should be rewritten to go through the parser.
2524
Table list instances created outside the parser in most cases
2525
refer to mysql.* system tables. It is not allowed to have
2526
a trigger on a system table, but keeping track of
2527
initialization provides extra safety in case this limitation
2531
switch (sql_command) {
2532
case SQLCOM_LOCK_TABLES:
2534
On a LOCK TABLE, all triggers must be pre-loaded for this TABLE_LIST
2535
when opening an associated TABLE.
2537
new_trg_event_map= static_cast<uint8>
2538
(1 << static_cast<int>(TRG_EVENT_INSERT)) |
2540
(1 << static_cast<int>(TRG_EVENT_UPDATE)) |
2542
(1 << static_cast<int>(TRG_EVENT_DELETE));
2545
Basic INSERT. If there is an additional ON DUPLIATE KEY UPDATE
2546
clause, it will be handled later in this method.
2548
case SQLCOM_INSERT: /* fall through */
2549
case SQLCOM_INSERT_SELECT:
2551
LOAD DATA ... INFILE is expected to fire BEFORE/AFTER INSERT
2553
If the statement also has REPLACE clause, it will be
2554
handled later in this method.
2556
case SQLCOM_LOAD: /* fall through */
2558
REPLACE is semantically equivalent to INSERT. In case
2559
of a primary or unique key conflict, it deletes the old
2560
record and inserts a new one. So we also may need to
2561
fire ON DELETE triggers. This functionality is handled
2562
later in this method.
2564
case SQLCOM_REPLACE: /* fall through */
2565
case SQLCOM_REPLACE_SELECT:
2567
CREATE TABLE ... SELECT defaults to INSERT if the table or
2568
view already exists. REPLACE option of CREATE TABLE ...
2569
REPLACE SELECT is handled later in this method.
2571
case SQLCOM_CREATE_TABLE:
2572
new_trg_event_map|= static_cast<uint8>
2573
(1 << static_cast<int>(TRG_EVENT_INSERT));
2575
/* Basic update and multi-update */
2576
case SQLCOM_UPDATE: /* fall through */
2577
case SQLCOM_UPDATE_MULTI:
2578
new_trg_event_map|= static_cast<uint8>
2579
(1 << static_cast<int>(TRG_EVENT_UPDATE));
2581
/* Basic delete and multi-delete */
2582
case SQLCOM_DELETE: /* fall through */
2583
case SQLCOM_DELETE_MULTI:
2584
new_trg_event_map|= static_cast<uint8>
2585
(1 << static_cast<int>(TRG_EVENT_DELETE));
2591
switch (duplicates) {
2593
new_trg_event_map|= static_cast<uint8>
2594
(1 << static_cast<int>(TRG_EVENT_UPDATE));
2597
new_trg_event_map|= static_cast<uint8>
2598
(1 << static_cast<int>(TRG_EVENT_DELETE));
2607
Do not iterate over sub-selects, only the tables in the outermost
2608
SELECT_LEX can be modified, if any.
2610
TABLE_LIST *tables= select_lex.get_table_list();
2615
This is a fast check to filter out statements that do
2616
not change data, or tables on the right side, in case of
2617
INSERT .. SELECT, CREATE TABLE .. SELECT and so on.
2618
Here we also filter out OPTIMIZE statement and non-updateable
2619
views, for which lock_type is TL_UNLOCK or TL_READ after
2622
if (static_cast<int>(tables->lock_type) >=
2623
static_cast<int>(TL_WRITE_ALLOW_WRITE))
2624
tables->trg_event_map= new_trg_event_map;
2625
tables= tables->next_local;
2631
Unlink the first table from the global table list and the first table from
2632
outer select (lex->select_lex) local list
2635
unlink_first_table()
2636
link_to_local Set to 1 if caller should link this table to local list
2639
We assume that first tables in both lists is the same table or the local
2643
0 If 'query_tables' == 0
2645
In this case link_to_local is set.
2648
TABLE_LIST *st_lex::unlink_first_table(bool *link_to_local)
2651
if ((first= query_tables))
2654
Exclude from global table list
2656
if ((query_tables= query_tables->next_global))
2657
query_tables->prev_global= &query_tables;
2659
query_tables_last= &query_tables;
2660
first->next_global= 0;
2663
and from local list if it is not empty
2665
if ((*link_to_local= test(select_lex.table_list.first)))
2667
select_lex.context.table_list=
2668
select_lex.context.first_name_resolution_table= first->next_local;
2669
select_lex.table_list.first= (uchar*) (first->next_local);
2670
select_lex.table_list.elements--; //safety
2671
first->next_local= 0;
2673
Ensure that the global list has the same first table as the local
2676
first_lists_tables_same();
2684
Bring first local table of first most outer select to first place in global
2688
st_lex::first_lists_tables_same()
2691
In many cases (for example, usual INSERT/DELETE/...) the first table of
2692
main SELECT_LEX have special meaning => check that it is the first table
2693
in global list and re-link to be first in the global list if it is
2694
necessary. We need such re-linking only for queries with sub-queries in
2695
the select list, as only in this case tables of sub-queries will go to
2696
the global list first.
2699
void st_lex::first_lists_tables_same()
2701
TABLE_LIST *first_table= (TABLE_LIST*) select_lex.table_list.first;
2702
if (query_tables != first_table && first_table != 0)
2705
if (query_tables_last == &first_table->next_global)
2706
query_tables_last= first_table->prev_global;
2708
if ((next= *first_table->prev_global= first_table->next_global))
2709
next->prev_global= first_table->prev_global;
2710
/* include in new place */
2711
first_table->next_global= query_tables;
2713
We are sure that query_tables is not 0, because first_table was not
2714
first table in the global list => we can use
2715
query_tables->prev_global without check of query_tables
2717
query_tables->prev_global= &first_table->next_global;
2718
first_table->prev_global= &query_tables;
2719
query_tables= first_table;
2725
Link table back that was unlinked with unlink_first_table()
2728
link_first_table_back()
2729
link_to_local do we need link this table to local
2735
void st_lex::link_first_table_back(TABLE_LIST *first,
2740
if ((first->next_global= query_tables))
2741
query_tables->prev_global= &first->next_global;
2743
query_tables_last= &first->next_global;
2744
query_tables= first;
2748
first->next_local= (TABLE_LIST*) select_lex.table_list.first;
2749
select_lex.context.table_list= first;
2750
select_lex.table_list.first= (uchar*) first;
2751
select_lex.table_list.elements++; //safety
2759
cleanup lex for case when we open table by table for processing
2762
st_lex::cleanup_after_one_table_open()
2765
This method is mostly responsible for cleaning up of selects lists and
2766
derived tables state. To rollback changes in Query_tables_list one has
2767
to call Query_tables_list::reset_query_tables_list(FALSE).
2770
void st_lex::cleanup_after_one_table_open()
2773
thd->lex->derived_tables & additional units may be set if we open
2774
a view. It is necessary to clear thd->lex->derived_tables flag
2775
to prevent processing of derived tables during next open_and_lock_tables
2776
if next table is a real table and cleanup & remove underlying units
2777
NOTE: all units will be connected to thd->lex->select_lex, because we
2778
have not UNION on most upper level.
2780
if (all_selects_list != &select_lex)
2783
/* cleunup underlying units (units of VIEW) */
2784
for (SELECT_LEX_UNIT *un= select_lex.first_inner_unit();
2786
un= un->next_unit())
2788
/* reduce all selects list to default state */
2789
all_selects_list= &select_lex;
2790
/* remove underlying units (units of VIEW) subtree */
2791
select_lex.cut_subtree();
2797
Save current state of Query_tables_list for this LEX, and prepare it
2798
for processing of new statemnt.
2801
reset_n_backup_query_tables_list()
2802
backup Pointer to Query_tables_list instance to be used for backup
2805
void st_lex::reset_n_backup_query_tables_list(Query_tables_list *backup)
2807
backup->set_query_tables_list(this);
2809
We have to perform full initialization here since otherwise we
2810
will damage backed up state.
2812
this->reset_query_tables_list(TRUE);
2817
Restore state of Query_tables_list for this LEX from backup.
2820
restore_backup_query_tables_list()
2821
backup Pointer to Query_tables_list instance used for backup
2824
void st_lex::restore_backup_query_tables_list(Query_tables_list *backup)
2826
this->destroy_query_tables_list();
2827
this->set_query_tables_list(backup);
2832
Checks for usage of routines and/or tables in a parsed statement
2835
st_lex:table_or_sp_used()
2838
FALSE No routines and tables used
2839
TRUE Either or both routines and tables are used.
2842
bool st_lex::table_or_sp_used()
2844
DBUG_ENTER("table_or_sp_used");
2846
if (sroutines.records || query_tables)
2854
Do end-of-prepare fixup for list of tables and their merge-VIEWed tables
2857
fix_prepare_info_in_table_list()
2859
tbl List of tables to process
2862
Perform end-end-of prepare fixup for list of tables, if any of the tables
2863
is a merge-algorithm VIEW, recursively fix up its underlying tables as
2868
static void fix_prepare_info_in_table_list(THD *thd, TABLE_LIST *tbl)
2870
for (; tbl; tbl= tbl->next_local)
2874
tbl->prep_on_expr= tbl->on_expr;
2875
tbl->on_expr= tbl->on_expr->copy_andor_structure(thd);
2877
fix_prepare_info_in_table_list(thd, tbl->merge_underlying_list);
2883
Save WHERE/HAVING/ON clauses and replace them with disposable copies
2886
st_select_lex::fix_prepare_information
2888
conds in/out pointer to WHERE condition to be met at execution
2889
having_conds in/out pointer to HAVING condition to be met at execution
2892
The passed WHERE and HAVING are to be saved for the future executions.
2893
This function saves it, and returns a copy which can be thrashed during
2894
this execution of the statement. By saving/thrashing here we mean only
2896
The function also calls fix_prepare_info_in_table_list that saves all
2900
void st_select_lex::fix_prepare_information(THD *thd, Item **conds,
2901
Item **having_conds)
2903
if (!thd->stmt_arena->is_conventional() && first_execution)
2909
*conds= where= prep_where->copy_andor_structure(thd);
2913
prep_having= *having_conds;
2914
*having_conds= having= prep_having->copy_andor_structure(thd);
2916
fix_prepare_info_in_table_list(thd, (TABLE_LIST *)table_list.first);
2922
There are st_select_lex::add_table_to_list &
2923
st_select_lex::set_lock_for_tables are in sql_parse.cc
2925
st_select_lex::print is in sql_select.cc
2927
st_select_lex_unit::prepare, st_select_lex_unit::exec,
2928
st_select_lex_unit::cleanup, st_select_lex_unit::reinit_exec_mechanism,
2929
st_select_lex_unit::change_result
2934
Sets the kind of hints to be added by the calls to add_index_hint().
2937
set_index_hint_type()
2938
type_arg The kind of hints to be added from now on.
2939
clause The clause to use for hints to be added from now on.
2942
Used in filling up the tagged hints list.
2943
This list is filled by first setting the kind of the hint as a
2944
context variable and then adding hints of the current kind.
2945
Then the context variable index_hint_type can be reset to the
2948
void st_select_lex::set_index_hint_type(enum index_hint_type type_arg,
2949
index_clause_map clause)
2951
current_index_hint_type= type_arg;
2952
current_index_hint_clause= clause;
2957
Makes an array to store index usage hints (ADD/FORCE/IGNORE INDEX).
2964
void st_select_lex::alloc_index_hints (THD *thd)
2966
index_hints= new (thd->mem_root) List<Index_hint>();
2972
adds an element to the array storing index usage hints
2973
(ADD/FORCE/IGNORE INDEX).
2978
str name of the index.
2979
length number of characters in str.
2982
0 on success, non-zero otherwise
2984
bool st_select_lex::add_index_hint (THD *thd, char *str, uint length)
2986
return index_hints->push_front (new (thd->mem_root)
2987
Index_hint(current_index_hint_type,
2988
current_index_hint_clause,
2993
A routine used by the parser to decide whether we are specifying a full
2994
partitioning or if only partitions to add or to split.
2996
@note This needs to be outside of WITH_PARTITION_STORAGE_ENGINE since it
2997
is used from the sql parser that doesn't have any ifdef's
2999
@retval TRUE Yes, it is part of a management partition command
3000
@retval FALSE No, not a management partition command
3003
bool st_lex::is_partition_management() const
3005
return (sql_command == SQLCOM_ALTER_TABLE &&
3006
(alter_info.flags == ALTER_ADD_PARTITION ||
3007
alter_info.flags == ALTER_REORGANIZE_PARTITION));