zoukankan      html  css  js  c++  java
  • 【mysql】ICP下mysql执行计划的一次解析

    mysql版本

    [root@xxxx]# mysql --version
    mysql  Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
    

    表结构

    注意索引:KEY idx_username (Username)

    | left_table | CREATE TABLE `left_table` (
      `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `Username` varchar(40) NOT NULL,
      `Birthday` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
      `CityID` smallint(6) NOT NULL DEFAULT '0',
      `CreatDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
      `AlterDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      PRIMARY KEY (`ID`),
      KEY `idx_username` (`Username`)
    ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 |
    

    执行计划:Using where; Using index

    MySQL [test]> explain select Username from left_table where Username='xxxxx@qq.com';
    +----+-------------+------------+------+---------------+--------------+---------+-------+------+--------------------------+
    | id | select_type | table      | type | possible_keys | key          | key_len | ref   | rows | Extra                    |
    +----+-------------+------------+------+---------------+--------------+---------+-------+------+--------------------------+
    |  1 | SIMPLE      | left_table | ref  | idx_username  | idx_username | 122     | const |    1 | Using where; Using index |
    +----+-------------+------------+------+---------------+--------------+---------+-------+------+--------------------------+
    
    

    疑惑: 为什么不是Using Index,而是 Using where; Using index

    index-condition-pushdown-optimization


    从官方文档可知:

    • 当不使用ICP时,where是在服务器处理的
    • 使用ICP时,where可以在存储引擎处理
    • 不使用ICP,存储引擎会查表获取完整记录(貌似索引覆盖也是如此,不知理解是否正确),然后返回给服务器;

    疑问解释

    mysql使用5.5版本,这个版本不支持ICP;
    不使用ICP的情况下:

    1. 存储引擎根据索引,查表获取完整记录,虽然是覆盖索引,还是进行了查表工作(根据主键二次查询),然后返回给服务器;
    2. 服务器进行where判断,所以显示 Using where,Using index
  • 相关阅读:
    BlackBerry Localiztion Websites
    BlackBerry device debug
    (收藏)Android VoIP
    How to access the folder of Android
    listView高度控制 底部tabhost标签 用android:layout_below="@+id/tab_all"
    自定义TabHost,TabWidget样式 .
    点击TextView 弹出复制选项
    如何实现验证两次输入的密码是否一致
    Android 获取SDCard上图片和视频的缩略图
    去掉activity(tabhost )顶部的gradient 黑线 横线 阴影
  • 原文地址:https://www.cnblogs.com/ssslinppp/p/8406157.html
Copyright © 2011-2022 走看看