+ -
当前位置:首页 → 问答吧 → update 与 删除 插入的性能问题

update 与 删除 插入的性能问题

时间:2011-08-22

来源:互联网

innodb的表,记录会过百万或千万,表上有索引,需要对表进行频繁的更新 怎么做效率高?

SQL code

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 ...





作者: baggio1984   发布时间: 2011-08-22

没啥区别

作者: rucypli   发布时间: 2011-08-22

感谢 1楼的回复 能告诉下为什么没区别吗 总感觉delete/insert需要更多的磁盘读写呢 难道是由于两次写 写磁盘的延迟 使得没了影响?

作者: baggio1984   发布时间: 2011-08-22

学习了

作者: uu_bird   发布时间: 2011-08-22