From 5f444158432a09f9ba457cfef7273a5ac98551fb Mon Sep 17 00:00:00 2001 From: Alex Chi Date: Wed, 13 Nov 2024 00:19:42 -0500 Subject: [PATCH] refactor(core): drop predicate binding interfaces Signed-off-by: Alex Chi --- optd-core/src/cascades/memo.rs | 63 ----------------------------- optd-core/src/cascades/optimizer.rs | 7 ---- 2 files changed, 70 deletions(-) diff --git a/optd-core/src/cascades/memo.rs b/optd-core/src/cascades/memo.rs index bbe182d4..31fb4506 100644 --- a/optd-core/src/cascades/memo.rs +++ b/optd-core/src/cascades/memo.rs @@ -158,24 +158,6 @@ pub trait Memo: 'static + Send + Sync { ) -> Result> { 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> { - 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> { - get_predicate_binding_group_inner(self, group_id, false) - } } fn get_best_group_binding_inner + ?Sized, T: NodeType>( @@ -204,51 +186,6 @@ fn get_best_group_binding_inner + ?Sized, T: NodeType>( bail!("no best group binding for group {}", group_id) } -fn get_predicate_binding_expr_inner + ?Sized, T: NodeType>( - this: &M, - expr_id: ExprId, - panic_on_invalid_group: bool, -) -> Option> { - 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 + ?Sized, T: NodeType>( - this: &M, - group_id: GroupId, - panic_on_invalid_group: bool, -) -> Option> { - 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 { // Source of truth. diff --git a/optd-core/src/cascades/optimizer.rs b/optd-core/src/cascades/optimizer.rs index 2af46e12..d1b66607 100644 --- a/optd-core/src/cascades/optimizer.rs +++ b/optd-core/src/cascades/optimizer.rs @@ -196,9 +196,6 @@ impl> CascadesOptimizer { 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); @@ -348,10 +345,6 @@ impl> CascadesOptimizer { self.memo.get_expr_memoed(expr_id) } - pub fn get_predicate_binding(&self, group_id: GroupId) -> Option> { - self.memo.get_predicate_binding(group_id) - } - pub fn get_pred(&self, pred_id: PredId) -> ArcPredNode { self.memo.get_pred(pred_id) }