[bug](fold) fix fold constant core dump with variant type (#32265)

1. variant type core dump at call get_data_at function, as not impl this function.
2. some case can't pass at old planner and fold_constant_by_be = on.
3. open enable_fold_constant_by_be = true.
This commit is contained in:
zhangstar333
2024-03-22 14:17:05 +08:00
committed by yiguolei
parent 8a6fc79797
commit e41311d77d
19 changed files with 64 additions and 11 deletions

View File

@ -32,7 +32,9 @@ import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.Cast;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Sleep;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.NumericLiteral;
import org.apache.doris.nereids.types.CharType;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DateTimeV2Type;
@ -127,11 +129,21 @@ public class FoldConstantRuleOnBE extends AbstractExpressionRewriteRule {
if (((Cast) expr).child().isNullLiteral()) {
return;
}
if (skipSleepFunction(((Cast) expr).child())) {
return;
}
}
// skip literal expr
if (expr.isLiteral()) {
return;
}
// eg: avg_state(1) return is agg function serialize data
if (expr.getDataType().isAggStateType()) {
return;
}
if (skipSleepFunction(expr)) {
return;
}
String id = idGenerator.getNextId().toString();
constMap.put(id, expr);
Expr staleExpr;
@ -150,6 +162,20 @@ public class FoldConstantRuleOnBE extends AbstractExpressionRewriteRule {
}
}
// if sleep(5) will cause rpc timeout
private boolean skipSleepFunction(Expression expr) {
if (expr instanceof Sleep) {
Expression param = expr.child(0);
if (param instanceof Cast) {
param = param.child(0);
}
if (param instanceof NumericLiteral) {
return ((NumericLiteral) param).getDouble() >= 5.0;
}
}
return false;
}
private Map<String, Expression> evalOnBE(Map<String, Map<String, TExpr>> paramMap,
Map<String, Expression> constMap, ConnectContext context) {
@ -183,8 +209,8 @@ public class FoldConstantRuleOnBE extends AbstractExpressionRewriteRule {
// TODO: will be delete the debug log after find problem of timeout.
LOG.info("fold query {} ", DebugUtil.printId(context.queryId()));
Future<PConstantExprResult> future =
BackendServiceProxy.getInstance().foldConstantExpr(brpcAddress, tParams);
Future<PConstantExprResult> future = BackendServiceProxy.getInstance().foldConstantExpr(brpcAddress,
tParams);
PConstantExprResult result = future.get(5, TimeUnit.SECONDS);
if (result.getStatus().getStatusCode() == 0) {

View File

@ -934,7 +934,7 @@ public class SessionVariable implements Serializable, Writable {
private boolean enableJoinReorderBasedCost = false;
@VariableMgr.VarAttr(name = ENABLE_FOLD_CONSTANT_BY_BE, fuzzy = true)
private boolean enableFoldConstantByBe = false;
public boolean enableFoldConstantByBe = true;
@VariableMgr.VarAttr(name = ENABLE_REWRITE_ELEMENT_AT_TO_SLOT, fuzzy = true)
private boolean enableRewriteElementAtToSlot = true;
@ -1785,7 +1785,12 @@ public class SessionVariable implements Serializable, Writable {
default:
break;
}
randomInt = random.nextInt(2);
if (randomInt % 2 == 0) {
this.enableFoldConstantByBe = false;
} else {
this.enableFoldConstantByBe = true;
}
this.runtimeFilterType = 1 << randomInt;
this.enableParallelScan = Config.pull_request_id % 2 == 0 ? randomInt % 2 == 0 : randomInt % 1 == 0;
switch (randomInt) {