How to force MySql not to locking all tables used in a trigger

Viewed 39

Suppose we have two tables, messages (msgid , mbody) and logs (logid, lbody). We add an AfterUpdate trigger on messages as follows:

BEGIN
    if new.msgid = 7 then
        do sleep(20);
        UPDATE logs SET lbody = 'test' WHERE logid = 5;
    end if;
END

Then, we update the row with msgid = 7 and it sleeps for 20 seconds. Meanwhile, we want to update a random row in logs but we must wait until the sleep ended because the entire logs table is locked!!

In practice, I encountered a very huge problem while triggering some processes since all of the used tables were locked.

Is there any way to explicitly say to MySql not to lock all rows in all tables used in a trigger? Any suggestion would be appreciated.

1 Answers

After a lot of exploring, I noticed that the engine of logs table was MyISAM not InnoDB and that was the cause of locking. I simply changed it and the problem solved.

Related