Repository navigation
Do not put a negated comparison into the constraints comparison graph - #121255
Conversation
`NOT (x < c)` is not `x >= c` when an argument can be a `NaN`, so #118216 stopped the CNF conversion from inverting an ordered comparison. `pushNotIn` and `Analyzer::CNF::pushNotIntoFunction` can therefore return an atom that is still negative, which the two places that build the constraints comparison graph did not expect: they asserted `!atom.negative` and then took the atom in as if it were positive. So `CREATE TABLE t (a Int64, b Int64, CONSTRAINT c ASSUME NOT (a < b))` is an exception in a build with assertions, and in a release build it puts `a < b` into the graph for a constraint that states the opposite - after which `optimize_using_constraints` answers `WHERE a < b` from the graph as always true and `WHERE a >= b` as always false. The comparison graph stores plain relations and has nowhere to put a negation, so such an atom is now left out of it. For the same reason the index-hint groups, which read the relation off the function name, no longer derive a hint from a negated atom. Found by BuzzHouse on master: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=a78f42eea9cea494806b50ec12b74dc72367944e&name_0=MasterCI&name_1=BuzzHouse%20%28amd_msan%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=ed38f61d0941cf0a81dd0b410b3a01afbd60eba0&name_0=MasterCI&name_1=BuzzHouse%20%28amd_debug%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=3c54270f07bd67f052bc900f371312f59f73505f&name_0=MasterCI&name_1=BuzzHouse%20%28arm_asan_ubsan%29 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [24de7c4] Summary: ✅
AI ReviewSummaryThis PR hardens the constraints comparison-graph and Final Verdict
LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 17 s compile time in total, 9 of them have a recent master baseline. |
…graph test #118216 was reverted by #121258, so the CNF conversion inverts `NOT (a < b)` into `a >= b` again even for `Float64`. The result of `WHERE a >= b` on the table with a `NaN` row depends on that, which is not what this test is about, so it is no longer checked. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121255&sha=4ce0e19ad7da1a501b440283b2607270955e32b7&name_0=PR&name_1=Fast%20test PR: #121255 Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is a pessimization. However, we can accept the fix for an assertion.
MasterCIis red:BuzzHousehitsLogical error: '!atom.negative'inConstraintsDescription::buildGraphonCREATE TABLE.NOT (x < c)is notx >= cwhen an argument can be aNaN, so #118216 stopped the CNF conversion from inverting an ordered comparison.pushNotInandAnalyzer::CNF::pushNotIntoFunctioncan therefore return an atom that is still negative, which the two places that build the constraints comparison graph did not expect: they asserted!atom.negativeand then took the atom in as if it were positive.So in a build with assertions the statement above is an exception, and in a release build it puts
a < binto the graph for a constraint that states the opposite - after whichoptimize_using_constraintsanswersWHERE a < bfrom the graph as always true andWHERE a >= bas always false.The comparison graph stores plain relations and has nowhere to put a negation, so such an atom is now left out of it. For the same reason the index-hint groups, which read the relation off the function name and would otherwise derive a hint from a constraint that says the opposite, no longer derive one from a negated atom.
CI reports:
Update (2026-10-03): #118216 has since been reverted by #121258, so on current master the CNF conversion inverts ordered comparisons again and the exception no longer happens. This change keeps the comparison graph and the index hints correct for a negated atom regardless, so that re-landing the
NaN-aware inversion (e.g. #112989) does not bring the exception back. The test no longer pins the result ofWHERE a >= bover aNaNrow, which depends on whether the inversion is in place.Related: #118216
Related: #121258
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121255]
Version info
26.10.1.1448-master(included in26.10and later)