The data of a field in the data table is faulty and is generated continuously.

Source: Internet
Author: User
Is there a problem that the data of a field in the data table is generated consecutively? There is a data table & nbsp; mem & nbsp; with Fields & nbsp; id & nbsp; sn & nbsp; (member number) & nbsp; & nbsp; The original membership number is manually filled in, for example, & nbsp; with data & nbsp; 03117777777 & nbsp; & is there a problem that the data of a field in the data table is generated consecutively?
One data table mem contains the field id sn (member number). The original member number is manually filled in. for example, if the data is 03117777777,031 bytes 555555,03100005556 sn is 11 bits, but the data sn is continuous and discontinuous, it is possible that the largest number is entered first, and the smallest number entered later cannot be repeatedly generated if you want to generate the original data after changing the requirements. each registered member generates a membership number for the member, how can we ensure that the member numbers are not repeated and can reduce the comparison and query? if you have any questions about the concurrency of multiple member registrations, do you have a good solution?
------ Solution ----------------------
First, find a member who is larger than all current members.
For example, if the maximum number of members is 03100005556, the next member is set to 03100010000, and the difference between the two is not used.
Then, every time a new user is added, more than 03100010000 IDs will be used as member accounts.

For example, if snapshot id = 5678 is used in the new region, then the member quota is 03100015678.

Insert a data volume before updating the sn after the id is obtained. This avoids unexpected data bursts. Because the primary shard is unique.
------ Solution ----------------------
1. obtain all your IDs to obtain the largest id. the newly added data is added after the maximum value.
2. concurrent user registration. data can be written to the cache through memcache or redis.
------ Solution ----------------------
You do not fully understand the fdipzone algorithm
He means:
There are two columns: id and sn. id is auto-incrementing.
If max (sn) = 03109999999
The constant n = max (sn)-max (id)
Make n + (max (id) + 1) = max (sn) = 03110000000
In this way, we can get out of the previous chaos. of course, this requires a considerable number of sn resources.

Therefore, you can use the following algorithms to complete the leak filling operation:
Select a. sn, B. sn as bsn from table a left join Table B on a. sn + 1 = B. sn having bsn is null limit 1
In this way, a discontinuous sn is found.
Sn + 1 is the inserted sn
You only need to create a unique index on the sn and try again when the insertion fails to solve the concurrency problem.
After all the SNS in the table are filled, the dipzone algorithm is used (after all, the database computing workload is much smaller)

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.