Data table A field of data has a fault now continuous generation of related issues
Source: Internet
Author: User
The data for a field in a data table has a problem with the continuous generation of faults now?
There is a data table mem has field ID SN (member number) The original member number is manually filled out such as data 03117777777, 03100005555,03100005556 SN is 11 bits but the data SN has a continuous discontinuity, it is possible to fill in the largest number, After filling in the smallest number now change the demand can not move the original data want to continuous generation can not be repeated, each registered a member to generate a membership number to the member, how to ensure that the membership number is not repeated and can reduce the contrast query, there are multiple member registration of the concurrency problems to ask you have a good solution
------to solve the idea----------------------
First find the number of members that are larger than the present.
For example, the largest membership is now 03100005556 then the next member is set to 03100010000, and the middle part of the difference is abandoned.
Then, for each new user, use 03100010000+id as a member.
For example, the new user id=5678, then the number is 03100015678
You can avoid the conflict by inserting an ID and then update the SN after the new registration. Because the key is the only one.
------to solve the idea----------------------
1. Take all your IDs out, get the maximum ID, the later new data, according to the maximum value added.
2. The user registers concurrently, can through the memcache or the Redis, the data writes the cache.
------to solve the idea----------------------
You don't fully understand Fdipzone's algorithm.
What he meant was:
There is an ID and SN two column with an ID of self-increment.
If Max (sn) = 03109999999
Then there is a constant n = max (sn)-MAX (ID)
Make N + (max (id) +1) = max (sn) = 03110000000
This is going to come out of the chaos, and of course it's missing a significant amount of SN resources
So you can also use the following algorithm to complete the trap operation
Select A.sn, b.sn as BSN from table A LEFT JOIN table B on a.sn+1=b.sn have BSN is null limit 1
So we find a discontinuous SN.
SN + 1 is the SN that is inserted
Solve concurrency problems by simply building a unique index on the SN and trying again when the insert fails
After the interval of SN in the table is full, then use the Dipzone algorithm (after all, the database is much less computationally)
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