I'm trying to find a solution for this, with no success.
I have a table with ~2M rows, and I need to do a WHERE with 3 expressions using OR.
name LIKE '%PARAM%' OR text1 LIKE '%PARAM%' OR text2 LIKE '%PARAM%' ORDER BY views DESC
name is a varchar
text1 and text2 are longtext (~6000 characters each)
text1 and text2 are indexed FULLTEXT
name is indexed BTREE, views too.
The table is MyISAM, it don't have many updates, but many selects;
The query takes ~12sec to complete.
Sorry if this question arleady exists, but I could not found this.
Thank u
Best Answer
Each run of this query will scan the whole table for two reasons:
name
will not be used as the value starts with a wild char%
fulltext
index on the other two fields.Proposed solution:
fulltext
index onname
fieldmatch
: https://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html#function_matchNotice: Depending on your version of MySQL, using
OR
to combine conditions could be a performance hit. It is not the case in 5.6 +