Skip to content

Backport text index prewhere filter type fix to 26.3 - #107758

Merged
thevar1able merged 1 commit into
26.3from
backport-26.3-text-index-filter-prewhere-type-fix
Jun 17, 2026
Merged

thevar1able merged 1 commit into
26.3from
backport-26.3-text-index-filter-prewhere-type-fix

Conversation

@thevar1able

Copy link
Copy Markdown
Member

Manual backport of 1c1c031 ("Fix text index prewhere mismatch with multiple indexes") from #98882.

With query_plan_direct_read_from_text_index and use_skip_indexes_on_data_read, the text index read is a None-type prewhere step. MergeTreeRangeReader executed that step's actions on the sample block in its constructor, while executePrewhereActionsAndFilterColumns skips None-type steps at runtime. When a row-level filter (e.g. a ROW POLICY) reads a String column before the None step, the sample-block column order diverged from the actual data, so the raw String column landed in a filter position and the query raised ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER ("Illegal type String of column for filter").

The fix skips executing step actions on the sample block for None-type steps, to match the runtime behavior. It also switches IndexReadTasks / IndexReadColumns to std::map for deterministic iteration order (the multiple-text-index variant of the same class of mismatch).

Adds 04332_text_index_direct_read_row_policy reproducing the single-index ROW POLICY case. Verified against public builds bracketing the fix: it raised ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER on 26.4.1.689 (commit c1225a6, before PR #98882) and returns 1000 on 26.4.1.691 (commit 4d79f6e, the PR #98882 merge).

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER when reading from a text index via query_plan_direct_read_from_text_index together with a row-level filter (such as a row policy) on a String column.

Manual backport of 1c1c031
("Fix text index prewhere mismatch with multiple indexes") from
#98882.

With `query_plan_direct_read_from_text_index` and `use_skip_indexes_on_data_read`,
the text index read is a `None`-type prewhere step. `MergeTreeRangeReader` executed
that step's actions on the sample block in its constructor, while
`executePrewhereActionsAndFilterColumns` skips `None`-type steps at runtime. When a
row-level filter (e.g. a `ROW POLICY`) reads a `String` column before the `None` step,
the sample-block column order diverged from the actual data, so the raw `String`
column landed in a filter position and the query raised
`ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER` ("Illegal type String of column for filter").

The fix skips executing step actions on the sample block for `None`-type steps, to
match the runtime behavior. It also switches `IndexReadTasks` / `IndexReadColumns` to
`std::map` for deterministic iteration order (the multiple-text-index variant of the
same class of mismatch).

Adds `04332_text_index_direct_read_row_policy` reproducing the single-index
`ROW POLICY` case. Verified against public builds bracketing the fix: it raised
`ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER` on 26.4.1.689 (commit c1225a6, before
PR #98882) and returns 1000 on 26.4.1.691 (commit 4d79f6e, the PR #98882 merge).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [f3ffa9e]

Summary: ✅

@thevar1able thevar1able changed the title Backport text index prewhere filter type fix to release/26.2 Backport text index prewhere filter type fix to release/26.3 Jun 17, 2026
@nikitamikhaylov nikitamikhaylov self-assigned this Jun 17, 2026
@thevar1able
thevar1able merged commit cd249e4 into 26.3 Jun 17, 2026
34 checks passed
@thevar1able
thevar1able deleted the backport-26.3-text-index-filter-prewhere-type-fix branch June 17, 2026 19:28
@thevar1able thevar1able changed the title Backport text index prewhere filter type fix to release/26.3 Backport text index prewhere filter type fix to 26.3 Jun 17, 2026
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
 text index prewhere fix)

STOR: with query_plan_direct_read_from_text_index and use_skip_indexes_on_data_read, each text index read is a
None-type PREWHERE step. IndexReadTasks/IndexReadColumns were std::unordered_map: the map is copied into the read
pool and iterated again in getPrewhereActions and getReadTaskColumns, and a copy need not iterate in the same order,
so the PREWHERE readers and the PREWHERE actions of the index steps could be paired differently. In addition
MergeTreeRangeReader executed the actions of None-type steps on its sample block although
executePrewhereActionsAndFilterColumns skips them at run time, so the sample block and the data diverged.
Upstream switches both maps to std::map and skips None-type steps on the sample block (26.3 backport ClickHouse#107758 of
1c1c031 from ClickHouse#98882; 26.4+ have it through ClickHouse#98882).
Effect in the fork: with three partially materialized text indexes in one query (04411, third section) the backport
of ClickHouse#108607 (a6ab685) ran equals(a, 'alpha') on a column that was not the String column a and failed with
TOO_DEEP_RECURSION (KD-UP-TEXTINDEX-DIRECTREAD-3IDX); with a row policy on a String column the upstream test 04332
fails with ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER. Upstream patch unchanged (applies cleanly), with its test
04332_text_index_direct_read_row_policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…P-TEXTINDEX-DIRECTREAD-3IDX and KD-ENV-HOSTNAME-SUBSTITUTION

KD-UP-107758 (fixed by ebce980): 04332_text_index_direct_read_row_policy fails on the production build a394e92 and
on CAND6 with ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER and passes on official 26.8.8.8 and on CAND7; it is added to the selection.
KD-UP-TEXTINDEX-DIRECTREAD-3IDX is fixed by the same backport (04411 third section: CAND6 TOO_DEEP_RECURSION, CAND7 correct).
KD-ENV-HOSTNAME-SUBSTITUTION is fixed in the test environment by f2f0ba1 (04881 passes with its unchanged reference).
Registry 149 entries, 1 open (KD-D512-MIXED-GROUPBY-NULLABLE); 231 selected tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants