Repository navigation
Fix ARGUMENT_OUT_OF_BOUND for a Decimal constant with more digits than its precision in queries sent to remote shards and parallel replicas - #126652
Conversation
…o other servers
A `Decimal(P, S)` value is bounded only by its native integer, not by `P`:
`toDecimal64(1, 18)` is a `Decimal(18, 18)` holding 1, and
`toDecimal32(0.6, 9) + toDecimal32(0.6, 9)` is a `Decimal(9, 9)` equal to 1.2.
The analyzer printed every `Decimal` constant for another server as
`_CAST('<text>', '<type>')`, and the receiver's `String -> Decimal` conversion
(`readDecimalText`) rejects more integer digits than `P - S`, so `remote()`,
`Distributed`, parallel replicas, `IN` sets, the filter pushdown and
`serialize_query_plan = 1` failed with `ARGUMENT_OUT_OF_BOUND` where the local
query succeeded. Released 26.3 and 26.8 behave the same.
Under the ParallelReplicas CI configuration (`parallel_replicas_local_plan = 1`)
the other replicas hit this error in every run of
`05339_decimal_wide_comparison_scale_overflow`, but the coordinator usually
cancels them first, which is why the test failed only once (PR ClickHouse#126018).
A value with `|raw| >= 10^P` (exactly the condition `readDecimalText` rejects) is
now sent as its native integer reinterpreted into the type,
`_CAST(reinterpret(_CAST('<raw>', 'IntN'), T), T)`: a same-width `reinterpret`
copies the bytes, and the outer `_CAST` over constants keeps
`receivedFromInitiatorServer()` true, so the receiver names the column like the
initiator. Values within the precision keep their text form byte-for-byte.
26.3, 26.8 and 26.9 receivers evaluate the new form exactly. Same form as
ClickHouse#126262 uses for `DateTime64` ticks.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261019-081900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261019-071800 |
|
cc @yakov-olkhovskiy @alexey-milovidov, could you review this and add the |
|
Workflow [PR], commit [c9cfee5] Summary: ✅
AI ReviewSummaryThe PR preserves Final VerdictStatus: ✅ Approve |
CI finish ledger - b6d6662Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261021-090014 |
|
@groeneai 🕵️ Looks good, two small requests:
|
…o shards
The beyond-precision branch of `makeDecimalLiteralASTImpl` now returns
`reinterpret(_CAST('<raw>', 'IntN'), T)`. Both callers of
`columnConstantToExactLiteralAST` (`ConstantNode::toASTImpl` and
`ReadFromRemote`) wrap a result that is not already a `_CAST` to `T` with
`makeCastToTypeNameAST`, so a top-level constant still reaches the other
server as `_CAST(reinterpret(...), T)` and is named like the initiator names
it: the query text the shards receive is byte-identical. Constants nested in
`Array`, `Tuple`, `Map` and `IN` sets lose only an identity cast; the whole
test, and 26.3, 26.8 and 26.9 receivers, give the same results.
The new test cases aggregate `toDecimal64(1, 18)` over two shards, as a
`GROUP BY` key and in a filter, so the initiator merges partial results
whose columns it matches by name. Both fail on master with
`ARGUMENT_OUT_OF_BOUND`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, both addressed in c9cfee5.
|
Related: #126018 (comment)
Related: #124680
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ARGUMENT_OUT_OF_BOUND(Decimal value is too big) inremote,Distributedand parallel-replicas queries with aDecimalconstant that has more digits than the precision of its type, such astoDecimal32(0.6, 9) + toDecimal32(0.6, 9)(aDecimal(9, 9)equal to1.2) ortoDecimal64(1, 18).Description
On 26.8.21.12 (and 26.3.33.24), with a
Decimal(9, 9)columneholding1.2,SELECT count() FROM remote('127.0.0.1', db.t) WHERE e = toDecimal32(0.6, 9) + toDecimal32(0.6, 9) SETTINGS prefer_localhost_replica = 0fails withARGUMENT_OUT_OF_BOUND, while the same filter on the local table returns1. On master it also fails throughDistributed, parallel replicas,INsets, the filter pushdown andserialize_query_plan = 1. It is the failure of05339_decimal_wide_comparison_scale_overflowreported on #126018: under parallel replicas the other replicas failed on_CAST('1', 'Decimal(18, 18)')in every run, and the client saw it only when the error arrived before the coordinator cancelled them.A
Decimal(P, S)value is bounded only by its native integer, so arithmetic andtoDecimal*can produce values with more thanPdigits. The analyzer printed everyDecimalconstant for another server as_CAST('<text>', '<type>'), and the receiver'sStringtoDecimalconversion rejects more digits than the precision.Such a value is now sent as its native integer reinterpreted into the type,
_CAST(reinterpret(_CAST('1000000000000000000', 'Int64'), 'Decimal(18, 18)'), 'Decimal(18, 18)'), the same form #126262 uses forDateTime64. Values within the precision keep their text. 26.3, 26.8 and 26.9 receivers evaluate the new form exactly.Validation: the new test fails on master and passes with the fix, including 50 randomized runs and the parallel-replicas and replicated-database configurations.
Workflow [PR]
Sync PR [sync-upstream/pr/126652]
Version info
26.11.1.872-master(included in26.11and later)