Commit 0fbe91b4 authored by unknown's avatar unknown

MDEV-6251: SIGSEGV in query optimizer (in set_check_materialized with MERGE view)

mysql_derived_merge() made correctly working with views.
parent 285160de
This diff is collapsed.
This diff is collapsed.
...@@ -391,17 +391,13 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) ...@@ -391,17 +391,13 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived)
if (parent_lex->get_free_table_map(&map, &tablenr)) if (parent_lex->get_free_table_map(&map, &tablenr))
{ {
/* There is no enough table bits, fall back to materialization. */ /* There is no enough table bits, fall back to materialization. */
derived->change_refs_to_fields(); goto unconditional_materialization;
derived->set_materialized_derived();
goto exit_merge;
} }
if (dt_select->leaf_tables.elements + tablenr > MAX_TABLES) if (dt_select->leaf_tables.elements + tablenr > MAX_TABLES)
{ {
/* There is no enough table bits, fall back to materialization. */ /* There is no enough table bits, fall back to materialization. */
derived->change_refs_to_fields(); goto unconditional_materialization;
derived->set_materialized_derived();
goto exit_merge;
} }
if (dt_select->options & OPTION_SCHEMA_TABLE) if (dt_select->options & OPTION_SCHEMA_TABLE)
...@@ -472,6 +468,15 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) ...@@ -472,6 +468,15 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived)
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
DBUG_RETURN(res); DBUG_RETURN(res);
unconditional_materialization:
derived->change_refs_to_fields();
derived->set_materialized_derived();
if (!derived->table || !derived->table->created)
res= mysql_derived_create(thd, lex, derived);
if (!res)
res= mysql_derived_fill(thd, lex, derived);
goto exit_merge;
} }
......
...@@ -4441,6 +4441,10 @@ void TABLE_LIST::set_check_merged() ...@@ -4441,6 +4441,10 @@ void TABLE_LIST::set_check_merged()
void TABLE_LIST::set_check_materialized() void TABLE_LIST::set_check_materialized()
{ {
DBUG_ENTER("TABLE_LIST::set_check_materialized");
SELECT_LEX_UNIT *derived= this->derived;
if (view)
derived= &view->unit;
DBUG_ASSERT(derived); DBUG_ASSERT(derived);
if (!derived->first_select()->exclude_from_table_unique_test) if (!derived->first_select()->exclude_from_table_unique_test)
derived->set_unique_exclude(); derived->set_unique_exclude();
...@@ -4453,6 +4457,7 @@ void TABLE_LIST::set_check_materialized() ...@@ -4453,6 +4457,7 @@ void TABLE_LIST::set_check_materialized()
derived->first_select()->first_inner_unit()->first_select()-> derived->first_select()->first_inner_unit()->first_select()->
exclude_from_table_unique_test); exclude_from_table_unique_test);
} }
DBUG_VOID_RETURN;
} }
TABLE *TABLE_LIST::get_real_join_table() TABLE *TABLE_LIST::get_real_join_table()
......
...@@ -1804,7 +1804,7 @@ struct TABLE_LIST ...@@ -1804,7 +1804,7 @@ struct TABLE_LIST
void set_materialized_derived() void set_materialized_derived()
{ {
DBUG_ENTER("set_materialized_derived"); DBUG_ENTER("set_materialized_derived");
derived_type= ((derived_type & DTYPE_MASK) | derived_type= ((derived_type & (derived ? DTYPE_MASK : DTYPE_VIEW)) |
DTYPE_TABLE | DTYPE_MATERIALIZE); DTYPE_TABLE | DTYPE_MATERIALIZE);
set_check_materialized(); set_check_materialized();
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
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