icydb_core/db/plan/
contract.rs1#[cfg(test)]
4use crate::db::access::AccessPath;
5#[cfg(test)]
6use crate::db::intent::LoadSpec;
7use crate::db::{
8 access::AccessPlan, consistency::ReadConsistency, intent::QueryMode, predicate::Predicate,
9};
10use std::ops::{Deref, DerefMut};
11
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18pub enum OrderDirection {
19 Asc,
20 Desc,
21}
22
23#[derive(Clone, Debug, Eq, PartialEq)]
29pub(crate) struct OrderSpec {
30 pub(crate) fields: Vec<(String, OrderDirection)>,
31}
32
33#[derive(Clone, Copy, Debug, Eq, PartialEq)]
39pub(crate) struct DeleteLimitSpec {
40 pub max_rows: u32,
41}
42
43#[derive(Clone, Debug, Eq, PartialEq)]
49pub(crate) struct PageSpec {
50 pub limit: Option<u32>,
51 pub offset: u32,
52}
53
54#[derive(Clone, Debug, Eq, PartialEq)]
75pub(crate) struct LogicalPlan {
76 pub(crate) mode: QueryMode,
78
79 pub(crate) predicate: Option<Predicate>,
81
82 pub(crate) order: Option<OrderSpec>,
84
85 pub(crate) distinct: bool,
87
88 pub(crate) delete_limit: Option<DeleteLimitSpec>,
90
91 pub(crate) page: Option<PageSpec>,
93
94 pub(crate) consistency: ReadConsistency,
96}
97
98#[derive(Clone, Debug, Eq, PartialEq)]
106pub(crate) struct AccessPlannedQuery<K> {
107 pub(crate) logical: LogicalPlan,
108 pub(crate) access: AccessPlan<K>,
109}
110
111impl<K> AccessPlannedQuery<K> {
112 #[must_use]
114 pub(crate) const fn from_parts(logical: LogicalPlan, access: AccessPlan<K>) -> Self {
115 Self { logical, access }
116 }
117
118 #[must_use]
120 pub(crate) fn into_parts(self) -> (LogicalPlan, AccessPlan<K>) {
121 (self.logical, self.access)
122 }
123
124 #[cfg(test)]
128 pub(crate) fn new(access: AccessPath<K>, consistency: ReadConsistency) -> Self {
129 Self {
130 logical: LogicalPlan {
131 mode: QueryMode::Load(LoadSpec::new()),
132 predicate: None,
133 order: None,
134 distinct: false,
135 delete_limit: None,
136 page: None,
137 consistency,
138 },
139 access: AccessPlan::path(access),
140 }
141 }
142}
143
144impl<K> Deref for AccessPlannedQuery<K> {
145 type Target = LogicalPlan;
146
147 fn deref(&self) -> &Self::Target {
148 &self.logical
149 }
150}
151
152impl<K> DerefMut for AccessPlannedQuery<K> {
153 fn deref_mut(&mut self) -> &mut Self::Target {
154 &mut self.logical
155 }
156}