Repository navigation
Conversation
`KeyCondition` can answer `f <op> const` over a transformed key by building a
range from the transform applied to the constant. `-0.` and `+0.` compare equal
but are distinct values, so a transform that reads the bit pattern maps them to
two different key values while the comparison feeding it treats them as one.
The point range built from one of them then misses the mark holding the other
and a matching row is dropped:
CREATE TABLE t (f Float64) ENGINE = MergeTree ORDER BY toString(f)
SETTINGS index_granularity = 1;
INSERT INTO t VALUES (-0);
SELECT count() FROM t WHERE f = 0; -- 0, expected 1
Exactness is not the lever. `ORDER BY cityHash64(f)` is not injective, so that
atom is already relaxed, and it loses the row too: `relaxed` widens
`can_be_false`, while `equals` is `FUNCTION_IN_RANGE` and its `can_be_true` is
`intersects`, which nothing widens.
Decline the atom instead, in the caller and before the transform runs, so the
direct-CAST fast path inside `applyDeterministicDagToColumn` is covered by the
same check. The constant is read in the domain the comparison happens in
(`dag.input_type`), because that is the domain in which its equality class has
two members. `tryConvertFieldToType` rather than `convertFieldToType`: this path
already treats a constant it cannot apply as "no atom" rather than an error
(`WHERE p = 'not-a-uuid'` over `ORDER BY toUUID(p)`), and a throwing probe would
turn queries that work today into errors. A Null result needs no handling: the
transform's own conversion is accurate and rejects a cast introducing a NULL, so
it cannot have produced a zero from a constant that is not exactly a zero there.
The value is walked instead of testing the type for a float, because both `JSON`
and `Dynamic` are accepted as the argument of a transformed sorting key and
neither reports a float child, which would leave a silent hole exactly where the
consequence is silent wrong results.
…ellings The previous commit declined the atom whenever the constant converted to a floating-point zero in the key transform's input domain. That is more than soundness needs, and it costs pruning where nothing was wrong: measured on 1000 rows with `index_granularity = 8`, `WHERE f = 0` over `ORDER BY (-f)`, `ORDER BY (f * 2)` and `ORDER BY (f + 1)` all went `Granules: 1/125` to `125/125`, while every one of those keys already returned the true count on an all-negative-zero table. `-f` is the only way to write a descending floating-point sort key, so the shape is idiomatic and the predicate is ordinary. Decline only when the transform actually sends the two spellings to key values the index does not compare as equal. Both spellings go through the transform in one column, and the results are compared with `Range::equals`, which is the relation the index itself uses (`accurateEquals`, plain `==` on two `Float64`, so the zeros are equal there). `Field::operator==` is not usable for this: it routes `Float64` through `FloatCompareHelper` and reports `NaN` equal to `NaN`. The probe column is built in `dag.input_type` so that `applyDeterministicDagToColumn` finds its input type already correct and executes the same transform the index applied; entering with a plain `Float64` column can instead take the direct-CAST fast path, which casts to the CAST's result type without normalizing to the key's input type. The probe cannot round-trip through the constant's own type either: for `WHERE f = 0` the constant is a `UInt64`, `convertFieldToType(-0., UInt64)` is `0`, both probe rows would become identical and the ordinary spelling would stay broken. A non-floating-point input domain cannot hold the other spelling and its columns need not accept a `Float64` value, so it is declined rather than probed. A dynamically typed input domain (`Dynamic`, `Variant`, `Object`) is declined before the constant is looked at, because there a value of one type equals a value of another: a stored `Float64 -0.` equals a `0` written as a `UInt64`, so the constant does not determine which values it stands for, and the converted constant need not be a float at all. The test is recursive because a `Tuple(Dynamic)` holding `(-0.)` loses a row the same way. If the type comparison in `applyDeterministicDagToColumn` ever changes, the probe's entry assumption is what breaks. No `try`/`catch` is added here: the helper calls the declared `try` form of the shared converter, and `applyDeterministicDagToColumn` owns the existing `catch`.
Five scenarios: `equals` and `notEquals` with the ordinary `WHERE f = 0` spelling, a zero nested in a tuple constant, and two controls that must keep pruning - a non-zero constant on a separating transform, and a zero constant on `ORDER BY (-f)`, which sends both spellings to key values the index compares as equal.
The changelog entry claims the sorting key, the partition key and a `minmax` index, and the description claims `equals`, `notEquals` and `isNotDistinctFrom` plus the decline on a dynamically typed input domain. The test pinned only `ORDER BY` transforms with `equals` and `notEquals`, so four claimed surfaces had no regression coverage even though every one of them is a measured carrier. Four scenarios are added, each an all-negative-zero table read back with the ordinary integer-spelled constant: `IS NOT DISTINCT FROM`, a `PARTITION BY toString(f)` key, an explicit `INDEX ... toString(f) TYPE minmax`, and a `Dynamic` column plus a `Tuple(Dynamic)` one. The `Dynamic` constant is spelled `toUInt64(0)::Dynamic`: a bare `0` never reaches key analysis against such a column, and the `UInt64` spelling is the one a guard that looks at the constant instead of the domain misses, so it is what makes the domain test load-bearing. The `Tuple(Dynamic)` scenario is what pins the recursion through `forEachChild`; deleting that line leaves every other row green.
…ive pruning control Two gaps in the test, both found by measuring rather than by reading. The `notEquals` row was setting-dependent. Its count can be answered from part metadata by an implicit projection, and the metadata is exactly what the wrong range describes, so with the projection path enabled the count returns 1 while a read-and-filter returns 0. The runner randomizes that path off in about a tenth of runs, and in 7 of 50 measured runs on a pristine binary the row therefore agreed with its own ground truth and could not distinguish the defect. It now carries a query-level clause pinning both projection settings to their defaults. Pinning only the child is not enough: the test runner declares `optimize_use_implicit_projections` as conditional on `optimize_use_projections` and forces the child off whenever the parent is off, which was measured to defeat a child-only pin. With both pinned, all eight carrier rows fail on a pristine binary in every combination of the two settings, and 50 randomized runs produce a single reddening set instead of two. The `minmax` skip index had no control proving it still prunes. A scenario with a non-zero constant is added whose plan row is the skip index's own granule count, so the coverage cannot evaporate silently while the test still passes. It is proven live, not constant: under a mutant that declines every atom on this path the row disappears, because there is no granule line to extract when the index is no longer consulted. An equivalent control for the partition pruner is not included. The automatic part-level min-max index on the partition key's column runs first and is handed the same predicate, so it prunes every non-matching part by itself and the partition pruner can only ever report one part out of one. The only pair of `Float64` values a range comparison cannot separate is `-0.` and `+0.`, which is the defect itself, so a non-zero fixture cannot attribute a strict reduction to the partition pruner. The partition key keeps its carrier and ground-truth pair, whose liveness two other mutants already establish. No source change: `src/` is byte-identical to the previous commit.
Two pruning controls, each measured on both binaries and each held in place by a named mutant rather than by assertion. A non-zero constant on a `PARTITION BY toString(f)` key asserts that the transformed atom still reaches the partition pruner. The assertion counts the `Partition` section's own `Condition:` line naming `toString(f)` instead of extracting its text, so a later change to how ranges are printed cannot fail the test with a confusing diff. A `Parts:`-based control cannot work here: the automatic part-level Min-Max index over the partition key's column runs first and prunes every non-matching part by itself, so the `Partition` section can only ever report `Parts: 1/1`. Proven live by the mutant that declines every constant, under which the `Keys:`/`Condition:` pair collapses to `Condition: true`. A non-zero constant inside a tuple asserts that a container constant holding no zero still builds a pruning range. That is the accept direction of the container branch, and replacing it with an unconditional decline leaves every previously shipped row green, because declining is the safe direction and the tuple carrier row cannot tell the difference. A new mutant does exactly that, and now moves this row and nothing else. Neither row can be answered from part metadata: the partition control's `EXPLAIN` reads rows rather than counting them, and the tuple control's three rows live in one part, so its predicate is never always-true for a part. Both rows are byte-identical on the base and fix binaries in all four combinations of `optimize_use_projections` and `optimize_use_implicit_projections`. The comment above the `notEquals` row now names the always-true step that makes that row depend on the projection settings. No source change: `src/` is byte-identical to the previous commit.
Internal second-model reviewFour rounds of independent review ran against this change before it was opened.
Round 4 changed nothing. The delta was verified by reading rather than by Two things worth flagging. For whoever lands #115970: making The Session id: cron:clickhouse-review-self-slot-58:20260902-022500 |
|
Workflow [PR], commit [8278b1c] Summary: ❌
AI ReviewSummaryThis PR teaches Findings
Final Verdict
LLVM Coverage Report |
Pre-PR validation gate (click to expand)
Regression sweep: 139 tests ( 50 randomized runs of the final 28-row test twice, once alone and once under a concurrent 50-test neighbour batch at Session id: cron:clickhouse-impl-self-slot-57:20260902-004700 |
|
cc @nihalzp @shankar-iyer, could you review this? Key analysis pushes the comparison constant through the key transform and uses the result as a range, but |
A `Variant` domain compares values of different alternatives as equal, and a
constant there can sit on the integer alternative, so the constant carries no
floating-point value at all while still standing for a stored `-0.`. Only the
test on the domain catches that: the walk over the constant's own value sees an
integer and accepts the atom.
That member had no row of its own. Deleting `Variant` from the domain test left
every shipped row green while `WHERE v = toUInt64(0)::Variant(Float64, UInt64)`
went back to dropping the mark holding `-0.` on a `Variant(Float64, UInt64)`
key, measured on both binaries. The new scenario is the missing pin: a mutant
that deletes exactly that member now moves this row and nothing else, while the
mutant that deletes `Dynamic` moves the two `Dynamic` rows and leaves it green.
`JSON` cannot be pinned the same way. Every `JSON` constant measured here that a
stored `-0.` compares equal to carries a floating-point zero inside it, so the
walk over the constant's value declines it before the domain is consulted, and
the one spelling whose value holds no float, `'{"a":0}'::JSON`, does not compare
equal to a stored `-0.` at all.
No source change: `src/` is byte-identical to the previous commit.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+35.04 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units10 translation units recompiled, 23 s compile time in total, 10 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.91 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…note a zero The screen declined every constant whose key transform reads a dynamically typed column. That withdrew pruning an existing test asserts: over ORDER BY (json.a, json.b::String), the atom json.b = 'str_0' lost CAST(json.b, 'String') from the condition and read 2/8 granules instead of 1/8, in 03277_json_subcolumns_in_primary_key. Such a domain compares values across types, so a stored -0. equals a zero written as an integer, as a decimal, or as a string that parses as one, and each of those spellings still has to be declined. A constant that denotes no number stands for itself alone there, so the range built from it is sound and is kept. The two new test rows pin both directions: a zero written as a string is still declined, and a constant denoting no number keeps Granules: 1/3.
CI caught an over-decline in the guard; narrowed in
|
| auto check = [&](const IDataType & child) | ||
| { | ||
| const WhichDataType which(child); | ||
| result = result || which.isDynamic() || which.isVariant() || which.isObject(); |
There was a problem hiding this comment.
Variant is not unconditionally a "dynamic-domain" comparison here. With use_variant_default_implementation_for_comparisons = 0, the comparison functions bypass the default Variant adaptor and fall back to native Variant semantics, where UInt64(0)::Variant(Float64, UInt64) no longer matches a stored Float64(-0.) just because the numeric values are equal.
This branch still declines the atom for every zero-like Variant constant, so a transformed key such as ORDER BY toString(v) (or any other exact transform over v) loses valid pruning under that supported setting. KeyCondition needs the same setting split that the comparison path already has, and it needs a regression with use_variant_default_implementation_for_comparisons = 0.
…the two zeros `keyTransformCanSeparateEqualValues` tested two things independently: whether the key expression's input type contained a dynamically typed member anywhere, and whether the constant held a zero anywhere. So a zero sitting under a fixed-typed member of a mixed container tripped the widened "any spelling of a zero" rule that only a dynamically typed member needs. `Tuple(UInt64, Dynamic)` with the constant `(0, 1)` is the smallest case. The zero is on the `UInt64` member, which has a single spelling of zero and cannot hold a stored `-0.`, so the atom was exact; it was declined anyway and the key stopped pruning altogether, measured as `Granules: 1/5` becoming `5/5`. Walk the constant together with its type and choose the leaf test per member: any spelling of a zero under a dynamically typed member, only a `Float64` zero elsewhere. A value that does not have the shape of its own type cannot be read, so it is declined. Two rows pin both directions. A zero on the dynamic member of a mixed container still declines, which also pins the positional pairing between elements and element types; a zero on the fixed-typed member beside it keeps its granule count.
`Build (arm_tidy)` runs clang-tidy with `-warnings-as-errors`, and `readability-container-data-pointer` rejects `&entry_elements[0]`. The value member is spelled the same way so the key and the value read alike. No behaviour change: the `Map` entry is checked to be a two-element tuple immediately above.
CI finish ledger - 8278b1cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260902-193000 |
…elling of a zero `IN` on a floating point column now matches a stored `-0.` against a set that contains `0.`, but `tryPrepareSetColumnsForIndex` pushed each set element through the sorting key transform as written. With a key like `ORDER BY reinterpretAsUInt64(f)` the element `0.` becomes the key value `0` while the stored `-0.` lives at `0x8000000000000000`, so `MergeTreeSetIndex::checkInRange` could report `can_be_true = false` and prune away a granule that row evaluation matches. The transform is injective there, so `out.relaxed` is not set and nothing masked the over-pruning. Decline the set index for such a transform: when the set holds a floating point zero at any depth and the key transform sends `-0.` and `0.` to key values the index compares as unequal, the atom is left to row evaluation. The screen looks at the elements that are actually in the set, so pruning is kept when the set has no zero in it, and it is value-independent on a domain whose type is only known at runtime, where one pair of probes cannot decide the whole value. The same composition on the `equals` / `notEquals` / `isNotDistinctFrom` atoms is fixed separately in #117611. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Closes: #117543
Related: #115970
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a lost row when a floating-point column is filtered with a zero constant and the sorting key, partition key or a
minmaxindex applies a transform to that column, for exampleORDER BY toString(f)withWHERE f = 0.-0.0and0.0compare equal buttoStringmaps them to different key values, so the primary key dropped the granule holding the other spelling. Closes #117543.Description
A filter on a zero silently returned fewer rows than a full scan when the sorting key, partition key or a
minmaxindex transformed the columnf:Root cause: over a transformed key, analysis pushes the constant through the transform and uses the result as a range.
-0.and+0.compare equal but are distinct values, so a transform reading the bit pattern maps them apart, and a range built from one misses the mark holding the other. Exactness is not the lever:ORDER BY cityHash64(f)is already relaxed and still loses the row, because relaxing widenscan_be_falsewhileequalsneedscan_be_true.The atom is now declined when the transform is measured to separate the constant's equality class: both spellings go through it in one column, compared with the index's own relation. Only a
Dynamic,VariantorJSONmember compares values across types, so a zero under such a member stands for a stored-0.in any spelling, a string that parses as one included, and is declined; a zero on a fixed-typed member beside it does not, nor does a constant denoting no number.This covers
=,!=andisNotDistinctFrom; theINset index reaches key space throughtryPrepareSetIndexForInand is untouched.Measured cost, in granules: a zero constant on a separating transform stops pruning (
1/125to125/125), as does a key whose image cannot hold-0.(2/65to65/65).ORDER BY (-f)keeps them equal and prunes as before; that ships as a test.LowCardinality(Float64)is not fixed here (#116637): the column collapses the two spellings on insert while the index does not.Workflow [PR]
Sync PR [sync-upstream/pr/117611]
Workflow [PR]
Sync PR [sync-upstream/pr/117611]