Skip to content

Commit

Permalink
MDEV-30651: Assertion `sel->quick' in make_range_rowid_filters
Browse files Browse the repository at this point in the history
The optimizer deals with Rowid Filters this way:

1. First, range optimizer is invoked. It saves information
   about all potential range accesses.
2. A query plan is chosen. Suppose, it uses a Rowid Filter on
   index $IDX.
3. JOIN::make_range_rowid_filters() calls the range optimizer
again to create a quick select on index $IDX which will be used
to populate the rowid filter.

The problem: KILL command catches the query in step #3. Quick
Select is not created which causes a crash.

Fixed by checking if query was killed. Note: the problem also
affects 10.6, even if error handling for
SQL_SELECT::test_quick_select is different there.
  • Loading branch information
spetrunia committed Jun 17, 2024
1 parent b47bd3f commit a2066b2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
28 changes: 28 additions & 0 deletions mysql-test/include/rowid_filter_debug_kill.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,33 @@ disconnect con1;
reap;
set debug_sync='RESET';

--echo #
--echo # MDEV-30651: SIGSEGV in st_join_table::save_explain_data and
--echo # Assertion `sel->quick' failed in make_range_rowid_filters
--echo #

--echo # Reusing table t2 and t3 from previous test
let $target_id= `select connection_id()`;

set debug_sync='in_forced_range_optimize SIGNAL ready1 WAIT_FOR go1';
send
explain
select * from t2, t3
where
t3.key1=t2.a and t3.key2 in (2,3);

connect (con1, localhost, root,,);
set debug_sync='now WAIT_FOR ready1';
evalp kill query $target_id;
set debug_sync='now SIGNAL go1';

connection default;
disconnect con1;

--error ER_QUERY_INTERRUPTED
reap;
set debug_sync='RESET';


drop table t2,t3;
--source include/wait_until_count_sessions.inc
18 changes: 18 additions & 0 deletions mysql-test/main/rowid_filter_innodb_debug.result
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,23 @@ connection default;
disconnect con1;
ERROR 70100: Query execution was interrupted
set debug_sync='RESET';
#
# MDEV-30651: SIGSEGV in st_join_table::save_explain_data and
# Assertion `sel->quick' failed in make_range_rowid_filters
#
# Reusing table t2 and t3 from previous test
set debug_sync='in_forced_range_optimize SIGNAL ready1 WAIT_FOR go1';
explain
select * from t2, t3
where
t3.key1=t2.a and t3.key2 in (2,3);
connect con1, localhost, root,,;
set debug_sync='now WAIT_FOR ready1';
kill query $target_id;
set debug_sync='now SIGNAL go1';
connection default;
disconnect con1;
ERROR 70100: Query execution was interrupted
set debug_sync='RESET';
drop table t2,t3;
set default_storage_engine=default;
18 changes: 18 additions & 0 deletions mysql-test/main/rowid_filter_myisam_debug.result
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,22 @@ connection default;
disconnect con1;
ERROR 70100: Query execution was interrupted
set debug_sync='RESET';
#
# MDEV-30651: SIGSEGV in st_join_table::save_explain_data and
# Assertion `sel->quick' failed in make_range_rowid_filters
#
# Reusing table t2 and t3 from previous test
set debug_sync='in_forced_range_optimize SIGNAL ready1 WAIT_FOR go1';
explain
select * from t2, t3
where
t3.key1=t2.a and t3.key2 in (2,3);
connect con1, localhost, root,,;
set debug_sync='now WAIT_FOR ready1';
kill query $target_id;
set debug_sync='now SIGNAL go1';
connection default;
disconnect con1;
ERROR 70100: Query execution was interrupted
set debug_sync='RESET';
drop table t2,t3;
3 changes: 3 additions & 0 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,10 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
only_single_index_range_scan= 1;

if (head->force_index || force_quick_range)
{
DEBUG_SYNC(thd, "in_forced_range_optimize");
scan_time= read_time= DBL_MAX;
}
else
{
scan_time= rows2double(records) / TIME_FOR_COMPARE;
Expand Down
13 changes: 8 additions & 5 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,9 @@ int JOIN::optimize()
object a pointer to which is set in the field JOIN_TAB::rowid_filter of
the joined table.

@retval false always
@retval
false OK
true Error, query should abort
*/

bool JOIN::make_range_rowid_filters()
Expand Down Expand Up @@ -1830,8 +1832,11 @@ bool JOIN::make_range_rowid_filters()
(ha_rows) HA_POS_ERROR,
true, false, true, true);
tab->table->force_index= force_index_save;
if (thd->is_error())
goto no_filter;
if (thd->is_error() || thd->check_killed())
{
delete sel;
DBUG_RETURN(true);
}
/*
If SUBS_IN_TO_EXISTS strtrategy is chosen for the subquery then
additional conditions are injected into WHERE/ON/HAVING and it may
Expand All @@ -1855,8 +1860,6 @@ bool JOIN::make_range_rowid_filters()
continue;
}
no_filter:
if (sel->quick)
delete sel->quick;
delete sel;
}

Expand Down

0 comments on commit a2066b2

Please sign in to comment.