26#include <drizzled/sql_reserved_words.h>
28#include <drizzled/configmake.h>
29#include <drizzled/item/num.h>
30#include <drizzled/error.h>
31#include <drizzled/session.h>
32#include <drizzled/sql_base.h>
33#include <drizzled/lookup_symbol.h>
35#include <drizzled/select_result.h>
36#include <drizzled/item/subselect.h>
37#include <drizzled/statement.h>
38#include <drizzled/sql_lex.h>
39#include <drizzled/plugin.h>
40#include <drizzled/lex_input_stream.h>
45#include <drizzled/message/alter_table.pb.h>
56static int lex_one_token(ParserType *arg, drizzled::Session *yysession);
64 order->item_ptr= item;
65 order->item= &order->item_ptr;
69 order->counter_used= 0;
70 list.link_in_list((
unsigned char*) order, (
unsigned char**) &order->next);
73Lex_input_stream::Lex_input_stream(Session& session, str_ref buffer) :
78 lookahead_token(END_OF_INPUT),
79 lookahead_yylval(NULL),
83 m_end_of_query(buffer.end()),
84 m_tok_start_prev(NULL),
86 m_buf_length(buffer.size()),
88 m_cpp_tok_start(NULL),
89 m_cpp_tok_start_prev(NULL),
92 m_cpp_utf8_processed_ptr(NULL),
93 next_state(MY_LEX_START),
95 in_comment(NO_COMMENT)
97 m_cpp_buf= (
char*) session.mem.alloc(buffer.size() + 1);
188void lex_start(Session *session)
190 LEX *lex= &session->lex();
192 lex->session= lex->unit.session= session;
194 lex->context_stack.clear();
195 lex->unit.init_query();
196 lex->unit.init_select();
198 lex->select_lex.parent_lex= lex;
199 lex->select_lex.init_query();
200 lex->value_list.clear();
201 lex->update_list.clear();
202 lex->auxiliary_table_list.clear();
203 lex->unit.next= lex->unit.master=
204 lex->unit.link_next= lex->unit.return_to= 0;
205 lex->unit.prev= lex->unit.link_prev= 0;
206 lex->unit.slave= lex->unit.global_parameters= lex->current_select=
207 lex->all_selects_list= &lex->select_lex;
208 lex->select_lex.master= &lex->unit;
209 lex->select_lex.prev= &lex->unit.slave;
210 lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
211 lex->select_lex.link_prev= (Select_Lex_Node**)&(lex->all_selects_list);
212 lex->select_lex.options= 0;
213 lex->select_lex.init_order();
214 lex->select_lex.group_list.clear();
216 lex->derived_tables= 0;
217 lex->lock_option= TL_READ;
218 lex->leaf_tables_insert= 0;
219 lex->var_list.clear();
220 lex->select_lex.select_number= 1;
222 lex->select_lex.in_sum_expr=0;
223 lex->select_lex.group_list.clear();
224 lex->select_lex.order_list.clear();
225 lex->sql_command= SQLCOM_END;
226 lex->duplicates= DUP_ERROR;
228 lex->escape_used=
false;
229 lex->query_tables= 0;
230 lex->reset_query_tables_list(
false);
231 lex->expr_allows_subselect=
true;
232 lex->use_only_table_context=
false;
234 lex->name.assign(NULL, 0);
236 lex->allow_sum_func= 0;
237 lex->in_sum_func= NULL;
240 lex->is_lex_started=
true;
241 lex->statement= NULL;
243 lex->is_cross=
false;
258 safe_delete(_create_table);
259 safe_delete(_alter_table);
267 safe_delete(statement);
270static int find_keyword(Lex_input_stream *lip, uint32_t len,
bool function)
274 const char *tok= lip->get_tok_start();
276 for (;tok_pos<len && tok_pos<63;tok_pos++)
277 tok_upper[tok_pos]= system_charset_info->toupper(tok[tok_pos]);
278 tok_upper[tok_pos]=0;
280 const SYMBOL *symbol= lookup_symbol(tok_upper, len, function);
283 lip->yylval->symbol.symbol=symbol;
284 lip->yylval->symbol.str= (
char*) tok;
285 lip->yylval->symbol.length=len;
294static lex_string_t get_token(Lex_input_stream *lip, uint32_t skip, uint32_t length)
297 lip->yytoklen= length;
299 tmp.assign(lip->m_session->mem.strdup(lip->get_tok_start() + skip, length), length);
300 lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
301 lip->m_cpp_text_end= lip->m_cpp_text_start + tmp.size();
311static lex_string_t get_quoted_token(Lex_input_stream *lip,
313 uint32_t length,
char quote)
316 lip->yytoklen= length;
318 tmp.assign((
char*)lip->m_session->mem.alloc(length + 1), length);
319 const char* from= lip->get_tok_start() + skip;
320 char* to= (
char*)tmp.data();
321 const char* end= to+length;
323 lip->m_cpp_text_start= lip->get_cpp_tok_start() + skip;
324 lip->m_cpp_text_end= lip->m_cpp_text_start + length;
328 if ((*to++= *from++) == quote)
331 lip->m_cpp_text_start++;
343static char *get_text(Lex_input_stream *lip,
int pre_skip,
int post_skip)
345 bool found_escape=
false;
346 const charset_info_st*
const cs= lip->m_session->charset();
349 unsigned char sep= lip->yyGetLast();
350 while (not lip->eof())
352 unsigned char c= lip->yyGet();
357 int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
360 lip->skip_binary(l-1);
374 if (c == lip->yyGet())
383 const char* str= lip->get_tok_start();
384 const char* end= lip->get_ptr();
390 char* start= (
char*) lip->m_session->mem.alloc((uint32_t) (end-str)+1);
392 lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
393 lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;
397 lip->yytoklen= (uint32_t) (end-str);
398 memcpy(start, str, lip->yytoklen);
399 start[lip->yytoklen]= 0;
405 for (to= start; str != end; str++)
409 int l= my_ismbchar(cs, str, end);
418 if (*str ==
'\\' && (str + 1) != end)
448 else if (*str == sep)
454 lip->yytoklen= (uint32_t) (to - start);
471static const char *long_str=
"2147483647";
472static const uint32_t long_len= 10;
473static const char *signed_long_str=
"-2147483648";
474static const char *int64_t_str=
"9223372036854775807";
475static const uint32_t int64_t_len= 19;
476static const char *signed_int64_t_str=
"-9223372036854775808";
477static const uint32_t signed_int64_t_len= 19;
478static const char *unsigned_int64_t_str=
"18446744073709551615";
479static const uint32_t unsigned_int64_t_len= 20;
481static inline uint32_t int_token(
const char *str,uint32_t length)
483 if (length < long_len)
491 else if (*str ==
'-')
496 while (*str ==
'0' && length)
500 if (length < long_len)
503 uint32_t smaller,bigger;
507 if (length == long_len)
509 cmp= signed_long_str+1;
513 else if (length < signed_int64_t_len)
515 else if (length > signed_int64_t_len)
519 cmp=signed_int64_t_str+1;
526 if (length == long_len)
532 else if (length < int64_t_len)
534 else if (length > int64_t_len)
536 if (length > unsigned_int64_t_len)
538 cmp=unsigned_int64_t_str;
539 smaller=ULONGLONG_NUM;
546 bigger= ULONGLONG_NUM;
549 while (*cmp && *cmp++ == *str++) ;
550 return ((
unsigned char) str[-1] <= (
unsigned char) cmp[-1]) ? smaller : bigger;
579 token= drizzled::lex_one_token(yylval, session);
590 token= drizzled::lex_one_token(yylval, session);
591 if (token == ROLLUP_SYM)
593 return WITH_ROLLUP_SYM;
615int lex_one_token(ParserType *yylval, drizzled::Session *session)
619 int tokval, result_state;
621 enum my_lex_states state;
623 LEX *lex= &session->lex();
625 unsigned char *state_map= cs->state_map;
626 unsigned char *ident_map= cs->ident_map;
631 state=lip->next_state;
632 lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
636 case MY_LEX_OPERATOR_OR_IDENT:
639 while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
648 lip->restart_token();
650 state= (
enum my_lex_states) state_map[c];
653 if (lip->yyGet() ==
'N')
655 yylval->lex_str.assign(
"\\N", 2);
661 if (c ==
'-' && lip->yyPeek() ==
'-' &&
662 (cs->isspace(lip->yyPeekn(1)) ||
663 cs->iscntrl(lip->yyPeekn(1))))
665 state=MY_LEX_COMMENT;
670 lip->next_state= MY_LEX_START;
683 lip->restart_token();
688 case MY_LEX_IDENT_OR_HEX:
689 if (lip->yyPeek() ==
'\'')
691 state= MY_LEX_HEX_NUMBER;
695 case MY_LEX_IDENT_OR_BIN:
696 if (lip->yyPeek() ==
'\'')
698 state= MY_LEX_BIN_NUMBER;
706 result_state= IDENT_QUOTED;
707 if (my_mbcharlen(cs, lip->yyGetLast()) > 1)
709 int l = my_ismbchar(cs,
711 lip->get_end_of_query());
716 lip->skip_binary(l - 1);
718 while (ident_map[c=lip->yyGet()])
720 if (my_mbcharlen(cs, c) > 1)
722 int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
725 lip->skip_binary(l-1);
731 for (result_state= c; ident_map[c= lip->yyGet()]; result_state|= c) {};
733 result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
735 length= lip->yyLength();
736 start= lip->get_ptr();
737 if (lip->ignore_space)
743 for (; state_map[c] == MY_LEX_SKIP ; c= lip->yyGet()) {};
745 if (start == lip->get_ptr() && c ==
'.' && ident_map[(uint8_t)lip->yyPeek()])
746 lip->next_state=MY_LEX_IDENT_SEP;
750 if ((tokval = find_keyword(lip, length, c ==
'(')))
752 lip->next_state= MY_LEX_START;
757 yylval->lex_str= get_token(lip, 0, length);
759 lip->body_utf8_append(lip->m_cpp_text_start);
761 lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
763 return(result_state);
765 case MY_LEX_IDENT_SEP:
766 yylval->lex_str.assign(lip->get_ptr(), 1);
768 lip->next_state= MY_LEX_IDENT_START;
769 if (!ident_map[(uint8_t)lip->yyPeek()])
770 lip->next_state= MY_LEX_START;
773 case MY_LEX_NUMBER_IDENT:
774 if (lip->yyGetLast() ==
'0')
779 while (cs->isxdigit((c = lip->yyGet()))) ;
780 if ((lip->yyLength() >= 3) && !ident_map[c])
783 yylval->lex_str= get_token(lip, 2, lip->yyLength()-2);
787 state= MY_LEX_IDENT_START;
792 while ((c= lip->yyGet()) ==
'0' || c ==
'1') {};
793 if ((lip->yyLength() >= 3) && !ident_map[c])
796 yylval->lex_str= get_token(lip, 2, lip->yyLength()-2);
800 state= MY_LEX_IDENT_START;
806 while (cs->isdigit((c = lip->yyGet()))) ;
809 state=MY_LEX_INT_OR_REAL;
812 if (c ==
'e' || c ==
'E')
815 if (cs->isdigit(lip->yyPeek()) ||
816 (c=(lip->yyGet())) ==
'+' || c ==
'-')
818 if (cs->isdigit(lip->yyPeek()))
821 while (cs->isdigit(lip->yyGet())) ;
822 yylval->lex_str= get_token(lip, 0, lip->yyLength());
829 case MY_LEX_IDENT_START:
833 result_state= IDENT_QUOTED;
834 while (ident_map[c=lip->yyGet()])
836 if (my_mbcharlen(cs, c) > 1)
838 int l= my_ismbchar(cs, lip->get_ptr() -1, lip->get_end_of_query());
841 lip->skip_binary(l-1);
847 for (result_state=0; ident_map[c= lip->yyGet()]; result_state|= c) {};
849 result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
851 if (c ==
'.' && ident_map[(uint8_t)lip->yyPeek()])
852 lip->next_state=MY_LEX_IDENT_SEP;
854 yylval->lex_str= get_token(lip, 0, lip->yyLength());
856 lip->body_utf8_append(lip->m_cpp_text_start);
857 lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
859 return(result_state);
861 case MY_LEX_USER_VARIABLE_DELIMITER:
863 uint32_t double_quotes= 0;
865 while ((c=lip->yyGet()))
868 if ((var_length= my_mbcharlen(cs, c)) == 1)
872 if (lip->yyPeek() != quote_char)
879 else if (var_length < 1)
881 lip->skip_binary(var_length-1);
883 yylval->lex_str= double_quotes
884 ? get_quoted_token(lip, 1, lip->yyLength() - double_quotes - 1, quote_char)
885 : get_token(lip, 1, lip->yyLength() - 1);
888 lip->next_state= MY_LEX_START;
889 lip->body_utf8_append(lip->m_cpp_text_start);
890 lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
893 case MY_LEX_INT_OR_REAL:
896 yylval->lex_str=get_token(lip, 0, lip->yyLength());
897 return int_token(yylval->lex_str.data(), yylval->lex_str.size());
901 while (cs->isdigit(c = lip->yyGet())) ;
903 if (c ==
'e' || c ==
'E')
906 if (c ==
'-' || c ==
'+')
913 while (cs->isdigit(lip->yyGet())) ;
914 yylval->lex_str=get_token(lip, 0, lip->yyLength());
917 yylval->lex_str=get_token(lip, 0, lip->yyLength());
920 case MY_LEX_HEX_NUMBER:
922 while (cs->isxdigit((c= lip->yyGet()))) ;
926 length= lip->yyLength();
929 yylval->lex_str=get_token(lip,
934 case MY_LEX_BIN_NUMBER:
936 while ((c= lip->yyGet()) ==
'0' || c ==
'1') {};
940 length= lip->yyLength();
941 yylval->lex_str= get_token(lip,
947 if (state_map[(uint8_t)lip->yyPeek()] == MY_LEX_CMP_OP ||
948 state_map[(uint8_t)lip->yyPeek()] == MY_LEX_LONG_CMP_OP)
950 if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
952 lip->next_state= MY_LEX_START;
958 case MY_LEX_LONG_CMP_OP:
959 if (state_map[(uint8_t)lip->yyPeek()] == MY_LEX_CMP_OP ||
960 state_map[(uint8_t)lip->yyPeek()] == MY_LEX_LONG_CMP_OP)
963 if (state_map[(uint8_t)lip->yyPeek()] == MY_LEX_CMP_OP)
966 if ((tokval = find_keyword(lip, lip->yyLength() + 1, 0)))
968 lip->next_state= MY_LEX_START;
975 if (c != lip->yyPeek())
981 tokval = find_keyword(lip,2,0);
982 lip->next_state= MY_LEX_START;
985 case MY_LEX_STRING_OR_DELIMITER:
988 state= MY_LEX_USER_VARIABLE_DELIMITER;
994 if (!(yylval->lex_str.str_ = get_text(lip, 1, 1)))
999 yylval->lex_str.assign(yylval->lex_str.data(), lip->yytoklen);
1001 lip->body_utf8_append(lip->m_cpp_text_start);
1002 lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
1004 lex->text_string_is_7bit= (lip->tok_bitmap & 0x80) ? 0 : 1;
1005 return(TEXT_STRING);
1007 case MY_LEX_COMMENT:
1008 lex->select_lex.options|= OPTION_FOUND_COMMENT;
1009 while ((c = lip->yyGet()) !=
'\n' && c) ;
1011 state = MY_LEX_START;
1014 case MY_LEX_LONG_COMMENT:
1015 if (lip->yyPeek() !=
'*')
1020 lex->select_lex.options|= OPTION_FOUND_COMMENT;
1024 if (lip->yyPeekn(2) ==
'!')
1026 lip->in_comment= DISCARD_COMMENT;
1028 lip->set_echo(
false);
1038 const int MAX_VERSION_SIZE= 16;
1039 char version_str[MAX_VERSION_SIZE];
1044 version_str[pos]= lip->yyPeekn(pos);
1046 }
while ((pos < MAX_VERSION_SIZE-1) && isdigit(version_str[pos-1]));
1047 version_str[pos]= 0;
1053 version=strtoll(version_str, NULL, 10);
1056 lip->yySkipn(pos-1);
1058 if (version <= DRIZZLE_VERSION_ID)
1061 lip->set_echo(
true);
1069 lip->set_echo(
true);
1075 lip->in_comment= PRESERVE_COMMENT;
1087 comment_closed=
false;
1088 while (! lip->eof())
1093 if (lip->yyPeek() ==
'/')
1096 comment_closed=
true;
1097 state = MY_LEX_START;
1105 if (! comment_closed)
1107 state = MY_LEX_START;
1108 lip->in_comment= NO_COMMENT;
1109 lip->set_echo(
true);
1112 case MY_LEX_END_LONG_COMMENT:
1113 if ((lip->in_comment != NO_COMMENT) && lip->yyPeek() ==
'/')
1118 lip->set_echo(lip->in_comment == PRESERVE_COMMENT);
1121 lip->set_echo(
true);
1122 lip->in_comment=NO_COMMENT;
1129 case MY_LEX_SET_VAR:
1130 if (lip->yyPeek() !=
'=')
1138 case MY_LEX_SEMICOLON:
1144 lip->next_state=MY_LEX_END;
1145 return(END_OF_INPUT);
1151 lip->set_echo(
false);
1153 lip->set_echo(
true);
1155 if (lip->in_comment != NO_COMMENT)
1157 lip->next_state=MY_LEX_END;
1158 return(END_OF_INPUT);
1164 lip->next_state=MY_LEX_END;
1169 case MY_LEX_REAL_OR_POINT:
1170 if (cs->isdigit(lip->yyPeek()))
1174 state= MY_LEX_IDENT_SEP;
1179 case MY_LEX_USER_END:
1180 switch (state_map[(uint8_t)lip->yyPeek()]) {
1182 case MY_LEX_USER_VARIABLE_DELIMITER:
1183 case MY_LEX_STRING_OR_DELIMITER:
1185 case MY_LEX_USER_END:
1186 lip->next_state=MY_LEX_SYSTEM_VAR;
1189 lip->next_state=MY_LEX_HOSTNAME;
1192 yylval->lex_str.assign(lip->get_ptr(), 1);
1195 case MY_LEX_HOSTNAME:
1196 for (c=lip->yyGet() ;
1197 cs->isalnum(c) || c ==
'.' || c ==
'_' || c ==
'$';
1199 yylval->lex_str=get_token(lip, 0, lip->yyLength());
1200 return(LEX_HOSTNAME);
1202 case MY_LEX_SYSTEM_VAR:
1203 yylval->lex_str.assign(lip->get_ptr(), 1);
1205 lip->next_state= (state_map[(uint8_t)lip->yyPeek()] ==
1206 MY_LEX_USER_VARIABLE_DELIMITER ?
1207 MY_LEX_OPERATOR_OR_IDENT :
1208 MY_LEX_IDENT_OR_KEYWORD);
1211 case MY_LEX_IDENT_OR_KEYWORD:
1218 for (result_state= 0; ident_map[c= lip->yyGet()]; result_state|= c) {};
1220 result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
1223 lip->next_state=MY_LEX_IDENT_SEP;
1225 length= lip->yyLength();
1229 if ((tokval= find_keyword(lip, length,0)))
1234 yylval->lex_str=get_token(lip, 0, length);
1236 lip->body_utf8_append(lip->m_cpp_text_start);
1237 lip->body_utf8_append_literal(yylval->lex_str, lip->m_cpp_text_end);
1239 return result_state;
1247void Select_Lex_Node::init_query()
1250 linkage= UNSPECIFIED_TYPE;
1251 no_error= no_table_names_allowed= 0;
1252 uncacheable.reset();
1255void Select_Lex_Node::init_select()
1259void Select_Lex_Unit::init_query()
1261 Select_Lex_Node::init_query();
1262 linkage= GLOBAL_OPTIONS_TYPE;
1263 global_parameters= first_select();
1264 select_limit_cnt= HA_POS_ERROR;
1265 offset_limit_cnt= 0;
1267 prepared= optimized= executed= 0;
1275 found_rows_for_union= 0;
1278void Select_Lex::init_query()
1280 Select_Lex_Node::init_query();
1282 top_join_list.clear();
1283 join_list= &top_join_list;
1284 embedding= leaf_tables= 0;
1288 olap= UNSPECIFIED_OLAP_TYPE;
1289 having_fix_field= 0;
1290 context.select_lex=
this;
1301 parent_lex->push_context(&context);
1302 cond_count= between_count= with_wild= 0;
1304 ref_pointer_array= 0;
1305 select_n_where_fields= 0;
1306 select_n_having_items= 0;
1307 subquery_in_having= explicit_limit= 0;
1308 is_item_list_lookup= 0;
1309 parsing_place= NO_MATTER;
1310 exclude_from_table_unique_test=
false;
1315void Select_Lex::init_select()
1321 in_sum_expr= with_wild= 0;
1324 interval_list.clear();
1325 inner_sum_func_list= 0;
1326 linkage= UNSPECIFIED_TYPE;
1327 order_list.elements= 0;
1328 order_list.first= 0;
1329 order_list.next= (
unsigned char**) &order_list.first;
1336 cur_pos_in_select_list= UNDEF_POS;
1337 non_agg_fields.clear();
1338 cond_value= having_value= Item::COND_UNDEF;
1339 inner_refs_list.clear();
1340 full_group_by_flag.reset();
1348void Select_Lex_Node::include_down(Select_Lex_Node *upper)
1350 if ((next= upper->slave))
1352 prev= &upper->slave;
1366void Select_Lex_Node::include_standalone(Select_Lex_Node *upper,
1367 Select_Lex_Node **ref)
1376void Select_Lex_Node::include_neighbour(Select_Lex_Node *before)
1378 if ((next= before->next))
1380 prev= &before->next;
1382 master= before->master;
1387void Select_Lex_Node::include_global(Select_Lex_Node **plink)
1389 if ((link_next= *plink))
1390 link_next->link_prev= &link_next;
1396void Select_Lex_Node::fast_exclude()
1400 if ((*link_prev= link_next))
1401 link_next->link_prev= link_prev;
1404 for (; slave; slave= slave->next)
1405 slave->fast_exclude();
1413void Select_Lex_Node::exclude()
1438void Select_Lex_Unit::exclude_level()
1440 Select_Lex_Unit *units= 0, **units_last= &units;
1441 for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1444 if (sl->link_prev && (*sl->link_prev= sl->link_next))
1445 sl->link_next->link_prev= sl->link_prev;
1448 Select_Lex_Unit **last= 0;
1449 for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
1452 last= (Select_Lex_Unit**)&(u->next);
1456 (*units_last)= sl->first_inner_unit();
1464 (*units_last)= (Select_Lex_Unit*)next;
1466 next->prev= (Select_Lex_Node**)units_last;
1481void Select_Lex_Unit::exclude_tree()
1483 for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1486 if (sl->link_prev && (*sl->link_prev= sl->link_next))
1487 sl->link_next->link_prev= sl->link_prev;
1490 for (Select_Lex_Unit *u= sl->first_inner_unit(); u; u= u->next_unit())
1508void Select_Lex::mark_as_dependent(Select_Lex *last)
1514 for (Select_Lex *s=
this;
1516 s= s->outer_select())
1518 if (! (s->uncacheable.test(UNCACHEABLE_DEPENDENT)))
1521 s->uncacheable.set(UNCACHEABLE_DEPENDENT);
1522 s->uncacheable.set(UNCACHEABLE_UNITED);
1523 Select_Lex_Unit *munit= s->master_unit();
1524 munit->uncacheable.set(UNCACHEABLE_UNITED);
1525 munit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1526 for (Select_Lex *sl= munit->first_select(); sl ; sl= sl->next_select())
1529 ! (sl->uncacheable.test(UNCACHEABLE_DEPENDENT) && sl->uncacheable.test(UNCACHEABLE_UNITED)))
1530 sl->uncacheable.set(UNCACHEABLE_UNITED);
1533 s->is_correlated=
true;
1535 if (subquery_predicate)
1536 subquery_predicate->is_correlated=
true;
1540bool Select_Lex_Node::set_braces(
bool)
1543bool Select_Lex_Node::inc_in_sum_expr()
1546uint32_t Select_Lex_Node::get_in_sum_expr()
1549TableList* Select_Lex_Node::get_table_list()
1558 const bitset<NUM_OF_TABLE_OPTIONS>&,
1570bool Select_Lex::test_limit()
1572 if (select_limit != 0)
1574 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
1575 "LIMIT & IN/ALL/ANY/SOME subquery");
1581Select_Lex_Unit* Select_Lex_Unit::master_unit()
1586Select_Lex* Select_Lex_Unit::outer_select()
1588 return (Select_Lex*) master;
1591void Select_Lex::add_order_to_list(
Session *session,
Item *item,
bool asc)
1596void Select_Lex::add_item_to_list(
Session *,
Item *item)
1598 item_list.push_back(item);
1601void Select_Lex::add_group_to_list(
Session *session,
Item *item,
bool asc)
1606Select_Lex_Unit* Select_Lex::master_unit()
1608 return (Select_Lex_Unit*) master;
1611Select_Lex* Select_Lex::outer_select()
1613 return (Select_Lex*) master->get_master();
1616bool Select_Lex::set_braces(
bool value)
1622bool Select_Lex::inc_in_sum_expr()
1628uint32_t Select_Lex::get_in_sum_expr()
1643void Select_Lex::setup_ref_array(
Session *session, uint32_t order_group_num)
1645 if (not ref_pointer_array)
1646 ref_pointer_array=
new (session->mem)
Item*[5 * (n_child_sum_items + item_list.size() + select_n_having_items + select_n_where_fields + order_group_num)];
1649void Select_Lex_Unit::print(
String *str)
1651 bool union_all= !union_distinct;
1652 for (Select_Lex *sl= first_select(); sl; sl= sl->next_select())
1654 if (sl != first_select())
1656 str->append(STRING_WITH_LEN(
" union "));
1658 str->append(STRING_WITH_LEN(
"all "));
1659 else if (union_distinct == sl)
1664 sl->print(session, str);
1668 if (fake_select_lex == global_parameters)
1670 if (fake_select_lex->order_list.elements)
1672 str->append(STRING_WITH_LEN(
" order by "));
1673 fake_select_lex->print_order(
1675 (
Order *) fake_select_lex->order_list.first);
1677 fake_select_lex->print_limit(session, str);
1681void Select_Lex::print_order(
String *str,
1684 for (; order; order= order->next)
1686 if (order->counter_used)
1689 uint32_t length= snprintf(buffer, 20,
"%d", order->counter);
1690 str->append(buffer, length);
1693 (*order->item)->print(str);
1695 str->append(STRING_WITH_LEN(
" desc"));
1703 Select_Lex_Unit *unit= master_unit();
1706 if (item && unit->global_parameters ==
this)
1708 Item_subselect::subs_type subs_type= item->substype();
1709 if (subs_type == Item_subselect::EXISTS_SUBS ||
1710 subs_type == Item_subselect::IN_SUBS ||
1711 subs_type == Item_subselect::ALL_SUBS)
1713 assert(!item->fixed ||
1718 (((subs_type == Item_subselect::IN_SUBS) &&
1720 Item_in_subselect::MATERIALIZATION) ?
1722 (select_limit->val_int() == 1L) &&
1723 offset_limit == 0));
1729 str->append(STRING_WITH_LEN(
" limit "));
1732 offset_limit->print(str);
1735 select_limit->print(str);
1741 delete _create_table;
1742 delete _alter_table;
1762void Query_tables_list::reset_query_tables_list(
bool init)
1764 if (!init && query_tables)
1769 if (query_tables_last == &table->next_global ||
1770 !(table= table->next_global))
1775 query_tables_last= &query_tables;
1776 query_tables_own_last= 0;
1799 sql_command(SQLCOM_END),
1801 option_type(OPT_DEFAULT),
1804 sum_expr_used(false),
1805 _create_table(NULL),
1807 _create_field(NULL),
1810 reset_query_tables_list(
true);
1820void Select_Lex_Unit::set_limit(Select_Lex *sl)
1822 ha_rows select_limit_val;
1825 val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
1826 select_limit_val= (ha_rows)val;
1831 if (val != (uint64_t)select_limit_val)
1832 select_limit_val= HA_POS_ERROR;
1833 offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
1835 select_limit_cnt= select_limit_val + offset_limit_cnt;
1836 if (select_limit_cnt < select_limit_val)
1837 select_limit_cnt= HA_POS_ERROR;
1858TableList *LEX::unlink_first_table(
bool *link_to_local)
1861 if ((first= query_tables))
1866 if ((query_tables= query_tables->next_global))
1867 query_tables->prev_global= &query_tables;
1869 query_tables_last= &query_tables;
1870 first->next_global= 0;
1875 if ((*link_to_local= test(select_lex.table_list.first)))
1877 select_lex.context.table_list=
1878 select_lex.context.first_name_resolution_table= first->next_local;
1879 select_lex.table_list.first= (
unsigned char*) (first->next_local);
1880 select_lex.table_list.elements--;
1881 first->next_local= 0;
1886 first_lists_tables_same();
1907void LEX::first_lists_tables_same()
1910 if (query_tables != first_table && first_table != 0)
1913 if (query_tables_last == &first_table->next_global)
1914 query_tables_last= first_table->prev_global;
1916 if ((next= *first_table->prev_global= first_table->next_global))
1917 next->prev_global= first_table->prev_global;
1919 first_table->next_global= query_tables;
1925 query_tables->prev_global= &first_table->next_global;
1926 first_table->prev_global= &query_tables;
1927 query_tables= first_table;
1941void LEX::link_first_table_back(
TableList *first,
bool link_to_local)
1945 if ((first->next_global= query_tables))
1946 query_tables->prev_global= &first->next_global;
1948 query_tables_last= &first->next_global;
1949 query_tables= first;
1953 first->next_local= (
TableList*) select_lex.table_list.first;
1954 select_lex.context.table_list= first;
1955 select_lex.table_list.first= (
unsigned char*) first;
1956 select_lex.table_list.elements++;
1972void LEX::cleanup_after_one_table_open()
1982 if (all_selects_list != &select_lex)
1986 for (Select_Lex_Unit *un= select_lex.first_inner_unit();
1988 un= un->next_unit())
1991 all_selects_list= &select_lex;
1993 select_lex.cut_subtree();
2024void Select_Lex::set_index_hint_type(index_hint_type type_arg, index_clause_map clause)
2026 current_index_hint_type= type_arg;
2027 current_index_hint_clause= clause;
2037void Select_Lex::alloc_index_hints (
Session *session)
2055void Select_Lex::add_index_hint(
Session *session,
const char *str)
2057 index_hints->push_front(
new (session->mem_root)
Index_hint(current_index_hint_type, current_index_hint_clause, str));
2060message::AlterTable *LEX::alter_table()
2062 if (not _alter_table)
2063 _alter_table=
new message::AlterTable;
2065 return _alter_table;
TODO: Rename this file - func.h is stupid.
static void add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)