• unknown's avatar
    Bug#27573: MIN() on an indexed column which is always NULL sets _other_ results · aaf6acae
    unknown authored
    to NULL
    
    For queries of the form SELECT MIN(key_part_k) FROM t1 
    WHERE key_part_1 = const and ... and key_part_k-1 = const,
    the opt_sum_query optimization tries to
    use an index to substitute MIN/MAX functions with their values according
    to the following rules:
    1) Insert the minimum non-null values where the WHERE clause still matches, or
    3) A row of nulls
    
    However, the correct semantics requires that there is a third case 2)
    such that a NULL value is substituted if there are only NULL values for 
    key_part_k.
    
    The patch modifies opt_sum_query() to handle this missing case.
    
    
    mysql-test/r/func_group.result:
      Bug #27573: Correct result
    mysql-test/t/func_group.test:
      Bug #27573: test case
    sql/opt_sum.cc:
      Bug #27573:
      Added code that will try to read the
      first non-null value for a given complete-field prefix, second
      choice is to read the null, and lastly set the error code if no row
      is found.
    aaf6acae
bdb_notembedded.result 1.21 KB