You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kosiew (via GitHub)" <gi...@apache.org> on 2026/06/10 08:17:19 UTC
[PR] Refactor outer join null-rejection analysis to track join sides directly [datafusion]
kosiew opened a new pull request, #22870:
URL: https://github.com/apache/datafusion/pull/22870
### Which issue does this PR close?
* Part of #22686
## Rationale for this change
`EliminateOuterJoin` makes join conversion decisions using side-level null-rejection information (`left_non_nullable` and `right_non_nullable`), but the existing implementation first collects null-rejecting columns and then derives side-level evidence by scanning that collection.
This intermediate column-based representation adds indirection and complicates reasoning about `AND`/`OR` null-rejection semantics. This change refactors the analysis to track null-rejection evidence directly at the join-side level while preserving existing behavior.
## What changes are included in this PR?
* Replaced column-based null-rejection tracking with a new private `NullRejectingSides` helper type containing `left` and `right` boolean flags.
* Added helper methods for combining side-level evidence:
* `union`
* `intersection`
* Refactored null-rejection extraction to return side-level evidence directly via `extract_null_rejecting_sides`.
* Simplified `try_simplify_join` by removing the intermediate `Vec<Column>` collection and schema scan used to derive side-level information.
* Preserved existing null-rejection semantics for:
* top-level `AND` chains
* `OR` expressions
* nested `AND` expressions
* null-propagating operators
* `IS NOT NULL`, `IS TRUE`, `IS FALSE`, and `IS NOT UNKNOWN` top-level handling
* Added unit tests for:
* `NullRejectingSides::union`
* `NullRejectingSides::intersection`
## Are these changes tested?
Yes.
Added unit tests covering:
* `null_rejecting_sides_union`
* `null_rejecting_sides_intersection`
The existing `eliminate_outer_join` test suite is expected to continue validating optimizer behavior unchanged, since this is intended to be a behavior-preserving refactor.
## Are there any user-facing changes?
No.
This is an internal optimizer refactor intended to preserve existing join-elimination behavior and does not change public APIs or SQL semantics.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Refactor outer join null-rejection analysis to track join sides directly [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #22870:
URL: https://github.com/apache/datafusion/pull/22870#issuecomment-4732483796
@neilconway
Thanks for the review and feedback.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Refactor outer join null-rejection analysis to track join sides directly [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on PR #22870:
URL: https://github.com/apache/datafusion/pull/22870#issuecomment-4731553186
Thanks @kosiew ! This is a nice cleanup.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Refactor outer join null-rejection analysis to track join sides directly [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway merged PR #22870:
URL: https://github.com/apache/datafusion/pull/22870
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Refactor outer join null-rejection analysis to track join sides directly [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on code in PR #22870:
URL: https://github.com/apache/datafusion/pull/22870#discussion_r3423902646
##########
datafusion/optimizer/src/eliminate_outer_join.rs:
##########
@@ -252,190 +242,134 @@ pub fn eliminate_outer(
}
}
-/// Find the columns that `expr` rejects NULL on. If any of these columns are
-/// NULL, `expr` is guaranteed to evaluate to NULL or false, and the row
-/// therefore cannot survive a WHERE clause. Matching columns are appended to
-/// `null_rejecting_cols`.
-///
-/// The caller uses the result to decide whether an outer join's null-padded
-/// rows could survive the predicate above the join: if a column from the
-/// nullable side appears in `null_rejecting_cols`, it cannot, and the outer
-/// join can be converted to an inner join.
+#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
+struct NullRejectingSides {
+ left: bool,
+ right: bool,
+}
+
+impl NullRejectingSides {
+ fn for_column(col: &Column, left_schema: &DFSchema, right_schema: &DFSchema) -> Self {
+ Self {
+ left: left_schema.has_column(col),
+ right: right_schema.has_column(col),
+ }
+ }
+
+ fn union(self, other: Self) -> Self {
+ Self {
+ left: self.left || other.left,
+ right: self.right || other.right,
+ }
+ }
+
+ fn intersection(self, other: Self) -> Self {
+ Self {
+ left: self.left && other.left,
+ right: self.right && other.right,
+ }
+ }
+}
+
+/// Compute which join sides cannot be NULL-padded and still pass `expr` in a
+/// WHERE clause. A marked side means rows with that side padded to NULL are
+/// guaranteed to evaluate to NULL or false and be filtered out.
Review Comment:
```suggestion
/// Compute which join sides are null-rejected by `expr` in a WHERE clause.
/// For each marked side, rows padded with NULLs on that side are guaranteed to
/// evaluate to NULL or false and be filtered out.
```
##########
datafusion/optimizer/src/eliminate_outer_join.rs:
##########
@@ -146,36 +146,26 @@ impl OptimizerRule for EliminateOuterJoin {
}
}
-/// Run the null-rejection analysis on `predicate` against `join`'s left/right
-/// schemas. Return `Some(new_join_plan)` if the join type can be tightened
-/// (e.g. LEFT → INNER), `None` otherwise.
+/// Determine which null-padded sides of `join` are rejected by `predicate`.
+/// Return `Some(new_join_plan)` if that side-level evidence can tighten the
+/// join type (e.g. LEFT → INNER), `None` otherwise.
Review Comment:
```suggestion
/// Attempt to simplify an outer join by analyzing `predicate` for
/// null-rejection. If the predicate filters out rows padded with NULLs on one
/// or both sides, return a copy of `join` rewritten to an equivalent join type
/// that omits those rows in the first place; otherwise return `None`.
```
##########
datafusion/optimizer/src/eliminate_outer_join.rs:
##########
@@ -252,190 +242,134 @@ pub fn eliminate_outer(
}
}
-/// Find the columns that `expr` rejects NULL on. If any of these columns are
-/// NULL, `expr` is guaranteed to evaluate to NULL or false, and the row
-/// therefore cannot survive a WHERE clause. Matching columns are appended to
-/// `null_rejecting_cols`.
-///
-/// The caller uses the result to decide whether an outer join's null-padded
-/// rows could survive the predicate above the join: if a column from the
-/// nullable side appears in `null_rejecting_cols`, it cannot, and the outer
-/// join can be converted to an inner join.
+#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
+struct NullRejectingSides {
+ left: bool,
+ right: bool,
+}
+
+impl NullRejectingSides {
+ fn for_column(col: &Column, left_schema: &DFSchema, right_schema: &DFSchema) -> Self {
+ Self {
+ left: left_schema.has_column(col),
+ right: right_schema.has_column(col),
+ }
+ }
Review Comment:
I think this merits an explanatory comment; it's a bit obscure what a helper called `for_column` is actually doing (the name just describes the input, not what the function really does). Maybe add a header comment like
```rust
/// The join side(s) a column belongs to.
///
/// A bare column reference is null-rejecting on its own side: if the column
/// is NULL, every null-propagating operator above it yields NULL and the row
/// is filtered.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org