comphead commented on code in PR #26013:
URL: https://github.com/apache/datafusion/pull/26013#discussion_r4296833568


##########
datafusion/optimizer/src/decorrelate.rs:
##########
@@ -828,6 +888,24 @@ fn can_pullup_over_aggregation(expr: &Expr) -> bool {
     }
 }
 
+/// Whether `expr` is `col = <expr>` or `<expr> = col`, where `<expr>` reads no
+/// subquery column. `CAST(col AS ..)` does not qualify: a lossy cast lets
+/// several `col` values match one outer row, see #26014.
+fn is_column_equality(expr: &Expr) -> bool {
+    let Expr::BinaryExpr(BinaryExpr {
+        left,
+        op: Operator::Eq,
+        right,
+    }) = expr
+    else {
+        return false;
+    };
+    match (&**left, &**right) {
+        (Expr::Column(_), other) | (other, Expr::Column(_)) => 
!other.any_column_refs(),

Review Comment:
   Fixed in 0092bee2a. A cast now qualifies when `is_injective_cast` holds, so 
`INT = BIGINT` coercion is accepted. That helper existed as a private map key 
helper in `datafusion-common`, so I renamed it and made it `pub`. Lossy casts 
still stay correlated (#26014), and a new slt case covers the widening cast.



##########
datafusion/optimizer/src/decorrelate.rs:
##########
@@ -828,6 +888,24 @@ fn can_pullup_over_aggregation(expr: &Expr) -> bool {
     }
 }
 
+/// Whether `expr` is `col = <expr>` or `<expr> = col`, where `<expr>` reads no
+/// subquery column. `CAST(col AS ..)` does not qualify: a lossy cast lets
+/// several `col` values match one outer row, see #26014.
+fn is_column_equality(expr: &Expr) -> bool {

Review Comment:
   Fixed in 0092bee2a. `can_pullup_over_aggregation` and the new check now 
share `split_column_equality`.



##########
datafusion/optimizer/src/decorrelate.rs:
##########


Review Comment:
   This also fails on `main` today, because `remove_duplicated_filter` drops 
the correlated filter before `correlated_subquery_cols_map` records it. It is 
tracked in #26032, so I kept this PR scoped. The PR does not make that case 
worse.



##########
datafusion/optimizer/src/decorrelate.rs:
##########


Review Comment:
   Updated in 0092bee2a.



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