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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java:
##########
@@ -588,6 +610,16 @@ private boolean isGroupByEquals(Pair<Plan, 
LogicalAggregate<Plan>> queryTopPlanA
         LogicalAggregate<Plan> queryAggregate = queryTopPlanAndAggPair.value();
         LogicalAggregate<Plan> viewAggregate = viewTopPlanAndAggPair.value();
 
+        // If the query is a scalar aggregate but the view groups by extra 
dimensions, the dimensions
+        // removed by the uniform function dependency below only guarantee at 
most one group, not that a
+        // group exists. Eliminating the aggregate into a bare project would 
lose the single row a scalar
+        // aggregate must always emit when the filter matches zero rows. Keep 
the aggregate by rejecting
+        // this fast path and falling back to the roll up rewrite.
+        if (queryAggregate.getGroupByExpressions().isEmpty()
+                && !viewAggregate.getGroupByExpressions().isEmpty()) {

Review Comment:
   [P1] Restore HAVING above the retained scalar aggregate
   
   For an MV `select k, count(*) cnt from t group by k having count(*) > 0`, 
consider `select count(*) from t where k = 9999 having count(*) > 0` when 
k=9999 is absent. The reduced query is `Filter(c > 0) -> Aggregate([], COUNT(*) 
AS c) -> Filter(k=9999) -> Scan(t)` and must return zero rows. 
`Predicates.compensatePredicates` removes the identical aggregate HAVING as an 
exact-covered residual before its unsafe-aggregate check. This new guard then 
forces the rollup, but `aggregateRewriteByView` restores only outputs, 
producing `Project(ifnull(s,0)) -> Aggregate([], SUM(mv.cnt) AS s) -> 
Filter(mv.k=9999) -> MVScan` with no upper HAVING. That plan returns a row 
containing 0; the previous aggregate-eliminating path returned zero rows. 
Rebuild the query HAVING above the compensated scalar result, and cover this 
case in the regression.



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