Skip to content

Conversation

@varundeepsaini
Copy link

  • The Jira issue number for this PR is: MDEV-33710

Description

Adds UUID_TIMESTAMP(uuid) function to extract timestamps from UUIDv1 and UUIDv7 values. Returns NULL for other versions (e.g., v4) or invalid input.

Release Notes

New function: UUID_TIMESTAMP(uuid) - Returns the generation timestamp from UUIDv1/v7 as TIMESTAMP(6).

How can this PR be tested?

./mysql-test/mtr --suite=type_uuid func_uuid_timestamp

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the main branch.
  • This is a bug fix.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@varundeepsaini varundeepsaini force-pushed the MDEV-33710-uuid-timestamp branch from 5bbed91 to 9aa596f Compare December 23, 2025 19:33
@FooBarrior
Copy link
Contributor

I have some concern about the tests... it's not easy to validate the UUID values used there.
One approach I can think of is:

  1. set timestamp to a fixed value. This will affect NOW() output
  2. See that value returned by UUID_TIMESTAMP(UUID*()) matches our value

We can test a couple of random values, plus corner cases: min and max value for timestamp variable, and for UUID

@FooBarrior
Copy link
Contributor

Strangely, there is a different result outpoutted in amd64-debian-11-debug-ps-embedded test run:

--- /home/buildbot/amd64-debian-11-debug-ps-embedded/build/plugin/type_uuid/mysql-test/type_uuid/func_uuid_timestamp.result	2025-12-23 19:37:10.000000000 +0000
+++ /home/buildbot/amd64-debian-11-debug-ps-embedded/build/plugin/type_uuid/mysql-test/type_uuid/func_uuid_timestamp.reject	2025-12-23 19:42:40.539670984 +0000
@@ -1,9 +1,9 @@
 SELECT UUID_TIMESTAMP('018d17f3-e9a3-7000-8000-000000000000');
 UUID_TIMESTAMP('018d17f3-e9a3-7000-8000-000000000000')
-2024-01-17 20:34:37.539000
+2024-01-17 15:04:37.539000
 SELECT UUID_TIMESTAMP('0188b5b8-8000-7000-8000-000000000000');
 UUID_TIMESTAMP('0188b5b8-8000-7000-8000-000000000000')
-2023-06-13 22:35:47.520000
+2023-06-13 17:05:47.520000

Please take a look

@varundeepsaini
Copy link
Author

i think the test failing is a timezone issue (exact 5.30 HRS), ill fix that

Copy link
Contributor

@FooBarrior FooBarrior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @varundeepsaini for the update, and besides such aquick one!
The PR moves in the right direction. Still some work to be done.


my_time_t seconds;
ulong usec;
const uchar *buf= (const uchar *) uuid.to_lex_cstring().str;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No functions really need uchar (except the newly added one, which we can change), also uuid is natively stored in char, so why make a conversion?

Copy link
Author

@varundeepsaini varundeepsaini Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mi_ prefix functions use uchar (they do cast it themselves tho, i can remove it from here but again, the cast is still there)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? where??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mysys/my_uuid.c Outdated
Bytes 6-7: version (4 bits) + sub-millisecond precision (12 bits)
*/

my_bool my_uuid_extract_ts(const uchar *uuid, my_time_t *seconds, ulong *usec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use just int.
Or alternatively, bool, with true meaning success

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well use bool here since there are only two result types.

Note for both int and bool: I hear that the convention is 1/true = error (which one might consider “timestamp invalid” to be one) and 0/false = no error.

@FooBarrior
Copy link
Contributor

Never mind the failing appveyor, it is used to be failing. However it may be useful to check the results, as it can reveal some windows build quirks (for example msvc doesn't like bool vs int mismatch, and has a 32-bit long )

@FooBarrior FooBarrior requested review from FooBarrior and removed request for FooBarrior December 26, 2025 14:04
Copy link
Contributor

@ParadoxV5 ParadoxV5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just passing by

mysys/my_uuid.c Outdated
Comment on lines 261 to 265
return 1;
}

if (version == 1)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beginner question: Would a switch block work here?

mysys/my_uuid.c Outdated
Bytes 6-7: version (4 bits) + sub-millisecond precision (12 bits)
*/

my_bool my_uuid_extract_ts(const uchar *uuid, my_time_t *seconds, ulong *usec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well use bool here since there are only two result types.

Note for both int and bool: I hear that the convention is 1/true = error (which one might consider “timestamp invalid” to be one) and 0/false = no error.

@ParadoxV5 ParadoxV5 requested review from vuvova and removed request for ParadoxV5 December 28, 2025 20:31
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Dec 29, 2025
@varundeepsaini
Copy link
Author

varundeepsaini commented Dec 29, 2025

@FooBarrior the my_uuic.c file is being compiled as c

hence when trying to use bool

it is triggering this macro

should i switch to int / my_bool ?

#if !defined(__cplusplus) && !defined(bool)
#define bool In_C_you_should_use_my_bool_instead()
#endif```

Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
@varundeepsaini
Copy link
Author

Generated the UUIDs from https://www.uuidgenerator.net/
and the min max UUIDs by hand

Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

4 participants