Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
refactor(core): drop predicate binding interfaces (#236)
Browse files Browse the repository at this point in the history
They are not used any more after the predicate refactor.

Signed-off-by: Alex Chi <iskyzh@gmail.com>
  • Loading branch information
skyzh authored Nov 13, 2024
1 parent b4061b1 commit 342f2fb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
63 changes: 0 additions & 63 deletions optd-core/src/cascades/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,6 @@ pub trait Memo<T: NodeType>: 'static + Send + Sync {
) -> Result<ArcPlanNode<T>> {
get_best_group_binding_inner(self, group_id, &mut post_process)
}

/// Get all bindings of a predicate group. Will panic if the group contains more than one
/// bindings. Note that we are currently in the refactor process of having predicates as a
/// separate entity. If the representation stores predicates in the rel node children, the
/// repr should use this function to get the predicate binding. Otherwise, use `ger_pred`
/// for those predicates stored within the `predicates` field.
///
/// TODO: this can be removed after the predicate refactor, unless someone comes up with a
/// plan representation that embeds predicates in the plan node.
fn get_predicate_binding(&self, group_id: GroupId) -> Option<ArcPlanNode<T>> {
get_predicate_binding_group_inner(self, group_id, true)
}

/// Get all bindings of a predicate group. Returns None if the group contains zero or more than
/// one bindings.
fn try_get_predicate_binding(&self, group_id: GroupId) -> Option<ArcPlanNode<T>> {
get_predicate_binding_group_inner(self, group_id, false)
}
}

fn get_best_group_binding_inner<M: Memo<T> + ?Sized, T: NodeType>(
Expand Down Expand Up @@ -204,51 +186,6 @@ fn get_best_group_binding_inner<M: Memo<T> + ?Sized, T: NodeType>(
bail!("no best group binding for group {}", group_id)
}

fn get_predicate_binding_expr_inner<M: Memo<T> + ?Sized, T: NodeType>(
this: &M,
expr_id: ExprId,
panic_on_invalid_group: bool,
) -> Option<ArcPlanNode<T>> {
let expr = this.get_expr_memoed(expr_id);
let mut children = Vec::with_capacity(expr.children.len());
for child in expr.children.iter() {
if let Some(child) = get_predicate_binding_group_inner(this, *child, panic_on_invalid_group)
{
children.push(PlanNodeOrGroup::PlanNode(child));
} else {
return None;
}
}
Some(Arc::new(PlanNode {
typ: expr.typ.clone(),
children,
predicates: expr.predicates.iter().map(|x| this.get_pred(*x)).collect(),
}))
}

fn get_predicate_binding_group_inner<M: Memo<T> + ?Sized, T: NodeType>(
this: &M,
group_id: GroupId,
panic_on_invalid_group: bool,
) -> Option<ArcPlanNode<T>> {
let exprs = this.get_all_exprs_in_group(group_id);
match exprs.len() {
0 => None,
1 => get_predicate_binding_expr_inner(
this,
exprs.first().copied().unwrap(),
panic_on_invalid_group,
),
len => {
if panic_on_invalid_group {
panic!("group {group_id} has {len} expressions")
} else {
None
}
}
}
}

/// A naive, simple, and unoptimized memo table implementation.
pub struct NaiveMemo<T: NodeType> {
// Source of truth.
Expand Down
7 changes: 0 additions & 7 deletions optd-core/src/cascades/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ impl<T: NodeType, M: Memo<T>> CascadesOptimizer<T, M> {
group.properties[id].as_ref()
)
}
if let Some(predicate_binding) = self.memo.try_get_predicate_binding(group_id) {
println!(" predicate={}", predicate_binding);
}
let mut all_predicates = BTreeSet::new();
for expr_id in self.memo.get_all_exprs_in_group(group_id) {
let memo_node = self.memo.get_expr_memoed(expr_id);
Expand Down Expand Up @@ -348,10 +345,6 @@ impl<T: NodeType, M: Memo<T>> CascadesOptimizer<T, M> {
self.memo.get_expr_memoed(expr_id)
}

pub fn get_predicate_binding(&self, group_id: GroupId) -> Option<ArcPlanNode<T>> {
self.memo.get_predicate_binding(group_id)
}

pub fn get_pred(&self, pred_id: PredId) -> ArcPredNode<T> {
self.memo.get_pred(pred_id)
}
Expand Down

0 comments on commit 342f2fb

Please sign in to comment.