Derived table optimization has wrong estimates for ORDER BY ... LIMIT

Bug #916551 reported by Sergey Petrunia
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
Medium
Igor Babaev

Bug Description

If I load mysql-test/include/world{_schema,}.inc and run the following query:

MariaDB [world]> explain select * from (select * from Country order by Population ASC limit 10) as small_country ;
+----+-------------+------------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+------+---------------+------+---------+------+------+----------------+
| 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 239 | |
| 2 | DERIVED | Country | ALL | NULL | NULL | NULL | NULL | 239 | Using filesort |
+----+-------------+------------+------+---------------+------+---------+------+------+----------------+
2 rows in set (0.00 sec)

I get 239 as the number of rows which will be scanned in table <derived2>.

This estimate is wrong, it should be easy to figure that "LIMIT 10" caps table
size to 10 rows.

Revision history for this message
Sergey Petrunia (sergefp) wrote :

Note that in MySQL 5.6.4-m7 the estimate is correct - it's 10 rows for <derived2>.

Changed in maria:
assignee: nobody → Igor Babaev (igorb-seattle)
Revision history for this message
Igor Babaev (igorb-seattle) wrote :

This is a duplicate of LP bug #917990.

Changed in maria:
status: New → Confirmed
importance: Undecided → Medium
milestone: none → 5.3
Changed in maria:
status: Confirmed → Fix Committed
Revision history for this message
Elena Stepanova (elenst) wrote :

Fix for bug #917990 released with 5.3.4-rc.

Changed in maria:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.