Fix projection matching regression from removeTrivialWrappers in appendExpression#104317
Open
amosbird wants to merge 1 commit intoClickHouse:masterfrom
Open
Fix projection matching regression from removeTrivialWrappers in appendExpression#104317amosbird wants to merge 1 commit intoClickHouse:masterfrom
removeTrivialWrappers in appendExpression#104317amosbird wants to merge 1 commit intoClickHouse:masterfrom
Conversation
…ppendExpression` Move `removeTrivialWrappers` from `QueryDAG::appendExpression` (called per-step during incremental DAG merging) to the end of `QueryDAG::build` (after the full DAG is assembled). When called during `appendExpression`, the early stripping of `materialize`/`identity` wrappers changes output names before subsequent `mergeInplace` calls, breaking name resolution across expression steps. This caused NOT_FOUND_COLUMN_IN_BLOCK with UNION ALL views (ClickHouse#104117), block structure mismatch with window functions (ClickHouse#104235), and AMBIGUOUS_COLUMN_NAME with alias collisions (ClickHouse#104256). Closes ClickHouse#104117 Closes ClickHouse#104235 Closes ClickHouse#104256
Contributor
|
Workflow [PR], commit [9139e41] Summary: ✅ AI ReviewSummaryThis PR moves Missing context
ClickHouse Rules
Final VerdictStatus: ✅ Approve |
Contributor
LLVM Coverage Report
Changed lines: 100.00% (7/7) | lost baseline coverage: 1 line(s) · Uncovered code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #88798 added
removeTrivialWrappersinsideQueryDAG::appendExpressionto stripmaterialize/identitywrappers, enabling aggregate projection matching through views. However, calling it during incremental DAG merging (per expression step) breaks the name chain between steps: early stripping changes output names (e.g.materialize(val)→val) before the nextmergeInplaceexpects them, causing three different failures depending on query shape:NOT_FOUND_COLUMN_IN_BLOCK: materialize(val)on UNION ALL view + projection + WHERE on aggregated columnLOGICAL_ERROR: Block structure mismatchbetweenMergeSortingTransformandWindowTransformwith projection + window function + WHERE on non-key column (query_plan_remove_unused_columns = 0)AMBIGUOUS_COLUMN_NAMEwhen SELECT alias collides with source column name + projection (query_plan_remove_unused_columns = 0)The fix moves
removeTrivialWrappersfromappendExpression(called per-step) to the end ofbuild(after the full DAG is assembled and filter nodes are wired into outputs). This preserves the original fix for #32753 (projection matching through views) while avoiding the name resolution breakage during incremental merging.Note on #104256 empty results: The empty-result behavior when
SELECT toString(x) AS x ... WHERE x IN ...is a pre-existing analyzer semantic — alias shadows the source column name in WHERE regardless of projections. This is controlled byprefer_column_name_to_alias(default0= prefer alias). The regression from #88798 was only the exception (AMBIGUOUS_COLUMN_NAME), not the empty result.Closes #104117
Closes #104235
Closes #104256
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix exceptions (
NOT_FOUND_COLUMN_IN_BLOCK,LOGICAL_ERROR,AMBIGUOUS_COLUMN_NAME) when using projections with UNION ALL views, window functions, or alias-column name collisions. Regression from #88798.Documentation entry for user-facing changes