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

types: fix mergeTypeFlag to consider UnsignedFlag #17386

Closed
wants to merge 1 commit into from

Conversation

smola
Copy link
Contributor

@smola smola commented May 25, 2020

What problem does this PR solve?

Issue Number: close #15771

Problem Summary: when merging type flags, unsigned is always set if left hand side is unsigned, but it should be set only if both sides are unsigned.

What is changed and how it works?

  • In field_type.go, mergeTypeFlag now considers mysql.UnsignedFlag. The flag will be set only if it is set for both sides.
  • This is used in AggFieldType, so the fix propagates to this function.
  • Other flags are not considered, but the same fix may apply to others too.

Check List

  • Unit tests

Release note

  • Fix type merging of signed and unsigned integers.

@smola smola requested a review from a team as a code owner May 25, 2020 09:14
@sre-bot sre-bot added the contribution This PR is from a community contributor. label May 25, 2020
@ghost ghost requested review from wshwsh12 and removed request for a team May 25, 2020 09:15
@smola smola changed the title types: fix MergeFieldType to consider UnsignedFlag types: fix mergeTypeFlag to consider UnsignedFlag May 25, 2020
Copy link
Contributor

@Reminiscent Reminiscent left a comment

Choose a reason for hiding this comment

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

LGTM

@Reminiscent Reminiscent requested review from windtalker and removed request for wshwsh12 May 26, 2020 11:37
@Reminiscent
Copy link
Contributor

@windtalker PTAL

@Reminiscent Reminiscent added the status/LGT1 Indicates that a PR has LGTM 1. label May 26, 2020
c &= ^mysql.UnsignedFlag
}

return c
Copy link
Contributor

@windtalker windtalker May 26, 2020

Choose a reason for hiding this comment

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

I think the unsigned flag can not be simply set or unset, because the range of tp is changed when the unsigned flag is changed. When merge unsigned int32 and signed int32, the best fit type should be signed int64, and things get more complex when merge unsigned int64 and signed int64, as far as I know, the latest mysql return decimal type, so simply set/unset the unsigned flag many cause some unknown issues, this is the reason why I does not check unsigned flag in the last pr. In order to handle the unsigned flag, maybe you need to make some changes in AggFieldType.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@windtalker Right, for case when MySQL 8 will use DECIMAL(20, 0) for signed int64 and unsigned int64. I'll give a look at the detailed logic.

@sre-bot
Copy link
Contributor

sre-bot commented Jun 5, 2020

@smola, please update your pull request.

1 similar comment
@sre-bot
Copy link
Contributor

sre-bot commented Jun 12, 2020

@smola, please update your pull request.

@smola
Copy link
Contributor Author

smola commented Jun 12, 2020

Closing this PR, since it requires a different approach as @windtalker pointed out.

@smola smola closed this Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The common type of bigint and bigint unsigned is not stable in TiDB
4 participants