Question

I have a problem with the query:

Select * From table Where MATCH(col1) AGAINST('mystring' IN BOOLEAN MODE) OR MATCH(col2) AGAINST('mystring' IN BOOLEAN MODE)

because it is not using the fulltext index, as the query:

Select * From table Where MATCH(col1) AGAINST('mystring' IN BOOLEAN MODE) AND MATCH(col2) AGAINST('mystring' IN BOOLEAN MODE)

does.

Both col1 and col2 has a fulltext index, but when using OR instead of AND, mysql performs a full table search instead of using one of the indexes.

How can I select records with (at least) one of the 2 columns matching 'mystring' using indexes?

Was it helpful?

Solution

Just try to select each set by isolated query (with only one filter) and than intersect results with UNION.
Another form:

SELECT * FROM table WHERE MATCH (col1, col2) AGAINST ('mystring' IN BOOLEAN MODE)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top