forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: migrate some collation tests to explain test (pingcap#31993)
ref pingcap#31625
- Loading branch information
1 parent
f8dc790
commit f2dba0e
Showing
9 changed files
with
229 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
create database collation_misc; | ||
use collation_misc; | ||
create table t1(a varchar(20) charset utf8); | ||
insert into t1 values ("t1_value"); | ||
alter table t1 collate uTf8mB4_uNiCoDe_Ci charset Utf8mB4 charset uTF8Mb4 collate UTF8MB4_BiN; | ||
alter table t1 modify column a varchar(20) charset utf8mb4; | ||
select * from t1; | ||
a | ||
t1_value | ||
create table t(a varchar(20) charset latin1); | ||
insert into t values ("t_value"); | ||
alter table t modify column a varchar(20) charset latin1; | ||
select * from t; | ||
a | ||
t_value | ||
alter table t modify column a varchar(20) charset utf8; | ||
Error 8200: Unsupported modify charset from latin1 to utf8 | ||
alter table t modify column a varchar(20) charset utf8mb4; | ||
Error 8200: Unsupported modify charset from latin1 to utf8mb4 | ||
alter table t modify column a varchar(20) charset utf8 collate utf8_bin; | ||
Error 8200: Unsupported modify charset from latin1 to utf8 | ||
alter table t modify column a varchar(20) charset utf8mb4 collate utf8mb4_general_ci; | ||
Error 8200: Unsupported modify charset from latin1 to utf8mb4 | ||
alter table t modify column a varchar(20) charset utf8mb4 collate utf8bin; | ||
[ddl:1273]Unknown collation: 'utf8bin' | ||
alter table t collate LATIN1_GENERAL_CI charset utf8 collate utf8_bin; | ||
Error 1302: Conflicting declarations: 'CHARACTER SET latin1' and 'CHARACTER SET utf8' | ||
alter table t collate LATIN1_GENERAL_CI collate UTF8MB4_UNICODE_ci collate utf8_bin; | ||
Error 1253: COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'latin1' | ||
create database if not exists cd_test_utf8 CHARACTER SET utf8 COLLATE utf8_bin; | ||
create database if not exists cd_test_latin1 CHARACTER SET latin1 COLLATE latin1_swedish_ci; | ||
use cd_test_utf8; | ||
select @@character_set_database; | ||
@@character_set_database | ||
utf8 | ||
select @@collation_database; | ||
@@collation_database | ||
utf8_bin | ||
use cd_test_latin1; | ||
select @@character_set_database; | ||
@@character_set_database | ||
latin1 | ||
select @@collation_database; | ||
@@collation_database | ||
latin1_swedish_ci | ||
create database if not exists test_db CHARACTER SET latin1 COLLATE latin1_swedish_ci; | ||
with cte as (select cast('2010-09-09' as date) a union select '2010-09-09 ') select count(*) from cte; | ||
count(*) | ||
2 | ||
set names utf8mb4 collate utf8mb4_general_ci; | ||
select position('a' in 'AA'); | ||
position('a' in 'AA') | ||
0 | ||
select locate('a', 'AA'); | ||
locate('a', 'AA') | ||
0 | ||
select locate('a', 'a'); | ||
locate('a', 'a') | ||
1 | ||
set names utf8mb4; | ||
SELECT default_collate_name, maxlen FROM information_schema.character_sets ORDER BY character_set_name; | ||
default_collate_name maxlen | ||
ascii_bin 1 | ||
binary 1 | ||
gbk_bin 2 | ||
latin1_bin 1 | ||
utf8_bin 3 | ||
utf8mb4_bin 4 | ||
SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name, id; | ||
character_set_name id sortlen | ||
ascii 65 1 | ||
binary 63 1 | ||
gbk 87 1 | ||
latin1 47 1 | ||
utf8 83 1 | ||
utf8mb4 46 1 | ||
select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY where COLLATION_NAME='utf8mb4_bin'; | ||
COLLATION_NAME CHARACTER_SET_NAME | ||
utf8mb4_bin utf8mb4 | ||
use test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
create database collation_misc; | ||
use collation_misc; | ||
create table t1(a varchar(20) charset utf8); | ||
insert into t1 values ("t1_value"); | ||
alter table t1 collate uTf8mB4_uNiCoDe_Ci charset Utf8mB4 charset uTF8Mb4 collate UTF8MB4_BiN; | ||
alter table t1 modify column a varchar(20) charset utf8mb4; | ||
select * from t1; | ||
a | ||
t1_value | ||
create table t(a varchar(20) charset latin1); | ||
insert into t values ("t_value"); | ||
alter table t modify column a varchar(20) charset latin1; | ||
select * from t; | ||
a | ||
t_value | ||
alter table t modify column a varchar(20) charset utf8; | ||
Error 8200: Unsupported modify charset from latin1 to utf8 | ||
alter table t modify column a varchar(20) charset utf8mb4; | ||
Error 8200: Unsupported modify charset from latin1 to utf8mb4 | ||
alter table t modify column a varchar(20) charset utf8 collate utf8_bin; | ||
Error 8200: Unsupported modify charset from latin1 to utf8 | ||
alter table t modify column a varchar(20) charset utf8mb4 collate utf8mb4_general_ci; | ||
Error 8200: Unsupported modify charset from latin1 to utf8mb4 | ||
alter table t modify column a varchar(20) charset utf8mb4 collate utf8bin; | ||
[ddl:1273]Unknown collation: 'utf8bin' | ||
alter table t collate LATIN1_GENERAL_CI charset utf8 collate utf8_bin; | ||
Error 1273: Unsupported collation when new collation is enabled: 'latin1_general_ci' | ||
alter table t collate LATIN1_GENERAL_CI collate UTF8MB4_UNICODE_ci collate utf8_bin; | ||
Error 1273: Unsupported collation when new collation is enabled: 'latin1_general_ci' | ||
create database if not exists cd_test_utf8 CHARACTER SET utf8 COLLATE utf8_bin; | ||
create database if not exists cd_test_latin1 CHARACTER SET latin1 COLLATE latin1_swedish_ci; | ||
Error 1273: Unsupported collation when new collation is enabled: 'latin1_swedish_ci' | ||
use cd_test_utf8; | ||
select @@character_set_database; | ||
@@character_set_database | ||
utf8 | ||
select @@collation_database; | ||
@@collation_database | ||
utf8_bin | ||
use cd_test_latin1; | ||
Error 1049: Unknown database 'cd_test_latin1' | ||
select @@character_set_database; | ||
@@character_set_database | ||
utf8 | ||
select @@collation_database; | ||
@@collation_database | ||
utf8_bin | ||
create database if not exists test_db CHARACTER SET latin1 COLLATE latin1_swedish_ci; | ||
Error 1273: Unsupported collation when new collation is enabled: 'latin1_swedish_ci' | ||
with cte as (select cast('2010-09-09' as date) a union select '2010-09-09 ') select count(*) from cte; | ||
count(*) | ||
1 | ||
set names utf8mb4 collate utf8mb4_general_ci; | ||
select position('a' in 'AA'); | ||
position('a' in 'AA') | ||
1 | ||
select locate('a', 'AA'); | ||
locate('a', 'AA') | ||
1 | ||
select locate('a', 'a'); | ||
locate('a', 'a') | ||
1 | ||
set names utf8mb4; | ||
SELECT default_collate_name, maxlen FROM information_schema.character_sets ORDER BY character_set_name; | ||
default_collate_name maxlen | ||
ascii_bin 1 | ||
binary 1 | ||
gbk_chinese_ci 2 | ||
latin1_bin 1 | ||
utf8_bin 3 | ||
utf8mb4_bin 4 | ||
SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name, id; | ||
character_set_name id sortlen | ||
ascii 65 1 | ||
binary 63 1 | ||
gbk 87 1 | ||
gbk 28 1 | ||
latin1 47 1 | ||
utf8 83 1 | ||
utf8 33 1 | ||
utf8 192 1 | ||
utf8mb4 46 1 | ||
utf8mb4 45 1 | ||
utf8mb4 224 1 | ||
select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY where COLLATION_NAME='utf8mb4_bin'; | ||
COLLATION_NAME CHARACTER_SET_NAME | ||
utf8mb4_bin utf8mb4 | ||
use test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# prepare database | ||
create database collation_misc; | ||
use collation_misc; | ||
|
||
# ChangingCharsetToUtf8 | ||
create table t1(a varchar(20) charset utf8); | ||
insert into t1 values ("t1_value"); | ||
alter table t1 collate uTf8mB4_uNiCoDe_Ci charset Utf8mB4 charset uTF8Mb4 collate UTF8MB4_BiN; | ||
alter table t1 modify column a varchar(20) charset utf8mb4; | ||
select * from t1; | ||
create table t(a varchar(20) charset latin1); | ||
insert into t values ("t_value"); | ||
alter table t modify column a varchar(20) charset latin1; | ||
select * from t; | ||
--error 8200 | ||
alter table t modify column a varchar(20) charset utf8; | ||
--error 8200 | ||
alter table t modify column a varchar(20) charset utf8mb4; | ||
--error 8200 | ||
alter table t modify column a varchar(20) charset utf8 collate utf8_bin; | ||
--error 8200 | ||
alter table t modify column a varchar(20) charset utf8mb4 collate utf8mb4_general_ci; | ||
--error 1273 | ||
alter table t modify column a varchar(20) charset utf8mb4 collate utf8bin; | ||
--error 1302, 1273 | ||
alter table t collate LATIN1_GENERAL_CI charset utf8 collate utf8_bin; | ||
--error 1253, 1273 | ||
alter table t collate LATIN1_GENERAL_CI collate UTF8MB4_UNICODE_ci collate utf8_bin; | ||
|
||
# TestCharsetDatabase | ||
create database if not exists cd_test_utf8 CHARACTER SET utf8 COLLATE utf8_bin; | ||
--error 1273 | ||
create database if not exists cd_test_latin1 CHARACTER SET latin1 COLLATE latin1_swedish_ci; | ||
use cd_test_utf8; | ||
select @@character_set_database; | ||
select @@collation_database; | ||
--error 1049 | ||
use cd_test_latin1; | ||
select @@character_set_database; | ||
select @@collation_database; | ||
|
||
# DefaultDBAfterDropCurDB | ||
--error 1273 | ||
create database if not exists test_db CHARACTER SET latin1 COLLATE latin1_swedish_ci; | ||
|
||
# CollationUnion | ||
with cte as (select cast('2010-09-09' as date) a union select '2010-09-09 ') select count(*) from cte; | ||
|
||
# Issue26989 | ||
set names utf8mb4 collate utf8mb4_general_ci; | ||
select position('a' in 'AA'); | ||
select locate('a', 'AA'); | ||
select locate('a', 'a'); | ||
set names utf8mb4; | ||
|
||
# CharacterSetCollations | ||
SELECT default_collate_name, maxlen FROM information_schema.character_sets ORDER BY character_set_name; | ||
SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name, id; | ||
select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY where COLLATION_NAME='utf8mb4_bin'; | ||
|
||
use test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters