Skip to content

Commit

Permalink
[fix](Nereids): add whole tree rewriter when root is not CTEAnchor (#…
Browse files Browse the repository at this point in the history
…33591) (#35269)

pick from master ##33591
  • Loading branch information
keanji-x authored May 24, 2024
1 parent f463643 commit 4cb9350
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,13 @@ private Optional<Pair<Cost, GroupExpression>> getCost(CascadesContext currentCtx
// set subtree rewrite cache
currentCtx.getStatementContext().getRewrittenCteProducer()
.put(currentCtx.getCurrentTree().orElse(null), (LogicalPlan) cboCtx.getRewritePlan());
// Do Whole tree rewrite
CascadesContext rootCtxCopy = CascadesContext.newCurrentTreeContext(rootCtx);
Rewriter.getWholeTreeRewriterWithoutCostBasedJobs(rootCtxCopy).execute();
// Do optimize
new Optimizer(rootCtxCopy).execute();
return rootCtxCopy.getMemo().getRoot().getLowestCostPlan(
rootCtxCopy.getCurrentJobContext().getRequiredProperties());
} else {
new Optimizer(cboCtx).execute();
return cboCtx.getMemo().getRoot().getLowestCostPlan(
cboCtx.getCurrentJobContext().getRequiredProperties());
}
// Do post tree rewrite
CascadesContext rootCtxCopy = CascadesContext.newCurrentTreeContext(rootCtx);
Rewriter.getWholeTreeRewriterWithoutCostBasedJobs(rootCtxCopy).execute();
// Do optimize
new Optimizer(rootCtxCopy).execute();
return rootCtxCopy.getMemo().getRoot().getLowestCostPlan(
rootCtxCopy.getCurrentJobContext().getRequiredProperties());
}
}

0 comments on commit 4cb9350

Please sign in to comment.