Skip to content

Commit c8c68b7

Browse files
Steinar H. Gundersondahlerlend
authored andcommitted
Bug #30277189: EXPLAIN ANALYZE + MULTI-TABLE JOIN = CRASH
Fix an assertion failure when doing EXPLAIN ANALYZE on a query that the iterator executor doesn't support. Change-Id: I10bb3d58afe49155bf06972afaeed5f6eb68f248
1 parent 7ade669 commit c8c68b7

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

mysql-test/r/explain_tree.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,23 @@ EXPLAIN
748748

749749
DROP TABLE t1;
750750
CREATE TABLE t1 (
751+
c1 INTEGER,
752+
c2 INTEGER
753+
);
754+
CREATE TABLE t2 (
755+
c1 INTEGER,
756+
c2 INTEGER
757+
);
758+
CREATE TABLE t3 (
759+
c1 INTEGER,
760+
c2 INTEGER
761+
);
762+
set optimizer_switch='block_nested_loop=on';
763+
EXPLAIN ANALYZE SELECT * FROM t1 JOIN t2 ON t1.c1 = t2.c2 JOIN t3 ON t2.c2 > t3.c2;
764+
ERROR 42000: This version of MySQL doesn't yet support 'EXPLAIN ANALYZE on this query'
765+
set optimizer_switch='block_nested_loop=off';
766+
DROP TABLE t1, t2, t3;
767+
CREATE TABLE t1 (
751768
b INTEGER,
752769
UNIQUE KEY ix1 (b)
753770
);

mysql-test/t/explain_tree.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,25 @@ EXPLAIN FORMAT=tree SELECT * FROM t1, ( SELECT f1 FROM t1 UNION ALL SELECT f1 +
428428

429429
DROP TABLE t1;
430430

431+
# EXPLAIN ANALYZE on a query the iterator executor doesn't support should give an error.
432+
CREATE TABLE t1 (
433+
c1 INTEGER,
434+
c2 INTEGER
435+
);
436+
CREATE TABLE t2 (
437+
c1 INTEGER,
438+
c2 INTEGER
439+
);
440+
CREATE TABLE t3 (
441+
c1 INTEGER,
442+
c2 INTEGER
443+
);
444+
set optimizer_switch='block_nested_loop=on';
445+
--error ER_NOT_SUPPORTED_YET
446+
EXPLAIN ANALYZE SELECT * FROM t1 JOIN t2 ON t1.c1 = t2.c2 JOIN t3 ON t2.c2 > t3.c2;
447+
set optimizer_switch='block_nested_loop=off';
448+
DROP TABLE t1, t2, t3;
449+
431450
#
432451
# Bug #30220791: INCORRECT RESULT WHEN THE ITERATOR EXECUTOR IS USED
433452
#

sql/opt_explain.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,13 @@ bool explain_query(THD *explain_thd, const THD *query_thd,
22052205
unit->set_executed();
22062206
return true;
22072207
}
2208+
if (unit->root_iterator() == nullptr) {
2209+
// TODO(sgunders): Remove when the iterator executor supports
2210+
// all queries.
2211+
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "EXPLAIN ANALYZE on this query");
2212+
unit->set_executed();
2213+
return true;
2214+
}
22082215

22092216
// Run the query, but with the result suppressed.
22102217
Query_result_null null_result;

0 commit comments

Comments
 (0)