covering index失效

[复制链接]
查看11 | 回复6 | 2011-2-18 11:42:47 | 显示全部楼层 |阅读模式
本帖最后由 clevernby 于 2013-2-6 14:25 编辑
MySQL 5.5 Reference Manual中有这样的描述
When a long-running transaction modifies a table, queries against that table from other transactions do not make use of the covering index technique
复制代码
真的是这样的吗?我无法实验出这个效果
环境
MySQL 5.5.27 Linux x86-64
create table t_coverindex(id1 int not null,id2 int not null,name char(30)) engine=InnoDB;
alter table t_coverindex add constraint pk_coverindex primary key (id1),add index idx_coverindex (id2);
复制代码
会话1执行
update t_coverindex set id1=0,id2=0,name='ses1' where id1=1;
一直不提交
复制代码
会话2执行
mysql> explain select id1,id2 from t_coverindex where id2=100000;
+----+-------------+--------------+------+----------------+----------------+---------+-------+------+-------------+
| id | select_type | table| type | possible_keys| key
| key_len | ref | rows | Extra |
+----+-------------+--------------+------+----------------+----------------+---------+-------+------+-------------+
|1 | SIMPLE| t_coverindex | ref| idx_coverindex | idx_coverindex | 4 | const |1 | Using index |
+----+-------------+--------------+------+----------------+----------------+---------+-------+------+-------------+
1 row in set (0.00 sec)
复制代码
Extra=Using index而非using where,文档中的这句话该如何理解?

回复

使用道具 举报

千问 | 2011-2-18 11:42:47 | 显示全部楼层
这个区人气不足呀,高手来指点下吧
回复

使用道具 举报

千问 | 2011-2-18 11:42:47 | 显示全部楼层


,干嘛加where条件啊,去掉试试啥效果,这说的应该是覆盖索引的问题了!
回复

使用道具 举报

千问 | 2011-2-18 11:42:47 | 显示全部楼层
草民的补丁 发表于 2013-2-7 11:30
,干嘛加where条件啊,去掉试试啥效果,这说的应该是覆盖索引的问题了!

一样的效果
mysql> explain select id1,id2 from t_coverindex;
+----+-------------+--------------+-------+---------------+----------------+---------+------+-------+-------------+
| id | select_type | table| type| possible_keys | key
| key_len | ref| rows| Extra |
+----+-------------+--------------+-------+---------------+----------------+---------+------+-------+-------------+
|1 | SIMPLE| t_coverindex | index | NULL
| idx_coverindex | 4 | NULL | 99935 | Using index |
+----+-------------+--------------+-------+---------------+----------------+---------+------+-------+-------------+
1 row in set (0.00 sec)
复制代码
回复

使用道具 举报

千问 | 2011-2-18 11:42:47 | 显示全部楼层
clevernby 发表于 2013-2-7 12:13
一样的效果

怎么回事一样的呢?你仔细看下possible_keys,以及这个值在使用覆盖索引的时候,会有哪些变化的状态,还有就是加where条件为什么不选择覆盖索引的情况,呵呵!
回复

使用道具 举报

千问 | 2011-2-18 11:42:47 | 显示全部楼层
先插入几条记录
回复

使用道具 举报

千问 | 2011-2-18 11:42:47 | 显示全部楼层
Extra显示 using index表示 使用了覆盖索引
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行