Details
-
Bug
-
Status: In Review (View Workflow)
-
Critical
-
Resolution: Unresolved
-
11.4, 13.2
-
Any platform; reproduced with debug builds of 11.4.13 and main (13.2.0) on Linux
-
Unexpected results
-
A boolean mode fulltext search with an excluded phrase (-"...") on a MyISAM or Aria table no longer excludes rows that contain the words of the phrase in another order or not next to each other.
Description
CREATE TABLE t (id INT PRIMARY KEY, c TEXT, FULLTEXT(c)) ENGINE=MyISAM; |
INSERT INTO t VALUES (1, 'xxxx alpha beta'), (2, 'xxxx beta alpha'), |
(3, 'xxxx alpha gamma beta'), (4, 'xxxx'); |
SELECT id FROM t WHERE MATCH(c) AGAINST('+xxxx -"alpha beta"' IN BOOLEAN MODE); |
Expected: 2, 3, 4 (InnoDB returns these). Actual with MyISAM and Aria on 11.4 and main: 4. Rows 2 and 3 contain both words, but not the phrase "alpha beta". '+xxxx +"alpha beta"' correctly returns only row 1.
Only the search through the fulltext index is affected: with IGNORE INDEX (c), MyISAM and Aria return 2, 3, 4, and MATCH() in the select list is > 0 for rows 2, 3 and 4.
Cause: during the index search, _ftb_climb_the_tree() (storage/myisam/ft_boolean_search.c, the same in storage/maria/ma_ft_boolean_search.c) takes a phrase as matched as soon as all its words are in the row. It checks the phrase itself only when called from ft_boolean_find_relevance() (if (mode && ftbe->phrase)). For +"..." this is fine, because ft_boolean_read_next() rechecks every found row with ft_boolean_find_relevance(). For -"..." the row has already been rejected before that recheck.
MySQL has the same code, and the bug is reported there as https://bugs.mysql.com/bug.php?id=84036 (earlier https://bugs.mysql.com/bug.php?id=31755). The test cases there fail on MariaDB, too.
We ran into this with the ngram parser proposed in MDEV-10267, which turns each word of a boolean mode query into a phrase of its n-grams: '-abc' means -"ab bc", so it also excludes a row with 'bcab', which contains both n-grams but not abc.
Attachments
Issue Links
- relates to
-
MDEV-41771 MyISAM and Aria: wrong results for boolean mode searches with an exclusion inside a group
-
- Confirmed
-
-
MDEV-10267 Add "ngram" support to MariaDB
-
- In Review
-
- links to