Skip to content

Commit b62ac16

Browse files
committed
MDEV-6439: Server crashes in Explain_union::print_explain with explain in slow log, tis620 charset
Item_subselect::is_expensive() used to return FALSE (Inexpensive) whenever it saw that one of SELECTs in the Subquery's UNION is degenerate. It ignored the fact that other parts of the UNION might not be inexpensive, including the case where pther parts of the UNION have no query plan yet. For a subquery in form col >= ANY (SELECT 'foo' UNION SELECT 'bar') this would cause the query to be considered inexpensive when there is no query plan for the second part of the UNION, which in turn would cause the SELECT 'foo' to compute and free itself while still inside JOIN::optimize for that SELECT (See MDEV comment for full description).
1 parent 9dfef6e commit b62ac16

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

mysql-test/r/subselect_extra_no_semijoin.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,22 @@ DROP TABLE t1,t2;
482482
set optimizer_switch= @tmp_subselect_extra_derived;
483483
set optimizer_switch= @subselect_extra_no_sj_tmp;
484484
set @optimizer_switch_for_subselect_extra_test=null;
485+
#
486+
# MDEV-6439: Server crashes in Explain_union::print_explain with explain in slow log, tis620 charset
487+
#
488+
SET NAMES tis620;
489+
set @tmp= @@global.slow_query_log;
490+
SET GLOBAL slow_query_log = 1;
491+
SET long_query_time = 0.000001;
492+
SET log_slow_verbosity = 'explain';
493+
CREATE TABLE t1 (a VARCHAR(3)) ENGINE=MyISAM;
494+
SELECT * FROM t1 WHERE a >= ANY ( SELECT 'foo');
495+
a
496+
SELECT * FROM t1 WHERE a >= ANY ( SELECT 'foo' UNION SELECT 'bar' );
497+
ERROR HY000: Illegal mix of collations (tis620_thai_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation '<='
498+
create table t2 (b int);
499+
insert into t2 values (1),(2),(3);
500+
SELECT * FROM t1 WHERE a >= ANY ( SELECT 'foo' FROM t2);
501+
ERROR HY000: Illegal mix of collations (tis620_thai_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation '<='
502+
drop table t1,t2;
503+
SET GLOBAL slow_query_log=@tmp;

mysql-test/t/subselect_extra_no_semijoin.test

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,33 @@ set @optimizer_switch_for_subselect_extra_test='semijoin=off,firstmatch=off,loo
66

77
set optimizer_switch= @subselect_extra_no_sj_tmp;
88

9-
set @optimizer_switch_for_subselect_extra_test=null;
9+
set @optimizer_switch_for_subselect_extra_test=null;
10+
11+
--echo #
12+
--echo # MDEV-6439: Server crashes in Explain_union::print_explain with explain in slow log, tis620 charset
13+
--echo #
14+
15+
## Using a separate client connection is easier than restoring state
16+
connect(con1,localhost,root,,);
17+
18+
SET NAMES tis620;
19+
set @tmp= @@global.slow_query_log;
20+
SET GLOBAL slow_query_log = 1;
21+
SET long_query_time = 0.000001;
22+
SET log_slow_verbosity = 'explain';
23+
24+
CREATE TABLE t1 (a VARCHAR(3)) ENGINE=MyISAM;
25+
SELECT * FROM t1 WHERE a >= ANY ( SELECT 'foo');
26+
--error ER_CANT_AGGREGATE_2COLLATIONS
27+
SELECT * FROM t1 WHERE a >= ANY ( SELECT 'foo' UNION SELECT 'bar' );
28+
29+
create table t2 (b int);
30+
insert into t2 values (1),(2),(3);
31+
32+
--error ER_CANT_AGGREGATE_2COLLATIONS
33+
SELECT * FROM t1 WHERE a >= ANY ( SELECT 'foo' FROM t2);
34+
35+
drop table t1,t2;
36+
SET GLOBAL slow_query_log=@tmp;
37+
disconnect con1;
38+
connection default;

sql/item_subselect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ bool Item_subselect::is_expensive()
575575
*/
576576
if (cur_join->optimized &&
577577
(cur_join->zero_result_cause || !cur_join->tables_list))
578-
return false;
578+
continue;
579579

580580
/*
581581
If a subquery is not optimized we cannot estimate its cost. A subquery is

0 commit comments

Comments
 (0)