Estimating storage from the number of index pages
Before you run a LOAD utility job to load an index, estimate the future storage requirements of the index.
About this task
An index key on an auxiliary table for LOBs is 19 bytes and uses the same formula as other indexes. The RID value that is stored within the index is 4, 5, or 7 bytes, depending on the table space type.
In general, the length of the index key is the sum of the lengths of all the columns of the key, plus the number of columns that allow nulls. The length of a varying-length column is the maximum length if the index is padded. Otherwise, if an index is not padded, estimate the length of a varying-length column to be the average length of the column data, and add a two-byte length field to the estimate. You can retrieve the value of the AVGKEYLEN column in the SYSIBM.SYSINDEXES catalog table to determine the average length of keys within an index.
The following index calculations are intended only to help you estimate the storage required for an index. Because there is no way to predict the exact number of duplicate keys that can occur in an index, the results of these calculations are not absolute. It is possible, for example, that for a nonunique index, more index entries than the calculations indicate might be able to fit on an index page.
In the following calculations, assume the following:
- k
- The length of the index key.
- n
- The average number of data records per distinct key value of a
nonunique index. For example:
- a = number of data records per index
- b = number of distinct key values per index
- n = a / b
- f
- The value of PCTFREE.
- p
- The value of FREEPAGE.
- r
- The record identifier (RID) length. Use 4, 5, or 7 bytes, depending on the table space type:
Table space type r value to use Partition-by-growth (PBG UTS) 5 Partition-by-range (PBR UTS) with relative page numbering
7
Partition-by-range (PBR UTS) with absolute page numbering
5 Non-UTS defined with DSSIZE 4G
or greater5 Non-UTS defined with LARGE
5 Other non-UTS types 4 - S
- The value of the page size minus the length of the page header and page tail.
- FLOOR
- The operation of discarding the decimal portion of a real number.
- CEILING
- The operation of rounding a real number up to the next highest integer.
- MAX
- The operation of selecting the highest integer value.
Procedure
To estimate index storage size, complete the following calculations:
Example
- The index is unique.
- The table it indexes has 100000 rows.
- The key is a single column defined as CHAR(10) NOT NULL.
- The value of PCTFREE is 5.
- The value of FREEPAGE is 4.
- The page size is 4 KB.
Quantity | Calculation | Result |
---|---|---|
Length of key
Average number of duplicate keys PCTFREE FREEPAGE |
k
n f p |
10
1 5 4 |
Calculate total leaf pages
Space per key Usable space per page Entries per page Total leaf pages |
k + 7 FLOOR((100 - f ) × 4032/100) FLOOR(usable space per page / space per key) CEILING(number of table rows / entries per page) |
17 3844 225 445 |
Calculate total nonleaf pages
Space per key Usable space per page Entries per page Minimum child pages Level 2 pages Level 3 pages Total nonleaf pages |
k + 7 FLOOR(MAX(90, (100 - f )) × 4046/100) FLOOR(usable space per page / space per key) MAX(2, (entries per page + 1)) CEILING(total leaf pages / minimum child pages) CEILING(level 2 pages / minimum child pages) (level 2 pages + level 3 pages +…+ level x pages until x = 1) |
17 3843 226 227 2 1 3 |
Calculate total space required
Free pages Tree pages Space map pages Total index pages TOTAL SPACE REQUIRED, in KB |
FLOOR(total leaf pages / p), or 0 if p = 0 MAX(2, (total leaf pages + total nonleaf pages)) CEILING((tree pages + free pages)/8131) MAX(4, (1 + tree pages + free pages + space map pages)) 4 × (total index pages + 2) |
111 448 1 561 2252 |