Repository navigation
Conversation
…onstant A NaN nested in a container constant was turned into an index range endpoint and then compared under the Field total order, which places a NaN after every finite value. SQL comparison does not follow that order: IEEE makes `1. < nan` and `1. = nan` both false, so `(1, 1) < (nan, 1.)` is false and `NOT (t < (nan, 1.))` holds for every row. Range analysis concluded the opposite and dropped every part or granule, returning 0 rows instead of all of them. `KeyCondition::extractAtomFromTree` already declines to build an atom for a bare NaN constant, but that guard is gated on `Field::isNaN`, which tests `which == Types::Float64` and therefore answers false for a Tuple or Array Field holding a NaN. Add a recursive predicate so the same decision is reached through Array, Tuple, Map and Object. The atom is declined rather than folded to a constant. Container equality and ordering flip with the nesting path, so no type-directed rule is safe: `[nan, 1.] = [nan, 1.]` is 1 while `(nan, 1.) = (nan, 1.)` is 0, and `[(1, 1)] < [(nan, 1)]` is 1 while `((1, 1), 1) < ((nan, 1), 1)` is 0. Folding equals to ALWAYS_FALSE for a container would drop rows that genuinely match. Declining only widens the scan and leaves the answer to the row filter. Three analysis layers reached the defect and are fixed together: partition pruning on a Tuple-typed partition key, primary key analysis on a Tuple(Float64, Float64) key, and a minmax skip index on the same. A bare floating point partition key is rejected with Code 36, but that check does not recurse into Tuple, which is why such a key can exist. Reproduced on 25.8.34.3 and 26.3.24.4. Pruning is also declined for an Array constant holding a NaN, where the total order does agree with SQL. Results do not change there, only the scan width, and only for a query whose constant contains a NaN. Co-Authored-By: Claude Opus 5 <[email protected]>
The regression test only exercised the ordering direction over rows that hold no `NaN`, so two different narrowings of the new guard in `KeyCondition::extractAtomFromTree` passed every asserted line while leaving a wrong-results shape broken. Add one arm per narrowing; no source change. `stored nan notEquals` refuses restricting the guard to `less` and `lessOrEquals`. `Field::operator==` routes `Float64` through `FloatCompareHelper::equals` with `nan_direction_hint = 1`, whose `compare` answers 0 for two `NaN`s, so two `NaN`-bearing tuples are equal in the `Field` total order while SQL tuple equality reports false. Over a `Tuple(Float64, Float64)` key that stores a `NaN`, the point range then contains the granule and the `NOT_IN_RANGE` inversion drops the row `t != (nan, 1.)` is true for. Measured 1 before the change and 2 after, on Build ID distinct binaries. `stored nan array equals` refuses folding the atom instead of declining it. `Array` comparison does follow the same total order, so `[nan, 1.] = [nan, 1.]` is true and the matching row must survive; extending the scalar `equals` to `ALWAYS_FALSE` fold to containers returns 0 instead of 1. Measured on a build carrying that fold, which reddens this arm and none of the fifteen pre-existing ones. Both facts are visible in the file itself: its `truth equals` line records that `(nan, 1.) = (nan, 1.)` is false while `[nan, 1.] = [nan, 1.]` is true, which is why equality and ordering cannot share one rule and why the guard declines rather than folds.
Internal second-model reviewTwo rounds. In round 1 ( Round 1, fixed in
Round 2, declined All three ask to pin the mechanism (declined rather than indexed) instead of the answer, on paths
A control asserting that index |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260827-155300 |
|
Workflow [PR], commit [f6483d9] Summary: ✅
AI ReviewSummaryThis PR declines Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit f6483d9.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
|
cc @rschu1ze @Algunenano, could you review this? |
The regression file did not reach one comparison shape. `NOT (t >= (nan, 1.))` is normalized to a `less` atom, and over a key row that itself holds a `NaN` the `Field`-ordered range `(-Inf, (nan, 1.))` excludes that row while SQL keeps it. Measured on the base build: one row instead of two. The guard is operator-agnostic, so its arms exist to catch a later narrowing. One build carrying an environment-gated variant that skips the guard for a chosen operator gives the whole picture: skipping `less` reddens only the new arm, `greaterOrEquals` reddens five, `greater` and `notEquals` one each, and `lessOrEquals` and `equals` redden nothing, because the ranges they build cannot drop a row. Every operator that can return a wrong answer now has an arm, and no existing arm covered `less`. An `equals` arm on the same table was tried and dropped as vacuous. The wrong answer it showed came from the implicit `_minmax_count_projection`, which this test disables in its first statement.
Index analysis converts the constant to the key type after the `NaN` handling
above it, so a value that is not a `NaN` in the query text can still become a
`NaN`-bearing range endpoint. Checking at the point where the atom is built
covers that:
CREATE TABLE t (t Tuple(Float64, Float64)) ENGINE = MergeTree ORDER BY t
SETTINGS index_granularity = 1;
INSERT INTO t VALUES ((1., 1.)), ((2., 2.));
SELECT count() FROM t WHERE NOT (t < '(nan,1)');
returned 0 with primary key analysis and 2 with an `ENGINE = Memory` copy of the
same rows. A plain `Float64` key against `'nan'` behaves the same with no
container involved, so the two new arms cover a container and a scalar carrier.
Mutation ladder from one build carrying the guard behind environment gates:
keeping the check at its old position reddens exactly the two new arms and
nothing else, restricting it to containers reddens only `converted scalar`, and
dropping the `Tuple` recursion reddens nine arms but not `converted scalar`. Ten
of the twenty arms are wrong on the base commit. A sweep of 686 existing tests
in the nan, key-condition, pruning, minmax and index-analysis families finds no
other output difference between the two positions.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 21 s compile time in total, 7 of them have a recent master baseline. |
The arm asserting that a constant holding no `NaN` still prunes parts looked for `Parts: 1/2` in `EXPLAIN indexes = 1` of `SELECT count() FROM t_partition WHERE NOT (t < (2, 2))`. With `enable_analyzer = 0` that query is answered by `optimize_trivial_count_query` from partition metadata, so the plan is `ReadFromPreparedSource (Optimized trivial count)` with no `Indexes:` section, and the arm read 0 on the `old analyzer` job. Reading a key column keeps a `ReadFromMergeTree` step in the plan under both analyzers. One build carrying an environment-gated guard that declines every container constant shows the arm was not only red but blind there: as written it reads 1 with a correct guard and 0 with an over-declining one under the new analyzer, but 0 in both cases under the old one, while reading a column gives 1 and 0 under both. `still prunes granules` needs no change, and the same build confirms it: its table has no partition key, so the metadata answer does not apply and it already reads 1 and 0 under both analyzers. `optimize_trivial_count_query` is randomized to true in 95% of runs, so the old spelling was wrong in most runs of that job rather than all of them. Ten of the twenty arms are still wrong on the base commit under both analyzers, the reference file is unchanged, and the test goes from 10 of 10 failing to 50 of 50 passing against a server with `allow_experimental_analyzer = 0`.
CI finish ledger - 12b263eCI is fully finished on this commit and clean, so there is no failure for this ledger to assign an owner to.
Session id: cron:our-pr-ci-monitor:20260828-063000 |
|
@groeneai Sorry, I will realistically not have time to check. |
| @@ -0,0 +1,102 @@ | |||
| -- A tuple or array constant that holds a NaN must not be used to skip parts or granules: | |||
There was a problem hiding this comment.
@groeneai Replace this test by a minimal reproducible example, not more and not less. Avoid slop like "IEEE rules" and "load-bearing".
There was a problem hiding this comment.
Done in a44edc3: the test is now one arm, a Tuple(Int32, Int32) partition key holding one row and NOT (k < (nan, 1.)), which returns nothing on master and the row with the fix.
I dropped the two EXPLAIN pruning guards as well instead of keeping them next to it: 57 existing pruning, minmax and key-condition tests fail if the new guard declines every atom, so that direction does not need an arm in this file. The PR description is updated to match.
… example The test carried 20 assertions over 11 tables plus two EXPLAIN pruning guards, which is more than is needed to pin the fix. One partition-key arm is enough: NOT (k < (nan, 1)) over a Tuple(Int32, Int32) partition key returns no rows on master and the row with the fix, measured against a pristine master binary. Pruning for constants that hold no NaN is already covered by the rest of the suite, so the two EXPLAIN guards added nothing that a regression there would not also break.
|
cc @shankar-iyer, could you review this? A comparison constant holding a |
…ttach serialization)
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6) / Container memory budget exceeded (/docker) |
the job's containers breach the /docker cgroup budget and the kernel kills processes inside it, so the shard errors at job level with no test attributed |
#117202 (external, merged 2026-08-31 11:05:36Z), merged master @ 910f9802eca14552b13a4a52bce5146248dd32ab |
Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) / Container memory budget exceeded (/docker) |
same signature | #117202 (external, merged 2026-08-31 11:05:36Z), merged master @ 910f9802eca14552b13a4a52bce5146248dd32ab |
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) |
same signature | #117202 (external, merged 2026-08-31 11:05:36Z), merged master @ 910f9802eca14552b13a4a52bce5146248dd32ab |
The three shard errors are one condition, and none of them can be caused by this PR: its diff is
src/Storages/MergeTree/KeyCondition.cpp plus the two files of one stateless test, which cannot
change how much memory an integration module's containers use. The three failing shards also carry
none of this PR's content. Mergeable Check reports Failed: 3 at this head, so the set above is
complete, and CIDB carries exactly these three failing rows over 285,037 rows ingested at the head.
Container memory budget exceeded (/docker) is the breach itself: docker compose stop signals a
whole cluster at once, so every node that outlives the shutdown deadline reaches gdb at the same
moment, and reading a debug build's stacks costs several GiB per node. A nine-node cluster therefore
asks for roughly the entire nested-container budget, the kernel kills the gdb processes, and the
shard reports the breach with no stacktrace. #117202 serializes that attach, so it addresses the
signature rather than one of its victims.
This head predates that fix: 7fc3004ed25a2dc8aa66428f4f010244dea3046a is not an ancestor of
a44edc32c97f, so I merged master in at 910f9802eca14552b13a4a52bce5146248dd32ab to pick it up
and CI is re-running. The merge is a pure master merge: it adds no commit of my own, its first
parent is the pre-merge head, the resulting tree is byte-identical to the tree I merged locally, and
no contrib/ submodule pin moved.
CH Inc sync was success at this head, so nothing here is exempt.
Session id: cron:our-pr-ci-monitor:20260831-193000
A `NaN` reaches the key range in two shapes: already inside the constant, or only after the constant is converted to the key type. The single arm pins the first one. With the `fieldContainsNaN` call moved back above the conversion block it still passes, so it cannot tell the two placements apart, and the second shape is the one that placement exists for. `NOT (f < 'nan')` over a `Float64` key is that shape: the constant stays a `String` until `convertFieldToType` parses it, so a guard above the block sees no `NaN`. Measured at test level on three binaries built from this tree: pristine master both arms absent FAIL guard above conversion arm 1 present, arm 2 absent FAIL this branch both arms present PASS
`fieldContainsNaN` ran only on the converted constant, which is after `canConstantBeWrappedByDeterministicFunctions` may have replaced it. For `ORDER BY toString(k)` the constant `(nan, 1.)` becomes the string `'(nan,1)'`, which holds no `NaN`, so the atom was built and generic exclusion search dropped the granule holding `(nan, 1.)`: `k != (nan, 1.)` returned one of two rows while the predicate is true for both. The scalar guard above already runs before the transformation, so this only makes the container one symmetric. Pre-existing, and measured identical on master, on the previous head of this branch, and on a build with the guard above the conversion block: 1 row against a truth of 2. With this commit, 2. The later check stays. It is the only one that sees a `NaN` produced by the conversion itself, which the second test arm pins. Its comment loses the nesting-path clause, which now sits at the earlier check.
CI finish ledger - 4eedcf0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task This head is 170 nodes: 143 OK, 22 SKIPPED, 5 red. The diff is 3 files (
Session id: cron:our-pr-ci-monitor:20260901-060000 |
|
@nihalzp , do you like to check this one? |
The branch was based on master at af30b32 (2026-09-08 13:43Z), which predates ClickHouse#117501 "Do not treat a key range as exact when the constant reaches the key transform as a NaN". That fix owns the carrier where the query text holds no NaN and the constant only becomes one while being normalized to the type the key transform reads, which this branch's two guards do not see: they inspect the constant as written and the value after the key chain has mapped it back into key space, not the intermediate one inside the transform helper. Picking the fix up here puts the whole family under test on one tree.
ClickHouse#117501 added the check this earlier guard was standing in for: it inspects the constant after it is normalized to the type the key transform reads, so a container NaN about to be pushed through the chain makes the atom inexact and the range is relaxed instead of exact. With that check in the tree, the guard here declines what the relaxed atom already answers correctly, and declining is coarser: it leaves no key condition at all, while a relaxed one still prunes. Measured on this tree with one binary carrying an env-gated bypass per guard, over 16 carriers (ORDER BY, PARTITION BY and a minmax index over toString and cityHash64; tuple, array and map constants; equals, notEquals, less, its negation, IN and NOT IN; the whole-string literal form) plus two controls pinning that an ordinary constant still prunes: disabling the pre-transform guard alone changes no answer, while disabling the range-endpoint guard alone loses the row of NOT (f < 'nan') over a Float64 key. 05055 passes either way, so neither guard interferes with the relaxation it asserts. The third test arm goes with the guard. It covered the container-plus-transform carrier that 05055 now owns, and it passes with both guards disabled, so it can no longer tell this change from master.
`anyFieldSatisfies` with `isNaNField` is the same predicate over `Array`, `Tuple`, `Map` and `Object`, walked with an explicit worklist instead of the native stack, so a constant whose nesting depth comes from data cannot make the check recurse that deep. It also leaves one copy of the traversal in the tree rather than two.
The two wrong-results arms also hold when every comparison atom is declined, since declining only widens the scan, so neither can see the guard's predicate turning always true and disabling pruning. Measured on a build whose guard declines unconditionally: those two arms stay green while this arm flips from 1 to 0.
Related: #106533
Related: #107074
Related: #117501
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed rows being silently dropped when a comparison constant that holds a
NaNwas used for partition pruning, primary key analysis or aminmaxskip index. TheNaNmay be nested in a tuple, or appear only after the constant is converted to the key type, as inNOT (f < 'nan'). For example,SELECT count() FROM t WHERE NOT (t < (nan, 1.))over aTuplekey returned0instead of the number of rows in the table.Description
A
NaNin a comparison constant became an index range endpoint, ordered by theFieldtotal order, which places aNaNlast. SQL does not:(1, 1) < (nan, 1.)is false, so its negation holds for every row, while range analysis concluded the opposite.extractAtomFromTreealready declines a bareNaNconstant, but that guard callsField::isNaN, which sees a scalarFloat64only. This one runs just before the range endpoint is built and usesanyFieldSatisfieswithisNaNField, so aNaNat any depth of anArray,Tuple,MaporObjectis seen, including one that appears only after the conversion, as inNOT (f < 'nan')over aFloat64key.The atom is declined, not folded: container equality and ordering flip with the nesting path.
[nan, 1.] = [nan, 1.]is1while(nan, 1.) = (nan, 1.)is0, so foldingequalsto false would drop rows.Reproduced across partition pruning, primary key analysis and a
minmaxskip index, on 25.8.34.3 and 26.3.24.4. AnArrayconstant is declined too, but there the total order agrees with SQL, so only scan width changes.The carrier where a constant becomes a
NaNonly while it is normalized for a transformed key belongs to #117501, merged and picked up here, so the guard this PR carried at that position is gone with it. Out of scope: the analyzer's redundant-comparison pass (#112272) and theMergeTreeSetIndexcomparator (#112502).Two arms, one per carrier: each wrong on master, right here, and both lost on a build with the guard bypassed. A third line pins that a finite constant still reaches one granule: it flips on a build whose guard declines every atom, where both arms stay green. 247 key-condition,
NaN,minmaxand pruning tests are byte-identical with and without this change.Workflow [PR]
Sync PR [sync-upstream/pr/116763]
Version info
26.9.1.1033(included in26.9and later)