💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
#### like查询 在使用like(模糊匹配)的时候,**在左边没有通配符的情况下**,才可以使用索引。在mysql里,以%开头的like查询,用不到索引。 错误: ~~~ explain select * from 表名 where name like '%ck'; ~~~ 结果 ~~~ id: 1 select_type: SIMPLE table: t1 partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1 filtered: 100.00 Extra: Using where //没有使用索引条件 ~~~ 正确: ~~~ explain select * from t1 where name like 'ja%'\G ~~~ 结果 ~~~ id: 1 select_type: SIMPLE table: t1 partitions: NULL type: range possible_keys: name,name_2 key: name key_len: 63 ref: NULL rows: 1 filtered: 100.00 Extra: Using index condition //使用了索引条件 ~~~ **注意,如果select的字段正好就是索引,那么会用到索引即索引覆盖。** ~~~ explain select name from t1 where name like '%ck'\G ~~~ 结果 ~~~ id: 1 select_type: SIMPLE table: t1 partitions: NULL type: index possible_keys: NULL key: name key_len: 63 ref: NULL rows: 1 filtered: 100.00 Extra: Using where; Using index ~~~