[infoschema] tikv_region_peers drops negative region_id/store_id predicates and returns all peers
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
> Evidence status: confirmed.
### 1. Minimal reproduce step (Required)
```sql
SELECT COUNT(*) FROM information_schema.tikv_region_peers; -- 269
EXPLAIN FORMAT='brief' SELECT * FROM information_schema.tikv_region_peers WHERE region_id = -1; -- MemTableScan without Selection and without region_ids filter
SELECT COUNT(*) FROM information_schema.tikv_region_peers WHERE region_id = -1; -- 269
SELECT COUNT(*) FROM information_schema.tikv_region_peers WHERE CASE WHEN region_id = -1 THEN TRUE ELSE FALSE END; -- 0
SELECT region_id, store_id, peer_id, region_id = -1 AS predicate_value FROM information_schema.tikv_region_peers WHERE region_id = -1 LIMIT 5; -- predicate_value=0 on returned rows
SELECT COUNT(*) FROM information_schema.tikv_region_peers WHERE store_id = -1; -- 269
SELECT COUNT(*) FROM information_schema.tikv_region_peers WHERE CASE WHEN store_id = -1 THEN TRUE ELSE FALSE END; -- 0
```
### 2. What did you expect to see? (Required)
A negative region_id/store_id predicate is unsatisfiable for TiKV peer metadata and should return an empty rowset. Invalid or out-of-domain extracted IDs must not bypass the SQL predicate; backend lookup errors for impossible filters should not replace SQL empty-row semantics.
### 3. What did you see instead? (Required)
The extractor removes the SQL predicate, fails to build a valid uint64 ID filter, and scans all peers. region_id=-1 and store_id=-1 return every row in information_schema.tikv_region_peers; rows visibly fail their own predicate. Non-numeric strings can additionally be coerced to region_ids:[0] and reported as a PD 400 error.
### 4. What is your TiDB version? (Required)
Confirmed on QA testbed 8192975. `SELECT VERSION()` returned `8.0.11-TiDB-v8.4.0-this-is-a-placeholder`.
Likely root cause and fix direction
extractCol removes EQ/IN predicates once it recognizes region_id/store_id. TikvRegionPeersExtractor then calls parseUint64 on the extracted string set. parseUint64 silently ignores ParseUint failures such as "-1" and returns an empty slice, but the original predicate has already been dropped and SkipRequest is not set. The resulting MemTableScan has neither a Selection nor a region/store ID filter, so it returns all peers.
Contributor guide
Research direction
Start with TikvRegionPeersExtractor, extractCol, and parseUint64, then reproduce the negative region_id and store_id queries from the issue. Trace how extracted predicates are removed and how an empty ID set reaches MemTableScan. Done means impossible negative predicates return an empty rowset without scanning all peers, while valid filters retain their existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100