racevedoo commented on code in PR #4144:
URL: https://github.com/apache/calcite/pull/4144#discussion_r1914691721


##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -392,21 +392,22 @@ private static RexNode rewriteSome(RexSubQuery e, 
Set<CorrelationId> variablesSe
         //     then false // sub-query is empty for corresponding corr value
         //   when q.c = 0 then false // sub-query is empty
         //   when e.deptno is null then unknown
-        //   when q.c <> q.d && q.d <= 1
+        //   when q.c <> q.d && q.dd <= 1

Review Comment:
   the `q.c <> q.d` comparison identifies if there are any null values, since 
`count(*)` counts null values and `count(deptno)` does not.
   the `q.dd <= 1` part (previously `q.d <= 1`) remains the with the same 
semantics (true if there is a single non-null value), since in this patch `dd` 
is `count(distinct deptno)`, which is equivalent to `d` in the main branch.
   
   so this `when` clause means "if there are any null values and there is a 
single non-null value".
   
   in `main`, c = `count(distinct *)` and d = `count(distinct deptno)`, which 
means that when there are null values and a single non-null value, `c = d` and 
this clause evaluates to false.
   
   I know it's a tricky case, so let me know if additional clarifications are 
needed 😄 



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

Reply via email to