hello-stephen commented on code in PR #71241:
URL: https://github.com/apache/doris/pull/71241#discussion_r4779283610
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java:
##########
@@ -390,6 +395,30 @@ public Expression visitDatabase(Database database,
ExpressionRewriteContext cont
return new VarcharLiteral(res);
}
+ @Override
+ public Expression visitIvmPlanSignatureFunc(IvmPlanSignatureFunc func,
ExpressionRewriteContext context) {
+ IvmPlanSignatureFunc rewritten = rewriteChildren(func, context);
+ if (!foldContextDependentExpressions) {
+ return rewritten;
+ }
+ StatementContext callerStmtCtx =
context.cascadesContext.getStatementContext();
+ if (callerStmtCtx != null) {
+ callerStmtCtx.getSqlCacheContext().ifPresent(cache ->
cache.setCannotProcessExpression(true));
+ }
+ Expression arg = rewritten.child();
+ if (arg instanceof NullLiteral) {
+ return new NullLiteral(StringType.INSTANCE);
+ }
+ if (!(arg instanceof StringLikeLiteral)) {
+ throw new AnalysisException("ivm_plan_signature requires a
constant string argument");
+ }
+ String qualifiedMvName = ((StringLikeLiteral) arg).getStringValue();
+ ConnectContext ctx = context.cascadesContext.getConnectContext();
+ return IvmPlanSignatureEvaluator.evaluate(ctx, callerStmtCtx,
qualifiedMvName)
Review Comment:
[P2] Defer signature evaluation until prepared parameters are bound
Preparing `SELECT COUNT(*) GROUP BY ivm_plan_signature(?)` through
`COM_STMT_PREPARE` reaches this lookup before the client supplies the MV name.
The reduced input is:
```text
Aggregate(group by ivm_plan_signature(?); count(*))
OneRow
```
`ExpressionAnalyzer.visitPlaceholder` substitutes dummy string `"0"` to
infer result metadata, and `NormalizeAggregate.eliminateGroupByConstant` calls
this folding visitor during the prepare analysis. It consequently looks up MV
`0` and throws when that MV does not exist, so the statement cannot be prepared
even though binding an existing MV name would be valid. Please defer this
metadata-dependent evaluation during the prepare stage and cover a
parameterized GROUP BY call.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]