[MDEV-31053] UUID(size) should be disallowed Created: 2023-04-14  Updated: 2024-01-16

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.11.2
Fix Version/s: 10.11

Type: Bug Priority: Minor
Reporter: Federico Razzoli Assignee: Dave Gosselin
Resolution: Unresolved Votes: 0
Labels: types, uuid


 Description   

It is possible to specify a length for a UUID column:

MariaDB [test]> CREATE TABLE t (
    ->     uuid UUID(24)
    -> );
Query OK, 0 rows affected (0.040 sec)

As far as I can tell, this has no effect, so it shouldn't be allowed or it should at least produce a warning. But if it has an effect, it should be documented.



 Comments   
Comment by Dave Gosselin [ 2023-12-15 ]

UUIDs are a UDT in MariaDB 10.11. As such, the grammar parsing follows field_type_all then udt_name productions, invoking LEX::set_field_type_udt. That method performs a lookup on the name of the type (in this case, 'UUID') and fetches the type_handler_uuid_dispatcher, retaining the passed length, 24, as part of the Lex_field_type_st. This value is ignored and in fact overwritten later during Type_handler_fbt<UUID<false>, Type_collection_uuid>::Column_definition_fix_attributes when the column's length is changed to 36 (the result of FbtImpl::max_char_length()). This is also the maximum length of a UUID code when represented as ASCII, including the hyphen separators. So in effect, the length specified by the user has no effect. We could emit a warning if we detect that this value is anything other than 0, but unless we change our grammar handling for UDTs, we cannot reject this query outright if we see the UUID field presenting with '(' x ')' because UDTs aren't invited into any aspect of syntax validation during create table.

Generated at Thu Feb 08 10:20:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.