当前位置:   article > 正文

关于 MySQL index dives 详细解读

index dive

文章未完工,码字中......

1. 关于 index dives  MySQL 官方文档中给出的解释

  1. Equality Range Optimization of Many-Valued Comparisons
  2. Consider these expressions, where col_name is an indexed column:
  3. col_name IN(val1, ..., valN)
  4. col_name = val1 OR ... OR col_name = valN
  5. Each expression is true if col_name is equal to any of several values. These comparisons are equality range comparisons (where the “range” is a single value). The optimizer estimates the cost of reading qualifying rows for equality range comparisons as follows:
  6. If there is a unique index on col_name, the row estimate for each range is 1 because at most one row can have the given value.
  7. Otherwise, any index on col_name is nonunique and the optimizer can estimate the row count for each range using dives into the index or index statistics.
  8. With index dives, the optimizer makes a dive at each end of a range and uses the number of rows in the range as the estimate. For example, the expression col_name IN (10, 20, 30) has three equality ranges and the optimizer makes two dives per range to generate a row estimate. Each pair of dives yields an estimate of the number of rows that have the given value.
  9. Index dives provide accurate row estimates, but as the number of comparison values in the expression increases, the optimizer takes longer to generate a row estimate. Use of index statistics is less accurate than index dives but permits faster row estimation for large value lists.
  10. The eq_range_index_dive_limit system variable enables you to configure the number of values at which the optimizer switches from one row estimation strategy to the other. To permit use of index dives for comparisons of up to N equality ranges, set eq_range_index_dive_limit to N + 1. To disable use of statistics and always use index dives regardless of N, set eq_range_index_dive_limit to 0.
  11. To update table index statistics for best estimates, use ANALYZE TABLE.
  12. Prior to MySQL 8.0, there is no way of skipping the use of index dives to estimate index usefulness, except by using the eq_range_index_dive_limit system variable. In MySQL 8.0, index dive skipping is possible for queries that satisfy all these conditions:
  13. The query is for a single table, not a join on multiple tables.
  14. A single-index FORCE INDEX index hint is present. The idea is that if index use is forced, there is nothing to be gained from the additional overhead of performing dives into the index.
  15. The index is nonunique and not a FULLTEXT index.
  16. No subquery is present.
  17. No DISTINCT, GROUP BY, or ORDER BY clause is present.
  18. For EXPLAIN FOR CONNECTION, the output changes as follows if index dives are skipped:
  19. For traditional output, the rows and filtered values are NULL.
  20. For JSON output, rows_examined_per_scan and rows_produced_per_join do not appear, skip_index_dive_due_to_force is true, and cost calculations are not accurate.
  21. Without FOR CONNECTION, EXPLAIN output does not change when index dives are skipped.
  22. After execution of a query for which index dives are skipped, the corresponding row in the INFORMATION_SCHEMA.OPTIMIZER_TRACE table contains an index_dives_for_range_access value of skipped_due_to_force_index.

2.关于 eq_range_index_dive_limit 参数

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/599078
推荐阅读
相关标签
  

闽ICP备14008679号