R
R
Ruslan Fedorov2015-10-31 08:39:30
MySQL
Ruslan Fedorov, 2015-10-31 08:39:30

Is it possible to not lock rows in InnoDB on selective update?

Being a total greenfield database neophyte, I'm wondering if it's safe to disable locks on a database in the following situation.
For example, there is the following table.

CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `score` int(11) DEFAULT NULL,
  `rating` int(10) unsigned DEFAULT NULL,
  ... ,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=... DEFAULT CHARSET=utf8;

Task:
There is a statistics module that works according to the following algorithm:
1) Get all `Users` records, sort by `score`
2) For each user, write to `rating` the position in the table obtained in step 1
2.a) In a separate transactions
2.b) In one transaction, updating all in bulk.
The condition implies that transactions will read one field and update another field. However, there are other transactions that perform various operations on the `Users` table and other tables. These operations conditionally require locks. Also these transactions can update `score`, but `rating` is read-only. For the work of the module in question, keeping track of the relevance in `score` between 1) and 2) is not required - what value was read at the time 1) is what you need to work with, even if it was updated later.
Problem of the current solution:
In the current solution, locks are implemented in the default mode of the MariaDB/XtraDB implementation, which, as far as I know, corresponds to that in mysql. There are a huge number of transactions and deadlocks happen. Deadlocks occur only if the statistics module is active. If the statistics module is excluded, the system functions perfectly and, judging by InnoTOP, there are practically no expectations.
Questions:
1) Is it safe to disable row locking for statistics module transactions without violating data integrity? Atomicity, from the condition, is not required, no one will try to write something else in the same column, but they may try to read it.
2) If the answer to (1) is yes, then how?
3) Generalization: is it possible to disable row-by-row locking of all transactions, if by condition it is guaranteed that no transaction will try to do an `update` at the same time for the same field of the same row in the same table as another. The columns in question are not indexed.
4) It is highly likely that my algorithm is crazy nonsense, which means I will be grateful for any advice on the implementation of the described module. (You just need to somehow, not necessarily in real time, but without hanging up the database, update the rating of users. ).
Thanks for the advice to a newbie!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Fedoseev, 2015-10-31
@martin74ua

g.zeos.in/?q=innodb%20%D0%B7%D0%B0%D0%B4%D0%B0%D1%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question