Slow MySQL full text search

CecilLynn

New Member
I'm using this query to perform a full text search on a MySQL database:\[code\]SELECT DISTINCT questions.id, questions.uniquecode, questions.spam,questions.questiondate,questions.userid,questions.description,users.login AS username,questions.questiontext,questions.totalvotes,MATCH(questions.questiontext, questions.uniquecode) AGAINST ('rock guitarist chick*' IN BOOLEAN MODE) AS relevance FROM questions LEFT JOIN users ON questions.userid = users.id LEFT JOIN answer_mapping ON questions.id = answer_mapping.questionid LEFT JOIN answers ON answer_mapping.answerid = answers.idLEFT JOIN tagmapping ON questions.id = tagmapping.questionidLEFT JOIN tags ON tagmapping.tagid = tags.id WHERE questions.spam < 10 AND ( MATCH(questions.questiontext, questions.uniquecode) AGAINST ('rock guitarist chick*' IN BOOLEAN MODE) OR MATCH(answers.answertext) AGAINST ('rock guitarist chick*' IN BOOLEAN MODE) OR MATCH (tags.tag) AGAINST ('rock guitarist chick*' IN BOOLEAN MODE)) GROUP BY questions.id ORDER BY relevance DESC\[/code\]The results are very relevant, but the search is really slow and is getting slower and slower as the tables grow.Table stats: questions - 400 records indexes
  • PRIMARY BTREE - id
  • BTREE - uniquecode
  • BTREE - questiondate
  • BTREE - userid
  • FULLTEXT - questiontext
  • FULLTEXT - uniquecode
answers - 3,635 recordsindexes
  • PRIMARY - BTREE - id
  • BTREE - answerdate
  • BTREE - questionid
  • FULLTEXT - answertext
answer_mapping - 4,228 recordsindexes
  • PRIMARY - BTREE - id
  • BTREE - answerid
  • BTREE - questionid
  • BTREE - userid
tags - 1,847 recordsindexes
  • PRIMARY - BTREE - id
  • BTREE - tag
  • FULLTEXT - tag
tagmapping - 3,389 recordsindexes
  • PRIMARY - BTREE - id
  • BTREE - tagid
  • BTREE - questionid
For whatever reason when I remove the tagmapping and tags JOINS the search speeds up considerably. Do you have any tips on how to speed this query up? Thanks in advance!
 
Back
Top