From dd1a4f5742dc1e8e65d41d3a7d61ee8e54fbf7d4 Mon Sep 17 00:00:00 2001 From: "dlenev@mockturtle.local" <> Date: Mon, 13 Nov 2006 11:10:49 +0300 Subject: [PATCH] Fix for bug bug#23651 "Server crashes when trigger which uses stored function invoked from different connections". Invocation of trigger which was using stored function from different connections caused server crashes (for non-debug server this happened in highly concurrent environment, but debug server failed on assertion in relatively simple scenario). Item_func_sp was not safe to use in triggers (in other words for re-execution from different threads) as artificial TABLE object pointed by Item_func_sp::dummy_table referenced incorrect THD object. To fix the problem we force re-initialization of this object for each re-execution of statement. --- mysql-test/r/trigger.result | 15 +++++++++++++++ mysql-test/t/trigger.test | 20 ++++++++++++++++++++ sql/item_func.cc | 1 + 3 files changed, 36 insertions(+) diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 5d643057666..9d3ab9b1d7d 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -1241,4 +1241,19 @@ i j 2 2 13 13 drop table t1; +drop table if exists t1; +drop function if exists f1; +create table t1 (i int); +create function f1() returns int return 10; +create trigger t1_bi before insert on t1 for each row set @a:= f1() + 10; +insert into t1 values (); +select @a; +@a +20 +insert into t1 values (); +select @a; +@a +20 +drop table t1; +drop function f1; End of 5.0 tests diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index 92320648033..81334f9b8ef 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -1499,4 +1499,24 @@ select * from t1; drop table t1; +# +# Bug #23651 "Server crashes when trigger which uses stored function +# invoked from different connections". +# +--disable_warnings +drop table if exists t1; +drop function if exists f1; +--enable_warnings +create table t1 (i int); +create function f1() returns int return 10; +create trigger t1_bi before insert on t1 for each row set @a:= f1() + 10; +insert into t1 values (); +select @a; +connection addconroot1; +insert into t1 values (); +select @a; +connection default; +drop table t1; +drop function f1; + --echo End of 5.0 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index a294bbd7a71..fd3d282364a 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4845,6 +4845,7 @@ Item_func_sp::cleanup() result_field= NULL; } m_sp= NULL; + dummy_table->s= NULL; Item_func::cleanup(); }