MySQL索引正则表达式 [英] MySQL regexp on Indexes

查看:281
本文介绍了MySQL索引正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在where子句中有多个正则表达式的查询. where子句中包含的列已被索引. 但是查询未使用索引. MySql regexp会导致使用索引吗?如果没有,这可能是什么解决方法?

I have query having multiple regexp in where clause. The coloumns contained in the where clause have already been indexed. But the query is not using the indexes. Does MySql regexp cause use of indexes ? If not, what could be the workaround for this ?

推荐答案

不,正则表达式查找不能使用索引.如果您要应用正则表达式的东西是索引,它的运行速度可能会更快一些,但实际上您是在进行表扫描.

No, a regular expression lookup can't use an index. If the thing to which you're applying the regex is an index, it might go a bit faster, but you're essentially table scanning.

我知道的唯一解决方法是,如果这是您的正则表达式,请使用LIKE 'foo%'而不是RLIKE 'foo.*'.这样的列上的索引可以使用LIKE,但不能使用RLIKE

The only workaround I know is to use LIKE 'foo%' instead of RLIKE 'foo.*' if that's your regex. An index on such a column can use the LIKE but not the RLIKE

这篇关于MySQL索引正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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