Skip to content

Commit

Permalink
Merge branch 'master' into qiuyesuifeng/update-vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyesuifeng committed May 10, 2016
2 parents 29ad227 + b32b26a commit e5de4e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions optimizer/typeinferer.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ func (v *typeInferrer) handleFuncCallExpr(x *ast.FuncCallExpr) {
switch x.FnName.L {
case "abs", "ifnull", "nullif":
tp = x.Args[0].GetType()
// TODO: We should cover all types.
if x.FnName.L == "abs" && tp.Tp == mysql.TypeDatetime {
tp = types.NewFieldType(mysql.TypeDouble)
}
case "pow", "power", "rand":
tp = types.NewFieldType(mysql.TypeDouble)
case "curdate", "current_date", "date":
Expand Down
1 change: 1 addition & 0 deletions optimizer/typeinferer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (ts *testTypeInferrerSuite) TestInferType(c *C) {
{"count(c1)", mysql.TypeLonglong, charset.CharsetBin},
{"abs(1)", mysql.TypeLonglong, charset.CharsetBin},
{"abs(1.1)", mysql.TypeNewDecimal, charset.CharsetBin},
{"abs(cast(\"20150817015609\" as DATETIME))", mysql.TypeDouble, charset.CharsetBin},
{"IF(1>2,2,3)", mysql.TypeLonglong, charset.CharsetBin},
{"IFNULL(1,0)", mysql.TypeLonglong, charset.CharsetBin},
{"POW(2,2)", mysql.TypeDouble, charset.CharsetBin},
Expand Down

0 comments on commit e5de4e5

Please sign in to comment.