-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
affects-5.4This bug affects the 5.4.x(LTS) versions.This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.This bug affects the 8.5.x(LTS) versions.epic/cardinality-estimationthe optimizer cardinality estimationthe optimizer cardinality estimationreport/customerCustomers have encountered this bug.Customers have encountered this bug.severity/majorsig/plannerSIG: PlannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.The issue or PR belongs to an enhancement.
Description
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)?
AilinKid, hawkingrei and fixdb
Metadata
Metadata
Assignees
Labels
affects-5.4This bug affects the 5.4.x(LTS) versions.This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.This bug affects the 8.5.x(LTS) versions.epic/cardinality-estimationthe optimizer cardinality estimationthe optimizer cardinality estimationreport/customerCustomers have encountered this bug.Customers have encountered this bug.severity/majorsig/plannerSIG: PlannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.The issue or PR belongs to an enhancement.