• mhansson/martin@linux-st28.site's avatar
    Bug#27573: MIN() on an indexed column which is always NULL sets _other_ results · 5bc137ff
    mhansson/martin@linux-st28.site 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.
    5bc137ff
opt_sum.cc 30.5 KB