Is there a problem that the data of a field in the data table is generated consecutively?

Source: Internet
Author: User
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?


Reply to discussion (solution)

First find? Ding Yi? Ratio? At all ??? All big ???.
For example? In the largest ??? Is 03100005556, so the next ???? OK? 03100010000, medium? Where is the difference? No.
Then every note? I? New use ?, Use 03100010000 + id ????.

For example, new ?? Used? Id = 5678, then ???? Is 03100015678

New ??? Insert ??,? Get the id and then update the sn ,?? Can be avoided ??? Suddenly. Because? Master? Be unique.

First find? Ding Yi? Ratio? At all ??? All big ???.
For example? In the largest ??? Is 03100005556, so the next ???? OK? 03100010000, medium? Where is the difference? No.
Then every note? I? New use ?, Use 03100010000 + id ????.

For example, new ?? Used? Id = 5678, then ???? Is 03100015678

New ??? Insert ??,? Get the id and then update the sn ,?? Can be avoided ??? Suddenly. Because? Master? Be unique.

Thank you for your enthusiastic answer. it is very helpful to me, but the data table is a bit messy and cannot be done by ID number. because the data was manually filled in at the beginning, all kinds of data may exist, the maximum member number is 03109999999.

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.

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)

Thank you for your enthusiastic answers. I understand that the foundation is not good.

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.