MySQL Locking table from Stored FUNCTION

Posted by Brandon on Stack Overflow See other posts from Stack Overflow or by Brandon
Published on 2012-11-30T17:02:40Z Indexed on 2012/11/30 17:03 UTC
Read the original article Hit count: 204

Filed under:

I have a function in a MySQL Database that determines some sync parameters for a mobile device. The function determines the last date/time the user synchronized with the database. During my sync operation I call this server side function twice. As soon as I call it the second time - the entire Sync_Records table is locked. I cannot write to it from any other connection anywhere (note, after first call, the table is not locked). I changed the function to a Procedure - and all is fine - no locking after the second call. The entire sync operation (including both calls to the function/procedure) is within a transaction. This is an InnoDb table.

The function/procedure simply does two select statements. They are storing results in local variables and then returning the date time variable. I don't understand why the tables are locked. Does anyone have any ideas?

© Stack Overflow or respective owner

Related posts about mysql