【业务系列】面对大表的归档处理

【业务系列】面对大表的归档处理可以搞个存储过程: create table history_tmp like history; maxid=select max(id) from history; minid=select id…

【业务系列】面对大表的归档处理

可以搞个存储过程:

create table history_tmp like history;
maxid=select max(id) from history;
minid=select id from history where addtime>"2013-01-01 00:00" order by addtime asc limit 1;
last=0;
set autocommit=1;
for(i=minid;i<maxid+1000;i+=1000)
{
insert into history_tmp select * from history where id>=last and id<i lock in share mode;
last=i;
}
begin;
lock table history_tmp write,history write;
maxid=select max(id) from history;
insert into history_tmp select * from history where id>=last and id<=maxid;
alter table history rename to history_2012;
alter table history_tmp rename to history;
unlock tables;
commit;

代码100分

缺点:

  • insert into history_tmp select * from history where id>=last and id<=maxid; 可能会超时吗?
  • insert into history_tmp select * from history where id>=last and id<=maxid; 如果不是按Pk 索引,是一些过期的券的dealine 时间,效率如何?

面对上面的手工触发器,安全性很低。 下面推荐这款工具:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/9354.html

(0)
上一篇 2023-02-10
下一篇 2023-02-10

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注