• unknown's avatar
    Fix for BUG#11044 - "SELECT DISTINCT on indexed column returns inconsistent results" · d87c2dd6
    unknown authored
    The problem was that when there was no MIN or MAX function, after finding the
    group prefix based on the DISTINCT or GROUP BY attributes we did not search further
    for a key in the group that satisfies the equi-join conditions on attributes that
    follow the group attributes. Thus we ended up with the wrong rows, and subsequent
    calls to select_cond->val_int() in evaluate_join_record() were filtering those
    rows. Hence - the query result set was empty.
    
    The problem occured both for GROUP BY queries without MIN/MAX and for queries
    with DISTINCT (which were internally executed as GROUP BY queries).
    
    
    mysql-test/r/group_min_max.result:
      Added test result for BUG#11044. Notice that the group by query is
      equivalent to the distinct query and both are executed via the same
      algorithm.
    mysql-test/t/group_min_max.test:
      Added test for BUG#11044. Notice that the group by query is
      equivalent to the distinct query and both are executed via the
      same algorithm.
    sql/opt_range.cc:
      * Use the extended prefix in QUICK_GROUP_MIN_MAX_SELECT::get_next()
        to find keys that satisfy equality conditions in the case when there is
        no MIN or MAX function.
      * Corrected some method comments.
      * Corrected debug printout of cost information.
    d87c2dd6
group_min_max.result 74.2 KB