• Martin Hansson's avatar
    Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and · 20bdf763
    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.
    20bdf763
sql_select.cc 550 KB