Skip to content
Permalink
Browse files

ddl: fix alter table charset bug that change blob column type to text(#…

  • Loading branch information...
crazycs520 authored and winkyao committed Jun 5, 2019
1 parent 9501014 commit 42b5413690ace6e31e8bbb084401ab131efd71bb
Showing with 13 additions and 1 deletion.
  1. +11 −0 ddl/db_integration_test.go
  2. +2 −1 ddl/table.go
@@ -44,6 +44,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testutil"
)

var _ = Suite(&testIntegrationSuite1{&testIntegrationSuite{}})
@@ -738,6 +739,16 @@ func (s *testIntegrationSuite10) TestChangingTableCharset(c *C) {
c.Assert(tbl.Meta().Columns[0].Collate, Equals, "")
tk.MustExec("alter table t convert to charset utf8mb4;")
checkCharset()

tk.MustExec("drop table t")
tk.MustExec("create table t (a blob) character set utf8;")
tk.MustExec("alter table t charset=utf8mb4 collate=utf8mb4_bin;")
tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|",
"t CREATE TABLE `t` (\n"+
" `a` blob DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))

}

func (s *testIntegrationSuite7) TestCaseInsensitiveCharsetAndCollate(c *C) {
@@ -23,6 +23,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/model"
field_types "github.com/pingcap/parser/types"
"github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
@@ -745,7 +746,7 @@ func onModifyTableCharsetAndCollate(t *meta.Meta, job *model.Job) (ver int64, _
tblInfo.Collate = toCollate
// update column charset.
for _, col := range tblInfo.Columns {
if typesNeedCharset(col.Tp) {
if field_types.HasCharset(&col.FieldType) {
col.Charset = toCharset
col.Collate = toCollate
} else {

0 comments on commit 42b5413

Please sign in to comment.
You can’t perform that action at this time.