Skip to content

Commit 23243c0

Browse files
Merge pull request #1297 from robgolebiowski/5.6-ps-bug1634932
Bug#1634932: Assertion failure in thread x in file fts0que.cc
2 parents 3dce315 + ef2c0bc commit 23243c0

15 files changed

Lines changed: 198 additions & 27 deletions

File tree

‎mysql-test/r/fulltext.result‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,10 @@ EXECUTE stmt;
689689
DEALLOCATE PREPARE stmt;
690690
DROP TABLE t1;
691691
End of 5.1 tests
692+
# Bug#21140111: Explain ... match against: Assertion failed: ret ...
693+
CREATE TABLE z(a INTEGER) engine=innodb;
694+
CREATE TABLE q(b TEXT CHARSET latin1, fulltext(b)) engine=innodb;
695+
explain format=json SELECT 1 FROM q
696+
WHERE (SELECT MATCH(b) AGAINST ('*') FROM z);
697+
ERROR HY000: Incorrect arguments to MATCH
698+
DROP TABLE z, q;
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= @@global.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= @@global.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;

‎mysql-test/t/fulltext.test‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,17 @@ DEALLOCATE PREPARE stmt;
632632
DROP TABLE t1;
633633

634634
--echo End of 5.1 tests
635+
636+
--echo # Bug#21140111: Explain ... match against: Assertion failed: ret ...
637+
638+
CREATE TABLE z(a INTEGER) engine=innodb;
639+
CREATE TABLE q(b TEXT CHARSET latin1, fulltext(b)) engine=innodb;
640+
641+
let $query=
642+
SELECT 1 FROM q
643+
WHERE (SELECT MATCH(b) AGAINST ('*') FROM z);
644+
645+
--error ER_WRONG_ARGUMENTS
646+
eval explain format=json $query;
647+
648+
DROP TABLE z, q;

‎sql/item_func.cc‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6239,7 +6239,16 @@ void Item_func_get_system_var::cleanup()
62396239
}
62406240

62416241

6242-
void Item_func_match::init_search(bool no_order)
6242+
/**
6243+
Initialize searching within full-text index.
6244+
6245+
@param thd Thread handler
6246+
@param no_order set if FT should not be sorted
6247+
6248+
@returns false if success, true if error
6249+
*/
6250+
6251+
bool Item_func_match::init_search(THD *thd, bool no_order)
62436252
{
62446253
DBUG_ENTER("Item_func_match::init_search");
62456254

@@ -6248,7 +6257,7 @@ void Item_func_match::init_search(bool no_order)
62486257
with fix_field
62496258
*/
62506259
if (!fixed)
6251-
DBUG_VOID_RETURN;
6260+
DBUG_RETURN(false);
62526261

62536262
/* Check if init_search() has been called before */
62546263
if (ft_handler)
@@ -6261,16 +6270,19 @@ void Item_func_match::init_search(bool no_order)
62616270
*/
62626271
if (join_key)
62636272
table->file->ft_handler= ft_handler;
6264-
DBUG_VOID_RETURN;
6273+
DBUG_RETURN(false);
62656274
}
62666275

62676276
if (key == NO_SUCH_KEY)
62686277
{
62696278
List<Item> fields;
6270-
fields.push_back(new Item_string(" ",1, cmp_collation.collation));
6279+
if (fields.push_back(new Item_string(" ",1, cmp_collation.collation)))
6280+
DBUG_RETURN(true);
62716281
for (uint i=1; i < arg_count; i++)
62726282
fields.push_back(args[i]);
62736283
concat_ws=new Item_func_concat_ws(fields);
6284+
if (concat_ws == NULL)
6285+
DBUG_RETURN(true);
62746286
/*
62756287
Above function used only to get value and do not need fix_fields for it:
62766288
Item_string - basic constant
@@ -6283,10 +6295,13 @@ void Item_func_match::init_search(bool no_order)
62836295
if (master)
62846296
{
62856297
join_key=master->join_key=join_key|master->join_key;
6286-
master->init_search(no_order);
6298+
if (master->init_search(thd, no_order))
6299+
DBUG_RETURN(true);
6300+
62876301
ft_handler=master->ft_handler;
62886302
join_key=master->join_key;
6289-
DBUG_VOID_RETURN;
6303+
6304+
DBUG_RETURN(false);
62906305
}
62916306

62926307
String *ft_tmp= 0;
@@ -6310,10 +6325,13 @@ void Item_func_match::init_search(bool no_order)
63106325
flags|=FT_SORTED;
63116326
ft_handler=table->file->ft_init_ext(flags, key, ft_tmp);
63126327

6328+
if (thd->is_error())
6329+
DBUG_RETURN(true);
6330+
63136331
if (join_key)
63146332
table->file->ft_handler=ft_handler;
63156333

6316-
DBUG_VOID_RETURN;
6334+
DBUG_RETURN(false);
63176335
}
63186336

63196337
/**

‎sql/item_func.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ class Item_func_match :public Item_real_func
18951895
virtual void print(String *str, enum_query_type query_type);
18961896

18971897
bool fix_index();
1898-
void init_search(bool no_order);
1898+
bool init_search(THD *thd, bool no_order);
18991899

19001900
/**
19011901
Get number of matching rows from FT handler.

‎sql/opt_sum.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ int opt_sum_query(THD *thd,
362362
!((Item_sum_count*) item)->get_arg(0)->maybe_null) // 4
363363
{
364364
Item_func_match* fts_item= static_cast<Item_func_match*>(conds);
365-
fts_item->init_search(true);
366-
if (thd->is_error())
365+
if (fts_item->init_search(thd, true))
367366
break;
368367
count= fts_item->get_count();
369368
}

‎sql/sql_base.cc‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9539,17 +9539,19 @@ int setup_ftfuncs(SELECT_LEX *select_lex)
95399539

95409540
int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
95419541
{
9542-
if (select_lex->ftfunc_list->elements)
9543-
{
9544-
List_iterator<Item_func_match> li(*(select_lex->ftfunc_list));
9545-
Item_func_match *ifm;
9546-
DBUG_PRINT("info",("Performing FULLTEXT search"));
9547-
THD_STAGE_INFO(thd, stage_fulltext_initialization);
9542+
DBUG_ASSERT(select_lex->has_ft_funcs());
9543+
9544+
List_iterator<Item_func_match> li(*(select_lex->ftfunc_list));
9545+
DBUG_PRINT("info",("Performing FULLTEXT search"));
9546+
THD_STAGE_INFO(thd, stage_fulltext_initialization);
95489547

9549-
while ((ifm=li++))
9550-
ifm->init_search(no_order);
9548+
Item_func_match *ifm;
9549+
while ((ifm= li++))
9550+
{
9551+
if (ifm->init_search(thd, no_order))
9552+
return true;
95519553
}
9552-
return 0;
9554+
return false;
95539555
}
95549556

95559557

‎sql/sql_delete.cc‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,18 @@ 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

330334
if (error)
331335
goto exit_without_my_ok;
332-
init_ftfuncs(thd, select_lex, 1);
336+
333337
THD_STAGE_INFO(thd, stage_updating);
334338

335339
if (table->triggers &&
@@ -763,7 +767,9 @@ multi_delete::initialize_tables(JOIN *join)
763767
table->file->ref_length,
764768
MEM_STRIP_BUF_SIZE);
765769
}
766-
init_ftfuncs(thd, thd->lex->current_select, 1);
770+
if (thd->lex->current_select->has_ft_funcs() && init_ftfuncs(thd, thd->lex->current_select, 1))
771+
DBUG_RETURN(true);
772+
767773
DBUG_RETURN(thd->is_fatal_error != 0);
768774
}
769775

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

0 commit comments

Comments
 (0)