diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/Optimizer.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/Optimizer.java index 773b4e96eb0ef8..99398694834e2a 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/Optimizer.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/Optimizer.java @@ -165,18 +165,14 @@ public OptExpression optimize(ConnectContext connectContext, // prepare for optimizer prepare(connectContext, columnRefFactory, logicOperatorTree); + // prepare for mv rewrite + prepareMvRewrite(connectContext, logicOperatorTree, columnRefFactory, requiredColumns); // try text based mv rewrite first before mv rewrite prepare so can deduce mv prepare time if it can be rewritten. try (Timer ignored = Tracers.watchScope("MVTextRewrite")) { logicOperatorTree = new TextMatchBasedRewriteRule(connectContext, stmt, optToAstMap) .transform(logicOperatorTree, context).get(0); } - // prepare for mv rewrite - prepareMvRewrite(connectContext, logicOperatorTree, columnRefFactory, requiredColumns); - - logicOperatorTree = new TextMatchBasedRewriteRule(connectContext, stmt, optToAstMap) - .transform(logicOperatorTree, context).get(0); - OptExpression result = optimizerConfig.isRuleBased() ? optimizeByRule(logicOperatorTree, requiredProperty, requiredColumns) : optimizeByCost(connectContext, logicOperatorTree, requiredProperty, requiredColumns);