[MDEV-9504] ANALYZE TABLE shows wrong 'rows' value for ORDER BY query Created: 2016-02-01  Updated: 2021-04-18

Status: Stalled
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.1.11
Fix Version/s: 10.2

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: analyze-stmt, optimizer


 Description   

create table t1 (
  a int, 
  filler1 char(128),
  filler2 char(128),
  key(a)
);
 
insert into t1 
select A.a+10*B.a+100*C.a, repeat('abc-',32), repeat('abc-',32)
from ten A, ten B, ten C;

EXPLAIN shows the correct estimate, we will read 10 rows:

explain select a from t1 order by a limit 10;
+------+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+------+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|    1 | SIMPLE      | t1    | index | NULL          | a    | 5       | NULL |   10 | Using index |
+------+-------------+-------+-------+---------------+------+---------+------+------+-------------+

ANALYZE's rows is different from the EXPLAIN:

analyze select a from t1 order by a limit 10;
MariaDB [j1]> analyze select a from t1 order by a limit 10;
+------+-------------+-------+-------+---------------+------+---------+------+------+--------+----------+------------+-------------+
| id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | r_rows | filtered | r_filtered | Extra       |
+------+-------------+-------+-------+---------------+------+---------+------+------+--------+----------+------------+-------------+
|    1 | SIMPLE      | t1    | index | NULL          | a    | 5       | NULL |  978 |  10.00 |   100.00 |     100.00 | Using index |
+------+-------------+-------+-------+---------------+------+---------+------+------+--------+----------+------------+-------------+

The value is wrong, it ignores the LIMIT clause.



 Comments   
Comment by Sergei Petrunia [ 2016-02-02 ]

The patch caused failures in buildbot. Fixing them is not easy.
Reverting the patch.

Comment by Daniel Black [ 2021-04-18 ]

from mariadb linked issue

     From: Jason Alpers <jasealpers@xxxxxxxxx>
    Date: Fri, 2 Apr 2021 14:04:25 -0500
 
Hello,
 
We're hitting the problem in MDEV-9504 (https://jira.mariadb.org/browse/MDEV-9504).  I see from the commit at https://github.com/MariaDB/server/commit/07b8aefe90ca830d2de068f2966cd2288b158a88
that this change was backed out due to test failures.  I ran through all the mysql-tests with and without the change and haven't been able to pinpoint a difference though.
 
The reverting commit indicates the correct value for select_limit is only computed when the query plan changes.  Any chance someone could provide more detail on what needs to be changed to avoid regression with this fix?
If there are sample queries that regress with only the original MDEV-9504 changes, that would be helpful.

Generated at Thu Feb 08 07:35:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.