1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

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
This commit is contained in:
Alexander Barkov
2024-04-04 17:13:09 +04:00
parent 0c0db46ba2
commit 9b02b7c77a
8 changed files with 110 additions and 64 deletions

View File

@ -118,8 +118,8 @@ create table t1 as select uuid(), length(uuid());
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`uuid()` uuid DEFAULT NULL,
`length(uuid())` int(10) DEFAULT NULL
`uuid()` uuid NOT NULL,
`length(uuid())` int(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
select length(`uuid()`) from t1;
length(`uuid()`)