revision-id: c2c1550f57bf61e60b778dc889be132cca176ff3 (mariadb-10.3.10-27-gc2c1550) parent(s): 97a37edc970f8619ffd23394b61fe310d705d0ef author: Igor Babaev committer: Igor Babaev timestamp: 2018-10-17 04:37:25 -0700 message: MDEV-17419 Subquery with group by returns wrong results Added only test case because the bug was fixed by the patch for mdev-17382. --- mysql-test/main/derived_cond_pushdown.result | 40 +++++++++++++++++++++++++++ mysql-test/main/derived_cond_pushdown.test | 41 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 51a4703..b6ebc4e 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -16448,3 +16448,43 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 /* select#1 */ select `test`.`t3`.`d` AS `d`,`dt`.`b` AS `b`,`dt`.`c` AS `c` from `test`.`t3` join (/* select#2 */ select `test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`b` = `test`.`t3`.`d` group by `test`.`t1`.`b`,`test`.`t2`.`c`) `dt` where `dt`.`b` = `test`.`t3`.`d` DROP TABLE t1,t2,t3; +# +# MDEV-17419: splittable materialized derived/view +# when join_cache_level = 4 +# +set join_cache_level = 4; +CREATE TABLE t1 ( +id INT UNSIGNED NOT NULL AUTO_INCREMENT, +username VARCHAR(50) NULL DEFAULT '0', +PRIMARY KEY (id) +) COLLATE='utf8_general_ci'; +CREATE TABLE t2 ( +id INT UNSIGNED NOT NULL AUTO_INCREMENT, +userid INT UNSIGNED NOT NULL, +logindate DATETIME NOT NULL, +PRIMARY KEY (id) +) COLLATE='utf8_general_ci'; +INSERT INTO t1 (id, username) VALUES +(1,"user1"), (2, "user2"); +INSERT INTO t2 (id, userid, logindate) VALUES +(1,1,"2015-06-19 12:17:02.828"), +(2,1,"2016-06-19 12:17:02.828"), +(3,2,"2017-06-19 12:17:02.828"), +(4,2,"2018-06-19 12:17:02.828"); +EXPLAIN select * from t1 as u +left join +(select * from t2 as au group by au.userid) as auditlastlogin +on u.id=auditlastlogin.userid; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY u ALL NULL NULL NULL NULL 2 +1 PRIMARY <derived2> ref key0 key0 5 test.u.id 2 +2 DERIVED au ALL NULL NULL NULL NULL 4 Using temporary; Using filesort +select * from t1 as u +left join +(select * from t2 as au group by au.userid) as auditlastlogin +on u.id=auditlastlogin.userid; +id username id userid logindate +1 user1 1 1 2015-06-19 12:17:02 +2 user2 3 2 2017-06-19 12:17:02 +set join_cache_level=default; +DROP TABLE t1,t2; diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 61541d2..1de1e8a 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -3143,3 +3143,44 @@ eval $q; eval EXPLAIN EXTENDED $q; DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-17419: splittable materialized derived/view +--echo # when join_cache_level = 4 +--echo # + +set join_cache_level = 4; + +CREATE TABLE t1 ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT, + username VARCHAR(50) NULL DEFAULT '0', + PRIMARY KEY (id) +) COLLATE='utf8_general_ci'; + +CREATE TABLE t2 ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT, + userid INT UNSIGNED NOT NULL, + logindate DATETIME NOT NULL, + PRIMARY KEY (id) +) COLLATE='utf8_general_ci'; + +INSERT INTO t1 (id, username) VALUES + (1,"user1"), (2, "user2"); +INSERT INTO t2 (id, userid, logindate) VALUES + (1,1,"2015-06-19 12:17:02.828"), + (2,1,"2016-06-19 12:17:02.828"), + (3,2,"2017-06-19 12:17:02.828"), + (4,2,"2018-06-19 12:17:02.828"); + +let $q= +select * from t1 as u + left join + (select * from t2 as au group by au.userid) as auditlastlogin + on u.id=auditlastlogin.userid; + +eval EXPLAIN $q; +eval $q; + +set join_cache_level=default; + +DROP TABLE t1,t2;