The cost of IndexLookUp is under-estimated when table rowsize is large
- 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
Assessment
This issue has not been assessed yet.