From 6898975a7d0e01be17d11f8cbffc202966801071 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Thu, 2 Dec 2021 17:05:54 +0800 Subject: [PATCH] parser: fix missing charset and collation of handle column (#30320) --- parser/charset/charset.go | 11 ++++++----- parser/model/model.go | 2 ++ parser/model/model_test.go | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/parser/charset/charset.go b/parser/charset/charset.go index 091800dd63003..0fdff1b75c13e 100644 --- a/parser/charset/charset.go +++ b/parser/charset/charset.go @@ -18,8 +18,10 @@ import ( "strings" "github.com/pingcap/errors" + "github.com/pingcap/log" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/terror" + "go.uber.org/zap" ) var ( @@ -158,11 +160,10 @@ func GetCharsetInfoByID(coID int) (string, string, error) { return collation.CharsetName, collation.Name, nil } - // TODO: uncomment it when issue #29697 be closed - // log.Warn( - // "Unable to get collation name from collation ID, return default charset and collation instead.", - // zap.Int("ID", coID), - // zap.Stack("stack")) + log.Warn( + "unable to get collation name from collation ID, return default charset and collation instead", + zap.Int("ID", coID), + zap.Stack("stack")) return mysql.DefaultCharset, mysql.DefaultCollationName, errors.Errorf("Unknown collation id %d", coID) } diff --git a/parser/model/model.go b/parser/model/model.go index 49d7cbc351194..20e770c607149 100644 --- a/parser/model/model.go +++ b/parser/model/model.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/parser/auth" + "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/types" ) @@ -628,6 +629,7 @@ func NewExtraHandleColInfo() *ColumnInfo { colInfo.Flag = mysql.PriKeyFlag | mysql.NotNullFlag colInfo.Tp = mysql.TypeLonglong colInfo.Flen, colInfo.Decimal = mysql.GetDefaultFieldLengthAndDecimal(mysql.TypeLonglong) + colInfo.Charset, colInfo.Collate = charset.CharsetBin, charset.CollationBin return colInfo } diff --git a/parser/model/model_test.go b/parser/model/model_test.go index 190932628c391..8c2365ea47ca4 100644 --- a/parser/model/model_test.go +++ b/parser/model/model_test.go @@ -19,6 +19,7 @@ import ( "testing" "time" + "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/types" "github.com/stretchr/testify/require" @@ -134,6 +135,8 @@ func TestModelBasic(t *testing.T) { extraPK := NewExtraHandleColInfo() require.Equal(t, mysql.NotNullFlag|mysql.PriKeyFlag, extraPK.Flag) + require.Equal(t, charset.CharsetBin, extraPK.Charset) + require.Equal(t, charset.CollationBin, extraPK.Collate) } func TestJobStartTime(t *testing.T) {