Skip to content

Commit 75e3077

Browse files
author
Dag Wanvik
committed
Bug#36487526 MDS Crash in X plugin protocol encoder
Also closes duplicate Bug#36505461. When trying to return metadata, the code sees a visible column (the first in the result set) which has no item_name set, which is inconsistent; all visible items in the select list have item names set. The first column in the result set in this case (marked as visible) is the COALESCE expression generated by the transform. This should have been marked as a hidden item. The underlying issue is that when the COALESCE is wrapped around the expression in Item_singlerow_subselect::replace_scalar_subquery, the new COALESCE doesn't inherit the hidden status of the expression it is wrapping. Solution: make COALESCE inherit the hidden status. Change-Id: Ia44e605db378bfc46821af5cdfefdf90999033ab
1 parent 4e7611d commit 75e3077

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

mysql-test/r/subquery_scalar_to_derived_correlated.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,4 +1657,20 @@ Warnings:
16571657
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
16581658
Note 1003 /* select#1 */ select coalesce(`derived_1_2`.`cnt`,if((`derived_1_2`.`Name_exp_3` is not null),0,NULL)) AS `cnt` from `test`.`t1` left join (/* select#2 */ select count(1) AS `cnt`,`test`.`t2`.`a` AS `a`,((sum(`test`.`t2`.`a`) + `cnt`) > 4) AS `Name_exp_3` from `test`.`t2` group by `test`.`t2`.`a` having ((sum(`test`.`t2`.`a`) + `cnt`) > 4)) `derived_1_2` on((`derived_1_2`.`a` = `test`.`t1`.`a`)) where true
16591659
DROP TABLE t1, t2;
1660+
#
1661+
# Bug#36487526 MDS Crash in X plugin protocol encoder
1662+
#
1663+
# Simplified repro
1664+
CREATE TABLE t1 (f1 INTEGER, f2 INTEGER);
1665+
SELECT COUNT(*)+(SELECT COUNT(*) FROM t1 WHERE t1.f1 = t2.f1) FROM t1 AS t2 GROUP BY f2;
1666+
COUNT(*)+(SELECT COUNT(*) FROM t1 WHERE t1.f1 = t2.f1)
1667+
EXPLAIN SELECT COUNT(*)+(SELECT COUNT(*) FROM t1 WHERE t1.f1 = t2.f1) FROM t1 AS t2 GROUP BY f2;
1668+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1669+
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using temporary
1670+
1 PRIMARY <derived2> NULL ref <auto_key0> <auto_key0> 5 test.t2.f1 2 100.00 NULL
1671+
2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using temporary
1672+
Warnings:
1673+
Note 1276 Field or reference 'test.t2.f1' of SELECT #2 was resolved in SELECT #1
1674+
Note 1003 /* select#1 */ select (count(0) + coalesce(`derived_1_2`.`COUNT(*)`,0)) AS `COUNT(*)+(SELECT COUNT(*) FROM t1 WHERE t1.f1 = t2.f1)` from `test`.`t1` `t2` left join (/* select#2 */ select count(0) AS `COUNT(*)`,`test`.`t1`.`f1` AS `f1` from `test`.`t1` group by `test`.`t1`.`f1`) `derived_1_2` on((`derived_1_2`.`f1` = `test`.`t2`.`f1`)) where true group by `test`.`t2`.`f2`
1675+
DROP TABLE t1;
16601676
SET optimizer_switch = 'subquery_to_derived=default';

mysql-test/t/subquery_scalar_to_derived_correlated.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,20 @@ eval EXPLAIN $query;
11201120

11211121
DROP TABLE t1, t2;
11221122

1123+
--echo #
1124+
--echo # Bug#36487526 MDS Crash in X plugin protocol encoder
1125+
--echo #
1126+
1127+
--echo # Simplified repro
1128+
CREATE TABLE t1 (f1 INTEGER, f2 INTEGER);
1129+
let $query=
1130+
SELECT COUNT(*)+(SELECT COUNT(*) FROM t1 WHERE t1.f1 = t2.f1) FROM t1 AS t2 GROUP BY f2;
1131+
1132+
eval $query;
1133+
eval EXPLAIN $query;
1134+
1135+
DROP TABLE t1;
1136+
11231137
SET optimizer_switch = 'subquery_to_derived=default';
11241138
# Local Variables:
11251139
# mode: sql

sql/item_subselect.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,6 +3065,7 @@ Item *Item_singlerow_subselect::replace_scalar_subquery(uchar *arg) {
30653065
Item *coa = new (mem_root) Item_func_coalesce(result, zero_or_if);
30663066
if (coa == nullptr) return nullptr;
30673067
if (coa->fix_fields(current_thd, &coa)) return nullptr;
3068+
coa->hidden = result->hidden;
30683069
result = coa;
30693070
}
30703071
return result;

0 commit comments

Comments
 (0)