[MDEV-17111] Estimates are low for a condition that satisfies all the rows of an INNODB table Created: 2018-08-31  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Optimizer, Storage Engine - InnoDB
Affects Version/s: 10.0, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Varun Gupta (Inactive) Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: records_in_range

Issue Links:
Relates
relates to MDEV-19424 InnoDB's records_in_range estimates a... Open
relates to MDEV-14621 Query very slow compared to Mysql Closed
relates to MDEV-21136 InnoDB's records_in_range estimates c... Closed

 Description   

Example: a table with 50K rows. All rows have a1=1. However, ha_innobase::records_in_range() will return about 25K to the optimizer.

This may cause a bad query plan. The impact of this is bigger in recent versions as they use E(rows) from the potential range accesses as a source of data about condition selectivity.

--source include/have_sequence.inc
--source include/have_innodb.inc
 
CREATE TABLE t1 (id int PRIMARY KEY, a1 int, KEY (a1))engine=innodb;
INSERT INTO t1 SELECT seq FROM seq_1_to_50000;

MariaDB [test]> explain select * FROM t1 force index(a1) where a1=1;
+------+-------------+-------+------+---------------+------+---------+-------+-------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref   | rows  | Extra       |
+------+-------------+-------+------+---------------+------+---------+-------+-------+-------------+
|    1 | SIMPLE      | t1    | ref  | a1            | a1   | 5       | const | 24485 | Using index |
+------+-------------+-------+------+---------------+------+---------+-------+-------+-------------+

MariaDB [test]> select count(*) from t1 where a1=1;
+----------+
| count(*) |
+----------+
|    50000 |
+----------+

I would expect the estimates to be more closer for such cases.



 Comments   
Comment by Sergei Petrunia [ 2018-09-03 ]

Notes from Slack discussion

Generated at Thu Feb 08 08:34:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.