diff options
author | timour@mysql.com <> | 2005-08-12 17:57:19 +0300 |
---|---|---|
committer | timour@mysql.com <> | 2005-08-12 17:57:19 +0300 |
commit | a247282aa6270e809f4ad3f5205dc79ca7be8ec0 (patch) | |
tree | 98cc5c366d6eaba9f415323933356e53cf8d3a92 /sql/sql_lex.cc | |
parent | 2889025accafd9f7a5c7b2788b9e34f31dc257e4 (diff) | |
download | mariadb-git-a247282aa6270e809f4ad3f5205dc79ca7be8ec0.tar.gz |
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
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 ccc0236997f..70b3e9e7427 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 } } |