Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan: refine return type, charset and collation for 'get variable' expression #4550

Merged
merged 9 commits into from
Sep 19, 2017
6 changes: 5 additions & 1 deletion plan/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/parser/opcode"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/sessionctx/varsutil"
"github.com/pingcap/tidb/util/charset"
"github.com/pingcap/tidb/util/types"
Expand Down Expand Up @@ -764,7 +765,10 @@ func (er *expressionRewriter) rewriteVariable(v *ast.VariableExpr) {
er.err = errors.Trace(err)
return
}
er.ctxStack = append(er.ctxStack, datumToConstant(types.NewStringDatum(val), mysql.TypeString))
e := datumToConstant(types.NewStringDatum(val), mysql.TypeVarString)
e.RetType.Charset = er.ctx.GetSessionVars().Systems[variable.CharacterSetConnection]
e.RetType.Collate = er.ctx.GetSessionVars().Systems[variable.CollationConnection]
er.ctxStack = append(er.ctxStack, e)
return
}

Expand Down
9 changes: 2 additions & 7 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ func NewSessionVars() *SessionVars {
}
}

const (
characterSetConnection = "character_set_connection"
collationConnection = "collation_connection"
)

// GetCharsetInfo gets charset and collation for current context.
// What character set should the server translate a statement to after receiving it?
// For this, the server uses the character_set_connection and collation_connection system variables.
Expand All @@ -263,8 +258,8 @@ const (
// have their own collation, which has a higher collation precedence.
// See https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
func (s *SessionVars) GetCharsetInfo() (charset, collation string) {
charset = s.Systems[characterSetConnection]
collation = s.Systems[collationConnection]
charset = s.Systems[CharacterSetConnection]
collation = s.Systems[CollationConnection]
return
}

Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ var SetNamesVariables = []string{
}

const (
// CharacterSetConnection is the name for character_set_connection system variable.
CharacterSetConnection = "character_set_connection"
// CollationConnection is the name for collation_connection system variable.
CollationConnection = "collation_connection"
// CharsetDatabase is the name for character_set_database system variable.
Expand Down