Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Feb 23, 2024
1 parent fccbae2 commit f6c4dbd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
11 changes: 9 additions & 2 deletions optd-core/src/cascades/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,28 @@ impl<T: RelNodeTyp> Memo<T> {
bail!("no best group binding for group {}", group_id)
}

pub fn get_best_group_binding(&self, group_id: GroupId) -> Result<RelNodeRef<T>> {
pub fn get_best_group_binding(&self, group_id: GroupId, meta: &mut Option<RelNodeMetaMap>) -> Result<RelNodeRef<T>> {
let info = self.get_group_info(group_id);
if let Some(winner) = info.winner {
if !winner.impossible {
let expr_id = winner.expr_id;
let expr = self.get_expr_memoed(expr_id);
let mut children = Vec::with_capacity(expr.children.len());
for child in &expr.children {
children.push(self.get_best_group_binding(*child)?);
children.push(self.get_best_group_binding(*child, meta)?);
}
let node = Arc::new(RelNode {
typ: expr.typ.clone(),
children,
data: expr.data.clone(),
});

if let Some(meta) = meta {
meta.insert(
node.as_ref() as *const _ as usize,
RelNodeMeta::new(group_id),
);
}
return Ok(node);
}
}
Expand Down
21 changes: 4 additions & 17 deletions optd-core/src/cascades/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,9 @@ impl<T: RelNodeTyp> CascadesOptimizer<T> {
Ok(group_id)
}

pub fn step_get_optimize_rel_with_meta(
&self,
group_id: GroupId,
meta: &mut RelNodeMetaMap,
) -> Result<RelNodeRef<T>> {
let rel = self.memo.get_best_group_binding_with_meta(group_id, meta)?;
meta.insert(
rel.as_ref() as *const _ as usize,
RelNodeMeta::new(group_id),
);
Ok(rel)
}

/// Get the group binding.
pub fn step_get_optimize_rel(&self, group_id: GroupId) -> Result<RelNodeRef<T>> {
self.memo.get_best_group_binding(group_id)
/// Gets the group binding.
pub fn step_get_optimize_rel(&self, group_id: GroupId, meta: &mut Option<RelNodeMetaMap>) -> Result<RelNodeRef<T>> {
self.memo.get_best_group_binding(group_id, meta)
}

fn fire_optimize_tasks(&mut self, group_id: GroupId) -> Result<()> {
Expand Down Expand Up @@ -265,7 +252,7 @@ impl<T: RelNodeTyp> CascadesOptimizer<T> {
fn optimize_inner(&mut self, root_rel: RelNodeRef<T>) -> Result<RelNodeRef<T>> {
let (group_id, _) = self.add_group_expr(root_rel, None);
self.fire_optimize_tasks(group_id)?;
self.memo.get_best_group_binding(group_id)
self.memo.get_best_group_binding(group_id, &mut None)
}

pub fn resolve_group_id(&self, root_rel: RelNodeRef<T>) -> GroupId {
Expand Down
19 changes: 3 additions & 16 deletions optd-datafusion-repr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,12 @@ impl DatafusionOptimizer {

let group_id = self.optimizer.step_optimize_rel(root_rel)?;

// let optimized_rel =
// self.optimizer
// .step_get_optimize_rel(group_id, |rel_node, group_id| {
// if rel_node.typ.is_plan_node() && self.enable_adaptive {
// return PhysicalCollector::new(
// PlanNode::from_rel_node(rel_node).unwrap(),
// group_id,
// )
// .into_rel_node();
// }
// rel_node
// })?;

let mut meta = HashMap::new();
let mut meta = Some(HashMap::new());
let optimized_rel = self
.optimizer
.step_get_optimize_rel_with_meta(group_id, &mut meta)?;
.step_get_optimize_rel(group_id, &mut meta)?;

Ok((group_id, optimized_rel, meta))
Ok((group_id, optimized_rel, meta.unwrap()))
}

pub fn dump(&self, group_id: Option<GroupId>) {
Expand Down

0 comments on commit f6c4dbd

Please sign in to comment.