pingcap / pingcap/tidb

Planner should consider specified partition when caculate `estRows`

Open
#53,657 2 comments 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
component/tablepartition epic/cardinality-estimation sig/planner type/enhancement
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

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.