繁体   English   中英

什么是为下面的查询创建索引的最佳方法

[英]What's is the best way to create indexes for the query below

我有这个查询:

select * from `metro_stations`
where `is_active` = 1
  and (`title` like '%search%' or `title_en` like '%search%')

如果is_active是TINYINT字段并且标题是VARCHAR(255),如何创建有效索引?

那这个查询呢:

select * from `metro_stations`
where `is_active` = 1
 and (`title` like '%search%' or
      `title_en` like '%search%' or
      `description` like '%search%')

如果描述字段是文本?

对每一列使用全文索引。 如果在查询“或”中使用,则单独使用fts索引,如果在“或”中使用,则混合fts索引(在一个索引中使用几列) 全文本索引

FULLTEXT(title, title_en)

WHERE is_active = 1
  AND MATCH(title, title_en) AGAINST ("+search" IN BOOLEAN MODE)

(这适用于InnoDB(5.6+)或MyISAM。)

请记住FULLTEXT中“单词长度”和“停用词”的限制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM