Database update deadlock, database update

Source: Internet
Author: User

Database update deadlock, database update

A common deadlock scenario is a scenario where concurrent batch update is performed:
Update cross_marketingset gmtModified = NOW (), pageview = pageview + # extpageview # WHERE marketingId = # marketingId #

 

For the first call, when marketingId is used for the second call, the order of incoming values of marketingId is: 1, 2, 5, and 3. the row is locked for each update. Then, when the first call is performed, the sequential lock row is found to have been locked by the second call after Update 3 and preparation for the new 5. At this time, the second call is just like getting the lock 3 after the new 5 preparation, but it is found to be occupied by the first call, so a deadlock occurs. Therefore, we need to sort batch update and delete operations in a fixed order and then perform operations. In the previous example, if the marketingId is sorted from small to large, it will become: for the first call, the order of marketingId input values: 1, 3, 5, 12, the order of marketingId input values: 1, 2, 3, 5 to avoid deadlock.

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.