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

executor: make the results of show create table more consistent with MySQL #9229

Merged
merged 5 commits into from
Feb 15, 2019

Conversation

spongedu
Copy link
Contributor

@spongedu spongedu commented Jan 30, 2019

What problem does this PR solve?

Fix issue #9211 , Make results of show create table more consistent with MySQL

What is changed and how it works?

  1. Don't show default values for generated columns
  2. Refine demonstration for CHARSET for character type columns

Check List

Tests

  • Unit test

@spongedu
Copy link
Contributor Author

spongedu commented Jan 30, 2019

@zimulala @zz-jason @xiekeyi98 PTAL :)

@codecov-io
Copy link

codecov-io commented Jan 30, 2019

Codecov Report

Merging #9229 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
executor/show.go 43.72% <100%> (+0.45%) ⬆️
ddl/session_pool.go 82.75% <0%> (-10.35%) ⬇️
ddl/delete_range.go 73.54% <0%> (-1.59%) ⬇️
executor/index_lookup_join.go 77.28% <0%> (-0.64%) ⬇️
executor/join.go 78.38% <0%> (-0.53%) ⬇️
executor/distsql.go 73% <0%> (+0.46%) ⬆️
expression/schema.go 94.53% <0%> (+0.78%) ⬆️
util/systimemon/systime_mon.go 100% <0%> (+20%) ⬆️
util/filesort/filesort.go 76.48% <0%> (+35.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f73c4e2...2561a4b. Read the comment docs.

@xiekeyi98 xiekeyi98 added type/compatibility contribution This PR is from a community contributor. sig/execution SIG execution labels Jan 30, 2019
@xiekeyi98 xiekeyi98 changed the title Fix #9211: make more consistent with MySQL executor: make more consistent with MySQL Jan 30, 2019
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
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reasonable ~

@spongedu spongedu changed the title executor: make more consistent with MySQL executor: make the results of show create table more consistent with MySQL Jan 30, 2019
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() {
Copy link
Contributor

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")
}
Copy link
Contributor

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)

Copy link
Contributor Author

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)

Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@xiekeyi98 xiekeyi98 left a 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.

@xiekeyi98 xiekeyi98 added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 31, 2019
winkyao
winkyao previously approved these changes Jan 31, 2019
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

@ngaut
Copy link
Member

ngaut commented Jan 31, 2019

/run-all-tests

@ngaut ngaut added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 31, 2019
@spongedu
Copy link
Contributor Author

It seems that the test cases should be updated. @zz-jason @winkyao

@xiekeyi98
Copy link
Contributor

@spongedu
Would you mind solve the conflicts?
And then I will update the test cases for this PR.

@spongedu
Copy link
Contributor Author

@xiekeyi98 OK

@spongedu
Copy link
Contributor Author

@xiekeyi98 PTAL :)

@xiekeyi98
Copy link
Contributor

/run-all-tests tidb-test=pr/735

@zimulala
Copy link
Contributor

/run-unit-test

@xiekeyi98
Copy link
Contributor

/run-all-tests

Copy link
Contributor

@xiekeyi98 xiekeyi98 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

@xiekeyi98 xiekeyi98 added status/LGT1 Indicates that a PR has LGTM 1. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Feb 15, 2019
Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 15, 2019
@zimulala zimulala merged commit 3d4ad1f into pingcap:master Feb 15, 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. sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants