Skip to content

Commit 12c0381

Browse files
committed
fix: respect null_equals_null in eliminate_cross_join rule
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
1 parent 3a1574d commit 12c0381

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

datafusion/optimizer/src/eliminate_cross_join.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl OptimizerRule for EliminateCrossJoin {
8989
let mut possible_join_keys = JoinKeySet::new();
9090
let mut all_inputs: Vec<LogicalPlan> = vec![];
9191
let mut all_filters: Vec<Expr> = vec![];
92+
let mut null_equals_null = false;
9293

9394
let parent_predicate = if let LogicalPlan::Filter(filter) = plan {
9495
// if input isn't a join that can potentially be rewritten
@@ -122,26 +123,30 @@ impl OptimizerRule for EliminateCrossJoin {
122123

123124
extract_possible_join_keys(&predicate, &mut possible_join_keys);
124125
Some(predicate)
125-
} else if matches!(
126-
plan,
127-
LogicalPlan::Join(Join {
128-
join_type: JoinType::Inner,
129-
..
130-
})
131-
) {
132-
if !can_flatten_join_inputs(&plan) {
133-
return Ok(Transformed::no(plan));
134-
}
135-
flatten_join_inputs(
136-
plan,
137-
&mut possible_join_keys,
138-
&mut all_inputs,
139-
&mut all_filters,
140-
)?;
141-
None
142126
} else {
143-
// recursively try to rewrite children
144-
return rewrite_children(self, plan, config);
127+
match plan {
128+
LogicalPlan::Join(Join {
129+
join_type: JoinType::Inner,
130+
null_equals_null: original_null_equals_null,
131+
..
132+
}) => {
133+
if !can_flatten_join_inputs(&plan) {
134+
return Ok(Transformed::no(plan));
135+
}
136+
flatten_join_inputs(
137+
plan,
138+
&mut possible_join_keys,
139+
&mut all_inputs,
140+
&mut all_filters,
141+
)?;
142+
null_equals_null = original_null_equals_null;
143+
None
144+
}
145+
_ => {
146+
// recursively try to rewrite children
147+
return rewrite_children(self, plan, config);
148+
}
149+
}
145150
};
146151

147152
// Join keys are handled locally:
@@ -153,6 +158,7 @@ impl OptimizerRule for EliminateCrossJoin {
153158
&mut all_inputs,
154159
&possible_join_keys,
155160
&mut all_join_keys,
161+
null_equals_null,
156162
)?;
157163
}
158164

@@ -290,6 +296,7 @@ fn find_inner_join(
290296
rights: &mut Vec<LogicalPlan>,
291297
possible_join_keys: &JoinKeySet,
292298
all_join_keys: &mut JoinKeySet,
299+
null_equals_null: bool,
293300
) -> Result<LogicalPlan> {
294301
for (i, right_input) in rights.iter().enumerate() {
295302
let mut join_keys = vec![];
@@ -328,7 +335,7 @@ fn find_inner_join(
328335
on: join_keys,
329336
filter: None,
330337
schema: join_schema,
331-
null_equals_null: false,
338+
null_equals_null,
332339
}));
333340
}
334341
}

0 commit comments

Comments
 (0)