在MySQL中创建一个基于时间的UUID并在表上应用分区
我需要在一个表格上的一个基于时间的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论