Skip to content

Commit

Permalink
expression: fix incorrect result of logical operators for vectorized …
Browse files Browse the repository at this point in the history
…expression evaluation (pingcap#15891)
  • Loading branch information
Reminiscent authored and sre-bot committed Mar 31, 2020
1 parent 52bf81d commit 9ed5c3e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
9 changes: 9 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5351,3 +5351,12 @@ select 6;`
tk.MustQuery(sql).Check(testutil.RowsWithSep("|", cas.result...))
}
}

func (s *testSuite1) TestIssue15718(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists tt;")
tk.MustExec("create table tt(a decimal(10, 0), b varchar(1), c time);")
tk.MustExec("insert into tt values(0, '2', null), (7, null, '1122'), (NULL, 'w', null), (NULL, '2', '3344'), (NULL, NULL, '0'), (7, 'f', '33');")
tk.MustQuery("select a and b as d, a or c as e from tt;").Check(testkit.Rows("0 <nil>", "<nil> 1", "0 <nil>", "<nil> 1", "<nil> <nil>", "0 1"))
}
40 changes: 34 additions & 6 deletions expression/builtin_op_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ func (b *builtinDecimalIsFalseSig) vecEvalInt(input *chunk.Chunk, result *chunk.
i64s := result.Int64s()

for i := 0; i < numRows; i++ {
if buf.IsNull(i) || !decs[i].IsZero() {
isNull := buf.IsNull(i)
if b.keepNull && isNull {
result.SetNull(i, true)
continue
}
if isNull || !decs[i].IsZero() {
i64s[i] = 0
} else {
i64s[i] = 1
Expand All @@ -162,7 +167,11 @@ func (b *builtinIntIsFalseSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu
}
i64s := result.Int64s()
for i := 0; i < numRows; i++ {
if result.IsNull(i) {
isNull := result.IsNull(i)
if b.keepNull && isNull {
continue
}
if isNull {
i64s[i] = 0
result.SetNull(i, false)
} else if i64s[i] != 0 {
Expand Down Expand Up @@ -467,7 +476,12 @@ func (b *builtinRealIsFalseSig) vecEvalInt(input *chunk.Chunk, result *chunk.Col
i64s := result.Int64s()
bufI64s := buf.Int64s()
for i := 0; i < numRows; i++ {
if buf.IsNull(i) || bufI64s[i] != 0 {
isNull := buf.IsNull(i)
if b.keepNull && isNull {
result.SetNull(i, true)
continue
}
if isNull || bufI64s[i] != 0 {
i64s[i] = 0
} else {
i64s[i] = 1
Expand Down Expand Up @@ -665,7 +679,12 @@ func (b *builtinRealIsTrueSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu
f64s := buf.Float64s()
i64s := result.Int64s()
for i := 0; i < numRows; i++ {
if buf.IsNull(i) || f64s[i] == 0 {
isNull := buf.IsNull(i)
if b.keepNull && isNull {
result.SetNull(i, true)
continue
}
if isNull || f64s[i] == 0 {
i64s[i] = 0
} else {
i64s[i] = 1
Expand Down Expand Up @@ -694,7 +713,12 @@ func (b *builtinDecimalIsTrueSig) vecEvalInt(input *chunk.Chunk, result *chunk.C
i64s := result.Int64s()

for i := 0; i < numRows; i++ {
if buf.IsNull(i) || decs[i].IsZero() {
isNull := buf.IsNull(i)
if b.keepNull && isNull {
result.SetNull(i, true)
continue
}
if isNull || decs[i].IsZero() {
i64s[i] = 0
} else {
i64s[i] = 1
Expand All @@ -714,7 +738,11 @@ func (b *builtinIntIsTrueSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colum
}
i64s := result.Int64s()
for i := 0; i < numRows; i++ {
if result.IsNull(i) {
isNull := result.IsNull(i)
if b.keepNull && isNull {
continue
}
if isNull {
i64s[i] = 0
result.SetNull(i, false)
} else if i64s[i] != 0 {
Expand Down
4 changes: 4 additions & 0 deletions expression/builtin_op_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var vecBuiltinOpCases = map[string][]vecExprBenchCase{
},
ast.LogicOr: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETReal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETDuration}},
},
ast.LogicXor: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
Expand All @@ -47,6 +49,8 @@ var vecBuiltinOpCases = map[string][]vecExprBenchCase{
},
ast.LogicAnd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal, types.ETReal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETDuration}},
},
ast.Or: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
Expand Down

0 comments on commit 9ed5c3e

Please sign in to comment.