pingcap / pingcap/tidb

Unstable statistical information of tables

Open
#52,430 1 comment 0 reactions 1 assignee Claimed by @winoros 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)
```sql
drop table if exists t1;
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE TABLE t1 (j JSON, pk VARCHAR(10) AS (j->>'$.id') STORED PRIMARY KEY);
INSERT INTO t1 (j) VALUES ('{"id":"a"}'), ('{"id":"b"}'), ('{"id":"c"}');
# Analyze to ensure table statistics are up to date before EXPLAIN.
ANALYZE TABLE t1;
explain SELECT * FROM t1 WHERE j->>'$.id'='b';

```

### 2. What did you expect to see? (Required)
```sql
[09:32:46]TiDB root:test> explain SELECT * FROM t1 WHERE j->>'$.id'='b';
+---------------------+---------+-----------+---------------+------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+---------------------+---------+-----------+---------------+------------------------------------------------------------------------------------+
| TableReader_7 | 2.40 | root | | data:Selection_6 |
| └─Selection_6 | 2.40 | cop[tikv] | | eq(json_unquote(cast(json_extract(test.t1.j, "$.id"), var_string(16777216))), "b") |
| └─TableFullScan_5 | 3.00 | cop[tikv] | table:t1 | keep order:false, stats:partial[j:unInitialized] |
+---------------------+---------+-----------+---------------+------------------------------------------------------------------------------------+
```
### 3. What did you see instead (Required)
sometimes the stats is `stats:partial[j:missing]`
![图片](https://github.com/pingcap/tidb/assets/10184437/47082862-47c1-4146-8050-f3f37b32c7ee)

### 4. What is your TiDB version? (Required)
```sql
[09:34:30]TiDB root:test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------+
| Release Version: v8.1.0-alpha-28-g8f985c70ae |
| Edition: Community |
| Git Commit Hash: 8f985c70aed8b289b7373fc317a89394b0b2d91d |
| Git Branch: HEAD |
| UTC Build Time: 2024-04-07 05:38:47 |
| GoVersion: go1.21.6 |
| Race Enabled: false |
| Check Table Before Drop: false |
| Store: tikv |
+-----------------------------------------------------------+
```

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.