mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
MDEV-23864 Bulk INSERT loses rows if a stored function executes DML
A DML statement of a stored function called by an optimized array binding INSERT consumed the next sets of parameters of the bulk operation. Reset THD::bulk_param during the function execution, as it is done for triggers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2239,7 +2239,16 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
|
||||
*/
|
||||
thd->set_n_backup_active_arena(call_arena, &backup_arena);
|
||||
|
||||
MYSQL_RUN_SP(this, err_status= execute(thd, TRUE));
|
||||
{
|
||||
/*
|
||||
DML statements of the function must not consume the next values of
|
||||
a bound array of the bulk operation which calls the function
|
||||
*/
|
||||
void *save_bulk_param= thd->bulk_param;
|
||||
thd->bulk_param= nullptr;
|
||||
MYSQL_RUN_SP(this, err_status= execute(thd, TRUE));
|
||||
thd->bulk_param= save_bulk_param;
|
||||
}
|
||||
|
||||
thd->restore_active_arena(call_arena, &backup_arena);
|
||||
|
||||
|
||||
@@ -23867,6 +23867,21 @@ static void test_mdev_23864()
|
||||
myquery(rc);
|
||||
rc= mysql_query(mysql, "DROP TRIGGER t1_au");
|
||||
myquery(rc);
|
||||
/* an error handled in a stored function */
|
||||
rc= mysql_query(mysql, "CREATE FUNCTION f2(x INT) RETURNS INT BEGIN "
|
||||
"DECLARE EXIT HANDLER FOR SQLEXCEPTION RETURN x; "
|
||||
"INSERT INTO t7 VALUES (x / 10); RETURN x; END");
|
||||
myquery(rc);
|
||||
test_mdev_23864_query("INSERT INTO t1 (id, val) VALUES (?, f2(?))",
|
||||
"REPLACE INTO t7 VALUES (2)", same, 3, FALSE);
|
||||
test_mdev_23864_query("INSERT INTO t1 (id, val) VALUES "
|
||||
"(?, f2((SELECT b FROM t2 WHERE a = ?)))",
|
||||
"REPLACE INTO t7 VALUES (20)", looked_up, 3, FALSE);
|
||||
test_mdev_23864_query("UPDATE t1 SET val= f2(10 * ?) WHERE id= ? / 10",
|
||||
"INSERT INTO t1 VALUES (1, 0), (2, 0), (3, 0)",
|
||||
same, 3, FALSE);
|
||||
rc= mysql_query(mysql, "DROP FUNCTION f2");
|
||||
myquery(rc);
|
||||
rc= mysql_query(mysql, "DROP TABLE t7");
|
||||
myquery(rc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user