下一次,使用单个“alter table”语句更新主键。
alter table xx drop primary key, add primary key(k1, k2, k3);
修复问题:
create table fixit (user_2, user_1, type, timestamp, n, primary key( user_2, user_1, type) );
lock table fixit write, user_interactions u write, user_interactions write;
insert into fixit
select user_2, user_1, type, max(timestamp), count(*) n from user_interactions u
group by user_2, user_1, type
having n > 1;
delete u from user_interactions u, fixit
where fixit.user_2 = u.user_2
and fixit.user_1 = u.user_1
and fixit.type = u.type
and fixit.timestamp != u.timestamp;
alter table user_interactions add primary key (user_2, user_1, type );
unlock tables;
锁应该停止进一步更新进来,而你这样做。这需要多长时间取决于您的表的大小。
主要的问题是如果你有一些重复的具有相同的时间戳。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/218644.html原文链接:https://javaforall.net
