Repository navigation
Conversation
`KeyCondition` (and partition pruning, primary-key analysis, min-max, skip indexes - all paths sharing `cloneDAGWithInversionPushDown`) rewrote `not(greater(x, c))` into `lessOrEquals(x, c)` via the `inverse_relations` table. This algebraic identity is invalid under IEEE-754: when `x` is NaN, `not(NaN > c)` is `not(false) = true`, while the candidate inverse `NaN <= c` is `false`. With `ORDER BY c0 PARTITION BY c0` and `c0 = -1`, partition pruning translated `not(sqrt(c0) > 10)` into `sqrt(c0) <= 10` and incorrectly dropped the partition where `sqrt(c0)` is NaN, returning empty results from queries that should keep that row. Skip the inverse rewrite for the six comparison ops (`<`, `>`, `<=`, `>=`, `=`, `!=`) when an operand can be NaN - either a non-constant floating-point column, or a constant `NaN` value. The fallback `not()` wrapper at the end of the function preserves the correct semantics; the inner comparison still drives index analysis. Plain literal cases like `c <= 5.5` (Int column vs Float literal) keep their full inversion since neither operand can be NaN. Closes: ClickHouse#106533 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-ci-task-worker:20260605-120200 |
|
cc @KochetovNicolai @CurtizJ — could you review this? It fixes wrong-results in partition and primary-key pruning where |
|
Workflow [PR], commit [62cb6e6] Summary: ❌
AI ReviewSummaryThis PR fixes an invalid Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 18/20 (90.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code |
CI ledger — covered SHA: 62cb6e6CI fully finished (Finish Workflow + Mergeable Check completed at 17:48:23Z, >20 min buffer).
No PR-caused failures. 144 pass / 19 skip / 1 chronic-tracked + 2 derivative. Ball with reviewers (@KochetovNicolai, @CurtizJ). Session: cron:our-pr-ci-monitor:20260605-190000 |
|
Superseded by #107074. While fixing #106948 (minmax skip index dropping NaN granules under a negated float range, flagged as a possible duplicate of #106533), I found that issue needs both this |
KeyCondition::cloneDAGWithInversionPushDown(used by partition pruning, primary-key analysis, min-max indexes, and skip indexes) rewritesnot(greater(x, c))intolessOrEquals(x, c)via theinverse_relationstable. This algebraic identity is invalid under IEEE-754: whenxis NaN,not(NaN > c)isnot(false) = true, while the candidate inverseNaN <= cisfalse.With
ORDER BY c0 PARTITION BY c0onINSERT INTO t VALUES (1), (-1), partition pruning translatednot(sqrt(c0) > 10)intosqrt(c0) <= 10and incorrectly dropped thec0 = -1partition wheresqrt(c0)is NaN. The metamorphic equivalence in the issue body broke as a result:The fix skips the inverse rewrite for the six comparison ops (
<,>,<=,>=,=,!=) when an operand can be NaN: either a non-constant floating-point column, or a constantNaNvalue. The fallbacknot()wrapper at the end ofcloneDAGWithInversionPushDownpreserves the correct semantics; the inner comparison still drives index analysis. Plain literal cases likec <= 5.5(Int column vs Float literal) keep their full inversion since neither operand can be NaN. Decimal is unaffected: it has no NaN.Closes: #106533
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong-results bug where partition and primary-key pruning rewrote
NOT (f(x) > c)intof(x) <= cfor floating-point operands, dropping rows wheref(x)is NaN. After the fix the inversion is skipped for the six comparison operators when an operand can be NaN, soWHERE NOT (sqrt(c0) > 10)keeps rows whosesqrt(c0)is NaN as IEEE-754 requires.Documentation entry for user-facing changes