Repository navigation
branch-4.2: [fix](mtmv) Keep constant-propagated predicates in materialized view rewrite #69464 - #69539
Open
github-actions[bot] wants to merge 1 commit into
Open
branch-4.2: [fix](mtmv) Keep constant-propagated predicates in materialized view rewrite #69464#69539github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…rewrite (#69464) Constant propagation rewrites a constant grouping key above the aggregate and reuses the exprId of the replaced column: ``` LogicalProject (projects=[2026 AS dt_year#4, org_group#7, ...]) +-- LogicalAggregate (groupByExpr=[org_group#7], ...) +-- LogicalFilter (predicates=[dt_year#4 = 2026, ...]) ``` The filter which constrains that column is still below the aggregate, so one exprId now describes two different values in two scopes. When the query is rewritten by a materialized view, `AbstractMaterializedViewRule#rewriteExpression` shuttles the compensation predicates through the query top plan with `shuttleExpressionWithLineage`, which resolves slots by exprId only. It picked up the constant alias above the aggregate and turned `dt_year#4 = 2026` into `2026 = 2026`; the tautology is folded away, so the rewritten MV scan loses the year predicate. The scan then reads and aggregates the rows of every year while the top projection still outputs the constant `2026`, i.e. a silent wrong result. This matches the reported symptom: the MV scan keeps the other filters (`org_group IN (...)`, `dt_quarter <= 3`, `account_type <> ...`) but not `dt_year = 2026`, and the query result is a multiple of the correct one. Fix: `ExpressionLineageReplacer` no longer accepts a constant alias as the lineage of an exprId which is still produced by the plan below that alias. Such an alias shadows the lower column instead of defining it for the expressions evaluated there, so the compensation predicate keeps referencing the column and is pushed to the MV scan. A query of this shape on a partitioned MV returns the aggregation of every year before the change and the correct per-year result after it. ### Release note Fixed a wrong-result issue where a materialized view rewrite could drop a filter predicate whose column was materialized as a constant by constant propagation.
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
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.
Cherry-picked from #69464