Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK when a set skip index is used with a row policy - #107971
Merged
Merged
Conversation
A SELECT on a table with a `set` data-skipping index could throw `NOT_FOUND_COLUMN_IN_BLOCK` when a row policy `USING` expression contained a constant-true term expressed as a function (e.g. `arrayExists(x -> 1 = 1, [...])`) OR-ed with a term that references a non-indexed column. `MergeTreeIndexConditionSet::atomFromDAG` returned a constant-folded `FUNCTION` node verbatim. Such a node carries a constant value but still keeps its argument subtree, which may reference columns that are not part of the index. `ActionsDAG::cloneSubDAG` then pulled those foreign `INPUT`s into the per-index `actions`, which failed at read time (lazy per-granule skip-index filtering in `MergeTreeSelectProcessor`) because the set granule block only carries the index's own column(s). The same predicate written directly in `WHERE` is constant-folded into a bare literal before reaching the index condition, so it only reproduced via the row-policy filter. Re-add a constant-folded function node as a fresh leaf constant so its now irrelevant argument subtree is dropped from `actions`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [2d97ada] Summary: ❌
AI ReviewSummaryThis PR fixes the Final VerdictStatus: ✅ Approve |
Per review: the folded-FUNCTION leaf-constant fix in atomFromDAG created a new ColumnConst from the node's value. ActionsDAG::Node::column is already a ColumnConstPtr (COW) and addColumn normalizes the row count, so pass the existing column directly - avoids the Field extraction and column rebuild.
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 6/7 (85.71%) | Lost baseline coverage: none · Uncovered code |
Contributor
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
alexey-milovidov
pushed a commit
to m-selmi/ClickHouse
that referenced
this pull request
Jun 28, 2026
Building a secondary (skip) index during an INSERT runs granule by granule in `MergeTreeDataPartWriterOnDisk::calculateAndSerializeSkipIndices` with no cancellation point. The INSERT pipeline only enforces query limits between blocks (`MergeTreeSink::consume`), so once execution is inside `writeTempPart` -> writer -> skip-index build, a `KILL QUERY` cannot interrupt it. An unbounded `set(0)` index on a high-cardinality column with a small `GRANULARITY` makes that build run for minutes, which tripped the 60s hung-check in `Stress test (arm_tsan)` even though the query was already cancelled (`is_cancelled = 1`). Check the query status once per granule via `checkTimeLimit`, mirroring the existing precedent in `MergeTreeIndexVectorSimilarity`. This covers every skip-index type in one shared place and honors both cancellation and `max_execution_time` (throw mode). `set(0)` semantics are unchanged. Related: ClickHouse#107971 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
Building a secondary (skip) index during an INSERT runs granule by granule in `MergeTreeDataPartWriterOnDisk::calculateAndSerializeSkipIndices` with no cancellation point. The INSERT pipeline only enforces query limits between blocks (`MergeTreeSink::consume`), so once execution is inside `writeTempPart` -> writer -> skip-index build, a `KILL QUERY` cannot interrupt it. An unbounded `set(0)` index on a high-cardinality column with a small `GRANULARITY` makes that build run for minutes, which tripped the 60s hung-check in `Stress test (arm_tsan)` even though the query was already cancelled (`is_cancelled = 1`). Check the query status once per granule via `checkTimeLimit`, mirroring the existing precedent in `MergeTreeIndexVectorSimilarity`. This covers every skip-index type in one shared place and honors both cancellation and `max_execution_time` (throw mode). `set(0)` semantics are unchanged. Related: ClickHouse#107971 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…w-policy-not-found-column Fix `NOT_FOUND_COLUMN_IN_BLOCK` when a `set` skip index is used with a row policy
This was referenced Sep 24, 2026
pull Bot
pushed a commit
to Mu-L/ClickHouse
that referenced
this pull request
Sep 25, 2026
…ition rewrite On 26.6, a filter that combines a condition on a column carrying a `set` skip index with `coalesce(nullIf(c2, ''), nullIf(c3, ''), 'x') = 'v1'` over columns that index does not cover fails index analysis with Code: 10. Not found column c2 in block: while executing 'INPUT : 1 -> c2 String : 5' ... (NOT_FOUND_COLUMN_IN_BLOCK) and `EXPLAIN indexes = 1` fails identically, so the fault is in analysis rather than execution. Reported in ClickHouse#121912 against a Cloud build, reproduced here on the official OSS binaries 26.6.1.1193 and 26.6.8.7 with plain MergeTree. The mechanism. ActionsDAGWithInversionPushDown is built once per filter and is the shared input to KeyCondition and to every skip-index condition, which is how a setting read only in KeyCondition.cpp changes what a set index sees. With allow_key_condition_coalesce_rewrite enabled, tryRewriteCoalesceComparison turns the comparison into a disjunction whose last disjunct carries 'x' = 'v1'; that is false, so the disjunct folds to a constant FUNCTION node which still retains its argument subtree over c2 and c3. Before ClickHouse#107971, atomFromDAG returned that folded node verbatim, so cloneSubDAG pulled INPUT c2 into the index's actions while the per-granule block holds only the indexed column c1. ClickHouse#107971 fixed it by re-adding a constant-carrying FUNCTION as a leaf constant, which is why 26.7 and later are green. It was never backported, so every 26.6 release including 26.6.8.7 still throws; whether it should be is a maintainer's call, not something to hand-author here. The coalesce rewrite is a second, independent entry point into that defect. ClickHouse#107971's own test pins only the row-policy entry point, and of the five existing coalesce/skip-index tests in 0_stateless none uses TYPE set, so this shape was uncovered. The test pins both spellings that throw (coalesce with a trailing constant, and the ifNull spelling over a single uncovered column), each against its setting-off control, and asserts that i1 is still analysed so the count assertions cannot pass vacuously. allow_key_condition_coalesce_rewrite and use_skip_indexes are pinned per query rather than with a blanket no-random-settings tag, since use_skip_indexes = 0 is the one setting that makes the shape green even unpatched. index_granularity is pinned in CREATE TABLE because the runner randomizes it over 1..65536. Reverting the ClickHouse#107971 guard on master makes this test fail 10/10 with the original error; restoring it passes 20/20. 150 randomized runs are green across three randomizer arms. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A
SELECTon aMergeTreetable that has asetdata-skipping index throwsNOT_FOUND_COLUMN_IN_BLOCKwhen the querying user is subject to a row policy whoseUSINGexpression has a constant-true term expressed as a function (e.g.arrayExists(x -> 1 = 1, [...])) OR-ed with a term that references a column the index does not cover.The same predicate written directly in
WHEREis constant-folded into a bare literal before reaching the index condition, so it reproduces only via the row-policy filter. Switching the index tobloom_filteravoids it. Reproduced on 26.2, 26.5 and current master.Root cause
MergeTreeIndexConditionSetbuilds anExpressionActions(actions) from the filter that is executed per index, over a granule block that contains only that index's own column(s). InMergeTreeIndexConditionSet::atomFromDAGa node that carries a constant column was returned verbatim:When constant-folding reduces
or(arrayExists(x -> 1 = 1, …), <term over a non-indexed column>)to a constant value, it keeps the call tree underneath (thearrayExists/hasfunctions and theirINPUTfor the non-indexed column). Returning that foldedFUNCTIONnode verbatim letsActionsDAG::cloneSubDAGpull the foreignINPUTintoactions. At read time — lazy per-granule skip-index filtering inMergeTreeSelectProcessor(InOrder) →getPossibleGranules→actions->execute(block)— that column is absent from the index granule block, henceNOT_FOUND_COLUMN_IN_BLOCK. A plain literal const term (e.g.1) is folded away entirely and does not leak; only the set index builds this per-granuleExpressionActions, sobloom_filteris unaffected.This is adjacent to the earlier
or(x, 0)fix (#98776, incheckDAGUseless); this one is in theactions-building path and is triggered by a constant-true function term.Fix
In
atomFromDAG, when a constant-foldedFUNCTIONnode is encountered, re-add it as a fresh leaf constant (same value/type/name) instead of returning the original node. This preserves the folded value while dropping the now-irrelevant argument subtree, soactionsonly ever references this index's own columns. Plain literal/COLUMNconstants are still returned verbatim.Regression test
04340_set_index_row_policy_const_folded_functioncovers the bare-hasand higher-order (arrayExistslambda capture) shapes; it fails on the unfixed binary with the error above and passes after the fix.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
SELECTfailing withNOT_FOUND_COLUMN_IN_BLOCKon a table that has asetdata-skipping index when a row policy filters it using an always-true condition combined with a check on a non-indexed column.Version info
26.7.1.218(included in26.7and later)