[tiflash] TiFlash can collapse distinct string IDs during CAST and make REPLACE lose rows
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
**Environment**
TiDB ed2376acc6; TiKV 730be34f95; TiFlash 028f117d3c; TiFlash master 555bb7cc2a; MDL ON; one TiDB/PD/TiKV/TiFlash; no injection
**Steps**
Create a TiFlash-replicated source with strings 9223372036854775808, 18446744073709551615, and -9223372036854775809. Compare CAST AS SIGNED/UNSIGNED under tikv root and enforced TiFlash MPP. Then with sql_mode empty, REPLACE the two positive rows into matched tables keyed by CAST(external_id AS SIGNED). Verify EXPLAIN ownership, exact values, source preimages, destination counts, and ADMIN CHECK TABLE.
### 2. What did you expect to see? (Required)
TiDB root and TiFlash preserve the same full 64-bit intermediate domain, cast values, warnings, and pairwise identity. The two positive source IDs materialize as MinInt64 and -1, leaving two destination rows.
### 3. What did you see instead? (Required)
TiFlash returns MaxInt64 for both positive strings. REPLACE reports replacement activity and leaves one MaxInt64 row instead of two. It also returns zero for CAST('-9223372036854775809' AS UNSIGNED), where TiDB returns 9223372036854775808.
### 4. What is your TiDB version? (Required)
TiDB ed2376acc6; TiKV 730be34f95; TiFlash 028f117d3c; TiFlash master 555bb7cc2a; MDL ON; one TiDB/PD/TiKV/TiFlash; no injection
Likely root cause and fix direction
**Likely root cause**
TiFlash strToInt calls toUInt or toInt with destination T already Int64/UInt64. This performs a destination-range check before TiDB SQL cast semantics. TiDB instead parses positive strings through the full UInt64 domain and negative strings through Int64, then applies destination signedness and warning/error policy.
**Fix direction**
Separate lexical parsing from destination conversion. Parse non-negative input in UInt64 and negative input in Int64, then apply target signedness and TiDB-compatible warnings/errors. Add MPP conformance and persistent key-collision tests.
Contributor guide
Research direction
Start at TiFlash's strToInt conversion path, then run the provided CAST and REPLACE reproduction under TiDB root and enforced TiFlash MPP. Compare the cast values, warnings, source preimages, destination counts, and ADMIN CHECK TABLE results. Done means preserving TiDB-compatible full 64-bit cast behavior and adding MPP conformance plus persistent key-collision tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100