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


##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -696,16 +696,15 @@ private static RexNode rewriteIn(RexSubQuery e, 
Set<CorrelationId> variablesSet,
         if (variablesSet.isEmpty()) {
           builder.aggregate(builder.groupKey(builder.field("cs")),
               builder.count(false, "c"));
-
-          // sorts input with desc order since we are interested
-          // only in the case when one of the values is true.
-          // When true value is absent then we are interested
-          // only in false value.
-          builder.sortLimit(0, 1,
-              ImmutableList.of(builder.desc(builder.field("cs"))));
         } else {
           builder.distinct();
         }
+        // sorts input with desc order since we are interested
+        // only in the case when one of the values is true.
+        // When true value is absent then we are interested
+        // only in false value.
+        builder.sortLimit(0, 1,

Review Comment:
   This includes the `order by cs limit 1` clause in the correlated query case. 
Without it, multiple rows are returned, as described in the issue.



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