pingcap / pingcap/tidb

TiKV and TiFlash Return Different Results for Query with Bitwise Shift (<<) and BETWEEN

Open
#61,449 4 comments 0 reactions 0 assignees View on GitHub
may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)
```
DROP TABLE IF EXISTS t0;
CREATE TABLE t0(c0 TINYINT , c1 TINYINT, c2 TINYINT , PRIMARY KEY(c0, c2, c1));
ALTER TABLE t0 SET TIFLASH REPLICA 1;
INSERT INTO t0 VALUES (0, 0, 0);

SELECT /*+ read_from_storage(tikv[t0]) */ t0.c0 FROM t0 WHERE (((216854894) BETWEEN (t0.c2) AND (t0.c2))AND(((-1247022746)<<(t0.c1))));
SELECT /*+ read_from_storage(tiflash[t0]) */ t0.c0 FROM t0 WHERE (((216854894) BETWEEN (t0.c2) AND (t0.c2))AND(((-1247022746)<<(t0.c1))));
```

### 2. What did you expect to see? (Required)
The same query returns the same results on both TiKV and TiFlash.
### 3. What did you see instead (Required)
```
mysql> SELECT /*+ read_from_storage(tikv[t0]) */ t0.c0 FROM t0 WHERE (((216854894) BETWEEN (t0.c2) AND (t0.c2))AND(((-1247022746)<<(t0.c1))));
Empty set (0.00 sec)

mysql> SELECT /*+ read_from_storage(tiflash[t0]) */ t0.c0 FROM t0 WHERE (((216854894) BETWEEN (t0.c2) AND (t0.c2))AND(((-1247022746)<<(t0.c1))));
+----+
| c0 |
+----+
| 0 |
+----+
1 row in set (0.13 sec)
```

If the primary key is NOT defined on the columns c0, c1, c2 ... then the results from TiKV and TiFlash are consistent
```
mysql> CREATE TABLE t0(c0 TINYINT, c1 TINYINT, c2 TINYINT);
Query OK, 0 rows affected (0.11 sec)

mysql> ALTER TABLE t0 SET TIFLASH REPLICA 1;
Query OK, 0 rows affected (0.13 sec)

mysql> INSERT INTO t0 VALUES (0, 0, 0);
Query OK, 1 row affected (0.03 sec)

mysql> SELECT /*+ read_from_storage(tikv[t0]) */ t0.c0 FROM t0 WHERE (((216854894) BETWEEN (t0.c2) AND (t0.c2))AND(((-1247022746)<<(t0.c1))));
Empty set (0.00 sec)

mysql> SELECT /*+ read_from_storage(tiflash[t0]) */ t0.c0 FROM t0 WHERE (((216854894) BETWEEN (t0.c2) AND (t0.c2))AND(((-1247022746)<<(t0.c1))));
Empty set (0.15 sec)
```
### 4. What is your TiDB version? (Required)
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.0
Edition: Community
Git Commit Hash: d13e52ed6e22cc5789bed7c64c861578cd2ed55b
Git Branch: HEAD
UTC Build Time: 2024-12-18 02:26:06
GoVersion: go1.23.3
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.