我是靠谱客的博主 整齐樱桃,最近开发中收集的这篇文章主要介绍mysql like 后缀,mysql:后缀搜索的有效方法(例如'%text'aka前缀通配符)?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Is there any build-in functionality in MySQL to do the above without scanning the entire table?

Only solution I found is to store a mirrored version of the column I want to compare and do a like 'txet%'.

I also don't see a way of getting around the postfix-search. It is for a German dictionary. Many words have a version with prefix, e.g. the user searches for "Gericht" (Engl. curt), but it is also valuable to know that there is a word "Amtsgericht" (Engl. district curt). Unfortunately often there is no space separating the two parts of the word in German language. Approx 15% of queries actually use the prefix-search.

解决方案

A index over reverse field will be the solution, some think like:

create index idx_reverse on table ( reverse( field ) );

select * from table where reverse(field) like 'txet%';

but MySQL don't alow index over expressions, only over columns:

CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name

[index_type]

ON tbl_name (index_col_name,...)

[index_option] ...

CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] name ON table [ USING method ]

( { column | ( expression ) } [ opclass ] [, ...] )

...

A work around may be create indexed second field (field -> dleif) and a mysql trigger to keep reversed field:

alter table my_table add column dleif ...;

create index idx_reverse on my_table ( dleif );

Create Trigger `reverse_field` Before Update on `my_table` for each row BEGIN

set new.dleif = reverse( new.field );

END;

select * from table where dleif like reverse('%text');

最后

以上就是整齐樱桃为你收集整理的mysql like 后缀,mysql:后缀搜索的有效方法(例如'%text'aka前缀通配符)?的全部内容,希望文章能够帮你解决mysql like 后缀,mysql:后缀搜索的有效方法(例如'%text'aka前缀通配符)?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部