On 07.10.10 08.29, Evgeny Potemkin wrote:
>> Do we have the same issue with other functions? E.g. CASE?
> The difference between coalesce and case is that case just passes val_xxx call
> to the appropriate item from the internal items array while coalesce is a
> descendant of Item_func_numhybrid and it operates in a bit different way.
> Item_func_numhybrid::val_xxx first calls xxx_op function of appropriate result
> type (str_op in case of datetime values) and then converts what it got to asked
> type. So there is no easy and safe way to fix it this way, IMO.
> With this fix even if there are similar problems they'll be hidden. Prior to it
> Item_cache_datetime expected a datetime returning item to also return correct
> int datetime representation. Now this is explicitly checked.
> However it's worth adding better implementation of result_as_longlong for
> IF/CASE functions. Will do in the next patch.
Just to chime in here, COALESCE is just a special case of a CASE, and could
easily have been transformed directly to a CASE expression. Simpler
optimization, simpler execution and less errors would be the result.
The same applies to NULLIF.