Skip to content

Commit 1173882

Browse files
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
1 parent 207c857 commit 1173882

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

mysql-test/main/explain.result

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,43 @@ id select_type table type possible_keys key key_len ref rows Extra
459459
NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL
460460
Warnings:
461461
Note 1249 Select 4 was reduced during optimization
462+
#
463+
# End of 10.4 tests
464+
#
465+
CREATE TABLE t1 (a INT);
466+
INSERT INTO t1 VALUES (1),(2);
467+
CREATE TABLE t2 (b INT);
468+
INSERT INTO t2 VALUES (3),(4);
469+
EXPLAIN SELECT * FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
470+
id select_type table type possible_keys key key_len ref rows Extra
471+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
472+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
473+
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
474+
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
475+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
476+
EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
477+
id select_type table type possible_keys key key_len ref rows Extra
478+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
479+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
480+
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
481+
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
482+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
483+
prepare stmt from "EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6)";
484+
execute stmt;
485+
id select_type table type possible_keys key key_len ref rows Extra
486+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
487+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
488+
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
489+
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
490+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
491+
execute stmt;
492+
id select_type table type possible_keys key key_len ref rows Extra
493+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
494+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
495+
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
496+
3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
497+
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
498+
DROP TABLE t1, t2;
499+
#
500+
# End of 10.5 tests
501+
#

mysql-test/main/explain.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,26 @@ drop table t1;
370370

371371
explain
372372
VALUES ( (VALUES (2))) UNION VALUES ( (SELECT 3));
373+
374+
--echo #
375+
--echo # End of 10.4 tests
376+
--echo #
377+
378+
CREATE TABLE t1 (a INT);
379+
INSERT INTO t1 VALUES (1),(2);
380+
CREATE TABLE t2 (b INT);
381+
INSERT INTO t2 VALUES (3),(4);
382+
383+
EXPLAIN SELECT * FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
384+
EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6);
385+
prepare stmt from "EXPLAIN DELETE t2 FROM t1, t2 WHERE t2.b IN (SELECT 5 UNION SELECT 6)";
386+
execute stmt;
387+
execute stmt;
388+
389+
# Cleanup
390+
391+
DROP TABLE t1, t2;
392+
393+
--echo #
394+
--echo # End of 10.5 tests
395+
--echo #

sql/sql_select.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27953,7 +27953,6 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
2795327953
bool distinct,const char *message)
2795427954
{
2795527955
THD *thd=join->thd;
27956-
select_result *result=join->result;
2795727956
DBUG_ENTER("select_describe");
2795827957

2795927958
if (join->select_lex->pushdown_select)
@@ -27988,7 +27987,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
2798827987

2798927988
if (unit->explainable())
2799027989
{
27991-
if (mysql_explain_union(thd, unit, result))
27990+
if (mysql_explain_union(thd, unit, unit->result))
2799227991
DBUG_VOID_RETURN;
2799327992
}
2799427993
}

0 commit comments

Comments
 (0)