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

Commit a516e0d

Browse files
committed
feat(plannertest): add disable pruning and dump memo flags (#223)
Signed-off-by: Alex Chi <[email protected]>
1 parent c251e6e commit a516e0d

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

optd-core/src/cascades/tasks/apply_rule.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ impl<T: NodeType, M: Memo<T>> Task<T, M> for ApplyRuleTask {
190190
as Box<dyn Task<T, M>>,
191191
);
192192
} else {
193-
tasks
194-
.push(Box::new(OptimizeInputsTask::new(expr_id, true))
195-
as Box<dyn Task<T, M>>);
193+
tasks.push(Box::new(OptimizeInputsTask::new(
194+
expr_id,
195+
!optimizer.prop.disable_pruning,
196+
)) as Box<dyn Task<T, M>>);
196197
}
197198
optimizer.unmark_expr_explored(expr_id);
198199
trace!(event = "apply_rule", expr_id = %self.expr_id, rule_id = %self.rule_id, new_expr_id = %expr_id);

optd-core/src/cascades/tasks/optimize_group.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ impl<T: NodeType, M: Memo<T>> Task<T, M> for OptimizeGroupTask {
4242
for &expr in &exprs {
4343
let typ = optimizer.get_expr_memoed(expr).typ.clone();
4444
if !typ.is_logical() {
45-
tasks.push(Box::new(OptimizeInputsTask::new(expr, true)) as Box<dyn Task<T, M>>);
45+
tasks.push(Box::new(OptimizeInputsTask::new(
46+
expr,
47+
!optimizer.prop.disable_pruning,
48+
)) as Box<dyn Task<T, M>>);
4649
}
4750
}
4851
trace!(event = "task_finish", task = "optimize_group", group_id = %self.group_id, exprs_cnt = exprs_cnt);

optd-sqlplannertest/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ impl DatafusionDBMS {
121121
} else {
122122
optimizer.panic_on_explore_limit(false);
123123
}
124+
if flags.disable_pruning {
125+
optimizer.disable_pruning(true);
126+
} else {
127+
optimizer.disable_pruning(false);
128+
}
124129
let rules = optimizer.rules();
125130
if flags.enable_logical_rules.is_empty() {
126131
for r in 0..rules.len() {
@@ -190,6 +195,17 @@ impl DatafusionDBMS {
190195
}
191196
}
192197
}
198+
if flags.dump_memo_table {
199+
let mut guard = self
200+
.optd_optimizer
201+
.as_ref()
202+
.unwrap()
203+
.optimizer
204+
.lock()
205+
.unwrap();
206+
let optimizer = guard.as_mut().unwrap().optd_optimizer_mut();
207+
optimizer.dump();
208+
}
193209
Ok(result)
194210
}
195211

@@ -326,6 +342,8 @@ struct TestFlags {
326342
enable_df_logical: bool,
327343
enable_logical_rules: Vec<String>,
328344
panic_on_budget: bool,
345+
dump_memo_table: bool,
346+
disable_pruning: bool,
329347
}
330348

331349
/// Extract the flags from a task. The flags are specified in square brackets.
@@ -353,6 +371,10 @@ fn extract_flags(task: &str) -> Result<TestFlags> {
353371
}
354372
} else if flag == "panic_on_budget" {
355373
options.panic_on_budget = true;
374+
} else if flag == "dump_memo_table" {
375+
options.dump_memo_table = true;
376+
} else if flag == "disable_pruning" {
377+
options.disable_pruning = true;
356378
} else {
357379
bail!("Unknown flag: {}", flag);
358380
}

0 commit comments

Comments
 (0)