perf(c/driver/postgresql): speed up decimal128 COPY encoding - #4498
Merged
lidavidm merged 2 commits intoJul 13, 2026
Conversation
Member
|
CC @Mandukhai-Alimaa for review |
BOKJUNSOO
force-pushed
the
optimize-postgresql-decimal128-copy
branch
from
July 10, 2026 09:08
4a44c14 to
38d7938
Compare
lidavidm
reviewed
Jul 12, 2026
lidavidm
left a comment
Member
There was a problem hiding this comment.
It appears we need to use __extension__ __int128 or similar to make GCC happy: https://stackoverflow.com/a/54649367
Contributor
Author
|
Thanks. Fixed in d929cfc by defining |
lidavidm
approved these changes
Jul 13, 2026
Member
|
@Mandukhai-Alimaa want to take a look as well? |
Member
|
Oh wait, you already did. |
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.
Summary
This adds a fast path for PostgreSQL binary COPY encoding of Arrow
decimal128values.The existing path converts every Arrow decimal value to a decimal string, splits
that string into integer/fractional parts, then parses those parts back into
PostgreSQL's base-10000 numeric representation. For
decimal128, we can avoidthat round trip: read the unscaled 128-bit integer directly, align it to
PostgreSQL's 4-decimal-digit groups, and write the numeric digits.
The fast path is guarded by
__SIZEOF_INT128__. Platforms without nativeunsigned __int128support keep using the existing implementation.decimal256is unchanged.Local benchmark
Environment:
adbc_driver_postgresql.dbapi.adbc_ingestv numericdecimal128(38, 6), valuesDecimal(i) / Decimal(100)Before, PyPI wheel
adbc-driver-postgresql==1.11.0:Before, local unpatched Release build from the ADBC source tree:
After this patch:
Testing
PKG_CONFIG_PATH=/opt/homebrew/lib/postgresql@14/pkgconfig \ cmake -S c -B build-local \ -DADBC_DRIVER_POSTGRESQL=ON \ -DADBC_BUILD_SHARED=ON \ -DADBC_BUILD_STATIC=OFF \ -DADBC_BUILD_TESTS=ON \ -DADBC_BUILD_BENCHMARKS=OFF \ -DADBC_WITH_VENDORED_FMT=ON \ -DADBC_WITH_VENDORED_NANOARROW=ON \ -DCMAKE_BUILD_TYPE=Release cmake --build build-local --target adbc-driver-postgresql-copy-test -j 8 ADBC_POSTGRESQL_TEST_URI='postgresql://postgres:password@127.0.0.1:9900/postgres?sslmode=disable' \ build-local/driver/postgresql/adbc-driver-postgresql-copy-testResult:
I also checked PostgreSQL roundtrips for scale 2/6/8/18, negative values,
small fractional values, and 38-digit
decimal128values.