pingcap / pingcap/tidb

UnionScan returns wrong results for unsigned virtual generated columns in transaction-local reads

Open
#67,991 2 comments 0 reactions 0 assignees View on GitHub
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

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

TiDB uses different evaluation paths for virtual generated columns in transaction-local reads versus normal reads, and the behaviors are not consistent for unsigned generated values derived from negative intermediate results.
In the transaction-local path, the generated value is preserved as a wrapped unsigned value, while in the normal read path it is normalized to 0. As a result, the same row can expose different generated-column values before and after commit, which leads to inconsistent and incorrect query results.
```sql
DROP TABLE IF EXISTS t_union_unsigned;
CREATE TABLE t_union_unsigned (
a INT,
g BIGINT UNSIGNED GENERATED ALWAYS AS (a - 10) VIRTUAL,
KEY idx_g(g)
);

BEGIN;
INSERT IGNORE INTO t_union_unsigned(a) VALUES (1);
select * from t_union_unsigned;
+------+----------------------+
| a | g |
+------+----------------------+
| 1 | 18446744073709551607 |
+------+----------------------+
commit;
select * from t_union_unsigned;
+------+------+
| a | g |
+------+------+
| 1 | 0 |
+------+------+
```

### 2. What did you expect to see? (Required)
Transaction-local reads and post-commit reads should be consistent.
For the inserted row, the virtual generated column g should be treated as 0
### 3. What did you see instead (Required)
So the same row is visible as 18446744073709551607 inside the transaction, but as 0 after commit
### 4. What is your TiDB version? (Required)

Release Version: v9.0.0-beta.2.pre-1598-g874ff3792e
Edition: Community
Git Commit Hash: 874ff3792e7e0f51068547f90cefc1acbfed7232
Git Branch: HEAD
UTC Build Time: 2026-04-22 02:24:07
GoVersion: go1.25.8
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Kernel Type: Classic

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.