Like the code below is it safe to do that?

create definer=`root`@`%` procedure `test`()
label: begin

declare exit handler for sqlexception rollback;
start transaction;

select condition from table where id = someid for update;

if condition = false then
  leave label;
end if;

// some query;
  • 2
    Implicit actions cannot be safe. Add rollback before leave. – Akina Oct 17 '19 at 4:45
  • 1
    In your example, the FOR UPDATE will continue to lock something until the next COMMIT or ROLLBACK. – Rick James Oct 20 '19 at 16:01

As mentioned on the comment of my question, the answer is "NO", especially the FOR UPDATE it will hold the lock until a COMMIT or ROLLBACK is called.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.