在MySQL中创建一个基于时间的UUID并在表上应用分区

发布于 2025-02-05 05:55:52 字数 1423 浏览 3 评论 0原文

我需要在一个表格上的一个基于时间的UUID中生成一个基于时间的UUID,为此我可以使用UUID版本(这是节点的时间戳 + MAC地址的组合)。

由于表非常大,我需要根据基于时间的UUID列对数据进行分区,并且限制是我需要根据基于该时间的UUID列值在基于时间的UUID列上应用分区。 。

基于提供的输入,已创建了用户_DEFIAND函数,为:

设置global log_bin_trust_function_creators = 1; 定界符$$

create function findObject(col_name VARCHAR(100)) returns DATETIME
begin
    DECLARE result DATETIME;
    SELECT   
       CONVERT(from_unixtime(
          (conv(                      
            concat(                   -- step 1: reconstruct hexadecimal timestamp
              substring(col_name, 16, 3)
            , substring(col_name, 10, 4)
            , substring(col_name, 1, 8)
            ), 16, 10)                -- step 2: convert hexadecimal to decimal
            div 10 div 1000 div 1000  -- step 3: go from nanoseconds to seconds
          ) - (141427 * 24 * 60 * 60) -- step 4: substract timestamp offset (October 15,  
        ),DATETIME)                          AS uuid_to_timestamp
    INTO result;
    RETURN result;
end$$
delimiter ;

,现在使用该函数将我的数据划分:

CREATE TABLE `mytable2` (
  `post_id` int DEFAULT NULL,
  `viewid` int DEFAULT NULL,
  `user_id` int DEFAULT NULL,
  `url_id` DATETIME  NULL
) 
PARTITION BY RANGE (YEAR(findObject(url_id)))  (
    PARTITION p2 VALUES LESS THAN (2001),
    PARTITION p3 VALUES LESS THAN MAXVALUE
);

但是不允许在(sub)分区功能中以恒定,随机或时区依赖性表达式获取误差。

请帮我

I need to generate a time based UUID in mysql over one of the table, for which i can use UUID version(which is combination of timestamp + mac address of the node).

As the table is very big ,I need to partitioned the data based on that time based UUID column and the limitation is that I need to apply the partition over the time based UUID column based on year and month available in that time based uuid column value.

Based on the inputs provided ,have created the user_defined function as:

SET GLOBAL log_bin_trust_function_creators = 1;
delimiter $$

create function findObject(col_name VARCHAR(100)) returns DATETIME
begin
    DECLARE result DATETIME;
    SELECT   
       CONVERT(from_unixtime(
          (conv(                      
            concat(                   -- step 1: reconstruct hexadecimal timestamp
              substring(col_name, 16, 3)
            , substring(col_name, 10, 4)
            , substring(col_name, 1, 8)
            ), 16, 10)                -- step 2: convert hexadecimal to decimal
            div 10 div 1000 div 1000  -- step 3: go from nanoseconds to seconds
          ) - (141427 * 24 * 60 * 60) -- step 4: substract timestamp offset (October 15,  
        ),DATETIME)                          AS uuid_to_timestamp
    INTO result;
    RETURN result;
end$
delimiter ;

and now using the function to partition my data :

CREATE TABLE `mytable2` (
  `post_id` int DEFAULT NULL,
  `viewid` int DEFAULT NULL,
  `user_id` int DEFAULT NULL,
  `url_id` DATETIME  NULL
) 
PARTITION BY RANGE (YEAR(findObject(url_id)))  (
    PARTITION p2 VALUES LESS THAN (2001),
    PARTITION p3 VALUES LESS THAN MAXVALUE
);

But getting the error as Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed .

Please please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文