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: refine range builder when meet unsigned_int_col <cmp> -int_cnst #10471

Merged
merged 26 commits into from May 31, 2019

Conversation

b41sh
Copy link
Member

@b41sh b41sh commented May 14, 2019

What problem does this PR solve?

fix unexpected result of unsigned_int_col >= -int_cnst #10450

What is changed and how it works?

convert negative value to zero for unsigned column

Check List

Tests

  • Unit test
  • Integration test

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #10471 into master will decrease coverage by 0.0064%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #10471        +/-   ##
================================================
- Coverage   78.1703%   78.1639%   -0.0065%     
================================================
  Files           413        413                
  Lines         87514      87566        +52     
================================================
+ Hits          68410      68445        +35     
- Misses        13961      13975        +14     
- Partials       5143       5146         +3

@@ -660,6 +660,13 @@ func (s *testRangerSuite) TestIndexRangeForUnsignedInt(c *C) {
filterConds: "[]",
resultStr: `[(NULL,1) (2,9223372036854775810) (9223372036854775810,+inf]]`,
},
{
indexPos: 0,
exprStr: `a >= -2`,
Copy link
Contributor

Choose a reason for hiding this comment

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

If a == -2, we'll get [eq(test.t.a), 0]?
Does it seem to be wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

no
If a == -2, we'll get [eq(test.t.a), -2]
convertPoint function only affect ranges

util/ranger/ranger_test.go Outdated Show resolved Hide resolved
@b41sh
Copy link
Member Author

b41sh commented May 16, 2019

@XuHuaiyu @winoros PTAL

@shenli
Copy link
Member

shenli commented May 22, 2019

@b41sh Could you add some comments and test cases?

@qw4990 qw4990 self-requested a review May 23, 2019 02:19
@zz-jason zz-jason added sig/planner SIG: Planner contribution This PR is from a community contributor. type/bug-fix This PR fixes a bug. labels May 23, 2019
value.Kind() == types.KindMysqlDecimal {
needFix = true
zeroValue.SetMysqlDecimal(new(types.MyDecimal))
}
Copy link
Member

Choose a reason for hiding this comment

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

should we also consider float or double values?

Copy link
Member Author

Choose a reason for hiding this comment

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

we don't need consider float and decimal, only unsigned integer will convert a negative number to positive number in function func (d *Datum) convertToUint(sc *stmtctx.StatementContext, target *FieldType) (Datum, error)

@XuHuaiyu
Copy link
Contributor

It'll be better to add the integration tests mentioned in #10450.

@XuHuaiyu XuHuaiyu requested a review from winoros May 28, 2019 05:36
@@ -250,6 +250,28 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []point {
return nil
}

// if the colunm is unsigned integer and the value
// is less than zero, we only need compare with zero.
if mysql.HasUnsignedFlag(ft.Flag) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we extract the part as a function like handleUnsignedIntCol?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@XuHuaiyu
Copy link
Contributor

PTAL @winoros

@b41sh
Copy link
Member Author

b41sh commented May 28, 2019

I have extract the code as a function handleUnsignedIntCol PTAL @XuHuaiyu @winoros

util/ranger/points.go Outdated Show resolved Hide resolved
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

rest part is ok for me

util/ranger/points.go Outdated Show resolved Hide resolved
util/ranger/points.go Outdated Show resolved Hide resolved
util/ranger/points.go Outdated Show resolved Hide resolved
util/ranger/points.go Show resolved Hide resolved
@@ -250,6 +250,11 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []point {
return nil
}

value, op, isValidRange := handleUnsignedIntCol(ft, value, op)
if isValidRange == false {
Copy link
Contributor

Choose a reason for hiding this comment

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

if !isValidRange

@XuHuaiyu XuHuaiyu requested a review from winoros May 30, 2019 04:15
@XuHuaiyu
Copy link
Contributor

/run-all-tests

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@XuHuaiyu XuHuaiyu added the status/LGT1 Indicates that a PR has LGTM 1. label May 30, 2019
util/ranger/points.go Outdated Show resolved Hide resolved
util/ranger/points.go Outdated Show resolved Hide resolved
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm
Thanks for you contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/bug-fix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants