Skip to content

Commit

Permalink
parser: fix missing charset and collation of handle column (#30320)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 committed Dec 2, 2021
1 parent 732b7eb commit 6898975
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions parser/charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions parser/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6898975

Please sign in to comment.