MySQL如何提高text等类型的查询

2017-03-03  本文已影响485人  Shaun_lan

①可以试着建立合成索引,context text所在表再加一列:hash_index varchar(50) 专门存储context的hash值。这样在查询context的值时就可以使用hash后的值跟 hash_index进行比较就可以了。但是要注意这种查询只适合精确匹配。

举例:

原数据库表为:

create table table_name {

      id int ,

      context text

};

更改为:

create table  table_name{

     id int,

    context text,

    hash_index varchar(50)

}

②如果是想对进行模糊查询,则可以建立前缀索引。

create index prefix_index on table_name (context(6));

6表示要匹配的context的前6个字符,6字符后的可以进行模糊查询了。

例如:select * from table_name where context like 'abcdef%';

上一篇 下一篇

猜你喜欢

热点阅读