seawinde commented on code in PR #66370:
URL: https://github.com/apache/doris/pull/66370#discussion_r3710086809


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExecuteCommand.java:
##########
@@ -91,6 +91,10 @@ public void run(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
         }
         PrepareCommand prepareCommand = preparedStmtCtx.command;
         StatementContext statementContext = 
preparedStmtCtx.getStatementContext();
+        // Prepared statements reuse StatementContext across executions. 
Discard partition
+        // information collected by the previous execution before planning the 
current one.
+        statementContext.getTableUsedPartitionNameMap().clear();

Review Comment:
   Fixed in b959429e41c. `mvCanRewritePartitionsMap` is now cleared at the same 
per-external-EXECUTE boundary as the query partition mappings, so the next 
planning pass cannot read the prior `{m1,m2}` value through `putIfAbsent` and 
must recompute the current valid set.
   
   The repeated-execution test seeds a stale MV-valid-partition cache, verifies 
it is empty before each planning pass, and runs the real Nereids planner twice. 
This directly covers the cache boundary responsible for the 
partial-invalidation failure without adding a heavyweight MTMV integration 
setup.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExecuteCommand.java:
##########
@@ -91,6 +91,10 @@ public void run(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
         }
         PrepareCommand prepareCommand = preparedStmtCtx.command;
         StatementContext statementContext = 
preparedStmtCtx.getStatementContext();
+        // Prepared statements reuse StatementContext across executions. 
Discard partition
+        // information collected by the previous execution before planning the 
current one.
+        statementContext.getTableUsedPartitionNameMap().clear();
+        statementContext.getCommonTableIdToRelationIdMap().clear();

Review Comment:
   Fixed in b959429e41c. The per-external-EXECUTE reset now clears 
`tmpPlanForMvRewrite`, `rewrittenPlansByMv`, `needPreMvRewriteRuleMasks`, 
`needPreMvRewrite`, `preMvRewritten`, `materializationRewrittenSuccessSet`, and 
`relationIdToStatisticsMap`, together with the MV partition caches, rewrite 
duration, and stale `UseMvHint` entries.
   
   The test executes a real Nereids planning pass twice on the reused prepared 
`StatementContext`; before each pass it verifies the previous MV plans, masks, 
flags, successes, and relation statistics are gone, then repopulates the 
prior-execution state to validate the second boundary independently and keep 
retained plan state bounded.



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