Bug Report
1. Minimal reproduce step (Required)
When we try to build multiple logical plans directly from the same AST, the planner still reuses some AST-owned mutable structures, especially FieldType instances carried by expression nodes.
This becomes a problem when we stop relying on logical-plan deep clone and instead rebuild plans from a shared AST: a later build can observe or mutate state that was attached to the previous build.
2. What did you expect to see? (Required)
Each logical-plan build should own its planner/runtime metadata. Building multiple logical plans from one AST should not share mutable FieldType state through expression return types or planner-created constants.
3. What did you see instead (Required)
Several planner paths pass AST-owned FieldType objects directly into expression builders. Some of those builders keep the pointer as RetType, and some code paths may even modify the target type during build.
4. What is your TiDB version? (Required)
master
5. Additional context
Suggested labels: type/bug, component/expression, sig/planner, severity/moderate, may-affects-8.5
Proposed execution steps:
- Deep-copy AST-owned
FieldType objects when building expression return types and planner-created constants. This step should also add regression tests for building from the same AST multiple times.
- Audit remaining planner/logical-plan fields that still retain AST pointers, such as index hints, lock info, and show/limit related AST nodes, and replace them with planner-owned state where feasible.
- Add broader end-to-end validation for building multiple logical plans from a shared AST without relying on deep-clone behavior.
This PR will cover step 1.
Bug Report
1. Minimal reproduce step (Required)
When we try to build multiple logical plans directly from the same AST, the planner still reuses some AST-owned mutable structures, especially
FieldTypeinstances carried by expression nodes.This becomes a problem when we stop relying on logical-plan deep clone and instead rebuild plans from a shared AST: a later build can observe or mutate state that was attached to the previous build.
2. What did you expect to see? (Required)
Each logical-plan build should own its planner/runtime metadata. Building multiple logical plans from one AST should not share mutable
FieldTypestate through expression return types or planner-created constants.3. What did you see instead (Required)
Several planner paths pass AST-owned
FieldTypeobjects directly into expression builders. Some of those builders keep the pointer asRetType, and some code paths may even modify the target type during build.4. What is your TiDB version? (Required)
master5. Additional context
Suggested labels:
type/bug,component/expression,sig/planner,severity/moderate,may-affects-8.5Proposed execution steps:
FieldTypeobjects when building expression return types and planner-created constants. This step should also add regression tests for building from the same AST multiple times.This PR will cover step 1.