Skip to main content

linkrs_query/optimizer/cost_based/join_order/
condition.rs

1//! Join condition description used by the join order optimizer.
2
3use crate::optimizer::cost_based::ndv::DEFAULT_JOIN_SELECTIVITY;
4use linkrs_core::types::ContextualExpression;
5
6/// Connection conditions
7#[derive(Debug, Clone)]
8pub struct JoinCondition {
9    /// Left table ID
10    pub left_table: String,
11    /// Right table ID
12    pub right_table: String,
13    /// Connection selectivity (estimated proportion of successful connection outcomes)
14    pub selectivity: f64,
15    /// Connection expression
16    pub expression: Option<ContextualExpression>,
17}
18
19impl JoinCondition {
20    /// Create new connection conditions.
21    pub fn new(left_table: String, right_table: String) -> Self {
22        Self {
23            left_table,
24            right_table,
25            selectivity: DEFAULT_JOIN_SELECTIVITY,
26            expression: None,
27        }
28    }
29
30    /// Set the option to be selective.
31    pub fn with_selectivity(mut self, selectivity: f64) -> Self {
32        self.selectivity = selectivity.clamp(0.0, 1.0);
33        self
34    }
35
36    /// Setting the connection expression
37    pub fn with_expression(mut self, expression: ContextualExpression) -> Self {
38        self.expression = Some(expression);
39        self
40    }
41}