Skip to content

Commit

Permalink
*: enable the new collation by default (#32016)
Browse files Browse the repository at this point in the history
ref #32015
  • Loading branch information
wjhuang2016 authored Feb 8, 2022
1 parent 077eb80 commit 3738dec
Show file tree
Hide file tree
Showing 47 changed files with 256 additions and 568 deletions.
1 change: 1 addition & 0 deletions cmd/explaintest/disable_new_collation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
lease = "0"
mem-quota-query = 34359738368
host = "127.0.0.1"
new_collations_enabled_on_first_bootstrap = false

[status]
status-host = "127.0.0.1"
Expand Down
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,11 @@ var defaultConf = Config{
AutoTLS: false,
RSAKeySize: 4096,
},
DeprecateIntegerDisplayWidth: false,
EnableEnumLengthLimit: true,
StoresRefreshInterval: defTiKVCfg.StoresRefreshInterval,
EnableForwarding: defTiKVCfg.EnableForwarding,
DeprecateIntegerDisplayWidth: false,
EnableEnumLengthLimit: true,
StoresRefreshInterval: defTiKVCfg.StoresRefreshInterval,
EnableForwarding: defTiKVCfg.EnableForwarding,
NewCollationsEnabledOnFirstBootstrap: true,
}

var (
Expand Down
2 changes: 1 addition & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ repair-table-list = []
max-server-connections = 0

# Whether new collations are enabled, as indicated by its name, this configuration entry take effect ONLY when a TiDB cluster bootstraps for the first time.
new_collations_enabled_on_first_bootstrap = false
new_collations_enabled_on_first_bootstrap = true

# Don't register information of this TiDB to etcd, so this instance of TiDB won't appear in the services like dashboard.
# This option is useful when you want to embed TiDB into your service(i.e. use TiDB as a library).
Expand Down
4 changes: 0 additions & 4 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/collate"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -1171,9 +1170,6 @@ func (s *testColumnSuiteToVerify) TestDropColumns() {
}

func TestModifyColumn(t *testing.T) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

store, err := mockstore.NewMockStore()
require.NoError(t, err)
d, err := testNewDDLAndStart(
Expand Down
3 changes: 0 additions & 3 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/testkit"
)
Expand Down Expand Up @@ -440,8 +439,6 @@ func (s *testColumnTypeChangeSuite) TestColumnTypeChangeFromIntegerToOthers(c *C
func (s *testColumnTypeChangeSuite) TestColumnTypeChangeBetweenVarcharAndNonVarchar(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk.MustExec("drop database if exists col_type_change_char;")
tk.MustExec("create database col_type_change_char;")
tk.MustExec("use col_type_change_char;")
Expand Down
6 changes: 3 additions & 3 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,11 @@ func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) {

tk.MustExec("drop table t")
tk.MustExec("create table t(a varchar(5) charset utf8 collate utf8_unicode_ci) charset utf8 collate utf8_unicode_ci")
tk.MustExec("alter table t collate utf8_danish_ci")
tk.MustExec("alter table t collate utf8_general_ci")
tbl = testGetTableByName(c, s.ctx, "test", "t")
c.Assert(tbl, NotNil)
c.Assert(tbl.Meta().Charset, Equals, "utf8")
c.Assert(tbl.Meta().Collate, Equals, "utf8_danish_ci")
c.Assert(tbl.Meta().Collate, Equals, "utf8_general_ci")
for _, col := range tbl.Meta().Columns {
c.Assert(col.Charset, Equals, "utf8")
// Column collate should remain unchanged.
Expand Down Expand Up @@ -2836,7 +2836,7 @@ func (s *testIntegrationSuite3) TestStrictDoubleTypeCheck(c *C) {
}

func (s *testSerialDBSuite) TestDuplicateErrorMessage(c *C) {
defer collate.SetNewCollationEnabledForTest(false)
defer collate.SetNewCollationEnabledForTest(true)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down
5 changes: 0 additions & 5 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
ntestkit "github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/mock"
Expand Down Expand Up @@ -367,8 +366,6 @@ func (s *testIntegrationSuite2) TestCreateTableWithHashPartition(c *C) {
}

func (s *testSerialDBSuite1) TestCreateTableWithRangeColumnPartition(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists log_message_1;")
Expand Down Expand Up @@ -3388,8 +3385,6 @@ func (s *testSerialDBSuite1) TestPartitionListWithTimeType(c *C) {
}

func (s *testSerialDBSuite1) TestPartitionListWithNewCollation(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
Expand Down
8 changes: 3 additions & 5 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import (
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/domainutil"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/mock"
Expand Down Expand Up @@ -2867,8 +2866,6 @@ func (s *testSerialDBSuite) TestCreateTable(c *C) {
tk.MustExec("use test")
failSQL := "create table t_enum (a enum('e','e'));"
tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk = testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
failSQL = "create table t_enum (a enum('e','E')) charset=utf8 collate=utf8_general_ci;"
Expand Down Expand Up @@ -3173,8 +3170,8 @@ func (s *testDBSuite2) TestCreateTableWithSetCol(c *C) {
tk.MustGetErrCode(failedSQL, errno.ErrInvalidDefault)
failedSQL = "create table t_set (a set('1', '4', '10') default '1,4,11');"
tk.MustGetErrCode(failedSQL, errno.ErrInvalidDefault)
failedSQL = "create table t_set (a set('1', '4', '10') default '1 ,4');"
tk.MustGetErrCode(failedSQL, errno.ErrInvalidDefault)
// Success when the new collation is enabled.
tk.MustExec("create table t_set (a set('1', '4', '10') default '1 ,4');")
// The type of default value is int.
failedSQL = "create table t_set (a set('1', '4', '10') default 0);"
tk.MustGetErrCode(failedSQL, errno.ErrInvalidDefault)
Expand All @@ -3183,6 +3180,7 @@ func (s *testDBSuite2) TestCreateTableWithSetCol(c *C) {

// The type of default value is int.
// It's for successful cases
tk.MustExec("drop table if exists t_set")
tk.MustExec("create table t_set (a set('1', '4', '10', '21') default 1);")
tk.MustQuery("show create table t_set").Check(testkit.Rows("t_set CREATE TABLE `t_set` (\n" +
" `a` set('1','4','10','21') DEFAULT '1'\n" +
Expand Down
6 changes: 0 additions & 6 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/gcutil"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
Expand Down Expand Up @@ -1521,9 +1520,6 @@ func (s *testSerialSuite) TestAutoRandomWithPreSplitRegion(c *C) {
}

func (s *testSerialSuite) TestModifyingColumn4NewCollations(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database dct")
tk.MustExec("use dct")
Expand Down Expand Up @@ -1557,8 +1553,6 @@ func (s *testSerialSuite) TestModifyingColumn4NewCollations(c *C) {
}

func (s *testSerialSuite) TestForbidUnsupportedCollations(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)

mustGetUnsupportedCollation := func(sql string, coll string) {
Expand Down
2 changes: 0 additions & 2 deletions executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,6 @@ func testAnalyzeIncremental(tk *testkit.TestKit, t *testing.T, dom *domain.Domai
}

func TestIssue20874(t *testing.T) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
store, clean := testkit.CreateMockStore(t)
defer clean()

Expand Down
4 changes: 0 additions & 4 deletions executor/collation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ import (
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/require"
)

func TestVecGroupChecker(t *testing.T) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

tp := &types.FieldType{Tp: mysql.TypeVarchar}
col0 := &expression.Column{
RetType: tp,
Expand Down
58 changes: 0 additions & 58 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/deadlockhistory"
"github.com/pingcap/tidb/util/gcutil"
"github.com/pingcap/tidb/util/israce"
Expand Down Expand Up @@ -322,14 +321,6 @@ func (s *testSuiteP1) TestShow(c *C) {
c.Assert(len(tk.MustQuery("show index in t").Rows()), Equals, 1)
c.Assert(len(tk.MustQuery("show index from t").Rows()), Equals, 1)

tk.MustQuery("show charset").Check(testkit.Rows(
"ascii US ASCII ascii_bin 1",
"binary binary binary 1",
"gbk Chinese Internal Code Specification gbk_bin 2",
"latin1 Latin1 latin1_bin 1",
"utf8 UTF-8 Unicode utf8_bin 3",
"utf8mb4 UTF-8 Unicode utf8mb4_bin 4",
))
c.Assert(len(tk.MustQuery("show master status").Rows()), Equals, 1)
tk.MustQuery("show create database test_show").Check(testkit.Rows("test_show CREATE DATABASE `test_show` /*!40100 DEFAULT CHARACTER SET utf8mb4 */"))
tk.MustQuery("show privileges").Check(testkit.Rows("Alter Tables To alter the table",
Expand Down Expand Up @@ -5730,54 +5721,9 @@ func (s *testSerialSuite2) TestUnsignedFeedback(c *C) {
c.Assert(result.Rows()[2][6], Equals, "keep order:false")
}

func (s *testSuiteWithCliBaseCharset) TestCharsetFeatureWithoutNewCollation(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustQuery("show charset").Check(testkit.Rows(
"ascii US ASCII ascii_bin 1",
"binary binary binary 1",
"gbk Chinese Internal Code Specification gbk_bin 2",
"latin1 Latin1 latin1_bin 1",
"utf8 UTF-8 Unicode utf8_bin 3",
"utf8mb4 UTF-8 Unicode utf8mb4_bin 4",
))
tk.MustQuery("show collation").Check(testkit.Rows(
"utf8mb4_bin utf8mb4 46 Yes Yes 1",
"latin1_bin latin1 47 Yes Yes 1",
"binary binary 63 Yes Yes 1",
"ascii_bin ascii 65 Yes Yes 1",
"utf8_bin utf8 83 Yes Yes 1",
"gbk_bin gbk 87 Yes Yes 1",
))
tk.MustExec("create table t5(a char(20), b char(20) charset utf8, c binary) charset gbk collate gbk_bin;")
}

func (s *testSuiteWithCliBaseCharset) TestCharsetFeature(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustQuery("show charset").Check(testkit.Rows(
"ascii US ASCII ascii_bin 1",
"binary binary binary 1",
"gbk Chinese Internal Code Specification gbk_chinese_ci 2",
"latin1 Latin1 latin1_bin 1",
"utf8 UTF-8 Unicode utf8_bin 3",
"utf8mb4 UTF-8 Unicode utf8mb4_bin 4",
))
tk.MustQuery("show collation").Check(testkit.Rows(
"ascii_bin ascii 65 Yes Yes 1",
"binary binary 63 Yes Yes 1",
"gbk_bin gbk 87 Yes 1",
"gbk_chinese_ci gbk 28 Yes Yes 1",
"latin1_bin latin1 47 Yes Yes 1",
"utf8_bin utf8 83 Yes Yes 1",
"utf8_general_ci utf8 33 Yes 1",
"utf8_unicode_ci utf8 192 Yes 1",
"utf8mb4_bin utf8mb4 46 Yes Yes 1",
"utf8mb4_general_ci utf8mb4 45 Yes 1",
"utf8mb4_unicode_ci utf8mb4 224 Yes 1",
))

tk.MustExec("set names gbk;")
tk.MustQuery("select @@character_set_connection;").Check(testkit.Rows("gbk"))
Expand Down Expand Up @@ -5820,8 +5766,6 @@ func (s *testSuiteWithCliBaseCharset) TestCharsetFeature(c *C) {
}

func (s *testSuiteWithCliBaseCharset) TestCharsetFeatureCollation(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
Expand All @@ -5847,8 +5791,6 @@ func (s *testSuiteWithCliBaseCharset) TestCharsetFeatureCollation(c *C) {
}

func (s *testSuiteWithCliBaseCharset) TestCharsetWithPrefixIndex(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down
4 changes: 0 additions & 4 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/testkit"
Expand Down Expand Up @@ -1496,9 +1495,6 @@ func (s *testSuite10) TestInsertRuntimeStat(c *C) {
}

func (s *testSerialSuite) TestDuplicateEntryMessage(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
for _, enable := range []variable.ClusteredIndexDefMode{variable.ClusteredIndexDefModeOn, variable.ClusteredIndexDefModeOff, variable.ClusteredIndexDefModeIntOnly} {
Expand Down
2 changes: 1 addition & 1 deletion executor/parallel_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ func (s *testSerialSuite) TestApplyWithOtherFeatures(c *C) {
tk.MustExec("set tidb_enable_parallel_apply=true")

// collation 1
collate.SetNewCollationEnabledForTest(true)
tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t(a varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, b int)")
tk.MustExec("create table t1(a varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, b int)")
Expand All @@ -405,6 +404,7 @@ func (s *testSerialSuite) TestApplyWithOtherFeatures(c *C) {
sql = "select (select min(t1.b) from t1 where t1.a >= t.a and t1.b >= t.b), (select sum(t1.b) from t1 where t1.a >= t.a and t1.b >= t.b) from t"
tk.MustQuery(sql).Sort().Check(testkit.Rows("1 10", "2 9", "3 7", "4 4"))
collate.SetNewCollationEnabledForTest(false)
defer collate.SetNewCollationEnabledForTest(true)

// plan cache
orgEnable := core.PreparedPlanCacheEnabled()
Expand Down
6 changes: 0 additions & 6 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/gcutil"
"github.com/pingcap/tidb/util/testutil"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1194,8 +1193,6 @@ func TestCoprocessorPriority(t *testing.T) {
}

func TestShowForNewCollations(t *testing.T) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
store, clean := testkit.CreateMockStore(t)
defer clean()

Expand All @@ -1221,9 +1218,6 @@ func TestForbidUnsupportedCollations(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()

collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

tk := testkit.NewTestKit(t, store)
mustGetUnsupportedCollation := func(sql string, coll string) {
tk.MustGetErrMsg(sql, fmt.Sprintf("[ddl:1273]Unsupported collation when new collation is enabled: '%s'", coll))
Expand Down
Loading

0 comments on commit 3738dec

Please sign in to comment.