Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/rewrite/exploitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Fn(&dyn ExecutionPlan) -> f64 + Send + Sync>;
pub type CostFn = Arc<
dyn for<'a> Fn(Box<dyn Iterator<Item = &'a dyn ExecutionPlan> + 'a>) -> Vec<f64> + Send + Sync,
>;

/// A logical optimizer that generates candidate logical plans in the form of [`OneOf`] nodes.
#[derive(Debug)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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!(
Expand Down
Loading