Skip to main content

featherdb_query/planner/
types.rs

1//! Basic types for query planning
2
3use featherdb_core::Value;
4
5/// Sort order
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum SortOrder {
8    Asc,
9    Desc,
10}
11
12/// Join type
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum JoinType {
15    Inner,
16    Left,
17    Right,
18    Full,
19}
20
21/// Bound for index range scans
22#[derive(Debug, Clone, PartialEq)]
23pub enum IndexBound {
24    /// Unbounded (scan from start or to end)
25    Unbounded,
26    /// Inclusive bound
27    Inclusive(Value),
28    /// Exclusive bound
29    Exclusive(Value),
30}
31
32/// Range specification for index scans
33#[derive(Debug, Clone)]
34pub struct IndexRange {
35    /// Lower bound of the range
36    pub start: IndexBound,
37    /// Upper bound of the range
38    pub end: IndexBound,
39}
40
41impl IndexRange {
42    /// Create a point lookup range (equality)
43    pub fn point(value: Value) -> Self {
44        IndexRange {
45            start: IndexBound::Inclusive(value.clone()),
46            end: IndexBound::Inclusive(value),
47        }
48    }
49
50    /// Create a range from start to end (both inclusive)
51    pub fn between(start: Value, end: Value) -> Self {
52        IndexRange {
53            start: IndexBound::Inclusive(start),
54            end: IndexBound::Inclusive(end),
55        }
56    }
57
58    /// Create a range >= value
59    pub fn from_inclusive(value: Value) -> Self {
60        IndexRange {
61            start: IndexBound::Inclusive(value),
62            end: IndexBound::Unbounded,
63        }
64    }
65
66    /// Create a range > value
67    pub fn from_exclusive(value: Value) -> Self {
68        IndexRange {
69            start: IndexBound::Exclusive(value),
70            end: IndexBound::Unbounded,
71        }
72    }
73
74    /// Create a range <= value
75    pub fn to_inclusive(value: Value) -> Self {
76        IndexRange {
77            start: IndexBound::Unbounded,
78            end: IndexBound::Inclusive(value),
79        }
80    }
81
82    /// Create a range < value
83    pub fn to_exclusive(value: Value) -> Self {
84        IndexRange {
85            start: IndexBound::Unbounded,
86            end: IndexBound::Exclusive(value),
87        }
88    }
89
90    /// Create an unbounded range (full scan)
91    pub fn full() -> Self {
92        IndexRange {
93            start: IndexBound::Unbounded,
94            end: IndexBound::Unbounded,
95        }
96    }
97
98    /// Check if this is a point lookup (equality)
99    pub fn is_point_lookup(&self) -> bool {
100        match (&self.start, &self.end) {
101            (IndexBound::Inclusive(s), IndexBound::Inclusive(e)) => s == e,
102            _ => false,
103        }
104    }
105}