diff options
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r-- | sql/sql_lex.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 674d9302c72..86e677cc8dc 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -118,8 +118,11 @@ void lex_start(THD *thd, uchar *buf,uint length) lex->buf= lex->ptr= buf; lex->end_of_query= buf+length; + lex->context_stack.empty(); lex->unit.init_query(); lex->unit.init_select(); + /* 'parent_lex' is used in init_query() so it must be before it. */ + lex->select_lex.parent_lex= lex; lex->select_lex.init_query(); lex->value_list.empty(); lex->update_list.empty(); @@ -148,7 +151,6 @@ void lex_start(THD *thd, uchar *buf,uint length) lex->leaf_tables_insert= lex->query_tables= 0; lex->query_tables_last= &lex->query_tables; lex->variables_used= 0; - lex->select_lex.parent_lex= lex; lex->empty_field_list_on_rset= 0; lex->select_lex.select_number= 1; lex->next_state=MY_LEX_START; @@ -1114,6 +1116,11 @@ void st_select_lex::init_query() having_fix_field= 0; context.select_lex= this; context.init(); + /* + Add the name resolution context of the current (sub)query to the + stack of contexts for the whole query. + */ + parent_lex->push_context(&context); cond_count= with_wild= 0; conds_processed_with_permanent_arena= 0; ref_pointer_array= 0; @@ -1130,7 +1137,7 @@ void st_select_lex::init_select() { st_select_lex_node::init_select(); group_list.empty(); - type= db= db1= table1= db2= table2= 0; + type= db= 0; having= 0; use_index_ptr= ignore_index_ptr= 0; table_join_options= 0; @@ -1860,8 +1867,9 @@ TABLE_LIST *st_lex::unlink_first_table(bool *link_to_local) */ if ((*link_to_local= test(select_lex.table_list.first))) { - select_lex.table_list.first= (byte*) (select_lex.context.table_list= - first->next_local); + select_lex.context.table_list= first->next_local; + select_lex.context.first_name_resolution_table= first->next_local; + select_lex.table_list.first= (byte*) (first->next_local); select_lex.table_list.elements--; //safety first->next_local= 0; /* @@ -1966,8 +1974,8 @@ void st_lex::link_first_table_back(TABLE_LIST *first, if (link_to_local) { first->next_local= (TABLE_LIST*) select_lex.table_list.first; - select_lex.table_list.first= - (byte*) (select_lex.context.table_list= first); + select_lex.context.table_list= first; + select_lex.table_list.first= (byte*) first; select_lex.table_list.elements++; //safety } } |