Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update description on rule based index selection #6160

Merged
merged 9 commits into from
Aug 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix improper expression
  • Loading branch information
Xiaozhen Liu committed Aug 18, 2021
commit 56651765f33edbdd612dc288e574c67cee6db748
8 changes: 4 additions & 4 deletions choose-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ Before introducing index selection, it is important to understand the ways TiDB

## Index selection rules

TiDB selects indexes based on rules or cost. the based rules include pre rules and Skyline-pruning. When selecting an index, TiDB tries the pre rule first. If the existing index satisfies a pre rule, TiDB will directly select the index. Otherwise, TiDB will use Skyline-Pruning to exclude unqualified indexes, and then based on the cost estimation of each operator for accessing tables, select the index with the lowest cost.
TiDB selects indexes based on rules or cost. the based rules include pre rules and Skyline-pruning. When selecting an index, TiDB tries the pre rule first. If an index satisfies a pre rule, TiDB will directly select the index. Otherwise, TiDB will use Skyline-Pruning to exclude unqualified indexes, and then based on the cost estimation of each operator for accessing tables, select the index with the lowest cost.

### Selection based on rules
Liuxiaozhen12 marked this conversation as resolved.
Show resolved Hide resolved

#### Pre rules
Liuxiaozhen12 marked this conversation as resolved.
Show resolved Hide resolved

TiDB uses the following heuristic pre rules to select index:

+ rule 1: If the existing index satisfies "unique indexes with full match + no need to retrieve rows from a table (which means the plan generated by the index is IndexReader operator)", directly select this index.
+ rule 1: If an index satisfies "unique indexes with full match + no need to retrieve rows from a table (which means the plan generated by the index is IndexReader operator)", directly select this index.

+ rule 2: If the existing index satisfies "unique indexes + need to retrieve rows from a table (which means the plan generated by the index is IndexReader operator)", select the index with the smallest number of retrieve rows from a table as the candidate index.
+ rule 2: If an index satisfies "unique indexes + need to retrieve rows from a table (which means the plan generated by the index is IndexReader operator)", select the index with the smallest number of retrieve rows from a table as the candidate index.

+ rule 3: If the existing index satisfies "common indexes + no need to retrieve rows from a table + the number of rows to be read is less than the value of a certain threshold", select the index with the smallest number of rows to be read as the candidate index.
+ rule 3: If an index satisfies "common indexes + no need to retrieve rows from a table + the number of rows to be read is less than the value of a certain threshold", select the index with the smallest number of rows to be read as the candidate index.

+ rule 4: If only one candidate index is selected based on rule 2 and 3, select this index. If two candidate index is separately selected based on rule 2 and 3, select the index with the smallest number of rows to be read (the number of rows with index + the number of rows to be retrieved from a table).
xuyifangreeneyes marked this conversation as resolved.
Show resolved Hide resolved

Expand Down