kumarUjjawal commented on code in PR #27544:
URL: https://github.com/apache/datafusion/pull/27544#discussion_r4667616234
##########
datafusion/optimizer/src/decorrelate_predicate_subquery.rs:
##########
@@ -1326,7 +1324,9 @@ fn build_join_with_count_bug(
let indicator_col = Expr::Column(Column::new(Some(alias),
UN_MATCHED_ROW_INDICATOR));
- let having_arm = pull_up_having_expr.map(|f| f.clone().is_not_true());
+ let having_arm = pull_up_having_expr
Review Comment:
`indicator_col`, `having_arm` and `unmatched_having_default` are each built
on their own, then matched on `having_arm`. All three are only needed when a
HAVING expression exists, so a single `match pull_up_having_expr { Some(f) =>
..., None => lit(true) }` could build them together.
##########
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:
The comment says the subquery is moved "instead of cloning", but
`Arc::unwrap_or_clone(plan)` still clones the root node whenever the subquery's
`Arc<LogicalPlan>` is shared.
--
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]