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 wrong flen from baseFunctionClass #56607

Merged
merged 6 commits into from
Nov 19, 2024

Conversation

joechenrh
Copy link
Contributor

@joechenrh joechenrh commented Oct 12, 2024

What problem does this PR solve?

Issue Number: close #56587

Problem Summary:

What changed and how does it work?

Previously, quoteFunctionClass may return type with flen = 0 when the underlying argument has the UnspecifiedLength which equals to -1.

bf.tp.SetFlen(2*args[0].GetType(ctx.GetEvalCtx()).GetFlen() + 2)

And this type will be passed into LogicalUnionAll and a wrong type is deduced.

resultTp := col.RetType
for j := 1; j < len(u.Children()); j++ {
tmpExprs = append(tmpExprs, u.Children()[j].Schema().Columns[i])
childTp := u.Children()[j].Schema().Columns[i].RetType
resultTp = unionJoinFieldType(resultTp, childTp)
}

Some other functions also have this problem, for example:

mysql> select elt(2, "123", cast('abcdefg' as char)) union all select "1234";
+----------------------------------------+
| elt(2, "123", cast('abcdefg' as char)) |
+----------------------------------------+
| abcd                                   |
| 1234                                   |
+----------------------------------------+
2 rows in set, 1 warning (0.00 sec)

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 12, 2024
Copy link

tiprow bot commented Oct 12, 2024

Hi @joechenrh. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.8608%. Comparing base (0e3efb6) to head (3afd694).
Report is 8 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #56607        +/-   ##
================================================
+ Coverage   72.8325%   74.8608%   +2.0283%     
================================================
  Files          1672       1717        +45     
  Lines        462833     472049      +9216     
================================================
+ Hits         337093     353380     +16287     
+ Misses       104947      96604      -8343     
- Partials      20793      22065      +1272     
Flag Coverage Δ
integration 49.1691% <83.3333%> (?)
unit 72.4300% <100.0000%> (+0.2216%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 60.7186% <ø> (+15.6309%) ⬆️
---- 🚨 Try these New Features:

@joechenrh joechenrh changed the title expression: fix wrong flen from quoteFunctionClass expression: fix wrong flen from baseFunctionClass Oct 12, 2024
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 12, 2024
@joechenrh
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Oct 12, 2024

@joechenrh: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

if err != nil {
return nil, err
}
argFieldTp := args[0].GetType(ctx.GetEvalCtx())
// Use UTF8MB4 as default.
if argLen != types.UnspecifiedLength {
bf.tp.SetFlen(argLen * 4 * 2)
}
bf.tp.SetFlen(argFieldTp.GetFlen() * 4 * 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

This line need to be removed?

if err != nil {
return nil, err
}
argFieldTp := args[0].GetType(ctx.GetEvalCtx())
// Use UTF8MB4 as default.
if argLen != types.UnspecifiedLength {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to use argFieldTp.GetFlen() as the argLen because inside newBaseBuiltinFuncWithTp, args[0] maybe changed by wrap some implict cast function

if err != nil {
return nil, err
}
bf.tp.SetFlen(args[0].GetType(ctx.GetEvalCtx()).GetFlen() * 2)
if argLen != types.UnspecifiedLength {
bf.tp.SetFlen(argLen * 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, better to use argFieldTp.GetFlen() as the argLen

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. do-not-merge/needs-triage-completed labels Oct 17, 2024
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 21, 2024
@yibin87
Copy link
Contributor

yibin87 commented Nov 19, 2024

/test check-dev

Copy link

tiprow bot commented Nov 19, 2024

@yibin87: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test check-dev

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.

Copy link
Contributor

@yibin87 yibin87 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

ti-chi-bot bot commented Nov 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: windtalker, yibin87

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 19, 2024
Copy link

ti-chi-bot bot commented Nov 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-21 05:46:33.878196916 +0000 UTC m=+243594.574987550: ☑️ agreed by windtalker.
  • 2024-11-19 07:51:17.919284155 +0000 UTC m=+947440.110153151: ☑️ agreed by yibin87.

@joechenrh
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Nov 19, 2024

@joechenrh: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@joechenrh
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Nov 19, 2024

@joechenrh: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@joechenrh
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Nov 19, 2024
@joechenrh
Copy link
Contributor Author

/retest

1 similar comment
@joechenrh
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 60bbccb into pingcap:master Nov 19, 2024
24 checks passed
@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Nov 19, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #57518.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TiDB and MySQL behave differently when union quote(cast('xxxx' as char)) and string literal
4 participants