Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaozhen Liu committed Aug 18, 2021
1 parent 6f02adb commit 40a51d1
Showing 1 changed file with 4 additions and 4 deletions.
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.

### Selection based on rules

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.

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.

```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

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

0 comments on commit 40a51d1

Please sign in to comment.