pick https://github.com/apache/doris/pull/35584
This commit is contained in:
@ -120,6 +120,8 @@ public class FoldConstantRuleOnBE implements ExpressionPatternRuleFactory {
|
||||
public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {
|
||||
return ImmutableList.of(
|
||||
root(Expression.class)
|
||||
.whenCtx(ctx -> !ctx.cascadesContext.getConnectContext().getSessionVariable()
|
||||
.isDebugSkipFoldConstant())
|
||||
.whenCtx(FoldConstantRuleOnBE::isEnableFoldByBe)
|
||||
.thenApply(FoldConstantRuleOnBE::foldByBE)
|
||||
);
|
||||
|
||||
@ -709,6 +709,8 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule
|
||||
private <E extends Expression> ExpressionPatternMatcher<? extends Expression> matches(
|
||||
Class<E> clazz, BiFunction<E, ExpressionRewriteContext, Expression> visitMethod) {
|
||||
return matchesType(clazz)
|
||||
.whenCtx(ctx -> !ctx.cascadesContext.getConnectContext().getSessionVariable()
|
||||
.isDebugSkipFoldConstant())
|
||||
.whenCtx(NOT_UNDER_AGG_DISTINCT.as())
|
||||
.thenApply(ctx -> visitMethod.apply(ctx.expr, ctx.rewriteContext));
|
||||
}
|
||||
|
||||
@ -142,6 +142,7 @@ public class SessionVariable implements Serializable, Writable {
|
||||
public static final String PREFER_JOIN_METHOD = "prefer_join_method";
|
||||
|
||||
public static final String ENABLE_FOLD_CONSTANT_BY_BE = "enable_fold_constant_by_be";
|
||||
public static final String DEBUG_SKIP_FOLD_CONSTANT = "debug_skip_fold_constant";
|
||||
|
||||
public static final String ENABLE_REWRITE_ELEMENT_AT_TO_SLOT = "enable_rewrite_element_at_to_slot";
|
||||
public static final String ENABLE_ODBC_TRANSCATION = "enable_odbc_transcation";
|
||||
@ -1054,6 +1055,8 @@ public class SessionVariable implements Serializable, Writable {
|
||||
|
||||
@VariableMgr.VarAttr(name = ENABLE_FOLD_CONSTANT_BY_BE, fuzzy = true)
|
||||
public boolean enableFoldConstantByBe = false;
|
||||
@VariableMgr.VarAttr(name = DEBUG_SKIP_FOLD_CONSTANT)
|
||||
public boolean debugSkipFoldConstant = false;
|
||||
|
||||
@VariableMgr.VarAttr(name = ENABLE_REWRITE_ELEMENT_AT_TO_SLOT, fuzzy = true)
|
||||
private boolean enableRewriteElementAtToSlot = true;
|
||||
@ -2622,6 +2625,10 @@ public class SessionVariable implements Serializable, Writable {
|
||||
return enableFoldConstantByBe;
|
||||
}
|
||||
|
||||
public boolean isDebugSkipFoldConstant() {
|
||||
return debugSkipFoldConstant;
|
||||
}
|
||||
|
||||
public boolean isEnableRewriteElementAtToSlot() {
|
||||
return enableRewriteElementAtToSlot;
|
||||
}
|
||||
@ -2638,6 +2645,10 @@ public class SessionVariable implements Serializable, Writable {
|
||||
this.enableFoldConstantByBe = foldConstantByBe;
|
||||
}
|
||||
|
||||
public void setDebugSkipFoldConstant(boolean debugSkipFoldConstant) {
|
||||
this.debugSkipFoldConstant = debugSkipFoldConstant;
|
||||
}
|
||||
|
||||
public int getParallelExecInstanceNum() {
|
||||
ConnectContext connectContext = ConnectContext.get();
|
||||
if (connectContext != null && connectContext.getEnv() != null && connectContext.getEnv().getAuth() != null) {
|
||||
|
||||
@ -1365,7 +1365,8 @@ public class StmtExecutor {
|
||||
}
|
||||
ExprRewriter rewriter = analyzer.getExprRewriter();
|
||||
rewriter.reset();
|
||||
if (context.getSessionVariable().isEnableFoldConstantByBe()) {
|
||||
if (context.getSessionVariable().isEnableFoldConstantByBe()
|
||||
&& !context.getSessionVariable().isDebugSkipFoldConstant()) {
|
||||
// fold constant expr
|
||||
parsedStmt.foldConstant(rewriter, tQueryOptions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user