ADMIN CHECK reports false data inconsistency for partial multi-valued indexes
- 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)
```sql
DROP TABLE IF EXISTS t;
CREATE TABLE t (
pk INT PRIMARY KEY,
a JSON,
flag INT,
INDEX idx ((CAST(a AS SIGNED ARRAY))) WHERE flag = 1
);
INSERT INTO t VALUES
(0, '[0,1,2]', 0),
(1, '[1,2,3]', 1);
ADMIN CHECK TABLE t;
ADMIN CHECK INDEX t idx;
```
The row with pk = 0 does not satisfy flag = 1, so it should not have any entries in idx.
### 2. What did you expect to see? (Required)
Both `ADMIN CHECK TABLE t` and `ADMIN CHECK INDEX t idx` should complete successfully.
Rows that do not satisfy the partial index condition are not expected to have index entries and should be skipped by the record-to-index consistency check.
### 3. What did you see instead (Required)
Both commands incorrectly report data inconsistency for the row excluded by the partial index condition:
```
ERROR 8223 (HY000): data inconsistency in table: t, index: idx,
handle: 0, index-values:"" != record-values:
"handle: 0, values: [KindMysqlJSON [0, 1, 2]]"
```
The record-side check calls Index.Exist for every table row without first evaluating the partial index condition, causing a false-positive inconsistency report.
### 4. What is your TiDB version? (Required)
The issue was reproduced on TiDB master:
```
Git Commit Hash: 66f307fab7ddfd1a9861715cd5533a04ebe2379d
Git Branch: master
```
Contributor guide
Assessment
This issue has not been assessed yet.