Skip to content

Commit f439cfd

Browse files
committed
MDEV-22001: Server crashes in st_select_lex_unit::exclude_level upon execution of SP
Running some statements that use IN subqueries outside context of a regular query could result in server abnormal termination. The reason for failure is that internal structures SELECT_LEX/SELECT_LEX_UNIT created on behalf of parsed query were initialized incorrectly. Incorrect initialization of the structures SELECT_LEX/SELECT_LEX_UNIT was introduced by the commit de745ec (MDEV-11953: support of brackets in UNION/EXCEPT/INTERSECT operations) pushed into 10.4, that is the reason this bug report is not reproduced in 10.3. To fix the issue the method SLECTE_LEX::register_unit is used for proper initialization of the data structures SELECT_LEX/SELECT_LEX_UNIT. Additionally, the method SELECT_LEX::get_slave() was removed from the source code base since for those use cases where it is used it can be replaced by the method first_inner_unit().
1 parent 9a0cbd3 commit f439cfd

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

mysql-test/main/sp-bugs.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,13 @@ drop table _t1;
353353
#
354354
# End of 10.3 tests
355355
#
356+
#
357+
# MDEV-22001: Server crashes in st_select_lex_unit::exclude_level upon execution of SP
358+
#
359+
BEGIN NOT ATOMIC DECLARE a INT DEFAULT 0 IN ( SELECT 1 ) OR 2 ; END $
360+
BEGIN NOT ATOMIC DECLARE a INT DEFAULT 0 IN ( SELECT 1 ) OR (SELECT 2) ; END $
361+
KILL (('x' IN ( SELECT 1)) MOD 44);
362+
ERROR HY000: Unknown thread id: 0
363+
#
364+
# End of 10.4 tests
365+
#

mysql-test/main/sp-bugs.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,18 @@ drop table _t1;
371371
--echo #
372372
--echo # End of 10.3 tests
373373
--echo #
374+
375+
--echo #
376+
--echo # MDEV-22001: Server crashes in st_select_lex_unit::exclude_level upon execution of SP
377+
--echo #
378+
--delimiter $
379+
BEGIN NOT ATOMIC DECLARE a INT DEFAULT 0 IN ( SELECT 1 ) OR 2 ; END $
380+
BEGIN NOT ATOMIC DECLARE a INT DEFAULT 0 IN ( SELECT 1 ) OR (SELECT 2) ; END $
381+
--delimiter ;
382+
383+
--error ER_NO_SUCH_THREAD
384+
KILL (('x' IN ( SELECT 1)) MOD 44);
385+
386+
--echo #
387+
--echo # End of 10.4 tests
388+
--echo #

sql/sql_lex.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9684,11 +9684,13 @@ void LEX::relink_hack(st_select_lex *select_lex)
96849684
{
96859685
if (!select_stack_top) // Statements of the second type
96869686
{
9687-
if (!select_lex->get_master()->get_master())
9688-
((st_select_lex *) select_lex->get_master())->
9689-
set_master(&builtin_select);
9690-
if (!builtin_select.get_slave())
9691-
builtin_select.set_slave(select_lex->get_master());
9687+
if (!select_lex->outer_select() &&
9688+
!builtin_select.first_inner_unit())
9689+
{
9690+
builtin_select.register_unit(select_lex->master_unit(),
9691+
&builtin_select.context);
9692+
builtin_select.add_statistics(select_lex->master_unit());
9693+
}
96929694
}
96939695
}
96949696

sql/sql_lex.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ class st_select_lex_node {
738738
}
739739

740740
inline st_select_lex_node* get_master() { return master; }
741-
inline st_select_lex_node* get_slave() { return slave; }
742741
void include_down(st_select_lex_node *upper);
743742
void add_slave(st_select_lex_node *slave_arg);
744743
void include_neighbour(st_select_lex_node *before);

0 commit comments

Comments
 (0)