Fix skip index not used for ALIAS columns when query plan expression merging is disabled#98960
Conversation
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok.
But I found the idea of this PR controversial, because
when query plan expression merging is disabled (query_plan_merge_expressions = 0
or query_plan_enable_optimizations = 0).
who and why needs to disable this optimizations but still expect something to be optimized?
|
Should we still classify it as a "bug fix"? What the bug was? |
Hi @alexey-milovidov, The real issue is #98822 — ALIAS column skip indexes stopped working after 24.2, which is a regression with default settings too. The disabled-optimizations scenario |
The bug is reported in #98822: skip indexes on ALIAS columns stopped working after version 24.2. Users observed that queries filtering on ALIAS columns no longer use |
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (24/24) |
Fix skip index not used for ALIAS columns when query plan expression merging is disabled
24.8.14 Backport of ClickHouse#98960 - Fix skip index not used for ALIAS columns when query plan expression merging is disabled
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix skip indexes (and primary key conditions) not being applied for ALIAS columns when query plan expression merging is disabled (query_plan_merge_expressions = 0
or query_plan_enable_optimizations = 0).
Documentation entry for user-facing changes
Documentation is written (mandatory for new features)
When query plan expression merging is disabled, ExpressionStep nodes like "Compute alias columns" and "Change column names to column identifiers" remain separate
from filter steps. The optimizePrimaryKeyConditionAndLimit optimization previously ignored these expression steps, causing filters on ALIAS columns to reference
unresolved column identifiers that the storage layer could not match against indexes.
This fix composes filter DAGs through accumulated expression DAGs (in bottom-to-top order) so that ALIAS column references are resolved to their underlying physical
column expressions, enabling correct primary key and skip index analysis regardless of whether expression merging is active.
Fixes Index using aliases does not work in new versions #98822
Note
Medium Risk
Touches query-plan optimization that builds primary key/skip index conditions; incorrect DAG composition could change which indexes are used or filter semantics for some plans. Covered by new regression tests, but the change impacts a performance-critical path.
Overview
Fixes index analysis when
query_plan_merge_expressions=0(or optimizations are disabled) by composingFilterStepDAGs through interveningExpressionStepDAGs inoptimizePrimaryKeyConditionAndLimit, so filters on ALIAS/renamed columns resolve to underlying physical expressions before being applied to storage.Adds a stateless regression test (
03822_alias_column_skip_index_no_merge) verifyingEXPLAIN indexes=1shows primary key and skip index conditions for ALIAS and nested-ALIAS predicates both with expression merging/optimizations disabled and under default settings.Written by Cursor Bugbot for commit 4f99990. This will update automatically on new commits. Configure here.