pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.39k stars 5.85k forks source link

Wrong result in Tiflash when processing timestamp #57653

Open Dylan0222 opened 4 days ago

Dylan0222 commented 4 days 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 (
    c0 TIMESTAMP, 
    c1 DOUBLE, 
    c2 TIMESTAMP AS (c0) VIRTUAL NOT NULL, 
    c3 INT UNSIGNED NOT NULL, 
    c4 VARCHAR(255), 
    c5 JSON, 
    PRIMARY KEY (c3), 
    UNIQUE INDEX idx1 (c2, c0),
    INDEX idx2 (c4)
);

ALTER TABLE t1 SET TIFLASH REPLICA 1;
INSERT IGNORE INTO t1(c1, c3, c4, c5) 
VALUES 
    (-10.0, 2900, 'example', '{"key": "value"}'),
    (232.0, 3921, 'test', '{"key": "test"}'),
    (12222.0, 2123, 'demo', '{"key": "demo"}');

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(tikv[t1]) */ c0
    -> FROM t1
    -> WHERE c1 = -10 and c2 IS NOT NULL or JSON_UNQUOTE(JSON_EXTRACT(c5, '$.key')) = 'value';
+---------------------+
| c0                  |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
1 row in set (0.05 sec)

mysql> SELECT /*+ READ_FROM_STORAGE(tiflash[t1]) */ c0
    -> FROM t1
    -> WHERE c1 = -10 and c2 IS NOT NULL or JSON_UNQUOTE(JSON_EXTRACT(c5, '$.key')) = 'value';
+------+
| c0   |
+------+
| NULL |
+------+
1 row in set (0.05 sec)

4. What is your TiDB version? (Required)

TiDB v8.4.0

Dylan0222 commented 4 days ago

/label affects-8.4 /label affects-8.5

yibin87 commented 1 day ago

It's strange for the following queries from tikv storage.

mysql> select c0 is null from t1;
+------------+
| c0 is null |
+------------+
|          1 |
|          1 |
|          1 |
+------------+
3 rows in set (0.00 sec)

mysql> select c0 from t1;
+---------------------+
| c0                  |
+---------------------+
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
+---------------------+
3 rows in set (0.00 sec)