-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
time_zone=SYSTEM has an influence on timestamp. #29427
Comments
China was using DST in the year 1990, which springs forward from 1990-04-15T02:00:00+08 to 1990-04-15T03:00:00+09 and fall backs from 1990-09-16T02:00:00+09 to 1990-09-16T01:00:00+08. The above is the rule used when the tz-database version is 2018f or above. Before this version, the spring forward / fall back time was wrongly set to 00:00:00 local time (eggert/tz@937286d). If your system's tz version is below 2018f, the second "bug" is not a bug at all. Upgrade your system. The "first bug" may be caused by using the coprocessor where TiKV and TiDB are using different tz-database versions. |
The first bug is related to the |
For the "first bug", I can't reproduce the different result with / without |
i suppose your system's TiKV is currently using |
It can reproduce in one of our internal testing cluster. The root cause for "1 SELECT with WHERE or not should have the same result when time_zone = SYSTEM" is that when timezone is "Asia/Shanghai", and the encoded UTC time value is 2240854276563795969, the calculated results in TiKV layer and TiDB layer is different. This is how I debug: dlv attach $PID, add break point and get the result of query "select * from t where id = 1", this is a point get and the kv value part from tikv is Add break point and debug another code path, query "select * from t where id = 1 or id > 100", this will be the coprocessor code path. The result is calculated in TiKV layer, and the final result is "1990-04-15 02:30:12" There is a session variable,
It's now clear that decode the raw KV data to chunk, when handled in TiKV or TiDB, the result is different. I test more timezone and find that 'Asia/Shanghai' seems to be the only case that TiDB and TiKV calculated the different result. All other timezone like "+8:00" "-8:00" "Australia/Perth" "America/Chicago" etc, the result is the same between TiDB and TiKV. |
obviously you haven't performed targeted checks against changes since 2018i 😏. example of difference when the TiDB node's set @@time_zone = '+00:00';
drop table if exists t;
create table t(id int primary key, a timestamp);
insert into t values
(1, '1985-04-19 21:30:00'),
(2, '1985-04-19 22:30:00'),
(3, '1985-04-19 23:30:00');
set @@time_zone = 'Europe/Istanbul'; -- not "SYSTEM" but anyway
select * from t;
/*
+----+---------------------+
| id | a |
+----+---------------------+
| 1 | 1985-04-20 00:30:00 |
| 2 | 1985-04-20 01:30:00 |
| 3 | 1985-04-20 02:30:00 |
+----+---------------------+
3 rows in set (0.04 sec)
*/
select * from t where id in (1, 2, 3);
/*
+----+---------------------+
| id | a |
+----+---------------------+
| 1 | 1985-04-19 23:30:00 |
| 2 | 1985-04-20 00:30:00 |
| 3 | 1985-04-20 02:30:00 |
+----+---------------------+
3 rows in set (0.04 sec)
*/ |
Do our TiDB distribution ship with a |
I believe we currently read the zoneinfo files provided by the OS on each instance, but GO does support embedding the tzdata database: https://pkg.go.dev/time/tzdata If users keep their TiDB binaries up to date (and uniform), that would be one way of guaranteeing consistency. |
The issue of the "first bug" is that both (a) TiDB's There are several solutions I can think of,
|
I vote for 2 |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
prepare data:
test:
2. What did you expect to see? (Required)
the results of timestamp should be the same.
3. What did you see instead (Required)
SELECT
withWHERE
or not should have the same result whentime_zone = SYSTEM
.4. What is your TiDB version? (Required)
v5.1.1, v5.2.0
The text was updated successfully, but these errors were encountered: