BUG#29445 - match ... against () never returns

Part 2:
Searching fulltext index for a word with boolean mode truncation
operator may cause infinite loop.

The problem was that "smarter index merge" was used with "trunc-words",
which must never happen.

Affects 5.1 only.
This commit is contained in:
svoj@mysql.com/april.(none) 2007-07-13 03:25:27 +05:00
parent 859304f708
commit e11d75e45b
3 changed files with 14 additions and 4 deletions

View File

@ -485,7 +485,10 @@ INSERT INTO t1 VALUES('Offside'),('City Of God');
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE); SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE);
a a
City Of God City Of God
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of)*' IN BOOLEAN MODE); SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of*)' IN BOOLEAN MODE);
a
City Of God
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city* of*' IN BOOLEAN MODE);
a a
City Of God City Of God
DROP TABLE t1; DROP TABLE t1;

View File

@ -414,7 +414,8 @@ DROP TABLE t1;
CREATE TABLE t1(a VARCHAR(20), FULLTEXT(a)); CREATE TABLE t1(a VARCHAR(20), FULLTEXT(a));
INSERT INTO t1 VALUES('Offside'),('City Of God'); INSERT INTO t1 VALUES('Offside'),('City Of God');
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE); SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE);
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of)*' IN BOOLEAN MODE); SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of*)' IN BOOLEAN MODE);
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city* of*' IN BOOLEAN MODE);
DROP TABLE t1; DROP TABLE t1;
# End of 4.1 tests # End of 4.1 tests

View File

@ -23,6 +23,12 @@
inside plus subtree. max_docid could be used by any word in plus inside plus subtree. max_docid could be used by any word in plus
subtree, but it could be updated by plus-word only. subtree, but it could be updated by plus-word only.
Fulltext "smarter index merge" optimization assumes that rows
it gets are ordered by doc_id. That is not the case when we
search for a word with truncation operator. It may return
rows in random order. Thus we may not use "smarter index merge"
optimization with "trunc-words".
The idea is: there is no need to search for docid smaller than The idea is: there is no need to search for docid smaller than
biggest docid inside current plus subtree or any upper plus subtree. biggest docid inside current plus subtree or any upper plus subtree.
@ -443,7 +449,7 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search)
memcpy(lastkey_buf+off, info->lastkey, info->lastkey_length); memcpy(lastkey_buf+off, info->lastkey, info->lastkey_length);
} }
ftbw->docid[0]=info->lastpos; ftbw->docid[0]=info->lastpos;
if (ftbw->flags & FTB_FLAG_YES) if (ftbw->flags & FTB_FLAG_YES && !(ftbw->flags & FTB_FLAG_TRUNC))
ftbw->max_docid_expr->max_docid= info->lastpos; ftbw->max_docid_expr->max_docid= info->lastpos;
return 0; return 0;
} }
@ -488,7 +494,7 @@ static void _ftb_init_index_search(FT_INFO *ftb)
{ {
if (ftbe->flags & FTB_FLAG_NO || /* 2 */ if (ftbe->flags & FTB_FLAG_NO || /* 2 */
ftbe->up->ythresh - ftbe->up->yweaks > ftbe->up->ythresh - ftbe->up->yweaks >
test(ftbe->flags & FTB_FLAG_YES)) /* 1 */ (uint) test(ftbe->flags & FTB_FLAG_YES)) /* 1 */
{ {
FTB_EXPR *top_ftbe=ftbe->up; FTB_EXPR *top_ftbe=ftbe->up;
ftbw->docid[0]=HA_OFFSET_ERROR; ftbw->docid[0]=HA_OFFSET_ERROR;