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 uniqueness of `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: [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