Omkar-Wagholikar commented on code in PR #27544:
URL: https://github.com/apache/datafusion/pull/27544#discussion_r4669597497


##########
datafusion/optimizer/src/rewrite_set_comparison.rs:
##########
@@ -105,53 +107,51 @@ fn build_set_comparison_subquery(
         Box::new(right_expr),
     ));
 
-    let true_exists =
-        exists_subquery(&subquery, 
Expr::IsTrue(Box::new(comparison.clone())))?;
-    let null_exists =
-        exists_subquery(&subquery, 
Expr::IsNull(Box::new(comparison.clone())))?;
-
-    let result_expr = match quantifier {
-        SetQuantifier::Any => Expr::Case(expr::Case {
-            expr: None,
-            when_then_expr: vec![
-                (Box::new(true_exists), Box::new(lit(true))),
-                (
-                    Box::new(null_exists),
-                    Box::new(Expr::Literal(ScalarValue::Boolean(None), None)),
-                ),
-            ],
-            else_expr: Some(Box::new(lit(false))),
-        }),
-        SetQuantifier::All => {
-            let false_exists =
-                exists_subquery(&subquery, 
Expr::IsFalse(Box::new(comparison.clone())))?;
-            Expr::Case(expr::Case {
-                expr: None,
-                when_then_expr: vec![
-                    (Box::new(false_exists), Box::new(lit(false))),
-                    (
-                        Box::new(null_exists),
-                        Box::new(Expr::Literal(ScalarValue::Boolean(None), 
None)),
-                    ),
-                ],
-                else_expr: Some(Box::new(lit(true))),
-            })
-        }
+    let Subquery {
+        subquery: plan,
+        spans,
+        ..
+    } = subquery;
+    let null_exists = exists_subquery(
+        plan.as_ref().clone(),
+        spans.clone(),
+        Expr::IsNull(Box::new(comparison.clone())),
+    )?;
+
+    let (filter, found): (fn(Box<Expr>) -> Expr, bool) = match quantifier {
+        SetQuantifier::Any => (Expr::IsTrue, true),
+        SetQuantifier::All => (Expr::IsFalse, false),
     };
+    // The last use of the subquery, so move it instead of cloning.

Review Comment:
   deleted the comment instead of rewording it, It could have been rephrased to 
something along the lines of: 'avoids a clone when the `Arc` is not shared' but 
even without a comment the code makes sense I think.
   I will add it back if you feel it is 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to