Skip to content

Commit e85f501

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 7574258 commit e85f501

5 files changed

Lines changed: 121 additions & 3 deletions

File tree

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

‎sql/sql_executor.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ JOIN::exec()
116116
if (prepare_result(&columns_list))
117117
DBUG_VOID_RETURN;
118118

119-
if (select_lex->materialized_table_count)
119+
if (select_lex->materialized_table_count && select_lex->has_ft_funcs())
120120
init_ftfuncs(thd, select_lex, order);
121121

122122
if (!tables_list && (tables || !select_lex->with_sum_func))

‎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)