Enhance the cost estimation of Sort operator
Open
affects-4.0
affects-5.0
affects-5.1
affects-5.2
affects-5.3
affects-5.4
affects-6.1
affects-6.5
affects-7.1
epic/cost-model
sig/planner
type/enhancement
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
https://github.com/pingcap/tidb/blob/5d05714eae5861ee175257c8bf0715d0547933fd/planner/core/plan_cost_ver2.go#L350-L370
In the logic of estimating Sort cost, `spill` doesn't accurately reflect whether disk spill happens in actual execution, and it causes a leap in cost function, which is prone to plan changes.
Besides, overestimating `sortDiskCost` may let the optimizer choose IndexRangeScan(more rows, keep order: true) instead of Sort->IndexRangeScan(less rows, keep order: false).
Maybe we can improve the cost estimation of Sort.
Contributor guide
Assessment
This issue has not been assessed yet.