Skip to content

Commit

Permalink
refactor(df-repr): remove cross join, use inner join (#265)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
  • Loading branch information
skyzh committed Dec 19, 2024
1 parent b4b1aea commit e599545
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 43 deletions.
5 changes: 3 additions & 2 deletions optd-datafusion-bridge/src/from_optd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ impl OptdPlanContext<'_> {
let physical_expr =
self.conv_from_optd_expr(node.cond(), &Arc::new(filter_schema.clone()))?;

if *node.join_type() == JoinType::Cross {
if node.join_type() == &JoinType::Inner
&& node.cond() == ConstantPred::bool(true).into_pred_node()
{
return Ok(Arc::new(CrossJoinExec::new(left_exec, right_exec))
as Arc<dyn ExecutionPlan + 'static>);
}
Expand All @@ -491,7 +493,6 @@ impl OptdPlanContext<'_> {
JoinType::LeftAnti => datafusion_expr::JoinType::LeftAnti,
JoinType::RightAnti => datafusion_expr::JoinType::RightAnti,
JoinType::LeftMark => datafusion_expr::JoinType::LeftMark,
_ => unimplemented!(),
};

let mut column_idxs = vec![];
Expand Down
2 changes: 1 addition & 1 deletion optd-datafusion-bridge/src/into_optd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl OptdPlanContext<'_> {
left,
right,
ConstantPred::bool(true).into_pred_node(),
JoinType::Cross,
JoinType::Inner,
))
} else if log_ops.len() == 1 {
Ok(LogicalJoin::new(left, right, log_ops.remove(0), join_type))
Expand Down
7 changes: 0 additions & 7 deletions optd-datafusion-repr-adv-cost/src/adv_stats/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,6 @@ impl<
JoinType::Inner => inner_join_selectivity,
JoinType::LeftOuter => f64::max(inner_join_selectivity, 1.0 / right_row_cnt),
JoinType::RightOuter => f64::max(inner_join_selectivity, 1.0 / left_row_cnt),
JoinType::Cross => {
assert!(
on_col_ref_pairs.is_empty(),
"Cross joins should not have on columns"
);
join_filter_selectivity
}
// TODO: Does this make sense?
JoinType::LeftMark => f64::max(inner_join_selectivity, 1.0 / right_row_cnt),
_ => unimplemented!("join_typ={} is not implemented", join_typ),
Expand Down
1 change: 0 additions & 1 deletion optd-datafusion-repr/src/plan_nodes/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub enum JoinType {
FullOuter,
LeftOuter,
RightOuter,
Cross,
LeftSemi,
RightSemi,
LeftAnti,
Expand Down
2 changes: 1 addition & 1 deletion optd-datafusion-repr/src/properties/column_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ impl LogicalPropertyBuilder<DfNodeType> for ColumnRefPropertyBuilder {
//
// Otherwise be conservative and discard all correlations.
let output_correlation = match join_type {
JoinType::Inner | JoinType::Cross => {
JoinType::Inner => {
// Merge the equal columns in the join condition into the those from the
// children.
if let Some(SemanticCorrelation {
Expand Down
2 changes: 1 addition & 1 deletion optd-datafusion-repr/src/properties/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl LogicalPropertyBuilder<DfNodeType> for SchemaPropertyBuilder {
DfNodeType::Join(join_type) => {
use crate::plan_nodes::JoinType::*;
match join_type {
Inner | LeftOuter | RightOuter | FullOuter | Cross => {
Inner | LeftOuter | RightOuter | FullOuter => {
let mut schema = children[0].clone();
let schema2 = children[1].clone();
schema.fields.extend(schema2.fields);
Expand Down
26 changes: 0 additions & 26 deletions optd-datafusion-repr/src/rules/filter_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,6 @@ fn apply_filter_merge(
vec![new_filter.into_plan_node().into()]
}

// TODO: define_rule! should be able to match on any join type, ideally...
define_rule!(
FilterCrossJoinTransposeRule,
apply_filter_cross_join_transpose,
(Filter, (Join(JoinType::Cross), child_a, child_b))
);

fn apply_filter_cross_join_transpose(
optimizer: &impl Optimizer<DfNodeType>,
binding: ArcDfPlanNode,
) -> Vec<PlanNodeOrGroup<DfNodeType>> {
filter_join_transpose(optimizer, binding)
}

define_rule!(
FilterInnerJoinTransposeRule,
apply_filter_inner_join_transpose,
Expand Down Expand Up @@ -256,18 +242,6 @@ fn filter_join_transpose(
let new_conds = merge_conds(and_expr_list_to_expr(join_conds), old_cond);
LogicalJoin::new_unchecked(new_left, new_right, new_conds, JoinType::Inner)
}
JoinType::Cross => {
if !join_conds.is_empty() {
LogicalJoin::new_unchecked(
new_left,
new_right,
and_expr_list_to_expr(join_conds),
JoinType::Inner,
)
} else {
LogicalJoin::new_unchecked(new_left, new_right, join_cond, JoinType::Cross)
}
}
_ => {
// We don't support modifying the join condition for other join types yet
LogicalJoin::new_unchecked(new_left, new_right, join_cond, *join_typ)
Expand Down
2 changes: 1 addition & 1 deletion optd-datafusion-repr/src/rules/joins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn apply_eliminate_join(
left,
right,
ConstantPred::bool(true).into_pred_node(),
JoinType::Cross,
JoinType::Inner,
);
return vec![node.into_plan_node().into()];
} else {
Expand Down
6 changes: 3 additions & 3 deletions optd-datafusion-repr/src/rules/subquery/depjoin_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn apply_dep_initial_distinct(
left,
right,
ConstantPred::bool(true).into_pred_node(),
JoinType::Cross,
JoinType::Inner,
)
.into_plan_node(),
SubqueryType::Exists => {
Expand Down Expand Up @@ -122,7 +122,7 @@ fn apply_dep_initial_distinct(
left,
count_star_to_bool_proj,
ConstantPred::bool(true).into_pred_node(),
JoinType::Cross,
JoinType::Inner,
)
.into_plan_node()
}
Expand All @@ -147,7 +147,7 @@ fn apply_dep_initial_distinct(
left,
right,
ConstantPred::bool(true).into_pred_node(),
JoinType::Cross,
JoinType::Inner,
);

return vec![new_join.into_plan_node().into()];
Expand Down

0 comments on commit e599545

Please sign in to comment.