# 索引失效的场景

1. like的模糊查询以%开头时索引会失效；
2. 应该尽量避免在where字句中使用！=或者<>操作符，否则存储引擎将放弃使用索引而进行全表扫描；
3. 应该尽量避免在where子句中用or来连接条件，否则索引失效；
4. 对于多列索引（联合索引），比如(A,B,C)，如果没有命中第一个（如B,C或者C），那索引失效；
5. 如果列的类型是字符串，那一定要在条件中将数据用引号引用起来，否则不会使用索引；
6. 应该避免在where字句中对字段进行表达式操作，比如select id from t where num/2=10；应该改为select id from t where num=100\*2；
7. 不能在where字句中对字段进行函数操作，否则索引失效；
8. 不要在where字句中的"="左边进行函数、算术运算符或其它表达式运算，否则索引失效；
9. 如果Mysql估计使用全表扫描要比使用索引快，则不用索引；
10. 不适用键值比较少的列（重复数据多的列）


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bing.gitbook.io/phper/data-base/my-sql/note/suo-yin-shi-xiao-de-chang-jing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
