Decimal type
The decimal
type is a numeric data
type with fixed scale and precision suitable for financial and other arithmetic calculations
where the imprecise representation and rounding behavior of float
and double
make those types impractical. The decimal
type is also useful for integers larger than int64 and cases with fractional
values in a primary key.
The decimal
type is a parameterized type that takes precision and
scale type attributes.
Precision represents the total number of digits that can be represented by the column, regardless of the location of the decimal point. This value must be between 1 and 38 and has no default. For example, a precision of 4 is required to represent integer values up to 9999, or to represent values up to 99.99 with two fractional digits. You can also represent corresponding negative values, without any change in the precision. For example, the range 9999 to 9999 still only requires a precision of 4.
Scale represents the number of fractional digits. This value must be between 0 and the precision. A scale of 0 produces integral values, with no fractional part. If precision and scale are equal, all of the digits come after the decimal point. For example, a decimal with precision and scale equal to 3 can represent values between 0.999 and 0.999.
Performance considerations:
Kudu stores each value in as few bytes as possible depending on the precision specified for the decimal column. For that reason it is not advised to just use the highest precision possible for convenience. Doing so could negatively impact performance, memory and storage.
Before encoding and compression:

Decimal values with precision of 9 or less are stored in 4 bytes.

Decimal values with precision of 10 through 18 are stored in 8 bytes.

Decimal values with precision greater than 18 are stored in 16 bytes.