diff --git a/src/rewrite/exploitation.rs b/src/rewrite/exploitation.rs index eef0708..11bcc14 100644 --- a/src/rewrite/exploitation.rs +++ b/src/rewrite/exploitation.rs @@ -42,7 +42,9 @@ use super::normal_form::SpjNormalForm; use super::QueryRewriteOptions; /// A cost function. Used to evaluate the best physical plan among multiple equivalent choices. -pub type CostFn = Arc f64 + Send + Sync>; +pub type CostFn = Arc< + dyn for<'a> Fn(Box + 'a>) -> Vec + Send + Sync, +>; /// A logical optimizer that generates candidate logical plans in the form of [`OneOf`] nodes. #[derive(Debug)] @@ -346,9 +348,10 @@ impl OneOfExec { "can't create OneOfExec with empty children".to_string(), )); } - let best = candidates + + let best = cost(Box::new(candidates.iter().map(|c| c.as_ref()))) .iter() - .position_min_by_key(|candidate| OrderedFloat(cost(candidate.as_ref()))) + .position_min_by_key(|&cost| OrderedFloat(*cost)) .unwrap(); Ok(Self { @@ -441,11 +444,7 @@ impl ExecutionPlan for OneOfExec { impl DisplayAs for OneOfExec { fn fmt_as(&self, t: DisplayFormatType, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let costs = self - .children() - .iter() - .map(|c| (self.cost)(c.as_ref())) - .collect_vec(); + let costs = (self.cost)(Box::new(self.children().iter().map(|arc| arc.as_ref()))); match t { DisplayFormatType::Default | DisplayFormatType::Verbose => { write!(