diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2021-04-12 15:46:23 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2021-04-12 15:59:23 +0200 |
commit | 68e0defc5be41e42f5f9d050a436a5f88277a586 (patch) | |
tree | 5148887c09c3a63b28b3f926b7ed7d5be62a61fc /mysql-test/t/derived_opt.test | |
parent | f8bf2a0170b385bbba8f9f8dc97841f58229d39a (diff) | |
download | mariadb-git-bb-10.2-MDEV-25182.tar.gz |
MDEV-25182 Complex query in Store procedure corrupts resultsbb-10.2-MDEV-25182
At the second execution of the PS
1. mark_as_dependent() is called with the same parameters as at the first
execution (select#4 and select#3)
2. as outer_select (select#3) has been already merged at the first
execution of PS it cannot be reached using the outer_select() function
anymore (and so can not stop iteration).
3. as a result all selects towards the top level select including the
select for 'ca' are marked as uncacheable.
4. Marked uncacheable it executed incorrectly triggering filling its
temporary table several times and using freed memory at the end.
To avoid the problem we use name resolution context to go "up".
NOTE: problem also exists in 10.2 but has no visible effect on execution.
That is why the problem is fixed in 10.2.
The patch also add debug logging of important procedures and
better specify parameters types of st_select_lex::mark_as_dependent.
Diffstat (limited to 'mysql-test/t/derived_opt.test')
-rw-r--r-- | mysql-test/t/derived_opt.test | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/mysql-test/t/derived_opt.test b/mysql-test/t/derived_opt.test index aab95f69f26..305cac120a0 100644 --- a/mysql-test/t/derived_opt.test +++ b/mysql-test/t/derived_opt.test @@ -401,5 +401,38 @@ set join_cache_level=default; DROP TABLE t1,t2; +# +# MDEV-25182: Complex query in Store procedure corrupts results +# +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch="derived_merge=on"; + +CREATE TABLE t1 (id int, d2 datetime, id1 int) ; +insert into t1 values (1,'2020-01-01 10:10:10',1),(2,'2020-01-01 10:10:10',2),(3,'2020-01-01 10:10:10',3); + +CREATE TABLE t2 (id int, d1 datetime, id1 int) ; +insert into t2 values (1,'2020-01-01 10:10:10',1),(2,'2020-01-01 10:10:10',2),(3,'2020-01-01 10:10:10',2); + +prepare stmt from " +SELECT * from + (SELECT min(d2) AS d2, min(d1) AS d1 FROM + (SELECT t1.d2 AS d2, (SELECT t2.d1 + FROM t2 WHERE t1.id1 = t2.id1 + ORDER BY t2.id DESC LIMIT 1) AS d1 + FROM t1 + ) dt2 + ) ca + ORDER BY ca.d2;"; + +execute stmt; +execute stmt; + +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1, t2; + +--echo # +--echo # End of 10.3 tests +--echo # + # The following command must be the last one the file set optimizer_switch=@exit_optimizer_switch; |