MySQL Index Condition Pushdown 原理与解析
set
optimizer_switch =
'index_condition_pushdown=off'
;
set
optimizer_switch =
'index_condition_pushdown=on'
;
测试过程
1.环境准备
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#mysql 5.6.25 #关闭结果缓存 mysql> set global query_cache_size=0; mysql> set query_cache_type= off ; #查看表结构 mysql> show create table employees\G *************************** 1. row *************************** Table : employees Create Table : CREATE TABLE `employees` ( `emp_no` int (11) NOT NULL , `birth_date` date NOT NULL , `first_name` varchar (14) NOT NULL , `last_name` varchar (16) NOT NULL , `gender` enum( 'M' , 'F' ) NOT NULL , `hire_date` date NOT NULL , PRIMARY KEY (`emp_no`), KEY `idx_first_last_name` (`first_name`,`last_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec) mysql> |
2.开启ICP后进行测试
1
2
3
4
5
|
mysql> set profiling = 1; mysql> select * from employees where first_name= 'Anneke' and last_name like '%sig' ; mysql> explain select * from employees where first_name= 'Anneke' and last_name like '%sig' ; mysql> show profiles; mysql> show profile cpu,block io for query 1; |
3.关闭ICP后进行测试
1
2
3
4
5
6
|
mysql> set optimizer_switch= 'index_condition_pushdown=off' ; mysql> set profiling = 1; mysql> select * from employees where first_name= 'Anneke' and last_name like '%sig' ; mysql> explain select * from employees where first_name= 'Anneke' and last_name like '%sig' ; mysql> show profiles; mysql> show profile cpu,block io for query 1; |
4.结果比较
开启ICP后的执行计划:执行计划中extra部分的内容是"using index condition"
1
2
3
4
5
6
|
mysql> explain select * from employees where first_name= 'Anneke' and last_name like '%sig' ; + ----+-------------+-----------+------+---------------------+---------------------+---------+-------+------+-----------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------+------+-----------------------+ | 1 | SIMPLE | employees | ref | idx_first_last_name | idx_first_last_name | 44 | const | 224 | Using index condition | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------+------+-----------------------+ |
关闭ICP后的执行计划:执行计划中extra部分的内容是"using where"
1
2
3
4
5
6
|
mysql> explain select * from employees where first_name= 'Anneke' and last_name like '%sig' ; + ----+-------------+-----------+------+---------------------+---------------------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------+------+-------------+ | 1 | SIMPLE | employees | ref | idx_first_last_name | idx_first_last_name | 44 | const | 224 | Using where | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------+------+-------------+ |
开启ICP后的profile内容:Sending data部分的值是0.000212s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
mysql> show profile cpu,block io for query 1; + ----------------------+----------+----------+------------+--------------+---------------+ | Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out | + ----------------------+----------+----------+------------+--------------+---------------+ | starting | 0.000114 | 0.000000 | 0.000000 | 0 | 0 | | checking permissions | 0.000007 | 0.000000 | 0.000000 | 0 | 0 | | Opening tables | 0.000018 | 0.000000 | 0.000000 | 0 | 0 | | init | 0.000034 | 0.000000 | 0.000000 | 0 | 0 | | System lock | 0.000008 | 0.000000 | 0.000000 | 0 | 0 | | optimizing | 0.000023 | 0.000000 | 0.000000 | 0 | 0 | | statistics | 0.000383 | 0.000000 | 0.000000 | 0 | 0 | | preparing | 0.000019 | 0.000000 | 0.000000 | 0 | 0 | | executing | 0.000002 | 0.000000 | 0.000000 | 0 | 0 | | Sending data | 0.000212 | 0.000000 | 0.000000 | 0 | 0 | | end | 0.000004 | 0.000000 | 0.000000 | 0 | 0 | | query end | 0.000004 | 0.000000 | 0.000000 | 0 | 0 | | closing tables | 0.000006 | 0.000000 | 0.000000 | 0 | 0 | | freeing items | 0.000020 | 0.000000 | 0.000000 | 0 | 0 | | cleaning up | 0.000011 | 0.000000 | 0.000000 | 0 | 0 | + ----------------------+----------+----------+------------+--------------+---------------+ |
关闭ICP后的profile内容:Sending data部分的值是0.010990s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
mysql> show profile cpu,block io for query 1; + ----------------------+----------+----------+------------+--------------+---------------+ | Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out | + ----------------------+----------+----------+------------+--------------+---------------+ | starting | 0.000165 | 0.000000 | 0.000000 | 0 | 0 | | checking permissions | 0.000022 | 0.000000 | 0.000000 | 0 | 0 | | Opening tables | 0.000027 | 0.000000 | 0.000000 | 0 | 0 | | init | 0.000039 | 0.000000 | 0.000000 | 0 | 0 | | System lock | 0.000008 | 0.000000 | 0.000000 | 0 | 0 | | optimizing | 0.000037 | 0.001000 | 0.000000 | 0 | 0 | | statistics | 0.000483 | 0.001000 | 0.000000 | 0 | 0 | | preparing | 0.000022 | 0.000000 | 0.000000 | 0 | 0 | | executing | 0.000002 | 0.000000 | 0.000000 | 0 | 0 | | Sending data | 0.010990 | 0.007999 | 0.002000 | 0 | 0 | | end | 0.000009 | 0.000000 | 0.000000 | 0 | 0 | | query end | 0.000005 | 0.000000 | 0.000000 | 0 | 0 | | closing tables | 0.000008 | 0.000000 | 0.000000 | 0 | 0 | | freeing items | 0.000028 | 0.000000 | 0.000000 | 0 | 0 | | cleaning up | 0.000014 | 0.000000 | 0.000000 | 0 | 0 | + ----------------------+----------+----------+------------+--------------+---------------+ |
其它:
当sql使用覆盖索引时,不支持ICP优化方法
1
2
3
4
5
6
7
8
9
10
11
12
|
mysql> explain select first_name,last_name from employees where first_name= 'Anneke' and last_name= 'Porenta' ; + ----+-------------+-----------+------+---------------------+---------------------+---------+-------------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------------+------+--------------------------+ | 1 | SIMPLE | employees | ref | idx_first_last_name | idx_first_last_name | 94 | const,const | 1 | Using where ; Using index | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------------+------+--------------------------+ mysql> explain select * from employees where first_name= 'Anneke' and last_name= 'Porenta' ; + ----+-------------+-----------+------+---------------------+---------------------+---------+-------------+------+-----------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------------+------+-----------------------+ | 1 | SIMPLE | employees | ref | idx_first_last_name | idx_first_last_name | 94 | const,const | 1 | Using index condition | + ----+-------------+-----------+------+---------------------+---------------------+---------+-------------+------+-----------------------+ |
MySQL Index Condition Pushdown 原理与解析的更多相关文章
- MySQL Index Condition Pushdown
Index Condition Pushdown (ICP)是MySQL 5.6 版本中的新特性,是一种在存储引擎层使用索引过滤数据的一种优化方式.[Index Condition Pushdown] ...
- MySQL Index Condition Pushdown(ICP) 优化
本文是作者留下的一个坑,他去上茅坑了.茅坑是谁?你猜.
- 1229【MySQL】性能优化之 Index Condition Pushdown
转自http://blog.itpub.net/22664653/viewspace-1210844/ [MySQL]性能优化之 Index Condition Pushdown2014-07-06 ...
- 【mysql】关于Index Condition Pushdown特性
ICP简介 Index Condition Pushdown (ICP) is an optimization for the case where MySQL retrieves rows from ...
- 浅析MySQL中的Index Condition Pushdown (ICP 索引条件下推)和Multi-Range Read(MRR 索引多范围查找)查询优化
本文出处:http://www.cnblogs.com/wy123/p/7374078.html(保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错误 ...
- MySQL索引与Index Condition Pushdown
实际上,这个页面所讲述的是在MariaDB 5.3.3(MySQL是在5.6)开始引入的一种叫做Index Condition Pushdown(以下简称ICP)的查询优化方式.由于本身不是一个层面的 ...
- MySQL ICP(Index Condition Pushdown)特性
一.SQL的where条件提取规则 在ICP(Index Condition Pushdown,索引条件下推)特性之前,必须先搞明白根据何登成大神总结出一套放置于所有SQL语句而皆准的where查询条 ...
- MySQL 中Index Condition Pushdown (ICP 索引条件下推)和Multi-Range Read(MRR 索引多范围查找)查询优化
一.ICP优化原理 Index Condition Pushdown (ICP),也称为索引条件下推,体现在执行计划的上是会出现Using index condition(Extra列,当然Extra ...
- MySQL 查询优化之 Index Condition Pushdown
MySQL 查询优化之 Index Condition Pushdown Index Condition Pushdown限制条件 Index Condition Pushdown工作原理 ICP的开 ...
随机推荐
- Azure disk iops的测试
在Public Cloud中,VM.Storage和Network是IaaS的三大基础.本文将介绍在Azure的VM上测试磁盘IOPS的工具和方法. 一.添加磁盘.初始化磁盘 1.添加磁盘 把相应的信 ...
- 自己封装的AJAX (带JSON)
最简单的封装的AJAX: function myajax(url,onsuccess,fail){ //确定是否支持xhr var xhr = new XMLHttpRequest ? new XML ...
- Object-C类、方法、构造函数(2)
Object-C 代码分为三部分:.h文件..m文件及调用文件 .h源文件 #import <Foundation/Foundation.h> @interface Student:NSO ...
- 蓝桥杯 算法训练 ALGO-141 P1102
算法训练 P1102 时间限制:1.0s 内存限制:256.0MB 定义一个学生结构体类型student,包括4个字段,姓名.性别.年龄和成绩.然后在主函数中定义一个结构体数组(长度不超过10 ...
- 编译适用于TP-Link WR703N的OpenWRT固件
编译适用于TP-Link WR703N TP-Link MR11U 以及使用AR9331芯片组的单WAN/LAN复用口的路由. 注:刷机有风险,刷机需谨慎.一般情况下是不会失败的,若无法通过捅Rese ...
- 【转】Rails 4中使用 Bootstrap 3
转自:http://rvg.me/2013/11/using-bootstrap-3-with-rails-4/ If you are looking to use Bootstrap 3 with ...
- SpringMVC---依赖注入与面向切面
1.依赖注入与面向切面 1.1.出现背景 ——如何简化java开发? 其中很重要的一点是“组件化”. ——如何更好的“组件化”? 松耦合,以及尽可能的让组件专注于本身. ——Spring框架的目的也只 ...
- 渗透测试框架-Fsociety
下载项目并赋予权限,打开 ┌─[root@sch01ar]─[/sch01ar] └──╼ #git clone https://github.com/Manisso/fsociety ┌─[root ...
- vue-cli脚手架build目录中的dev-server.js配置文件
本文系统讲解vue-cli脚手架build目录中的dev-server.js配置文件 这个配置文件是命令npm run dev 和 npm run start 的入口配置文件,主要用于开发环境 由于这 ...
- 2015.3.20 Oracle使用正则表达式
.Oracle正则表达式使用介绍 正则表达式具有强大.便捷.高效的文本处理功能.能够添加.删除.分析.叠加.插入和修整各种类型的文本和数据.Oracle从10g开始支持正则表达式 ..下面通过一些例子 ...