planner: estimation error of `between ... and ...` when cardinality is low
- 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)
This bug was found by AI, please use the plan replayer below to reproduce:
[plan_replayer.zip](https://github.com/user-attachments/files/24667868/plan_replayer.zip)
```
mysql> EXPLAIN ANALYZE SELECT /*+ IGNORE_INDEX(LowCard PRIMARY) */ 1 FROM LowCard WHERE LowCard_int BETWEEN 0 AND 50;
+--------------------------+---------+---------+-----------+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+--------------------------+---------+---------+-----------+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
| Projection_4 | 3357.15 | 62159 | root | | time:93.7ms, open:69µs, close:8µs, loops:62, RU:41.95, Concurrency:5 | 1->Column#5 | 88.7 KB | N/A |
| └─IndexReader_7 | 3357.15 | 62159 | root | | time:93.6ms, open:66.6µs, close:4.21µs, loops:62, cop_task: {num: 9, max: 22.2ms, min: 4.38ms, avg: 10.4ms, p95: 22.2ms, tot_proc: 89ms, copr_cache_hit_ratio: 0.00, build_task_duration: 20.4µs, max_distsql_concurrency: 1}, fetch_resp_duration: 93.1ms, rpc_info:{Cop:{num_rpc:9, total_time:93.1ms}} | index:IndexRangeScan_6 | 376.6 KB | N/A |
| └─IndexRangeScan_6 | 3357.15 | 62159 | cop[tikv] | table:LowCard, index:idx_LowCard_int(LowCard_int) | tikv_task:{proc max:22.1ms, min:4.23ms, avg: 10.3ms, p80:14.6ms, p95:22.1ms, iters:0, tasks:9}, time_detail: {total_process_time: 89ms} | range:[0,50], keep order:false | N/A | N/A |
+--------------------------+---------+---------+-----------+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------+------+
3 rows in set (0.096 sec)
```
### 2. What did you expect to see? (Required)
The estimation should be more accurate.
### 3. What did you see instead (Required)
Large estimation error, 3357 vs. 62159
### 4. What is your TiDB version? (Required)
Master
Contributor guide
Assessment
This issue has not been assessed yet.