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

timestamp column default value bug in multiple time zones #9064

Closed
victorggsimida opened this issue Jan 15, 2019 · 22 comments
Closed

timestamp column default value bug in multiple time zones #9064

victorggsimida opened this issue Jan 15, 2019 · 22 comments
Assignees
Labels
type/bug The issue is confirmed as a bug.

Comments

@victorggsimida
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.

the privious version : 08.14 rc version

currecnt version: 2019-01-03 rc version

  1. What did you expect to see?

now=2019-01-05 15:06

mysql> alter table Account add column marstime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
Query OK, 0 rows affected (1.02 sec)

mysql> alter table Account add index(marstime);
^@^@^@^@^@^@^@query OK, 0 rows affected (7 min 3.18 sec)

mysql> select max(marstime) From Account;
+---------------------+
| max(marstime) |
+---------------------+
| 2019-01-15 22:54:33 |
+---------------------+
1 row in set (0.38 sec)

mysql> select min(marstime) From Account;
+---------------------+
| min(marstime) |
+---------------------+
| 2019-01-15 14:57:46 |
+---------------------+
1 row in set (0.26 sec)

mysql> explain select max(marstime) From Account;
+----------------+--------------+----------------+------+--------------------------------------------------------------------------+-------+
| id | parents | children | task | operator info | count |
+----------------+--------------+----------------+------+--------------------------------------------------------------------------+-------+
| IndexScan_29 | Limit_30 | | cop | table:Account, index:marstime, range:[,+inf], keep order:true, desc | 1.00 |
| Limit_30 | | IndexScan_29 | cop | offset:0, count:1 | 1.00 |
| IndexReader_31 | Limit_16 | | root | index:Limit_30 | 1.00 |
| Limit_16 | StreamAgg_12 | IndexReader_31 | root | offset:0, count:1 | 1.00 |
| StreamAgg_12 | | Limit_16 | root | , funcs:max(**.account.marstime) | 1.00 |
+----------------+--------------+----------------+------+--------------------------------------------------------------------------+-------+
5 rows in set (0.00 sec)

Account schema:

CREATE TABLE Account (
asdfid int(11) NOT NULL AUTO_INCREMENT,
nsdfafsdme varchar(60) NOT NULL DEFAULT '',
daisdfn varchar(60) NOT NULL DEFAULT '',
fsag int(11) DEFAULT '0',
unt int(11) DEFAULT '0',
uib int(11) NOT NULL DEFAULT '0',
pot int(11) DEFAULT '0',
blom int(11) DEFAULT '0',
im int(10) UNSIGNED DEFAULT '0',
bce int(11) DEFAULT '0',
newe datetime DEFAULT NULL,
pad varchar(16) DEFAULT NULL,
marstime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (asdfid),
UNIQUE KEY n (nsdfafsdme,daisdfn),
UNIQUE KEY d (daisdfn,nsdfafsdme),
KEY marstime (marstime)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=22938908
1 row in set (0.03 sec)

Account data count: 2kw+, and the data is imported by myloader in privious tidb_version;;

I do the same thing in : tidb( 2018-08-14 rc version) and (2019-01-03 version)
is stil the same

  1. What did you see instead?

when I calculate marstime with max, it return the impossible data.

the value is in the future

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

| Release Version: v2.0.11
Git Commit Hash: 83889a5
Git Branch: release-2.0
UTC Build Time: 2019-01-03 09:27:12
GoVersion: go version go1.11.2 linux/amd64
TiKV Min Version: 2.0.0-rc.4.1 |

@XuHuaiyu
Copy link
Contributor

@victorggsimida Thanks for your feedback.
1.

the privious version : 08.14 rc version
currecnt version: 2019-01-03 rc version

May you provide us the githash of these two tidb-server binary?

I do the same thing in : tidb( 2018-08-14 rc version) and (2019-01-03 version)
is stil the same

What does still the same mean?

now=2019-01-05 15:06

What does this mean?

mysql> select max(marstime) From Account;
+---------------------+
| max(marstime) |
+---------------------+
| 2019-01-15 22:54:33 |
+---------------------+
1 row in set (0.38 sec)
mysql> select min(marstime) From Account;
+---------------------+
| min(marstime) |
+---------------------+
| 2019-01-15 14:57:46 |
+---------------------+
1 row in set (0.26 sec)

Are these the results of MySQL or TiDB?

@victorggsimida
Copy link
Author

@XuHuaiyu
1.
Release Version: 2.0.11
Git Commit Hash: c666277d3565164a00451b95666012cb04274d93
Git Commit Branch: release-2.0
UTC Build Time: 2019-01-03 09:29:52
Rust Version: 1.27.0-nightly (48fa6f963 2018-04-05)

privious version:
tidb-server v2.0.6

  1. the same: I execute the same command in this two version and the result is the same.

Today: I upgrade the cluster from V2.0.6 to 2.0.11.
I test in these two versions

  1. now means the time I execute the command. For showing the imporssible timestamp value '2019-01-15 22:54:33'

4.These result are in TiDB.
The max values of 'marstime' column is impossible

@XuHuaiyu
Copy link
Contributor

OK, @victorggsimida
I have 2 more questions:

  1. What's the result of select @@time_zone in TiDB?
    If it's SYSTEM, you may further check what's the timezone of your system.

  2. I can not find this git commit hash c666277d3565164a00451b95666012cb04274d93 in branch release-2.0. Is it a temporary version?

@victorggsimida
Copy link
Author

@XuHuaiyu

  1. time_zone variables:

before upgrade today, I remember that I have set the time_zone to shanghai to avoid the problem of glibc timestamp transfer lock.

Because I have a problem of using too much system cpu where I select many data which the data include timestamp type.

After upgrade: I roll update the cluster and the time_zone is as below shows
mysql> select @@time_zone;
+-------------+
| @@time_zone |
+-------------+
| SYSTEM |
+-------------+
1 row in set (0.00 sec)

  1. version info:
    I use the wget: wget http://download.pingcap.org/tidb-v2.0.11-linux-amd64.tar.gz to download the binary.

tidb_version = v2.0.11

Hope my answer can help u.

@victorggsimida
Copy link
Author

@XuHuaiyu is there any progress in this issue?

@XuHuaiyu
Copy link
Contributor

Sorry for late reply, I did not notice your comment before.

before upgrade today, I remember that I have set the time_zone to shanghai

Do you mean you changed your timezone to shanghai in tidb server? If so, how did you do that?

What's the timezone of your system?

@victorggsimida
Copy link
Author

@XuHuaiyu

  1. yes. before upgrade the cluster. I set the timezone.
    I can't precisely remember the command.
    But I remember the link I reference
    试试 SET GLOBAL time_zone = 'Asia/Shanghai';

reference: https://github.com/pingcap/docs-cn/blob/master/sql/time-zone.md

  1. timezone of my system:
    utc 8

@XuHuaiyu
Copy link
Contributor

what's the result of
explain select min(marstime) From Account;

@victorggsimida
Copy link
Author

@XuHuaiyu
mysql> explain select min(marstime) From Account;
+----------------+--------------+----------------+------+--------------------------------------------------------------------+-------+
| id | parents | children | task | operator info | count |
+----------------+--------------+----------------+------+--------------------------------------------------------------------+-------+
| IndexScan_29 | Limit_30 | | cop | table:Account, index:marstime, range:[,+inf], keep order:true | 1.00 |
| Limit_30 | | IndexScan_29 | cop | offset:0, count:1 | 1.00 |
| IndexReader_31 | Limit_16 | | root | index:Limit_30 | 1.00 |
| Limit_16 | StreamAgg_12 | IndexReader_31 | root | offset:0, count:1 | 1.00 |
| StreamAgg_12 | | Limit_16 | root | , funcs:min(wh.account.marstime) | 1.00 |
+----------------+--------------+----------------+------+--------------------------------------------------------------------+-------+
5 rows in set (0.00 sec)

mysql>

@XuHuaiyu
Copy link
Contributor

So your operation process is as follows?

  1. SET GLOBAL time_zone = 'Asia/Shanghai'; // I'm not really sure whether you really set the GLOBAL timezone.
  2. upgrade tidb cluster to v2.0.11
  3. run alter table Account add column marstime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
  4. run alter table Account add index(marstime);

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Jan 17, 2019

And please run the following sqls:
select min(marstime) From Account ignore index(marstime)
explain select min(marstime) From Account ignore index(marstime)
select max(marstime) From Account ignore index(marstime)
explain select max(marstime) From Account ignore index(marstime)

@victorggsimida
Copy link
Author

@XuHuaiyu

  1. I am sure. Because I exit session. and relogin and check the variable

  2. tidb version now:::
    What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    | Release Version: v2.0.11
    Git Commit Hash: 83889a5
    Git Branch: release-2.0
    UTC Build Time: 2019-01-03 09:27:12
    GoVersion: go version go1.11.2 linux/amd64
    TiKV Min Version: 2.0.0-rc.4.1 |

step 3,4 already try it .

it is not oK

@XuHuaiyu
Copy link
Contributor

Yep.
I meant that: Did the 4 steps the same as what you did 2 days ago?

@victorggsimida
Copy link
Author

@XuHuaiyu
mysql> select min(marstime) From Account ignore index(marstime)
-> ;
+---------------------+
| min(marstime) |
+---------------------+
| 2019-01-17 10:49:10 |
+---------------------+
1 row in set (8.73 sec)

mysql> explain select min(marstime) From Account ignore index(marstime);
+----------------+--------------+----------------+------+----------------------------------------------------+-------------+
| id | parents | children | task | operator info | count |
+----------------+--------------+----------------+------+----------------------------------------------------+-------------+
| TableScan_19 | TopN_20 | | cop | table:Account, range:[-inf,+inf], keep order:false | 18943432.00 |
| TopN_20 | | TableScan_19 | cop | wh.account.marstime:asc, offset:0, count:1 | 1.00 |
| TableReader_21 | TopN_13 | | root | data:TopN_20 | 1.00 |
| TopN_13 | StreamAgg_12 | TableReader_21 | root | wh.account.marstime:asc, offset:0, count:1 | 1.00 |
| StreamAgg_12 | | TopN_13 | root | , funcs:min(wh.account.marstime) | 1.00 |
+----------------+--------------+----------------+------+----------------------------------------------------+-------------+
5 rows in set (0.00 sec)

mysql> select max(marstime) From Account ignore index(marstime);
+---------------------+
| max(marstime) |
+---------------------+
| 2019-01-17 10:49:10 |
+---------------------+
1 row in set (5.45 sec)

mysql> explain select max(marstime) From Account ignore index(marstime);
+----------------+--------------+----------------+------+----------------------------------------------------+-------------+
| id | parents | children | task | operator info | count |
+----------------+--------------+----------------+------+----------------------------------------------------+-------------+
| TableScan_19 | TopN_20 | | cop | table:Account, range:[-inf,+inf], keep order:false | 18943432.00 |
| TopN_20 | | TableScan_19 | cop | wh.account.marstime:desc, offset:0, count:1 | 1.00 |
| TableReader_21 | TopN_13 | | root | data:TopN_20 | 1.00 |
| TopN_13 | StreamAgg_12 | TableReader_21 | root | wh.account.marstime:desc, offset:0, count:1 | 1.00 |
| StreamAgg_12 | | TopN_13 | root | , funcs:max(wh.account.marstime) | 1.00 |
+----------------+--------------+----------------+------+----------------------------------------------------+-------------+
5 rows in set (0.00 sec)

mysql>

@victorggsimida
Copy link
Author

@XuHuaiyu
mysql> select min(marstime) From Account;
+---------------------+
| min(marstime) |
+---------------------+
| 2019-01-17 18:49:10 |
+---------------------+
1 row in set (0.08 sec)

mysql> select max(marstime) From Account;
+---------------------+
| max(marstime) |
+---------------------+
| 2019-01-17 18:49:10 |
+---------------------+
1 row in set (0.59 sec)

mysql>

@crazycs520
Copy link
Contributor

@victorggsimida , It looks like this bug: #7724.
When you create the index?

@victorggsimida
Copy link
Author

I just now rerun the sql

run alter table Account add column marstime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
run alter table Account add index(marstime);

@crazycs520
Copy link
Contributor

@victorggsimida , add column and create index in v2.0.11?

@XuHuaiyu XuHuaiyu added the type/bug The issue is confirmed as a bug. label Jan 17, 2019
@XuHuaiyu XuHuaiyu changed the title timestamp incorrect value with max different values of table and index for timestamp column Jan 17, 2019
@crazycs520
Copy link
Contributor

crazycs520 commented Jan 17, 2019

I reproduce this bug in tidb, pd, tikv release 2.1.
bellow is tidb version.

Release Version: v2.1.2-7-g08f56d318                                     
Git Commit Hash: 08f56d31857c75e9187f48a558dc9455105783b3               
Git Branch: release-2.1                                                  
UTC Build Time: 2019-01-16 04:29:17

prepare

use test.
create table t (a int);
insert into t1 values (2);

Then

Create 2 sessions, both execute use test first.
then:
session 1:

set global time_zone = '+02:00';

session 2:

alter table t1 add column b timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
alter table t1 add index(b);

Then, use follow sql to check:

select b from t1;
select b from t1 use index(b);
admin check table t1;

@XuHuaiyu
Copy link
Contributor

@victorggsimida
Thanks for your report, we'll fix it soon.

Feel free to let us know if you need any further help.

@victorggsimida
Copy link
Author

victorggsimida commented Jan 17, 2019

@XuHuaiyu

ok when u fix it,pls let me know. I will upgrade it

@crazycs520 crazycs520 changed the title different values of table and index for timestamp column timestamp column default value bug in multiple time zones Jan 29, 2019
@ghost
Copy link

ghost commented Jul 15, 2020

I can confirm that this bug has been fixed in mater. I am going to close this issue now, but please feel free to re-open if you have any further questions. Thanks!

..

mysql> select b from t1;
+---------------------+
| b                   |
+---------------------+
| 2020-07-14 18:42:19 |
+---------------------+
1 row in set (0.00 sec)

mysql> select b from t1 use index(b);
+---------------------+
| b                   |
+---------------------+
| 2020-07-14 18:42:19 |
+---------------------+
1 row in set (0.00 sec)

mysql> admin check table t1;
Query OK, 0 rows affected (0.02 sec)

@ghost ghost closed this as completed Jul 15, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants