{"id":18806735,"url":"https://github.com/lefred/mysql-component-uuid_v7","last_synced_at":"2025-04-13T19:12:51.735Z","repository":{"id":140210184,"uuid":"611397946","full_name":"lefred/mysql-component-uuid_v7","owner":"lefred","description":"MySQL Component to generate UUID_v7 ","archived":false,"fork":false,"pushed_at":"2024-01-23T19:45:14.000Z","size":39,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T09:52:01.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lefred.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-08T18:41:11.000Z","updated_at":"2025-01-02T10:03:15.000Z","dependencies_parsed_at":"2024-01-23T18:25:18.554Z","dependency_job_id":"8175e5eb-fdc4-4624-b90e-21e62093e3e4","html_url":"https://github.com/lefred/mysql-component-uuid_v7","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-uuid_v7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-uuid_v7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-uuid_v7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lefred%2Fmysql-component-uuid_v7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lefred","download_url":"https://codeload.github.com/lefred/mysql-component-uuid_v7/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766745,"owners_count":21158301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T22:49:25.353Z","updated_at":"2025-04-13T19:12:51.703Z","avatar_url":"https://github.com/lefred.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mysql-component-uuid_v7\n\nExtending MySQL using the Component Infrastructure - Adding a UUID v7 generator user function.\n\n```\n MySQL \u003e install component \"file://component_uuid_v7\";\n Query OK, 0 rows affected (0.0005 sec)\n \n MySQL \u003e select uuid_v7();\n+--------------------------------------+\n| uuid_v7()                            |\n+--------------------------------------+\n| 0186c285-2890-79d1-a8f0-6229ba440ade |\n+--------------------------------------+\n1 row in set (0.0008 sec)\n\n MySQL \u003e select uuid_v7_to_timestamp(\"0186c285-2890-79d1-a8f0-6229ba440ade\");\n+--------------------------------------------------------------+\n| uuid_v7_to_timestamp(\"0186c285-2890-79d1-a8f0-6229ba440ade\") |\n+--------------------------------------------------------------+\n| 2023-03-08 21:39:12.016                                      |\n+--------------------------------------------------------------+\n1 row in set (0.0003 sec)\n\n MySQL \u003e select uuid_v7_to_timestamp(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\");\n+--------------------------------------------------------------+\n| uuid_v7_to_timestamp(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\") |\n+--------------------------------------------------------------+\n| 2023-08-11 01:28:14.609                                      |\n+--------------------------------------------------------------+\n1 row in set (0.0005 sec)\n\n MySQL \u003e select uuid_v7_to_unixtime(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\");\n+-------------------------------------------------------------+\n| uuid_v7_to_unixtime(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\") |\n+-------------------------------------------------------------+\n|                                                  1691706494 |\n+-------------------------------------------------------------+\n1 row in set (0.0006 sec)\n\n MySQL \u003e select from_unixtime(uuid_v7_to_unixtime(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\"));\n+----------------------------------------------------------------------------+\n| from_unixtime(uuid_v7_to_unixtime(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\")) |\n+----------------------------------------------------------------------------+\n| 2023-08-11 01:28:14                                                        |\n+----------------------------------------------------------------------------+\n1 row in set (0.0006 sec)\n \n MySQL \u003e select from_unixtime(uuid_v7_to_unixtime(uuid_v7()));\n+-----------------------------------------------+\n| from_unixtime(uuid_v7_to_unixtime(uuid_v7())) |\n+-----------------------------------------------+\n| 2023-08-11 11:33:22                           |\n+-----------------------------------------------+\n1 row in set (0.0005 sec)\n \n MySQL \u003e select uuid_v7_to_timestamp_long(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\");\n+-------------------------------------------------------------------+\n| uuid_v7_to_timestamp_long(\"0189e190-8e91-7d81-9f8d-d9a1edbf955a\") |\n+-------------------------------------------------------------------+\n| Fri Aug 11 01:28:14 2023 GMT                                      |\n+-------------------------------------------------------------------+\n1 row in set (0.0007 sec) \n```\n\n## Errors Handling\n\nThe current checks performed:\n\n```\n MySQL \u003e select uuid_v7_to_timestamp(\"0189e190-8e91-4d81-9f8d-d9a1edbf955a\");\nERROR: 3200 (HY000): uuid_v7_to_timestamp UDF failed; This is not a UUID v7\n\n MySQL \u003e select uuid_v7_to_timestamp(\"0189e190-8e91-4d81-9f8d-d9a1edbf955a1\");\nERROR: 3200 (HY000): uuid_v7_to_timestamp UDF failed; Invalid UUID string length\n\n MySQL \u003e select uuid_v7_to_timestamp(\"aaa\");\nERROR: 3200 (HY000): uuid_v7_to_timestamp UDF failed; Invalid UUID string length\n\n MySQL \u003e select uuid_v7_to_timestamp(\"0189e190-8e91-4d81-9f8d-d9a1edbf955a1\",1);\nERROR: 3200 (HY000): uuid_v7_to_timestamp UDF failed; this function requires only 1 parameteter\n\n MySQL \u003e select uuid_v7_to_timestamp();\nERROR: 3200 (HY000): uuid_v7_to_timestamp UDF failed; this function requires 1 parameteter\n```\n\n## How to use a UUID v7 as primary key for a table\n\n```\n MySQL \u003e create table t1 (uuid varbinary(16) primary key, \n         name varchar(20), created timestamp default current_timestamp());\n\n MySQL \u003e insert into t1 (uuid, name) values (UUID_TO_BIN(uuid_v7()), \"fred\");\n MySQL \u003e insert into t1 (uuid, name) values (UUID_TO_BIN(uuid_v7()), \"scott\");\n MySQL \u003e insert into t1 (uuid, name) values (UUID_TO_BIN(uuid_v7()), \"lenka\");\n\n MySQL \u003e select * from t1;\n+------------------------------------+-------+---------------------+\n| uuid                               | name  | created             |\n+------------------------------------+-------+---------------------+\n| 0x0189E3CEE2A677819EE703856F8135C0 | fred  | 2023-08-11 11:55:33 |\n| 0x0189E3CEF8027A58951D745F60AF0068 | scott | 2023-08-11 11:55:39 |\n| 0x0189E3CF84BB766EAB94A674678379DC | lenka | 2023-08-11 11:56:15 |\n+------------------------------------+-------+---------------------+\n3 rows in set (0.0007 sec)\n\n MySQL \u003e select BIN_TO_UUID(uuid), name, created from t1;\n+--------------------------------------+-------+---------------------+\n| BIN_TO_UUID(uuid)                    | name  | created             |\n+--------------------------------------+-------+---------------------+\n| 0189e3ce-e2a6-7781-9ee7-03856f8135c0 | fred  | 2023-08-11 11:55:33 |\n| 0189e3ce-f802-7a58-951d-745f60af0068 | scott | 2023-08-11 11:55:39 |\n| 0189e3cf-84bb-766e-ab94-a674678379dc | lenka | 2023-08-11 11:56:15 |\n+--------------------------------------+-------+---------------------+\n3 rows in set (0.0003 sec)\n\n MySQL \u003e select BIN_TO_UUID(uuid), created, \n       uuid_v7_to_timestamp_long(BIN_TO_UUID(uuid)) uuid_ts from t1;\n+--------------------------------------+---------------------+------------------------------+\n| BIN_TO_UUID(uuid)                    | created             | uuid_ts                      |\n+--------------------------------------+---------------------+------------------------------+\n| 0189e3ce-e2a6-7781-9ee7-03856f8135c0 | 2023-08-11 11:55:33 | Fri Aug 11 11:55:33 2023 GMT |\n| 0189e3ce-f802-7a58-951d-745f60af0068 | 2023-08-11 11:55:39 | Fri Aug 11 11:55:39 2023 GMT |\n| 0189e3cf-84bb-766e-ab94-a674678379dc | 2023-08-11 11:56:15 | Fri Aug 11 11:56:15 2023 GMT |\n+--------------------------------------+---------------------+------------------------------+\n\n MySQL \u003e explain select * from t1 \n    where uuid=UUID_TO_BIN('0189e3ce-f802-7a58-951d-745f60af0068')\\G\n*************************** 1. row ***************************\n           id: 1\n  select_type: SIMPLE\n        table: t1\n   partitions: NULL\n         type: const\npossible_keys: PRIMARY\n          key: PRIMARY\n      key_len: 18\n          ref: const\n         rows: 1\n     filtered: 100\n        Extra: NULL\n1 row in set, 1 warning (0.0011 sec)\n\n MySQL \u003e explain format=tree select * from t1 \n    where uuid=UUID_TO_BIN('0189e3ce-f802-7a58-951d-745f60af0068')\\G\n*************************** 1. row ***************************\nEXPLAIN: -\u003e Rows fetched before execution  (cost=0..0 rows=1\n\n MySQL \u003e explain format=json select * from t1 \n    where uuid=UUID_TO_BIN('0189e3ce-f802-7a58-951d-745f60af0068')\\G\n*************************** 1. row ***************************\nEXPLAIN: {\n  \"query_block\": {\n    \"select_id\": 1,\n    \"cost_info\": {\n      \"query_cost\": \"1.00\"\n    },\n    \"table\": {\n      \"table_name\": \"t1\",\n      \"access_type\": \"const\",\n      \"possible_keys\": [\n        \"PRIMARY\"\n      ],\n      \"key\": \"PRIMARY\",\n      \"used_key_parts\": [\n        \"uuid\"\n      ],\n      \"key_length\": \"18\",\n      \"ref\": [\n        \"const\"\n      ],\n      \"rows_examined_per_scan\": 1,\n      \"rows_produced_per_join\": 1,\n      \"filtered\": \"100.00\",\n      \"cost_info\": {\n        \"read_cost\": \"0.00\",\n        \"eval_cost\": \"0.10\",\n        \"prefix_cost\": \"0.00\",\n        \"data_read_per_join\": \"104\"\n      },\n      \"used_columns\": [\n        \"uuid\",\n        \"name\",\n        \"created\"\n      ]\n    }\n  }\n}\n\n MySQL \u003e alter table t1 add column uuid_text char(36) \n         generated always as (BIN_TO_UUID(uuid)) virtual;\n\n MySQL \u003e select * from t1 ;\n+------------------------------------+-------+---------------------+--------------------------------------+\n| uuid                               | name  | created             | uuid_text                            |\n+------------------------------------+-------+---------------------+--------------------------------------+\n| 0x0189E3CEE2A677819EE703856F8135C0 | fred  | 2023-08-11 11:55:33 | 0189e3ce-e2a6-7781-9ee7-03856f8135c0 |\n| 0x0189E3CEF8027A58951D745F60AF0068 | scott | 2023-08-11 11:55:39 | 0189e3ce-f802-7a58-951d-745f60af0068 |\n| 0x0189E3CF84BB766EAB94A674678379DC | lenka | 2023-08-11 11:56:15 | 0189e3cf-84bb-766e-ab94-a674678379dc |\n+------------------------------------+-------+---------------------+--------------------------------------+         \n```\n\nThe only caveat is that such a component function cannot be used\nas default value for any column.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flefred%2Fmysql-component-uuid_v7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flefred%2Fmysql-component-uuid_v7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flefred%2Fmysql-component-uuid_v7/lists"}