-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
executor: make the results of show create table
more consistent with MySQL
#9229
Conversation
@zimulala @zz-jason @xiekeyi98 PTAL :) |
Codecov Report
@@ Coverage Diff @@
## master #9229 +/- ##
==========================================
+ Coverage 67.03% 67.17% +0.14%
==========================================
Files 371 371
Lines 77531 77531
==========================================
+ Hits 51973 52085 +112
+ Misses 20922 20788 -134
- Partials 4636 4658 +22
Continue to review full report at Codecov.
|
executor/show.go
Outdated
@@ -614,7 +615,8 @@ func (e *ShowExec) fetchShowCreateTable() error { | |||
if mysql.HasNotNullFlag(col.Flag) { | |||
buf.WriteString(" NOT NULL") | |||
} | |||
if !mysql.HasNoDefaultValueFlag(col.Flag) { | |||
// don't show default value for generated columns |
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.
I think we'd better to explain why "not show default value for generated columns".
For example, "Default value are not shown for generated columns in mysql".
The current comment, I think, is the same as the code(a little bit redundant)
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.
Reasonable ~
show create table
more consistent with MySQL
executor/show.go
Outdated
if col.Charset != "binary" { | ||
fmt.Fprintf(&buf, " CHARSET %s COLLATE %s", col.Charset, col.Collate) | ||
// charset && collate are not shown for generated columns in MySQL | ||
if col.Charset != "binary" && !col.IsGenerated() { |
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.
"Because it is generated , charset and collate are not shown." OR "Because it is generated and charset is binary, charset and collate are not shown".
" `b` char(10) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL\n"+ | ||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", | ||
)) | ||
tk.MustExec("drop table t") | ||
} |
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.
I was wondering if you could add test like this create table test ( a char(10) charset gb2312 , b char(10) charset utf8 as (rtrim(a)) );
?
BTW, The following is the result of MYSQL:
mysql> create table test ( a char(10) charset gb2312 , b char(10) charset utf8 as (rtrim(a)) );
Query OK, 0 rows affected (0.02 sec)
mysql> show create table test;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`a` char(10) CHARACTER SET gb2312 DEFAULT NULL,
`b` char(10) CHARACTER SET utf8 GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.7.25-0ubuntu0.18.04.2 |
+-------------------------+
1 row in set (0.00 sec)
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.
@xiekeyi98 I seems make a mistake here. I made several tests and found that whether a column is generated do not actually determine whether CHARSET
&& COLLATE
are shown. In fact, it's determined by whether CHARSET
&& COLLATE
are specified explicitly.
I'd prefer left it to another issue and make this pr clearer.
BTW, TiDB
seems don't support gb2312
for now.
The following are my tests:
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.17-log |
+------------+
1 row in set (0.01 sec)
mysql> create table test ( a char(10) charset utf8 , b char(10) charset utf8 as (rtrim(a)) );
Query OK, 0 rows affected (0.03 sec)
mysql> show create table test;
+-------+-------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------+| test | CREATE TABLE `test` (
`a` char(10) CHARACTER SET utf8 DEFAULT NULL,
`b` char(10) CHARACTER SET utf8 GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
mysql> drop table test;
Query OK, 0 rows affected (0.02 sec)
mysql> create table test ( a char(10) charset utf8 , b char(10) as (rtrim(a)) );
Query OK, 0 rows affected (0.03 sec)
mysql> show create table test;
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`a` char(10) CHARACTER SET utf8 DEFAULT NULL,
`b` char(10) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> drop table test;
Query OK, 0 rows affected (0.02 sec)
mysql> create table test ( a char(10), b char(10) as (rtrim(a)) );
Query OK, 0 rows affected (0.03 sec)
mysql> show create table test;
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`a` char(10) DEFAULT NULL,
`b` char(10) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> desc test;
+-------+----------+------+-----+---------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------------------+
| a | char(10) | YES | | NULL | |
| b | char(10) | YES | | NULL | VIRTUAL GENERATED |
+-------+----------+------+-----+---------+-------------------+
2 rows in set (0.01 sec)
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.
Sorry for my negligence.
Whether gb2312 or not is not necessary, I just want to show something like this.
In my mind, whether mysql displays that fields depends on whether the table and column charset are consistent(I am not very sure).
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.
@xiekeyi98 I've opened another issue #9232 for the demonstration of the demonstration of CHARSET
&& COLLATE
. It's not related to generated columns, indeed. I'll look into this later.
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.
Well done. Thanks for you contribution.
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.
seems you've working on this in #9113 :P
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,Thanks for your contribution.
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
/run-all-tests |
@spongedu |
@xiekeyi98 OK |
@xiekeyi98 PTAL :) |
/run-all-tests tidb-test=pr/735 |
/run-unit-test |
/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, thank you.
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
What problem does this PR solve?
Fix issue #9211 , Make results of
show create table
more consistent with MySQLWhat is changed and how it works?
CHARSET
for character type columnsCheck List
Tests