pingcap / pingcap/tidb

Optimize the plan selection logic for LIMIT and TopN

Open
#64,181 0 comments 0 reactions 0 assignees View on GitHub
sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement
For LIMIT plan and TOPN plan, we have the following different kinds of plans(assume plan-1, plan-2, plan-3, plan-4 all use the same index)
1. plan-1: limit pushdown to tikv
2. plan-2: limit not pushdown to tikv
3. plan-3: topn pushdown to tikv
4. plan-4: topn not pushdown to tikv
5. plan-n: plans that use other index

The follwing rules are always valid(`plan-x > plan-y` means `plan-x` is definitly better than `plan-y`), we can implement thes rules in tidb, which can avoid wrong plan due to stats is no accurate.
1. plan-1 > plan-2/plan-3/plan-4
2. plan-3 > plan-4

And for other plan comparison(like plan-2 VS plan-4), we have to use cost comparison, because there is no explicit rule.

NOTE:
For now, tidb only implement the following rule:
1. plan-1 > plan-2
2. plan-3 > plan-4

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.