rowlocking

MySQL - Update table rows without locking the rows

三世轮回 提交于 2020-01-04 05:37:18
问题 I have requirement where we need to update the row without holding the lock for the while updating. Here is the details of the requirements, we will be running a batch processing on a table every 5 mins update blogs set is_visible=1 where some conditions this query as to run on millions of records so we don't want to block all the rows for write during updates. I totally understand the implications of not having write locks which is fine for us because is_visible column will be updated only

MySQL: INSERT blocked by an UPDATE of the foreign key referenced row

别等时光非礼了梦想. 提交于 2019-12-25 18:48:45
问题 Let me start my question with an SQL example... Here is the table setup, Create table X and Y. With y.x refers to x.id. Insert a row into X (id=1) START TRANSACTION; CREATE TABLE `x` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `value` INT(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB; CREATE TABLE `y` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `x_id` INT(11) NOT NULL, `value` INT(11) NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_x` FOREIGN KEY (`x_id`) REFERENCES `x` (`id`) ) ENGINE=INNODB; INSERT

oracle row contention causing deadlock errors in high throughtput JMS application

穿精又带淫゛_ 提交于 2019-12-11 01:49:01
问题 Summary: I am interested in knowing what's the best practice for high throughput applications that have bulk messages trying to update the same row and get oracle deadlock errors. I know you cannot avoid those errors but how do you recover from them gracefully without getting bogged down by such deadlock errors happening over and over again. Details: We are building a high throughput JMS messaging application. Production environment will be two weblogic 11g nodes (running 6 MDB listener

UPDATE with SELECT, will it lock each row or all SELECTed records

扶醉桌前 提交于 2019-12-10 13:07:59
问题 It is unclear to me (by reading MySQL docs) if the following query ran on INNODB tables on MySQL 5.1, would create WRITE LOCK for each of the rows the db updates internally (5000 in total) or LOCK all the rows in the batch. As the database has really heavy load, this is very important. UPDATE `records` INNER JOIN ( SELECT id, name FROM related LIMIT 0, 5000 ) AS `j` ON `j`.`id` = `records`.`id` SET `name` = `j`.`name` I'd expect it to be per row but as I do not know a way to make sure it is

Concurrent execution in SQL Server

巧了我就是萌 提交于 2019-12-10 02:17:34
问题 Table schemas (SQL Server 2012) Create Table InterestBuffer ( AccountNo CHAR(17) PRIMARY KEY, CalculatedInterest MONEY, ProvisionedInterest MONEY, AccomodatedInterest MONEY, ) Create Table #tempInterestCalc ( AccountNo CHAR(17) PRIMARY KEY, CalculatedInterest MONEY ) I am doing an upsert. Update rows those existed and insert others. UPDATE A SET A.CalculatedInterest = A.CalculatedInterest + B.CalculatedInterest FROM InterestBuffer A INNER JOIN #tempInterestCalc B ON A.AccountNo = B.AccountNo

Row Level Locking in Mysql

守給你的承諾、 提交于 2019-12-09 11:56:46
问题 I have 5 rows in a table (1 to 5). I want row 2 lock for some update and in the meanwhile if someone tries to update row 4, then he should able to update. I am trying this with code below, but I feel its placing lock on table level rather than row level. ------ session 1 START TRANSACTION; SELECT * FROM test WHERE t=1 FOR UPDATE; UPDATE test SET NAME='irfandd' WHERE t=2; COMMIT; ----- session 2 (which is being blocked) START TRANSACTION; UPDATE test SET NAME='irfandd' WHERE t=4; COMMIT; 回答1:

MySQL InnoDB locking only the affected rows?

旧巷老猫 提交于 2019-12-06 06:27:38
问题 I have an InnoDB table containing users, like this: +--------------+-----------------------+ | user_id | name | +--------------+-----------------------+ | 1 | Bob | | 1 | Marry | | 2 | Bob | | 1 | John | | 3 | Bob | | 2 | Marry | +--------------+-----------------------+ On each insert I increment user_id by 1 so for example, the next user_id for Bob will be 4 I use this query to do that: INSERT INTO users (user_id, name) SELECT 1 + coalesce((SELECT max(user_id) FROM users WHERE name='Bob'), 0

Concurrent execution in SQL Server

牧云@^-^@ 提交于 2019-12-05 01:42:52
Table schemas (SQL Server 2012) Create Table InterestBuffer ( AccountNo CHAR(17) PRIMARY KEY, CalculatedInterest MONEY, ProvisionedInterest MONEY, AccomodatedInterest MONEY, ) Create Table #tempInterestCalc ( AccountNo CHAR(17) PRIMARY KEY, CalculatedInterest MONEY ) I am doing an upsert. Update rows those existed and insert others. UPDATE A SET A.CalculatedInterest = A.CalculatedInterest + B.CalculatedInterest FROM InterestBuffer A INNER JOIN #tempInterestCalc B ON A.AccountNo = B.AccountNo INSERT INTO InterestBuffer SELECT A.AccountNo, A.CalculatedInterest, 0, 0 FROM #tempInterestCalc A LEFT

How to totally lock a row in Entity Framework

大城市里の小女人 提交于 2019-12-04 17:24:35
问题 I am working with a situation where we are dealing with money transactions. For example, I have a table of users wallets, with their balance in that row. UserId; Wallet Id; Balance Now in our website and web services, every time a certain transaction happens, we need to: check that there is enough funds available to perform that transaction: deduct the costs of the transaction from the balance. How and what is the correct way to go about locking that row / entity for the entire duration of my

Row Level Locking in Mysql

一个人想着一个人 提交于 2019-12-03 15:07:36
I have 5 rows in a table (1 to 5). I want row 2 lock for some update and in the meanwhile if someone tries to update row 4, then he should able to update. I am trying this with code below, but I feel its placing lock on table level rather than row level. ------ session 1 START TRANSACTION; SELECT * FROM test WHERE t=1 FOR UPDATE; UPDATE test SET NAME='irfandd' WHERE t=2; COMMIT; ----- session 2 (which is being blocked) START TRANSACTION; UPDATE test SET NAME='irfandd' WHERE t=4; COMMIT; Instead of FOR UPDATE use LOCK IN SHARE MODE . FOR UPDATE prevents other transactions to read the row as