【问题标题】:Covering SELECT on index gives using where; using index; instead of only using index;在索引上覆盖 SELECT 可以使用 where;使用索引;而不是只使用索引;
【发布时间】:2015-10-16 21:28:57
【问题描述】:

查询:

SELECT A from table_name where A = 'a';

解释输出

1   SIMPLE  table_name  ref A_idx   A_idx   1   const   40582635    **Using where; Using index**

问题

我有一个复合索引A_idx on (A,B,C)...

我希望输出仅使用索引,因为索引涵盖了完整的查询。但我仍然得到一个 using where;使用索引...

有问题的列是具有以下定义的 ENUM。

A enum('a','b','c') COLLATE utf8_unicode_ci NOT NULL,

【问题讨论】:

  • 显然我什至得到这个..如果我这样做select id from table where id > 100 ....
  • 让我们以不同的方式检查。你从FLUSH STATUS; SELECT ... ; SHOW SESSION STATUS LIKE 'Handler%'; 得到什么?表格中有多少行?
  • 我会这样做并尽快分享结果
  • bugs.mysql.com 提交错误。

标签: mysql optimization indexing innodb b-tree


【解决方案1】:

explain output documentation 的相应部分所述,“即使您对 WHERE 子句的所有部分都使用索引,您也可能会看到使用 where 如果列可以为 NULL。”

更新:文档还说“如果 Extra 列还说 Using where [beside using index],这意味着索引正在用于执行键值的查找。”

【讨论】:

  • 该列不为空。因此我添加了列定义。
  • 它不应该查找键值,因为所需的值是索引本身的一部分。这不是覆盖索引的全部意义所在。 ?
  • 显然优化器决定不这样做。
  • 即使是select count(*) from table where id > 100
猜你喜欢
  • 1970-01-01
  • 2017-11-15
  • 2019-09-12
  • 2016-01-03
  • 1970-01-01
  • 2020-05-09
  • 2015-04-29
  • 1970-01-01
  • 2015-03-18
相关资源
最近更新 更多