seawinde opened a new pull request, #66370:
URL: https://github.com/apache/doris/pull/66370
### What problem does this PR solve?
Issue Number: N/A
Related PR: N/A
Problem Summary:
Repeated server prepared statement executions can retain query partition and
relation mappings from earlier executions. No GitHub issue is associated with
this fix; the production incident is tracked outside GitHub.
**Root cause:** In `ExecuteCommand.run()`, server prepared statements reuse
the
same `StatementContext`, while `QueryPartitionCollector` appends current
partition and relation mappings without removing mappings from prior
executions. `PartitionCompensator.getQueryUsedPartitions()` then scans the
accumulated entries and creates a temporary `BitSet` for every RelationId,
increasing FE CPU, allocation, and GC overhead as the connection remains
active.
**Change Summary:**
| File | Change Description |
|------|-------------------|
| `ExecuteCommand.java` | Clear the previous execution's query partition and
relation mappings before planning the next `EXECUTE`. |
| `PartitionCompensator.java` | Query the existing relation `BitSet`
directly instead of allocating a singleton `BitSet` for each mapping. |
| `ExecuteCommandTest.java` | Verify both mappings are cleared on every
prepared statement execution. |
The change resets only the two confirmed per-execution mappings and leaves
placeholder, short-circuit, connector, MVCC, and other prepared statement
state
unchanged.
```mermaid
flowchart LR
A[EXECUTE starts] --> B[Clear prior partition mappings]
B --> C[Plan current execution]
C --> D[Check RelationId with BitSet.get]
```
### Release note
Fixed excessive FE CPU and memory usage when repeatedly executing prepared
statements with materialized view rewrite.
### Check List (For Author)
- Test
- [ ] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason
`./run-fe-ut.sh --run
org.apache.doris.nereids.trees.plans.commands.ExecuteCommandTest,org.apache.doris.nereids.rules.exploration.mv.PartitionCompensatorTest`
- Behavior changed:
- [x] No.
- [ ] Yes.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]