Commit ab15833a authored by Alexander Barkov's avatar Alexander Barkov

Bug#55744 GROUP_CONCAT + CASE + ucs return garbage

Problem: CASE didn't work with a mixture of different character
sets in THEN/ELSE in some cases.
This happened because after character set aggregation
newly created Item_func_conv_charset items corresponding
to THEN/ELSE arguments were not put back to args[] array.

Fix:
put all Item_func_conv_charset back to args[].


  @ mysql-test/include/ctype_numconv.inc
  @ mysql-test/r/ctype_ucs.result
  Adding tests

  @ sql/item_cmpfunc.cc
  Put "agg" back to args[] after character set aggregation.
parent 817f02fd
...@@ -1635,12 +1635,7 @@ CREATE TABLE t1 (a MEDIUMINT NULL) ENGINE=MYISAM; ...@@ -1635,12 +1635,7 @@ CREATE TABLE t1 (a MEDIUMINT NULL) ENGINE=MYISAM;
INSERT INTO t1 VALUES (1234567); INSERT INTO t1 VALUES (1234567);
SELECT GROUP_CONCAT(IFNULL(a,'')) FROM t1; SELECT GROUP_CONCAT(IFNULL(a,'')) FROM t1;
SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1; SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1;
if (`SELECT @@character_set_connection != 'ucs2'`) SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1;
{
# Temporarily disable for ucs2
# For details, see Bug#55744 GROUP_CONCAT + CASE + ucs return garbage
SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1;
}
--enable_metadata --enable_metadata
SELECT COALESCE(a,'') FROM t1 GROUP BY 1; SELECT COALESCE(a,'') FROM t1 GROUP BY 1;
--disable_metadata --disable_metadata
......
...@@ -3853,6 +3853,9 @@ GROUP_CONCAT(IFNULL(a,'')) ...@@ -3853,6 +3853,9 @@ GROUP_CONCAT(IFNULL(a,''))
SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1; SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1;
GROUP_CONCAT(IF(a,a,'')) GROUP_CONCAT(IF(a,a,''))
1234567 1234567
SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1;
GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END)
1234567
SELECT COALESCE(a,'') FROM t1 GROUP BY 1; SELECT COALESCE(a,'') FROM t1 GROUP BY 1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def COALESCE(a,'') 253 9 7 Y 0 31 8 def COALESCE(a,'') 253 9 7 Y 0 31 8
......
...@@ -3029,6 +3029,14 @@ void Item_func_case::fix_length_and_dec() ...@@ -3029,6 +3029,14 @@ void Item_func_case::fix_length_and_dec()
{ {
if (agg_arg_charsets_for_string_result(collation, agg, nagg)) if (agg_arg_charsets_for_string_result(collation, agg, nagg))
return; return;
/*
Copy all THEN and ELSE items back to args[] array.
Some of the items might have been changed to Item_func_conv_charset.
*/
for (nagg= 0 ; nagg < ncases / 2 ; nagg++)
args[nagg * 2 + 1]= agg[nagg];
if (else_expr_num != -1)
args[else_expr_num]= agg[nagg++];
} }
else else
collation.set_numeric(); collation.set_numeric();
......
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