Optimize the way optimizer do the index selection when topn is pushed down
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
In current physical optimization, pushing TopN down to the tikv is an individual part from the index selection. And the index selection happens before the topn's pushdown.
We find a case where: when the final plan is the case that topn pushed down, the cost we use to do the index selection is the one without topn's push down.
That is to say, we compare the different indexes' cost without the pushed topn, though it can be pushed down.
For `IndexLookUp(TopN->IndexScan, TableScan)` and `TableReader(TopN->TableScan)`, we do the index selection between `IndexLookUp(IndexScan, TableScan)` and `TableScan(TableScan)`, actually. This may lead to the wrong index selection because the network cost may have a large difference.
We may need to find a way to optimize it.
Contributor guide
Assessment
This issue has not been assessed yet.