This repository was archived by the owner on Jul 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterface.rs
More file actions
141 lines (127 loc) · 5.84 KB
/
Copy pathinterface.rs
File metadata and controls
141 lines (127 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use crate::StorageResult;
/// A trait representing an implementation of a memoization table.
///
/// Note that we use [`trait_variant`] here in order to add bounds on every method.
/// See this [blog post](
/// https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits)
/// for more information.
///
/// TODO Figure out for each when to get the ID of a record or the entire record itself.
#[trait_variant::make(Send)]
pub trait MemoStorage {
/// A type representing a group in the Cascades framework.
type Group;
/// A type representing a unique identifier for a group.
type GroupId;
/// A type representing a logical expression.
type LogicalExpression;
/// A type representing a unique identifier for a logical expression.
type LogicalExpressionId;
/// A type representing a physical expression.
type PhysicalExpression;
/// A type representing a unique identifier for a physical expression.
type PhysicalExpressionId;
/// Retrieves a [`Self::Group`] given a [`Self::GroupId`].
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn get_group(&self, group_id: Self::GroupId) -> StorageResult<Self::Group>;
/// Retrieves all group IDs that are stored in the memo table.
async fn get_all_groups(&self) -> StorageResult<Vec<Self::Group>>;
/// Retrieves a [`Self::LogicalExpression`] given a [`Self::LogicalExpressionId`].
///
/// If the logical expression does not exist, returns a [`MemoError::UnknownLogicalExpression`]
/// error.
async fn get_logical_expression(
&self,
logical_expression_id: Self::LogicalExpressionId,
) -> StorageResult<Self::LogicalExpression>;
/// Retrieves a [`Self::PhysicalExpression`] given a [`Self::PhysicalExpressionId`].
///
/// If the physical expression does not exist, returns a
/// [`MemoError::UnknownPhysicalExpression`] error.
async fn get_physical_expression(
&self,
physical_expression_id: Self::PhysicalExpressionId,
) -> StorageResult<Self::PhysicalExpression>;
/// Retrieves the parent group ID of a logical expression given its expression ID.
///
/// If the logical expression does not exist, returns a [`MemoError::UnknownLogicalExpression`]
/// error.
async fn get_group_from_logical_expression(
&self,
logical_expression_id: Self::LogicalExpressionId,
) -> StorageResult<Self::GroupId>;
/// Retrieves the parent group ID of a logical expression given its expression ID.
///
/// If the physical expression does not exist, returns a
/// [`MemoError::UnknownPhysicalExpression`] error.
async fn get_group_from_physical_expression(
&self,
physical_expression_id: Self::PhysicalExpressionId,
) -> StorageResult<Self::GroupId>;
/// Retrieves all of the logical expression "children" of a group.
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn get_group_logical_expressions(
&self,
group_id: Self::GroupId,
) -> StorageResult<Vec<Self::LogicalExpression>>;
/// Retrieves all of the physical expression "children" of a group.
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn get_group_physical_expressions(
&self,
group_id: Self::GroupId,
) -> StorageResult<Vec<Self::PhysicalExpression>>;
/// Retrieves the best physical query plan (winner) for a given group.
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn get_winner(
&self,
group_id: Self::GroupId,
) -> StorageResult<Option<Self::PhysicalExpressionId>>;
/// Updates / replaces a group's best physical plan (winner). Optionally returns the previous
/// winner's physical expression ID.
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn update_group_winner(
&self,
group_id: Self::GroupId,
physical_expression_id: Self::PhysicalExpressionId,
) -> StorageResult<Option<Self::PhysicalExpressionId>>;
/// Adds a logical expression to an existing group via its [`Self::GroupId`].
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn add_logical_expression_to_group(
&self,
group_id: Self::GroupId,
logical_expression: Self::LogicalExpression,
children: Vec<Self::LogicalExpressionId>,
) -> StorageResult<()>;
/// Adds a physical expression to an existing group via its [`Self::GroupId`].
///
/// If the group does not exist, returns a [`MemoError::UnknownGroup`] error.
async fn add_physical_expression_to_group(
&self,
group_id: Self::GroupId,
physical_expression: Self::PhysicalExpression,
children: Vec<Self::LogicalExpressionId>,
) -> StorageResult<()>;
/// Adds a new logical expression into the memo table, creating a new group if the expression
/// does not already exist.
///
/// The [`Self::LogicalExpression`] type should have some sort of mechanism for checking if
/// the expression has been seen before, and if it has already been created, then the parent
/// group ID should also be retrievable.
///
/// If the expression already exists, then this function will return the [`Self::GroupId`] of
/// the parent group and the corresponding (already existing) [`Self::LogicalExpressionId`].
///
/// If the expression does not exist, this function will create a new group and a new
/// expression, returning brand new IDs for both.
async fn add_logical_expression(
&self,
expression: Self::LogicalExpression,
children: Vec<Self::LogicalExpressionId>,
) -> StorageResult<(Self::GroupId, Self::LogicalExpressionId)>;
}