What is the maximum primary key size in Firebird?

I need to set the Varchar field (255) as the primary key of the database table in Firebird 2.1.

I get error messages saying that the field size is too large. I use UTF8 as my character set and the default page size is 4096.

Is it possible to do this in Firebird? I need to make sure this column is unique.

+5
source share
3 answers

As explained, the maximum key size is 1/4 of the page size, but from the Firebird reference update (here), the maximum index row length in bytes is 9 less than the maximum key length. And UTF8 in Firebird is stored inside 4 bytes / char .

Thus, the maximum length for UTF8 in a database of 4096 pages is 253 characters (4096/4 -9 = 1024 -9 = 1015, which limits 253 * 4 = 1012). So, if you need a large string, you need a large database with page size (even if you use Firebird 2.5.x).

+8
source

FirebirdFAQ Firebird 2.x . 4096 , 1024 .
UTF8 varchars 32 char, . , varchar (255) UTF8 1020 . , , varchar (254).

+1

gstat d:\path\database.fdb

:

> Index CLIENT_IDX (2) 
>         Depth: 3, leaf buckets: 545, nodes: 138523 
>         Average data length: 10.12, total dup: 13873, max dup: 645 
>         Fill distribution: 
>              0 - 19% = 0 
>             20 - 39% = 0 
>             40 - 59% = 0 
>             60 - 79% = 0 
>             80 - 99% = 545

Depth 3: . , .

, IBExpert IBAnalist

0

All Articles