Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
zclllyybb committed May 29, 2024
1 parent d6279fa commit fb50a70
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {

/** evaluate by visitor */
public static Expression evaluate(Expression expr, ExpressionRewriteContext ctx) {
if (ctx.cascadesContext != null
&& ctx.cascadesContext.getConnectContext() != null
&& ctx.cascadesContext.getConnectContext().getSessionVariable().isEnableFoldConstantByBe()) {
return FULL_FOLD_REWRITER.rewrite(expr, ctx);
} else {
if (ctx.cascadesContext != null && ctx.cascadesContext.getConnectContext() != null) {
if (ctx.cascadesContext.getConnectContext().getSessionVariable().isDebugSkipFoldConstant()) {
return expr;
}
if (ctx.cascadesContext.getConnectContext().getSessionVariable().isEnableFoldConstantByBe()) {
return FULL_FOLD_REWRITER.rewrite(expr, ctx);
}
return FoldConstantRuleOnFE.VISITOR_INSTANCE.rewrite(expr, ctx);
}
return FoldConstantRuleOnFE.VISITOR_INSTANCE.rewrite(expr, ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public List<ExpressionPatternMatcher<? extends Expression>> buildRules() {
public static boolean isEnableFoldByBe(ExpressionMatchingContext<Expression> ctx) {
return ctx.cascadesContext != null
&& ctx.cascadesContext.getConnectContext() != null
&& ctx.cascadesContext.getConnectContext().getSessionVariable().isEnableFoldConstantByBe();
&& ctx.cascadesContext.getConnectContext().getSessionVariable().isEnableFoldConstantByBe()
&& !ctx.cascadesContext.getConnectContext().getSessionVariable().isDebugSkipFoldConstant();
}

/** foldByBE */
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 @@ -135,6 +135,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 @@ -999,6 +1000,8 @@ public class SessionVariable implements Serializable, Writable {

@VariableMgr.VarAttr(name = ENABLE_FOLD_CONSTANT_BY_BE, fuzzy = true)
public boolean enableFoldConstantByBe = true;
@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 @@ -2491,6 +2494,10 @@ public boolean isEnableFoldConstantByBe() {
return enableFoldConstantByBe;
}

public boolean isDebugSkipFoldConstant() {
return debugSkipFoldConstant;
}

public boolean isEnableRewriteElementAtToSlot() {
return enableRewriteElementAtToSlot;
}
Expand All @@ -2507,6 +2514,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 @@ -1424,7 +1424,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 fb50a70

Please sign in to comment.