mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Bug #15355: Common natural join column not resolved in prepared statement nested
query Problem: There was a wrong context assigned to the columns that were added in insert_fields() when expanding a '*'. When this is done in a prepared statement it causes fix_fields() to fail to find the table that these columns reference. Actually the right context is set in setup_natural_join_row_types() called at the end of setup_tables(). However when executed in a context of a prepared statement setup_tables() resets the context, but setup_natural_join_row_types() was not setting it to the correct value assuming it has already done so. Solution: The top-most, left-most NATURAL/USING join must be set as a first_name_resolution_table in context even when operating on prepared statements. mysql-test/r/join.result: testsuite for the bug mysql-test/t/join.test: testsuite for the bug sql/sql_base.cc: The context must be set even when executed as prepared statement.
This commit is contained in:
@ -4184,10 +4184,6 @@ static bool setup_natural_join_row_types(THD *thd,
|
||||
if (from_clause->elements == 0)
|
||||
return FALSE; /* We come here in the case of UNIONs. */
|
||||
|
||||
/* For stored procedures do not redo work if already done. */
|
||||
if (!context->select_lex->first_execution)
|
||||
return FALSE;
|
||||
|
||||
List_iterator_fast<TABLE_LIST> table_ref_it(*from_clause);
|
||||
TABLE_LIST *table_ref; /* Current table reference. */
|
||||
/* Table reference to the left of the current. */
|
||||
@ -4200,14 +4196,18 @@ static bool setup_natural_join_row_types(THD *thd,
|
||||
{
|
||||
table_ref= left_neighbor;
|
||||
left_neighbor= table_ref_it++;
|
||||
if (store_top_level_join_columns(thd, table_ref,
|
||||
left_neighbor, right_neighbor))
|
||||
return TRUE;
|
||||
if (left_neighbor)
|
||||
/* For stored procedures do not redo work if already done. */
|
||||
if (context->select_lex->first_execution)
|
||||
{
|
||||
TABLE_LIST *first_leaf_on_the_right;
|
||||
first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
|
||||
left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
|
||||
if (store_top_level_join_columns(thd, table_ref,
|
||||
left_neighbor, right_neighbor))
|
||||
return TRUE;
|
||||
if (left_neighbor)
|
||||
{
|
||||
TABLE_LIST *first_leaf_on_the_right;
|
||||
first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
|
||||
left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
|
||||
}
|
||||
}
|
||||
right_neighbor= table_ref;
|
||||
}
|
||||
|
Reference in New Issue
Block a user