Inconsistent cast conversion in Tiflash
Open
Nobody has claimed this yet.
affects-8.4
affects-8.5
component/compute
impact/inconsistency
may-affects-5.4
may-affects-6.1
may-affects-6.5
may-affects-7.1
may-affects-7.5
may-affects-8.1
severity/major
type/bug
- Dominant language
- C++
- Stars
- 1k
- Forks
- 423
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 24
Description
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Drop table if exists test_table;
CREATE TABLE test_table (
id INT PRIMARY KEY AUTO_INCREMENT,
col1 VARCHAR(255),
col2 TINYINT,
col3 SMALLINT
);
INSERT INTO test_table (col1, col2, col3) VALUES
('-9223372036854775809', -128, -32768),
('-9223372036854775808', 127, 32767);
ALTER TABLE test_table SET TIFLASH REPLICA 1;
SELECT /*+ READ_FROM_STORAGE(TIKV[test_table])*/
id,
col1,
CAST(col1 AS SIGNED) AS signed_int,
CAST(col1 AS UNSIGNED) AS unsigned_int,
CAST(col1 AS DECIMAL(65,30)) AS decimal_value,
CAST(col1 AS DOUBLE) AS double_value
FROM
test_table;
SELECT /*+ READ_FROM_STORAGE(TIFLASH[test_table])*/
id,
col1,
CAST(col1 AS SIGNED) AS signed_int,
CAST(col1 AS UNSIGNED) AS unsigned_int,
CAST(col1 AS DECIMAL(65,30)) AS decimal_value,
CAST(col1 AS DOUBLE) AS double_value
FROM
test_table;
2. What did you expect to see? (Required)
I find that unsigned_int is inconsistent across two queries.
3. What did you see instead (Required)
mysql> SELECT /*+ READ_FROM_STORAGE(TIKV[test_table])*/
-> id,
-> col1,
-> CAST(col1 AS SIGNED) AS signed_int,
-> CAST(col1 AS UNSIGNED) AS unsigned_int,
-> CAST(col1 AS DECIMAL(65,30)) AS decimal_value,
-> CAST(col1 AS DOUBLE) AS double_value
-> FROM
-> test_table;
+----+----------------------+----------------------+---------------------+-----------------------------------------------------+-----------------------+
| id | col1 | signed_int | unsigned_int | decimal_value | double_value |
+----+----------------------+----------------------+---------------------+-----------------------------------------------------+-----------------------+
| 1 | -9223372036854775809 | -9223372036854775808 | 9223372036854775808 | -9223372036854775809.000000000000000000000000000000 | -9.223372036854776e18 |
| 2 | -9223372036854775808 | -9223372036854775808 | 9223372036854775808 | -9223372036854775808.000000000000000000000000000000 | -9.223372036854776e18 |
+----+----------------------+----------------------+---------------------+-----------------------------------------------------+-----------------------+
2 rows in set, 4 warnings (0.01 sec)
mysql> SELECT /*+ READ_FROM_STORAGE(TIFLASH[test_table])*/ id, col1, CAST(col1 AS SIGNED) AS signed_int, CAST(col1 AS UNSIGNED) AS unsigned_int, CAST(col1 AS DECIMAL(65,30)) AS decimal_value, CAST(col1 AS DOUBLE) AS double_value FROM
test_table;
+----+----------------------+----------------------+---------------------+-----------------------------------------------------+-----------------------+
| id | col1 | signed_int | unsigned_int | decimal_value | double_value |
+----+----------------------+----------------------+---------------------+-----------------------------------------------------+-----------------------+
| 1 | -9223372036854775809 | -9223372036854775808 | 0 | -9223372036854775809.000000000000000000000000000000 | -9.223372036854776e18 |
| 2 | -9223372036854775808 | -9223372036854775808 | 9223372036854775808 | -9223372036854775808.000000000000000000000000000000 | -9.223372036854776e18 |
+----+----------------------+----------------------+---------------------+-----------------------------------------------------+-----------------------+
2 rows in set (0.01 sec)
4. What is your TiDB version? (Required)
TiDB v8.4.0
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided SQL reproduction on TiDB v8.4.0 and compare the TIKV and TIFLASH READ_FROM_STORAGE results for CAST(col1 AS UNSIGNED). Trace the cast handling in the two storage paths, focusing on the boundary values shown; it is done when both queries produce consistent unsigned_int results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100