Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mariadb row level read locking

Tags:

mysql

mariadb

Does any of the mariadb backends support row-level read locking ? What I mean is:

I have an application that may run on three or four different machines. The number of machines is dynamic and not with fixed addresses. The application will execute the following two queries:

SELECT col3 from table1 WHERE col1=X
<do some checking with the version>
UPDATE table1 SET col2 = somevalue, col3 = somevalue WHERE col1=X

Now, between the first SELECT query and the second UPDATE query, I do not want any instance of the application to even read (not just WRITE) the record(s) corresponding to col1=X

Is it possible to achieve in mariadb ?

like image 333
Sankar Avatar asked Feb 11 '15 10:02

Sankar


Video Answer


1 Answers

To answer my question:

We can use the SELECT ... FOR UPDATE clauses for locking the individual records. This lock will be automatically released on the transaction commit/rollback. More information at: https://dev.mysql.com/doc/refman/5.6/en/innodb-locking-reads.html

like image 88
Sankar Avatar answered Sep 28 '22 00:09

Sankar