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 result type for greatest/least #30589

Closed
wants to merge 8 commits into from

Conversation

SeaRise
Copy link
Contributor

@SeaRise SeaRise commented Dec 9, 2021

What problem does this PR solve?

Issue Number: close #30261

Problem Summary:
When arguments of greatest/least are mixed with temporalType and string, tidb will
1、Convert all args as String
2、EvalString to get arg value
3、Parse string as datetime. If it's a valid datetime, use string(datetime) to compare. Otherwise use the result of EvalString to compare.

But it is not compitable with mysql
1、if { arg.is_temporal, EvalTime to get arg value (https://github.com/mysql/mysql-server/blob/8.0/sql/item_cmpfunc.cc#L1498) } else { EvalString to get arg value, and parse string to MYSQL_TIMESTAMP_DATE/MYSQL_TIMESTAMP_DATETIME(https://github.com/mysql/mysql-server/blob/8.0/sql/item_func.cc#L3667-L3678, https://github.com/mysql/mysql-server/blob/8.0/sql/item_cmpfunc.cc#L1520-L1524) }
2、compare with time value (https://github.com/mysql/mysql-server/blob/8.0/sql/item_func.cc#L3708)
3、if there any err, use the result of EvalString to compare (https://github.com/mysql/mysql-server/blob/8.0/sql/item_func.cc#L3745-L3748)

What is changed and how it works?

Port the code of https://github.com/mysql/mysql-server/blob/8.0/sql/item_cmpfunc.cc#L1520-L1524

TODO:
When arguments of greatest/least are mixed with time, duration, string, the result is not compitable with mysql.
Such as SELECT GREATEST(cast('000:59:59' as time), cast('2000' as YEAR), '2002-01-01');

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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

fix wrong result type for greatest/least

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 9, 2021
@XuHuaiyu XuHuaiyu added sig/execution SIG execution type/bugfix This PR fixes a bug. labels Dec 14, 2021
@XuHuaiyu XuHuaiyu requested a review from guo-shaoge December 14, 2021 07:48
@SeaRise
Copy link
Contributor Author

SeaRise commented Dec 27, 2021

fixed by #31037

@SeaRise SeaRise closed this Dec 27, 2021
@SeaRise SeaRise deleted the fix_issue_30261 branch January 11, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GREATEST function with DATE type returns DATETIME result
3 participants