FAQ Series | Using MySQL to implement the generator number

Source: Internet
Author: User
Tags generator

Problem: Use MySQL to implement the function of the generator, to ensure that the ID number is unique to each fetch
Implementation: The following is a general idea, throw a brick, welcome replies.
Depending on the size of the number segment, decide whether to divide into multiple tables, each of which fills in the different number segments beforehand.
At each application end, set the transaction isolation level to: repeatable read, and reads the data in the following way

SELECT ' id ' from ' id_range_xx ' ORDER by ID of LIMIT 1 for UPDATE

In the above scenario, whenever an ID number is selected, the other terminal also reads the number, which creates a lock wait, without the case where the ID number is reused.
Considering concurrency issues, it is recommended that you increase the number of tables, each time you loop or randomly read data from the table, reducing concurrent requests to a single table.


--------------------------------------Split Line--------------------------------------

Hall of Understanding ( http://zhishuedu.com Training is a professional quality training brand jointly launched by senior MySQL expert Ye Jinlong and Wu Bingxi, which mainly includes MySQL DBA combat optimization and Python Operation Development Course, which is the most conscientious and quality training course in the industry.


This article is from the "Lao Ye teahouse" blog, please be sure to keep this source http://imysql.blog.51cto.com/1540006/1879715

FAQ Series | Using MySQL to implement the generator number

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.