diff options
author | Oleg Smirnov <olernov@gmail.com> | 2022-07-06 16:00:12 +0400 |
---|---|---|
committer | Oleg Smirnov <olernov@gmail.com> | 2022-07-13 21:07:10 +0700 |
commit | ffc335251bab3687823ee2beae1b45f4ea71019a (patch) | |
tree | 4b52bd233d0f51fdb8c0876fff216ad1310d4cbc | |
parent | f332260c9872a428f68e0461329bb5fa29461592 (diff) | |
download | mariadb-git-ffc335251bab3687823ee2beae1b45f4ea71019a.tar.gz |
MDEV-28881 Server crash in Dep_analysis_context::create_table_value
SELECT_LEX::first_select()->join is NULL for degenerate derived tables
which are known to have just one row and so were already materialized
by the optimizer.
This commit adds a check for this.
-rw-r--r-- | mysql-test/main/table_elim.result | 18 | ||||
-rw-r--r-- | mysql-test/main/table_elim.test | 19 | ||||
-rw-r--r-- | sql/opt_table_elimination.cc | 9 |
3 files changed, 44 insertions, 2 deletions
diff --git a/mysql-test/main/table_elim.result b/mysql-test/main/table_elim.result index 4f648f45895..35098b10822 100644 --- a/mysql-test/main/table_elim.result +++ b/mysql-test/main/table_elim.result @@ -985,3 +985,21 @@ drop table t1, t11, t12, t13, t2; # # End of MDEV-26278: Table elimination does not work across derived tables # +# +# MDEV-28881: Server crashes in Dep_analysis_context::create_table_value/ +# check_func_dependency +# +CREATE TABLE t1 (a1 int, a2 int); +INSERT INTO t1 VALUES (0,276),(5,277),(NULL,278); +CREATE TABLE t2 ( a1 int, a2 int, KEY a2 (a2)); +INSERT INTO t2 VALUES (11,NULL),(185,0); +SELECT t1.* FROM t1 LEFT JOIN +( SELECT * FROM (SELECT t2.a1 AS a1, min(t2.a2) AS a2 FROM t2 +WHERE t2.a2 <> NULL +GROUP BY t2.a1) dt +) dt2 ON dt2.a2 = t1.a2; +a1 a2 +0 276 +5 277 +NULL 278 +DROP TABLE t1, t2; diff --git a/mysql-test/main/table_elim.test b/mysql-test/main/table_elim.test index a1f7ef91522..9b98c4688f2 100644 --- a/mysql-test/main/table_elim.test +++ b/mysql-test/main/table_elim.test @@ -759,3 +759,22 @@ drop table t1, t11, t12, t13, t2; --echo # --echo # End of MDEV-26278: Table elimination does not work across derived tables --echo # + +--echo # +--echo # MDEV-28881: Server crashes in Dep_analysis_context::create_table_value/ +--echo # check_func_dependency +--echo # + +CREATE TABLE t1 (a1 int, a2 int); +INSERT INTO t1 VALUES (0,276),(5,277),(NULL,278); + +CREATE TABLE t2 ( a1 int, a2 int, KEY a2 (a2)); +INSERT INTO t2 VALUES (11,NULL),(185,0); + +SELECT t1.* FROM t1 LEFT JOIN + ( SELECT * FROM (SELECT t2.a1 AS a1, min(t2.a2) AS a2 FROM t2 + WHERE t2.a2 <> NULL + GROUP BY t2.a1) dt + ) dt2 ON dt2.a2 = t1.a2; + +DROP TABLE t1, t2;
\ No newline at end of file diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index cb8ebe9c167..53a99166168 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1720,9 +1720,14 @@ void Dep_analysis_context::create_unique_pseudo_key_if_needed( /* GROUP BY expression is considered as a unique pseudo-key - for the derived table. Add this pseudo key as a dependency + for the derived table. Add this pseudo key as a dependency. + + first_select->join is NULL for degenerate derived tables + which are known to have just one row and so were already materialized + by the optimizer, check this here */ - if (first_select && first_select->group_list.elements > 0) + if (first_select && first_select->join && + first_select->group_list.elements > 0) { bool valid= true; std::set<field_index_t> exposed_fields_indexes; |