Repository navigation
Conversation
Three or more OR-ed equality comparisons on a Variant expression whose alternative is an Array or a Tuple were merged into an `in` whose set `getSetElementsForConstantValue` cannot place, so the query was rejected with `Unsupported types for IN` while one comparison and a raised `optimize_min_equality_disjunction_chain_length` both answered it. Whether the query is accepted therefore depended on how many comparisons were conjoined. `getSetElementsForConstantValue` decides by nesting depth whether to read the constant right-hand side as the list of set members (depths differ by one), as one whole value (depths equal), or neither, in which case it throws. `getCompoundTypeDepth` unwraps Nullable and descends Array and Tuple but not Variant, and the pass writes the literals with the alternative's type rather than the Variant's, so `Variant(Array(Int64))` measures 0 against the built `Tuple(Array(Int64), ...)`'s 2 and no branch matches. The throw fires at planning time from CollectSets, not while the pass runs, so `EXPLAIN QUERY TREE` succeeds and the pass cannot detect the failure by resolving the node: a predicate is required. Both chain-to-`in` seams now decline when any literal does not sit at the expression's own depth, asking a predicate exported from SetUtils rather than restating the depth rules in the pass. Declining hands the chain back to the comparisons it was built from, so the outcome becomes the unmerged chain's own: the correct answer for the shapes above, and, for the one mixed-depth shape described below, the error that chain already raises. The notEquals seam is guarded for symmetry with the `hasDynamicStructure()` screen beside it even though it is measurably inert for this shape at default settings. Widening the set builder instead was refuted by measurement: on a `Variant(Array(Date), Array(UInt64))` column a hand-written `IN` already answers 0 where `=` answers 1, because a set element is rebuilt from a Field that carries no discriminator, so admitting more Variant pairs would replace an explicit error with silent wrong results. That faithfulness defect is separate and has to land first. Requiring every literal at the expression's depth is stricter than the set builder, which looks only at the first element. One shape changes as a result: `v = 1 OR v = [2] OR v = 3` on `Variant(Int64, Array(Int64))` answered 2 by silently dropping the unconvertible member, and now raises, verbatim, the same `Illegal types of arguments ... of function equals` the unmerged chain raises. The test asserts that error, so the change is pinned rather than only described. The alternative, a first-element-only screen, would decline `v = [1] OR v = 2 OR v = 3` and admit `v = 2 OR v = [1] OR v = 3`, and that same test row is what fails under it. A hand-written `IN` on the affected shape is unchanged and still throws. Related: ClickHouse#121146 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings in both rounds) plus a
Verified against the code rather than assumed:
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260920-140800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260920-134600 |
|
Workflow [PR], commit [e259375] Summary: ❌
AI ReviewSummaryThis PR teaches the logical-expression optimizer to skip Final Verdict✅ No blocking issues found in the current diff. LLVM Coverage ReportMeasured on commit e259375.
Changed lines: Changed C/C++ lines covered: 27/28 (96.43%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 9c7ca2fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The red CIDB carries zero FAIL/ERROR test rows at this sha, and the dedupped check-run census is Session id: cron:our-pr-ci-monitor:20260921-000159 |
Related: #121146 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Three or more
OR-ed equality comparisons on aVariantcolumn whose alternative is anArrayor aTuplewere merged into anINwhose set cannot be built, so the query was rejected withUnsupported types for INwhile one comparison and a raisedoptimize_min_equality_disjunction_chain_lengthboth answered it. The merge is now skipped for such a pair.Description
Whether a query is accepted must not depend on an optimizer threshold. On master at defaults:
One term answers 1, and these three answer 3 at threshold 100.
Variant(Tuple(Int64))too.Root cause:
getSetElementsForConstantValuedecides by nesting depth whether the constant is the list of members or one value, andgetCompoundTypeDepthdescendsArrayandTuplebut notVariant. The pass builds the right-hand side from the literals' own types, soVariant(Array(Int64))measures 0 against the tuple's 2, no branch matches, and the terminal throw fires at planning time.I decline the rewrite at both chain-to-
INseams when a literal does not sit at the expression's own depth, through a predicate exported fromSetUtilsrather than a copy of its arithmetic.convertNotEqualsChainToNotInis guarded for symmetry with thehasDynamicStructure()screen beside it, though that seam is measurably inert here. The other passes that build anINfrom constants cannot reach such a pair; I read both.I did not widen
INinstead: onVariant(Array(Date), Array(UInt64))a hand-writtenINanswers 0 where=answers 1, so admitting more pairs would turn an explicit error into silent wrong results.One shape changes: requiring every literal at that depth is stricter than the set builder, which looks only at the first, so
v = 1 OR v = [2] OR v = 3onVariant(Int64, Array(Int64))answered 2 by silently dropping the unconvertible member and now raises the error the unmerged chain already raises. Making it answer needs the set path to carry aVariantdiscriminator, a separate defect. Say the word and I will fold that in.Workflow [PR]
Sync PR [sync-upstream/pr/121196]