Skip to content

Commit

Permalink
[branch-2.1](session-variable) Add a debug variable of constant fold (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
zclllyybb authored Sep 23, 2024
1 parent 7d64c8c commit d44ee1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ public <E extends Expression> Predicate<ExpressionMatchingContext<E>> as() {
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));
}
Expand Down
11 changes: 11 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2622,6 +2625,10 @@ public boolean isEnableFoldConstantByBe() {
return enableFoldConstantByBe;
}

public boolean isDebugSkipFoldConstant() {
return debugSkipFoldConstant;
}

public boolean isEnableRewriteElementAtToSlot() {
return enableRewriteElementAtToSlot;
}
Expand All @@ -2638,6 +2645,10 @@ public void setEnableFoldConstantByBe(boolean foldConstantByBe) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,8 @@ private void analyzeAndGenerateQueryPlan(TQueryOptions tQueryOptions) throws Use
}
ExprRewriter rewriter = analyzer.getExprRewriter();
rewriter.reset();
if (context.getSessionVariable().isEnableFoldConstantByBe()) {
if (context.getSessionVariable().isEnableFoldConstantByBe()
&& !context.getSessionVariable().isDebugSkipFoldConstant()) {
// fold constant expr
parsedStmt.foldConstant(rewriter, tQueryOptions);
}
Expand Down

0 comments on commit d44ee1c

Please sign in to comment.