pingcap / pingcap/tidb

planner: physical LEADING extraction misses joins behind wrappers

Open
#70,351 0 comments 0 reactions 0 assignees View on GitHub
contribution
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

1. Build a physical plan whose reordered join group contains a `PhysicalJoin` below a `PhysicalSelection` or `PhysicalProjection` wrapper.
2. Run `EXPLAIN FORMAT='hint'` for the statement.
3. Inspect the generated `LEADING` hint.

The relevant code is `extractOrderedPhysicalJoinGroup` in `pkg/planner/core/hint_utils.go`. It recursively enters only a direct `PhysicalJoin` child, while logical join-group extraction can traverse allowed Selection/Projection wrappers. As a result, the physical hint generator can observe a smaller join group than join reorder used.

### 2. What did you expect to see? (Required)

For wrappers that preserve the join-group boundary, physical LEADING extraction should traverse them consistently with logical join-group extraction and emit a replayable LEADING hint for the complete reordered group.

### 3. What did you see instead (Required)

The extractor stops at the Selection/Projection wrapper. This can omit LEADING generation or export only a partial physical join group, so `EXPLAIN FORMAT='hint'` does not fully reproduce the physical join order.

### 4. What is your TiDB version? (Required)

Current master / PR #68561 development branch (observed at `f6cf8822f4`).

Contributor guide

Open the contributing guide

Research direction

Start in pkg/planner/core/hint_utils.go at extractOrderedPhysicalJoinGroup, then compare its traversal with the logical join-group extraction described in the issue. Reproduce the case with a PhysicalJoin beneath a PhysicalSelection or PhysicalProjection and inspect EXPLAIN FORMAT='hint'. Done means the complete reordered group produces a replayable physical LEADING hint.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.