Planner should consider specified partition when caculate `estRows`
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
```
mysql> create table t(a int, b int, unique index idx(b)) partition by hash(a) partitions 5;
Query OK, 0 rows affected (0.03 sec)
mysql> insert into t values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> analyze table t;
Query OK, 0 rows affected, 5 warnings (0.25 sec)
```
The `estRows` below should be 1 instead of 5.
```
mysql> explain select * from t partition(p0) use index(idx);
+-------------------------------+---------+-----------+-----------------------+--------------------+
| id | estRows | task | access object | operator info |
+-------------------------------+---------+-----------+-----------------------+--------------------+
| IndexLookUp_8 | 5.00 | root | partition:p0 | |
| ├─Selection_7(Build) | 5.00 | cop[tikv] | | in(_tidb_pid, 282) |
| │ └─IndexFullScan_4 | 5.00 | cop[tikv] | table:t, index:idx(b) | keep order:false |
| └─TableRowIDScan_5(Probe) | 5.00 | cop[tikv] | table:t | keep order:false |
+-------------------------------+---------+-----------+-----------------------+--------------------+
4 rows in set (0.00 sec)
```
Another example without global index
```
mysql> explain select * from t partition(p0);
+-----------------------+---------+-----------+---------------+----------------------+
| id | estRows | task | access object | operator info |
+-----------------------+---------+-----------+---------------+----------------------+
| TableReader_5 | 5.00 | root | partition:p0 | data:TableFullScan_4 |
| └─TableFullScan_4 | 5.00 | cop[tikv] | table:t | keep order:false |
+-----------------------+---------+-----------+---------------+----------------------+
2 rows in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.