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

* fix timestamp default value bug in multiple time zones. #9115

Merged
merged 36 commits into from Feb 18, 2019

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Fix timestamp default value bug in multiple time zones.
TiDB

mysql> set @@time_zone="+08:00"
mysql> create table t1 (a int, b timestamp default "2019-01-17 14:46:14"); 
mysql> insert into t1 set a=1; /* b = "2019-01-17 14:46:14 +08:00" = "2019-01-17 06:46:14 UTC"   */
mysql> show create table t1
+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (                                         |
|       |   `a` int(11) DEFAULT NULL,                                 |
|       |   `b` timestamp DEFAULT '2019-01-17 14:46:14'               |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+
mysql> set @@time_zone="+00:00"
mysql> insert into t1 set a=2;  /* b = "2019-01-17 14:46:14 +00:00" = "2019-01-17 14:46:14 UTC"   */
mysql> show create table t1
+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (                                         |
|       |   `a` int(11) DEFAULT NULL,                                 |
|       |   `b` timestamp DEFAULT '2019-01-17 14:46:14'               |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+
mysql> select a,b from t1;
+---+---------------------+
| a | b                   |
+---+---------------------+
| 1 | 2019-01-17 06:46:14 |
| 2 | 2019-01-17 14:46:14 |
+---+---------------------+
2 rows in set
mysql> set @@time_zone="+08:00"
mysql> select a,b from t1;
+---+---------------------+
| a | b                   |
+---+---------------------+
| 1 | 2019-01-17 14:46:14 |
| 2 | 2019-01-17 22:46:14 |
+---+---------------------+

mysql

mysql> set @@time_zone="+08:00"
mysql> create table t1 (a int, b timestamp default "2019-01-17 14:46:14");
mysql> insert into t1 set a=1
mysql> show create table t1
+-------+--------------------------------------------------------+
| Table | Create Table                                           |
+-------+--------------------------------------------------------+
| t1    | CREATE TABLE `t1` (                                    |
|       |   `a` int(11) DEFAULT NULL,                            |
|       |   `b` timestamp NOT NULL DEFAULT '2019-01-17 14:46:14' | 
|       | ) ENGINE=InnoDB DEFAULT CHARSET=latin1                 |
+-------+--------------------------------------------------------+
mysql> set @@time_zone="+00:00"
mysql> insert into t1 set a=2;
mysql> show create table t1
+-------+--------------------------------------------------------+
| Table | Create Table                                           |
+-------+--------------------------------------------------------+
| t1    | CREATE TABLE `t1` (                                    |
|       |   `a` int(11) DEFAULT NULL,                            |
|       |   `b` timestamp NOT NULL DEFAULT '2019-01-17 06:46:14' |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=latin1                 |
+-------+--------------------------------------------------------+
mysql> select a,b from t1;
+---+---------------------+
| a | b                   |
+---+---------------------+
| 1 | 2019-01-17 06:46:14 |
| 2 | 2019-01-17 06:46:14 |
+---+---------------------+
2 rows in set
mysql> set @@time_zone="+08:00"
mysql> select a,b from t1;
+---+---------------------+
| a | b                   |
+---+---------------------+
| 1 | 2019-01-17 14:46:14 |
| 2 | 2019-01-17 14:46:14 |
+---+---------------------+

Related Parser PR:pingcap/parser#183
releated Issue: #9064

What is changed and how it works?

Old tidb save timestamp default value without convert to UTC time. Then if TiDB in multiple timezone, and use the default value of timestamp will have different result problem.
This PR will save timestamp default value in UTC time.
And add a version field to solve compatible problem.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch

@crazycs520 crazycs520 added type/bug-fix This PR fixes a bug. require-LGT3 Indicates that the PR requires three LGTM. labels Jan 18, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

@zimulala @XuHuaiyu @winkyao PTAL, Ci failed because go.mod. After parser merged, I will fix this.

ddl/column.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
executor/show.go Outdated Show resolved Hide resolved
executor/show.go Outdated Show resolved Hide resolved
table/column.go Outdated Show resolved Hide resolved
table/column.go Outdated Show resolved Hide resolved
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.

reset 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 12, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

@XuHuaiyu PTAL

@crazycs520
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@ciscoxll ciscoxll left a comment

Choose a reason for hiding this comment

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

LGTM

@ciscoxll ciscoxll added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Feb 14, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

@zz-jason
Copy link
Member

@crazycs520 Is this PR ready to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
require-LGT3 Indicates that the PR requires three LGTM. status/LGT3 The PR has already had 3 LGTM. type/bug-fix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants