diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2020-08-18 17:31:10 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-08-19 14:45:19 +0530 |
commit | d08b9d3c1c5be5dc183b1384730973be0e70c44d (patch) | |
tree | 4463a9041ea33e822be6b4949f2afb21f8e5f53d /mysql-test/t/subselect4.test | |
parent | 8ddc2182fdfd8f8b8dcffccb4605cd9deac35c7a (diff) | |
download | mariadb-git-10.1-varun.tar.gz |
MDEV-23160: SIGSEGV in Explain_node::print_explain_for_children on UNION SELECT or on EXPLAIN EXTENDED10.1-varun
The issue here was that the ORDER BY clause had a subquery and the
ORDER BY clause was defined for a UNION inside an IN subquery.
For IN/ALL/ANY subquery the ORDER BY clause makes no sense and should be removed.
But the removal of the ORDER BY clause happened before name resolution. So an invalid query
could also be parsed and would not return an error.
The reason for the crash is that for EXPLAIN of UNION, the fake_select_lex adds the
removed subquery as its child. The subquery being removed does not create a node for itself
for EXPLAIN. But when the EXPLAIN is printed for the fake_select_lex it tries to print the nodes
of its children.
The fix would be to mark the subquery to be eliminated so that it is not added as a child
to the fake_select_lex node. Then after name resolution is done and the query is valid
then remove the subquery so that it does not get executed.
Diffstat (limited to 'mysql-test/t/subselect4.test')
-rw-r--r-- | mysql-test/t/subselect4.test | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test index 03929517126..8bd43661dbc 100644 --- a/mysql-test/t/subselect4.test +++ b/mysql-test/t/subselect4.test @@ -2173,4 +2173,40 @@ INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4), (5,5); SELECT a, b FROM t1 WHERE a IN (SELECT A.a FROM t1 A GROUP BY s.id); DROP TABLE t1; +--echo # +--echo # MDEV-23160: SIGSEGV in Explain_node::print_explain_for_children on UNION SELECT +--echo # or on EXPLAIN EXTENDED +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +EXPLAIN SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION SELECT B.a FROM t1 B ORDER BY (SELECT a)); + +SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION SELECT B.a FROM t1 B ORDER BY (SELECT a)); + +EXPLAIN SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION ALL SELECT B.a FROM t1 B ORDER BY (SELECT a)); + +SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION ALL SELECT B.a FROM t1 B ORDER BY (SELECT a)); + +PREPARE stmt FROM 'EXPLAIN SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION SELECT B.a FROM t1 B ORDER BY (SELECT a))'; + +EXECUTE stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +--error ER_BAD_FIELD_ERROR +SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION SELECT B.a FROM t1 B ORDER BY (SELECT id)); + +--error ER_BAD_FIELD_ERROR +SELECT * FROM t1 +WHERE a IN (SELECT A.a FROM t1 A UNION ALL SELECT B.a FROM t1 B ORDER BY (SELECT id)); + +DROP TABLE t1; + --echo # end of 10.1 tests |