github-actions[bot] commented on code in PR #68648:
URL: https://github.com/apache/doris/pull/68648#discussion_r4359578727


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -377,6 +382,18 @@ protected List<Plan> doRewrite(StructInfo queryStructInfo, 
CascadesContext casca
                 }
                 boolean needRemoveMvPartitions = 
!invalidPartitions.key().isEmpty();
                 boolean needBaseTableUnion = 
!invalidPartitions.value().isEmpty();
+                // An uncovered base partition is read beside the MV 
partitions that stay, and the two can
+                // answer the same aggregate group -- a merged LIST 
component's MV partition holds a key the
+                // uncovered partition also carries. The union is below the 
aggregate then, so the group is
+                // two rows rather than one. Answered from the base table 
instead of splitting it.
+                if (needBaseTableUnion && 
!uncoveredNarrowedBasePartitions.isEmpty()
+                        && 
queryPlan.anyMatch(LogicalAggregate.class::isInstance)) {

Review Comment:
   [P2] Preserve safe RANGE aggregate union rewrites
   
   This also rejects ordinary windowed RANGE MVs whose aggregate groups are 
disjoint. For example, let `t` have populated daily `RANGE(d)` partitions for 
2020-01-01 and 2038-01-01, plus an unrelated 2040 partition. Refresh `PARTITION 
BY(d) AS SELECT d,SUM(v) FROM t GROUP BY d` with a 2 YEAR sync limit, then 
query those first two dates:
   ```text
   Aggregate(d, SUM(v))
     Filter(d IN (2020-01-01, 2038-01-01))
       Scan t[old, kept]
   ```
   `calcInvalidPartitions` reports `old` in `uncoveredNarrowedBasePartitions`, 
so this guard rejects the candidate before `canUnionRewrite`. But 
`UnionAll(Scan MV[kept], Aggregate(d,SUM(v)) -> Scan t[old])` is correct: its 
groups have different `d` values. The query now scans and aggregates the 
retained base data too, losing the normal TTL/union optimization (also expected 
by `partition_union_rewrite/partition_mv_rewrite.groovy`). Limit the fallback 
to cases where uncovered partitions can overlap retained aggregate groups, and 
preserve this disjoint RANGE case.



-- 
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]

Reply via email to