Skip to content

Commit

Permalink
sql: remove HashJoin::left_label and right_label
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jul 16, 2024
1 parent daa3260 commit b123bf0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 48 deletions.
10 changes: 1 addition & 9 deletions src/sql/execution/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ pub fn execute(node: Node, txn: &impl Transaction) -> Result<Rows> {
Ok(transform::filter(source, predicate))
}

Node::HashJoin {
left,
left_field,
left_label: _,
right,
right_field,
right_label: _,
outer,
} => {
Node::HashJoin { left, left_field, right, right_field, outer } => {
let right_size = right.size();
let left = execute(*left, txn)?;
let right = execute(*right, txn)?;
Expand Down
16 changes: 2 additions & 14 deletions src/sql/planner/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,16 @@ pub(super) fn join_type(node: Node) -> Result<Node> {
predicate: Some(Expression::Equal(lhs, rhs)),
outer,
} => match (*lhs, *rhs) {
(
Expression::Field(mut left_field, mut left_label),
Expression::Field(mut right_field, mut right_label),
) => {
(Expression::Field(mut left_field, _), Expression::Field(mut right_field, _)) => {
// The LHS field may be a field in the right table; swap them.
if right_field < left_field {
(left_field, right_field) = (right_field, left_field);
(left_label, right_label) = (right_label, left_label);
}
// The NestedLoopJoin predicate uses field indexes in the joined
// row, while the HashJoin uses field indexes for each table
// individually. Adjust the RHS field reference.
right_field -= left.size();
Node::HashJoin {
left,
left_field,
left_label,
right,
right_field,
right_label,
outer,
}
Node::HashJoin { left, left_field, right, right_field, outer }
}
(lhs, rhs) => {
let predicate = Some(Expression::Equal(lhs.into(), rhs.into()));
Expand Down
29 changes: 4 additions & 25 deletions src/sql/planner/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ pub enum Node {
HashJoin {
left: Box<Node>,
left_field: usize,
left_label: Label,
right: Box<Node>,
right_field: usize,
right_label: Label,
outer: bool,
},
/// Looks up the given values in a secondary index and emits matching rows.
Expand Down Expand Up @@ -153,21 +151,11 @@ impl Node {
Self::Filter { source, predicate } => {
Self::Filter { source: transform(source)?, predicate }
}
Self::HashJoin {
left,
left_field,
left_label,
right,
right_field,
right_label,
outer,
} => Self::HashJoin {
Self::HashJoin { left, left_field, right, right_field, outer } => Self::HashJoin {
left: transform(left)?,
left_field,
left_label,
right: transform(right)?,
right_field,
right_label,
outer,
},
Self::Limit { source, limit } => Self::Limit { source: transform(source)?, limit },
Expand Down Expand Up @@ -441,22 +429,13 @@ impl Node {
write!(f, "Filter: {predicate}")?;
source.format(f, prefix, false, true)?;
}
Self::HashJoin {
left,
left_field,
left_label,
right,
right_field,
right_label,
outer,
..
} => {
Self::HashJoin { left, left_field, right, right_field, outer } => {
let kind = if *outer { "outer" } else { "inner" };
let left_label = match left_label {
let left_label = match left.column_label(*left_field) {
Label::None => format!("left #{left_field}"),
label => format!("{label}"),
};
let right_label = match right_label {
let right_label = match right.column_label(*right_field) {
Label::None => format!("right #{right_field}"),
label => format!("{label}"),
};
Expand Down

0 comments on commit b123bf0

Please sign in to comment.