github-actions[bot] commented on code in PR #66370:
URL: https://github.com/apache/doris/pull/66370#discussion_r3703389966
##########
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:
**[P2] Reset retained MV pre-rewrite state for each EXECUTE**
`RecordPlanForMvPreRewrite` appends a complete analyzed plan on every
eligible execution, but this boundary never clears `tmpPlanForMvRewrite`.
`preMaterializedViewRewrite` then walks the entire retained history on each
later pass (the code even assumes the list has only one plan), while the
retained `preMvRewritten` flag makes `OptimizeGroupExpressionJob` omit all MV
exploration rules from the subsequent CBO phase. Repeated EXECUTEs therefore
retain unbounded plan graphs and do O(n) historical work per pass while
carrying the prior phase decision forward. Clear the temporary/rewritten plans,
MV phase flags/masks, and relation statistics here, and add a repeated
real-planning test that keeps the state bounded and validates the next
execution's MV phases independently.
##########
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:
**[P1] Reset cached MV-valid partitions before each EXECUTE**
On the CBO/`NOT_IN_RBO` path, this reused context also retains
`mvCanRewritePartitionsMap`. Suppose EXECUTE 1 records `{m1,m2}` as
synchronized, then a write makes only `m2` stale. EXECUTE 2 recomputes current
validity as `{m1}`, which is still nonempty, but
`MTMVRelationManager.isMVPartitionValid` uses `putIfAbsent`, so
`PartitionCompensator.calcInvalidPartitions` reads the old `{m1,m2}`. It
consequently adds neither `PartitionRemover` nor the base-table `LogicalUnion`
for `m2`, and stale MV rows can be returned. Clear this cache at the same
per-execution boundary and cover a two-EXECUTE partial-invalidation case.
##########
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
Review Comment:
**[P2] Reset the remaining per-query planner state here**
These two clears leave other state from the same planning pass alive in the
reused context: `materializedViewRewriteDuration` accumulates until later
EXECUTEs hit the rewrite cutoff; `hints` appends until one `USE_MV`/`NO_USE_MV`
becomes a duplicate; `joinFilters` grows and is rescanned by `CostModel`; and
`queryStatsRecorded` suppresses hit accounting after the first client
execution. The cached `disableRules` BitSet also makes a later `SET
disable_nereids_rules` ineffective for this prepared statement. Please make
this a centralized per-external-EXECUTE reset (without resetting retry-scoped
state inside one execution) and exercise an actual second planner run rather
than only a mocked `executor.execute()`.
--
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]