-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: don't cast collation for in expression is the new collation is disabled #52812
Conversation
pkg/expression/collation.go
Outdated
if err != nil && !collate.NewCollationEnabled() { | ||
// args[0] can't be nil here. | ||
// Use the collation of the first argument instead of returning an error. | ||
et = &ExprCollation{ |
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.
It'll cause some behavior change 🤔 . For example:
select convert('1' using utf8) collate utf8_bin = convert('1' using utf8) collate utf8_general_ci;
It'll return an error before this PR no matter whether new_collation
is enabled or not, but after this PR, it'll return without any error.
For this issue, I propose two other options, but none of them is perfect 🤦 :
-
Avoid constant propogation in this case. We can replace the
NewFunctionInternal
withNewFunction
in theColumnSubstituteImpl
, and check theerr
. If it returns an err, we can avoidsubstitute
in this case. -
Add back the
newExpr.SetCoercibility(v.Coercibility())
removed in expression, cmd: fix ColumnSubstitute and allow some cases to substitute #38826. It sounds better because actually the coercibility (aftersubstitute
) should be theColumn
(2). I'm not sure 100% sure, but maybe we can fix the issue found in expression, cmd: fix ColumnSubstitute and allow some cases to substitute #38826 byClone
thenewExpr
beforeSetCoercibility
.
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 proposal 2 is not correct, because the following case will fail:
create table t (a char(10) collate utf8mb4_bin, b char(10) collate utf8mb4_general_ci);
insert into t values ('a', 'A');
select * from t t1, t t2 where t1.a=t2.b and t2.b='a' collate utf8mb4_general_ci;
It's expected to return 0 row, but it returns 1 row.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #52812 +/- ##
================================================
+ Coverage 72.3233% 74.8697% +2.5463%
================================================
Files 1473 1478 +5
Lines 427451 433899 +6448
================================================
+ Hits 309147 324859 +15712
+ Misses 99013 89220 -9793
- Partials 19291 19820 +529
Flags with carried forward coverage won't be shown. Click here to find out more.
|
9440aa5
to
0d7d490
Compare
@@ -1951,6 +1951,9 @@ func (er *expressionRewriter) castCollationForIn(colLen int, elemCnt int, stkLen | |||
if colLen != 1 { | |||
return | |||
} | |||
if !collate.NewCollationEnabled() { |
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.
Please add a comment here to tell why castCollationForIn
is disabled when new collation is not enabled? It's not intuitive. IIUC, it works because it didn't set coercibility to 0, so that the following panic (mix collation with 0 coercibility) will not happen.
I personally prefer to also enable the collation check in ColumnSubstituteImpl
for old collation, but it may cause big performance impact and need manually workaround (rewriting SQL), so it's not good.
This solution is also fine for me, as I cannot think up any counter example in old collation.
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: winoros, YangKeao The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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>
In response to a cherrypick label: new pull request created to branch |
…on is disabled (pingcap#52812) close pingcap#52772
What problem does this PR solve?
Issue Number: close #52772
Problem Summary:
If the new collation is disabled, we should not cast collation for in expression, which may lead to panic in the issue case.
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.