After the mysqlinnodb row lock is unlocked, the 1213 death rate is like Deadlockfoundwhen unlock_mysql.

Source: Internet
Author: User
After the mysqlinnodb row locks are unlocked, the 1213 dead performance is like Deadlockfoundwhen solving bitsCN.com.

After the mysql innodb row lock is unlocked, the system displays the 1213 dead result, which is like the Deadlock found when solution.

Remember that the row locks and locks of innodb are for primary key indexes. If the table is locked based on the index during the query, but it is not updated through the primary key during the update, the process waiting to unlock the query will report a 1213 error, and a null value may be returned in the program.

Instance:

Table

Soldgoods (table name)

SoldgoodsID index

Productid

Businessid

Enable thread

Run:

Set autocommit = 0;

Select businessid from soldgoods where soldgoodsID = 'ac63837c76222e4a5419e2529d775ae4 'for UPDATE;

Query Results

Enable thread B

Run:

Set autocommit = 0;

Select businessid from soldgoods where soldgoodsID = 'ac63837c76222e4a5419e2529d775ae4 'for UPDATE;

Query waiting to unlock

At this time, execute in thread:

Update soldgoods set productid = 2 where businessid = '0a527df4763c3dc71cbafebec5a8d787'

Instead of updating the lock table value based on the primary key

Thread B appears:

[Err] 1213-Deadlock found when trying to get lock; try restarting transaction

If the statement executed in the last thread A is changed:

Update soldgoods set productid = 2 where soldgoodsID = 'ac63837c76222e4a5419e2529d775ae4'

Modify value based on index

Then

Commit;

Commit a transaction. Thread B can get the query value smoothly.

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.