diff --git a/optd-core/src/cascades/memo.rs b/optd-core/src/cascades/memo.rs index b46296d1..ec102ad5 100644 --- a/optd-core/src/cascades/memo.rs +++ b/optd-core/src/cascades/memo.rs @@ -495,37 +495,6 @@ impl Memo { grp.unwrap().info = group_info; } - /// Gets the best group binding with metadata collected. - pub fn get_best_group_binding_with_meta( - &self, - group_id: GroupId, - meta: &mut RelNodeMetaMap, - ) -> Result> { - let info = self.get_group_info(group_id); - if let Some(winner) = info.winner { - if !winner.impossible { - let expr_id = winner.expr_id; - let expr = self.get_expr_memoed(expr_id); - let mut children = Vec::with_capacity(expr.children.len()); - for child in &expr.children { - children.push(self.get_best_group_binding_with_meta(*child, meta)?); - } - let node = Arc::new(RelNode { - typ: expr.typ.clone(), - children, - data: expr.data.clone(), - }); - - meta.insert( - node.as_ref() as *const _ as usize, - RelNodeMeta::new(group_id), - ); - return Ok(node); - } - } - bail!("no best group binding for group {}", group_id) - } - pub fn get_best_group_binding( &self, group_id: GroupId, diff --git a/optd-core/src/cascades/optimizer.rs b/optd-core/src/cascades/optimizer.rs index f6a421d1..a2e4ea7b 100644 --- a/optd-core/src/cascades/optimizer.rs +++ b/optd-core/src/cascades/optimizer.rs @@ -10,7 +10,7 @@ use crate::{ cost::CostModel, optimizer::Optimizer, property::{PropertyBuilder, PropertyBuilderAny}, - rel_node::{RelNodeMeta, RelNodeMetaMap, RelNodeRef, RelNodeTyp}, + rel_node::{RelNodeMetaMap, RelNodeRef, RelNodeTyp}, rules::RuleWrapper, }; diff --git a/optd-core/src/rel_node.rs b/optd-core/src/rel_node.rs index 9f356c6d..bcb474ae 100644 --- a/optd-core/src/rel_node.rs +++ b/optd-core/src/rel_node.rs @@ -203,8 +203,10 @@ impl RelNode { } } +/// Metadata for a rel node. #[derive(Clone, Debug, PartialEq)] pub struct RelNodeMeta { + /// The group (id) of the `RelNode` pub group_id: GroupId, } diff --git a/optd-datafusion-bridge/src/from_optd.rs b/optd-datafusion-bridge/src/from_optd.rs index 31a0c1ea..7765a082 100644 --- a/optd-datafusion-bridge/src/from_optd.rs +++ b/optd-datafusion-bridge/src/from_optd.rs @@ -595,13 +595,18 @@ impl OptdPlanContext<'_> { typ => unimplemented!("{}", typ), }; - let bare_with_collector: Result> = Ok(Arc::new(CollectorExec::new( - bare, - group_id, - self.optimizer.as_ref().unwrap().runtime_statistics.clone(), - )) - as Arc); - bare_with_collector.with_context(|| format!("when processing {}", rel_node_dbg)) + let optimizer = self.optimizer.as_ref().unwrap(); + if optimizer.adaptive_enabled() { + let bare_with_collector: Result> = + Ok(Arc::new(CollectorExec::new( + bare, + group_id, + self.optimizer.as_ref().unwrap().runtime_statistics.clone(), + )) as Arc); + bare_with_collector.with_context(|| format!("when processing {}", rel_node_dbg)) + } else { + Ok(bare) + } } pub async fn conv_from_optd( diff --git a/optd-datafusion-repr/src/lib.rs b/optd-datafusion-repr/src/lib.rs index 92a71730..fe9ae850 100644 --- a/optd-datafusion-repr/src/lib.rs +++ b/optd-datafusion-repr/src/lib.rs @@ -40,6 +40,10 @@ impl DatafusionOptimizer { self.enable_adaptive = enable; } + pub fn adaptive_enabled(&self) -> bool { + self.enable_adaptive + } + pub fn optd_optimizer(&self) -> &CascadesOptimizer { &self.optimizer }