1use crate::PhysicalPlan;
2
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub struct Cost(pub f64);
5
6pub trait CostModel {
7 fn cost(&self, plan: &PhysicalPlan) -> Cost;
8}
9
10impl PhysicalPlan {
11 pub fn node_count(&self) -> usize {
12 match self {
13 PhysicalPlan::TableScan { .. } => 1,
14 PhysicalPlan::IndexScan { .. } => 1,
15 PhysicalPlan::Dml { .. } => 1,
16 PhysicalPlan::Derived { input, .. } => 1 + input.node_count(),
17 PhysicalPlan::Filter { input, .. } => 1 + input.node_count(),
18 PhysicalPlan::Projection { input, .. } => 1 + input.node_count(),
19 PhysicalPlan::Join { left, right, .. } => 1 + left.node_count() + right.node_count(),
20 PhysicalPlan::Aggregate { input, .. } => 1 + input.node_count(),
21 PhysicalPlan::Distinct { input } => 1 + input.node_count(),
22 PhysicalPlan::TopN { input, .. } => 1 + input.node_count(),
23 PhysicalPlan::Sort { input, .. } => 1 + input.node_count(),
24 PhysicalPlan::Limit { input, .. } => 1 + input.node_count(),
25 }
26 }
27}