Skip to content

Fix NOT_FOUND_COLUMN_IN_BLOCK when text index predicate is referenced in SELECT - #99504

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
CurtizJ:fix-text-index-direct-read-alias
Mar 16, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
CurtizJ:fix-text-index-direct-read-alias

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Mar 14, 2026 •

Copy link
Copy Markdown
Member

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 NOT_FOUND_COLUMN_IN_BLOCK exception when a text index predicate (e.g. hasAllTokens) is referenced in both SELECT and WHERE clauses via an alias.

Fixes #99468.

Version info

  • Merged into: 26.3.1.714
  • Backported to: 26.2.5.29, 25.12.9.51

CurtizJ and others added 4 commits March 13, 2026 23:24
… in SELECT

When a text-search function (e.g. `hasAllTokens`) appeared both in SELECT
(via alias) and in WHERE, the direct read optimization in
`replaceFunctionsToVirtualColumns` replaced the predicate with a virtual
column input node, changing its name to `__text_index_...`. But the
downstream ExpressionStep still expected the original column name,
causing a NOT_FOUND_COLUMN_IN_BLOCK exception.

The fix adds an alias after the replacement to preserve the original
function name, mirroring what `preprocessTextIndexFunction` already does.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
After the alias fix, the Filter/Prewhere column names now show original
function names instead of `__text_index_...` virtual column names. Update
EXPLAIN query filters from `LIKE '%Filter column%'` to
`LIKE '%\_\_text_index%'` to match the INPUT/ALIAS lines in the Actions
section, which is a more precise check for the optimization.

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

clickhouse-gh Bot commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0509f96]

Summary: ✅


AI Review

Summary

This PR fixes NOT_FOUND_COLUMN_IN_BLOCK for text-index direct-read predicates referenced in both SELECT and WHERE by preserving the original predicate column name via addAlias. It also updates existing text-index EXPLAIN checks to match the new Actions: INPUT ... __text_index... output and adds a focused regression test for alias usage. I did not find high-confidence correctness, safety, or performance regressions in the submitted changes.

Missing context

  • ⚠️ No CI run status/log links were provided in the review context, so I could not validate runtime coverage beyond the changed tests in diff.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsHistory.cpp ➖
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 14, 2026
@CurtizJ CurtizJ added pr-must-backport Pull request should be backported intentionally. Use this label with great care! v25.12-must-backport labels Mar 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.70% 83.80% +0.10%
Functions 23.90% 23.90% +0.00%
Branches 76.20% 76.30% +0.10%

PR changed lines: PR changed-lines coverage: 100.00% (5/5, 0 noise lines excluded)
Diff coverage report
Uncovered code

@alexey-milovidov alexey-milovidov self-assigned this Mar 16, 2026
@alexey-milovidov
alexey-milovidov merged commit 7b4fbce into ClickHouse:master Mar 16, 2026
159 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Mar 16, 2026
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 16, 2026
robot-clickhouse added a commit that referenced this pull request Mar 16, 2026
…dex predicate is referenced in SELECT
robot-clickhouse added a commit that referenced this pull request Mar 16, 2026
…ndex predicate is referenced in SELECT
clickhouse-gh Bot added a commit that referenced this pull request Mar 17, 2026
Backport #99504 to 26.2: Fix `NOT_FOUND_COLUMN_IN_BLOCK` when text index predicate is referenced in SELECT
alexey-milovidov added a commit that referenced this pull request Mar 17, 2026
…n text index predicate is referenced in SELECT"

This reverts commit 57801bd.
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Mar 17, 2026
zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Mar 17, 2026
Tests that `query_plan_direct_read_from_text_index` works correctly when
the text-index predicate is referenced via an alias in `SELECT` and used
in `PREWHERE`. PR ClickHouse#99504 fixed `NOT_FOUND_COLUMN_IN_BLOCK` for this pattern.

Covers: `hasToken`, `hasAllTokens`, `hasAnyTokens` with `PREWHERE` alias,
`PREWHERE + WHERE` combined, explicit `PREWHERE` predicate with alias in
`SELECT`, and `NOT` predicate with `PREWHERE` alias.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@rschu1ze rschu1ze left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the EXPLAIN PLAN examples for direct read in the docs need to be updated?

CurtizJ added a commit that referenced this pull request Mar 18, 2026
The backport of PR #99504 added an alias in replaceNodes() to preserve
original column names for downstream steps, fixing NOT_FOUND_COLUMN_IN_BLOCK.
This alias causes EXPLAIN to show original expression names instead of
__text_index_* virtual column names in Filter/Prewhere column output.

Update all affected tests to check for __text_index virtual column presence
in EXPLAIN actions output instead of checking Filter column names, matching
the approach used in the original master PR.

Also add missing SET allow_experimental_full_text_index = 1 to the new
04039_text_index_direct_read_select_alias test.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Mar 19, 2026
Backport #99504 to 25.12: Fix `NOT_FOUND_COLUMN_IN_BLOCK` when text index predicate is referenced in SELECT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NOT_FOUND_COLUMN_IN_BLOCK when running SELECT with hasAllTokens

5 participants