美文网首页
MySQL如何提高text等类型的查询

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

作者: Shaun_lan | 来源:发表于2017-03-03 14:21 被阅读485次

①可以试着建立合成索引,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%';

相关文章

网友评论

      本文标题:MySQL如何提高text等类型的查询

      本文链接:https://www.haomeiwen.com/subject/ajxrgttx.html