Skip to content

Commit 6beb08c

Browse files
committed
MDEV-15624 Changing the default character set to utf8mb4 changes query evaluation in a very surprising way
1 parent f5369fa commit 6beb08c

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed

mysql-test/r/ctype_ucs.result

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,5 +4397,36 @@ Field Type Null Key Default Extra
43974397
c1 mediumtext YES NULL
43984398
DROP TABLE t1;
43994399
#
4400+
# MDEV-15624 Changing the default character set to utf8mb4 changes query evaluation in a very surprising way
4401+
#
4402+
SET NAMES utf8;
4403+
CREATE TABLE t1 (id INT);
4404+
INSERT INTO t1 VALUES (1),(2),(3);
4405+
SELECT COUNT(DISTINCT c) FROM (SELECT id, REPLACE(uuid_short(), '0', CAST('o' AS CHAR CHARACTER SET ucs2)) AS c FROM t1) AS d1;
4406+
COUNT(DISTINCT c)
4407+
3
4408+
SELECT DISTINCT REPLACE(uuid_short(), '0', CAST('o' AS CHAR CHARACTER SET ucs2)) AS c FROM t1;
4409+
c
4410+
xxxxxxxxxxxxxxxxx
4411+
xxxxxxxxxxxxxxxxx
4412+
xxxxxxxxxxxxxxxxx
4413+
SELECT COUNT(DISTINCT c) FROM (SELECT id, INSERT(uuid_short(), 1, 1, CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1) AS d1;
4414+
COUNT(DISTINCT c)
4415+
3
4416+
SELECT DISTINCT INSERT(uuid_short(), 1, 1, CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1;
4417+
c
4418+
xxxxxxxxxxxxxxxxx
4419+
xxxxxxxxxxxxxxxxx
4420+
xxxxxxxxxxxxxxxxx
4421+
SELECT COUNT(DISTINCT c) FROM (SELECT id, CONCAT(uuid_short(), CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1) AS d1;
4422+
COUNT(DISTINCT c)
4423+
3
4424+
SELECT DISTINCT CONCAT(uuid_short(), CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1;
4425+
c
4426+
xxxxxxxxxxxxxxxxx
4427+
xxxxxxxxxxxxxxxxx
4428+
xxxxxxxxxxxxxxxxx
4429+
DROP TABLE t1;
4430+
#
44004431
# End of 5.5 tests
44014432
#

mysql-test/r/ctype_utf8mb4.result

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,29 @@ SELECT LENGTH(data) AS len FROM (SELECT REPEAT('☃', 65536) AS data ) AS sub;
26562656
len
26572657
196608
26582658
#
2659+
# MDEV-15624 Changing the default character set to utf8mb4 changes query evaluation in a very surprising way
2660+
#
2661+
SET NAMES utf8mb4;
2662+
CREATE TABLE t1 (id INT);
2663+
INSERT INTO t1 VALUES (1),(2),(3);
2664+
SELECT COUNT(DISTINCT c) FROM (SELECT id, REPLACE(UUID(), "-", "") AS c FROM t1) AS d1;
2665+
COUNT(DISTINCT c)
2666+
3
2667+
SELECT DISTINCT INSERT(uuid(), 9, 1, "X") AS c FROM t1;
2668+
c
2669+
xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
2670+
xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
2671+
xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
2672+
SELECT COUNT(DISTINCT c) FROM (SELECT id, INSERT(UUID(), 9, 1, "X") AS c FROM t1) AS d1;
2673+
COUNT(DISTINCT c)
2674+
3
2675+
SELECT DISTINCT INSERT(UUID(), 9, 1, "X") AS c FROM t1;
2676+
c
2677+
xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
2678+
xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
2679+
xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
2680+
DROP TABLE t1;
2681+
#
26592682
# End of 5.5 tests
26602683
#
26612684
#

mysql-test/t/ctype_ucs.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,28 @@ DESCRIBE t1;
885885
DROP TABLE t1;
886886

887887

888+
--echo #
889+
--echo # MDEV-15624 Changing the default character set to utf8mb4 changes query evaluation in a very surprising way
890+
--echo #
891+
892+
SET NAMES utf8;
893+
CREATE TABLE t1 (id INT);
894+
INSERT INTO t1 VALUES (1),(2),(3);
895+
896+
SELECT COUNT(DISTINCT c) FROM (SELECT id, REPLACE(uuid_short(), '0', CAST('o' AS CHAR CHARACTER SET ucs2)) AS c FROM t1) AS d1;
897+
--replace_column 1 xxxxxxxxxxxxxxxxx
898+
SELECT DISTINCT REPLACE(uuid_short(), '0', CAST('o' AS CHAR CHARACTER SET ucs2)) AS c FROM t1;
899+
900+
SELECT COUNT(DISTINCT c) FROM (SELECT id, INSERT(uuid_short(), 1, 1, CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1) AS d1;
901+
--replace_column 1 xxxxxxxxxxxxxxxxx
902+
SELECT DISTINCT INSERT(uuid_short(), 1, 1, CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1;
903+
904+
SELECT COUNT(DISTINCT c) FROM (SELECT id, CONCAT(uuid_short(), CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1) AS d1;
905+
--replace_column 1 xxxxxxxxxxxxxxxxx
906+
SELECT DISTINCT CONCAT(uuid_short(), CAST('0' AS CHAR CHARACTER SET ucs2)) AS c FROM t1;
907+
DROP TABLE t1;
908+
909+
888910
--echo #
889911
--echo # End of 5.5 tests
890912
--echo #

mysql-test/t/ctype_utf8mb4.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,25 @@ SELECT LENGTH(data) AS len FROM (SELECT REPEAT('☃', 21846) AS data ) AS sub;
18581858
SELECT LENGTH(data) AS len FROM (SELECT REPEAT('☃', 65535) AS data ) AS sub;
18591859
SELECT LENGTH(data) AS len FROM (SELECT REPEAT('☃', 65536) AS data ) AS sub;
18601860

1861+
--echo #
1862+
--echo # MDEV-15624 Changing the default character set to utf8mb4 changes query evaluation in a very surprising way
1863+
--echo #
1864+
1865+
SET NAMES utf8mb4;
1866+
CREATE TABLE t1 (id INT);
1867+
INSERT INTO t1 VALUES (1),(2),(3);
1868+
1869+
SELECT COUNT(DISTINCT c) FROM (SELECT id, REPLACE(UUID(), "-", "") AS c FROM t1) AS d1;
1870+
--replace_column 1 xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
1871+
SELECT DISTINCT INSERT(uuid(), 9, 1, "X") AS c FROM t1;
1872+
1873+
SELECT COUNT(DISTINCT c) FROM (SELECT id, INSERT(UUID(), 9, 1, "X") AS c FROM t1) AS d1;
1874+
--replace_column 1 xxxxxxxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
1875+
SELECT DISTINCT INSERT(UUID(), 9, 1, "X") AS c FROM t1;
1876+
1877+
DROP TABLE t1;
1878+
1879+
18611880
--echo #
18621881
--echo # End of 5.5 tests
18631882
--echo #

sql/item_func.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,8 @@ class Item_func_uuid_short :public Item_int_func
21332133
Item_func_uuid_short() :Item_int_func() {}
21342134
const char *func_name() const { return "uuid_short"; }
21352135
longlong val_int();
2136+
bool const_item() const { return false; }
2137+
table_map used_tables() const { return RAND_TABLE_BIT; }
21362138
void fix_length_and_dec()
21372139
{ max_length= 21; unsigned_flag=1; }
21382140
bool check_vcol_func_processor(uchar *int_arg)

sql/item_strfunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ class Item_func_uuid: public Item_str_func
997997
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
998998
fix_char_length(MY_UUID_STRING_LENGTH);
999999
}
1000+
bool const_item() const { return false; }
10001001
table_map used_tables() const { return RAND_TABLE_BIT; }
10011002
const char *func_name() const{ return "uuid"; }
10021003
String *val_str(String *);

0 commit comments

Comments
 (0)