简体   繁体   English

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

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

I have this query: 我有这个查询:

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

How to create effective indexes if is_active is TINYINT field and titles are VARCHAR(255) ? 如果is_active是TINYINT字段并且标题是VARCHAR(255),如何创建有效索引?

And what about this query: 那这个查询呢:

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

if description field is text? 如果描述字段是文本?

use full text index for each column. 对每一列使用全文索引。 If use in query "or" use seperately fts index, if use "and" mix fts index (in one index use several column) Full Text Index 如果在查询“或”中使用,则单独使用fts索引,如果在“或”中使用,则混合fts索引(在一个索引中使用几列) 全文本索引

FULLTEXT(title, title_en)

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

(This should work for either InnoDB (5.6+) or MyISAM.) (这适用于InnoDB(5.6+)或MyISAM。)

Keep in mind the limitations of "word length" and "stop words" in FULLTEXT. 请记住FULLTEXT中“单词长度”和“停用词”的限制。

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

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