简体   繁体   中英

MySql FullText Search seems slow, How can I make this faster? Any Optimization required?

I have a table with 1 million records and want to apply faster way to fetch record against any search query. As I am bad with mysql fulltext search.

I made following tests:

  • Initially I applied MATCH AGAINS on single column it return result fast.
  • Secondly I applied MATCH AGAINS on two columns and return very slow.
  • Then I made column optimization and combined two columns into one and applied MATCH AGAINS on computed column. It returns very slow on first time but reasonably fast on second attempt with same search term.

Is there any issue with my query how I should amend this with more optimization?

 select name, meaning, m.gender, m.similar
        FROM
        NAMES n
        INNER JOIN meta m ON m.nameid = n.id
        WHERE MATCH (nameandmeaning) AGAINST ('searchterm*' IN BOOLEAN MODE) 
        AND meaning IS NOT NULL
        ORDER BY LENGTH(m.similar) DESC
        LIMIT 0 , 10;

Note: nameandmeaning is combinition of name, meaning .

My Table Structure is as follow:

CREATE TABLE NAMES (
  id BIGINT(20) NOT NULL AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  meaning VARCHAR(2000) DEFAULT NULL,
  nameandmeaning VARCHAR(2000) DEFAULT NULL,
  PRIMARY KEY  (id),
  FULLTEXT KEY constains_name(name,meaning),
  FULLTEXT KEY contains_namemeaing (nameandmeaning)
) ENGINE=MYISAM AUTO_INCREMENT=67846 DEFAULT CHARSET=latin1;
CREATE TABLE NAMES (
  id BIGINT(20) NOT NULL AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  meaning VARCHAR(2000) DEFAULT NULL,
  -- skip this:  nameandmeaning VARCHAR(2000) DEFAULT NULL,
  PRIMARY KEY  (id),
  FULLTEXT KEY constains_name(name, meaning),
  -- skip this:  FULLTEXT KEY contains_namemeaing (nameandmeaning)
) ENGINE=MYISAM AUTO_INCREMENT=67846 DEFAULT CHARSET=latin1;

Then these should work fast:

MATCH(name) AGAINST (...)
MATCH(meaning) AGAINST (...)
MATCH(name, meaning) AGAINST (...)

When you upgrade to InnoDB, you should have all 3 of these (if you are doing all 3 of those MATCHes):

  FULLTEXT (name),
  FULLTEXT (meaning),
  FULLTEXT (name, meaning)

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