Let's say you have a stored procedure that looks something like this:
CREATE OR REPLACE
PROCEDURE usp_do_something (
IN param1 INT,
IN param2 INT,
IN param3 INT
)
MODIFIES SQL DATA
BEGIN
START TRANSACTION;
INSERT `table1` ( `ID` ) VALUES (param1);
INSERT `table2` ( `ID` ) VALUES (param2);
INSERT `table3` ( `ID` ) VALUES (param3);
COMMIT;
END;
And then the stored procedure is called with a set of parameter values which cause one of the INSERT
operations to fail, raising an SQLEXCEPTION
.
There is no explicit ROLLBACK
command in this example. Testing shows that the transaction is not committed when the SQLEXCEPTION occurs before the COMMIT;
statement. Is the transaction implicitly rolled back when the stored procedure ends? Or will the transaction be left hanging until some kind of timeout occurs? Could this cause the stored proc to hold locks for some time after it's failed?
I know that I can explicitly trigger ROLLBACK
on failure using DECLARE HANDLER
as described in this question but I can't find any documentation that describes what MariaDB does if a stored-procedure transaction fails before reaching a COMMIT
statement without any explicit ROLLBACK
.
Is there a MariaDB/MySQL log or transaction state table that I could look at to see what the server is doing with this transaction?