pingcap / pingcap/tidb

planner: disambiguate MPP dynamic partition pruning in explain output

Open
#68,571 1 comment 0 reactions 0 assignees View on GitHub
component/tablepartition MPP sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement

When `EXPLAIN` prints dynamic partition pruning information for an MPP plan, the partition information is attached to the root `PhysicalTableReader` access object. For an MPP plan tree that contains multiple table scans of the same table name, this output can become ambiguous.

Example:

```sql
set tidb_allow_mpp = 1;
set tidb_enforce_mpp = 1;
set tidb_partition_prune_mode = dynamic;

create table t (a int, b char(20)) partition by range(a) (
partition p0 values less than (2),
partition p1 values less than (3),
partition pMax values less than maxvalue
);
alter table t set tiflash replica 1;

explain format = 'plan_tree'
select *
from (select * from t where a = 1) x
join (select * from t where a = 2) y on x.b = y.b;
```

The plan can look like this:

```text
TableReader root partition:p0 of t, partition:p1 of t MppVersion: 3, data:ExchangeSender
└─ExchangeSender mpp[tiflash] ExchangeType: PassThrough
└─HashJoin mpp[tiflash] inner join, equal:[eq(test.t.b, test.t.b)]
├─ExchangeReceiver(Build) mpp[tiflash]
│ └─ExchangeSender mpp[tiflash] ExchangeType: Broadcast, Compression: FAST
│ └─Selection mpp[tiflash] not(isnull(test.t.b))
│ └─TableFullScan mpp[tiflash] table:t pushed down filter:eq(test.t.a, 1), keep order:false, stats:pseudo, PartitionTableScan:true
└─Selection(Probe) mpp[tiflash] not(isnull(test.t.b))
└─TableFullScan mpp[tiflash] table:t pushed down filter:eq(test.t.a, 2), keep order:false, stats:pseudo, PartitionTableScan:true
```

The root access object says `partition:p0 of t, partition:p1 of t`, while both child scans are printed as `table:t`. For a larger MPP tree, or when the same base table appears many times, it is hard to tell which partition pruning result belongs to which scan without reverse-engineering the predicates and tree shape.

It would be helpful if the dynamic partition pruning output for multi-scan MPP `TableReader` plans included a stable disambiguator, for example:

- the corresponding table scan plan id, such as `partition:p0 of TableFullScan_x`;
- the effective table alias when available;
- or another scan-local identifier that can be matched back to the child scan in the plan tree.

Related background: #30365 fixed/covered the older problem where MPP dynamic partition pruning information was not shown in `EXPLAIN` at all. This issue is about the remaining usability problem when multiple collected MPP table scans have the same printed table name.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.