目的是将公司所有访问的IP做更新,打上新/老的戳。字段暂定2个:ip,type
现建了一张IP历史表,每天将访问的IP与历史表比对,如果存在就把历史表的type=1,不存在就插入到历史表type=0。
现在呢,不知道到目前为止所有出现过的、不重复IP的总数,可能百万也可能千万、亿万....下面是我的操作思路,目的只有一个,尽可能的快。用的是存储过程。
1. distinct 当天的IP 到tmp表
2. tmp表 inner join 历史表 on 两表IP相等,结果入tmp2 ,type打上1
3. delet tmp where tmp 在 tmp2 出现的ip
4. merge 历史表 use (tmp union tmp2)
这个方法我唯一担忧的是最后的merge,毕竟历史表是会不断增大,这样merge 下去会越来越慢。
【请拍砖,求抛玉】

解决方案 »

  1.   

    你想做什么?
    最快的插入方法,直接插入,然后JOB运行你的业务
      

  2.   

    给个建议,大数据量按照IP访问,MERGER 符合业务流程提高速度,历史表按照IP断建立散列分区,全局索引+局部索引,快速定位,
      

  3.   

    流程过复杂了。/*
    ip_tb   ip
    sip_tb  ip u_type 
    */merge into sip_tb spt
    using (select ip
             from ip_tb
            where not exists (select null
                     from sip_tb
                    where sip_tb.ip = ip_tb.ip
                      and sip_tb.u_type = 1)) ipt
    on (spt.ip = ipt.ip)
    when matched then
      update set spt.u_type = 1
    when not matched then
      insert values (ipt.ip, 0);
      

  4.   

    LS
    你Using里 获得的 当期与历史相比 是新的IP,这样永远也触发不了update
      

  5.   

    (select null  from sip_tb
                    where sip_tb.ip = ip_tb.ip
                      and sip_tb.u_type = 1) 这个条件没限制到?
    是新的,但是如果就的type=0,旧的IP也会触发update。