planner, statistics: use selected partition stats for dynamic pruning
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
TiDB currently prefers dynamic partition pruning for partitioned tables. This avoids building static-pruning plans, but it also means the optimizer usually estimates row counts from the partition table stats path instead of the stats of the actually selected partitions.
In some queries, this leads to less accurate cardinality estimation. The partition table global stats are aggregated from all partitions, so they are not a good replacement when the query only touches a subset of partitions.
We should improve this path by:
1. Keeping dynamic partition pruning as the execution mode.
2. Reusing the partition pruning result when the optimizer can determine the selected partitions during planning.
3. Merging stats from the selected partitions at runtime for cardinality estimation, instead of falling back to the partition table global stats.
4. Skipping plan cache when static-pruning information is involved, because cached plans can otherwise reuse an incorrect partition-specific estimation result.
This should improve plan quality for partitioned tables without reintroducing the old static-pruning execution behavior.
Contributor guide
Research direction
No files or tests are named in the issue. Start by tracing TiDB's planner paths for dynamic partition pruning, selected-partition statistics, and plan caching. Done means dynamic pruning remains the execution mode, selected partition stats improve cardinality estimation, and plans involving static-pruning information are not cached.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100