Support DECIMAL widths beyond 38 digits, stored as BIGNUM blobs
The Issue & Context
Previously, DuckDB limited DECIMAL types to a maximum precision of 38 digits, causing errors or imprecise storage when users needed wider decimals, such as those found in BigQuery BIGDECIMAL(77,38) or large financial calculations.
Root Cause Analysis
The existing decimal implementation stored unscaled values in fixed-size integer types (up to 128-bit), which inherently capped the maximum precision at 38 digits. The system lacked a scalable storage and arithmetic tier for decimals exceeding this fixed-width range.
Solution Strategy & Architectural Pattern
This PR introduces a fifth decimal tier using a BIGNUM representation stored as VARCHAR blobs, with a C++ type 'bignum_t'. The decimal width and scale are now stored as uint32_t, allowing widths up to a configurable max (default 1,000,000). The decimal code paths were extended to dispatch on PhysicalType::VARCHAR for wide decimals, integrating bignum arithmetic and conversions alongside existing fixed-size integer tiers. This approach reuses existing dispatch mechanisms and adds bignum-specific helpers for parsing, formatting, and arithmetic, enabling seamless support for arbitrarily wide decimals without breaking existing behavior for <=38 digits.
Key Takeaway for Contributors
When extending numeric types beyond fixed-size limits, layering a new representation as an additional dispatch tier integrated with existing type-switching logic allows scalable precision growth without duplicating code paths or disrupting existing functionality.