Mysql 使用通配符提高搜索性能 (%%) [英] Mysql Improve Search Performance with wildcards (%%)

查看:33
本文介绍了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.

这篇关于Mysql 使用通配符提高搜索性能 (%%)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆