Skip to main content

linkrs_query/optimizer/cost_based/aggregate_strategy/
context.rs

1//! Contextual information for the selection of aggregation strategies.
2
3/// Contextual information for the selection of aggregation strategies
4#[derive(Debug, Clone)]
5pub struct AggregateContext {
6    /// Number of input lines
7    pub input_rows: u64,
8    /// List of grouping keys
9    pub group_keys: Vec<String>,
10    /// Number of aggregate functions
11    pub agg_function_count: usize,
12    /// Memory limit (in bytes; 0 indicates no limit)
13    pub memory_limit: u64,
14    /// Are the input data already sorted?
15    pub input_is_sorted: bool,
16    /// Does the sorting key match the grouping key?
17    pub sort_keys_match_group_keys: bool,
18    /// Are aggregate expressions deterministic?
19    pub is_deterministic: bool,
20    /// Aggregation expression complexity score
21    pub complexity_score: u32,
22    /// Table name (tag name) for statistics lookup
23    pub table_name: Option<String>,
24}
25
26impl AggregateContext {
27    /// Create a new aggregation context.
28    pub fn new(input_rows: u64, group_keys: Vec<String>, agg_function_count: usize) -> Self {
29        Self {
30            input_rows,
31            group_keys,
32            agg_function_count,
33            memory_limit: 0,
34            input_is_sorted: false,
35            sort_keys_match_group_keys: false,
36            is_deterministic: true,
37            complexity_score: 0,
38            table_name: None,
39        }
40    }
41
42    /// Setting memory limits
43    pub fn with_memory_limit(mut self, memory_limit: u64) -> Self {
44        self.memory_limit = memory_limit;
45        self
46    }
47
48    /// Set the input to be sorted.
49    pub fn with_sorted_input(mut self, sort_keys_match: bool) -> Self {
50        self.input_is_sorted = true;
51        self.sort_keys_match_group_keys = sort_keys_match;
52        self
53    }
54
55    /// Setting expression properties
56    pub fn with_expression_analysis(
57        mut self,
58        is_deterministic: bool,
59        complexity_score: u32,
60    ) -> Self {
61        self.is_deterministic = is_deterministic;
62        self.complexity_score = complexity_score;
63        self
64    }
65
66    /// Set table name for statistics lookup
67    pub fn with_table_name(mut self, table_name: Option<String>) -> Self {
68        self.table_name = table_name;
69        self
70    }
71}