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 painc on substring_index #7806

Merged
merged 8 commits into from
Oct 8, 2018

Conversation

zz-jason
Copy link
Member

What problem does this PR solve?

This PR fixes the panic in substring_index:

select substring_index('xyz', 'abc', 9223372036854775808);

What is changed and how it works?

Check List

Tests

  • Unit test

@@ -1208,6 +1208,9 @@ func (b *builtinSubstringIndexSig) evalString(row chunk.Row) (d string, isNull b
end = count
}
} else {
if count <= -int64(math.Pow(2, 63)) {
return "", false, nil
}
// If count is negative, everything to the right of the final delimiter (counting from the right) is returned.
count = -count
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 just check count < 0 again here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we don't need to check count<0 again. Because once we enter the above else branch, count<0 is guaranteed.

Copy link
Contributor

Choose a reason for hiding this comment

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

the else branch indicates the count is < 0, then we assign -count to count, I mean, if we check count < 0 again after assigning -count to count, we can remove if count <= -int64(math.Pow(2, 63)) check then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. Comment addressed, PTAL again

@zz-jason
Copy link
Member Author

zz-jason commented Oct 8, 2018

@XuHuaiyu @winoros PTAL

@@ -1208,6 +1208,9 @@ func (b *builtinSubstringIndexSig) evalString(row chunk.Row) (d string, isNull b
end = count
}
} else {
if count <= -int64(math.Pow(2, 63)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. -(1<<63) is ok?
  2. Do we need to leave a comment here to explain this check?

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

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

@zz-jason
Copy link
Member Author

zz-jason commented Oct 8, 2018

/run-all-tests

@zz-jason
Copy link
Member Author

zz-jason commented Oct 8, 2018

/run-common-test tidb-test=pr/631

@zz-jason
Copy link
Member Author

zz-jason commented Oct 8, 2018

/run-integration-common-test tidb-test=pr/631

@zz-jason zz-jason merged commit aec4814 into pingcap:master Oct 8, 2018
@zz-jason zz-jason deleted the dev/fix-substr-index branch October 8, 2018 14:07
@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. status/all tests passed labels Oct 8, 2018
zz-jason added a commit to zz-jason/tidb that referenced this pull request Oct 15, 2018
zz-jason added a commit to zz-jason/tidb that referenced this pull request Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants