Commit 11738822 authored by Rex's avatar Rex Committed by Rex Johnston

MDEV-33165 Incorrect result interceptor passed to mysql_explain_union()

Statements affect by this bug are all SQL statements that
1) prefixed with "EXPLAIN"
2) have a lower level join structure created for a union subquery.

A bug in select_describe() passed an incorrect "result" object to
mysql_explain_union(), resulting in unpredictable behaviour and
out of context calls.

Reviewed by: Oleksandr Byelkin, sanja@mariadb.com
parent 207c8578
...@@ -459,3 +459,43 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -459,3 +459,43 @@ id select_type table type possible_keys key key_len ref rows Extra
NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1249 Select 4 was reduced during optimization Note 1249 Select 4 was reduced during optimization
#
# End of 10.4 tests
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (3),(4);
EXPLAIN SELECT * FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
prepare stmt from "EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6)";
execute stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
execute stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
DROP TABLE t1, t2;
#
# End of 10.5 tests
#
...@@ -370,3 +370,26 @@ drop table t1; ...@@ -370,3 +370,26 @@ drop table t1;
explain explain
VALUES ( (VALUES (2))) UNION VALUES ( (SELECT 3)); VALUES ( (VALUES (2))) UNION VALUES ( (SELECT 3));
--echo #
--echo # End of 10.4 tests
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (3),(4);
EXPLAIN SELECT * FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
prepare stmt from "EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6)";
execute stmt;
execute stmt;
# Cleanup
DROP TABLE t1, t2;
--echo #
--echo # End of 10.5 tests
--echo #
...@@ -27953,7 +27953,6 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, ...@@ -27953,7 +27953,6 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
bool distinct,const char *message) bool distinct,const char *message)
{ {
THD *thd=join->thd; THD *thd=join->thd;
select_result *result=join->result;
DBUG_ENTER("select_describe"); DBUG_ENTER("select_describe");
if (join->select_lex->pushdown_select) if (join->select_lex->pushdown_select)
...@@ -27988,7 +27987,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, ...@@ -27988,7 +27987,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
if (unit->explainable()) if (unit->explainable())
{ {
if (mysql_explain_union(thd, unit, result)) if (mysql_explain_union(thd, unit, unit->result))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
} }
......
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