• unknown's avatar
    Fixed bug#18360: Incorrect type coercion in IN() results in false comparison · a719dc38
    unknown authored
    The IN() function uses agg_cmp_type() to aggregate all types of its arguments
    to find out some common type for comparisons. In this particular case the 
    char() and the int was aggregated to double because char() can contain values
    like '1.5'. But all strings which do not start from a digit are converted to
    0. thus 'a' and 'z' become equal. 
    This behaviour is reasonable when all function arguments are constants. But 
    when there is a field or an expression this can lead to false comparisons. In
    this case it makes more sense to coerce constants to the type of the field
    argument.
    
    The agg_cmp_type() function now aggregates types of constant and non-constant
    items separately. If some non-constant items will be found then their
    aggregated type will be returned. Thus after the aggregation constants will be
    coerced to the aggregated type. 
    
    
    mysql-test/t/func_in.test:
      Added test case for bug#18360: Incorrect type coercion in IN() results in false comparison.
    mysql-test/r/func_in.result:
      Added test case for bug#18360: Incorrect type coercion in IN() results in false comparison.
    sql/item_cmpfunc.cc:
      Fixed bug#18360: Incorrect type coercion in IN() results in false comparison.
      The agg_cmp_type() function now aggregates types of constant and non-constant
      items separately. If some non-constant items will be found then their
      aggregated type will be returned. Thus after the aggregation constants will
      be coerced to the aggregated type.
    a719dc38
func_in.result 4.72 KB