yujun777 opened a new pull request, #69464:
URL: https://github.com/apache/doris/pull/69464
### What problem does this PR solve?
Issue Number: None
Problem Summary:
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.
### Check List (For Author)
- Test
- [x] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
- Behavior changed:
- [x] No.
- Does this need documentation?
- [x] No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]