Skip to content

Substitute ALIAS columns in text index arguments - #109161

Closed
YjyJeff wants to merge 1 commit into
ClickHouse:masterfrom
YjyJeff:fix-alias-columns-in-skip-index-arguments
Closed

YjyJeff wants to merge 1 commit into
ClickHouse:masterfrom
YjyJeff:fix-alias-columns-in-skip-index-arguments

Conversation

@YjyJeff

@YjyJeff YjyJeff commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes: #95944

The ALIAS-to-expression substitution in IndexDescription::getIndexFromAST only rewrote the index KEY expression (extractKeyExpressionList), leaving index TYPE arguments untouched. A text index argument that references an ALIAS column — e.g. preprocessor = lower(combined) where combined ALIAS concat(title, ' ', body) — failed validation, because at argument-validation time only the physical source columns exist:

SET enable_full_text_index = 1;
CREATE TABLE providers
(
    provider Nullable(String),
    name String ALIAS ifNull(provider, 'default_name'),
    INDEX name_text_idx(name) TYPE text(tokenizer = sparseGrams(3), preprocessor = lower(name))
)
ENGINE = MergeTree ORDER BY tuple();
-- Code: 36. DB::Exception: Preprocessor function must only reference column: ifNull(provider, 'default_name'), also got: name (BAD_ARGUMENTS)

This change applies the same alias substitution to the argument VALUES. Only the text index has expression-valued arguments (preprocessor / postprocessor) that may reference columns; every other index type takes positional literal arguments, where an identifier is a value rather than a column reference, so the substitution is scoped to text. To avoid clobbering a parameter NAME (a column aliased like tokenizer / preprocessor), only the value side (children[1]) of each equals(key, value) argument pair is visited, never the key.

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

Allow ALIAS columns to be referenced in text index preprocessor / postprocessor arguments (e.g. preprocessor = lower(alias_col)), which previously failed validation with a "Missing columns" / "Preprocessor function must only reference column" error.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

The ALIAS-to-expression substitution in `IndexDescription::getIndexFromAST`
only rewrote the index KEY expression (`extractKeyExpressionList`), leaving
index TYPE arguments untouched. A `text` index argument that references an
ALIAS column -- e.g. `preprocessor = lower(combined)` where
`combined ALIAS concat(title, ' ', body)` -- failed validation with
"Missing columns: 'combined'", because at argument-validation time only the
physical source columns exist.

Apply the same alias substitution to the argument VALUES. Only the `text`
index has expression-valued arguments (`preprocessor` / `postprocessor`) that
may reference columns; every other index type takes positional literal
arguments where an identifier is a value, not a column reference, so the
substitution is scoped to `text`. To avoid clobbering a parameter NAME (a
column aliased like `tokenizer` / `preprocessor`), only the value side
(`children[1]`) of each `equals(key, value)` argument pair is visited, never
the key.

Ported from internal fix:
https://git.woa.com/BigDataCore/Cooperative/TitanEngine/ClickHouse/-/merge_requests/60

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

YjyJeff commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate — #103626 (by @ahmadov) already fixes this exact issue (#95944) with essentially the same approach (alias substitution scoped to the text index). Apologies for the noise; I found #103626 only after opening this. Deferring to #103626, which is further along in review. I'll leave a note there.

@ahmadov

ahmadov commented Jul 2, 2026

Copy link
Copy Markdown
Member

Closing as a duplicate — #103626 (by @ahmadov) already fixes this exact issue (#95944) with essentially the same approach (alias substitution scoped to the text index). Apologies for the noise; I found #103626 only after opening this. Deferring to #103626, which is further along in review. I'll leave a note there.

Hi @YjyJeff, no worries! I'll prioritize that PR to merge it soon.

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.

Support ALIAS columns in preprocessor argument for Full-Text Index

2 participants