diff options
author | Monty <monty@mariadb.org> | 2023-03-01 19:59:42 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2023-03-02 13:11:54 +0200 |
commit | ae0509771462c02149e294f8f8593d6ff10755f7 (patch) | |
tree | 401534c7241f30fa04b91a12d2bfd7982ed124a6 /mysql-test/suite | |
parent | bc3596fe129dc12977522243f92202609e06fdab (diff) | |
download | mariadb-git-ae0509771462c02149e294f8f8593d6ff10755f7.tar.gz |
Fixed crashing bug in recursive SQL if write to tmp table would fail
This error was discovered while working on
MDEV-30540 Wrong result with IN list length reaching
IN_PREDICATE_CONVERSION_THRESHOLD
If there is read error from handler::ha_rnd_next() during a recursive
query, st_select_lex_unit::exec_recursive() will crash as it will try to
get the error code from a structure that was deleted by the callee.
The code was using the construct:
sl->join->exec();
saved_error=sl->join->error;
This does not work as sl->join was freed by the exec() and sl->join would
be set to 0.
Fixed by having JOIN::exec() return the error code.
The included test case simulates the error in ha_rnd_next(), which causes
a crash without the patch.
scovered whle working on
MDEV-30540 Wrong result with IN list length reaching
IN_PREDICATE_CONVERSION_THRESHOLD
If there is read error from handler::ha_rnd_next() during a recursive
query, st_select_lex_unit::exec_recursive() will crash as it will try to
get the error code from a structure that was deleted by the callee.
The code was using the construct:
sl->join->exec();
saved_error=sl->join->error;
This does not work as sl->join was freed by the exec() and sl->join was
set to 0.
Fixed by having JOIN::exec() return the error code.
The included test case simulates the error in ha_rnd_next(), which causes
a crash without the patch.
Diffstat (limited to 'mysql-test/suite')
-rw-r--r-- | mysql-test/suite/maria/crash-recursive.result | 53 | ||||
-rw-r--r-- | mysql-test/suite/maria/crash-recursive.test | 67 |
2 files changed, 120 insertions, 0 deletions
diff --git a/mysql-test/suite/maria/crash-recursive.result b/mysql-test/suite/maria/crash-recursive.result new file mode 100644 index 00000000000..998bb9e501b --- /dev/null +++ b/mysql-test/suite/maria/crash-recursive.result @@ -0,0 +1,53 @@ +set @save_big_tables=@@big_tables; +set big_tables=1; +Warnings: +Warning 1287 '@@big_tables' is deprecated and will be removed in a future release +create table folks(id int, name char(32), dob date, father int, mother int); +insert into folks values +(100, 'Me', '2000-01-01', 20, 30), +(20, 'Dad', '1970-02-02', 10, 9), +(30, 'Mom', '1975-03-03', 8, 7), +(10, 'Grandpa Bill', '1940-04-05', null, null), +(9, 'Grandma Ann', '1941-10-15', null, null), +(25, 'Uncle Jim', '1968-11-18', 8, 7), +(98, 'Sister Amy', '2001-06-20', 20, 30), +(7, 'Grandma Sally', '1943-08-23', null, 6), +(8, 'Grandpa Ben', '1940-10-21', null, null), +(6, 'Grandgrandma Martha', '1923-05-17', null, null), +(67, 'Cousin Eddie', '1992-02-28', 25, 27), +(27, 'Auntie Melinda', '1971-03-29', null, null); +call mtr.add_suppression(".*marked as crashed.*"); +SET @saved_dbug= @@SESSION.debug_dbug; +SET SESSION debug_dbug="+d,ha_rnd_next_error"; +SET @ha_rnd_next_error_counter=110; +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, +w_id, w_name, w_dob, w_father, w_mother) +as +( +select h.*, w.* +from folks h, folks w, coupled_ancestors a +where a.father = h.id AND a.mother = w.id +union +select h.*, w.* +from folks v, folks h, folks w +where v.name = 'Me' and +(v.father = h.id AND v.mother= w.id) +), +coupled_ancestors (id, name, dob, father, mother) +as +( +select h_id, h_name, h_dob, h_father, h_mother +from ancestor_couples +union +select w_id, w_name, w_dob, w_father, w_mother +from ancestor_couples +) +select h_name, h_dob, w_name, w_dob +from ancestor_couples; +ERROR HY000: Table '(temporary)' is marked as crashed and should be repaired +drop table folks; +set big_tables=@save_big_tables; +Warnings: +Warning 1287 '@@big_tables' is deprecated and will be removed in a future release +SET @@SESSION.debug_dbug=@saved_dbug; diff --git a/mysql-test/suite/maria/crash-recursive.test b/mysql-test/suite/maria/crash-recursive.test new file mode 100644 index 00000000000..1fa18ce85c0 --- /dev/null +++ b/mysql-test/suite/maria/crash-recursive.test @@ -0,0 +1,67 @@ +# +# This test simulates an error in an aria file discovered during a recursive SQL call. +# The error handling causes used join structures to be deleted, which caused crashes in +# upper levels when trying to access structures that does not exist anymore +# + +--source include/have_debug_sync.inc +--source include/not_embedded.inc + +set @save_big_tables=@@big_tables; +set big_tables=1; + +create table folks(id int, name char(32), dob date, father int, mother int); + +insert into folks values +(100, 'Me', '2000-01-01', 20, 30), +(20, 'Dad', '1970-02-02', 10, 9), +(30, 'Mom', '1975-03-03', 8, 7), +(10, 'Grandpa Bill', '1940-04-05', null, null), +(9, 'Grandma Ann', '1941-10-15', null, null), +(25, 'Uncle Jim', '1968-11-18', 8, 7), +(98, 'Sister Amy', '2001-06-20', 20, 30), +(7, 'Grandma Sally', '1943-08-23', null, 6), +(8, 'Grandpa Ben', '1940-10-21', null, null), +(6, 'Grandgrandma Martha', '1923-05-17', null, null), +(67, 'Cousin Eddie', '1992-02-28', 25, 27), +(27, 'Auntie Melinda', '1971-03-29', null, null); + + +call mtr.add_suppression(".*marked as crashed.*"); +SET @saved_dbug= @@SESSION.debug_dbug; +SET SESSION debug_dbug="+d,ha_rnd_next_error"; +SET @ha_rnd_next_error_counter=110; + +let q= +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, + w_id, w_name, w_dob, w_father, w_mother) +as +( + select h.*, w.* + from folks h, folks w, coupled_ancestors a + where a.father = h.id AND a.mother = w.id + union + select h.*, w.* + from folks v, folks h, folks w + where v.name = 'Me' and + (v.father = h.id AND v.mother= w.id) +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select h_id, h_name, h_dob, h_father, h_mother + from ancestor_couples + union + select w_id, w_name, w_dob, w_father, w_mother + from ancestor_couples +) +select h_name, h_dob, w_name, w_dob + from ancestor_couples; + +--error ER_CRASHED_ON_USAGE +eval $q; +drop table folks; + +set big_tables=@save_big_tables; +SET @@SESSION.debug_dbug=@saved_dbug;
\ No newline at end of file |