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: length(binary(m)) should return 'm' instead of the concrete string length #10671

Conversation

miraclesu
Copy link
Contributor

What problem does this PR solve?

Fixes #3644.

What is changed and how it works?

Right-padded with the pad value to the specified length.

Check List

Tests

  • Integration test

Code changes

N/A

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch

@shenli shenli added contribution This PR is from a community contributor. type/bugfix This PR fixes a bug. labels May 31, 2019
@zz-jason zz-jason requested a review from winoros June 3, 2019 12:44
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Jun 3, 2019

Codecov Report

Merging #10671 into master will decrease coverage by 1.2245%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##             master    #10671        +/-   ##
===============================================
- Coverage   79.5906%   78.366%   -1.2246%     
===============================================
  Files           415       414         -1     
  Lines         88131     87654       -477     
===============================================
- Hits          70144     68691      -1453     
- Misses        12801     13832      +1031     
+ Partials       5186      5131        -55

@zz-jason zz-jason requested a review from XuHuaiyu June 3, 2019 12:50
valLen := len([]rune(val))
// See #3644.
// Binary type column value will changed after modify the column length.
if (ctx.GetSessionVars().StmtCtx.PadCharToFullLength || (mysql.HasBinaryFlag(uint(col.GetType().Tp)) && col.GetType().Charset == charset.CharsetBin)) && col.GetType().Tp == mysql.TypeString {
Copy link
Member

Choose a reason for hiding this comment

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

how about using types.IsBinaryStr()?

@miraclesu miraclesu force-pushed the fix/binary_column_length_after_modify branch from a4d8376 to 299273b Compare June 9, 2019 13:59
@miraclesu
Copy link
Contributor Author

@zz-jason I've added types.IsBinaryStr and used it.

@zz-jason
Copy link
Member

@zz-jason I've added types.IsBinaryStr and used it.

@miraclesu There is already a function named IsBinaryStr() in the tidb project:

 83 // IsBinaryStr returns a boolean indicating
 84 // whether the field type is a binary string type.
 85 func IsBinaryStr(ft *FieldType) bool {
 86     if ft.Collate == charset.CollationBin && IsString(ft.Tp) {
 87         return true
 88     }
 89     return false
 90 }

You can see it in types/etc.go

@miraclesu
Copy link
Contributor Author

miraclesu commented Jun 11, 2019

@zz-jason Oh, it's my mistake.
IsBinaryStr() function including string, varchar, blob, varstring and Unspecified binary type, only string binary type needs to be filled space, should we add a new function like IsBinary()?

reference: MySQL doc

valLen := len([]rune(val))
// See #3644.
// Binary type column value will changed after modify the column length.
if (ctx.GetSessionVars().StmtCtx.PadCharToFullLength && col.GetType().Tp == mysql.TypeString) || col.GetType().IsBinaryStr() {
Copy link
Member

Choose a reason for hiding this comment

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

We store CHAR[N] in TiKV by removing the trailing spaces. But for BINARY[N], we add trailing spaces to N bytes.

When modifying a column from BINARY[X] to BINARY[Y], the underlying data should be regenerated. I think this is the correct way to fix this kind of issue.

@zimulala How do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zz-jason
Yes. But I think we can do this first and add a TODO. Wait until the "modify column" can handle the problem of regenerating the data and then remove the logic.

Copy link
Member

Choose a reason for hiding this comment

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

Okay. I think we'd better file an issue about this bug.

Copy link
Member

@zz-jason zz-jason Aug 3, 2019

Choose a reason for hiding this comment

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

@zimulala Since these kinds of DDL operations are not working correctly at present. I think a workaround is to forbid these operations. Do not allow modifying a binary(x) column to a binary(y) column if x is not equal to y.

Copy link
Member

Choose a reason for hiding this comment

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

see #11597 for details.

@zz-jason zz-jason requested review from zimulala and removed request for winoros and XuHuaiyu July 15, 2019 15:41
@zz-jason
Copy link
Member

@miraclesu friendly ping, any update?

@sre-bot
Copy link
Contributor

sre-bot commented Sep 1, 2019

@miraclesu, please update your pull request.

1 similar comment
@sre-bot
Copy link
Contributor

sre-bot commented Sep 8, 2019

@miraclesu, please update your pull request.

@sre-bot sre-bot closed this Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

length result is wrong after modify column length
5 participants