不区分大小写的搜索无需附加规则?
我试图在 MySQL 中找到一种排序规则(我的版本是 5.0),其中大小写不同的字符串被认为是相同的,但没有其他规则,例如:
á = a
等。
我试图在这里找到正确的排序规则: http://www.collation-charts .org/mysql60/by-charset.html 但似乎我正在寻找的排序规则不存在。
我不能在 SQL 查询中使用: SELECT ... WHERE lower(column1) = lower(column2) 因为当时不使用列 column1 和 column2 上的索引,而且我的查询速度非常慢。
感谢您的任何建议!
I'm trying to find a collation in MySQL (my version is 5.0) where strings that differ in case are considered the same but there're no other rules like:
á = a
and so on.
I tried to find the proper collation here: http://www.collation-charts.org/mysql60/by-charset.html but it seems that the collation I'm looking for doesn't exist.
I can't use in SQL query: SELECT ... WHERE lower(column1) = lower(column2) because indices on columns column1 and column2 are not used then and my query is terrible slow.
Thanks for any suggestion!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我得到了一个建议:只需有这样的表:id,word,word_in_lowercase..数据确实是多余的,但除此之外它满足了我的所有需求。
word_in_lowercase 的自动更新可以通过触发器或一些附加编程来完成。
I was given an advice: simply have table like this: id, word, word_in_lowercase.. it's true that data are redundant but otherwise it fulfils all my needs.
Automatic update of word_in_lowercase may be done via trigger or some additional programming.
相关表中设置了哪种类型的排序规则? 我目前正在使用很多带有
utf8_hungarian_ci
的表,因为这个表不区分大小写。Which type of collation set in the tables that in question? I'm currently using a lot of tables with
utf8_hungarian_ci
because of this one is case-insensitive.http://dev.mysql.com/doc/refman/ 5.0/en/case-sensitivity.html 表示非二进制字符串默认不区分大小写。 您是否测试过不使用 lower() 就无法正常工作?
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html indicates that nonbinary strings are case insensitive by default. Have you tested to see that it is not working properly without using lower()?
为什么不使用 MySQL 的全文搜索功能来进行搜索查询呢?
对于像您这样的任务,我使用 MATCH AGAINST 功能。
请阅读 mysql.com 上的规范以使其清楚 - 链接< /a>
一个例子:
这将不区分大小写地执行。
Why don't you use the full text search functions of MySQL for your search query?
For tasks like yours I am using the MATCH AGAINST function.
Read the Specifications at mysql.com to make it clear - Link
One example:
And this will be executed case insensitive.