Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit c251e6e

Browse files
committed
feat(core): dump predicates when dumping the memo table (#223)
Signed-off-by: Alex Chi <[email protected]>
1 parent c7f4610 commit c251e6e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

optd-core/src/cascades/optimizer.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
collections::{HashMap, HashSet, VecDeque},
2+
collections::{BTreeSet, HashMap, HashSet, VecDeque},
33
fmt::Display,
44
sync::Arc,
55
};
@@ -37,6 +37,8 @@ pub struct OptimizerProperties {
3737
pub partial_explore_iter: Option<usize>,
3838
/// Plan space can be expanded by this number of times before we stop applying logical rules.
3939
pub partial_explore_space: Option<usize>,
40+
/// Disable pruning during optimization.
41+
pub disable_pruning: bool,
4042
}
4143

4244
pub struct CascadesOptimizer<T: NodeType, M: Memo<T> = NaiveMemo<T>> {
@@ -142,6 +144,10 @@ impl<T: NodeType, M: Memo<T>> CascadesOptimizer<T, M> {
142144
self.prop.panic_on_budget = enabled;
143145
}
144146

147+
pub fn disable_pruning(&mut self, enabled: bool) {
148+
self.prop.disable_pruning = enabled;
149+
}
150+
145151
pub fn cost(&self) -> Arc<dyn CostModel<T, M>> {
146152
self.cost.clone()
147153
}
@@ -191,10 +197,17 @@ impl<T: NodeType, M: Memo<T>> CascadesOptimizer<T, M> {
191197
if let Some(predicate_binding) = self.memo.try_get_predicate_binding(group_id) {
192198
println!(" predicate={}", predicate_binding);
193199
}
200+
let mut all_predicates = BTreeSet::new();
194201
for expr_id in self.memo.get_all_exprs_in_group(group_id) {
195202
let memo_node = self.memo.get_expr_memoed(expr_id);
203+
for pred in &memo_node.predicates {
204+
all_predicates.insert(*pred);
205+
}
196206
println!(" expr_id={} | {}", expr_id, memo_node);
197207
}
208+
for pred in all_predicates {
209+
println!(" {}={}", pred, self.memo.get_pred(pred));
210+
}
198211
}
199212
}
200213

optd-core/src/nodes.rs

+12
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ pub struct PredNode<T: NodeType> {
334334
pub data: Option<Value>,
335335
}
336336

337+
impl<T: NodeType> std::fmt::Display for PredNode<T> {
338+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
339+
write!(f, "({}", self.typ)?;
340+
for child in &self.children {
341+
write!(f, " {}", child)?;
342+
}
343+
if let Some(data) = &self.data {
344+
write!(f, " {}", data)?;
345+
}
346+
write!(f, ")")
347+
}
348+
}
337349
impl<T: NodeType> PredNode<T> {
338350
pub fn child(&self, idx: usize) -> ArcPredNode<T> {
339351
self.children[idx].clone()

0 commit comments

Comments
 (0)