Commit fb018850 authored by Michael Widenius's avatar Michael Widenius Committed by Sergei Golubchik

Fixed that setup_natural_join_row_types can safely be called twice

sql/item.h:
  Added cache for setup_natural_join_row_types
sql/sql_base.cc:
  Cache old value of first_name_resolution_table for next call.
  (It's not safe to try to recalculate the value as the join structure may have been changed by the optimizer)
parent 6e699eb4
......@@ -332,6 +332,8 @@ struct Name_resolution_context: Sql_alloc
*/
TABLE_LIST *last_name_resolution_table;
/* Cache first_name_resolution_table in setup_natural_join_row_types */
TABLE_LIST *natural_join_first_table;
/*
SELECT_LEX item belong to, in case of merged VIEW it can differ from
SELECT_LEX where item was created, so we can't use table_list/field_list
......
......@@ -7925,6 +7925,11 @@ err:
order, thus when we iterate over it, we are moving from the right
to the left in the FROM clause.
NOTES
We can't run this many times as the first_name_resolution_table would
be different for subsequent runs when sub queries has been optimized
away.
RETURN
TRUE Error
FALSE OK
......@@ -7946,7 +7951,8 @@ static bool setup_natural_join_row_types(THD *thd,
*/
if (!context->select_lex->first_natural_join_processing)
{
DBUG_PRINT("info", ("using cached store_top_level_join_columns"));
context->first_name_resolution_table= context->natural_join_first_table;
DBUG_PRINT("info", ("using cached setup_natural_join_row_types"));
DBUG_RETURN(false);
}
context->select_lex->first_natural_join_processing= false;
......@@ -7989,6 +7995,11 @@ static bool setup_natural_join_row_types(THD *thd,
DBUG_ASSERT(right_neighbor);
context->first_name_resolution_table=
right_neighbor->first_leaf_for_name_resolution();
/*
This is only to ensure that first_name_resolution_table doesn't
change on re-execution
*/
context->natural_join_first_table= context->first_name_resolution_table;
DBUG_RETURN (false);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment