Commit d9cb1352 authored by unknown's avatar unknown

merge of MDEV-5356 5.1->5.3 (with more fixes and test suite).

THD::thd->activate_stmt_arena_if_needed() should be used to temporary activating statement arena instead of direct usage of THD::set_n_backup_active_arena() because possible such scenario:
  1) func1 saves current arena and activates copy1 of statement arena
  2) func2 saves copy1 of statement arena setup by func1 and activates copy2
  3) some changes made for copy 2
  4) func2 stores changed copy2 back to statenet arena and activates copy1
  5) func1 store unchanged copy1 back to statemnt arena (rewrite changed copy 2 so changes become lost) and activates arena which was before.
parents bea9f826 5f5f7bef
......@@ -479,5 +479,27 @@ SELECT * FROM
WHERE tmp.a;
a b
100 200
#
# MDEV-5356: Server crashes in Item_equal::contains on 2nd
# execution of a PS
#
CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1 VALUES (1,2),(3,4);
CREATE TABLE t2 (c INT);
INSERT INTO t2 VALUES (5),(6);
CREATE TABLE t3 (d INT);
INSERT INTO t3 VALUES (7),(8);
CREATE PROCEDURE pr()
UPDATE t3,
(SELECT c FROM
(SELECT 1 FROM t1 WHERE a=72 AND NOT b) sq,
t2
) sq2
SET d=sq2.c;
CALL pr();
CALL pr();
CALL pr();
drop procedure pr;
drop table t1,t2,t3;
# End of 5.3 tests
set optimizer_switch=@save_derived_optimizer_switch;
......@@ -394,6 +394,35 @@ WHERE tmp.b;
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.a;
--echo #
--echo # MDEV-5356: Server crashes in Item_equal::contains on 2nd
--echo # execution of a PS
--echo #
CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1 VALUES (1,2),(3,4);
CREATE TABLE t2 (c INT);
INSERT INTO t2 VALUES (5),(6);
CREATE TABLE t3 (d INT);
INSERT INTO t3 VALUES (7),(8);
CREATE PROCEDURE pr()
UPDATE t3,
(SELECT c FROM
(SELECT 1 FROM t1 WHERE a=72 AND NOT b) sq,
t2
) sq2
SET d=sq2.c;
CALL pr();
CALL pr();
CALL pr();
drop procedure pr;
drop table t1,t2,t3;
--echo # End of 5.3 tests
set optimizer_switch=@save_derived_optimizer_switch;
......@@ -8050,12 +8050,9 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
if (table_list->merge_underlying_list)
{
DBUG_ASSERT(table_list->is_merged_derived());
Query_arena *arena= thd->stmt_arena, backup;
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
bool res;
if (arena->is_conventional())
arena= 0; // For easier test
else
thd->set_n_backup_active_arena(arena, &backup);
res= table_list->setup_underlying(thd);
if (arena)
thd->restore_active_arena(arena, &backup);
......@@ -8434,11 +8431,8 @@ void wrap_ident(THD *thd, Item **conds)
{
Item_direct_ref_to_ident *wrapper;
DBUG_ASSERT((*conds)->type() == Item::FIELD_ITEM || (*conds)->type() == Item::REF_ITEM);
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0;
else
thd->set_n_backup_active_arena(arena, &backup);
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
if ((wrapper= new Item_direct_ref_to_ident((Item_ident *)(*conds))))
(*conds)= (Item*) wrapper;
if (arena)
......
......@@ -614,11 +614,8 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
thd->lex->sql_command == SQLCOM_DELETE_MULTI))))
DBUG_RETURN(FALSE);
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0; // For easier test
else
thd->set_n_backup_active_arena(arena, &backup);
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
SELECT_LEX *first_select= unit->first_select();
......
......@@ -3679,11 +3679,8 @@ void SELECT_LEX::mark_const_derived(bool empty)
bool st_select_lex::save_leaf_tables(THD *thd)
{
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0;
else
thd->set_n_backup_active_arena(arena, &backup);
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
List_iterator_fast<TABLE_LIST> li(leaf_tables);
TABLE_LIST *table;
......@@ -3711,10 +3708,7 @@ bool st_select_lex::save_prep_leaf_tables(THD *thd)
return 0;
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0;
else
thd->set_n_backup_active_arena(arena, &backup);
arena= thd->activate_stmt_arena_if_needed(&backup);
List_iterator_fast<TABLE_LIST> li(leaf_tables);
TABLE_LIST *table;
......
......@@ -1000,11 +1000,8 @@ JOIN::optimize()
MEMROOT for prepared statements and stored procedures.
*/
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0; // For easier test
else
thd->set_n_backup_active_arena(arena, &backup);
Query_arena *arena, backup;
arena= thd->activate_stmt_arena_if_needed(&backup);
sel->first_cond_optimization= 0;
......
......@@ -1121,11 +1121,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
will be TRUE as far as we make new table cache).
*/
old_lex= thd->lex;
arena= thd->stmt_arena;
if (arena->is_conventional())
arena= 0;
else
thd->set_n_backup_active_arena(arena, &backup);
arena= thd->activate_stmt_arena_if_needed(&backup);
/* init timestamp */
if (!table->timestamp.str)
......
......@@ -3560,7 +3560,7 @@ bool TABLE_LIST::create_field_translation(THD *thd)
SELECT_LEX *select= get_single_select();
List_iterator_fast<Item> it(select->item_list);
uint field_count= 0;
Query_arena *arena= thd->stmt_arena, backup;
Query_arena *arena, backup;
bool res= FALSE;
if (thd->stmt_arena->is_conventional() ||
......@@ -3598,10 +3598,7 @@ bool TABLE_LIST::create_field_translation(THD *thd)
return FALSE;
}
if (arena->is_conventional())
arena= 0; // For easier test
else
thd->set_n_backup_active_arena(arena, &backup);
arena= thd->activate_stmt_arena_if_needed(&backup);
/* Create view fields translation table */
......
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