-
Notifications
You must be signed in to change notification settings - Fork 6k
infoschema: fix bug of column size of set and enum type #7347
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
Conversation
infoschema/tables_test.go
Outdated
testkit.Rows("s2 30")) | ||
tk.MustQuery("select column_name, character_maximum_length from information_schema.columns where table_schema=Database() and table_name = 't' and column_name = 'e1'").Check( | ||
testkit.Rows("e1 4")) | ||
// |
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.
Remove this line.
infoschema/tables.go
Outdated
} | ||
colLen = sumLen + cnt | ||
} | ||
if col.Tp == mysql.TypeEnum { |
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.
else if
infoschema/tables.go
Outdated
@@ -797,6 +797,30 @@ func dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) [][]types | |||
if colLen == types.UnspecifiedLength { | |||
colLen = defaultFlen | |||
} | |||
if col.Tp == mysql.TypeSet { | |||
//example: In MySQL set('a','bc','def','ghij') has length 13, This is because | |||
//len('a')+len('bc')+len('def')+len('ghij')+len(ThreeComma)=13 |
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.
It's better to check whether MySQL uses this rule.
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.
It is better to add a reference link.
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.
Ok, I'm looking for MySQL's method.
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.
Reference link: https://bugs.mysql.com/bug.php?id=22613
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.
It's better to add the link to the comments.
infoschema/tables.go
Outdated
} | ||
if col.Tp == mysql.TypeEnum { | ||
//exapmle: In MySQL enum('a', 'ab', 'cdef') has length 4, This is because | ||
//the longest string in the enum is 'cdef' |
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.
ditto
/run-all-tests |
/rebuild |
/run-all-tests |
infoschema/tables_test.go
Outdated
@@ -77,6 +77,16 @@ func (s *testSuite) TestDataForTableRowsCountField(c *C) { | |||
tk.MustExec("create user xxx") | |||
tk.MustExec("flush privileges") | |||
|
|||
//Test for length of enmu and set |
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.
enmu
-> enum
. And it is better to add a space between //
and comment.
infoschema/tables.go
Outdated
} | ||
colLen = sumLen + cnt | ||
} else if col.Tp == mysql.TypeEnum { | ||
//exapmle: In MySQL enum('a', 'ab', 'cdef') has length 4, This is because |
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.
exapmle
->example
.- It is better to add a space between // and comment.
- It is better to remove the
This is
.
/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.
LGTM
infoschema/tables.go
Outdated
// Example: In MySQL set('a','bc','def','ghij') has length 13, because | ||
// len('a')+len('bc')+len('def')+len('ghij')+len(ThreeComma)=13 | ||
// Reference link: https://bugs.mysql.com/bug.php?id=22613 | ||
sumLen, cnt := 0, 0 |
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.
how about this:
colLen = 0
for _, ele := range col.Elems {
colLen += len(ele)
}
if len(col.Elems) != 0 {
colLen = len(col.Elems) - 1
}
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.
@crazycs520
it looks grate. But it should be:
if len(col.Elems) != 0 {
colLen += (len(col.Elems) - 1)
}
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.
ye~😢
infoschema/tables_test.go
Outdated
@@ -77,6 +77,16 @@ func (s *testSuite) TestDataForTableRowsCountField(c *C) { | |||
tk.MustExec("create user xxx") | |||
tk.MustExec("flush privileges") | |||
|
|||
//Test for length of enum and set |
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.
Add space. // Test....
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
PTAL @winoros @crazycs520 |
/run-all-tests |
What have you changed? (mandatory)
I add code to fix bug when query column size of set and enum type.
Originally the column size of set and enum type while be default value 2^64 - 1. (See mysql/util:65)
This is different from MySQL's result.
For example, in MySQL 5.7.
But in TiDB:
I fix this bug by adding code to calculate size of set and enum like MySQL.
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
unit test
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
No
Does this PR affect tidb-ansible update? (mandatory)
No
Does this PR need to be added to the release notes? (mandatory)
No
Refer to a related PR or issue link (optional)
Fix #7297
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)