From d15cbc1a1abf8c61398c096b0a0271d361da552c Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Fri, 28 Nov 2008 20:36:07 +0400 Subject: [PATCH] Bug #40745: Error during WHERE clause calculation in UPDATE leads to an assertion failure Any run-time error in stored function (like recursive function call or update of table that is already updating by statement which invoked this stored function etc.) that was used in some expression of the single-table UPDATE statement caused an assertion failure. Multiple-table UPDATE (as well as INSERT and both single- and multiple-table DELETE) are not affected. mysql-test/r/update.result: Added test case for bug #40745. mysql-test/t/update.test: Added test case for bug #40745. sql/sql_update.cc: Bug #40745: Error during WHERE clause calculation in UPDATE leads to an assertion failure The mysql_update function has been updated to take into account the status of invoked stored functions before setting the status of whole UPDATE query to OK. --- mysql-test/r/update.result | 11 +++++++++++ mysql-test/t/update.test | 21 +++++++++++++++++++++ sql/sql_update.cc | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result index b861ec96882..7a51649fac5 100644 --- a/mysql-test/r/update.result +++ b/mysql-test/r/update.result @@ -491,4 +491,15 @@ update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id; affected rows: 127 info: Rows matched: 128 Changed: 127 Warnings: 0 drop table t1,t2; +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS INT RETURN f1(); +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1); +UPDATE t1 SET i = 3 WHERE f1(); +ERROR HY000: Recursive stored functions and triggers are not allowed. +UPDATE t1 SET i = f1(); +ERROR HY000: Recursive stored functions and triggers are not allowed. +DROP TABLE t1; +DROP FUNCTION f1; End of 5.0 tests diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test index f79c9e773aa..7d56df259ba 100644 --- a/mysql-test/t/update.test +++ b/mysql-test/t/update.test @@ -430,4 +430,25 @@ drop table t1,t2; connection default; disconnect con1; +# +# Bug #40745: Error during WHERE clause calculation in UPDATE +# leads to an assertion failure +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +CREATE FUNCTION f1() RETURNS INT RETURN f1(); +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1); + +--error ER_SP_NO_RECURSION +UPDATE t1 SET i = 3 WHERE f1(); +--error ER_SP_NO_RECURSION +UPDATE t1 SET i = f1(); + +DROP TABLE t1; +DROP FUNCTION f1; + --echo End of 5.0 tests diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 4fbf08c44d3..dbdd30552ec 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -715,6 +715,11 @@ int mysql_update(THD *thd, else table->file->unlock_row(); thd->row_count++; + if (thd->is_error()) + { + error= 1; + break; + } } dup_key_found= 0; /*