hello-stephen commented on code in PR #70289:
URL: https://github.com/apache/doris/pull/70289#discussion_r4736574915
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/MTMVPartitionDefinition.java:
##########
@@ -72,30 +86,87 @@ public class MTMVPartitionDefinition {
* @return MTMVPartitionInfo
*/
public MTMVPartitionInfo
analyzeAndTransferToMTMVPartitionInfo(NereidsPlanner planner) {
- MTMVPartitionInfo mtmvPartitionInfo = new
MTMVPartitionInfo(partitionType);
- if (this.partitionType == MTMVPartitionType.SELF_MANAGE) {
- return mtmvPartitionInfo;
+ if (partitionType == MTMVPartitionType.SELF_MANAGE) {
+ return new MTMVPartitionInfo(partitionType);
+ }
+ if (existingPartitionInfo != null) {
+ return reanalyzePartition(planner);
+ }
+ PartitionColumn declared = partitionType == MTMVPartitionType.EXPR
+ ? partitionColumnFromExpression(functionCallExpression) : new
PartitionColumn(partitionCol, null);
+ MTMVPartitionInfo analyzed = analyzePartition(planner, declared,
partitionType);
+ analyzed.setDeclaredPartitionTimeUnit(declared.timeUnit() == null ? ""
: declared.timeUnit());
+ partitionType = analyzed.getPartitionType();
+ return analyzed;
+ }
+
+ private MTMVPartitionInfo reanalyzePartition(NereidsPlanner planner) {
+ String declaredUnit =
existingPartitionInfo.getDeclaredPartitionTimeUnit();
+ if (partitionType == MTMVPartitionType.FOLLOW_BASE_TABLE ||
"".equals(declaredUnit)) {
+ MTMVPartitionInfo analyzed = analyzePartition(planner,
+ new PartitionColumn(partitionCol, null),
MTMVPartitionType.FOLLOW_BASE_TABLE);
Review Comment:
[P2] Retain compatible stored-unit recovery for implicit UNIONs
This early return makes a compatible schema change fail for a newly created
`PARTITION BY (q)` MV over range-partitioned DUP sources `(dt DATETIME NOT
NULL, v VARCHAR(10))`:
```text
UnionAll(dt, q, v, pad)
Project(dt, q=date_trunc(dt,'month'), v, pad=0) Scan(l)
Project(dt, q=date_trunc(dt,'quarter'), v, pad=0) Scan(r)
```
Use `REFRESH COMPLETE ON MANUAL`, ordinary sources without
policies/TTL/changelog, and `0 AS pad` in both SELECTs.
`getRelatedTableColumnInfosWithCheck` emits tables in the check context's
`HashMap` order, and `fillPctInfos` overwrites `expr` for each table.
`SlotReference.hashCode()` returns its ExprId, while `LogicalOlapScan`
allocates IDs for every base column, including unused ones. In the ordinary
source-derived allocation, the two `dt` IDs are 2/5, so QUARTER is stored.
Adding 11 unused INT columns to `l` shifts them to 2/16: the right slot's hash
bucket now precedes the left, and reanalysis infers MONTH instead. The
projected schema and query are unchanged, but `ensureMTMVQueryUsable` rejects
the unit mismatch, preventing refresh after schema invalidation.
The base implementation reapplies the stored QUARTER to the projected raw
`dt` in both branches, so its result is independent of that iteration order.
Preserve a compatibility-checked stored-expression recovery here, or make
effective-unit derivation stable against unrelated slot allocation. Extend the
mixed-UNION test with unused-column additions; its current VARCHAR widening
does not change slot counts. This trace is from source inspection; no runtime
test was run.
--
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]