Skip to content

Commit

Permalink
ddl: fix alter table charset bug that change blob column type to text (
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and zimulala committed Jun 10, 2019
1 parent 1602766 commit d7129e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
"github.com/pingcap/tidb/util/testutil"
)

var _ = Suite(&testIntegrationSuite{})
Expand Down Expand Up @@ -390,6 +391,16 @@ func (s *testIntegrationSuite) 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 *testIntegrationSuite) TestCaseInsensitiveCharsetAndCollate(c *C) {
Expand Down
3 changes: 2 additions & 1 deletion ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"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"
Expand Down Expand Up @@ -511,7 +512,7 @@ func onModifyTableCharsetAndCollate(t *meta.Meta, job *model.Job) (ver int64, _
}
// 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 {
Expand Down

0 comments on commit d7129e2

Please sign in to comment.