diff options
author | gkodinov/kgeorge@macbook.gmz <> | 2007-02-19 14:39:37 +0200 |
---|---|---|
committer | gkodinov/kgeorge@macbook.gmz <> | 2007-02-19 14:39:37 +0200 |
commit | d17ad7b3a40e23d08bc8398dda5d784cbb988b59 (patch) | |
tree | cf74708b8339ba17919b8f5210fe226d74f16433 /sql/sql_prepare.cc | |
parent | 4908cf0772166d3b93297601265ba52f34bca7f2 (diff) | |
download | mariadb-git-d17ad7b3a40e23d08bc8398dda5d784cbb988b59.tar.gz |
Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
Several problems fixed:
1. There was a "catch-all" context initialization in setup_tables()
that was causing the table that we insert into to be visible in the
SELECT part of an INSERT .. SELECT .. statement with no tables in
its FROM clause. This was making sure all the under-initialized
contexts in various parts of the code are not left uninitialized.
Fixed by removing the "catch-all" statement and initializing the
context in the parser.
2. Incomplete name resolution context when resolving the right-hand
values in the ON DUPLICATE KEY UPDATE ... part of an INSERT ... SELECT ...
caused columns from NATURAL JOIN/JOIN USING table references in the
FROM clause of the select to be unavailable.
Fixed by establishing a proper name resolution context.
3. When setting up the special name resolution context for problem 2
there was no check for cases where an aggregate function without a
GROUP BY effectively takes the column from the SELECT part of an
INSERT ... SELECT unavailable for ON DUPLICATE KEY UPDATE.
Fixed by checking for that condition when setting up the name
resolution context.
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r-- | sql/sql_prepare.cc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 002b1d52331..3b46d613c93 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1571,21 +1571,16 @@ error: static bool mysql_insert_select_prepare_tester(THD *thd) { - TABLE_LIST *first; - bool res; SELECT_LEX *first_select= &thd->lex->select_lex; + TABLE_LIST *second_table= ((TABLE_LIST*)first_select->table_list.first)-> + next_local; + /* Skip first table, which is the table we are inserting in */ - first_select->table_list.first= (byte*)(first= - ((TABLE_LIST*)first_select-> - table_list.first)->next_local); - res= mysql_insert_select_prepare(thd); - /* - insert/replace from SELECT give its SELECT_LEX for SELECT, - and item_list belong to SELECT - */ - thd->lex->select_lex.context.resolve_in_select_list= TRUE; - thd->lex->select_lex.context.table_list= first; - return res; + first_select->table_list.first= (byte *) second_table; + thd->lex->select_lex.context.table_list= + thd->lex->select_lex.context.first_name_resolution_table= second_table; + + return mysql_insert_select_prepare(thd); } |