Skip to content

Text index: support ALIAS column in preprocessor - #103626

Closed
ahmadov wants to merge 15 commits into
masterfrom
ahmadov/gh-95944
Closed

ahmadov wants to merge 15 commits into
masterfrom
ahmadov/gh-95944

Conversation

@ahmadov

@ahmadov ahmadov commented Apr 28, 2026

Copy link
Copy Markdown
Member

Fixes #95944

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):

Fixes the referencing the ALIAS columns in the text index preprocessor expression.

@clickhouse-gh

clickhouse-gh Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4c6bb8c]

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 28, 2026
@ahmadov

ahmadov commented Apr 28, 2026

Copy link
Copy Markdown
Member Author

I suppose we don't need to backport that since there are workarounds to avoid this bug.

@ahmadov
ahmadov requested review from CurtizJ and rschu1ze April 28, 2026 01:54
Comment thread src/Storages/IndicesDescription.cpp Resolved
Comment thread src/Storages/IndicesDescription.cpp Resolved
Comment thread src/Storages/IndicesDescription.cpp Resolved
Comment thread src/Storages/IndicesDescription.cpp Resolved
@rschu1ze rschu1ze self-assigned this Jun 16, 2026
{
result.arguments = index_type->arguments->clone();

if (result.type == TEXT_INDEX_NAME)

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.

Hmm, I don't really like that this is a text-index only path. Also, we are calling result.initExpressionInfo(...) above which runs very similar code. Maybe we can somehow unify?

@YjyJeff

YjyJeff commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Hi @ahmadov @rschu1ze — we hit this exact bug independently (a text index with preprocessor = lower(alias_col) fails validation with Missing columns / Preprocessor function must only reference column), implemented essentially the same fix, and only then found this PR — so I closed my duplicate (#109161) in favor of this one. This is confirmation that the issue is affecting real users: we urgently need this capability, as the only workaround is materializing an extra physical column, which is exactly the cost the ALIAS is meant to avoid.

It looks like the only thing outstanding is @rschu1ze's design question from 2026-06-16 — whether the text-index-only substitution path can be unified with the alias substitution already done in initExpressionInfo. Is there anything blocking beyond that discussion? If it would help move things along, one option is to keep the current narrow, low-risk fix as-is (it's correctly scoped to text and to the preprocessor value, which avoids the tokenizer/key collision regressions the earlier review flagged) and track the initExpressionInfo unification as a separate refactor, so users aren't blocked on the cleanup.

Happy to help however is useful — reviewing, testing, or taking over the branch if @ahmadov is busy. Thanks for the work on this!

lower_tags Array(String) ALIAS arrayMap(x -> lower(x), tags),
INDEX idx(lower_tags) TYPE text(
tokenizer = array,
preprocessor = concat(lower_tags, '_suffix')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This case no longer exercises the lambda-shadowing path that ReplaceAliasByExpressionVisitor just added. preprocessor = concat(lower_tags, '_suffix') only proves plain alias expansion; if a table also has x String ALIAS 'shadow', removing the new private_aliases masking would still pass this test even though arrayMap(x -> lower(x), ...) would regress again.

Please add a focused case where the preprocessor itself contains a lambda whose parameter name collides with an ALIAS column, and assert that the DDL succeeds and the indexed tokens come from the lambda-local x.


const auto * key = func->arguments->children[0]->as<ASTIdentifier>();
if (key && key->name() == "preprocessor")
replaceAliasColumnsWithExpressions(func->arguments->children[1], columns);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expanding the preprocessor AST in place here changes more than validation. For preprocessor = lower(name) on an ALIAS column, this rewrites the AST to lower(<alias expression>), so MergeTreeIndexTextPreprocessor::isLowerOrUpper never sets is_lower_or_upper anymore because it only recognizes lower / upper applied to an ASTIdentifier (src/Storages/MergeTree/MergeTreeIndexTextPreprocessor.cpp:154-159).

That, in turn, disables the text-index direct-read path for ILIKE in MergeTreeIndexConditionText, even though the equivalent physical-column definition still uses the optimization and the docs say ILIKE works with lower / upper preprocessors. Can we preserve the logical lower(name) form for this check, or relax isLowerOrUpper to accept an argument whose getColumnName() matches the indexed expression exactly?

@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.90% 85.90% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 42/42 (100.00%) · Uncovered code

Full report · Diff report

@ahmadov
ahmadov requested a review from rschu1ze July 9, 2026 07:15

@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.

Now that the postprocessor is also merged, could you please check that postprocessor expressions also work with alias columns?

EDIT: I just noticed #110014

@rschu1ze

Copy link
Copy Markdown
Member

Superseded by #110014

@rschu1ze rschu1ze closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ALIAS columns in preprocessor argument for Full-Text Index

4 participants