summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/main/explain_innodb.result20
-rw-r--r--mysql-test/main/explain_innodb.test20
-rw-r--r--sql/sql_select.cc8
3 files changed, 48 insertions, 0 deletions
diff --git a/mysql-test/main/explain_innodb.result b/mysql-test/main/explain_innodb.result
new file mode 100644
index 00000000000..fe51e45e35d
--- /dev/null
+++ b/mysql-test/main/explain_innodb.result
@@ -0,0 +1,20 @@
+#
+# MDEV-26249: Crash in in Explain_node::print_explain_for_children while writing to the slow query log
+#
+set @sql_tmp=@@slow_query_log;
+SET GLOBAL slow_query_log = 1;
+SET long_query_time = 0.000000;
+SET log_slow_verbosity = 'explain';
+CREATE TABLE t1 ( id varchar(50), KEY (id)) engine=innodb;
+SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0;
+id
+select 1;
+1
+1
+explain
+SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+2 DERIVED t1 index NULL id 53 NULL 1 Using index
+SET GLOBAL slow_query_log = @sql_tmp;
+drop table t1;
diff --git a/mysql-test/main/explain_innodb.test b/mysql-test/main/explain_innodb.test
new file mode 100644
index 00000000000..2c29a6e26da
--- /dev/null
+++ b/mysql-test/main/explain_innodb.test
@@ -0,0 +1,20 @@
+--echo #
+--echo # MDEV-26249: Crash in in Explain_node::print_explain_for_children while writing to the slow query log
+--echo #
+
+--source include/have_innodb.inc
+
+set @sql_tmp=@@slow_query_log;
+SET GLOBAL slow_query_log = 1;
+SET long_query_time = 0.000000;
+SET log_slow_verbosity = 'explain';
+
+CREATE TABLE t1 ( id varchar(50), KEY (id)) engine=innodb;
+SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0;
+select 1;
+
+explain
+SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0;
+
+SET GLOBAL slow_query_log = @sql_tmp;
+drop table t1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 40ecc45df45..93e1c0ccba8 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2732,6 +2732,14 @@ setup_subq_exit:
}
if (make_aggr_tables_info())
DBUG_RETURN(1);
+
+ /*
+ It could be that we've only done optimization stage 1 for
+ some of the derived tables, and never did stage 2.
+ Do it now, otherwise Explain data structure will not be complete.
+ */
+ if (select_lex->handle_derived(thd->lex, DT_OPTIMIZE))
+ DBUG_RETURN(1);
}
/*
Even with zero matching rows, subqueries in the HAVING clause may