• Martin Hansson's avatar
    Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and · 3beeb5d0
    Martin Hansson authored
    ORDER BY computed col
          
    GROUP BY implies ORDER BY in the MySQL dialect of SQL. Therefore, when an
    index on the first table in the query is used, and that index satisfies
    ordering according to the GROUP BY clause, the query optimizer estimates the
    number of tuples that need to be read from this index. If there is a LIMIT
    clause, table statistics on tables following this 'sort table' are employed.
    
    There may be a separate ORDER BY clause however, which mandates reading the
    whole 'sort table' anyway. But the previous estimate was left untouched.
    
    Fixed by removing the estimate from EXPLAIN output if GROUP BY is used in
    conjunction with an ORDER BY clause that mandates using a temporary table.
    3beeb5d0
order_by.test 66.2 KB