Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4
-
None
Description
The affected-rows count of a bulk operation (COM_STMT_BULK_EXECUTE) also counts the rows changed by DML in stored functions called by the statement. A non-bulk statement does not.
How to repeat
CREATE TABLE tu (id INT PRIMARY KEY, val INT); |
CREATE TABLE tc (c INT); |
INSERT INTO tc VALUES (0); |
INSERT INTO tu VALUES (1,0),(2,0),(3,0); |
CREATE FUNCTION f2(x INT) RETURNS INT MODIFIES SQL DATA |
BEGIN UPDATE tc SET c=c+1; RETURN x; END; |
 |
-- bulk, 3 parameter sets: (10,1), (20,2), (30,3)
|
UPDATE tu SET val=f2(?) WHERE id=?; |
-- bulk, 3 parameter sets: (1,10), (2,20), (3,30)
|
CREATE TABLE tu2 (id INT, val INT); |
INSERT INTO tu2 VALUES (?, f2(?)); |
Both bulk statements change 3 rows of the target table, and the data is correct, but mysql_stmt_affected_rows() returns 6 for each. The plain statement UPDATE tu SET val=f2(5) WHERE id=1 returns 1.
Reproduced on 10.11 (10.11.19 debug) and 11.4 (11.4.13 debug, source revision 4813c2f0a8a79e4e4c000cc8c9447096fafe7033).
The function's UPDATE calls my_ok(), and in bulk mode Diagnostics_area::set_ok_status() adds to m_affected_rows (DA_OK_BULK) instead of replacing it. For triggers, mysql_insert() skips my_ok() when SUB_STMT_TRIGGER is set, but there is no such check for stored functions, or for UPDATE/DELETE.
Related: MDEV-41213 (the same problem for bulk unit results) and MDEV-41267 (a stored function's INSERT consumes the bulk parameter sets).
Attachments
Issue Links
- relates to
-
MDEV-41213 Bulk unit results (STMT_BULK_FLAG_SEND_UNIT_RESULTS) include rows for DML executed by triggers and stored functions
-
- Stalled
-
-
MDEV-41267 Bulk execution (COM_STMT_BULK_EXECUTE) loses parameter sets when a stored function called by the statement executes an INSERT
-
- Open
-