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