hello-stephen commented on code in PR #71241:
URL: https://github.com/apache/doris/pull/71241#discussion_r4757066499


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java:
##########
@@ -390,6 +394,26 @@ 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;
+        }
+        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, qualifiedMvName)

Review Comment:
   [P2] Preserve cache tracking when folding signature-valued group keys
   
   With SQL cache enabled and a populated, unchanged cache-eligible `unrelated` 
table, run:
   
   ```sql
   SELECT ivm_plan_signature('mv') AS sig, count(*)
   FROM unrelated GROUP BY sig;
   ```
   
   The reduced input shape is:
   
   ```text
   Aggregate(group by sig; sig, count(*))
     Project(ivm_plan_signature('mv') AS sig)
       Scan(unrelated)
   ```
   
   `NormalizeAggregate.eliminateGroupByConstant` evaluates the call here, 
removes its bottom projection and substitutes a signature literal in the upper 
output **before** `FoldConstantForSqlCache` runs. No function remains to record 
a nondeterministic-expression pair, and the evaluator's separate 
`StatementContext` does not add `mv` to the caller's dependencies. Once this 
query is cached, `DROP MATERIALIZED VIEW mv` only invalidates the MV's 
dependencies; repeating the query can therefore return the old signature 
instead of the missing-MV error. Please disable caching for the caller during 
evaluation, or preserve the function/dependencies through analysis-time 
folding, and add a cache regression for this path.



-- 
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]

Reply via email to