简体   繁体   中英

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) ?

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

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.)

Keep in mind the limitations of "word length" and "stop words" in FULLTEXT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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