-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
ddl: do change column data when binary to binary with different length #24681
Conversation
/cc @AilinKid |
@ti-srebot /run-all-tests |
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we plan to remove tidb_enable_change_column_type, after the column type change is GA, we can support it directly.
right, then the only difference would be need to do reorg when |
/cc @AilinKid |
mb := getModifyColumn(c, s.s.(sessionctx.Context), "test", "tt", "a", false) | ||
c.Assert(mb.FieldType.Flen, Equals, 10) | ||
tk.MustQuery("select * from tt").Check(testkit.Rows("111\x00\x00\x00\x00\x00\x00\x00", "10000\x00\x00\x00\x00\x00")) | ||
tk.MustGetErrMsg("alter table tt change a a binary(4);", "[types:1406]Data Too Long, field len 4, data len 10") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add more tests, for example, char type which also has a binary opt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mysql> alter table t modify b char(33) binary;
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1
However, in MySQL, the length won't change during alter binary(22)
to char(33) binary
I think TiDB may have some incompatibility here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of MySQL is reasonable.
char(33) binary
defines the collation to "_bin", the ordering/comparison behavior may changed, but char
always right-padded with spaces to the specified length according to here. So length is not influenced by collation. (BTW, char(33) binary
become ambiguous since MySQL 8.0 provide two _bin
collations to utf8mb4
)
For the char
type, the retrieved value would keep the trailing spaces only if SQL_MODE contains PAD_CHAR_TO_FULL_LENGTH
, which is disable at default. That's why Length()
result not changed. (On the contrary, binary
padding with 0x00 and always keep the padding bytes at retrieve, so the 0x00 can be count at Length()
)
If we add PAD_CHAR_TO_FULL_LENGTH
to sql_mode, execute alter table t modify b char(33) binary;
, we can get length = 33
.
But when it comes to TiDB, column change to different charset still unsupported now. So I think maybe it's better to add such tests along with the feature development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every Impressive, thanks LENSHOOD
@@ -708,6 +708,11 @@ func needChangeColumnData(oldCol, newCol *model.ColumnInfo) bool { | |||
return isElemsChangedToModifyColumn(oldCol.Elems, newCol.Elems) | |||
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong: | |||
return toUnsigned != originUnsigned | |||
case mysql.TypeString: | |||
// Due to the behavior of padding \x00 at binary type, always change column data when binary length changed | |||
if types.IsBinaryStr(&oldCol.FieldType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
varbinary doesn't have padding \x00
@LENSHOOD Could you update this PR? |
I've missed your last comment about "varbinary" ! Anyway, varbinary doesn't have to add padding, indeed. But due to the varbinary 's (am I understand you comment correctly?) |
Okay, I check it and it's expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: f4b49f5
|
Since it's not a critical bug, or user requirements, we will not cherry-pick it release 5.1 |
@AilinKid @wjhuang2016 |
This pr break integration tests https://ci.pingcap.net/blue/organizations/jenkins/tidb_ghpr_common_test/detail/tidb_ghpr_common_test/5633/
|
Sorry, I cannot access the repo |
What problem does this PR solve?
Issue Number: close #3644
Problem Summary:
tidb_enable_change_column_type = 0
tidb_enable_change_column_type = 1
, then no matter the new binary length is great or less than the original one, change column data should be performed.What is changed and how it works?
What's Changed:
Check List
Tests
Release note