The size of a file can be calculated in the same way for both NK-ISAM and K-ISAM. First, the number of data blocks is calculated from the record length, the usable block size and the number of records.
Usable block size:
|
n | blocking factor |
PAD | PAD value (see PAD operand of the FILE macro) |
RECSIZE | Record length |
Size of the data section:
|
For NK-ISAM, the number of overflow blocks must also be estimated. This is dependent on the record length:
Overflow blocks:
|
i = 0 | for RECSIZE <= n * 2032 - 16 |
i = 1 | for RECSIZE > n * 2032 - 16 |
In sequentially created NK-ISAM files, each primary index block can hold an average of about 200 primary index entries. The size of an NK-ISAM file can thus be estimated as follows:
Size of file:
|
i = 1 / i= 0 takes account of overflow blocks (see above).
For NK-ISAM files, the total number of primary index blocks in a file can be considered to be approximately the same as the number of primary index blocks in the lowest primary index level. The following tables simplify the estimation of the sizes of NK-ISAM files.
For NK-ISAM files created sequentially, each primary index block holds about 200 primary index entries (due to key compression); this results in the values shown in the following table:
Number of data blocks | Number of primary index levels |
---|---|
0 - 200 | 1 |
For files created non-sequentially, the number of primary index levels increases faster than for sequentially created files, due to the block splitting involved. If there is more than one primary index level, each primary index block contains an average of about 160 index entries.
Number of data blocks | Number of primary index levels |
---|---|
0 - 200 | 1 |
For a file with secondary keys, the number of secondary index blocks can be estimated with the aid of the following formula. This formula takes into account the fact that an attempt is made to fill the secondary index blocks to a level of 75%. This percentage is only an average value. In some cases, this figure cannot be achieved.
Secondary index blocks for secondary key i:
|
PAM pagesi | PAM pages for the secondary index blocks for secondary key i. |
P-KEYLEN | Length of the primary key of the file. |
hi
| Relative frequency with which different values occur in the file for secondary key i: if, for example, there are on average 10 records with the same value in secondary key i, then hi = 0.1 |
S-KEYLENi | Length of secondary key i. |
The total number of secondary index blocks for all secondary keys in the file is then the sum of the values determined for all defined secondary keys:
Secondary index blocks for a file with n secondary keys:
|
K-ISAM
For K-ISAM files, the number of primary index entries per index block depends on the key length:
|
This formula takes into account the fact that a primary index block cannot be more than 50% full. The total size of a K-ISAM file is then calculated as follows:
Size of file:
|
KEYLEN: Key length.