gpt4 book ai didi

MySQL 将旧行修剪为每天 1 行

转载 作者:行者123 更新时间:2023-11-29 21:34:08 26 4
gpt4 key购买 nike

我有一个巨大的 MySQL 表,它每秒增长约 90 行,每 4 小时就有 130 万行与时间戳一起转储到其中

user(varchar)   | created_at(timestamp)
----------------------------
user 1 | 2016-01-27 08:00:00
user 2 | 2016-01-27 08:00:00
user 3 | 2016-01-27 08:00:00
...
user 1 | 2016-01-27 12:00:00
user 2 | 2016-01-27 12:00:00

等等...将一个月以上的数据修剪为每天只有一行的最佳方法是什么?

00:00 总是有行,所以我在想一些类似的事情

created_at >= date + 00:00 and created_at < date + 19:59

select user, max(created_at) from table where created_at = date group by username

最佳答案

对于如此大量的数据,您可能需要使用分区来管理数据,因为在大表上运行带有过滤器的删除语句可能需要很长时间。当您按月创建分区时,删除分区的速度非常快。但这会删除该月的数据,因此您可能需要在删除分区之前将用户摘要存储在另一个表中。

关于MySQL 将旧行修剪为每天 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35032466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com