
Implementation of the Vardecimal Storage Format
Depending on the precision of the column (1 to 38), storage of a decimal value consumes between 5 and 17 bytes. When a table is not using the vardecimal storage format, every entry in the table consumes the same number of bytes for each defined decimal column, even if the value of a row is 0, NULL, or some value that could be expressed in a smaller number of bytes, such as the number 3. When a table is stored in the vardecimal storage format, the decimal columns of each row consume only the space that is required to contain the provided number, plus 2 bytes of overhead. The result is always between 5 and 20 bytes. This includes the 2 bytes of overhead to store the offset to the value. However, null values and zeros are treated specially and take only 2 bytes.
If the table does not have any variable length columns, there is an additional overhead of 2 bytes per row to store the number of variable length columns. If the table already has at least one variable length column, there is no additional overhead.
The following table shows the number of bytes that are required to store decimal data in the regular fixed format, and the maximum number of bytes that are required to store decimal data in the vardecimal storage format. When a table is stored in the fixed format, the value that is listed will be used for every row. When a table is stored in vardecimal storage format, many values will require less than the number of bytes that is listed.
|
Column precision
|
Original fixed decimal size (bytes)
|
Maximum vardecimal data area (bytes)
|
Overhead to store offset (bytes)
|
Maximum vardecimal storage used (bytes)
|
|---|
|
1-3
|
5
|
3
|
2
|
5
|
|
4-6
|
5
|
4
|
2
|
6
|
|
7-9
|
5
|
5
|
2
|
7
|
|
10-12
|
9
|
6
|
2
|
8
|
|
13-15
|
9
|
8
|
2
|
10
|
|
16-18
|
9
|
9
|
2
|
11
|
|
19
|
9
|
10
|
2
|
12
|
|
20-21
|
13
|
10
|
2
|
12
|
|
22-24
|
13
|
11
|
2
|
13
|
|
25-27
|
13
|
13
|
2
|
15
|
|
28
|
13
|
14
|
2
|
16
|
|
29-30
|
17
|
14
|
2
|
16
|
|
31-33
|
17
|
15
|
2
|
17
|
|
34-36
|
17
|
16
|
2
|
18
|
|
37-38
|
17
|
18
|
2
|
20
|