Replication Integer Primary Key

I am weighing my options for entire primary keys that can be used in multiserver replication. (I almost completely sell for using whole keys instead of GUIDs)

The best I can think of is to have the most important data first and have the server number last: for example. invoice 1 on server 1 = 101 invoice 1 on server 2 = 102 where the non-server part (invoiceno) comes from the db number generator

algorithmically: gen_id (INVOICENO_GEN, 1) * 100 + serverno and you can get the server number by looking at the value and mathematically.

Which leaves room for 99 servers, although it remains short and readable and will not collide. Using this scheme and a column with a normal integer size, you will create maximum rows (21,474,836) or if bigint uses a lot of billions.

for example, the keys of the table of accounts will look like this:

Server 1    
101
201
301
401

Server 2    
102
202
302
402

So my question is: any criticisms or flaws that I missed?

The database is Firebird.

+3
source share
2 answers

How easy is it to create a composite primary key?

Define "ServerID" to install on each server, for example. 1, 2, 3, 4, etc. Like int. Then enter "InvoiceID" as INT in the invoice table.

Create a primary key (ServerID, InvoiceID).

, 99 , / - .

, , , (ServerID, InvoiceID) - , ServerID , .

+2

, -, . . , , ( ).

+2

Source: https://habr.com/ru/post/1720096/


All Articles