MySQL Concurrency update

Source: Internet
Author: User

MySQL concurrency update common scenarios optimistic lock
select * from tab1 where id = ?;update tab1 set col1 = ? where id = ? and version = ?;
    • Disadvantages
      • May fail to update under high concurrency, so need to retry (Select...,update ...) To improve the update success rate
Read lock MySQL 8.0 Reference Manual/.../Locking Reads
select * from tab1 where id = ? for update;update tab1 set col1 = ? where id = ?;
    • Advantages
      • No retries required
    • Disadvantages
      • May cause other related (include the For Update line content) concurrent operation to block
Condition update MySQL 8.0 Reference Manual/.../update Syntax
update tab1 set col1 = col1-1 where col1>1
    • Advantages
      • Simple, one statement can be implemented
      • No retries required
    • Disadvantages
      • Unable to get the value of the Col1 field before and after update
      • Applies only to simple where conditions
Asynchronous update
    • Advantages
      • Reduce client wait Time
      • Increase concurrency on the service side
      • Convert concurrent operations into simpler synchronization operations
    • Disadvantages
      • The service side and the client need to support asynchronous message notification because the result of an asynchronous operation can only be returned asynchronously
      • Message Queuing and asynchronous message notifications are required, and code implementations are more complex without the framework support available
      • Other logic that relies on updating results is not supported unless all logic is asynchronous

MySQL Concurrency update

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.