Commit 8cbaafd2 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-8018: main.multi_update fails with --ps-protocol

save_prep_leaf_tables() made recursive to work with underlying view

Arena restoiring fixed in case of EOM.
parent e428c809
...@@ -1010,6 +1010,11 @@ CREATE ALGORITHM=UNDEFINED ...@@ -1010,6 +1010,11 @@ CREATE ALGORITHM=UNDEFINED
DEFINER=`root`@`localhost` SQL SECURITY DEFINER DEFINER=`root`@`localhost` SQL SECURITY DEFINER
VIEW `v3` AS select `t1c`.`fe2` AS `fe2`,`t1c`.`f34` AS `f34`,`t1c`.`f33` AS `f33`,`t1c`.`f32` AS `f32`,`t1c`.`f37` AS `f37`,`t1c`.`fe10` AS `fe10`,if((`tov`.`ft6` in ('klarmobil','callmobile')),`tov`.`ft9`,`tov`.`ft6`) AS `ft6_1`,`tov`.`ft6_2` AS `ft6_2`,`ua`.`fe18` AS `fe18`,`ua`.`ft3` AS `ft3` from ((`t3` `t1c` left join `v2` `ua` on((`t1c`.`fe2` = `ua`.`fe2`))) left join `v1` `tov` on((`t1c`.`fe8` = `tov`.`ft4`))) where (`t1c`.`ft3` = `ua`.`ft3`) group by `t1c`.`fe2`,`t1c`.`f34`,`t1c`.`f33`,`t1c`.`f32` order by `t1c`.`f34`; VIEW `v3` AS select `t1c`.`fe2` AS `fe2`,`t1c`.`f34` AS `f34`,`t1c`.`f33` AS `f33`,`t1c`.`f32` AS `f32`,`t1c`.`f37` AS `f37`,`t1c`.`fe10` AS `fe10`,if((`tov`.`ft6` in ('klarmobil','callmobile')),`tov`.`ft9`,`tov`.`ft6`) AS `ft6_1`,`tov`.`ft6_2` AS `ft6_2`,`ua`.`fe18` AS `fe18`,`ua`.`ft3` AS `ft3` from ((`t3` `t1c` left join `v2` `ua` on((`t1c`.`fe2` = `ua`.`fe2`))) left join `v1` `tov` on((`t1c`.`fe8` = `tov`.`ft4`))) where (`t1c`.`ft3` = `ua`.`ft3`) group by `t1c`.`fe2`,`t1c`.`f34`,`t1c`.`f33`,`t1c`.`f32` order by `t1c`.`f34`;
UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01'; UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01';
#MDEV-8018: main.multi_update fails with --ps-protocol
prepare stmt1 from "UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01'";
execute stmt1;
execute stmt1;
deallocate prepare stmt1;
drop view v3,v2,v1; drop view v3,v2,v1;
drop table t1,t2,t3; drop table t1,t2,t3;
end of 5.5 tests end of 5.5 tests
...@@ -1047,6 +1047,12 @@ VIEW `v3` AS select `t1c`.`fe2` AS `fe2`,`t1c`.`f34` AS `f34`,`t1c`.`f33` AS `f3 ...@@ -1047,6 +1047,12 @@ VIEW `v3` AS select `t1c`.`fe2` AS `fe2`,`t1c`.`f34` AS `f34`,`t1c`.`f33` AS `f3
UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01'; UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01';
--echo #MDEV-8018: main.multi_update fails with --ps-protocol
prepare stmt1 from "UPDATE t1 t1 left join v3 t2 on t1.f4 = t2.fe2 SET t1.f20 = t2.ft6_1, t1.f32 = t2.f32, t1.f33 = t2.f33, t1.f37 = t2.f37 WHERE f5 >= '2015-02-01'";
execute stmt1;
execute stmt1;
deallocate prepare stmt1;
drop view v3,v2,v1; drop view v3,v2,v1;
drop table t1,t2,t3; drop table t1,t2,t3;
--echo end of 5.5 tests --echo end of 5.5 tests
......
...@@ -610,7 +610,7 @@ int mysql_multi_delete_prepare(THD *thd) ...@@ -610,7 +610,7 @@ int mysql_multi_delete_prepare(THD *thd)
*/ */
lex->select_lex.exclude_from_table_unique_test= FALSE; lex->select_lex.exclude_from_table_unique_test= FALSE;
if (lex->select_lex.save_prep_leaf_tables(thd)) if (lex->save_prep_leaf_tables())
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
......
...@@ -169,7 +169,9 @@ mysql_handle_single_derived(LEX *lex, TABLE_LIST *derived, uint phases) ...@@ -169,7 +169,9 @@ mysql_handle_single_derived(LEX *lex, TABLE_LIST *derived, uint phases)
uint8 allowed_phases= (derived->is_merged_derived() ? DT_PHASES_MERGE : uint8 allowed_phases= (derived->is_merged_derived() ? DT_PHASES_MERGE :
DT_PHASES_MATERIALIZE); DT_PHASES_MATERIALIZE);
DBUG_ENTER("mysql_handle_single_derived"); DBUG_ENTER("mysql_handle_single_derived");
DBUG_PRINT("enter", ("phases: 0x%x allowed: 0x%x", phases, allowed_phases)); DBUG_PRINT("enter", ("phases: 0x%x allowed: 0x%x alias: '%s'",
phases, allowed_phases,
(derived->alias ? derived->alias : "<NULL>")));
if (!lex->derived_tables) if (!lex->derived_tables)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
......
...@@ -4102,27 +4102,48 @@ bool st_select_lex::save_leaf_tables(THD *thd) ...@@ -4102,27 +4102,48 @@ bool st_select_lex::save_leaf_tables(THD *thd)
} }
bool st_select_lex::save_prep_leaf_tables(THD *thd) bool LEX::save_prep_leaf_tables()
{ {
if (!thd->save_prep_leaf_list) if (!thd->save_prep_leaf_list)
return 0; return FALSE;
Query_arena *arena= thd->stmt_arena, backup; Query_arena *arena= thd->stmt_arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
//It is used for DETETE/UPDATE so top level has only one SELECT
DBUG_ASSERT(select_lex.next_select() == NULL);
bool res= select_lex.save_prep_leaf_tables(thd);
if (arena)
thd->restore_active_arena(arena, &backup);
if (res)
return TRUE;
thd->save_prep_leaf_list= FALSE;
return FALSE;
}
bool st_select_lex::save_prep_leaf_tables(THD *thd)
{
List_iterator_fast<TABLE_LIST> li(leaf_tables); List_iterator_fast<TABLE_LIST> li(leaf_tables);
TABLE_LIST *table; TABLE_LIST *table;
while ((table= li++)) while ((table= li++))
{ {
if (leaf_tables_prep.push_back(table)) if (leaf_tables_prep.push_back(table))
return 1; return TRUE;
}
is_prep_leaf_list_saved= TRUE;
for (SELECT_LEX_UNIT *u= first_inner_unit(); u; u= u->next_unit())
{
for (SELECT_LEX *sl= u->first_select(); sl; sl= sl->next_select())
{
if (sl->save_prep_leaf_tables(thd))
return TRUE;
}
} }
thd->lex->select_lex.is_prep_leaf_list_saved= TRUE;
thd->save_prep_leaf_list= FALSE;
if (arena)
thd->restore_active_arena(arena, &backup);
return 0; return FALSE;
} }
......
...@@ -2766,6 +2766,8 @@ struct LEX: public Query_tables_list ...@@ -2766,6 +2766,8 @@ struct LEX: public Query_tables_list
} }
return FALSE; return FALSE;
} }
bool save_prep_leaf_tables();
}; };
......
...@@ -1388,7 +1388,7 @@ int mysql_multi_update_prepare(THD *thd) ...@@ -1388,7 +1388,7 @@ int mysql_multi_update_prepare(THD *thd)
*/ */
lex->select_lex.exclude_from_table_unique_test= FALSE; lex->select_lex.exclude_from_table_unique_test= FALSE;
if (lex->select_lex.save_prep_leaf_tables(thd)) if (lex->save_prep_leaf_tables())
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
DBUG_RETURN (FALSE); 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