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

expression: fix incorrect result of logical operators for vectorized expression evaluation #15891

Merged
merged 5 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5362,3 +5362,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