Timothée HENRY
Timothée HENRY

Reputation: 14614

How to optimize MySQL query to find substring among three fields?

I have the following MySQL table fields:

description1, description2, description3: Varchar(500)

value: int

and wish to find the records where at least one of the description includes the string searched by the user. Right now I am using the following query. It works, but it takes about 1.5 second to return the results.

SELECT `table`.`value`, 
      `table`.`description1`, 
      `table`.`description2`, 
      `table`.`description3`
      FROM `table`
WHERE ( `table`.`description1` LIKE '%string%'
OR `table`.`description2` LIKE '%string%'
OR `table`.`description3` LIKE '%string%' )
ORDER BY  `table`.`value` DESC LIMIT 0 , 9

Is there any way to get the results faster?

(Note that the value field is already indexed).

Upvotes: 1

Views: 714

Answers (1)

cetver
cetver

Reputation: 11839

add full text index and instead like use AGAINST

Upvotes: 1

Related Questions