MariaDB UUID functions plugin

At the end of my first day at MariaDB, I wanted to investigate a bit on how easy it is to extend MariaDB Server with extensions.

As for MySQL, MariaDB can be extended with plugins. MariaDB has no component infrastructure, but extensibility via plugins seems easier.

And indeed, it was very easy to add some functions (542 lines of code) to parse the supported UUIDs.

Compared to MySQL, MariaDB natively supports UUID versions 1, 4, and 7.

My plugin adds some functions to parse those UUIDs and extract the timestamp value when supported (v1 and v7).

The plugin can be found on GitHub: https://github.com/lefred/mariadb-plugin-func_uuid

Let’s have a look at its usage:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 12.3.1-MariaDB-log Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Help others discover MariaDB. Star it on GitHub: https://github.com/MariaDB/server

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB > install soname 'func_uuid.so';
Query OK, 0 rows affected (0.0014 sec)

MariaDB > SELECT plugin_name, plugin_type, plugin_library,
          plugin_description, plugin_author 
          FROM information_schema.PLUGINS WHERE PLUGIN_TYPE = 'FUNCTION'
          AND plugin_library='func_uuid.so'\G
*************************** 1. row ***************************
       plugin_name: uuid_to_timestamp
       plugin_type: FUNCTION
    plugin_library: func_uuid.so
plugin_description: Function UUID_TO_TIMESTAMP()
     plugin_author: lefred
*************************** 2. row ***************************
       plugin_name: uuid_to_timestamp_long
       plugin_type: FUNCTION
    plugin_library: func_uuid.so
plugin_description: Function UUID_TO_TIMESTAMP_LONG()
     plugin_author: lefred
*************************** 3. row ***************************
       plugin_name: uuid_to_unixtime
       plugin_type: FUNCTION
    plugin_library: func_uuid.so
plugin_description: Function UUID_TO_UNIXTIME()
     plugin_author: lefred
3 rows in set (0.001 sec)

We can see that the plugin creates 3 new functions. We can also notice them in the error log:

2026-02-16 19:42:41 4 [Warning] Plugin 'uuid_to_timestamp' is of maturity level experimental while the server is gamma
2026-02-16 19:42:41 4 [Warning] Plugin 'uuid_to_timestamp_long' is of maturity level experimental while the server is gamma
2026-02-16 19:42:41 4 [Warning] Plugin 'uuid_to_unixtime' is of maturity level experimental while the server is gamma

UUIDv1 and UUIDv7

As those functions extract the timestamp of the UUID, they only work with UUIDv1 (the default) and UUIDv7.

When using version 4, it fails:

MariaDB > select uuid_to_timestamp(uuid_v4());
ERROR: 1105 (HY000): uuid_to_timestamp: not a valid UUID or no timestamp available

Let’s try to extract the timestamp of the two UUID versions storing the timestamp:

MariaDB > select uuid_to_timestamp(uuid());
+---------------------------+
| uuid_to_timestamp(uuid()) |
+---------------------------+
| 2026-02-16 19:43:41.500   |
+---------------------------+
1 row in set (0.000 sec)

MariaDB > select uuid_to_timestamp(uuid_v7());
+------------------------------+
| uuid_to_timestamp(uuid_v7()) |
+------------------------------+
| 2026-02-16 19:44:07.776      |
+------------------------------+
1 row in set (0.001 sec)

We can also have a longer output:

MariaDB > select uuid_to_timestamp_long(uuid());
+--------------------------------+
| uuid_to_timestamp_long(uuid()) |
+--------------------------------+
| Mon Feb 16 19:44:32 2026 CET   |
+--------------------------------+
1 row in set (0.000 sec)

MariaDB > select uuid_to_timestamp_long(uuid_v7());
+-----------------------------------+
| uuid_to_timestamp_long(uuid_v7()) |
+-----------------------------------+
| Mon Feb 16 19:44:49 2026 CET      |
+-----------------------------------+
1 row in set (0.000 sec)

If you are using UUIDs as a column in a table, it’s possible to know when the record was created even without a dedicated timestamp column 😉

Conclusion

In fact, it’s very easy to extend MariaDB with plugins. The secret lies in the plugin’s declaration. This is the content for one function:

maria_declare_plugin(type_test)
{
  MariaDB_FUNCTION_PLUGIN,                      // the plugin type (see include/mysql/plugin.h)
  &plugin_descriptor_function_uuid_to_timestamp, // pointer to type-specific plugin descriptor
  "uuid_to_timestamp",                           // plugin name
  "lefred",                                     // plugin author
  "Function UUID_TO_TIMESTAMP()",                // the plugin description
  PLUGIN_LICENSE_GPL,                            // the plugin license (see include/mysql/plugin.h)
  0,                                            // Pointer to plugin initialization function
  0,                                            // Pointer to plugin deinitialization function
  0x0100,                                       // Numeric version 0xAABB means AA.BB version
  NULL,                                         // Status variables
  NULL,                                         // System variables
  "1.0",                                       // String version representation
  MariaDB_PLUGIN_MATURITY_EXPERIMENTAL         // Maturity(see include/mysql/plugin.h)*/
}
maria_declare_plugin_end;

I have some other plugins in mind that I will share soon. But in case you want to extend MariaDB, don’t hesitate, and don’t forget that you can find help on our Zulip chat. And in case you want to contribute code to MariaDB, check our contribution page.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply

Your email address will not be published. Required fields are marked *