pingcap / pingcap/tidb

The estRows of equal condition is overestimated when the modify count is zero

Open
#65,924 8 comments 0 reactions 1 assignee Claimed by @terry1purcell View on GitHub
affects-8.5 report/customer 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)

```
set global tidb_analyze_column_options='all';
create table test(id int not null auto_increment, tag int);
insert into test(tag) values (0),(0) .... ; // millions of values 0
insert into test(tag) values (1); // one value 1
analyze table test;
```

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

```
mysql> explain select * from test where tag=1;
+-------------------------+------------+-----------+---------------+----------------------+
| id | estRows | task | access object | operator info |
+-------------------------+------------+-----------+---------------+----------------------+
| TableReader_7 | 1.00 | root | | data:Selection_6 |
| └─Selection_6 | 1.00 | cop[tikv] | | eq(test.test.tag, 1) |
| └─TableFullScan_5 | 4194305.00 | cop[tikv] | table:test | keep order:false |
+-------------------------+------------+-----------+---------------+----------------------+
3 rows in set (0.00 sec)
```

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

```
mysql> explain select * from test where tag=1;
+-------------------------+------------+-----------+---------------+----------------------+
| id | estRows | task | access object | operator info |
+-------------------------+------------+-----------+---------------+----------------------+
| TableReader_7 | 4194304.00 | root | | data:Selection_6 |
| └─Selection_6 | 4194304.00 | cop[tikv] | | eq(test.test.tag, 1) |
| └─TableFullScan_5 | 4194305.00 | cop[tikv] | table:test | keep order:false |
+-------------------------+------------+-----------+---------------+----------------------+
3 rows in set (0.00 sec)
```

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

v8.5.4

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.