[MDEV-6905] START TRANSACTION IF NOT EXISTS Created: 2014-10-21 Updated: 2015-02-17 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor |
| Reporter: | Federico Razzoli | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | transactions | ||
| Description |
|
SHORT VERSION: Could we have a START TRANSACTION IF EXISTS that does not commit existing transaction? – LONG VERSION: Sometimes, when a procedure is called, there are possible 2 cases: But START TRANSACTION commits existing transaction. A snippet like this does NOT solve the problem:
Because, if the procedure is called by a trigger, I get: START TRANSACTION IF EXISTS would solve the problem. |
| Comments |
| Comment by Sergei Golubchik [ 2014-10-21 ] | ||||||||
|
technically, you can DECLARE HANDLER to intercept this error. You can even wrap that in a nice procedure, like (not tested)
| ||||||||
| Comment by Federico Razzoli [ 2014-10-21 ] | ||||||||
|
I think that the correct syntax is:
But for some reason, the result is the same when you call the procedure from a trigger. I have no idea if it is a bug or not. | ||||||||
| Comment by Federico Razzoli [ 2014-10-22 ] | ||||||||
|
Just to be clear: an error occurs because even this snippet causes an error, if it is inside a trigger:
| ||||||||
| Comment by Sergei Golubchik [ 2015-02-16 ] | ||||||||
|
Okay. This fails because START TRANSACTION is not allowed inside a trigger. Not even if hidden inside a stored procedure. There's an early check (in the CALL statement itself) that the called procedure doesn't have START TRANSACTION. And there's also a run-time check inside START TRANSACTION itself. You suggest to work around it by introducing a new statement START TRANSACTION IF NOT EXISTS that is allowed inside a stored procedure called from a trigger. But then, I think, an easy fix would be simply to allow START TRANSACTION directly and only keep the run-time check. But here're two more thoughts:
This means that logically we should disable early checks completely for all statements (as they all can be put under IF FALSE THEN, right?), but also in almost all cases the early checks are useful. May be a solution to these all issues would be to allow you to disable this early check per procedure? Like, declare a procedure “safe to be invoked from a trigger”. Then CALL won't check anything and START TRANSACTION will fail when executed from a trigger. It'll be up to you to protect all these dangerous statements with IF-s to make sure they don't break a trigger. | ||||||||
| Comment by Federico Razzoli [ 2015-02-17 ] | ||||||||
|
I see your points. Sounds like a good idea. I suspect that other (corner?) cases would benefit from this change, when we have a trigger (or a function?) calling a stored procedure. |