Putting an order in the way how locks are aquired in MySQL
NickName:artaxerxe Ask DateTime:2015-12-09T16:35:24

Putting an order in the way how locks are aquired in MySQL

From MySQL documentation:

A locking read, an UPDATE, or a DELETE generally set record locks on every index record that is scanned in the processing of the SQL statement. It does not matter whether there are WHERE conditions in the statement that would exclude the row. InnoDB does not remember the exact WHERE condition, but only knows which index ranges were scanned.

When I'm performing an UPDATE (although I would be interested about the others also, now I'm concerned with UPDATE statement), is there a way to put lock in the same order, so that to avoid deadlocks as much as possible?

I would also be very much interested if that's possible when performing UPDATE with INNER JOIN (or with multiple tables).

N.B. Deadlocks occur in my table due to concurrent updates and inserts (and even deletes).

Copyright Notice:Content Author:「artaxerxe」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34174109/putting-an-order-in-the-way-how-locks-are-aquired-in-mysql

More about “Putting an order in the way how locks are aquired in MySQL” related questions

Putting an order in the way how locks are aquired in MySQL

From MySQL documentation: A locking read, an UPDATE, or a DELETE generally set record locks on every index record that is scanned in the processing of the SQL statement. It does not matter whether...

Show Detail

Mysql table lock instead of row locks

Mysql (5.5) Innodb in this certain case is putting table lock rather than row locks. And this is causing failure of other insert queries to the table. Also this is a part of a larger transaction.

Show Detail

Logging for Locks in MySQL

How do i enable logs for locks in MySQL? For example, if i run select * from table on my InnoDB table, MySQL must internally lock this table. I want to learn how and when MySQL locks my table and in

Show Detail

How to use exclusive locks in MySQL?

I'm trying to implement my own version of session handler using MySQL in PHP. My version differs from existing ones (like Zend's) in that mine is namespaced and each namespace is stored and locked

Show Detail

How to get list of named MySQL locks held by MySQL client connections

For MySQL 5.1, is there a way to get a list of named MySQL "locks" held by MySQL client connections? I know I can check a specific named lock, if I know the name of the lock. But I want to know ho...

Show Detail

Possible to force order of TX locks in ORA?

While analyzing a deadlock caused by two concurrent SELECT FOR UPDATE statements I found following interesting article: https://hoopercharles.wordpress.com/2011/11/21/select-for-update-in-what-orde...

Show Detail

MySql InnoDB Repeatable Read Unexpected behavior of locks

As I know, innoDB use mechanism of consistent non blocking read, so every transaction works with its own snapshot. it is told also in official documentation A consistent read does not set any...

Show Detail

How to deal with Spring hibernate no lock aquired exception inside a transaction

I have applied @Transactional in my interface, and inside my serviceImpl, the corresponding method is calling some other methods, one method is reading, another method is writing. Although I have

Show Detail

Using Java locks for database concurrency

I have the following scenario. I have two tables. One stores multi values that are counters for transactions. Through a java application the first table value is read, incremented and written to the

Show Detail

mysql - Long query execute time locks table

I have a mysql database which collects data from all kinds of resources. In order to show some statistics from different tables, I run a long query which takes about a couple of minutes to execute....

Show Detail