MDEV-33827 UUID() returns a NULL-able result
It was wrong to derive Item_func_uuid from Item_func_sys_guid, because the former is a function returning the UUID data type, while the latter is a string function returning VARCHAR. As a result of the wrong hierarchy, Item_func_uuid erroneously derived Item_str_func::fix_fields(), which contains this code: /* In Item_str_func::check_well_formed_result() we may set null_value flag on the same condition as in test() below. */ if (thd->is_strict_mode()) set_maybe_null(); This code is not relevant to UUID() at all. A simple fix would be to set_maybe_null(false) in Item_func_uuid::fix_length_and_dec(). However, it'd fix only exactly this single consequence of the wrong class hierarchy, and similar bugs could appear again in the future. Moreover, we're going to add functions UUIDv4() and UUIDv7() soon (in 11.6). So it's better to fix the class hierarchy in the right way before adding these new functions. Fix: - Adding a new abstract class Item_fbt_func in the template in sql_type_fixedbin.h - Deriving Item_typecast_fbt from Item_fbt_func - Deriving Item_func_uuid from Item_fbt_func - Adding a new helper class UUIDv1. It derives from UUID, and additionally initializes the value to "UUID version 1" right in the constructor. Note, the new coming soon SQL functions UUIDv4() and UUIDv7() will also have corresponding classes UUIDv4 and UUIDv7. So now UUID() is a pure "returning UUID" function, like CAST(expr AS UUID) used to be, without any unintentional artifacts of functions returning VARCHAR/TEXT. Cleanup: - Removing the member Item_func_sys_guid::with_dashes, as it's not needed any more: * Item_func_sys_guid now does not have any descendants any more * Item_func_sys_guid::val_str() itself always displays without dashes
Showing
Please register or sign in to comment