[Commits] c600523: MDEV-10729: Server crashes in st_select_lex::set_explain_type

Sergei Petrunia psergey at askmonty.org
Wed Sep 7 17:09:29 EEST 2016


revision-id: c6005238d43cd752069a2b3feafab99238203578
parent(s): e305054f3119a403cfc4a8a69a5f3d947ee23532
committer: Sergei Petrunia
branch nick: 10.2
timestamp: 2016-09-07 17:09:29 +0300
message:

MDEV-10729: Server crashes in st_select_lex::set_explain_type

Make the new (CTE-related) code in set_explain_type to take into
account that some JOIN_TABs are non-merged semi-joins, and do not
have a TABLE object.

---
 mysql-test/r/cte_nonrecursive.result |   15 +++++++++++++++
 mysql-test/t/cte_nonrecursive.test   |   18 ++++++++++++++++++
 sql/sql_lex.cc                       |    2 +-
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result
index 690355c..7c758c3 100644
--- a/mysql-test/r/cte_nonrecursive.result
+++ b/mysql-test/r/cte_nonrecursive.result
@@ -880,3 +880,18 @@ id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
 1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (flat, BNL join)
 DROP TABLE t1,t2,t3;
+#
+# MDEV-10729: Server crashes in st_select_lex::set_explain_type
+#
+CREATE TABLE t1 (i1 INT, KEY(i1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4),(8);
+CREATE TABLE t2 (a2 INT, b2 INT, KEY(b2)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8,7);
+CREATE TABLE t3 (i3 INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (2),(6);
+SELECT * FROM t1, t2 WHERE a2 = i1 and b2 >= i1 AND i1 IN ( SELECT i3 FROM t3 )
+UNION
+SELECT * FROM t1, t2 WHERE a2 = i1 and b2 >= i1 AND i1 IN ( SELECT i3 FROM t3 )
+;
+i1	a2	b2
+DROP TABLE t1,t2,t3;
diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test
index 435364b..ccd0894 100644
--- a/mysql-test/t/cte_nonrecursive.test
+++ b/mysql-test/t/cte_nonrecursive.test
@@ -558,3 +558,21 @@ INSERT INTO t3 VALUES (1),(2),(3);
 EXPLAIN SELECT * FROM (WITH a AS (SELECT * FROM t1) (t2 NATURAL JOIN t3));
 explain SELECT * FROM (WITH a AS (SELECT * FROM t1) SELECT * FROM t2 NATURAL JOIN t3) AS d1;
 DROP TABLE t1,t2,t3;
+
+--echo #
+--echo # MDEV-10729: Server crashes in st_select_lex::set_explain_type
+--echo #
+CREATE TABLE t1 (i1 INT, KEY(i1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (4),(8);
+                        
+CREATE TABLE t2 (a2 INT, b2 INT, KEY(b2)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (8,7);
+            
+CREATE TABLE t3 (i3 INT) ENGINE=MyISAM;
+INSERT INTO t3 VALUES (2),(6);
+ 
+SELECT * FROM t1, t2 WHERE a2 = i1 and b2 >= i1 AND i1 IN ( SELECT i3 FROM t3 )
+UNION
+SELECT * FROM t1, t2 WHERE a2 = i1 and b2 >= i1 AND i1 IN ( SELECT i3 FROM t3 )
+;
+DROP TABLE t1,t2,t3;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index a22d296..8830f2d 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -4370,7 +4370,7 @@ void st_select_lex::set_explain_type(bool on_the_fly)
           for (JOIN_TAB *tab= first_explain_order_tab(join); tab;
                tab= next_explain_order_tab(join, tab))
           {
-            if (tab->table->pos_in_table_list->with)
+            if (tab->table && tab->table->pos_in_table_list->with)
             {
               uses_cte= true;
               break;


More information about the commits mailing list