MySQL: increasing text in DB

I need to have text identifiers in my application. For example, we have an acceptable encoding azAZ09 and a valid range of identifiers [aaa] - [cZ9]. The first generated identifier will be aaa, then aab, aac, aad etc

How can I return the identifier and increase the lower border of the transaction? (provided that there are hundreds of simultaneous requests, and everyone should have the correct result)

To reduce the load, I assume that you can define 20 separate ranges and return the identifier from an arbitrary range - this should reduce competition, but it is not clear how to do one operation in the first place.

Also, note that the number of identifiers in a range can exceed 2 ^ 32.

Another idea is to have ranges of 64-bit integers and convert integer → char id to program code, where this could be done asynchronously.

Any ideas?

+5
source share
2 answers

I asked another question to solve the same problem: how can I use the functions of my database to implement my requirement.

See what your database offers in terms of sequence management. Some of them can handle something similar. If you don’t have a database, I would look at the “screw up support” on the usual numeric keys, as they already solve all the problems that you expect.

: , , 0. . : ( , - ) , Java. . , ... - .

!

+1

, long (bigint), , , , 32 ,

  • 32 range0.. range31 ( 32 , )

  • , auto_increment 64 - , 63, . 5 , 0 31. 1 + 5 = 6 . 1 (2 ^ 58-1) 10 ^ 17... .

  • , range i, 0 31.

create tables - , , Java

  String table;
  String query;
  long increment;

  for (long i=0 ; i<32 ; i++) {
    table = "range"+i;
    increment = (i<<58) + 1;
    query = "CREATE TABLE "+table+" (v bigint auto_increment primary key) auto_increment="+increment;

    do_query(query);
  }
+2

All Articles