Using MySQL 5.6, this request
SELECT foo
FROM bar
WHERE groupId = '1'
AND MATCH (foo) AGAINST ('"myQuery"' IN BOOLEAN MODE);
and
SELECT foo
FROM bar
WHERE groupId = '1'
AND foo like '%myQuery%';
returns both correct results, but when I combine the two with:
SELECT foo
FROM bar
WHERE groupId = '1'
AND (
MATCH (foo) AGAINST ('"myQuery"' IN BOOLEAN MODE)
OR foo LIKE '%myQuery%'
);
I got some extra results, which do not appear in any of the first two requests, and didn't contain myQuery
at all.
Is there any trick with the parenthesis that I missed?
Or could it be related to any sort of index cache? Sometimes the results are correct, and suddenly, there are not anymore.
I also tried with
WHERE (
groupId = '1' AND MATCH (foo) AGAINST ('"myQuery"' IN BOOLEAN MODE)
) OR (
groupId = '1' AND foo like '%myQuery%'
);
Edit: here are the results of my requests, with myQuery = 'gold'
.
The 1st and 2nd one returns:
'Fancy gold'
'Nice gold'
'Super Nice gold'
'Ugly gold'
The last one returns:
'Cornices diamond'
'Custom'
'Fancy gold'
'Nice gold'
'Super Nice gold'
'Ugly gold'
One other thing I noticed, I ran Optimize table bar
, and then results are correct. I ran again 1st request again, and then the 3rd results are not correct anymore. So I really suspect something related to the full-text index.
Edit 2: Here is a dbFiddle : https://www.db-fiddle.com/f/iSXdTK7EzfoQ46RgDX7wF3/1