summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Didriksen <tor.didriksen@oracle.com>2011-03-24 11:27:11 +0100
committerTor Didriksen <tor.didriksen@oracle.com>2011-03-24 11:27:11 +0100
commite57beba62dadd21c698a58cc805d0d3e2bd09451 (patch)
tree0995f2f971509550f444815e4701b16dc5617be2
parent9d32caa13d47a23fb6bbb6eefd8c76b7eac9d8ad (diff)
downloadmariadb-git-e57beba62dadd21c698a58cc805d0d3e2bd09451.tar.gz
Bug#11829785 EXPLAIN EXTENDED CRASH WITH RIGHT OUTER JOIN, SUBQUERIES
This is a backport of Bug #46860 Crash/segfault using EXPLAIN EXTENDED on query using UNION in subquery. mysql-test/r/explain.result: Remove the extended Note, since explain returns error. New test case. mysql-test/r/func_gconcat.result: Remove the extended Note, since explain returns error. mysql-test/r/subselect3.result: Remove the extended Note, since explain returns error. mysql-test/t/explain.test: New test case. sql/sql_parse.cc: Skip the extended description if we have an error.
-rw-r--r--mysql-test/r/explain.result15
-rw-r--r--mysql-test/r/func_gconcat.result1
-rw-r--r--mysql-test/r/subselect3.result3
-rw-r--r--mysql-test/t/explain.test23
-rw-r--r--sql/sql_parse.cc6
5 files changed, 41 insertions, 7 deletions
diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result
index b9ae362f6cd..b8f791b27f4 100644
--- a/mysql-test/r/explain.result
+++ b/mysql-test/r/explain.result
@@ -180,7 +180,6 @@ ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP col
SHOW WARNINGS;
Level Code Message
Error 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
-Note 1003 select 1 AS `1` from `test`.`t1` where <not>(<exists>(...))
SET SESSION sql_mode=@old_sql_mode;
DROP TABLE t1;
End of 5.0 tests.
@@ -318,3 +317,17 @@ id select_type table type possible_keys key key_len ref rows Extra
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
End of 5.1 tests.
+#
+# Bug#11829785 EXPLAIN EXTENDED CRASH WITH RIGHT OUTER JOIN, SUBQUERIES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0), (0);
+PREPARE s FROM
+'EXPLAIN EXTENDED
+SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
+FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
+EXECUTE s;
+ERROR 21000: Subquery returns more than 1 row
+DEALLOCATE PREPARE s;
+DROP TABLE t1;
+#
diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result
index 01b93df6894..6c400a8ddcc 100644
--- a/mysql-test/r/func_gconcat.result
+++ b/mysql-test/r/func_gconcat.result
@@ -1056,7 +1056,6 @@ ERROR HY000: Only constant XPATH queries are supported
SHOW WARNINGS;
Level Code Message
Error 1105 Only constant XPATH queries are supported
-Note 1003 select updatexml('1',`test`.`t1`.`a`,'1') AS `UPDATEXML('1', a, '1')` from `test`.`t1` order by (select group_concat(1 separator ',') from `test`.`t1`)
DROP TABLE t1;
End of 5.1 tests
DROP TABLE IF EXISTS t1, t2;
diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result
index 2962a12d9a2..4e18a81b534 100644
--- a/mysql-test/r/subselect3.result
+++ b/mysql-test/r/subselect3.result
@@ -865,9 +865,6 @@ Level Code Message
Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
Note 1276 Field or reference 'test.t1.c' of SELECT #3 was resolved in SELECT #2
Error 1054 Unknown column 'c' in 'field list'
-Note 1003 select `c` AS `c` from (select (select count(`test`.`t1`.`a`) from dual group by `c`) AS `(SELECT COUNT(a) FROM
-(SELECT COUNT(b) FROM t1) AS x GROUP BY c
-)` from `test`.`t1` group by `test`.`t1`.`b`) `y`
DROP TABLE t1;
End of 5.0 tests
create table t0 (a int);
diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test
index 931948b1b65..8376fdf1ad1 100644
--- a/mysql-test/t/explain.test
+++ b/mysql-test/t/explain.test
@@ -1,5 +1,5 @@
#
-# Test of different EXPLAIN's
+# Test of different EXPLAINs
--disable_warnings
drop table if exists t1;
@@ -275,3 +275,24 @@ DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo End of 5.1 tests.
+
+--echo #
+--echo # Bug#11829785 EXPLAIN EXTENDED CRASH WITH RIGHT OUTER JOIN, SUBQUERIES
+--echo #
+
+CREATE TABLE t1(a INT);
+
+INSERT INTO t1 VALUES (0), (0);
+
+PREPARE s FROM
+'EXPLAIN EXTENDED
+SELECT SUBSTRING(1, (SELECT 1 FROM t1 a1 RIGHT OUTER JOIN t1 ON 0)) AS d
+FROM t1 WHERE 0 > ANY (SELECT @a FROM t1)';
+
+--error ER_SUBQUERY_NO_1_ROW
+EXECUTE s;
+
+DEALLOCATE PREPARE s;
+DROP TABLE t1;
+
+--echo #
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 367699ea6cb..7d0186c0752 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4434,7 +4434,11 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
return 1; /* purecov: inspected */
thd->send_explain_fields(result);
res= mysql_explain_union(thd, &thd->lex->unit, result);
- if (lex->describe & DESCRIBE_EXTENDED)
+ /*
+ The code which prints the extended description is not robust
+ against malformed queries, so skip it if we have an error.
+ */
+ if (!res && (lex->describe & DESCRIBE_EXTENDED))
{
char buff[1024];
String str(buff,(uint32) sizeof(buff), system_charset_info);