Mysql 使用通配符提高搜索性能 (%%)
以下是我用于通过电子邮件搜索某人的查询
Below is a query I use for searching a person by email
SELECT *
FROM phppos_customers
JOIN phppos_people ON phppos_customers.person_id = phppos_people.person_id
WHERE deleted = 0
AND email LIKE '%f%'
ORDER BY email ASC
在email"上添加索引会加快查询速度吗?
Will adding an index on "email" speed up the query?
推荐答案
否,因为当您有前导通配符时,MySQL 将无法使用索引.如果您将 LIKE 更改为 'f%',那么它就可以使用索引了.
No, because MySQL will not be able to utilize the index when you have a leading wildcard. If you changed your LIKE to 'f%', then it would be able to use the index.
相关文章