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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -377,8 +383,23 @@ 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 it can carry a
+                // key one of them already holds: a merged LIST component's MV 
partition is recorded with
+                // several keys of the MV's partition column. The aggregate 
compensation unions the MV's answer
+                // with the base table's, so such a group comes out twice 
instead of once. Answered from the
+                // base table instead of splitting the group. Groupings that 
cannot keep the two branches apart
+                // for other reasons are declined by canUnionRewrite below.
+                if (queryPlan.anyMatch(LogicalAggregate.class::isInstance)
+                        && needBaseTableUnion && 
!uncoveredNarrowedBasePartitions.isEmpty()) {

Review Comment:
   [P2] Keep full-key LIST aggregates eligible for partial rewrite
   
   This also discards aggregates whose extra grouping keys prove the branches 
disjoint. Use `LIST(d,k)` with `p_kept={(2020-01-01,1),(2038-01-01,1)}`, 
`p_bridge={(2038-01-01,2)}` and `p_old={(2020-01-01,2)}`, a 2 YEAR sync window, 
and a refreshed `PARTITION BY(d) AS SELECT d,k,SUM(v) s FROM t GROUP BY d,k` 
MV. Query `SELECT d,k,SUM(v) FROM t WHERE d='2020-01-01' GROUP BY d,k`; pruning 
reads kept+old, while the fresh MV component records kept+bridge. The valid 
reduced plan is:
   
   ```text
   UnionAll
     Filter(d=2020-01-01) -> Scan MV[M]          // k=1
     Aggregate(d,k,SUM(v))
       Filter(query AND d=2020-01-01 AND k=2) -> Scan t
   ```
   
   `PredicateAdder` now pins the compensation to the full tuple, so these 
groups differ in `k` and need no aggregate above the union. But 
`overlappingUncoveredListPartitions` compares only `d`, reports old, and this 
guard rejects before `canUnionRewrite`, rescanning/reaggregating all retained 
rows even when millions preaggregate to one MV row. The earlier [group-split 
finding](https://github.com/apache/doris/pull/68648#discussion_r4356885832) 
grouped only by `d`; this distinct full-tuple grouping is safe. Make rejection 
depend on the actual grouping keys, and add both MV/UNION plan and 
ordered-result coverage for this 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