大数据量时更新某字段的两种方案 哪个更好?

场景描述:
现在有两个表分别为ip和data表,
ip表:ipId,startIp,endIp 都是整型 数据量为千级,可以按照1000左右来算
data表:dataId,ip,status 都是整型(另外还有其他字段) 数据量为百万级 可以按照2 000 000左右来算

因为业务上的需要,现在需要更新data表的status值为0或1,规则是:如果ip在【startIp,endIp】之间 则更新为1,否则更新为0

我现在只想到了2种方案:
A: 先遍历data表全部设置为status=0,然后根据针对每条ip表记录 更新data表中对应ip段内所有记录的status为1
update data set status=0 ;
update data set status=1 where status=0 and (ip bwteen startIp1 and endIp1 );
update data set status=1 where status=0 and (ip bwteen startIp2 and endIp2 );
update data set status=1 where status=0 and (ip bwteen startIp3 and endIp3 );
...
update data set status=1 where status=0 and (ip bwteen startIpN and endIpN );


B:针对data表的所有ip,我们去匹配ip表,只要ip在ip表的任意一个【startIp,endIp】内我就更新status为1 ,否则为0
update data set status=1 where status=0 and  (   (ip bwteen startIp1  and endIp1 ) 
or (ip bwteen startIp2 and endIp2 )
or (ip bwteen startIp3 and endIp3 )
...
or (ip bwteen startIpN and endIpN )
);

update data set status=0 where status=1 and not ( (ip bwteen startIp1 and endIp1 )
or (ip bwteen startIp2 and endIp2 )
or (ip bwteen startIp3 and endIp3 )
...
or (ip bwteen startIpN and endIpN )
);


本人在数据库方面基础薄弱 实在看不出来哪种方法好,希望大家帮忙分析一下
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值