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
address comments
  • Loading branch information
Xiaozhen Liu committed Aug 18, 2021
commit 40a51d14d5d26fe58f28df41c5497e8902a58888
8 changes: 4 additions & 4 deletions choose-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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 an index satisfies a pre rule, TiDB directly selects the index. Otherwise, TiDB uses Skyline-pruning to exclude unqualified indexes, and then based on the cost estimation of each operator for accessing tables, selects 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 directly selects the index. Otherwise, TiDB uses skyline-pruning to exclude unsuitable indexes, and then based on the cost estimation of each operator for accessing tables, selects the index with the lowest cost.
Liuxiaozhen12 marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -78,9 +78,9 @@ Skyline-pruning is a heuristic filtering rule for indexes, which can reduce the

- How many access conditions are covered by the indexed columns. An "access condition" is a where condition that can be converted to a column range. And the more access conditions an indexed column set covers, the better it is in this dimension.

For these three dimensions, if the index `idx_a` is not worse than the index `idx_b` in all three dimensions and one of the dimensions is better than `idx_b`, then `idx_a` is preferred. When executing the `EXPLAIN FORMAT = 'verbose' ...` statement, if Skyline-pruning excludes some indexes, TiDB will output a NOTE level warning listing the reserved indexes after Skyline-pruning's exclusion.
For these three dimensions, if the index `idx_a` is not worse than the index `idx_b` in all three dimensions and one of the dimensions is better than `idx_b`, then `idx_a` is preferred. When executing the `EXPLAIN FORMAT = 'verbose' ...` statement, if skyline-pruning excludes some indexes, TiDB will output a NOTE level warning listing the reserved indexes after skyline-pruning's exclusion.
Liuxiaozhen12 marked this conversation as resolved.
Show resolved Hide resolved

In the following example, the index `idx_b` and `idx_e` are both inferior to `idx_b_c`, so they are excluded by Skyline-pruning. The returned result of `SHOW WARNING` displays the remaining indexes after Skyline-pruning.
In the following example, the index `idx_b` and `idx_e` are both inferior to `idx_b_c`, so they are excluded by skyline-pruning. The returned result of `SHOW WARNING` displays the remaining indexes after skyline-pruning.
Liuxiaozhen12 marked this conversation as resolved.
Show resolved Hide resolved

```sql
mysql> CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, d INT, e INT, INDEX idx_b(b), INDEX idx_b_c(b, c), INDEX idx_e(e));
Expand All @@ -105,7 +105,7 @@ mysql> SHOW WARNINGS;

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

After using the Skyline-pruning rule to rule out inappropriate indexes, the selection of indexes is based entirely on the cost estimation. The cost estimation of accessing tables requires the following considerations:
After using the skyline-pruning rule to rule out inappropriate indexes, the selection of indexes is based entirely on the cost estimation. The cost estimation of accessing tables requires the following considerations:

- The average length of each row of the indexed data in the storage engine.
- The number of rows in the query range generated by the index.
Expand Down