Skip to content

Commit

Permalink
Revert "expression: Fix greatest and least function lost decimal prec…
Browse files Browse the repository at this point in the history
…ision compared with MySQL" (pingcap#26046)
  • Loading branch information
lzmhhh123 authored Jul 9, 2021
1 parent f0f7091 commit eedb191
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 101 deletions.
44 changes: 0 additions & 44 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,38 +565,16 @@ func (b *builtinGreatestDecimalSig) evalDecimal(row chunk.Row) (max *types.MyDec
if isNull || err != nil {
return max, isNull, err
}

var digitFrac = max.GetDigitsFrac()
var digitsInt = max.GetDigitsInt()
var resultFrac = max.GetResultFrac()

for i := 1; i < len(b.args); i++ {
var v *types.MyDecimal
v, isNull, err = b.args[i].EvalDecimal(b.ctx, row)
if isNull || err != nil {
return max, isNull, err
}

if v.GetResultFrac() > resultFrac {
resultFrac = v.GetResultFrac()
}

if v.GetDigitsFrac() > digitFrac {
digitFrac = v.GetDigitsFrac()
}

if v.GetDigitsInt() > digitsInt {
digitsInt = v.GetDigitsInt()
}

if v.Compare(max) > 0 {
max = v
}
}

max.SetResultFrac(resultFrac)
max.SetDigitsFrac(digitFrac)
max.SetDigitsInt(digitsInt)
return
}

Expand Down Expand Up @@ -804,38 +782,16 @@ func (b *builtinLeastDecimalSig) evalDecimal(row chunk.Row) (min *types.MyDecima
if isNull || err != nil {
return min, isNull, err
}

var digitFrac = min.GetDigitsFrac()
var digitsInt = min.GetDigitsInt()
var resultFrac = min.GetResultFrac()

for i := 1; i < len(b.args); i++ {
var v *types.MyDecimal
v, isNull, err = b.args[i].EvalDecimal(b.ctx, row)
if isNull || err != nil {
return min, isNull, err
}

if v.GetResultFrac() > resultFrac {
resultFrac = v.GetResultFrac()
}

if v.GetDigitsFrac() > digitFrac {
digitFrac = v.GetDigitsFrac()
}

if v.GetDigitsInt() > digitsInt {
digitsInt = v.GetDigitsInt()
}

if v.Compare(min) < 0 {
min = v
}
}

min.SetResultFrac(resultFrac)
min.SetDigitsFrac(digitFrac)
min.SetDigitsInt(digitsInt)
return
}

Expand Down
8 changes: 0 additions & 8 deletions expression/builtin_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,6 @@ func (s *testEvaluatorSuite) TestGreatestLeastFunc(c *C) {
[]interface{}{tm, "123"},
curTimeString, "123", false, false,
},
{
[]interface{}{2.0, 3, 1.000, 4.00},
4.000, 1.000, false, false,
},
{
[]interface{}{2.0, 3, 1.00, 4},
4.00, 1.00, false, false,
},
{
[]interface{}{tm, 123},
curTimeString, "123", false, false,
Expand Down
18 changes: 0 additions & 18 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package expression
import (
"strings"

"github.com/cznic/mathutil"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand Down Expand Up @@ -46,18 +45,9 @@ func (b *builtinGreatestDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *c
continue
}
v := buf.GetDecimal(i)

var maxDigitFrac = mathutil.MaxInt8(v.GetDigitsFrac(), d64s[i].GetDigitsFrac())
var maxDigitInt = mathutil.MaxInt8(v.GetDigitsInt(), d64s[i].GetDigitsInt())
var maxResultFrac = mathutil.MaxInt8(v.GetResultFrac(), d64s[i].GetResultFrac())

if v.Compare(&d64s[i]) > 0 {
d64s[i] = *v
}

d64s[i].SetDigitsFrac(maxDigitFrac)
d64s[i].SetDigitsInt(maxDigitInt)
d64s[i].SetResultFrac(maxResultFrac)
}
}
return nil
Expand Down Expand Up @@ -90,17 +80,9 @@ func (b *builtinLeastDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chun
continue
}
v := buf.GetDecimal(i)
var maxDigitFrac = mathutil.MaxInt8(v.GetDigitsFrac(), d64s[i].GetDigitsFrac())
var maxDigitInt = mathutil.MaxInt8(v.GetDigitsInt(), d64s[i].GetDigitsInt())
var maxResultFrac = mathutil.MaxInt8(v.GetResultFrac(), d64s[i].GetResultFrac())

if v.Compare(&d64s[i]) < 0 {
d64s[i] = *v
}

d64s[i].SetDigitsFrac(maxDigitFrac)
d64s[i].SetDigitsInt(maxDigitInt)
d64s[i].SetResultFrac(maxResultFrac)
}
}
return nil
Expand Down
11 changes: 0 additions & 11 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9800,17 +9800,6 @@ func (s *testIntegrationSuite2) TestIssue25591(c *C) {
rows.Check(testkit.Rows())
}

func (s *testIntegrationSuite2) TestGreatestLeast(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(id int, nu decimal(10, 2));")
tk.MustExec("insert into t values(1, 2.00),(2, 1.00),(3,3.00);")

tk.MustQuery("select id, greatest(nu, 1, 2), least(nu, 1.000, 3.0000) from t order by id").Check(
testkit.Rows("1 2.00 1.0000", "2 2.00 1.0000", "3 3.00 1.0000"))
}

func (s *testIntegrationSuite2) TestIssue25526(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
20 changes: 0 additions & 20 deletions types/mydecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,6 @@ type MyDecimal struct {
wordBuf [maxWordBufLen]int32
}

// SetDigitsInt set value of digitsInt
func (d *MyDecimal) SetDigitsInt(digitsInt int8) {
d.digitsInt = digitsInt
}

// SetDigitsFrac set value of digitsFrac
func (d *MyDecimal) SetDigitsFrac(digitsFrac int8) {
d.digitsFrac = digitsFrac
}

// GetResultFrac get value of resultFrac
func (d *MyDecimal) GetResultFrac() int8 {
return d.resultFrac
}

// SetResultFrac set value of resultFrac
func (d *MyDecimal) SetResultFrac(resultFrac int8) {
d.resultFrac = resultFrac
}

// IsNegative returns whether a decimal is negative.
func (d *MyDecimal) IsNegative() bool {
return d.negative
Expand Down

0 comments on commit eedb191

Please sign in to comment.