Skip to content

Commit

Permalink
*: migrate some collation tests to explain test (pingcap#31993)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Jan 26, 2022
1 parent f8dc790 commit f2dba0e
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 107 deletions.
80 changes: 80 additions & 0 deletions cmd/explaintest/r/collation_misc_disabled.result
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;
88 changes: 88 additions & 0 deletions cmd/explaintest/r/collation_misc_enabled.result
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;
61 changes: 61 additions & 0 deletions cmd/explaintest/t/collation_misc.test
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;
26 changes: 0 additions & 26 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,32 +831,6 @@ func (s *testIntegrationSuite2) TestDependedGeneratedColumnPrior2GeneratedColumn
tk.MustExec("alter table t add column(e int as (c+1))")
}

func (s *testIntegrationSuite3) TestChangingCharsetToUtf8(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("use test")
tk.MustExec("create table t1(a varchar(20) charset utf8)")
tk.MustExec("insert into t1 values (?)", "t1_value")
tk.MustExec("alter table t1 collate uTf8mB4_uNiCoDe_Ci charset Utf8mB4 charset uTF8Mb4 collate UTF8MB4_BiN")
tk.MustExec("alter table t1 modify column a varchar(20) charset utf8mb4")
tk.MustQuery("select * from t1;").Check(testkit.Rows("t1_value"))

tk.MustExec("create table t(a varchar(20) charset latin1)")
tk.MustExec("insert into t values (?)", "t_value")

tk.MustExec("alter table t modify column a varchar(20) charset latin1")
tk.MustQuery("select * from t;").Check(testkit.Rows("t_value"))

tk.MustGetErrCode("alter table t modify column a varchar(20) charset utf8", errno.ErrUnsupportedDDLOperation)
tk.MustGetErrCode("alter table t modify column a varchar(20) charset utf8mb4", errno.ErrUnsupportedDDLOperation)
tk.MustGetErrCode("alter table t modify column a varchar(20) charset utf8 collate utf8_bin", errno.ErrUnsupportedDDLOperation)
tk.MustGetErrCode("alter table t modify column a varchar(20) charset utf8mb4 collate utf8mb4_general_ci", errno.ErrUnsupportedDDLOperation)

tk.MustGetErrCode("alter table t modify column a varchar(20) charset utf8mb4 collate utf8bin", errno.ErrUnknownCollation)
tk.MustGetErrCode("alter table t collate LATIN1_GENERAL_CI charset utf8 collate utf8_bin", errno.ErrConflictingDeclarations)
tk.MustGetErrCode("alter table t collate LATIN1_GENERAL_CI collate UTF8MB4_UNICODE_ci collate utf8_bin", errno.ErrCollationCharsetMismatch)
}

func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
19 changes: 0 additions & 19 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,25 +671,6 @@ func (s *testSuite6) TestAlterTableModifyColumn(c *C) {

}

func (s *testSuite6) TestDefaultDBAfterDropCurDB(c *C) {
tk := testkit.NewTestKit(c, s.store)

testSQL := `create database if not exists test_db CHARACTER SET latin1 COLLATE latin1_swedish_ci;`
tk.MustExec(testSQL)

testSQL = `use test_db;`
tk.MustExec(testSQL)
tk.MustQuery(`select database();`).Check(testkit.Rows("test_db"))
tk.MustQuery(`select @@character_set_database;`).Check(testkit.Rows("latin1"))
tk.MustQuery(`select @@collation_database;`).Check(testkit.Rows("latin1_swedish_ci"))

testSQL = `drop database test_db;`
tk.MustExec(testSQL)
tk.MustQuery(`select database();`).Check(testkit.Rows("<nil>"))
tk.MustQuery(`select @@character_set_database;`).Check(testkit.Rows(mysql.DefaultCharset))
tk.MustQuery(`select @@collation_database;`).Check(testkit.Rows(mysql.DefaultCollationName))
}

func (s *testSuite6) TestColumnCharsetAndCollate(c *C) {
tk := testkit.NewTestKit(c, s.store)
dbName := "col_charset_collate"
Expand Down
16 changes: 0 additions & 16 deletions executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,6 @@ func (s *testInfoschemaTableSuite) TestEngines(c *C) {
tk.MustQuery("select * from information_schema.ENGINES;").Check(testkit.Rows("InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES"))
}

func (s *testInfoschemaTableSuite) TestCharacterSetCollations(c *C) {
tk := testkit.NewTestKit(c, s.store)

// The description column is not important
tk.MustQuery("SELECT default_collate_name, maxlen FROM information_schema.character_sets ORDER BY character_set_name").Check(
testkit.Rows("ascii_bin 1", "binary 1", "gbk_bin 2", "latin1_bin 1", "utf8_bin 3", "utf8mb4_bin 4"))

// The is_default column is not important
// but the id's are used by client libraries and must be stable
tk.MustQuery("SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name").Check(
testkit.Rows("ascii 65 1", "binary 63 1", "gbk 87 1", "latin1 47 1", "utf8 83 1", "utf8mb4 46 1"))

tk.MustQuery("select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY where COLLATION_NAME='utf8mb4_bin';").Check(
testkit.Rows("utf8mb4_bin utf8mb4"))
}

// https://github.com/pingcap/tidb/issues/25467.
func (s *testInfoschemaTableSuite) TestDataTypesMaxLengthAndOctLength(c *C) {
tk := testkit.NewTestKit(c, s.store)
Expand Down
19 changes: 0 additions & 19 deletions executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,6 @@ import (
"github.com/pingcap/tidb/util/testutil"
)

func (s *testSuite3) TestCharsetDatabase(c *C) {
tk := testkit.NewTestKit(c, s.store)
testSQL := `create database if not exists cd_test_utf8 CHARACTER SET utf8 COLLATE utf8_bin;`
tk.MustExec(testSQL)

testSQL = `create database if not exists cd_test_latin1 CHARACTER SET latin1 COLLATE latin1_swedish_ci;`
tk.MustExec(testSQL)

testSQL = `use cd_test_utf8;`
tk.MustExec(testSQL)
tk.MustQuery(`select @@character_set_database;`).Check(testkit.Rows("utf8"))
tk.MustQuery(`select @@collation_database;`).Check(testkit.Rows("utf8_bin"))

testSQL = `use cd_test_latin1;`
tk.MustExec(testSQL)
tk.MustQuery(`select @@character_set_database;`).Check(testkit.Rows("latin1"))
tk.MustQuery(`select @@collation_database;`).Check(testkit.Rows("latin1_swedish_ci"))
}

func (s *testSuite3) TestDo(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("do 1, @a:=1")
Expand Down
16 changes: 0 additions & 16 deletions expression/integration_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,22 +1450,6 @@ func TestLikeWithCollation(t *testing.T) {
tk.MustQuery(`select '😛' collate utf8mb4_unicode_ci = '😋';`).Check(testkit.Rows("1"))
}

func TestCollationUnion(t *testing.T) {
// For issue 19694.
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)

tk.MustQuery("select cast('2010-09-09' as date) a union select '2010-09-09 ' order by a;").Check(testkit.Rows("2010-09-09", "2010-09-09 "))
res := tk.MustQuery("select cast('2010-09-09' as date) a union select '2010-09-09 ';")
require.Len(t, res.Rows(), 2)
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
res = tk.MustQuery("select cast('2010-09-09' as date) a union select '2010-09-09 ';")
require.Len(t, res.Rows(), 1)
}

func TestCollationPrefixClusteredIndex(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
Expand Down
11 changes: 0 additions & 11 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4763,17 +4763,6 @@ func TestIssue17287(t *testing.T) {
tk.MustQuery("execute stmt7 using @val2;").Check(testkit.Rows("1589873946"))
}

func TestIssue26989(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;")
tk.MustQuery("select position('a' in 'AA');").Check(testkit.Rows("0"))
tk.MustQuery("select locate('a', 'AA');").Check(testkit.Rows("0"))
tk.MustQuery("select locate('a', 'a');").Check(testkit.Rows("1"))
}

func TestIssue17898(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
Expand Down

0 comments on commit f2dba0e

Please sign in to comment.