-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
expression/builtin_string.go
Outdated
@@ -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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- -(1<<63) is ok?
- Do we need to leave a comment here to explain this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
/run-common-test tidb-test=pr/631 |
/run-integration-common-test tidb-test=pr/631 |
What problem does this PR solve?
This PR fixes the panic in
substring_index
:What is changed and how it works?
Check List
Tests