use super::CostCalculator;
impl CostCalculator {
pub fn calculate_hash_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
let build_cost = left_rows as f64 * self.config.cpu_tuple_cost;
let probe_cost = right_rows as f64 * self.config.cpu_tuple_cost;
let hash_overhead =
left_rows as f64 * self.config.hash_build_overhead * self.config.cpu_operator_cost;
build_cost + probe_cost + hash_overhead
}
pub fn calculate_hash_left_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
self.calculate_hash_join_cost(left_rows, right_rows) * 1.1
}
pub fn calculate_inner_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
self.calculate_nested_loop_join_cost(left_rows, right_rows)
}
pub fn calculate_left_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
self.calculate_nested_loop_join_cost(left_rows, right_rows) * 1.1
}
pub fn calculate_cross_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
let output_rows = left_rows as f64 * right_rows as f64;
output_rows * self.config.cpu_tuple_cost
}
pub fn calculate_nested_loop_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
let outer_cost = left_rows as f64 * self.config.cpu_tuple_cost;
let inner_cost = left_rows as f64 * right_rows as f64 * self.config.cpu_tuple_cost;
outer_cost + inner_cost
}
pub fn calculate_full_outer_join_cost(&self, left_rows: u64, right_rows: u64) -> f64 {
let base_cost = self.calculate_hash_join_cost(left_rows, right_rows);
base_cost * 1.5 }
}