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

planner: fix wrong row compare logic in expression_rewriter #8241

Merged
merged 3 commits into from Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions planner/core/expression_rewriter.go
Expand Up @@ -220,6 +220,18 @@ func (er *expressionRewriter) constructBinaryOpFunction(l expression.Expression,
if err != nil {
return nil, errors.Trace(err)
}
if evalexpr, ok := expr1.(*expression.Constant); ok {
_, isNull, err1 := evalexpr.EvalInt(er.ctx, chunk.Row{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(er.ctx, nil) is enough.

if err1 != nil || isNull {
return expr1, err1
}
}
if evalexpr, ok := expr2.(*expression.Constant); ok {
_, isNull, err1 := evalexpr.EvalInt(er.ctx, chunk.Row{})
if err1 != nil || isNull {
return expr2, err1
}
}
expr3, err = er.constructBinaryOpFunction(l, r, op)
if err != nil {
return nil, errors.Trace(err)
Expand Down
8 changes: 8 additions & 0 deletions planner/core/expression_test.go
Expand Up @@ -241,6 +241,14 @@ func (s *testExpressionSuite) TestCompareRow(c *C) {
exprStr: "row(1+3,2,3)<>row(1+3,2,3)",
resultStr: "0",
},
{
exprStr: "row(1,2,3)<row(1,NULL,3)",
resultStr: "<nil>",
},
{
exprStr: "row(1,2,3)<row(2,NULL,3)",
resultStr: "1",
},
}
s.runTests(c, tests)
}
Expand Down