XieJiann commented on code in PR #30774:
URL: https://github.com/apache/doris/pull/30774#discussion_r1477308879


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupBy.java:
##########
@@ -50,8 +53,11 @@ public Rule build() {
                     Set<Slot> groupby = 
agg.getGroupByExpressions().stream().map(e -> (Slot) e)
                             .collect(Collectors.toSet());
                     Plan child = agg.child();
-                    boolean unique = 
child.getLogicalProperties().getFunctionalDependencies()
-                            .isUniqueAndNotNull(groupby);
+                    //boolean unique = 
child.getLogicalProperties().getFunctionalDependencies()
+                    //        .isUniqueAndNotNull(groupby);
+                    ImmutableSet<FdItem> fdItems = 
child.getLogicalProperties().getFdItems();
+                    boolean unique = !groupby.isEmpty() && 
fdItems.stream().anyMatch(e ->
+                            e.isUnique() && !e.isCandidate() && 
groupby.containsAll(e.getParentExprs()));

Review Comment:
   It's incomplete. such as :
   ```
   select * from (select a, b, sum(a + b) as c group by a, b) group by a b c
   ```
   a c are unique, and unique a, b, c also can be infered . That is the 
uniqueness can be inferred by uniqueness of any subset



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to