看到高性能mysql里面说
索引列如果不能是表达式的一部分或者为函数的参数时不会使用到索引。
select actor_id from sakila.actor where actor_id + 1 = 5;
不会使用到actor_id上面的索引,但是我自己试了一下,貌似可以用啊,

解决方案 »

  1.   

    这个actor_id 是不需要转化的   可以直接用
      

  2.   

    explain  select actor_id from sakila.actor where actor_id + 1 = 5;
    分析下
      

  3.   

    是不可以用的
    但是你的语句确实用到了 只不过是用的覆盖索引而已 但是无法使用索引树定位这个数据 仍然要逐个值的扫描
    你可以试试把SELECT那里写成SELECT *  那样就完全不能用索引了
      

  4.   

    贴出 explain select actor_id from sakila.actor where actor_id + 1 = 5; 以确定的确用到了索引。
      

  5.   

    mysql> explain select * from test where substr(stat_day, 0 ,5) = '20131'\G;
    *************************** 1. row ***************************
               id: 1
      select_type: SIMPLE
            table: test
             type: index
    possible_keys: NULL
              key: test
          key_len: 10
              ref: NULL
             rows: 3
            Extra: Using where; Using index
    1 row in set (0.00 sec)
      

  6.   

       书的意思是,你自己写SQL要注意这些问题,例如 不能是表达式的一部分、函数的参数。
      

  7.   

    mysql> explain select * from test where substr(stat_day, 0 ,5) = '20131'\G;
    *************************** 1. row ***************************
               id: 1
      select_type: SIMPLE
            table: test
             type: index
    possible_keys: NULL
              key: test
          key_len: 10
              ref: NULL
             rows: 3
            Extra: Using where; Using index
    1 row in set (0.00 sec)
    建议提问时保持例子问题的一惯性。你的例子和你顶楼的已经不是一个语句了。请同时贴出explain select ....
    show index from ...