pingcap / pingcap/tidb

The cost of IndexLookUp is under-estimated when table rowsize is large

Open
#61,342 3 comments 0 reactions 0 assignees View on GitHub
affects-6.5 epic/cost-model may-affects-6.1 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major 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)
```
create table test(id int not null auto_increment primary key, data varchar(16383), status int, key idx(status));
insert into test(data,status) values(repeat('a',16383),0);
insert into test(data,status) select data,status from test; // repeat multiple times
analyze table test;
```

### 2. What did you expect to see? (Required)
The execution plan chooses TableFullScan by default.

```
mysql> explain format='verbose' select * from test use index() where status=0;
+-------------------------+---------+------------+-----------+---------------+-------------------------+
| id | estRows | estCost | task | access object | operator info |
+-------------------------+---------+------------+-----------+---------------+-------------------------+
| TableReader_7 | 1024.00 | 4479066.13 | root | | data:Selection_6 |
| └─Selection_6 | 1024.00 | 634675.47 | cop[tikv] | | eq(test.test.status, 0) |
| └─TableFullScan_5 | 1024.00 | 583577.87 | cop[tikv] | table:test | keep order:false |
+-------------------------+---------+------------+-----------+---------------+-------------------------+
3 rows in set (0.02 sec)
```
### 3. What did you see instead (Required)
```
mysql> explain format='verbose' select * from test where status=0;
+-------------------------------+---------+------------+-----------+-------------------------------+-------------------------------+
| id | estRows | estCost | task | access object | operator info |
+-------------------------------+---------+------------+-----------+-------------------------------+-------------------------------+
| IndexLookUp_10 | 1024.00 | 2888871.87 | root | | |
| ├─IndexRangeScan_8(Build) | 1024.00 | 208384.00 | cop[tikv] | table:test, index:idx(status) | range:[0,0], keep order:false |
| └─TableRowIDScan_9(Probe) | 1024.00 | 583577.87 | cop[tikv] | table:test | keep order:false |
+-------------------------------+---------+------------+-----------+-------------------------------+-------------------------------+
3 rows in set (0.00 sec)
```

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

v6.5.12

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.