update tt_sta_mon_new 
             set during_new =(select during_new from
             (select calling_code,sum(duration) as during_new 
             from tlw_list_ip group by calling_code) a 
             where a.calling_code = tt_sta_mon_new.calling_no)
tlw_list_ip这张表里的数据量比较大  有好几百万条 
我执行这行这条语句三个小时没执行完成
请教各位高手

解决方案 »

  1.   

    建个临时表   然后通过这两个表UPDATE试下你的那个表有多大,为什么要3个小时tlw_list_ip表有没有索引
      

  2.   

    select calling_code,sum(duration) as during_new 
                 from tlw_list_ip group by calling_code
    改为:
    select calling_code,sum(duration) as during_new 
                 from tlw_list_ip where a.calling_code = tt_sta_mon_new.calling_no
      

  3.   

    tlw_list_ip表有没有索引
    这个问题比较关键
    然后,几百万的表,为什么动不动就全表操作呢,难道没有什么约束条件?
      

  4.   

    你完全可以这么写,最简便
    update tt_sta_mon_new 
                 set during_new =
                (select sum(duration) as during_new 
                 from tlw_list_ip
                 where calling_code = tt_sta_mon_new.calling_no)
      

  5.   

    因为你的写法大大增加了数据库的操作
    比如
    update tt_sta_mon_new 
                 set during_new =(select during_new from
                 (select calling_code,sum(duration) as during_new 
                 from tlw_list_ip group by calling_code) a 
                 where a.calling_code = tt_sta_mon_new.calling_no)本来运算9次,但是你的这个就应该是 8*8 + 1次
    所以你的速度就不能提高上去
      

  6.   

    所以建议使用update tt_sta_mon_new 
                 set during_new =
                (select sum(duration) as during_new 
                 from tlw_list_ip
                 where calling_code = tt_sta_mon_new.calling_no)
      

  7.   

    曾经做过Update 800W 记录 到一个1000W的表,搞了一个晚上都没完。结果,用建新表 的方式0多分钟搞定!
    所以我认为,即使有索引,也不如新建表
      

  8.   

    如果你表中的数据量大,最好不要全表检索.也最好不要用group by .正如上面那为老兄说的:几百万的表,为什么动不动就全表操作呢,难道没有什么约束条件?
      

  9.   

    update tt_sta_mon_new 
                 set during_new =
                (select sum(duration) as during_new 
                 from tlw_list_ip
                 where calling_code = tt_sta_mon_new.calling_no)这种方式至少可以在半分钟检索完.
      

  10.   

    如果你的表经常都在用UPDATE,INSERT,DELETE操作的话,有索引也可重建一下,不然有索引也慢.方法: 1 新建一表
          2 重建索引