Skip to content

Commit 42b5133

Browse files
authored
chore(planner): fix distributed query plan (#14951)
chore: fix distributed query plan
1 parent 96c39f7 commit 42b5133

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/query/sql/src/planner/optimizer/optimizer.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,14 @@ pub fn optimize_query(opt_ctx: OptimizerContext, mut s_expr: SExpr) -> Result<SE
283283
enable_distributed_query,
284284
)?;
285285

286+
if opt_ctx.enable_join_reorder {
287+
s_expr =
288+
RecursiveOptimizer::new([RuleID::CommuteJoin].as_slice(), &opt_ctx).run(&s_expr)?;
289+
}
290+
286291
// Cascades optimizer may fail due to timeout, fallback to heuristic optimizer in this case.
287292
s_expr = match cascades.optimize(s_expr.clone()) {
288293
Ok(mut s_expr) => {
289-
let rules = if opt_ctx.enable_join_reorder {
290-
[RuleID::EliminateEvalScalar, RuleID::CommuteJoin].as_slice()
291-
} else {
292-
[RuleID::EliminateEvalScalar].as_slice()
293-
};
294-
295-
s_expr = RecursiveOptimizer::new(rules, &opt_ctx).run(&s_expr)?;
296-
297294
// Push down sort and limit
298295
// TODO(leiysky): do this optimization in cascades optimizer
299296
if enable_distributed_query {
@@ -308,10 +305,6 @@ pub fn optimize_query(opt_ctx: OptimizerContext, mut s_expr: SExpr) -> Result<SE
308305
"CascadesOptimizer failed, fallback to heuristic optimizer: {}",
309306
e
310307
);
311-
312-
s_expr =
313-
RecursiveOptimizer::new(&[RuleID::EliminateEvalScalar], &opt_ctx).run(&s_expr)?;
314-
315308
if enable_distributed_query {
316309
s_expr = optimize_distributed_query(opt_ctx.table_ctx.clone(), &s_expr)?;
317310
}
@@ -320,6 +313,9 @@ pub fn optimize_query(opt_ctx: OptimizerContext, mut s_expr: SExpr) -> Result<SE
320313
}
321314
};
322315

316+
s_expr =
317+
RecursiveOptimizer::new([RuleID::EliminateEvalScalar].as_slice(), &opt_ctx).run(&s_expr)?;
318+
323319
Ok(s_expr)
324320
}
325321

0 commit comments

Comments
 (0)