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: Improved precision of FROM_UNIXTIME(char) #35184 #37788

Merged
merged 43 commits into from Sep 22, 2022

Conversation

keeplearning20221
Copy link
Contributor

@keeplearning20221 keeplearning20221 commented Sep 13, 2022

What problem does this PR solve?

Issue Number: ref #35184

Problem Summary:
fix FROM_UNIXTIME(char/double) is not compatible with mysql

What is changed and how it works?

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

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

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 13, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • qw4990
  • windtalker

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 do-not-merge/invalid-title release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 13, 2022
@keeplearning20221 keeplearning20221 changed the title expression,parser,types:Improved precision of FROM_UNIXTIME(char) #35184 expression[,parser,types]:Improved precision of FROM_UNIXTIME(char) #35184 Sep 13, 2022
@keeplearning20221 keeplearning20221 changed the title expression[,parser,types]:Improved precision of FROM_UNIXTIME(char) #35184 expression[,parser,mysql,types]:Improved precision of FROM_UNIXTIME(char) #35184 Sep 13, 2022
	modified:   types/field_type.go
@keeplearning20221 keeplearning20221 changed the title expression[,parser,mysql,types]:Improved precision of FROM_UNIXTIME(char) #35184 expression [, parser, mysql, types]: Improved precision of FROM_UNIXTIME(char) #35184 Sep 13, 2022
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 14, 2022
types/datum.go Outdated
@@ -1468,6 +1469,14 @@ func (d *Datum) convertToMysqlDecimal(sc *stmtctx.StatementContext, target *Fiel
// ProduceDecWithSpecifiedTp produces a new decimal according to `flen` and `decimal`.
func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.StatementContext) (_ *MyDecimal, err error) {
flen, decimal := tp.GetFlen(), tp.GetDecimal()

//If string to decimal, determine the precision for each string
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any possible that (tp.GetFlag() & mysql.StringToDecimalFlag) is true and flen != UnspecifiedLength && decimal != UnspecifiedLength is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NO, None of these types (mysql.TypeString, mysql.TypeVarchar, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob) GetFlen() == -1

Copy link
Contributor

Choose a reason for hiding this comment

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

you'd better to decrease cyclomatic complexity. I mean that you added if {} block before origin if flen != UnspecifiedLength && decimal != UnspecifiedLength {}, the code looks a little hard to read and maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

result.Check(testkit.Rows(unixTime1, unixTime2))

tk.MustExec("drop table if exists ft;")
tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar longblob);")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you remove the irrelevant columns and tail semicolon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@TonsnakeLin
Copy link
Contributor

No obvious problem was found, but please ask the developer of the relevant code to review it again.

	modified:   expression/integration_test.go
	modified:   planner/core/plan_to_pb.go
	modified:   types/datum.go
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 17, 2022
	modified:   expression/builtin_time.go
	modified:   expression/builtin_time_vec.go
	modified:   expression/expr_to_pb.go
	modified:   expression/expression.go
	modified:   parser/mysql/type.go
@@ -1661,6 +1661,10 @@ func (c *fromUnixTimeFunctionClass) getFunction(ctx sessionctx.Context, args []E
return nil, err
}

if fieldString(arg0Tp.GetType()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use isArg0Str?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TypeUnspecified is not the expected type,which satisfies types.IsString.
and TypeVarString is an input parameter, no need to adjust the precision .

if ok {
// FixUnixtimePrecision is used to adjust FromUnixTime precision #Fixbug35184
if x.FuncName.L == ast.Cast {
if x.RetType.GetDecimal() == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. why need to check x.RetType.GetDecimal(), sometime the decimal can be -1, and it also need to be updated.
  2. why need check if it is cast function? I think just check if the return type if decimal is ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1)string type must be equal to 0
2)The current application scenario is cast

result.Check(testkit.Rows("1973-11-30 08:38:10.1"))

result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar,'%Y%m%d') from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ")
result.Check(testkit.Rows("19731130"))
Copy link
Contributor

Choose a reason for hiding this comment

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

also add a test that the input is string literal?

@keeplearning20221
Copy link
Contributor Author

/run-unit-test

@keeplearning20221 keeplearning20221 changed the title expression, mysql: Improved precision of FROM_UNIXTIME(char) #35184 expression: Improved precision of FROM_UNIXTIME(char) #35184 Sep 21, 2022
@keeplearning20221
Copy link
Contributor Author

/run-unit-test

1 similar comment
@keeplearning20221
Copy link
Contributor Author

/run-unit-test

@keeplearning20221
Copy link
Contributor Author

/run-build

@keeplearning20221
Copy link
Contributor Author

/run-unit-test

if ok {
//used to adjust FromUnixTime precision #Fixbug35184
if x.FuncName.L == ast.Cast {
if x.RetType.GetDecimal() == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add extra check to make sure the x.RetType is decimal ?

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 added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 22, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 22, 2022
@windtalker
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 7dbfbdf

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 22, 2022
@ti-chi-bot
Copy link
Member

@keeplearning20221: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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.

@ti-chi-bot ti-chi-bot merged commit b2b8c56 into pingcap:master Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants