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:fix case-when and coalesce type inferer #2918

Merged
merged 6 commits into from
Mar 29, 2017
Merged

plan:fix case-when and coalesce type inferer #2918

merged 6 commits into from
Mar 29, 2017

Conversation

coocood
coocood previously approved these changes Mar 24, 2017
return &currType
}

func aggClassType(args []ast.ExprNode, flag *uint) types.TypeClass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to 'aggTypeClass' it better.

@@ -544,6 +557,20 @@ func (v *typeInferrer) convertValueToColumnTypeIfNeeded(x *ast.PatternInExpr) {
}

func aggArgsType(args []ast.ExprNode) *types.FieldType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to aggFieldType is better.

if unsigned {
ft.Flag |= mysql.UnsignedFlag
*flag |= mysql.UnsignedFlag
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
  *flag &= ^mysql.UnsignedFlag
}

@@ -411,7 +411,22 @@ func (v *typeInferrer) handleFuncCallExpr(x *ast.FuncCallExpr) {
chs = v.defaultCharset
tp.Flen = 40
case ast.Coalesce:
var gotBinString bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be computed and returned in aggClassType.

currType.Charset = t.Charset
currType.Collate = t.Collate
var gotBinString = false
exprs := make([]ast.ExprNode, len(x.WhenClauses))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a larger capacity slice for else.

for i, w := range x.WhenClauses {
exprs[i] = w.Result
ft := w.Result.GetType()
if ft.ToClass() == types.ClassString && mysql.HasBinaryFlag(ft.Flag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it in aggClassType

@coocood coocood dismissed their stale review March 24, 2017 05:24

not approved yet

@XuHuaiyu
Copy link
Contributor Author

PTAL @coocood

for _, arg := range args {
argFieldType := arg.GetType()
if argFieldType.Tp == mysql.TypeNull {
continue
}
if argFieldType.ToClass() == types.ClassString && mysql.HasBinaryFlag(argFieldType.Flag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argTypeClass := argFieldType.ToClass()

Then it can be used multiple times.

ft.Charset, ft.Collate = types.DefaultCharsetForType(ft.Tp)
return ft
if tpClass == types.ClassString && !gotBinString {
*flag &= ^uint(mysql.BinaryFlag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated work.
Better define a function that turn flag on and off like

func setTypeFlag(*flag uint, flagItem uint, on bool)

@coocood
Copy link
Member

coocood commented Mar 27, 2017

LGTM
@hanfei1991 PTAL

Copy link
Member

@hanfei1991 hanfei1991 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coocood coocood merged commit b48e5fe into master Mar 29, 2017
@coocood coocood deleted the xhy/infer-case branch March 29, 2017 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants