Details
-
Task
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Many functions and operators in Drill need to handle decimal types. This may mean two formats; an expanded format for use during processing, and a compact format for efficient representation on disk.
Postgres' compact (on-disk) format for the decimal types NumericShort and NumericLong generally fit into a 64 bits:
1 bit for sign 6 bits for scale in NumericShort; 16 bits in NumericLong 7 bits for weight in NumericShort; 16 bits in NumericLong 16 bits for the digits
The expanded (in-memory) format in Postgres is defined in numeric.c as follows:
typedef struct NumericVar { int ndigits; /* # of digits in digits[] - can be 0! */ int weight; /* weight of first digit */ int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */ int dscale; /* display scale */ NumericDigit *buf; /* start of palloc'd space for digits[] */ NumericDigit *digits; /* base-NBASE digits */ } NumericVar;
Additional notes and links to related published papers are in the aforementioned source file.