• 优化器参数-eq_range_index_dive_limit-索引下探


    5.7中当出现数据大量切斜的时候执行计划依然能够得到正确的执行计划。比如性别列索引,其中30行,29行为男性,1行为女性,下面是执行计划示例:

    mysql> set eq_range_index_dive_limit=100;
    Query OK, 0 rows affected (0.00 sec)
    mysql> desc select * from testdvi3 where sex='M';
    +----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+
    | id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
    +----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+
    |  1 | SIMPLE      | testdvi3 | NULL       | ALL  | sex           | NULL | NULL    | NULL |   30 |    96.67 | Using where |
    +----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+
    1 row in set, 1 warning (2.74 sec)
    mysql> desc select * from testdvi3 where sex='W';
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    | id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref   | rows | filtered | Extra |
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    |  1 | SIMPLE      | testdvi3 | NULL       | ref  | sex           | sex  | 9       | const |    1 |   100.00 | NULL  |
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    1 row in set, 1 warning (2.00 sec)
    mysql> set eq_range_index_dive_limit=1;
    Query OK, 0 rows affected (0.00 sec)
    mysql> desc select * from testdvi3 where sex='W';
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    | id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref   | rows | filtered | Extra |
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    |  1 | SIMPLE      | testdvi3 | NULL       | ref  | sex           | sex  | 9       | const |   15 |   100.00 | NULL  |
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    1 row in set, 1 warning (0.00 sec)
    mysql> desc select * from testdvi3 where sex='M';
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    | id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref   | rows | filtered | Extra |
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    |  1 | SIMPLE      | testdvi3 | NULL       | ref  | sex           | sex  | 9       | const |   15 |   100.00 | NULL  |
    +----+-------------+----------+------------+------+---------------+------+---------+-------+------+----------+-------+
    

      使用限制

    • 唯一条件的等值查询也不会使用索引下探(= in or )。
    • 一般是非唯一索引或者范围查询(< > <= >=)才会用到索引下探,实际上他们都是‘RANGE’。
    螃蟹在剥我的壳,笔记本在写我,漫天的我落在枫叶上雪花上,而你在想我。 --章怀柔
  • 相关阅读:
    查看crontab的日志记录定位定时任务问题
    Latex 表格内公式换行方法
    C语言中qsort函数用法
    7 种常用的排序算法-视觉直观感受
    Ubuntu下如何安装YouCompleteMe插件
    Linux下非root用户如何安装软件
    系统进化树-原理介绍及软件使用
    LaTeX 页眉页脚的设置
    TEXshade教程- 多重比对着色软件包
    easyUI自带的时间插件日期选择、月份选择、时间选择的使用
  • 原文地址:https://www.cnblogs.com/lovezhr/p/13407299.html
Copyright © 2020-2023  润新知