[英]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.