56,673
社区成员
发帖
与我相关
我的任务
分享
create table t_user
(
kid bigint not null auto_increment,
user_id bigint not null,
user_xx int not null,
user_yy int not null,
isvalid int not null,
primary key(kid)
)engine = innodb;
create index index_user on t_user(user_id);
每个user_id 对应 几十条记录 主键不一定连续 每次更新的记录数和更新的字段都有变化
下面两个效率有区别吗。。。 本来我以为直接更新的会效率高 觉得没有索引的重建,但用十万左右的记录 更新 随机和连续的 几千条记录 感觉没啥大的差别 这是为啥。。。。。
1. 先删再插
delete from t_user where user_id = xxx;
insert into t_user() values();
2.先置为无效再更新
update set isvalid = 0 where user_id = xxx;
存储过程
procedure
select user_id to temp_id from t_user where user_id = xxx;
if temp_id = xxx then
update ....
else
insert ...