0

根据我现在正在运行的查询,我认为这是一个白日梦:

我在包含字符串 id 的列上有一个索引。这些 ID 最后有一个标识符,所以要捕获我需要的数据,我需要像这样进行模式匹配:

key LIKE '%racecar'

由于您不能利用通配符开始字符串的索引,我希望我能做到这一点:

reverse(key) LIKE 'racecar%'

但是,这意味着 MySQL 必须查看并在每一行上执行一个函数,对吗?除了更改命名约定之外,还有其他解决此问题的方法吗?

4

1 回答 1

0

This smells like bad DB design. Split the string and the id into two separate columns and the problem(and many other problems) will be automatically solved.

I also doubt the order of the string and the id will make difference to MYSQL with respect to performance.

Also keep in mind you have an index over key, but this does not mean you have an index over the reverse of key which is the reason you get no speedup at all. I believe that given the situation the performance is beyond salvation.

于 2013-03-08T15:55:38.867 回答