Commit fba385e3 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops with UNION in ALL subquery

Do not mark subquery as inexpensive when it is not optimized.
parent a02d4023
...@@ -1101,7 +1101,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -1101,7 +1101,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where (not(<expr_cache><6,5>(<in_optimizer>((6,5),<exists>(select 7,5 having (trigcond(((<cache>(6) = 7) or isnull(7))) and trigcond(((<cache>(5) = 5) or isnull(5))) and trigcond(<is_not_null_test>(7)) and trigcond(<is_not_null_test>(5)))))))) Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where 1
SELECT t.a,t.b FROM t3 RIGHT JOIN ((SELECT * FROM t1) AS t, t2) ON t2.b != 0 SELECT t.a,t.b FROM t3 RIGHT JOIN ((SELECT * FROM t1) AS t, t2) ON t2.b != 0
WHERE (t.a,t.b) NOT IN (SELECT 7, 5); WHERE (t.a,t.b) NOT IN (SELECT 7, 5);
a b a b
...@@ -1115,7 +1115,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -1115,7 +1115,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where (not(<expr_cache><6,5>(<in_optimizer>((6,5),<exists>(select 7,5 having (trigcond(((<cache>(6) = 7) or isnull(7))) and trigcond(((<cache>(5) = 5) or isnull(5))) and trigcond(<is_not_null_test>(7)) and trigcond(<is_not_null_test>(5)))))))) Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where 1
SELECT t.a,t.b FROM t3 RIGHT JOIN (v1 AS t, t2) ON t2.b != 0 SELECT t.a,t.b FROM t3 RIGHT JOIN (v1 AS t, t2) ON t2.b != 0
WHERE (t.a,t.b) NOT IN (SELECT 7, 5); WHERE (t.a,t.b) NOT IN (SELECT 7, 5);
a b a b
...@@ -1129,7 +1129,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -1129,7 +1129,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where (not(<expr_cache><6,5>(<in_optimizer>((6,5),<exists>(select 7,5 having (trigcond(((<cache>(6) = 7) or isnull(7))) and trigcond(((<cache>(5) = 5) or isnull(5))) and trigcond(<is_not_null_test>(7)) and trigcond(<is_not_null_test>(5)))))))) Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where 1
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
# #
......
...@@ -7147,3 +7147,15 @@ sq ...@@ -7147,3 +7147,15 @@ sq
NULL NULL
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
#
# MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
# with UNION in ALL subquery
#
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
f
foo
drop table t1;
SET NAMES default;
...@@ -7147,6 +7147,18 @@ sq ...@@ -7147,6 +7147,18 @@ sq
NULL NULL
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
#
# MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
# with UNION in ALL subquery
#
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
f
foo
drop table t1;
SET NAMES default;
set optimizer_switch=default; set optimizer_switch=default;
select @@optimizer_switch like '%exists_to_in=off%'; select @@optimizer_switch like '%exists_to_in=off%';
@@optimizer_switch like '%exists_to_in=off%' @@optimizer_switch like '%exists_to_in=off%'
......
...@@ -7140,6 +7140,18 @@ sq ...@@ -7140,6 +7140,18 @@ sq
NULL NULL
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
#
# MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
# with UNION in ALL subquery
#
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
f
foo
drop table t1;
SET NAMES default;
set optimizer_switch=default; set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%'; select @@optimizer_switch like '%materialization=on%';
@@optimizer_switch like '%materialization=on%' @@optimizer_switch like '%materialization=on%'
......
...@@ -7138,4 +7138,16 @@ sq ...@@ -7138,4 +7138,16 @@ sq
NULL NULL
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
#
# MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
# with UNION in ALL subquery
#
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
f
foo
drop table t1;
SET NAMES default;
set @optimizer_switch_for_subselect_test=null; set @optimizer_switch_for_subselect_test=null;
...@@ -7153,6 +7153,18 @@ sq ...@@ -7153,6 +7153,18 @@ sq
NULL NULL
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
#
# MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
# with UNION in ALL subquery
#
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
f
foo
drop table t1;
SET NAMES default;
set optimizer_switch=default; set optimizer_switch=default;
select @@optimizer_switch like '%subquery_cache=on%'; select @@optimizer_switch like '%subquery_cache=on%';
@@optimizer_switch like '%subquery_cache=on%' @@optimizer_switch like '%subquery_cache=on%'
......
...@@ -7138,5 +7138,17 @@ sq ...@@ -7138,5 +7138,17 @@ sq
NULL NULL
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
#
# MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
# with UNION in ALL subquery
#
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
f
foo
drop table t1;
SET NAMES default;
set @optimizer_switch_for_subselect_test=null; set @optimizer_switch_for_subselect_test=null;
set @join_cache_level_for_subselect_test=NULL; set @join_cache_level_for_subselect_test=NULL;
...@@ -387,6 +387,7 @@ a ...@@ -387,6 +387,7 @@ a
00 00
select a from t1 where a=(select 2000 from dual where 1); select a from t1 where a=(select 2000 from dual where 1);
a a
00
select a from t1 where a=y2k(); select a from t1 where a=y2k();
a a
00 00
......
...@@ -6000,3 +6000,14 @@ SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; ...@@ -6000,3 +6000,14 @@ SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq;
drop view v2; drop view v2;
drop table t1,t2; drop table t1,t2;
--echo #
--echo # MDEV-9487: Server crashes in Time_and_counter_tracker::incr_loops
--echo # with UNION in ALL subquery
--echo #
SET NAMES utf8;
CREATE TABLE t1 (f VARCHAR(8)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
SELECT f FROM t1 WHERE f > ALL ( SELECT 'bar' UNION SELECT 'baz' );
drop table t1;
SET NAMES default;
...@@ -561,22 +561,34 @@ bool Item_subselect::is_expensive() ...@@ -561,22 +561,34 @@ bool Item_subselect::is_expensive()
for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select()) for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select())
{ {
JOIN *cur_join= sl->join; JOIN *cur_join= sl->join;
/* not optimized subquery */
if (!cur_join) if (!cur_join)
continue; return true;
/* very simple subquery */
if (!cur_join->tables_list && !sl->first_inner_unit())
return false;
/*
If the subquery is not optimised or in the process of optimization
it supposed to be expensive
*/
if (!cur_join->optimized)
return true;
/* /*
Subqueries whose result is known after optimization are not expensive. Subqueries whose result is known after optimization are not expensive.
Such subqueries have all tables optimized away, thus have no join plan. Such subqueries have all tables optimized away, thus have no join plan.
*/ */
if (cur_join->optimized && if ((cur_join->zero_result_cause || !cur_join->tables_list))
(cur_join->zero_result_cause || !cur_join->tables_list))
return false; return false;
/* /*
If a subquery is not optimized we cannot estimate its cost. A subquery is If a subquery is not optimized we cannot estimate its cost. A subquery is
considered optimized if it has a join plan. considered optimized if it has a join plan.
*/ */
if (!(cur_join->optimized && cur_join->join_tab)) if (!cur_join->join_tab)
return true; return true;
if (sl->first_inner_unit()) if (sl->first_inner_unit())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment