-
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 tikv crash when bool like cast(bit as char)
#57484
Conversation
Hi @lcwangchao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
031c6bb
to
6af72e2
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #57484 +/- ##
================================================
+ Coverage 72.8488% 73.3407% +0.4918%
================================================
Files 1672 1676 +4
Lines 462666 470868 +8202
================================================
+ Hits 337047 345338 +8291
+ Misses 104821 104711 -110
- Partials 20798 20819 +21
Flags with carried forward coverage won't be shown. Click here to find out more.
|
6af72e2
to
4ed280e
Compare
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/retest |
@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
4108a75
to
48abcf7
Compare
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 for the optimizer part.
[LGTM Timeline notifier]Timeline:
|
sig.setPbCode(tipb.ScalarFuncSig_CastStringAsString) | ||
return sig, nil | ||
if ft := args[0].GetType(ctx.GetEvalCtx()); ft.Hybrid() { | ||
castBitAsUnBinary := ft.GetType() == mysql.TypeBit && c.tp.GetCharset() != charset.CharsetBin |
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.
For other type that store binary string like Blob
, will TiDB meet the same problem?
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.
No, only the "hybrid" types will address this issue. Their "EvalType" may return ETInt
, but when converting them to strings, we should be recognized as bytes instead.
I did not handle other hybrid types like enum and set in this PR, because in most time their should have a legal encoding and another reason is to introduce less logic change in this fix.
castTp := types.NewFieldType(mysql.TypeString) | ||
castTp.SetCharset(charset.CharsetBin) | ||
castTp.SetCollate(charset.CollationBin) | ||
castByteAsStringFunc, err := NewFunction(mock.NewContext(), ast.Cast, castTp, byteColumn) |
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.
This function can not be push down to TiKV because from_binary
can not be push down to TiKV?
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.
no, I think it's the issue: #51877 The tidb have some special logic for function conv
. When converting a BIT type, it uses conv(cast(bit as char))
which uses cast
to cast bit to string, but conv
should also handles the string as a binary number instead of string...
See:
tidb/pkg/expression/builtin_math.go
Lines 1281 to 1290 in 9530fdc
if x.FuncName.L == ast.Cast { | |
arg0 := x.GetArgs()[0] | |
if arg0.GetType(ctx).Hybrid() || IsBinaryLiteral(arg0) { | |
str, isNull, err = arg0.EvalString(ctx, row) | |
if isNull || err != nil { | |
return str, isNull, err | |
} | |
d := types.NewStringDatum(str) | |
str = d.GetBinaryLiteral().ToBitLiteralString(true) | |
} |
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 added a comment in this test
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.
This test is not related with this issue, but we should update it to set to casted type as bin collations to make the test pass.
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
@lcwangchao: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
In response to a cherrypick label: new pull request created to branch |
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
/cherry-pick release-7.5 |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@lcwangchao: new pull request created to branch In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/cherry-pick release-8.1 |
@lcwangchao: new pull request created to branch In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
/cherry-pick release-7.1 |
@lcwangchao: new pull request created to branch In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
/cherry-pick release-8.1 |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@lcwangchao: new pull request created to branch In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/cherry-pick release-6.5 |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@lcwangchao: new pull request created to branch In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #56494
What changed and how does it work?
When casting the bit type to a non binary string, this PR first convert bits to binary string first. This can ensure
HandleBinaryLiteral
can be used in the following code and convert binary to the specified collation with right behavior.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.