pingcap / pingcap/tidb

statistics: targeted stats refresh can leave pseudo stats after analyze

Open
#69,882 0 comments 0 reactions 1 assignee Claimed by @wlwilliamx View on GitHub
component/statistics severity/moderate sig/planner 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)

1. Analyze a table so its persisted `mysql.stats_meta` version is lower than a later, unrelated stats update.
2. Evict or clear the analyzed table from the in-memory stats cache, then let a planner lookup cache a pseudo entry for it.
3. Advance the cache-wide maximum stats version with another physical table.
4. Run the targeted `StatsHandle.Update(ctx, infoSchema, tableID)` used after `ANALYZE TABLE`.

A deterministic unit-test setup uses persisted version `100` for the requested table and cache-wide version `200`. The targeted update then queries:

```sql
SELECT ...
FROM mysql.stats_meta
WHERE version > 200 AND table_id IN (...)
```

### 2. What did you expect to see? (Required)

The targeted update should reload every explicitly requested table or partition from `mysql.stats_meta`, even when its version is below the cache-wide watermark. It should not advance that watermark.

### 3. What did you see instead (Required)

The cache-wide version predicate filters out the requested row. The table remains pseudo in the stats cache immediately after `ANALYZE TABLE`, so subsequent planning can use pseudo estimates.

### 4. What is your TiDB version? (Required)

TiDB `master` at commit `531e40cd25989404f9fd1f51cddf278326983af1` (fetched on 2026-07-16).

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.