Skip to content

Do not use a key or index range built from a constant that holds a NaN inside a container - #116763

Merged
nihalzp merged 14 commits into
ClickHouse:masterfrom
groeneai:nan-in-container-constant-key-condition
Sep 9, 2026
Merged

nihalzp merged 14 commits into
ClickHouse:masterfrom
groeneai:nan-in-container-constant-key-condition

Conversation

@groeneai

@groeneai groeneai commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #106533
Related: #107074
Related: #117501

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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 NaN was used for partition pruning, primary key analysis or a minmax skip index. The NaN may be nested in a tuple, or appear only after the constant is converted to the key type, as in NOT (f < 'nan'). For example, SELECT count() FROM t WHERE NOT (t < (nan, 1.)) over a Tuple key returned 0 instead of the number of rows in the table.

Description

A NaN in a comparison constant became an index range endpoint, ordered by the Field total order, which places a NaN last. SQL does not: (1, 1) < (nan, 1.) is false, so its negation holds for every row, while range analysis concluded the opposite.

extractAtomFromTree already declines a bare NaN constant, but that guard calls Field::isNaN, which sees a scalar Float64 only. This one runs just before the range endpoint is built and uses anyFieldSatisfies with isNaNField, so a NaN at any depth of an Array, Tuple, Map or Object is seen, including one that appears only after the conversion, as in NOT (f < 'nan') over a Float64 key.

The atom is declined, not folded: container equality and ordering flip with the nesting path. [nan, 1.] = [nan, 1.] is 1 while (nan, 1.) = (nan, 1.) is 0, so folding equals to false would drop rows.

Reproduced across partition pruning, primary key analysis and a minmax skip index, on 25.8.34.3 and 26.3.24.4. An Array constant is declined too, but there the total order agrees with SQL, so only scan width changes.

The carrier where a constant becomes a NaN only 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 the MergeTreeSetIndex comparator (#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, minmax and pruning tests are byte-identical with and without this change.


Workflow [PR]
Sync PR [sync-upstream/pr/116763]

Version info

  • Merged into: 26.9.1.1033 (included in 26.9 and later)

groeneai and others added 2 commits August 27, 2026 14:40
…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.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work labels Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Two rounds. In round 1 (95dd3691e914088) my own review and a second model reached the same gap from
opposite sides, so the test grew two arms. In round 2 (b83b2ef31d3f7d7) three further findings all
turned out to be one class, and I declined all three with measurements.

Round 1, fixed in b83b2ef31d3f7d7

finding verdict
❌ notEquals against a NaN-bearing tuple constant, over stored key values that themselves hold a NaN, prunes a row the predicate is true for. Restricting the guard to less and lessOrEquals passes every other arm. AGREE, arm added: 1 before, 2 after
❌ No arm proved an Array constant holding a NaN is declined rather than folded, although the description asserts that folding would drop matching rows. AGREE, arm added: a build carrying that fold answers 0 instead of 1, and reddens no other line
⚠️ Changelog entry said "tuple or array"; rows are only dropped through a tuple nesting path. AGREE, corrected
⚠️ Related: given as a short reference rather than a full URL. AGREE, corrected
💡 Commit message leaves some type names unbackticked. Not correctable without an amend, which the repository rulebook forbids; the follow-up commit complies. noted
💡 Test number 05050 rather than the next free 05045. disagreed: 05045 is taken by #116655, opened the same day against this file

Round 2, declined

All three ask to pin the mechanism (declined rather than indexed) instead of the answer, on paths
where indexing returns the correct answer. An arm there could not fail for a correctness reason.

finding verdict
⚠️ The Array equality arm detects folding but not indexing, so the promised decline is unproven. DISAGREE. True, and measured harmless: master does index that constant, and answers identically on all three Array arms (0/0, 2/2, 1/1). Array comparison follows the same NaN-last order the index range uses, so indexing it is sound and only the scan width changes.
⚠️ The minmax arm does not prove index i is enabled, or that the guard changed its decision. DISAGREE. The arm answers 0 before and 3 after, on binaries with distinct build ids. The table is ORDER BY x while the predicate is on t, so i is the only pruner that can reach it, and bypassing just the new predicate on one binary returns the arm to 0.
⚠️ The Map recursion branch is untested. DISAGREE. ColumnMap::compareAt delegates to the nested Array(Tuple(K, V)) comparator with the same NaN direction, so Map belongs to the Array class rather than the tuple class, and dropping that case cannot change an answer.

A control asserting that index i still prunes for a finite constant would be a reasonable later
addition. It guards against a future silent coverage loss rather than against anything in this change.

@clickhouse-gh clickhouse-gh Bot closed this Aug 27, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local --queries-file 05050_key_condition_nan_in_container_constant.sql on the base commit returns the wrong answer on every run: 50/50 runs fail under the test runner's own randomization, collapsing to a single diff class. No forced settings needed.
b Root cause explained? Field::isNaN (Field.h:456) tests which == Types::Float64, so a NaN inside a Tuple/Array Field answers false. The existing decline for a NaN constant in extractAtomFromTree (KeyCondition.cpp:3927-3951) is gated on it, so the atom is built, NOT (t < c) is inverted to the range [(nan, 1.), +Inf), and Range::less falls through to Field::operator< (Field.cpp:271-273, "Put NaN at the end"), which reports (1., 1.) < (nan, 1.) as true. SQL says false, so the part or granule is dropped although every row matches.
c Fix matches root cause? Yes. The defect is that an atom was built from a constant whose SQL comparison semantics Range cannot model, so the atom is declined at construction, where the same decision is already taken for a scalar NaN. No widened bound, no relaxed range, no no-random-* tag, no guard at the symptom site.
d Test intent preserved / new tests added? No existing test weakened or removed; a 216-test sweep over the nan, key-condition, partition-pruning, minmax and skip-index families shows 0 regressions. New stateless test with 17 asserted lines, 7 of which return the wrong answer without the change. Every arm is proven to detect something: the two keep-pruning arms redden when the predicate is made to fire unconditionally, and the two stored-NaN arms redden under the two narrowings of the guard that all other arms accept (restricting it to less/lessOrEquals; folding equals to ALWAYS_FALSE instead of declining).
e Both directions demonstrated? Yes, on Build-ID-distinct binaries (c0a58d1f… base, 0c8bd079… fixed), 50 runs each: base 0 OK / 50 FAIL, fixed 50 OK / 0 FAIL. Bypassing only the new predicate in a third build returns all six ordering arms to their base values, and a fourth build that folds instead of declining reddens the Array equality arm, so the new code is what changed the answers.
f Fix is general across code paths? Declining at atom construction covers every consumer of element.range in one place: both checkInHyperrectangle overloads, extractPlainRanges, extractBounds, matchesExactContinuousRange. Measured on all three analysis layers that reach it: partition pruning, primary key, minmax skip index. Sibling isNaN sites reviewed: the three key_range guards are container-blind too, but making them recursive would prune harder, and this carrier needs the part kept; tryRewriteFloatLiteralForIntKeyComparison requires Float64 right after its isNaN test, so a container constant is already rejected.
g Fix generalizes across inputs (params/datatypes/wrappers)? The predicate is value-directed, not type-directed, so it is wrapper-agnostic. Exercised on Tuple(Int32, Int32), Tuple(Float64, Int32), Tuple(Float64, Float64), Tuple(Tuple(Float64, Float64), Float64) and Array(Float64); Map and Object go through the same switch. Matrix bounds are measured, not assumed: Tuple(String, Int32) cannot express the query (Code: 386 NO_COMMON_TYPE) and a bare float partition key is rejected (Code: 36).
h Backward compatible? (maintainer-approved exception only) Yes. No new setting, no default change, no serialization or format change, so no SettingsChangesHistory.cpp entry is due. The change can only make an index condition less selective, so no existing setup can start failing, and a query whose constant holds no NaN is unaffected.
i Invariants and contracts preserved? extractAtomFromTree's contract is that returning false leaves the atom FUNCTION_UNKNOWN, which is what the new branch does and what the enclosing scalar-NaN block already does on three of its four paths. out is not mutated before the check, so no partially populated RPNElement escapes. The check sits after that block, every path of which returns, so scalar behaviour is unreachable from the new code and measured unchanged. No locking, allocation or lifetime surface; cost is one type-tag test per analysed atom at analysis time.

Session id: cron:clickhouse-impl-self-slot-57:20260827-155300

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f6483d9]

Summary: ✅


AI Review

Summary

This PR declines KeyCondition atoms when the comparison constant reaches range construction with a nested NaN, and the current head also carries the transformed-key NaN handling from #117501. After re-checking the current code, the updated stateless tests, and every prior review thread, I did not find any remaining correctness, safety, performance, or evidence gaps in the current diff.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit f6483d9.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @Algunenano, could you review this? Field::isNaN only recognizes a scalar Float64, so a NaN inside a tuple constant became an index range endpoint and was then ordered NaN-last by the Field total order, which SQL tuple comparison does not follow, so a negated comparison pruned every part or granule. The atom is declined at construction rather than folded to a constant, because container equality and ordering disagree per nesting path.

Comment thread src/Storages/MergeTree/KeyCondition.cpp Resolved
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.
@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f6483d94d with master 9c307529d (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 21 s compile time in total, 7 of them have a recent master baseline.

Job report

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`.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 12b263e

CI is fully finished on this commit and clean, so there is no failure for this ledger to assign an owner to.

  • 175 check runs in a single workflow run (33131779728): 157 success, 0 failure, 18 skipped. Last completion 2026-08-28T06:11:24Z, Config Workflow and Finish Workflow both green.
  • The 18 skips are the routine set for this diff (Bugfix validation, PGO/BOLT toolchain, Dockers Build, Performance Comparison, PromQL Compliance, Mintlify, integration flaky). No test-matrix job was dropped, so this is a real pass and not a void run.
  • CIDB control at this exact commit: 303360 rows across 158 checks, 0 FAIL/ERROR. The zero is measured rather than missing ingestion.
  • All five Stateless tests (*, flaky check) arms ran and passed, so the new 05050_key_condition_nan_in_container_constant test is not itself flaky.

Session id: cron:our-pr-ci-monitor:20260828-063000

@rschu1ze

Copy link
Copy Markdown
Member

@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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai Replace this test by a minimal reproducible example, not more and not less. Avoid slop like "IEEE rules" and "load-bearing".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @shankar-iyer, could you review this? A comparison constant holding a NaN inside a tuple became an index range endpoint and was then ordered by the Field total order, which puts a NaN after every finite value, so NOT (k < (nan, 1.)) pruned every part instead of returning the rows; the atom is now declined instead.

Comment thread src/Storages/MergeTree/KeyCondition.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a44edc32c97f75c3d44f5eeee1f5180578425d8a

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

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.
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4eedcf0

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

This head is 170 nodes: 143 OK, 22 SKIPPED, 5 red. The diff is 3 files (src/Storages/MergeTree/KeyCondition.cpp plus one stateless test and its reference), 0 under ci/, and none of the 5 reds touches a path it changes.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, amd64) ERRORs at ci/jobs/functional_tests.py:734 with AssertionError: Could not find master builds in S3 before any server starts, so the job validated nothing and reports at job level with no test attributed. Trunk-wide #117433 (mine, open)
Bugfix validation (functional tests, aarch64) same Could not find master builds in S3 abort as the row above #117433 (mine, open)
Finish Workflow / python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py cascade of the two rows above: the hook reds when no per-arch bugfix job reports OK or XFAIL #117433 (mine, open)
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) job-level container-memory abort with no failing test assertion: the shard's nested containers breach the /docker cgroup leaf, which ci/jobs/integration_test_job.py then reports. The earlier owner I posted for this row, #117202, is now in this tree (compare reports behind_by=0) and the shard failed anyway, so it is superseded rather than competing #117411 / #117412 (external, open)
Upgrade check (amd_release) / Error message in clickhouse-server.log (see upgrade_error_messages.txt) Failures: 1/12. The referenced file is 4 lines, and all 4 are Cluster: Code: 198. DB::NetException: Not found address of host: <250-byte host> (DNS_ERROR), with 0 lines of any other error: that is 04725_distributed_async_insert_long_directory_name's deliberately unresolvable Remote hosts leaking into the upgrade log scan, a pre-existing fixture rather than this diff #117284 (mine, open)

Session id: cron:our-pr-ci-monitor:20260901-060000

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@rschu1ze

rschu1ze commented Sep 7, 2026

Copy link
Copy Markdown
Member

@nihalzp , do you like to check this one?

Comment thread src/Storages/MergeTree/KeyCondition.cpp Resolved
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-key-condition Analysis of a filter against a key. KeyCondition turns a WHERE condition into ranges over the pri... groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants