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, infoschema: fix display of default CURRENT_TIMESTAMP with decimal #11070

Merged
merged 4 commits into from
Jul 4, 2019

Conversation

bb7133
Copy link
Member

@bb7133 bb7133 commented Jul 4, 2019

What problem does this PR solve?

This PR fixes the following scenarios in which decimal fraction is missed for default CURRENT_TIMESTAMP in TiDB:

tidb> create table t(a datetime(3) default current_timestamp(3), b timestamp(4) default current_timestamp(4));
Query OK, 0 rows affected (0.01 sec)
  • For SHOW CREATE TABLE:
tidb> show create table t;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                   |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `a` datetime(3) DEFAULT CURRENT_TIMESTAMP,
  `b` timestamp(4) DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
  • For SHOW (FULL) COLUMNS:
tidb> show full columns from t;
+-------+--------------+-----------+------+------+-------------------+-------+---------------------------------+---------+
| Field | Type         | Collation | Null | Key  | Default           | Extra | Privileges                      | Comment |
+-------+--------------+-----------+------+------+-------------------+-------+---------------------------------+---------+
| a     | datetime(3)  | NULL      | YES  |      | CURRENT_TIMESTAMP |       | select,insert,update,references |         |
| b     | timestamp(4) | NULL      | YES  |      | CURRENT_TIMESTAMP |       | select,insert,update,references |         |
+-------+--------------+-----------+------+------+-------------------+-------+---------------------------------+---------+
2 rows in set (0.01 sec)
  • For the queries on information_schema:
tidb> select column_name, column_default from information_schema.COLUMNS where table_schema="test" and table_name = "t" order by column_name;
+-------------+-------------------+
| column_name | column_default    |
+-------------+-------------------+
| a           | CURRENT_TIMESTAMP |
| b           | CURRENT_TIMESTAMP |
+-------------+-------------------+
2 rows in set (0.00 sec)

Notice that for all displays of the default values of time-related columns, the decimal fraction part is missed. This would cause some errors when users try to use those pieces of information, for example, create a table from SHOW CREATE TABLE:

tidb> CREATE TABLE `t` (
  `a` datetime(3) DEFAULT CURRENT_TIMESTAMP,
  `b` timestamp(4) DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
ERROR 1067 (42000): Invalid default value for 'a'

What is changed and how it works?

Simply adding the missed parts.

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has interface methods change

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

@bb7133 bb7133 changed the title executor, infoschema: fix display of default CURRENT_TIMESTAMP with d… executor, infoschema: fix display of default CURRENT_TIMESTAMP with decimal Jul 4, 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

@winkyao
Copy link
Contributor

winkyao commented Jul 4, 2019

/rebuild

Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

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

LGTM

@tangenta tangenta added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 4, 2019
@codecov
Copy link

codecov bot commented Jul 4, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@e1f2b37). Click here to learn what that means.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11070   +/-   ##
===========================================
  Coverage          ?   81.0658%           
===========================================
  Files             ?        419           
  Lines             ?      89848           
  Branches          ?          0           
===========================================
  Hits              ?      72836           
  Misses            ?      11772           
  Partials          ?       5240

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133
Copy link
Member Author

bb7133 commented Jul 4, 2019

/run-all-tests

@bb7133
Copy link
Member Author

bb7133 commented Jul 4, 2019

/run-integration-common-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants