• Alexander Barkov's avatar
    MDEV-21034 GREATEST() and LEAST() malfunction for NULL · 24abbb9b
    Alexander Barkov authored
    There is a convention that Item::val_int() and Item::val_real() return
    SQL NULL doing effectively what this code does:
      null_value= true;
      return 0; // Always return 0 for SQL NULL
    
    This is done to optimize boolean value evaluation:
    if Item::val_int() or Item::val_real() returned 1 -
    that always means TRUE and never can means SQL NULL.
    This convention helps to avoid unnecessary testing
    Item::null_value after getting a non-zero return value.
    
    Item_func_min_max did not follow this convention.
    It could return a non-zero value together with null_value==true.
    This made evaluate_join_record() erroneously misinterpret
    SQL NULL as TRUE in this call:
    
      select_cond_result= MY_TEST(select_cond->val_int());
    
    Fixing Item_func_min_max to follow the convention.
    24abbb9b
item_func.cc 189 KB