• unknown's avatar
    Fix for BUG#12882 - min/max inconsistent on empty table. · 8e7217e4
    unknown authored
    The problem was in that the MIN/MAX optimization in opt_sum_query was
    replacing MIN/MAX functions with their constant argument without
    taking into account that a query has no result rows.
    
    
    mysql-test/r/func_group.result:
      Test for BUG#12882.
    mysql-test/t/func_group.test:
      Test for BUG#12882.
    sql/item_sum.cc:
      If it is known that a query has no result rows, do not call add()
      via the call to Item_sum::no_rows_in_result() which calls reset().
      Instead directly call clear() so that the MIN and MAX functions
      produce NULL when there are no result rows.
    sql/opt_sum.cc:
      * Do not apply MIN/MAX optimization when the operand of MIN/MAX is
        a constant if it can't be determined whether the query has any
        result rows. The reason is that if the query has result rows,
        then the result of MIN/MAX is its constant argument, but if the
        query result is empty, then the result of MIN/MAX must be NULL
        irrespective of its argument.
      
      * The patch also simplifies a bit the branch that hadles COUNT().
    8e7217e4
item_sum.cc 45.7 KB