-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MDEV-33710 Implement UUID_TIMESTAMP() function #4496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
varundeepsaini
wants to merge
7
commits into
MariaDB:main
Choose a base branch
from
varundeepsaini:MDEV-33710-uuid-timestamp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
149c995
Implement UUID_TIMESTAMP() function that extracts timestamp from UUID…
varundeepsaini 273db49
refactoring
varundeepsaini 1a96b36
refactoring
varundeepsaini 3566feb
fixed test
varundeepsaini b7e70e4
refactored if to switch
varundeepsaini 0ca9ce8
changed return type to bool
varundeepsaini acd4413
refactoring
varundeepsaini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
plugin/type_uuid/mysql-test/type_uuid/func_uuid_timestamp.result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| SET time_zone='+00:00'; | ||
| # | ||
| # UUIDv1 with known timestamps | ||
| # | ||
| SELECT '4bd352dc-e593-11f0-8de9-0242ac120002' AS uuid, | ||
| UUID_TIMESTAMP('4bd352dc-e593-11f0-8de9-0242ac120002') AS ts; | ||
| uuid ts | ||
| 4bd352dc-e593-11f0-8de9-0242ac120002 2025-12-30 15:22:04.357910 | ||
| SELECT 'bec1046a-e593-11f0-8de9-0242ac120002' AS uuid, | ||
| UUID_TIMESTAMP('bec1046a-e593-11f0-8de9-0242ac120002') AS ts; | ||
| uuid ts | ||
| bec1046a-e593-11f0-8de9-0242ac120002 2025-12-30 15:25:17.175921 | ||
| SELECT 'c28c09a0-e593-11f0-8de9-0242ac120002' AS uuid, | ||
| UUID_TIMESTAMP('c28c09a0-e593-11f0-8de9-0242ac120002') AS ts; | ||
| uuid ts | ||
| c28c09a0-e593-11f0-8de9-0242ac120002 2025-12-30 15:25:23.539600 | ||
| # | ||
| # UUIDv7 with known timestamps (ms precision) | ||
| # | ||
| SELECT '019b6fdd-4937-7bb5-95c7-53363c6df927' AS uuid, | ||
| UUID_TIMESTAMP('019b6fdd-4937-7bb5-95c7-53363c6df927') AS ts; | ||
| uuid ts | ||
| 019b6fdd-4937-7bb5-95c7-53363c6df927 2025-12-30 15:25:31.831000 | ||
| SELECT '019b6fdd-5f17-7cf2-b034-248b9c207db6' AS uuid, | ||
| UUID_TIMESTAMP('019b6fdd-5f17-7cf2-b034-248b9c207db6') AS ts; | ||
| uuid ts | ||
| 019b6fdd-5f17-7cf2-b034-248b9c207db6 2025-12-30 15:25:37.431000 | ||
| SELECT '019b6fdd-7327-7a5b-935c-4de00dd0e7c6' AS uuid, | ||
| UUID_TIMESTAMP('019b6fdd-7327-7a5b-935c-4de00dd0e7c6') AS ts; | ||
| uuid ts | ||
| 019b6fdd-7327-7a5b-935c-4de00dd0e7c6 2025-12-30 15:25:42.567000 | ||
| # | ||
| # UUIDv4 returns NULL (no timestamp) | ||
| # | ||
| SELECT UUID_TIMESTAMP(UUID_V4()) IS NULL AS v4_returns_null; | ||
| v4_returns_null | ||
| 1 | ||
| SELECT UUID_TIMESTAMP('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11') IS NULL AS v4_string_returns_null; | ||
| v4_string_returns_null | ||
| 1 | ||
| # | ||
| # NULL and invalid input | ||
| # | ||
| SELECT UUID_TIMESTAMP(NULL) IS NULL AS null_input; | ||
| null_input | ||
| 1 | ||
| SELECT UUID_TIMESTAMP('not-a-valid-uuid'); | ||
| UUID_TIMESTAMP('not-a-valid-uuid') | ||
| NULL | ||
| Warnings: | ||
| Warning 1292 Incorrect uuid value: 'not-a-valid-uuid' | ||
| # | ||
| # Native UUID type | ||
| # | ||
| SELECT '019b6fdd-4937-7bb5-95c7-53363c6df927' AS uuid, | ||
| UUID_TIMESTAMP(CAST('019b6fdd-4937-7bb5-95c7-53363c6df927' AS UUID)) AS ts; | ||
| uuid ts | ||
| 019b6fdd-4937-7bb5-95c7-53363c6df927 2025-12-30 15:25:31.831000 | ||
| # | ||
| # Return type is TIMESTAMP(6) | ||
| # | ||
| CREATE TABLE t1 AS SELECT UUID_TIMESTAMP('019b6fdd-4937-7bb5-95c7-53363c6df927') AS ts; | ||
| SHOW CREATE TABLE t1; | ||
| Table Create Table | ||
| t1 CREATE TABLE `t1` ( | ||
| `ts` timestamp(6) NULL DEFAULT NULL | ||
| ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci | ||
| DROP TABLE t1; | ||
| # | ||
| # Edge cases | ||
| # | ||
| SELECT '00000000-0000-1000-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('00000000-0000-1000-8000-000000000000') IS NULL AS before_unix_epoch; | ||
| uuid before_unix_epoch | ||
| 00000000-0000-1000-8000-000000000000 1 | ||
| SELECT '00000000-0000-7000-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('00000000-0000-7000-8000-000000000000') AS ts; | ||
| uuid ts | ||
| 00000000-0000-7000-8000-000000000000 0000-00-00 00:00:00.000000 | ||
| SELECT 'ffffffff-ffff-7fff-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('ffffffff-ffff-7fff-8000-000000000000') AS ts; | ||
| uuid ts | ||
| ffffffff-ffff-7fff-8000-000000000000 2042-12-13 16:54:30.655000 | ||
| SELECT 'ffffffff-ffff-1fff-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('ffffffff-ffff-1fff-8000-000000000000') AS ts; | ||
| uuid ts | ||
| ffffffff-ffff-1fff-8000-000000000000 2105-11-25 16:30:52.684697 | ||
| SET time_zone=DEFAULT; |
66 changes: 66 additions & 0 deletions
66
plugin/type_uuid/mysql-test/type_uuid/func_uuid_timestamp.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # MDEV-33710: UUID_TIMESTAMP() extracts timestamp from UUIDv1 and UUIDv7 | ||
FooBarrior marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SET time_zone='+00:00'; | ||
|
|
||
| --echo # | ||
| --echo # UUIDv1 with known timestamps | ||
| --echo # | ||
| SELECT '4bd352dc-e593-11f0-8de9-0242ac120002' AS uuid, | ||
| UUID_TIMESTAMP('4bd352dc-e593-11f0-8de9-0242ac120002') AS ts; | ||
| SELECT 'bec1046a-e593-11f0-8de9-0242ac120002' AS uuid, | ||
| UUID_TIMESTAMP('bec1046a-e593-11f0-8de9-0242ac120002') AS ts; | ||
| SELECT 'c28c09a0-e593-11f0-8de9-0242ac120002' AS uuid, | ||
| UUID_TIMESTAMP('c28c09a0-e593-11f0-8de9-0242ac120002') AS ts; | ||
|
|
||
| --echo # | ||
| --echo # UUIDv7 with known timestamps (ms precision) | ||
| --echo # | ||
| SELECT '019b6fdd-4937-7bb5-95c7-53363c6df927' AS uuid, | ||
| UUID_TIMESTAMP('019b6fdd-4937-7bb5-95c7-53363c6df927') AS ts; | ||
| SELECT '019b6fdd-5f17-7cf2-b034-248b9c207db6' AS uuid, | ||
| UUID_TIMESTAMP('019b6fdd-5f17-7cf2-b034-248b9c207db6') AS ts; | ||
| SELECT '019b6fdd-7327-7a5b-935c-4de00dd0e7c6' AS uuid, | ||
| UUID_TIMESTAMP('019b6fdd-7327-7a5b-935c-4de00dd0e7c6') AS ts; | ||
|
|
||
| --echo # | ||
| --echo # UUIDv4 returns NULL (no timestamp) | ||
| --echo # | ||
| SELECT UUID_TIMESTAMP(UUID_V4()) IS NULL AS v4_returns_null; | ||
| SELECT UUID_TIMESTAMP('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11') IS NULL AS v4_string_returns_null; | ||
|
|
||
| --echo # | ||
| --echo # NULL and invalid input | ||
| --echo # | ||
| SELECT UUID_TIMESTAMP(NULL) IS NULL AS null_input; | ||
| SELECT UUID_TIMESTAMP('not-a-valid-uuid'); | ||
|
|
||
| --echo # | ||
| --echo # Native UUID type | ||
| --echo # | ||
| SELECT '019b6fdd-4937-7bb5-95c7-53363c6df927' AS uuid, | ||
| UUID_TIMESTAMP(CAST('019b6fdd-4937-7bb5-95c7-53363c6df927' AS UUID)) AS ts; | ||
|
|
||
| --echo # | ||
| --echo # Return type is TIMESTAMP(6) | ||
| --echo # | ||
| CREATE TABLE t1 AS SELECT UUID_TIMESTAMP('019b6fdd-4937-7bb5-95c7-53363c6df927') AS ts; | ||
| SHOW CREATE TABLE t1; | ||
| DROP TABLE t1; | ||
|
|
||
| --echo # | ||
| --echo # Edge cases | ||
| --echo # | ||
| # UUIDv1 before Unix epoch | ||
| SELECT '00000000-0000-1000-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('00000000-0000-1000-8000-000000000000') IS NULL AS before_unix_epoch; | ||
| # UUIDv7 at Unix epoch (ts=0) | ||
| SELECT '00000000-0000-7000-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('00000000-0000-7000-8000-000000000000') AS ts; | ||
| # UUIDv7 max 48-bit timestamp | ||
| SELECT 'ffffffff-ffff-7fff-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('ffffffff-ffff-7fff-8000-000000000000') AS ts; | ||
| # UUIDv1 max timestamp | ||
| SELECT 'ffffffff-ffff-1fff-8000-000000000000' AS uuid, | ||
| UUID_TIMESTAMP('ffffffff-ffff-1fff-8000-000000000000') AS ts; | ||
|
|
||
| SET time_zone=DEFAULT; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.