Skip to main content

linkrs_query/optimizer/cost_based/join_order/
table_info.rs

1//! Table information used by the join order optimizer.
2
3/// Table information
4#[derive(Debug, Clone)]
5pub struct TableInfo {
6    /// Table identifier (variable name)
7    pub id: String,
8    /// Estimated number of lines
9    pub estimated_rows: u64,
10    /// Selective (0.0 ~ 1.0)
11    pub selectivity: f64,
12    /// Is there an index available?
13    pub has_index: bool,
14    /// The unique identifier of the table (used for bit operations)
15    pub bit_id: u32,
16}
17
18impl TableInfo {
19    /// Create information for a new table.
20    pub fn new(id: String, estimated_rows: u64) -> Self {
21        Self {
22            id,
23            estimated_rows,
24            selectivity: 1.0,
25            has_index: false,
26            bit_id: 0,
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    /// Set whether an index is to be created.
37    pub fn with_index(mut self, has_index: bool) -> Self {
38        self.has_index = has_index;
39        self
40    }
41
42    /// Set Bit ID
43    pub fn with_bit_id(mut self, bit_id: u32) -> Self {
44        self.bit_id = bit_id;
45        self
46    }
47}