Decode numeric to Decimal128 directly, without text round-trip#34
Merged
Conversation
Owner
|
@qsliu2017 thank you so much for the PR! It’s really great that you took a look at the project, benchmarked it, and The change looks good to me. Could you please add yourself to AUTHORS and fix the lint failures? After |
Replace the numeric_out text round-trip in slot_encoder's read_numeric_decimal128_with_scale with a direct decode of the PostgreSQL numeric varlena: accumulate the base-10000 NumericDigit array into an i128 at the target scale, ported from PG numeric.c internals. The decode lives in a new PostgreSQL-runtime-free pg_type::numeric module (pure, safe `numeric_to_decimal128(&[u8], scale, precision)` with its own NumericDecodeError); slot_encoder just detoasts, slices, calls it, and maps the error. Behavior is unchanged -- same NaN/Inf and out-of-range/precision handling -- and TPC-H Q1 results are identical while the conversion step gets much faster. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0901286 to
5c9ea93
Compare
Contributor
Author
Done. |
Codecov Report❌ Patch coverage is
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Owner
|
@qsliu2017 thanks a lot for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of all, thanks for creating this awesome project!
Profiling pg_fusion on TPC-H Q1,
slot_encoder::datum::read_numeric_decimal128_with_scalewas the top hotspot. It converted each PG numeric by formatting it to a string and then parsing back into an i128.This PR replaces that with a direct decode of the numeric varlena, ported from Postgres' numeric.c.
With this PR, TPC-H Q1 speed up ~2.3x (from ~110s to ~48s, single-threaded) in my laptop.