Skip to content

Commit a1811e2

Browse files
author
Robert Golebiowski
committed
Bug#1634932/83648: Assertion failure in thread x in file fts0que.cc
The bug was caused by three problems: 1) query->intersection was not freed in case of error caused by exceeding innodb_ft_result_cache_limit. 2) errors from init_ftfuncs were not propagated - this was fixed in 5.7 by bug fix 21140111. This was ported into 5.6 3) bug fix 21140111 was causing assertion failure when innodb_ft_result_cache was exceeded in DELETE command. This was also fixed.
1 parent ea345cd commit a1811e2

4 files changed

Lines changed: 117 additions & 2 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Bug 1634932: Assertion failure in thread x in
3+
# file fts0que.cc
4+
#
5+
CREATE TABLE `t1` (
6+
`FTS_DOC_ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
7+
`text_content` MEDIUMTEXT, PRIMARY KEY (`FTS_DOC_ID`)
8+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
9+
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX ON t1(FTS_DOC_ID);
10+
SET autocommit=0;
11+
CREATE PROCEDURE populate_t1()
12+
BEGIN
13+
DECLARE i INT DEFAULT 1;
14+
WHILE (i <= 250) DO
15+
INSERT INTO t1 (text_content) VALUES ("some_text_1234 aaa");
16+
SET i = i + 1;
17+
END WHILE;
18+
END//
19+
CALL populate_t1;
20+
SET autocommit=1;
21+
SET SESSION debug="+d,fts_instrument_result_cache_limit";
22+
ALTER TABLE t1 ADD FULLTEXT INDEX `text_content_idx` (`text_content`);
23+
SELECT FTS_DOC_ID, text_content
24+
FROM t1
25+
WHERE MATCH text_content AGAINST ('+some_text_1234' IN BOOLEAN MODE);
26+
ERROR HY000: FTS query exceeds result cache limit
27+
UPDATE t1
28+
SET text_content='some_text_12345'
29+
where MATCH text_content AGAINST ('+some_text_1234' IN BOOLEAN MODE);
30+
ERROR HY000: FTS query exceeds result cache limit
31+
DELETE FROM t1
32+
WHERE MATCH text_content AGAINST ('+some_text_1234' IN BOOLEAN MODE);
33+
ERROR HY000: FTS query exceeds result cache limit
34+
SET GLOBAL innodb_ft_result_cache_limit=default;
35+
DROP TABLE t1;
36+
DROP PROCEDURE populate_t1;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--echo #
2+
--echo # Bug 1634932: Assertion failure in thread x in
3+
--echo # file fts0que.cc
4+
--echo #
5+
6+
--source include/have_innodb.inc
7+
--source include/have_debug.inc
8+
9+
CREATE TABLE `t1` (
10+
`FTS_DOC_ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
11+
`text_content` MEDIUMTEXT, PRIMARY KEY (`FTS_DOC_ID`)
12+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
13+
14+
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX ON t1(FTS_DOC_ID);
15+
16+
SET autocommit=0;
17+
18+
DELIMITER //;
19+
CREATE PROCEDURE populate_t1()
20+
BEGIN
21+
DECLARE i INT DEFAULT 1;
22+
WHILE (i <= 250) DO
23+
INSERT INTO t1 (text_content) VALUES ("some_text_1234 aaa");
24+
SET i = i + 1;
25+
END WHILE;
26+
END//
27+
28+
DELIMITER ;//
29+
30+
CALL populate_t1;
31+
SET autocommit=1;
32+
33+
SET SESSION debug="+d,fts_instrument_result_cache_limit";
34+
35+
ALTER TABLE t1 ADD FULLTEXT INDEX `text_content_idx` (`text_content`);
36+
37+
# HA_ERR_FTS_EXCEED_RESULT_CACHE_LIMIT = 188
38+
--error 188
39+
SELECT FTS_DOC_ID, text_content
40+
FROM t1
41+
WHERE MATCH text_content AGAINST ('+some_text_1234' IN BOOLEAN MODE);
42+
43+
--error 188
44+
UPDATE t1
45+
SET text_content='some_text_12345'
46+
where MATCH text_content AGAINST ('+some_text_1234' IN BOOLEAN MODE);
47+
48+
--error 188
49+
DELETE FROM t1
50+
WHERE MATCH text_content AGAINST ('+some_text_1234' IN BOOLEAN MODE);
51+
52+
SET GLOBAL innodb_ft_result_cache_limit=default;
53+
54+
DROP TABLE t1;
55+
DROP PROCEDURE populate_t1;

‎sql/sql_delete.cc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,16 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, Item *conds,
322322
table->file->print_error(error, MYF(0));
323323
goto exit_without_my_ok;
324324
}
325+
326+
if (select_lex->has_ft_funcs() && init_ftfuncs(thd, select_lex, 1))
327+
goto exit_without_my_ok;
328+
325329
if (usable_index==MAX_KEY || (select && select->quick))
326330
error= init_read_record(&info, thd, table, select, 1, 1, FALSE);
327331
else
328332
error= init_read_record_idx(&info, thd, table, 1, usable_index, reverse);
329333

330-
if (error || (select_lex->has_ft_funcs() && init_ftfuncs(thd, select_lex, 1)))
334+
if (error)
331335
goto exit_without_my_ok;
332336

333337
THD_STAGE_INFO(thd, stage_updating);

‎storage/innobase/fts/fts0que.cc‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,18 @@ fts_query_free_doc_ids(
953953
query->total_size -= SIZEOF_RBT_CREATE;
954954
}
955955

956+
/**
957+
Free the query intersection
958+
@param[in] query query instance */
959+
static
960+
void
961+
fts_query_free_intersection(
962+
fts_query_t* query)
963+
{
964+
fts_query_free_doc_ids(query, query->intersection);
965+
query->intersection = NULL;
966+
}
967+
956968
/*******************************************************************//**
957969
Add the word to the documents "list" of matching words from
958970
the query. We make a copy of the word from the query heap. */
@@ -1311,6 +1323,7 @@ fts_query_intersect(
13111323
/* error is passed by 'query->error' */
13121324
if (query->error != DB_SUCCESS) {
13131325
ut_ad(query->error == DB_FTS_EXCEED_RESULT_CACHE_LIMIT);
1326+
fts_query_free_intersection(query);
13141327
return(query->error);
13151328
}
13161329

@@ -1339,7 +1352,9 @@ fts_query_intersect(
13391352

13401353
ut_a(!query->multi_exist || (query->multi_exist
13411354
&& rbt_size(query->doc_ids) <= n_doc_ids));
1342-
}
1355+
} else if (query->intersection != NULL) {
1356+
fts_query_free_intersection(query);
1357+
}
13431358
}
13441359

13451360
return(query->error);
@@ -1557,6 +1572,11 @@ fts_merge_doc_ids(
15571572
query, ranking->doc_id, ranking->rank);
15581573

15591574
if (query->error != DB_SUCCESS) {
1575+
if (query->intersection != NULL)
1576+
{
1577+
ut_a(query->oper == FTS_EXIST);
1578+
fts_query_free_intersection(query);
1579+
}
15601580
DBUG_RETURN(query->error);
15611581
}
15621582

0 commit comments

Comments
 (0)