Repository navigation
Conversation
…anule is not MergeTreeIndexConditionSet reused the predicate's pre-resolved function nodes on the granule block. When the predicate is resolved at a Nullable type (query uses toNullable(), or an MV declares the column Nullable) while the granule column is the plain storage type, ExpressionActions::execute produced a non-Nullable result and tripped the function result_type invariant: 'Unexpected return type from equals. Expected Nullable(UInt8). Got UInt8'. Fix: in atomFromDAG, add an INPUT of the granule storage type and a CAST back to the type the predicate expects when the two differ, so the pre-resolved functions see their resolved types while the granule block stays unchanged. Closes ClickHouse#89802. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260714-070000 |
|
cc @rschu1ze @shankar-iyer — could you review? Fixes a LOGICAL_ERROR in |
|
Workflow [PR], commit [5c4b643] Summary: ❌
|
…pe predicates correct A mixed predicate reusing the same set-index expression at different types, e.g. WHERE (t % 19) = 1 OR (t % toNullable(19)) = 2, canonicalizes both branches to the same column name modulo(t, 19). The name-only key_column_inputs cache returned the first branch's adapted node for the second, so the plain and Nullable uses shared one node and the wrong-typed branch again hit "Unexpected return type from equals. Expected Nullable(UInt8). Got UInt8". Cache the storage-typed INPUT once per column and memoize the adapted node (raw INPUT or its CAST) by (column name, expected type). Regression covers both AND/OR orders of mixed plain and Nullable use of one set-index expression. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed in 9e3d7b2. The name-only Confirmed the exact bug on the pre-fix build: the mixed predicate reproduces |
CI finish ledger — 9e3d7b2Both failures below are the chronic trunk "Unexpected return type" AST-fuzzer family (STID 1611-*), not caused by this PR. This PR only touches
Session id: cron:our-pr-ci-monitor:20260714-133000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 37/38 (97.37%) · Uncovered code |
CI finish ledger - 112e5e8Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-120000 |
|
Two AST-fuzzer aborts today reach The two rows (STID Same broken invariant this PR repairs, arriving with a
The Measured on a debug build at
So the set index is genuinely consulted on the This PR's guard is Worth noting for whoever lands this: #113244 fixes the same lines differently, returning For the record, this route is distinct from the |
|
Closing in favour of #113244 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR("Unexpected return type from ...") when a query filters on asetskip-index expression whose predicate is resolved at aNullabletype while the granule column is the plain storage type. This happens when the query wraps the indexed expression argument withtoNullable()(e.g.t % toNullable(19) = 2), or when the column is read through aMaterializedViewthat declares itNullable.Description
MergeTreeIndexConditionSetrebuilds the WHERE predicate onto the granule block, reusing the predicate's pre-resolved function nodes. Those functions may be resolved against aNullableargument type (from atoNullable()in the query, or from an MV_CASTto a declaredNullabletype), while the granule block carries the indexed expression at its plain storage type.ExpressionActions::executethen runs the function on the non-Nullablegranule column, produces a non-Nullableresult, and trips theresult_typeinvariant:Fix: in
MergeTreeIndexConditionSet::atomFromDAG, record each key column's granule (storage) type and, when it differs from the type the predicate expects, add anINPUTof the storage type plus aCASTback to the expected type. The pre-resolved functions then see the type they were resolved for, keeping theresult_typeinvariant intact while the block fed into the actions stays the storage column unchanged. The skip index continues to prune granules as before.Found by the server-side AST fuzzer (STID 1611-11ad/4523/447a/483a, 3262 family) on
01786_explain_merge_tree; also reported as issue #89802 (MV variant). Reproduces deterministically on a debug build: