yujun777 opened a new pull request, #71368:
URL: https://github.com/apache/doris/pull/71368
### Background
Asynchronous materialized view partition tracking
(`PartitionIncrementMaintainer` and
`MaterializedViewUtils.getRelatedTableInfos`) maps the MV partition output
column back to one or more base-table partition columns and a single
`MTMVPartitionInfo.expr` (`date_trunc` expression). All tracked branches and
references that feed the MV partition column must agree on the truncation
granularity.
### What problem does this PR solve?
Issue Number: None
Related PR: #70289 (follow-up for pre-existing partition lineage consistency
gaps surfaced during review)
PR Type: Bugfix
Problem Summary:
Partition tracking can accept inconsistent `date_trunc` expressions across
`UNION ALL` branches (including self-`UNION ALL` over the same base table) or
overwrite conflicting `date_trunc` units on a shared CTE producer slot during a
CTE self-join. Both `CREATE MATERIALIZED VIEW` and refresh-time reanalysis can
therefore accept an invalid partition mapping where one branch contributes rows
truncated at a different granularity than the stored MV partition expression.
### Details
- **Change map:** 3 production files (`PartitionIncrementMaintainer.java`,
`MaterializedViewUtils.java`, `MTMVPartitionDefinition.java`) and 1 FE unit
test file (`MTMVPartitionReanalysisTest.java`).
- **Root cause:**
1. `PartitionIncrementMaintainer` wrote directly to
`partitionAndRefExpressionMap` via `put`/`putAll`, allowing a later CTE
consumer or `UNION ALL` branch to silently overwrite an earlier conflicting
`date_trunc` expression on the same slot.
2. `MaterializedViewUtils.checkPartitionRefExpression()` only checked that
each individual expression contained at most one `DateTrunc`, without checking
unit consistency across tracked base partition columns before
`getRelatedTableColumnInfosWithCheck()` deduplicates by `BaseTableInfo`.
3. `MTMVPartitionDefinition.getRelatedTableInfos()` fell back to wrapping
`partitionCol` with an outer `date_trunc` even when direct tracing (`timeUnit =
null`) had already failed (`!direct.isPctPossible()`).
- **Fix:**
- Add `PartitionIncrementMaintainer.extractDateTruncUnit()` and
`PartitionIncrementCheckContext.putPartitionAndRefExpression()` /
`putAllPartitionAndRefExpressions()` so conflicting `date_trunc` units on the
same tracked slot fail fast instead of overwriting.
- Extend `MaterializedViewUtils.checkPartitionRefExpression()` to verify
that all tracked base partition columns with `date_trunc` share the same unit
and repeated references to the same base table agree on whether and how they
truncate (while preserving valid cross-table joins between a bare `DATE` column
and `date_trunc(dt, 'day')`).
- Short-circuit `MTMVPartitionDefinition.getRelatedTableInfos()` when
direct reanalysis already fails (`!direct.isPctPossible()`).
- **Behavior change:** MVs whose `UNION ALL` branches or CTE self-joins mix
conflicting `date_trunc` units are rejected during both creation and refresh
reanalysis.
### Testing
- `MTMVPartitionReanalysisTest`: 23 tests passed (including new
positive/negative cases for self-UNION, multi-table UNION ALL, shared-CTE UNION
ALL, and CTE self-join).
- `MTMVPlanUtilTest`: 26 tests passed.
- `PartitionColumnTraceTest`: 52 tests passed (including cross-table `DATE`
/ `date_trunc('day')` join cases `test500` and `test5000`).
- FE Checkstyle (`mvn -f fe/pom.xml -pl fe-core -am validate -DskipTests`):
passed.
### Release note
Reject asynchronous materialized views whose partition lineage mixes
conflicting `date_trunc` units across `UNION ALL` branches or CTE references.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Locally verified with focused FE unit tests and
Checkstyle; full CI pending.
--
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]