Commit c03d50fc authored by Oleg Smirnov's avatar Oleg Smirnov

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.
parent 7f0201a2
......@@ -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;
......@@ -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
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment