Skip to content

Commit

Permalink
util: fix bad number error with DISTINCT when dividing long decimals (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TszKitLo40 authored Dec 18, 2020
1 parent 503819b commit e9b11b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7267,3 +7267,8 @@ func (s *testSuite) Test12201(c *C) {
tk.MustQuery("select * from e where case e when 1 then e end").Check(testkit.Rows("a"))
tk.MustQuery("select * from e where case 1 when e then e end").Check(testkit.Rows("a"))
}

func (s *testSuite) TestIssue15563(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustQuery("select distinct 0.7544678906163867 / 0.68234634;").Check(testkit.Rows("1.10569639842486251190"))
}
4 changes: 4 additions & 0 deletions util/codec/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package codec
import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
)

Expand All @@ -24,6 +25,9 @@ func EncodeDecimal(b []byte, dec *types.MyDecimal, precision, frac int) ([]byte,
if precision == 0 {
precision, frac = dec.PrecisionAndFrac()
}
if frac > mysql.MaxDecimalScale {
frac = mysql.MaxDecimalScale
}
b = append(b, byte(precision), byte(frac))
b, err := dec.WriteBin(precision, frac, b)
return b, errors.Trace(err)
Expand Down

0 comments on commit e9b11b7

Please sign in to comment.