pingcap / tiflash

The analytical engine for TiDB and TiDB Cloud. Try free: https://tidbcloud.com/free-trial
https://docs.pingcap.com/tidb/stable/tiflash-overview
Apache License 2.0
950 stars 410 forks source link

Wrong Result from Tiflash when process Time #9657

Open Dylan0222 opened 1 week ago

Dylan0222 commented 1 week ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Drop table if exists t1;
CREATE TABLE t1 (
    id INT PRIMARY KEY AUTO_INCREMENT,
    col1 TIME DEFAULT NULL
);

insert into t1 values(1, '838:59:59');
insert into t1 values(2, '-838:59:59');
insert into t1 values(3, '0');
ALTER TABLE t1 SET TIFLASH REPLICA 1;

2. What did you expect to see? (Required)

I find that the returned information is inconsistent across two queries.

3. What did you see instead (Required)

mysql> SELECT /*+ READ_FROM_STORAGE(TIFLASH[t1]) */
    ->     id,
    ->     col1,
    ->     ADDDATE(col1, INTERVAL 12 HOUR_MINUTE) AS updated_col1,
    ->     CASE
    ->         WHEN ADDDATE(col1, INTERVAL 12 HOUR_MINUTE) IS NULL THEN 'NULL VALUE'
    ->         ELSE 'VALID VALUE'
    ->     END AS value_status,
    ->     LENGTH(col1) AS col1_length,
    ->     CONCAT(ADDDATE(col1, INTERVAL 12 HOUR_MINUTE), ' processed') AS processed_value
    -> FROM
    ->     t1
    -> WHERE
    ->     ADDDATE(col1, INTERVAL 12 HOUR_MINUTE) IS NOT NULL;
+----+------------+--------------+--------------+-------------+----------------------+
| id | col1       | updated_col1 | value_status | col1_length | processed_value      |
+----+------------+--------------+--------------+-------------+----------------------+
|  1 | 838:59:59  | 839:09:59    | VALID VALUE  |           9 | 839:11:59 processed  |
|  2 | -838:59:59 | -838:49:59   | VALID VALUE  |          10 | -838:47:59 processed |
|  3 | 00:00:00   | 00:12:00     | VALID VALUE  |           8 | 00:12:00 processed   |
+----+------------+--------------+--------------+-------------+----------------------+
3 rows in set (0.04 sec)

mysql> SELECT /*+ READ_FROM_STORAGE(TIKV[t1]) */
    ->     id,
    ->     col1,
    ->     ADDDATE(col1, INTERVAL 12 HOUR_MINUTE) AS updated_col1,
    ->     CASE
    ->         WHEN ADDDATE(col1, INTERVAL 12 HOUR_MINUTE) IS NULL THEN 'NULL VALUE'
    ->         ELSE 'VALID VALUE'
    ->     END AS value_status,
    ->     LENGTH(col1) AS col1_length,
    ->     CONCAT(ADDDATE(col1, INTERVAL 12 HOUR_MINUTE), ' processed') AS processed_value
    -> FROM
    ->     t1
    -> WHERE
    ->     ADDDATE(col1, INTERVAL 12 HOUR_MINUTE) IS NOT NULL;
+----+------------+--------------+--------------+-------------+----------------------+
| id | col1       | updated_col1 | value_status | col1_length | processed_value      |
+----+------------+--------------+--------------+-------------+----------------------+
|  2 | -838:59:59 | -838:47:59   | VALID VALUE  |          10 | -838:47:59 processed |
|  3 | 00:00:00   | 00:12:00     | VALID VALUE  |           8 | 00:12:00 processed   |
+----+------------+--------------+--------------+-------------+----------------------+
2 rows in set, 1 warning (0.04 sec)

4. What is your TiDB version? (Required)

TiDB v8.4.0

Dylan0222 commented 1 week ago

/label affects-8.5

Dylan0222 commented 1 week ago

/label affects-8.4

Dylan0222 commented 1 week ago

I have found some additional bugs in TiFlash, which have been submitted in the TiDB repository. Could you please help check them as well? Thanks a lot, @JaySon-Huang.

yibin87 commented 4 days ago

The "updated_col1" value in tiflash is "00:12:00" instead of "00:10:00" with latest version, do I miss anything? @Dylan0222

Dylan0222 commented 4 days ago

The "updated_col1" value in tiflash is "00:12:00" instead of "00:10:00" with latest version, do I miss anything? @Dylan0222

I’m very sorry for my mistake. It is indeed 00:12:00, but there is one more row compared to TiKV. I will update the above information.

yibin87 commented 4 days ago

Tikv returns only two rows with the warning: evaluation failed: Duration value is out of range in '(838:59:59 - 00:12:00)' Check that mysql return two rows also, with warning: Datetime function: time field overflow And according to MySQL document, time data type should have a valid range: https://dev.mysql.com/doc/refman/8.4/en/time.html#:~:text=MySQL%20retrieves%20and%20displays%20TIME%20values%20in%20%27hh%3Amm%3Ass%27%20format%20(or%20%27hhh%3Amm%3Ass%27%20format%20for%20large%20hours%20values).%20TIME%20values%20may%20range%20from%20%27%2D838%3A59%3A59%27%20to%20%27838%3A59%3A59%27. Thus, tiflash needs to be consistent with this behavior.