[英]mySQL - Regexp or LIKE in multiple search?
This script searches multiple keywords. 该脚本搜索多个关键字。
SELECT ID,SURNAME FROM people where name='john'
and SURNAME REGEXP 'search1|search2|search3'
ORDER BY id DESC
However, I have heard that regexp has lower performance and never use indexes. 但是,我听说regexp性能较低,并且从不使用索引。 Is there a better/faster way to do the same ?
是否有更好/更快的方法可以做到这一点?
it depends a lot on the size of your dataset and the surname column. 这很大程度上取决于数据集和姓氏列的大小。 it also depends on how many surnames you end up including in your search.
这还取决于您最终在搜索中包括多少个姓氏。
I suggest testing it with a few different search terms and seeing if this is faster: 我建议使用一些不同的搜索词对其进行测试,看看是否更快:
SELECT ID,SURNAME FROM people where name='john'
and (SURNAME LIKE '%search1%' OR SURNAME LIKE '%search2%' OR SURNAME LIKE '%search3%')
ORDER BY id DESC
note that if your search only needs a wildcard at the end, you can use 'search1%' instead of '%search1%' which should be faster 请注意,如果您的搜索最后只需要通配符,则可以使用“ search1%”而不是“%search1%”,这样做应该更快
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.