planner: zero estimation result if all values are in TopN #47400
Closed
Description
opened on Oct 5, 2023
Enhancement
create table t (a int, key(a));
insert into t values (1), (3);
analyze table t with 2 topn;
insert into t values (2);
explain select * from t where a=2;
+------------------------+---------+-----------+---------------------+-------------------------------+
| id | estRows | task | access object | operator info |
+------------------------+---------+-----------+---------------------+-------------------------------+
| IndexReader_6 | 0.00 | root | | index:IndexRangeScan_5 |
| └─IndexRangeScan_5 | 0.00 | cop[tikv] | table:t, index:a(a) | range:[2,2], keep order:false |
+------------------------+---------+-----------+---------------------+-------------------------------+
2 rows in set (0.00 sec)
After v6.5, in the case above, the estimation result for a=2
is zero, which seems dangerous.
If no TopN
, it'll be 1
:
create table t (a int, key(a));
insert into t values (1), (3);
analyze table t with 0 topn;
insert into t values (2);
mysql> explain select * from t where a=2;
+------------------------+---------+-----------+---------------------+-------------------------------+
| id | estRows | task | access object | operator info |
+------------------------+---------+-----------+---------------------+-------------------------------+
| IndexReader_6 | 1.00 | root | | index:IndexRangeScan_5 |
| └─IndexRangeScan_5 | 1.00 | cop[tikv] | table:t, index:a(a) | range:[2,2], keep order:false |
+------------------------+---------+-----------+---------------------+-------------------------------+
Should we avoid using 0
in this case (this value is not in TopN and there is no Histogram)?
Metadata
Assignees
Labels
This bug affects the 6.5.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.This bug affects the 8.5.x(LTS) versions.the optimizer cardinality estimationCustomers have encountered this bug.SIG: PlannerThe issue or PR belongs to an enhancement.
Activity