When running EXPLAIN, if the field value for key is not null but Extra is blank, is the key used?

后端 未结 1 1948
温柔的废话
温柔的废话 2020-12-21 09:56

When running this EXPLAIN query without an index

EXPLAIN SELECT exec_date,
    100 * SUM(CASE WHEN cached = \'no\' THEN 1 ELSE 0 END)  / SUM(1)          


        
1条回答
  •  太阳男子
    2020-12-21 10:37

    Using index doesn't mean what you think it means. If it is present in the Extra column, it indicates that the optimizer isn't actually reading the entire rows, it is using the index (exclusively) to find column information.

    The key could still be in use for other things, for example to perform lookups if you have a WHERE clause etc. In your specific scenario, for example, the disappearance of the Using temporary; actually does mean that your index is being utilized, since MySQL no longer needs to rearrange the contents of your table into a new temporary table to perform the GROUP BY.

    0 讨论(0)
提交回复
热议问题