没有合适的资源?快使用搜索试试~ 我知道了~
MySQL Index Condition Pushdown(ICP)性能优化方法实例
0 下载量 126 浏览量
2020-12-15
17:14:23
上传
评论
收藏 108KB PDF 举报
温馨提示
试读
4页
一 概念介绍 Index Condition Pushdown (ICP)是MySQL 5.6 版本中的新特性,是一种在存储引擎层使用索引过滤数据的一种优化方式。 a 当关闭ICP时,index 仅仅是data access 的一种访问方式,存储引擎通过索引回表获取的数据会传递到MySQL Server 层进行where条件过滤。 b 当打开ICP时,如果部分where条件能使用索引中的字段,MySQL Server 会把这部分下推到引擎层,可以利用index过滤的where条件在存储引擎层进行数据过滤,而非将所有通过index access的结果传递到MySQL server层进行where
资源推荐
资源详情
资源评论
MySQL Index Condition Pushdown(ICP)性能优化方法实例性能优化方法实例
一一 概念介绍概念介绍
Index Condition Pushdown (ICP)是MySQL 5.6 版本中的新特性,是一种在存储引擎层使用索引过滤数据的一种优化方式。
a 当关闭ICP时,index 仅仅是data access 的一种访问方式,存储引擎通过索引回表获取的数据会传递到MySQL Server 层进行
where条件过滤。
b 当打开ICP时,如果部分where条件能使用索引中的字段,MySQL Server 会把这部分下推到引擎层,可以利用index过滤的where
条件在存储引擎层进行数据过滤,而非将所有通过index access的结果传递到MySQL server层进行where过滤.
优化效果:ICP能减少引擎层访问基表的次数和MySQL Server 访问存储引擎的次数,减少io次数,提高查询语句性能。
二二 原理原理
Index Condition Pushdown is not used:
1 Get the next row, first by reading the index tuple, and then by using the index tuple to locate and read the full table row.
2 Test the part of the WHERE condition that applies to this table. Accept or reject the row based on the test result.
Index Condition Pushdown is used
1 Get the next row s index tuple (but not the full table row).
2 Test the part of the WHERE condition that applies to this table and can be checked using only index columns.
If the condition is not satisfied, proceed to the index tuple for the next row.
3 If the condition is satisfied, use the index tuple to locate and read the full table row.
4 est the remaining part of the WHERE condition that applies to this table. Accept or reject the row based on the test result.
三三 实践案例实践案例
a 环境准备
数据库版本 5.6.16
关闭缓存
代码如下:
set query_cache_size=0;
set query_cache_type=OFF;
测试数据下载地址
b 当开启ICP时
代码如下:
mysql> SET profiling = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select * from employees where first_name=’Anneke’ and last_name like ‘%sig’ ;
+——–+————+————+———–+——–+————+
| emp_no | birth_date | first_name | last_name | gender | hire_date |
+——–+————+————+———–+——–+————+
| 10006 | 1953-04-20 | Anneke | Preusig | F | 1989-06-02 |
+——–+————+————+———–+——–+————+
1 row in set (0.00 sec)
mysql> show profiles;
+———-+————+——————————————————————————–+
| Query_ID | Duration | Query |
+———-+————+——————————————————————————–+
| 1 | 0.00060275 | select * from employees where first_name=’Anneke’ and last_name like ‘%sig’ |
+———-+————+——————————————————————————–+
3 rows in set, 1 warning (0.00 sec)
此时情况下根据MySQL的最左前缀原则, first_name 可以使用索引,last_name采用了like 模糊查询,不能使用索引。
c 关闭ICP
代码如下:
mysql> set optimizer_switch=’index_condition_pushdown=off’;
Query OK, 0 rows affected (0.00 sec)
mysql> SET profiling = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select * from employees where first_name=’Anneke’ and last_name like ‘%sig’ ;
+——–+————+————+———–+——–+————+
| emp_no | birth_date | first_name | last_name | gender | hire_date |
+——–+————+————+———–+——–+————+
| 10006 | 1953-04-20 | Anneke | Preusig | F | 1989-06-02 |
+——–+————+————+———–+——–+————+
资源评论
weixin_38743235
- 粉丝: 10
- 资源: 941
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功