Skip to content

Commit feda5a9

Browse files
author
Sreeharsha Ramanavarapu
committed
Bug #22270139: SERVER CRASH WHEN TRYING TO COUNT THE
RESULTS OF A SUBQUERY USING FULLTEXT Issue: ----- These issues occur under the following conditions: 1) A derived table is merged into the outer query block. 2) The same match function is used in the select-list and where clause of the derived table. The following are the problem areas: a) When a select count(*) without group-by is used in the outer-query, opt_sum_query tries to set the hints for the where condition. This is not allowed since, hints for slave (i.e., the where condition) are not accessed. But this where condition already has a master that has been set by the setup_ftfuncs. The result is an assert. b) While merging the derived table into the outer query, the fulltext function list is rebuilt. Only this time, the order of the functions is flipped. This creates a problem when deciding who-is-who's master. Since setup_ftfuncs expects the early expression to be the master of the later expression. Because of this, the ft-functions in select and where lists are eachother's master. The result is a recursion of the get_master function. SOLUTION: --------- sql/opt_sum.cc: Since the where condition is supplied to the opt_sum_query by default, setting hints should be done on the master. sql/sql_resolver.cc: Since we want the early-late expression order to be maintained, use push_back. sql/item_func.h: In case of prepare-execute statements, we need to set the master variable to NULL. This will be reset when the execute statement will call setup_ftfuncs.
1 parent c55a234 commit feda5a9

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

sql/item_func.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,7 @@ class Item_func_match :public Item_real_func
23812381
ft_handler= NULL;
23822382
concat_ws= NULL;
23832383
table_ref= NULL; // required by Item_func_match::eq()
2384+
master= NULL;
23842385
DBUG_VOID_RETURN;
23852386
}
23862387
virtual Item *key_item() const { return against; }

sql/opt_sum.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ int opt_sum_query(THD *thd,
373373
!((Item_sum_count*) item)->get_arg(0)->maybe_null) // 4
374374
{
375375
Item_func_match* fts_item= static_cast<Item_func_match*>(conds);
376-
fts_item->set_hints(NULL, FT_NO_RANKING, HA_POS_ERROR, false);
376+
fts_item->get_master()->set_hints(NULL, FT_NO_RANKING,
377+
HA_POS_ERROR, false);
377378
if (fts_item->init_search(thd))
378379
break;
379380
count= fts_item->get_count();

sql/sql_resolver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2743,7 +2743,7 @@ bool SELECT_LEX::add_ftfunc_list(List<Item_func_match> *ftfuncs)
27432743
List_iterator_fast<Item_func_match> li(*ftfuncs);
27442744
while ((ifm= li++))
27452745
{
2746-
if (ftfunc_list->push_front(ifm))
2746+
if (ftfunc_list->push_back(ifm))
27472747
return true; /* purecov: inspected */
27482748
}
27492749
return false;

0 commit comments

Comments
 (0)