From 5e9d6511088e4435470b37bcc07825a77cc99539 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 18 May 2017 23:54:43 -0700 Subject: Fixed the bug mdev-12788. In some rare cases queries with UNION ALL using a derived table specified by a grouping select with a subquery in WHERE and impossible HAVING detected after constant row substitution could hang. The cause was not a proper return from the function subselect_single_select_engine::exec() in the case when the subquery was not optimized beforehand and the optimization performed in this function requested for a change of the subquery engine. This was fixed. Also a change was applied that avoided execution of a subquery if impossible having was detected for the main query at the optimization stage. --- mysql-test/t/union.test | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'mysql-test/t/union.test') diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index e0c011e3d20..359872d7e6d 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -1507,3 +1507,28 @@ SELECT * FROM t1 t1_1 LEFT JOIN t1 t1_2 ON ( t1_2.b = t1_1.a ) WHERE t1_2.b NOT IN ( SELECT 4 UNION ALL SELECT 5 ); DROP TABLE t1; + +--echo # +--echo # Bug mdev-12788: UNION ALL + impossible having for derived +--echo # with IN subquery in WHERE +--echo # + +CREATE TABLE t1 (i int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1); + +CREATE TABLE t2 (pk int PRIMARY KEY) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1),(2); + +let $q= +SELECT 1, 2 +UNION ALL +SELECT i, COUNT(*) FROM ( + SELECT * FROM t1 WHERE i IN ( SELECT pk FROM t2 ) +) AS sq +GROUP BY i +HAVING i = 10; + +eval $q; +eval EXPLAIN EXTENDED $q; + +DROP TABLE t1,t2; -- cgit v1.2.1