Skip to content

planner: track AST decoupling for rebuilding logical plans from a shared AST #66651

@AilinKid

Description

@AilinKid

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:

  1. 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.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions