mysql注意点

limit 1 的使用

1
$ select name from user where id = "23" limit 1

避免使用 select / count

1
$  使用 count(1) 或者 count(列) 代替 count(*)

创建索引但无法命中的几种情况

  1. 使用函数

    1
    $ select name from user where reverse(name) = 'sanzhang'
  2. 类型不一致
    假设 name 为字符串类型,

1
$ select name from user where name= 999
  1. like ‘%xx’

  2. 普通的 != 不走索引