Skip to content

Commit

Permalink
MDEV-8018: main.multi_update fails with --ps-protocol
Browse files Browse the repository at this point in the history
save_prep_leaf_tables() made recursive to work with underlying view

Arena restoiring fixed in case of EOM.
  • Loading branch information
sanja-byelkin committed Apr 22, 2015
1 parent e428c80 commit 8cbaafd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
5 changes: 5 additions & 0 deletions mysql-test/r/multi_update.result
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,11 @@ CREATE ALGORITHM=UNDEFINED
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`;
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 table t1,t2,t3;
end of 5.5 tests
6 changes: 6 additions & 0 deletions mysql-test/t/multi_update.test
Original file line number Diff line number Diff line change
Expand Up @@ -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';

--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 table t1,t2,t3;
--echo end of 5.5 tests
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ int mysql_multi_delete_prepare(THD *thd)
*/
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(FALSE);
Expand Down
4 changes: 3 additions & 1 deletion sql/sql_derived.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
DT_PHASES_MATERIALIZE);
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)
DBUG_RETURN(FALSE);

Expand Down
37 changes: 29 additions & 8 deletions sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
return 0;
return FALSE;

Query_arena *arena= thd->stmt_arena, 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);
TABLE_LIST *table;
while ((table= li++))
{
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;
}


Expand Down
2 changes: 2 additions & 0 deletions sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,8 @@ struct LEX: public Query_tables_list
}
return FALSE;
}

bool save_prep_leaf_tables();
};


Expand Down
2 changes: 1 addition & 1 deletion sql/sql_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ int mysql_multi_update_prepare(THD *thd)
*/
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 (FALSE);
Expand Down

0 comments on commit 8cbaafd

Please sign in to comment.