From fb50a707372fba66295117c79f422636ab7f4d83 Mon Sep 17 00:00:00 2001 From: zhaochangle Date: Wed, 29 May 2024 14:11:41 +0800 Subject: [PATCH] 1 --- .../rules/expression/rules/FoldConstantRule.java | 13 ++++++++----- .../expression/rules/FoldConstantRuleOnBE.java | 3 ++- .../java/org/apache/doris/qe/SessionVariable.java | 11 +++++++++++ .../main/java/org/apache/doris/qe/StmtExecutor.java | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRule.java index 04acb91d9e2d397..b4b253e836571fe 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRule.java @@ -51,12 +51,15 @@ public List> 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); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java index d9e2187596b89b9..fa9e424ff6553b0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java @@ -127,7 +127,8 @@ public List> buildRules() { public static boolean isEnableFoldByBe(ExpressionMatchingContext 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 */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 44cb076d3ed2427..ba7087f2a6af4b5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -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"; @@ -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; @@ -2491,6 +2494,10 @@ public boolean isEnableFoldConstantByBe() { return enableFoldConstantByBe; } + public boolean isDebugSkipFoldConstant() { + return debugSkipFoldConstant; + } + public boolean isEnableRewriteElementAtToSlot() { return enableRewriteElementAtToSlot; } @@ -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) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 235d3ac2426fc34..90bde60d06c79e9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -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); }